This series adds an option to set the memory layout preference, both at compile time (via kconfig) and runtime (via fwcfg).
Gerd Hoffmann (4): add guest hint variable use guest hint as additional condition add guest hint default kconfig add guest hint fw_cfg override
src/fw/paravirt.h | 1 + src/fw/paravirt.c | 9 +++++++++ src/fw/pciinit.c | 2 +- src/Kconfig | 7 +++++++ 4 files changed, 18 insertions(+), 1 deletion(-)
This holds the hint whenever the guest is 32-bit or 64-bit, so seabios can optimize the memory layout (pci bar placement) accordingly.
Default is '32' for best backward compatibility.
Signed-off-by: Gerd Hoffmann kraxel@redhat.com --- src/fw/paravirt.h | 1 + src/fw/paravirt.c | 2 ++ 2 files changed, 3 insertions(+)
diff --git a/src/fw/paravirt.h b/src/fw/paravirt.h index 62a2cd075d2b..cf28528e0261 100644 --- a/src/fw/paravirt.h +++ b/src/fw/paravirt.h @@ -33,6 +33,7 @@ extern u64 RamSizeOver4G; extern int PlatformRunningOn; extern u8 CPUPhysBits; extern u8 CPULongMode; +extern u8 GuestHint;
static inline int runningOnQEMU(void) { return CONFIG_QEMU || ( diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index e5d4eca0cb5a..fbd00f1c072f 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -36,6 +36,8 @@ u64 RamSizeOver4G; u8 CPUPhysBits; // 64bit processor u8 CPULongMode; +// memory layout hint (32bit or 64bit guests). +u8 GuestHint = 32; // Type of emulator platform. int PlatformRunningOn VARFSEG; // cfg enabled
check guest hint as additional condition to enable the 64-bit guest friendly memory layout.
With '32' seabios will use traditional pci configuration for best compatibility: all PCI bars will be mapped into the 32-bit PCI MMIO window below 4G if they fit there.
With '64' seabios will use the new pci configuration introduced by commit 96a8d130a8c2 ("be less conservative with the 64bit pci io window"): the 64-bit MMIO window will be used unconditionally and PCI bridges will get larger bridge windows.
Signed-off-by: Gerd Hoffmann kraxel@redhat.com --- src/fw/pciinit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index b3e359d7fe62..ab28286e7018 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -1202,7 +1202,7 @@ pci_setup(void) } }
- if (CPUPhysBits >= 36 && CPULongMode && RamSizeOver4G) + if (CPUPhysBits >= 36 && CPULongMode && RamSizeOver4G && GuestHint == 64) pci_pad_mem64 = 1;
dprintf(1, "=== PCI bus & bridge init ===\n");
Add compile time config option for the guest hint default value.
Signed-off-by: Gerd Hoffmann kraxel@redhat.com --- src/fw/paravirt.c | 2 +- src/Kconfig | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index fbd00f1c072f..001be7caf102 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -37,7 +37,7 @@ u8 CPUPhysBits; // 64bit processor u8 CPULongMode; // memory layout hint (32bit or 64bit guests). -u8 GuestHint = 32; +u8 GuestHint = CONFIG_DEFAULT_GUEST_HINT; // Type of emulator platform. int PlatformRunningOn VARFSEG; // cfg enabled diff --git a/src/Kconfig b/src/Kconfig index 3a8ffa15fded..7c8104f01718 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -478,6 +478,13 @@ menu "BIOS interfaces" help Provide TPM support along with TCG BIOS extensions
+ config DEFAULT_GUEST_HINT + int "tweak default config for 32-bit or 64-bit guests" + default 32 + help + Optimize memory layout (specifically the placement + of pci bars) for 32-bit or 64-bit guests. + endmenu
menu "BIOS Tables"
Add runtime fwcfg override for the guest hint. Usage: qemu -fw_cfg name=etc/guest-hint,string=32
Signed-off-by: Gerd Hoffmann kraxel@redhat.com --- src/fw/paravirt.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 001be7caf102..25b37647d299 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -720,6 +720,13 @@ void qemu_cfg_init(void) dprintf(1, "Moving pm_base to 0x%x\n", acpi_pm_base); }
+ // guest hint + char *hint = romfile_loadfile("etc/guest-hint", NULL); + if (hint && strcmp(hint, "32") == 0) + GuestHint = 32; + if (hint && strcmp(hint, "64") == 0) + GuestHint = 64; + // serial console u16 nogfx = 0; qemu_cfg_read_entry(&nogfx, QEMU_CFG_NOGRAPHIC, sizeof(nogfx));
On Fri, Nov 15, 2024 at 12:40:06PM +0100, Gerd Hoffmann wrote:
This series adds an option to set the memory layout preference, both at compile time (via kconfig) and runtime (via fwcfg).
Gerd Hoffmann (4): add guest hint variable use guest hint as additional condition add guest hint default kconfig add guest hint fw_cfg override
Thanks. For what it is worth, I think it would be preferable to have a more specific variable name, such as "etc/pci-pad-64bit-mappings" and make the implementation specific to the pciinit.c code. I fear a generic name like "GuestHint" will be opaque to users and future developers, and possibly encourage complicated heuristics.
It might also be nice to support forcing the option in both directions - for example: 0 - use default heuristic, 1 - avoid 64bit padding, 2 - force 64bit padding.
I'd also avoid adding a Kconfig setting for this - we don't use Kconfig for any other defaults and I think it will be unwieldly to try to use Kconfig in that role.
Cheers, -Kevin