Skip to contentSkip to conversation

Kconfig vs. default devices

PATCH Superseded Fabiano Rosas 4 participants 13 messages Feb 8, 2023 – May 2, 2023 1 message not in the archive

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Kconfig vs. default devices

v2:
Applying the feedback received, all small tweaks.

Patch 6 still needs consensus on whether to apply the fix to Kconfig or elsewhere. Link to the previous version:
https://lore.kernel.org/r/[email protected]

changelog:

- patch 1: moved isa-parallel to a build time check like the other

           patches;

- patch 3: tweaked commit message;
- patch 7: removed the default from XLNX_USB_SUBSYS.

v1:
https://lore.kernel.org/r/[email protected]

We currently have a situation where disabling a Kconfig might result in a runtime error when QEMU selects the corresponding device as a default value for an option. But first a disambiguation:

Kconfig default::
a device "Foo" for which there's "config FOO default y" or "config X imply FOO" in Kconfig.

QEMU hardcoded default::
a fallback; a device "Foo" that is chosen in case no corresponding option is given in the command line.

The issue I'm trying to solve is that there is no link between the two "defaults" above, which means that when the user at build time de-selects a Kconfig default, either via configs/devices/*/*.mak or --without-default-devices, the subsequent invocation at runtime might continue to try to create the missing device due to QEMU defaults.

Even a experienced user that tweaks the build via .mak files is not required to know about what QEMU developers chose to use as fallbacks in the code. Moreover, the person/entity that builds the code might not be the same that runs it, which makes it even more confusing.

We do have -nodefaults in the command line, but that doesn't include all types of fallbacks that might be set in the code. It also does not cover individual CONFIGs and their respective use as a fallback in the code.

So my proposal here is actually simple: Let's make sure every fallback device creation *without* a validation check gets a hard dependency in Kconfig. A validation check being something like:

if (has_defaults && object_get_class("foo") {
create_foo();
}

Fabiano Rosas (10):
hw/i386: Select CONFIG_PARALLEL for PC machines hw/i386: Select E1000E for q35
hw/i386: Select VGA_PCI in Kconfig
hw/i386: Select E1000_PCI for i440fx
hw/arm: Select VIRTIO_NET for virt machine hw/arm: Select VIRTIO_BLK for virt machine hw/arm: Select XLNX_USB_SUBSYS for xlnx-zcu102 machine hw/arm: Select GICV3_TCG for sbsa-ref machine hw/arm: Select e1000e for sbsa-ref machine hw/arm: Select VGA_PCI for sbsa-ref machine

 hw/arm/Kconfig  | 7 +++++++
 hw/i386/Kconfig | 8 ++++----
 hw/usb/Kconfig  | 1 -
 3 files changed, 11 insertions(+), 5 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH v2 4/10 hw/i386: Select E1000_PCI for i440fx

The i440fx machines uses the e1000 adapter as the default when no other network card is configured.

Move the E1000_PCI entry in Kconfig from 'imply' to 'select' to avoid the following situation:

./qemu-system-i386 -machine pc-i440fx-8.0
qemu-system-i386: Unsupported NIC model: e1000

---
 hw/i386/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/Kconfig +1 -1
index 36590e2691..e98af283b4 100644
@@ -66,7 +66,6 @@ config PC_ACPI
 
 config I440FX
     bool
-    imply E1000_PCI
     imply VMPORT
     imply VMMOUSE
     select ACPI_PIIX4
@@ -78,6 +77,7 @@ config I440FX
     select DIMM
     select SMBIOS
     select FW_CFG_DMA
+    select E1000_PCI
 
 config ISAPC
     bool
Signature · 1 line
2.35.3
#2 lore raw

PATCH v2 5/10 hw/arm: Select VIRTIO_NET for virt machine

In reply to Fabiano Rosas

The 'virt' machine uses virtio-net-pci as a fallback when no other network driver has been selected via command line. Select VIRTIO_NET and VIRTIO_PCI from CONFIG_ARM_VIRT to avoid errors when PCI_DEVICES=n (due to e.g. --without-default-devices):

$ ./qemu-system-aarch64 -M virt -accel tcg -cpu max
qemu-system-aarch64: Unsupported NIC model: virtio-net-pci
---
 hw/arm/Kconfig | 2 ++
 1 file changed, 2 insertions(+)
hw/arm/Kconfig +2 -0
index 2d157de9b8..8dcc08b7ec 100644
@@ -31,6 +31,8 @@ config ARM_VIRT
     select VIRTIO_MEM_SUPPORTED
     select ACPI_CXL
     select ACPI_HMAT
+    select VIRTIO_PCI
+    select VIRTIO_NET
 
 config CHEETAH
     bool
Signature · 1 line
2.35.3
#3 lore raw

PATCH v2 6/10 hw/arm: Select VIRTIO_BLK for virt machine

In reply to Fabiano Rosas

The virt machine has IF_VIRTIO as block_default_type, which causes the generic code to try to create a virtio-blk-pci device pair at configure_blockdev()/qemu_create_cli_devices().

Select VIRTIO_BLK and VIRTIO_PCI from CONFIG_ARM_VIRT to avoid errors when PCI_DEVICES=n (due to e.g. --without-default-devices):

$ ./qemu-system-aarch64 -M virt -accel tcg -cpu max -nodefaults -cdrom foo.qcow2
qemu-system-aarch64: -cdrom foo.qcow2: 'virtio-blk' (alias
'virtio-blk-pci') is not a valid device model name
---
 hw/arm/Kconfig | 1 +
 1 file changed, 1 insertion(+)
hw/arm/Kconfig +1 -0
index 8dcc08b7ec..296d4f5176 100644
@@ -33,6 +33,7 @@ config ARM_VIRT
     select ACPI_HMAT
     select VIRTIO_PCI
     select VIRTIO_NET
+    select VIRTIO_BLK
 
 config CHEETAH
     bool
Signature · 1 line
2.35.3
#4 lore raw

PATCH v2 7/10 hw/arm: Select XLNX_USB_SUBSYS for xlnx-zcu102 machine

In reply to Fabiano Rosas

This machine hardcodes initialization of the USB device, so select the corresponding Kconfig. It is not enough to have it as "default y if XLNX_VERSAL" at usb/Kconfig because building --without-default-devices disables the default selection resulting in:

$ ./qemu-system-aarch64 -M xlnx-zcu102
qemu-system-aarch64: missing object type 'usb_dwc3'
Aborted (core dumped)
---
 hw/arm/Kconfig | 1 +
 hw/usb/Kconfig | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
hw/arm/Kconfig +1 -0
index 296d4f5176..552e3d04ee 100644
@@ -405,6 +405,7 @@ config XLNX_VERSAL
     select OR_IRQ
     select XLNX_BBRAM
     select XLNX_EFUSE_VERSAL
+    select XLNX_USB_SUBSYS
 
 config NPCM7XX
     bool
hw/usb/Kconfig +0 -1
index ce4f433976..0ec6def4b8 100644
@@ -136,5 +136,4 @@ config USB_DWC3
 
 config XLNX_USB_SUBSYS
     bool
-    default y if XLNX_VERSAL
     select USB_DWC3
Signature · 1 line
2.35.3
#5 lore raw

PATCH v2 8/10 hw/arm: Select GICV3_TCG for sbsa-ref machine

In reply to Fabiano Rosas

This machine hardcodes the creation of the interrupt controller, so make sure the dependency is explicitly described in the Kconfig.

---
 hw/arm/Kconfig | 1 +
 1 file changed, 1 insertion(+)
hw/arm/Kconfig +1 -0
index 552e3d04ee..823f8b11f1 100644
@@ -232,6 +232,7 @@ config SBSA_REF
     select PL061 # GPIO
     select USB_EHCI_SYSBUS
     select WDT_SBSA
+    select ARM_GICV3_TCG
 
 config SABRELITE
     bool
Signature · 1 line
2.35.3
#6 lore raw

PATCH v2 9/10 hw/arm: Select e1000e for sbsa-ref machine

In reply to Fabiano Rosas

This machine explicitly selects the e1000e network adapter if no other option was given in the command line. Make sure e1000e is present in the build.

---
 hw/arm/Kconfig | 1 +
 1 file changed, 1 insertion(+)
hw/arm/Kconfig +1 -0
index 823f8b11f1..5022d519ea 100644
@@ -233,6 +233,7 @@ config SBSA_REF
     select USB_EHCI_SYSBUS
     select WDT_SBSA
     select ARM_GICV3_TCG
+    select E1000E_PCI_EXPRESS
 
 config SABRELITE
     bool
Signature · 1 line
2.35.3
#7 lore raw

PATCH v2 10/10 hw/arm: Select VGA_PCI for sbsa-ref machine

In reply to Fabiano Rosas

The sbsa-ref machine explicitly creates a VGA PCI device, so make sure vga-pci.c is included in the build.

---
 hw/arm/Kconfig | 1 +
 1 file changed, 1 insertion(+)
hw/arm/Kconfig +1 -0
index 5022d519ea..74fceb419d 100644
@@ -234,6 +234,7 @@ config SBSA_REF
     select WDT_SBSA
     select ARM_GICV3_TCG
     select E1000E_PCI_EXPRESS
+    select VGA_PCI
 
 config SABRELITE
     bool
Signature · 1 line
2.35.3
#8 lore raw
In reply to Fabiano Rosas
Quoted 12 lines · Fabiano Rosas

We currently have a situation where disabling a Kconfig might result in a runtime error when QEMU selects the corresponding device as a default value for an option. But first a disambiguation:

Kconfig default::
a device "Foo" for which there's "config FOO default y" or "config X imply FOO" in Kconfig.

QEMU hardcoded default::
a fallback; a device "Foo" that is chosen in case no corresponding option is given in the command line.

Quoted 5 lines

The issue I'm trying to solve is that there is no link between the two "defaults" above, which means that when the user at build time de-selects a Kconfig default, either via configs/devices/*/*.mak or --without-default-devices, the subsequent invocation at runtime might continue to try to create the missing device due to QEMU defaults.

This will keep bitrotting if we don't cover such configs in our CI.

Why do you want to get this fixed BTW? I'm not sure there is a big interest (as in "almost no users").

I tried to do that few years ago [*] and Thomas said:

"in our CI, we should test what users really need,
and not each and every distantly possible combination."

[*] https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 17 lines

Fabiano Rosas (10):
hw/i386: Select CONFIG_PARALLEL for PC machines hw/i386: Select E1000E for q35
hw/i386: Select VGA_PCI in Kconfig
hw/i386: Select E1000_PCI for i440fx
hw/arm: Select VIRTIO_NET for virt machine hw/arm: Select VIRTIO_BLK for virt machine hw/arm: Select XLNX_USB_SUBSYS for xlnx-zcu102 machine hw/arm: Select GICV3_TCG for sbsa-ref machine hw/arm: Select e1000e for sbsa-ref machine hw/arm: Select VGA_PCI for sbsa-ref machine

  hw/arm/Kconfig  | 7 +++++++
  hw/i386/Kconfig | 8 ++++----
  hw/usb/Kconfig  | 1 -
  3 files changed, 11 insertions(+), 5 deletions(-)
#9 lore raw
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Fabiano Rosas

We currently have a situation where disabling a Kconfig might result in a runtime error when QEMU selects the corresponding device as a default value for an option. But first a disambiguation:

Kconfig default::
   a device "Foo" for which there's "config FOO default y" or "config X imply FOO" in Kconfig.

QEMU hardcoded default::
   a fallback; a device "Foo" that is chosen in case no corresponding option is given in the command line.

Quoted 5 lines

The issue I'm trying to solve is that there is no link between the two "defaults" above, which means that when the user at build time de-selects a Kconfig default, either via configs/devices/*/*.mak or --without-default-devices, the subsequent invocation at runtime might continue to try to create the missing device due to QEMU defaults.

This will keep bitrotting if we don't cover such configs in our CI.

Quoted 7 lines

Why do you want to get this fixed BTW? I'm not sure there is a big interest (as in "almost no users").

I tried to do that few years ago [*] and Thomas said:

"in our CI, we should test what users really need,
 and not each and every distantly possible combination."

You're mis-quoting me here. That comment was made when we were talking about very arbitrary configs that likely nobody is going to use. Fabiano's series here is about the --without-default-devices configure option which everybody could add to their set of "configure" options easily.

Thomas

#10 lore raw
Quoted 27 lines · Thomas Huth
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Fabiano Rosas

We currently have a situation where disabling a Kconfig might result in a runtime error when QEMU selects the corresponding device as a default value for an option. But first a disambiguation:

Kconfig default::
   a device "Foo" for which there's "config FOO default y" or "config X imply FOO" in Kconfig.

QEMU hardcoded default::
   a fallback; a device "Foo" that is chosen in case no corresponding option is given in the command line.

Quoted 5 lines

The issue I'm trying to solve is that there is no link between the two "defaults" above, which means that when the user at build time de-selects a Kconfig default, either via configs/devices/*/*.mak or --without-default-devices, the subsequent invocation at runtime might continue to try to create the missing device due to QEMU defaults.

Quoted 6 lines

This will keep bitrotting if we don't cover such configs in our CI. Why do you want to get this fixed BTW? I'm not sure there is a big interest (as in "almost no users").
I tried to do that few years ago [*] and Thomas said:
"in our CI, we should test what users really need,
 and not each and every distantly possible combination."

Quoted 5 lines

You're mis-quoting me here. That comment was made when we were talking about very arbitrary configs that likely nobody is going to use. Fabiano's series here is about the --without-default-devices configure option which everybody could add to their set of "configure" options easily.

Indeed - while trying to reduce the compile time I ran into this with a plain --without-default-devices check. We also have in the meantime introduced --with-devices-FOO so we can do minimal builds.

Quoted 2 lines

Thomas

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw

Re: [PATCH v2 01/10] hw/i386: Select CONFIG_PARALLEL for PC machines

Quoted 25 lines · Fabiano Rosas

Currently the isa-parallel driver is always added by the PC machines regardless of the presence of the actual code in the build, which can lead to a crash:

qemu-system-i386: unknown type 'isa-parallel'
Aborted (core dumped)

---
  hw/i386/Kconfig | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/Kconfig +0 -1
index 1bf47b0b0b..d3c340e053 100644
@@ -20,7 +20,6 @@ config PC
      imply PCI_IPMI_BT
      imply IPMI_SSIF
      imply ISA_DEBUG
-    imply PARALLEL
      imply PCI_DEVICES
      imply PVPANIC_ISA
      imply QXL

hw/i386/Kconfig config PC · line 51

Quoted 7 lines
hw/i386/Kconfig +1 -0
@@ -46,6 +45,7 @@ config PC
      select ACPI_VMGENID
      select VIRTIO_PMEM_SUPPORTED
      select VIRTIO_MEM_SUPPORTED
+    select PARALLEL
 
  config PC_PCI
      bool

Phew ... Ack from a plain upstream point of view. From a Red Hat downstream point of view, this will cause another downstream-only patch for us, since the binaries (and the machine types) that we have in RHEL have the "isa-parallel" device not compiled in on purpose.

So I started wondering now whether we could tackle all this a little bit different, in a more flexible way ... something similar like you did in your parallel port patch in v1 / something similar to what Peter suggested in his option (2) here:

https://lore.kernel.org/qemu-devel/CAFEAcA9VkFU_bh=aBAOoXCUCeSm1xuR+H+uerd468=vVuDrJEg@mail.gmail.com/

For display devices, we already have default_display in MachineClass, so instead of always selecting the VGA device in your "Select VGA_PCI in Kconfig" patch, we could check that in vl.c and set default_vga = 0 if it is not available.

For network devices, there is already default_nic_model in PCMachineClass ... we could move that to the generic MachineClass and use it in vl.c according.

Then no_parallel, no_serial, no_floppy, no_cdrom, no_sdcard in the MachineClass could be replaced by a "char *default_XYZ", too, so that we rather have a device name here to indicate the availability of a default device than a boolean flag. If the pointer is not set ==> no default device. If the pointer is set and the device is available ==> use the default device. If the pointer is set and the device is not compiled in ==> emit a warning, but continue as if the pointer was not set.

What do you think?

Thomas

#13 lore raw
In reply to Fabiano Rosas
Quoted 7 lines · Fabiano Rosas

v2:
Applying the feedback received, all small tweaks.

Patch 6 still needs consensus on whether to apply the fix to Kconfig or elsewhere. Link to the previous version:
https://lore.kernel.org/r/[email protected]

Quoted 6 lines

changelog:

- patch 1: moved isa-parallel to a build time check like the other

           patches;

- patch 3: tweaked commit message;
- patch 7: removed the default from XLNX_USB_SUBSYS.

I've queued the ARM tweaks to testing/next where I can add a test for it in the end. I'll leave the x86 stuff for discussion of the more complete solution that avoids hacky downstream patching.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro