Skip to contentSkip to conversation

x86/hvm: fix reading from 0xe9 IO port if port E9 hack is active

PATCH In review Roger Pau Monne 4 participants 9 messages Oct 2, 2025 – Oct 3, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: fix reading from 0xe9 IO port if port E9 hack is active

Reading from the E9 port if the emergency console is active should return 0xe9 according to the documentation from Bochs:

https://bochs.sourceforge.io/doc/docbook/user/bochsrc.html

See port_e9_hack section description.

Fix Xen so it also returns the port address. OSes can use it to detect whether the emergency console is available or not.

Fixes d1bd157fbc9b ("Big merge the HVM full-virtualisation abstractions.")
---
 xen/arch/x86/hvm/hvm.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/hvm.c +9 -3
index 23bd7f078a1d..0c60faa39d7b 100644
@@ -567,9 +567,15 @@ static int cf_check hvm_print_line(
 
     ASSERT(bytes == 1 && port == XEN_HVM_DEBUGCONS_IOPORT);
 
-    /* Deny any input requests. */
-    if ( dir != IOREQ_WRITE )
-        return X86EMUL_UNHANDLEABLE;
+    if ( dir == IOREQ_READ )
+    {
+        /*
+         * According to Bochs documentation, reading from the E9 port should
+         * return 0xE9 if the "port E9 hack" is implemented.
+         */
+        *val = XEN_HVM_DEBUGCONS_IOPORT;
+        return X86EMUL_OKAY;
+    }
 
     if ( !is_console_printable(c) )
         return X86EMUL_OKAY;
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Roger Pau Monne

Reading from the E9 port if the emergency console is active should return 0xe9 according to the documentation from Bochs:

https://bochs.sourceforge.io/doc/docbook/user/bochsrc.html

Quoted 7 lines

See port_e9_hack section description.

Fix Xen so it also returns the port address. OSes can use it to detect whether the emergency console is available or not.

Fixes d1bd157fbc9b ("Big merge the HVM full-virtualisation abstractions.")

That's been wrong for rather a long time.  How did you find it?

CC-ing Oleksii as you've tagged this for 4.21.

Quoted 27 lines
---
 xen/arch/x86/hvm/hvm.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/hvm.c +9 -3
index 23bd7f078a1d..0c60faa39d7b 100644
@@ -567,9 +567,15 @@ static int cf_check hvm_print_line(
 
     ASSERT(bytes == 1 && port == XEN_HVM_DEBUGCONS_IOPORT);
 
-    /* Deny any input requests. */
-    if ( dir != IOREQ_WRITE )
-        return X86EMUL_UNHANDLEABLE;
+    if ( dir == IOREQ_READ )
+    {
+        /*
+         * According to Bochs documentation, reading from the E9 port should
+         * return 0xE9 if the "port E9 hack" is implemented.
+         */
+        *val = XEN_HVM_DEBUGCONS_IOPORT;
+        return X86EMUL_OKAY;
+    }
 
     if ( !is_console_printable(c) )
         return X86EMUL_OKAY;
#2 lore raw
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Roger Pau Monne

Reading from the E9 port if the emergency console is active should return 0xe9 according to the documentation from Bochs:

https://bochs.sourceforge.io/doc/docbook/user/bochsrc.html

See port_e9_hack section description.

Fix Xen so it also returns the port address. OSes can use it to detect whether the emergency console is available or not.

Quoted 6 lines
Quoted 2 lines
Fixes d1bd157fbc9b ("Big merge the HVM full-virtualisation abstractions.")

That's been wrong for rather a long time.  How did you find it?

I came across the documentation above and I didn't remember Xen returning any value for reads, which sadly was indeed true.

This was because I had the intention to suggest Alejandro to (also?) use the port 0xe9 hack for printing from XTF, which should work for both Xen and QEMU.

Quoted 1 line

CC-ing Oleksii as you've tagged this for 4.21.

I was told that bugfixes didn't need a release-ack until hard code freeze, which is the 31st of October?

Thanks, Roger.

#3 lore raw
Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Andrew Cooper
Quoted 5 lines · Roger Pau Monne

Reading from the E9 port if the emergency console is active should return 0xe9 according to the documentation from Bochs:

https://bochs.sourceforge.io/doc/docbook/user/bochsrc.html

Quoted 7 lines

See port_e9_hack section description.

Fix Xen so it also returns the port address. OSes can use it to detect whether the emergency console is available or not.

Fixes d1bd157fbc9b ("Big merge the HVM full-virtualisation abstractions.")
Quoted 8 lines
Quoted 1 line

That's been wrong for rather a long time.  How did you find it?

I came across the documentation above and I didn't remember Xen returning any value for reads, which sadly was indeed true.

This was because I had the intention to suggest Alejandro to (also?) use the port 0xe9 hack for printing from XTF, which should work for both Xen and QEMU.

QEMU doesn't support 0xE9 though?

Cheers,
Alejandro

#4 lore raw
Quoted 20 lines · Alejandro Vallejo
Quoted 19 lines · Roger Pau Monné
Quoted 17 lines · Andrew Cooper
Quoted 5 lines · Roger Pau Monne

Reading from the E9 port if the emergency console is active should return 0xe9 according to the documentation from Bochs:

https://bochs.sourceforge.io/doc/docbook/user/bochsrc.html

Quoted 7 lines

See port_e9_hack section description.

Fix Xen so it also returns the port address. OSes can use it to detect whether the emergency console is available or not.

Fixes d1bd157fbc9b ("Big merge the HVM full-virtualisation abstractions.")

That's been wrong for rather a long time.  How did you find it?

Quoted 8 lines
Quoted 6 lines

I came across the documentation above and I didn't remember Xen returning any value for reads, which sadly was indeed true.

This was because I had the intention to suggest Alejandro to (also?) use the port 0xe9 hack for printing from XTF, which should work for both Xen and QEMU.

QEMU doesn't support 0xE9 though?

AFAICT it does:

https://wiki.osdev.org/QEMU#The_debug_console

However when running QEMU on Xen as a device model writes to 0xe9 are handled in the hypervisor, and never forwarded to any device model.

Regards, Roger.

#5 lore raw
Quoted 30 lines · Roger Pau Monné
Quoted 20 lines · Alejandro Vallejo
Quoted 19 lines · Roger Pau Monné
Quoted 17 lines · Andrew Cooper
Quoted 5 lines · Roger Pau Monne

Reading from the E9 port if the emergency console is active should return 0xe9 according to the documentation from Bochs:

https://bochs.sourceforge.io/doc/docbook/user/bochsrc.html

Quoted 7 lines

See port_e9_hack section description.

Fix Xen so it also returns the port address. OSes can use it to detect whether the emergency console is available or not.

Fixes d1bd157fbc9b ("Big merge the HVM full-virtualisation abstractions.")

That's been wrong for rather a long time.  How did you find it?

Quoted 8 lines
Quoted 6 lines

I came across the documentation above and I didn't remember Xen returning any value for reads, which sadly was indeed true.

This was because I had the intention to suggest Alejandro to (also?) use the port 0xe9 hack for printing from XTF, which should work for both Xen and QEMU.

QEMU doesn't support 0xE9 though?

Quoted 8 lines

AFAICT it does:

https://wiki.osdev.org/QEMU#The_debug_console

However when running QEMU on Xen as a device model writes to 0xe9 are handled in the hypervisor, and never forwarded to any device model.

Regards, Roger.

The more you know. I searched for it once upon a time and couldn't find it. Thanks for the pointer.

Regardless, "-debugcon stdio" is functionally equivalent to "-serial stdio" and the latter can be adapted to work on real hardware too.

Cheers,
Alejandro

#6 lore raw
Quoted 38 lines · Alejandro Vallejo
Quoted 37 lines · Roger Pau Monné
Quoted 20 lines · Alejandro Vallejo
Quoted 19 lines · Roger Pau Monné
Quoted 17 lines · Andrew Cooper
Quoted 5 lines · Roger Pau Monne

Reading from the E9 port if the emergency console is active should return 0xe9 according to the documentation from Bochs:

https://bochs.sourceforge.io/doc/docbook/user/bochsrc.html

Quoted 7 lines

See port_e9_hack section description.

Fix Xen so it also returns the port address. OSes can use it to detect whether the emergency console is available or not.

Fixes d1bd157fbc9b ("Big merge the HVM full-virtualisation abstractions.")

That's been wrong for rather a long time.  How did you find it?

Quoted 8 lines
Quoted 6 lines

I came across the documentation above and I didn't remember Xen returning any value for reads, which sadly was indeed true.

This was because I had the intention to suggest Alejandro to (also?) use the port 0xe9 hack for printing from XTF, which should work for both Xen and QEMU.

QEMU doesn't support 0xE9 though?

AFAICT it does:

https://wiki.osdev.org/QEMU#The_debug_console

However when running QEMU on Xen as a device model writes to 0xe9 are handled in the hypervisor, and never forwarded to any device model.

Quoted 7 lines
Quoted 1 line

Regards, Roger.

The more you know. I searched for it once upon a time and couldn't find it. Thanks for the pointer.

Regardless, "-debugcon stdio" is functionally equivalent to "-serial stdio" and the latter can be adapted to work on real hardware too.

The emulated serial is possibly equivalent to the 0xe9 hack in QEMU, as I expect the serial is mostly setup to "just work". On native you likely need to configure the baud rate &c, plus implement flow control?

Is there any testing XTF should do to ensure the serial is there, before blindly writing at 0x3f8?

Thanks, Roger.

#7 lore raw
Quoted 44 lines · Roger Pau Monné
Quoted 43 lines · Alejandro Vallejo
Quoted 30 lines · Roger Pau Monné
Quoted 20 lines · Alejandro Vallejo
Quoted 19 lines · Roger Pau Monné
Quoted 17 lines · Andrew Cooper
Quoted 5 lines · Roger Pau Monne

Reading from the E9 port if the emergency console is active should return 0xe9 according to the documentation from Bochs:

https://bochs.sourceforge.io/doc/docbook/user/bochsrc.html

Quoted 7 lines

See port_e9_hack section description.

Fix Xen so it also returns the port address. OSes can use it to detect whether the emergency console is available or not.

Fixes d1bd157fbc9b ("Big merge the HVM full-virtualisation abstractions.")

That's been wrong for rather a long time.  How did you find it?

Quoted 8 lines
Quoted 6 lines

I came across the documentation above and I didn't remember Xen returning any value for reads, which sadly was indeed true.

This was because I had the intention to suggest Alejandro to (also?) use the port 0xe9 hack for printing from XTF, which should work for both Xen and QEMU.

QEMU doesn't support 0xE9 though?

Quoted 8 lines

AFAICT it does:

https://wiki.osdev.org/QEMU#The_debug_console

However when running QEMU on Xen as a device model writes to 0xe9 are handled in the hypervisor, and never forwarded to any device model.

Regards, Roger.

The more you know. I searched for it once upon a time and couldn't find it. Thanks for the pointer.

Quoted 7 lines
Quoted 2 lines

Regardless, "-debugcon stdio" is functionally equivalent to "-serial stdio" and the latter can be adapted to work on real hardware too.

The emulated serial is possibly equivalent to the 0xe9 hack in QEMU, as I expect the serial is mostly setup to "just work". On native you likely need to configure the baud rate &c, plus implement flow control?

You'd need to boot XTF via GRUB (or similar), which would've pre-configured the serial port for you.

And baud rate, flow control and the like are ignored when emulated, so that's all fine.

Quoted 3 lines

Is there any testing XTF should do to ensure the serial is there, before blindly writing at 0x3f8?

Closest would be parsing the FADT for LEGACY_DEVICES being set, but if that was clear we'd be out of options because there's nothing else to write to. I don't intend to make XTF rock solid on real hardware, just "workable" on typical everyday devices/servers with GRUB's help.

FWIW Xen just assumes it's there if com1= is given in the cmdline AFAICS. The most likely case for COM1 not being there is on PV(H), which XTF already uses the PV console for.

Cheers,
Alejandro

#8 lore raw
In reply to Roger Pau Monné
Quoted 20 lines · Roger Pau Monné
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Roger Pau Monne

Reading from the E9 port if the emergency console is active should return 0xe9 according to the documentation from Bochs:

https://bochs.sourceforge.io/doc/docbook/user/bochsrc.html

See port_e9_hack section description.

Quoted 8 lines
Quoted 5 lines

Fix Xen so it also returns the port address. OSes can use it to detect whether the emergency console is available or not.

Fixes d1bd157fbc9b ("Big merge the HVM full-virtualisation abstractions.")

That's been wrong for rather a long time.  How did you find it?

I came across the documentation above and I didn't remember Xen returning any value for reads, which sadly was indeed true.

Quoted 7 lines

This was because I had the intention to suggest Alejandro to (also?) use the port 0xe9 hack for printing from XTF, which should work for both Xen and QEMU.

Quoted 1 line

CC-ing Oleksii as you've tagged this for 4.21.

I was told that bugfixes didn't need a release-ack until hard code freeze, which is the 31st of October?

I meant until the start of the hard code freeze, which is on October 4. So there is no need for a release-ack for this patch.

Thanks.

~ Oleksii