qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/28] x86: Improve operation under QEMU
@ 2025-02-16 20:43 Simon Glass
  2025-02-16 20:43 ` [PATCH v2 02/28] x86: qemu: Switch to bochs display Simon Glass
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Simon Glass @ 2025-02-16 20:43 UTC (permalink / raw)
  To: U-Boot Mailing List
  Cc: Bin Meng, Simon Glass, Andrew Goodbody, Andy Shevchenko,
	Angelo Dureghello, Love Kumar, Mattijs Korpershoek,
	Philip Oberfichtner, Stephen Warren, Stephen Warren, Tom Rini,
	qemu-devel

U-Boot can start and boot an OS in both qemu-x86 and qemu-x86_64 but it
is not perfect.

With both builds, executing the VESA ROM causes an intermittent hang, at
least on some AMD CPUs.

With qemu-x86_64 kvm cannot be used since the move to long mode (64-bit)
is done in a way that works on real hardware but not with QEMU. This
means that performance is 4-5x slower than it could be, at least on my
CPU.

We can work around the first problem by using Bochs, which is anyway a
better choice than VESA for QEMU. The second can be addressed by using
the same descriptor across the jump to long mode.

With an MTRR fix this allows booting into Ubuntu on qemu-x86_64

Changes in v2:
- Redo commit message
- Add new patch to rename the _D dirty flag
- Add new patch to support CPU functions in long mode
- Add new patch to tidy up address size in MTRR calculations
- Add new patch with a 64-bit version of is_power_of_2()
- Add new patch to set an MTRR for the RAM in QEMU
- Add new patch with a helper to send characters
- Add new patch to allow tests to be filtered by role
- Add more patches to support booting with kvm
- Add new patch with a test for booting Ubuntu 24.04

Simon Glass (28):
  x86: Expand x86_64 early memory
  x86: qemu: Switch to bochs display
  x86: qemu: Enable dhrystone
  x86: qemu: Avoid accessing BSS too early
  x86: Drop mpspec from the SPL build
  x86: Add some log categories
  x86: Drop use of CONFIG_REALMODE_DEBUG
  x86: Avoid clearing the VESA display
  x86: Add 64-bit entries to the GDT
  x86: Use defines for the cache flags
  x86: spl: Drop duplicate CPU init
  x86: Drop the message about features missing in 64-bit
  x86: Include stdbool.h in interrupt header
  x86: Tidy up the GDT size in start/16.S
  x86: Disable paging before changing to long mode
  x86: Use the same GDT when jumping to long mode
  x86: Use a simple jump into long mode
  x86: Rename the _D dirty flag
  x86: Support CPU functions in long mode
  x86: Tidy up address size in MTRR calculations
  Add a 64-bit version of is_power_of_2()
  x86: Support MTRRs of 4GB on 32-bit machines
  x86: emulation: Set an MTRR for the RAM
  scripts: Expand a few options
  test/py: Add a helper to send characters
  test/py: Allow tests to be filtered by role
  RFC: test/py: Deal with timeouts
  test: Add a test for booting Ubuntu 24.04

 .gitlab-ci.yml                   |  5 +++
 arch/x86/cpu/cpu.c               | 24 +++++++++++++++
 arch/x86/cpu/i386/call64.S       | 35 +++++++++------------
 arch/x86/cpu/i386/cpu.c          | 41 +++++++++---------------
 arch/x86/cpu/mtrr.c              | 12 +++++---
 arch/x86/cpu/qemu/dram.c         | 15 +++++++++
 arch/x86/cpu/qemu/qemu.c         | 20 ++++++++----
 arch/x86/cpu/start.S             |  4 ++-
 arch/x86/cpu/start16.S           |  3 +-
 arch/x86/cpu/x86_64/cpu.c        |  5 ---
 arch/x86/include/asm/cpu.h       | 35 ++++++++++++++++++---
 arch/x86/include/asm/interrupt.h |  1 +
 arch/x86/include/asm/processor.h |  5 ++-
 arch/x86/lib/Makefile            |  2 ++
 arch/x86/lib/bios.c              | 27 +++++++++-------
 arch/x86/lib/bios_interrupts.c   |  8 ++---
 arch/x86/lib/i8259.c             |  2 ++
 arch/x86/lib/spl.c               |  4 +--
 configs/qemu-x86_64_defconfig    | 10 +++---
 configs/qemu-x86_defconfig       |  6 ++--
 include/linux/log2.h             |  6 ++++
 scripts/build-qemu.sh            |  4 +--
 test/py/conftest.py              | 22 +++++++++++++
 test/py/console_base.py          | 33 ++++++++++++--------
 test/py/pytest.ini               |  1 +
 test/py/tests/test_distro.py     | 53 ++++++++++++++++++++++++++++++++
 test/py/tests/test_sleep.py      |  1 +
 27 files changed, 273 insertions(+), 111 deletions(-)
 create mode 100644 test/py/tests/test_distro.py

-- 
2.43.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 02/28] x86: qemu: Switch to bochs display
  2025-02-16 20:43 [PATCH v2 00/28] x86: Improve operation under QEMU Simon Glass
@ 2025-02-16 20:43 ` Simon Glass
  2025-02-16 20:43 ` [PATCH v2 03/28] x86: qemu: Enable dhrystone Simon Glass
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Simon Glass @ 2025-02-16 20:43 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Bin Meng, Simon Glass, Tom Rini, qemu-devel

The vesa display is widely used on hardware, but it is a bit of a pain
with QEMU. It requires executing option ROMs, which either doesn't work
with kvm, or is difficult to do in a kvm/QEMU-friendly way.

THe bochs display is probably better anyway, so switch to that. It works
fine with kvm as it doesn't need an option ROM.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: https://source.denx.de/u-boot/custodians/u-boot-dm/-/issues/31
---

Changes in v2:
- Redo commit message

 configs/qemu-x86_64_defconfig | 5 ++---
 configs/qemu-x86_defconfig    | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/configs/qemu-x86_64_defconfig b/configs/qemu-x86_64_defconfig
index af275e8ce8f..ff2a192ee7d 100644
--- a/configs/qemu-x86_64_defconfig
+++ b/configs/qemu-x86_64_defconfig
@@ -83,9 +83,8 @@ CONFIG_SYS_NS16550_PORT_MAPPED=y
 CONFIG_SPI=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_CONSOLE_TRUETYPE=y
-CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
-CONFIG_FRAMEBUFFER_VESA_MODE_USER=y
-CONFIG_FRAMEBUFFER_VESA_MODE=0x144
+CONFIG_VIDEO_BOCHS=y
+# CONFIG_VIDEO_VESA is not set
 CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_SPL_VIDEO=y
 # CONFIG_SPL_USE_TINY_PRINTF is not set
diff --git a/configs/qemu-x86_defconfig b/configs/qemu-x86_defconfig
index 0b0e10c795f..ee5b150e062 100644
--- a/configs/qemu-x86_defconfig
+++ b/configs/qemu-x86_defconfig
@@ -62,9 +62,8 @@ CONFIG_SYS_NS16550_PORT_MAPPED=y
 CONFIG_SPI=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_CONSOLE_TRUETYPE=y
-CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
-CONFIG_FRAMEBUFFER_VESA_MODE_USER=y
-CONFIG_FRAMEBUFFER_VESA_MODE=0x144
+CONFIG_VIDEO_BOCHS=y
+# CONFIG_VIDEO_VESA is not set
 CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_GENERATE_ACPI_TABLE=y
 # CONFIG_GZIP is not set
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 03/28] x86: qemu: Enable dhrystone
  2025-02-16 20:43 [PATCH v2 00/28] x86: Improve operation under QEMU Simon Glass
  2025-02-16 20:43 ` [PATCH v2 02/28] x86: qemu: Switch to bochs display Simon Glass
@ 2025-02-16 20:43 ` Simon Glass
  2025-02-16 20:43 ` [PATCH v2 04/28] x86: qemu: Avoid accessing BSS too early Simon Glass
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Simon Glass @ 2025-02-16 20:43 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Bin Meng, Simon Glass, Tom Rini, qemu-devel

Provide the 'dhry' command, which helps to check that kvm is being used
properly with QEMU.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 configs/qemu-x86_64_defconfig | 1 +
 configs/qemu-x86_defconfig    | 1 +
 2 files changed, 2 insertions(+)

diff --git a/configs/qemu-x86_64_defconfig b/configs/qemu-x86_64_defconfig
index ff2a192ee7d..84b7dc8e99f 100644
--- a/configs/qemu-x86_64_defconfig
+++ b/configs/qemu-x86_64_defconfig
@@ -89,4 +89,5 @@ CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_SPL_VIDEO=y
 # CONFIG_SPL_USE_TINY_PRINTF is not set
 CONFIG_GENERATE_ACPI_TABLE=y
+CONFIG_CMD_DHRYSTONE=y
 # CONFIG_GZIP is not set
diff --git a/configs/qemu-x86_defconfig b/configs/qemu-x86_defconfig
index ee5b150e062..d52afa42955 100644
--- a/configs/qemu-x86_defconfig
+++ b/configs/qemu-x86_defconfig
@@ -66,4 +66,5 @@ CONFIG_VIDEO_BOCHS=y
 # CONFIG_VIDEO_VESA is not set
 CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_GENERATE_ACPI_TABLE=y
+CONFIG_CMD_DHRYSTONE=y
 # CONFIG_GZIP is not set
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 04/28] x86: qemu: Avoid accessing BSS too early
  2025-02-16 20:43 [PATCH v2 00/28] x86: Improve operation under QEMU Simon Glass
  2025-02-16 20:43 ` [PATCH v2 02/28] x86: qemu: Switch to bochs display Simon Glass
  2025-02-16 20:43 ` [PATCH v2 03/28] x86: qemu: Enable dhrystone Simon Glass
@ 2025-02-16 20:43 ` Simon Glass
  2025-02-16 21:13 ` [PATCH v2 00/28] x86: Improve operation under QEMU Paolo Bonzini
  2025-02-16 21:57 ` Tom Rini
  4 siblings, 0 replies; 9+ messages in thread
From: Simon Glass @ 2025-02-16 20:43 UTC (permalink / raw)
  To: U-Boot Mailing List
  Cc: Bin Meng, Simon Glass, Andy Shevchenko, Tom Rini, qemu-devel

BSS is placed in DRAM which is actually available early with QEMU. But
it is cleared by the init sequence, so values stored there are lost.

Move the system-type flag into a function, instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 arch/x86/cpu/qemu/qemu.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 563f63e2bc8..e846ccd44aa 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -15,14 +15,21 @@
 #include <asm/arch/qemu.h>
 #include <asm/u-boot-x86.h>
 
-static bool i440fx;
-
 #if CONFIG_IS_ENABLED(QFW_PIO)
 U_BOOT_DRVINFO(x86_qfw_pio) = {
 	.name = "qfw_pio",
 };
 #endif
 
+static bool is_i440fx(void)
+{
+	u16 device;
+
+	pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID, &device);
+
+	return device == PCI_DEVICE_ID_INTEL_82441;
+}
+
 static void enable_pm_piix(void)
 {
 	u8 en;
@@ -50,16 +57,17 @@ static void enable_pm_ich9(void)
 
 void qemu_chipset_init(void)
 {
-	u16 device, xbcs;
+	bool i440fx;
+	u16 xbcs;
 	int pam, i;
 
+	i440fx = is_i440fx();
+
 	/*
 	 * i440FX and Q35 chipset have different PAM register offset, but with
 	 * the same bitfield layout. Here we determine the offset based on its
 	 * PCI device ID.
 	 */
-	pci_read_config16(PCI_BDF(0, 0, 0), PCI_DEVICE_ID, &device);
-	i440fx = (device == PCI_DEVICE_ID_INTEL_82441);
 	pam = i440fx ? I440FX_PAM : Q35_PAM;
 
 	/*
@@ -123,7 +131,7 @@ int mp_determine_pci_dstirq(int bus, int dev, int func, int pirq)
 {
 	u8 irq;
 
-	if (i440fx) {
+	if (is_i440fx()) {
 		/*
 		 * Not like most x86 platforms, the PIRQ[A-D] on PIIX3 are not
 		 * connected to I/O APIC INTPIN#16-19. Instead they are routed
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 00/28] x86: Improve operation under QEMU
  2025-02-16 20:43 [PATCH v2 00/28] x86: Improve operation under QEMU Simon Glass
                   ` (2 preceding siblings ...)
  2025-02-16 20:43 ` [PATCH v2 04/28] x86: qemu: Avoid accessing BSS too early Simon Glass
@ 2025-02-16 21:13 ` Paolo Bonzini
  2025-02-17 13:16   ` Simon Glass
  2025-02-16 21:57 ` Tom Rini
  4 siblings, 1 reply; 9+ messages in thread
From: Paolo Bonzini @ 2025-02-16 21:13 UTC (permalink / raw)
  To: Simon Glass, U-Boot Mailing List
  Cc: Bin Meng, Andrew Goodbody, Andy Shevchenko, Angelo Dureghello,
	Love Kumar, Mattijs Korpershoek, Philip Oberfichtner,
	Stephen Warren, Stephen Warren, qemu-devel, Tom Rini

On 2/16/25 21:43, Simon Glass wrote:
> U-Boot can start and boot an OS in both qemu-x86 and qemu-x86_64 but it
> is not perfect.
> 
> With both builds, executing the VESA ROM causes an intermittent hang, at
> least on some AMD CPUs.
> 
> With qemu-x86_64 kvm cannot be used since the move to long mode (64-bit)
> is done in a way that works on real hardware but not with QEMU. This
> means that performance is 4-5x slower than it could be, at least on my
> CPU.

Do you have a reproducer for this?  It shouldn't happen... also, do you 
know if this is broken for both Intel and AMD CPUs?

Thanks,

Paolo

> We can work around the first problem by using Bochs, which is anyway a
> better choice than VESA for QEMU. The second can be addressed by using
> the same descriptor across the jump to long mode.
> 
> With an MTRR fix this allows booting into Ubuntu on qemu-x86_64
> 
> Changes in v2:
> - Redo commit message
> - Add new patch to rename the _D dirty flag
> - Add new patch to support CPU functions in long mode
> - Add new patch to tidy up address size in MTRR calculations
> - Add new patch with a 64-bit version of is_power_of_2()
> - Add new patch to set an MTRR for the RAM in QEMU
> - Add new patch with a helper to send characters
> - Add new patch to allow tests to be filtered by role
> - Add more patches to support booting with kvm
> - Add new patch with a test for booting Ubuntu 24.04
> 
> Simon Glass (28):
>    x86: Expand x86_64 early memory
>    x86: qemu: Switch to bochs display
>    x86: qemu: Enable dhrystone
>    x86: qemu: Avoid accessing BSS too early
>    x86: Drop mpspec from the SPL build
>    x86: Add some log categories
>    x86: Drop use of CONFIG_REALMODE_DEBUG
>    x86: Avoid clearing the VESA display
>    x86: Add 64-bit entries to the GDT
>    x86: Use defines for the cache flags
>    x86: spl: Drop duplicate CPU init
>    x86: Drop the message about features missing in 64-bit
>    x86: Include stdbool.h in interrupt header
>    x86: Tidy up the GDT size in start/16.S
>    x86: Disable paging before changing to long mode
>    x86: Use the same GDT when jumping to long mode
>    x86: Use a simple jump into long mode
>    x86: Rename the _D dirty flag
>    x86: Support CPU functions in long mode
>    x86: Tidy up address size in MTRR calculations
>    Add a 64-bit version of is_power_of_2()
>    x86: Support MTRRs of 4GB on 32-bit machines
>    x86: emulation: Set an MTRR for the RAM
>    scripts: Expand a few options
>    test/py: Add a helper to send characters
>    test/py: Allow tests to be filtered by role
>    RFC: test/py: Deal with timeouts
>    test: Add a test for booting Ubuntu 24.04
> 
>   .gitlab-ci.yml                   |  5 +++
>   arch/x86/cpu/cpu.c               | 24 +++++++++++++++
>   arch/x86/cpu/i386/call64.S       | 35 +++++++++------------
>   arch/x86/cpu/i386/cpu.c          | 41 +++++++++---------------
>   arch/x86/cpu/mtrr.c              | 12 +++++---
>   arch/x86/cpu/qemu/dram.c         | 15 +++++++++
>   arch/x86/cpu/qemu/qemu.c         | 20 ++++++++----
>   arch/x86/cpu/start.S             |  4 ++-
>   arch/x86/cpu/start16.S           |  3 +-
>   arch/x86/cpu/x86_64/cpu.c        |  5 ---
>   arch/x86/include/asm/cpu.h       | 35 ++++++++++++++++++---
>   arch/x86/include/asm/interrupt.h |  1 +
>   arch/x86/include/asm/processor.h |  5 ++-
>   arch/x86/lib/Makefile            |  2 ++
>   arch/x86/lib/bios.c              | 27 +++++++++-------
>   arch/x86/lib/bios_interrupts.c   |  8 ++---
>   arch/x86/lib/i8259.c             |  2 ++
>   arch/x86/lib/spl.c               |  4 +--
>   configs/qemu-x86_64_defconfig    | 10 +++---
>   configs/qemu-x86_defconfig       |  6 ++--
>   include/linux/log2.h             |  6 ++++
>   scripts/build-qemu.sh            |  4 +--
>   test/py/conftest.py              | 22 +++++++++++++
>   test/py/console_base.py          | 33 ++++++++++++--------
>   test/py/pytest.ini               |  1 +
>   test/py/tests/test_distro.py     | 53 ++++++++++++++++++++++++++++++++
>   test/py/tests/test_sleep.py      |  1 +
>   27 files changed, 273 insertions(+), 111 deletions(-)
>   create mode 100644 test/py/tests/test_distro.py
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 00/28] x86: Improve operation under QEMU
  2025-02-16 20:43 [PATCH v2 00/28] x86: Improve operation under QEMU Simon Glass
                   ` (3 preceding siblings ...)
  2025-02-16 21:13 ` [PATCH v2 00/28] x86: Improve operation under QEMU Paolo Bonzini
@ 2025-02-16 21:57 ` Tom Rini
  2025-02-17 13:14   ` Simon Glass
  4 siblings, 1 reply; 9+ messages in thread
From: Tom Rini @ 2025-02-16 21:57 UTC (permalink / raw)
  To: Simon Glass
  Cc: U-Boot Mailing List, Bin Meng, Andrew Goodbody, Andy Shevchenko,
	Angelo Dureghello, Love Kumar, Mattijs Korpershoek,
	Philip Oberfichtner, Stephen Warren, Stephen Warren, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 834 bytes --]

On Sun, Feb 16, 2025 at 01:43:45PM -0700, Simon Glass wrote:

> U-Boot can start and boot an OS in both qemu-x86 and qemu-x86_64 but it
> is not perfect.
> 
> With both builds, executing the VESA ROM causes an intermittent hang, at
> least on some AMD CPUs.
> 
> With qemu-x86_64 kvm cannot be used since the move to long mode (64-bit)
> is done in a way that works on real hardware but not with QEMU. This
> means that performance is 4-5x slower than it could be, at least on my
> CPU.
> 
> We can work around the first problem by using Bochs, which is anyway a
> better choice than VESA for QEMU. The second can be addressed by using
> the same descriptor across the jump to long mode.
> 
> With an MTRR fix this allows booting into Ubuntu on qemu-x86_64

This seems needlessly not against mainline.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 00/28] x86: Improve operation under QEMU
  2025-02-16 21:57 ` Tom Rini
@ 2025-02-17 13:14   ` Simon Glass
  2025-02-17 14:05     ` Tom Rini
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Glass @ 2025-02-17 13:14 UTC (permalink / raw)
  To: Tom Rini
  Cc: U-Boot Mailing List, Bin Meng, Andrew Goodbody, Andy Shevchenko,
	Angelo Dureghello, Love Kumar, Mattijs Korpershoek,
	Philip Oberfichtner, Stephen Warren, Stephen Warren, qemu-devel

Hi Tom,

On Sun, 16 Feb 2025 at 14:57, Tom Rini <trini@konsulko.com> wrote:
>
> On Sun, Feb 16, 2025 at 01:43:45PM -0700, Simon Glass wrote:
>
> > U-Boot can start and boot an OS in both qemu-x86 and qemu-x86_64 but it
> > is not perfect.
> >
> > With both builds, executing the VESA ROM causes an intermittent hang, at
> > least on some AMD CPUs.
> >
> > With qemu-x86_64 kvm cannot be used since the move to long mode (64-bit)
> > is done in a way that works on real hardware but not with QEMU. This
> > means that performance is 4-5x slower than it could be, at least on my
> > CPU.
> >
> > We can work around the first problem by using Bochs, which is anyway a
> > better choice than VESA for QEMU. The second can be addressed by using
> > the same descriptor across the jump to long mode.
> >
> > With an MTRR fix this allows booting into Ubuntu on qemu-x86_64
>
> This seems needlessly not against mainline.

I just tried it and yes there is a very small delta. I can resend it
rebased to -next if you like. I'd really like to get some OS-booting
tests into CI.

Regards,
Simon


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 00/28] x86: Improve operation under QEMU
  2025-02-16 21:13 ` [PATCH v2 00/28] x86: Improve operation under QEMU Paolo Bonzini
@ 2025-02-17 13:16   ` Simon Glass
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Glass @ 2025-02-17 13:16 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: U-Boot Mailing List, Bin Meng, Andrew Goodbody, Andy Shevchenko,
	Angelo Dureghello, Love Kumar, Mattijs Korpershoek,
	Philip Oberfichtner, Stephen Warren, Stephen Warren, qemu-devel,
	Tom Rini

Hi Paolo,

On Sun, 16 Feb 2025 at 14:14, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 2/16/25 21:43, Simon Glass wrote:
> > U-Boot can start and boot an OS in both qemu-x86 and qemu-x86_64 but it
> > is not perfect.
> >
> > With both builds, executing the VESA ROM causes an intermittent hang, at
> > least on some AMD CPUs.
> >
> > With qemu-x86_64 kvm cannot be used since the move to long mode (64-bit)
> > is done in a way that works on real hardware but not with QEMU. This
> > means that performance is 4-5x slower than it could be, at least on my
> > CPU.
>
> Do you have a reproducer for this?  It shouldn't happen... also, do you
> know if this is broken for both Intel and AMD CPUs?

You can see this if you build the right commit (e52e307c7ca) from my
tree[1], i.e. after U-Boot changes to Bochs and before it changes the
64-bit entry mechanism:

04:57 $ pe
e52e307c7ca (HEAD) x86: qemu: Switch to bochs display
83f8b00df47 x86: Expand x86_64 early memory
71a6c3eb3d8 Revert "efi_memory: do not add U-Boot memory to the memory map"
d9d87e11e97 test: Make net tests depend on CONFIG_CMD_NET
3c67e62b109 test/py: Show info about module-loading
7059d976d22 test/py: Drop assigning ubman to cons
e361abfc638 test/py: Drop importing utils as util
460ecb6e5cd test/py: Drop u_boot_ prefix on test files
cc5600e734c test/py: Shorten u_boot_console
777c7a0c20e test: Update documentation
✔ ~/u [:e52e307c7ca|…6⚑ 1160]
04:57 $ ./tools/buildman/buildman --bo qemu-x86_64 -o /tmp/b/qemu-x86_64/ -w
Building current source for 1 boards (1 thread, 32 jobs per thread)
    1    0    0 /1              qemu-x86_64
Completed: 1 total built, 1 newly), duration 0:00:02, rate 0.50
✔ ~/u [:e52e307c7ca|…6⚑ 1160]
04:57 $ qemu-system-x86_64 -bios /tmp/b/qemu-x86_64/u-boot.rom
-enable-kvm    -nographic
Running qemu-system-x86_64  -display none -serial mon:stdio

U-Boot SPL 2025.01-rc3-00635-ge52e307c7ca8 (Feb 17 2025 - 04:57:59 -0700)
Trying to boot from SPI
Jumping to 64-bit U-Boot: Note many features are missing
(hangs here)
QEMU: Terminated

I am running this on an AMD system. But I just tried it on an Intel
laptop and it has the same issue.
>
> Thanks,
>
> Paolo
>
Regards,
Simon

> > We can work around the first problem by using Bochs, which is anyway a
> > better choice than VESA for QEMU. The second can be addressed by using
> > the same descriptor across the jump to long mode.
> >
> > With an MTRR fix this allows booting into Ubuntu on qemu-x86_64
> >
> > Changes in v2:
> > - Redo commit message
> > - Add new patch to rename the _D dirty flag
> > - Add new patch to support CPU functions in long mode
> > - Add new patch to tidy up address size in MTRR calculations
> > - Add new patch with a 64-bit version of is_power_of_2()
> > - Add new patch to set an MTRR for the RAM in QEMU
> > - Add new patch with a helper to send characters
> > - Add new patch to allow tests to be filtered by role
> > - Add more patches to support booting with kvm
> > - Add new patch with a test for booting Ubuntu 24.04
> >
> > Simon Glass (28):
> >    x86: Expand x86_64 early memory
> >    x86: qemu: Switch to bochs display
> >    x86: qemu: Enable dhrystone
> >    x86: qemu: Avoid accessing BSS too early
> >    x86: Drop mpspec from the SPL build
> >    x86: Add some log categories
> >    x86: Drop use of CONFIG_REALMODE_DEBUG
> >    x86: Avoid clearing the VESA display
> >    x86: Add 64-bit entries to the GDT
> >    x86: Use defines for the cache flags
> >    x86: spl: Drop duplicate CPU init
> >    x86: Drop the message about features missing in 64-bit
> >    x86: Include stdbool.h in interrupt header
> >    x86: Tidy up the GDT size in start/16.S
> >    x86: Disable paging before changing to long mode
> >    x86: Use the same GDT when jumping to long mode
> >    x86: Use a simple jump into long mode
> >    x86: Rename the _D dirty flag
> >    x86: Support CPU functions in long mode
> >    x86: Tidy up address size in MTRR calculations
> >    Add a 64-bit version of is_power_of_2()
> >    x86: Support MTRRs of 4GB on 32-bit machines
> >    x86: emulation: Set an MTRR for the RAM
> >    scripts: Expand a few options
> >    test/py: Add a helper to send characters
> >    test/py: Allow tests to be filtered by role
> >    RFC: test/py: Deal with timeouts
> >    test: Add a test for booting Ubuntu 24.04
> >
> >   .gitlab-ci.yml                   |  5 +++
> >   arch/x86/cpu/cpu.c               | 24 +++++++++++++++
> >   arch/x86/cpu/i386/call64.S       | 35 +++++++++------------
> >   arch/x86/cpu/i386/cpu.c          | 41 +++++++++---------------
> >   arch/x86/cpu/mtrr.c              | 12 +++++---
> >   arch/x86/cpu/qemu/dram.c         | 15 +++++++++
> >   arch/x86/cpu/qemu/qemu.c         | 20 ++++++++----
> >   arch/x86/cpu/start.S             |  4 ++-
> >   arch/x86/cpu/start16.S           |  3 +-
> >   arch/x86/cpu/x86_64/cpu.c        |  5 ---
> >   arch/x86/include/asm/cpu.h       | 35 ++++++++++++++++++---
> >   arch/x86/include/asm/interrupt.h |  1 +
> >   arch/x86/include/asm/processor.h |  5 ++-
> >   arch/x86/lib/Makefile            |  2 ++
> >   arch/x86/lib/bios.c              | 27 +++++++++-------
> >   arch/x86/lib/bios_interrupts.c   |  8 ++---
> >   arch/x86/lib/i8259.c             |  2 ++
> >   arch/x86/lib/spl.c               |  4 +--
> >   configs/qemu-x86_64_defconfig    | 10 +++---
> >   configs/qemu-x86_defconfig       |  6 ++--
> >   include/linux/log2.h             |  6 ++++
> >   scripts/build-qemu.sh            |  4 +--
> >   test/py/conftest.py              | 22 +++++++++++++
> >   test/py/console_base.py          | 33 ++++++++++++--------
> >   test/py/pytest.ini               |  1 +
> >   test/py/tests/test_distro.py     | 53 ++++++++++++++++++++++++++++++++
> >   test/py/tests/test_sleep.py      |  1 +
> >   27 files changed, 273 insertions(+), 111 deletions(-)
> >   create mode 100644 test/py/tests/test_distro.py
> >
>

[1] https://ci.u-boot.org/u-boot/u-boot/-/commits/qemu?ref_type=heads


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 00/28] x86: Improve operation under QEMU
  2025-02-17 13:14   ` Simon Glass
