Skip to contentSkip to conversation

ns16550c: avoid crash in ns16550_endboot in PV shim mode

PATCH In review David Woodhouse 5 participants 12 messages Oct 19, 2023 – Oct 23, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ns16550c: avoid crash in ns16550_endboot in PV shim mode

From: David Woodhouse <[email protected]>

In shim mode there is no hardware_domain. Dereferencing the pointer doesn't end well.

---
This is about as far as I got in my abortive attempt to use the PV shim without an actual PV console being provided by the HVM hosting environment. It still doesn't pass the guest's console through to serial; that only seems to shim to an actual PV console.

 xen/drivers/char/ns16550.c | 2 ++
 1 file changed, 2 insertions(+)
xen/drivers/char/ns16550.c +2 -0
index 28ddedd50d..0818f5578c 100644
@@ -586,6 +586,8 @@ static void __init cf_check ns16550_endboot(struct serial_port *port)
 
     if ( uart->remapped_io_base )
         return;
+    if (!hardware_domain)
+        return;
     rv = ioports_deny_access(hardware_domain, uart->io_base, uart->io_base + 7);
     if ( rv != 0 )
         BUG();
Signature · 1 line
2.34.1
#1 lore raw

xen/drivers/char/ns16550.c static void __init cf_check ns16550_endboot(struct serial_port *port) · line 593

Quoted 11 lines · David Woodhouse
xen/drivers/char/ns16550.c +2 -0
@@ -586,6 +586,8 @@ static void __init cf_check ns16550_endboot(struct serial_port *port)
 
     if ( uart->remapped_io_base )
         return;
+    if (!hardware_domain)
+        return;
     rv = ioports_deny_access(hardware_domain, uart->io_base, uart->io_base + 7);
     if ( rv != 0 )
         BUG();

Considering this is the only use of hardware_domain in the driver, fixing it like this (with style adjusted) is certainly an option. I'd like to ask though whether it makes sense for execution to make it here in shim mode, where there's no serial port anyway (unless we start supporting pass-through [of possibly even non-PCI devices] for the shim). I wonder whether we wouldn't want to bypass ns16550_init() - likely as well as the EHCI and XHCI ones - instead, until (if ever) such passing through was actually deemed necessary to support.

Jan

#2 lore raw
In reply to David Woodhouse
Quoted 11 lines · David Woodhouse

From: David Woodhouse <[email protected]>

In shim mode there is no hardware_domain. Dereferencing the pointer doesn't end well.

---
This is about as far as I got in my abortive attempt to use the PV shim without an actual PV console being provided by the HVM hosting environment. It still doesn't pass the guest's console through to serial; that only seems to shim to an actual PV console.

There's no such thing as a Xen VM without a PV console.

And yes, this is an error, but that horse bolted 2 decades ago.

It would be nice if having a "real" serial didn't crash like this, but PV Shim is specialised to transplant one normal-looking PV guest, and the interposition logic is tied to the PV console.

~Andrew

#3 lore raw
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · David Woodhouse

From: David Woodhouse <[email protected]>

In shim mode there is no hardware_domain. Dereferencing the pointer doesn't end well.

Quoted 8 lines
Quoted 6 lines

---
This is about as far as I got in my abortive attempt to use the PV shim without an actual PV console being provided by the HVM hosting environment. It still doesn't pass the guest's console through to serial; that only seems to shim to an actual PV console.

There's no such thing as a Xen VM without a PV console.

Huh? There are literally millions of them. Every EC2 Xen HVM instance boots with a serial device but no Xen console. That's true of the ones running on true Xen, as well as the newer launches which are running on top of Linux/KVM.

We implemented Xen console support in the Nitro hypervisor, then had to disable it because it wasn't faithful to the production environment that guests previously experienced on Xen, and eventually ripped it out because it was dead code.

Likewise, upstream Qemu's Xen emulation mode doesn't currently have console support (although I did just add it to get the shim working).

Quoted 6 lines

And yes, this is an error, but that horse bolted 2 decades ago.

It would be nice if having a "real" serial didn't crash like this, but PV Shim is specialised to transplant one normal-looking PV guest, and the interposition logic is tied to the PV console.

That's a nicer model. When Spectre/Meltdown broke and we posted the 'Vixen' version of a shim, it actually implemented a console backend and would output to the serial port. But I do agree it's nicer not to.

Even with a PV console though, it might still be useful to have the shim's output going to a serial port while the guest's output goes to the console though, to keep them separate.

#4 lore raw
Quoted 7 lines · David Woodhouse
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · David Woodhouse

From: David Woodhouse <[email protected]>

In shim mode there is no hardware_domain. Dereferencing the pointer doesn't end well.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

---
This is about as far as I got in my abortive attempt to use the PV shim without an actual PV console being provided by the HVM hosting environment. It still doesn't pass the guest's console through to serial; that only seems to shim to an actual PV console.

There's no such thing as a Xen VM without a PV console.

Huh? There are literally millions of them.

I'm very prepared to believe there are millions which don't overtly malfunction when you don't fill in the HVM Params.

Which is very different from saying "there's a way in the Xen guest ABI to express 'you don't have a PV console' ".

~Andrew

#5 lore raw
Quoted 14 lines · Andrew Cooper
Quoted 13 lines · David Woodhouse
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · David Woodhouse

From: David Woodhouse <[email protected]>

In shim mode there is no hardware_domain. Dereferencing the pointer doesn't end well.

---
This is about as far as I got in my abortive attempt to use the PV shim without an actual PV console being provided by the HVM hosting environment. It still doesn't pass the guest's console through to serial; that only seems to shim to an actual PV console.

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

There's no such thing as a Xen VM without a PV console.

Huh? There are literally millions of them.

I'm very prepared to believe there are millions which don't overtly malfunction when you don't fill in the HVM Params.

Which is very different from saying "there's a way in the Xen guest ABI to express 'you don't have a PV console' ".

FWIW, Linux assumes that either the console page or the event channel being 0 implies no console available [0], so I guess that's the ABI now.

Roger.

[0] https://elixir.bootlin.com/linux/latest/source/drivers/tty/hvc/hvc_xen.c#L258

#6 lore raw
Quoted 21 lines · Roger Pau Monné
Quoted 20 lines · Andrew Cooper
Quoted 7 lines · David Woodhouse
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · David Woodhouse

From: David Woodhouse <[email protected]>

In shim mode there is no hardware_domain. Dereferencing the pointer doesn't end well.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

---
This is about as far as I got in my abortive attempt to use the PV shim without an actual PV console being provided by the HVM hosting environment. It still doesn't pass the guest's console through to serial; that only seems to shim to an actual PV console.

There's no such thing as a Xen VM without a PV console.

Huh? There are literally millions of them.

I'm very prepared to believe there are millions which don't overtly malfunction when you don't fill in the HVM Params.

Quoted 6 lines
Quoted 2 lines

Which is very different from saying "there's a way in the Xen guest ABI to express 'you don't have a PV console' ".

FWIW, Linux assumes that either the console page or the event channel being 0 implies no console available [0], so I guess that's the ABI now.

Or if the HVMOP_get_param call returns an error.

Quoted 3 lines

Roger.

[0] https://elixir.bootlin.com/linux/latest/source/drivers/tty/hvc/hvc_xen.c#L258

I'm not convinced I believe what the comment says there about evtchn 0 being theoretically valid. I don't believe zero is a valid evtchn#, is it?

#8 lore raw
Quoted 11 lines · Paul

On 20/10/2023 14:37, David Woodhouse wrote:
[snip]

Quoted 7 lines
Quoted 3 lines

[0]
https://elixir.bootlin.com/linux/latest/source/drivers/tty/hvc/hvc_xen.c#L258

I'm not convinced I believe what the comment says there about evtchn 0 being theoretically valid. I don't believe zero is a valid evtchn#, is it?

gfn 0 might be valid, but I'm also pretty sure evtchn 0 is not valid.

GFN 0 very much is valid.

evtchn 0 OTOH is explicitly not valid.  From evtchn_init():

    evtchn_from_port(d, 0)->state = ECS_RESERVED;

However, the fields being 0 doesn't mean not available.  That's the signal to saying "not connected yet", because that's what dom0 gets before xenconsoled starts up.

~Andrew

#9 lore raw
Quoted 15 lines · Andrew Cooper
Quoted 11 lines · Paul

On 20/10/2023 14:37, David Woodhouse wrote:
[snip]

Quoted 7 lines
Quoted 3 lines

[0]
https://elixir.bootlin.com/linux/latest/source/drivers/tty/hvc/hvc_xen.c#L258

I'm not convinced I believe what the comment says there about evtchn 0 being theoretically valid. I don't believe zero is a valid evtchn#, is it?

gfn 0 might be valid, but I'm also pretty sure evtchn 0 is not valid.

GFN 0 very much is valid.

Quoted 8 lines

evtchn 0 OTOH is explicitly not valid.  From evtchn_init():

    evtchn_from_port(d, 0)->state = ECS_RESERVED;

However, the fields being 0 doesn't mean not available.  That's the signal to saying "not connected yet", because that's what dom0 gets before xenconsoled starts up.

Someone asked me the same a while back, and IIRC we don't state anywhere in the public headers that event channel 0 is reserved, however that has always? been part of the implementation.

If we intend this to be reliable, we should add a define to the public headers in order to signal that 0 will always be reserved.

Roger.

#10 lore raw
Quoted 25 lines · Roger Pau Monné
Quoted 15 lines · Andrew Cooper
Quoted 11 lines · Paul

On 20/10/2023 14:37, David Woodhouse wrote:
[snip]

Quoted 7 lines
Quoted 3 lines

[0]
https://elixir.bootlin.com/linux/latest/source/drivers/tty/hvc/hvc_xen.c#L258

I'm not convinced I believe what the comment says there about evtchn 0 being theoretically valid. I don't believe zero is a valid evtchn#, is it?

gfn 0 might be valid, but I'm also pretty sure evtchn 0 is not valid.

GFN 0 very much is valid.

Quoted 8 lines

evtchn 0 OTOH is explicitly not valid.  From evtchn_init():

    evtchn_from_port(d, 0)->state = ECS_RESERVED;

However, the fields being 0 doesn't mean not available.  That's the signal to saying "not connected yet", because that's what dom0 gets before xenconsoled starts up.

Quoted 6 lines

Someone asked me the same a while back, and IIRC we don't state anywhere in the public headers that event channel 0 is reserved, however that has always? been part of the implementation.

If we intend this to be reliable, we should add a define to the public headers in order to signal that 0 will always be reserved.

I agree a comment should have been there; it's not clear to me what useful #define we could add.

Jan

#11 lore raw
Quoted 30 lines · Jan Beulich
Quoted 29 lines · Roger Pau Monné
Quoted 15 lines · Andrew Cooper
Quoted 11 lines · Paul

On 20/10/2023 14:37, David Woodhouse wrote:
[snip]

Quoted 7 lines
Quoted 3 lines

[0]
https://elixir.bootlin.com/linux/latest/source/drivers/tty/hvc/hvc_xen.c#L258

I'm not convinced I believe what the comment says there about evtchn 0 being theoretically valid. I don't believe zero is a valid evtchn#, is it?

gfn 0 might be valid, but I'm also pretty sure evtchn 0 is not valid.

GFN 0 very much is valid.

Quoted 8 lines

evtchn 0 OTOH is explicitly not valid.  From evtchn_init():

    evtchn_from_port(d, 0)->state = ECS_RESERVED;

However, the fields being 0 doesn't mean not available.  That's the signal to saying "not connected yet", because that's what dom0 gets before xenconsoled starts up.

Someone asked me the same a while back, and IIRC we don't state anywhere in the public headers that event channel 0 is reserved, however that has always? been part of the implementation.

Quoted 5 lines
Quoted 2 lines

If we intend this to be reliable, we should add a define to the public headers in order to signal that 0 will always be reserved.

I agree a comment should have been there; it's not clear to me what useful #define we could add.

EVTCHN_PORT_INVALID 0 or some such, but a comment would also be fine, the point is to be part of the public interface.

Thanks, Roger.