@ 2025-02-17 14:05     ` Tom Rini
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Rini @ 2025-02-17 14:05 UTC (permalink / raw)
  To: Simon Glass
  Cc: U-Boot Mailing List, Bin Meng, Andrew Goodbody, Andy Shevchenko,
	Angelo Dureghello, Love Kumar, Mattijs Korpershoek,
	Philip Oberfichtner, Stephen Warren, Stephen Warren, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1606 bytes --]

On Mon, Feb 17, 2025 at 06:14:12AM -0700, Simon Glass wrote:
> Hi Tom,
> 
> On Sun, 16 Feb 2025 at 14:57, Tom Rini <trini@konsulko.com> wrote:
> >
> > On Sun, Feb 16, 2025 at 01:43:45PM -0700, Simon Glass wrote:
> >
> > > U-Boot can start and boot an OS in both qemu-x86 and qemu-x86_64 but it
> > > is not perfect.
> > >
> > > With both builds, executing the VESA ROM causes an intermittent hang, at
> > > least on some AMD CPUs.
> > >
> > > With qemu-x86_64 kvm cannot be used since the move to long mode (64-bit)
> > > is done in a way that works on real hardware but not with QEMU. This
> > > means that performance is 4-5x slower than it could be, at least on my
> > > CPU.
> > >
> > > We can work around the first problem by using Bochs, which is anyway a
> > > better choice than VESA for QEMU. The second can be addressed by using
> > > the same descriptor across the jump to long mode.
> > >
> > > With an MTRR fix this allows booting into Ubuntu on qemu-x86_64
> >
> > This seems needlessly not against mainline.
> 
> I just tried it and yes there is a very small delta. I can resend it
> rebased to -next if you like. I'd really like to get some OS-booting
> tests into CI.

Sure, and please start pushing scripts to u-boot-extras. Having these
scripts in u-boot itself explicitly makes it harder to use them for
debug as you now rely on them being within the tree with the changes you
want on whatever older commit you want. And since you want to move these
to Python too you that also means language updates need to be in there
as well. Thanks.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-02-17 14:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-16 20:43 [PATCH v2 00/28] x86: Improve operation under QEMU Simon Glass
2025-02-16 20:43 ` [PATCH v2 02/28] x86: qemu: Switch to bochs display Simon Glass
2025-02-16 20:43 ` [PATCH v2 03/28] x86: qemu: Enable dhrystone Simon Glass
2025-02-16 20:43 ` [PATCH v2 04/28] x86: qemu: Avoid accessing BSS too early Simon Glass
2025-02-16 21:13 ` [PATCH v2 00/28] x86: Improve operation under QEMU Paolo Bonzini
2025-02-17 13:16   ` Simon Glass
2025-02-16 21:57 ` Tom Rini
2025-02-17 13:14   ` Simon Glass
2025-02-17 14:05     ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).