2022-05-27 16:28:30

by Jason Wang

[permalink] [raw]
Subject: [PATCH V6 9/9] virtio: use WARN_ON() to warning illegal status value

We used to use BUG_ON() in virtio_device_ready() to detect illegal
status value, this seems sub-optimal since the value is under the
control of the device. Switch to use WARN_ON() instead.

Cc: Thomas Gleixner <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: Vineeth Vijayan <[email protected]>
Cc: Peter Oberparleiter <[email protected]>
Cc: [email protected]
Signed-off-by: Jason Wang <[email protected]>
---
include/linux/virtio_config.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index d4edfd7d91bb..9a36051ceb76 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -255,7 +255,7 @@ void virtio_device_ready(struct virtio_device *dev)
{
unsigned status = dev->config->get_status(dev);

- BUG_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
+ WARN_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);

/*
* The virtio_synchronize_cbs() makes sure vring_interrupt()
--
2.25.1



2022-05-28 02:53:32

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [PATCH V6 9/9] virtio: use WARN_ON() to warning illegal status value

On Fri, May 27, 2022 at 02:01:20PM +0800, Jason Wang wrote:
>We used to use BUG_ON() in virtio_device_ready() to detect illegal
>status value, this seems sub-optimal since the value is under the
>control of the device. Switch to use WARN_ON() instead.
>
>Cc: Thomas Gleixner <[email protected]>
>Cc: Peter Zijlstra <[email protected]>
>Cc: "Paul E. McKenney" <[email protected]>
>Cc: Marc Zyngier <[email protected]>
>Cc: Halil Pasic <[email protected]>
>Cc: Cornelia Huck <[email protected]>
>Cc: Vineeth Vijayan <[email protected]>
>Cc: Peter Oberparleiter <[email protected]>
>Cc: [email protected]
>Signed-off-by: Jason Wang <[email protected]>
>---
> include/linux/virtio_config.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Stefano Garzarella <[email protected]>


2022-05-28 18:25:49

by Xuan Zhuo

[permalink] [raw]
Subject: Re: [PATCH V6 9/9] virtio: use WARN_ON() to warning illegal status value

On Fri, 27 May 2022 14:01:20 +0800, Jason Wang <[email protected]> wrote:
> We used to use BUG_ON() in virtio_device_ready() to detect illegal
> status value, this seems sub-optimal since the value is under the
> control of the device. Switch to use WARN_ON() instead.
>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: "Paul E. McKenney" <[email protected]>
> Cc: Marc Zyngier <[email protected]>
> Cc: Halil Pasic <[email protected]>
> Cc: Cornelia Huck <[email protected]>
> Cc: Vineeth Vijayan <[email protected]>
> Cc: Peter Oberparleiter <[email protected]>
> Cc: [email protected]
> Signed-off-by: Jason Wang <[email protected]>

Reviewed-by: Xuan Zhuo <[email protected]>

> ---
> include/linux/virtio_config.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> index d4edfd7d91bb..9a36051ceb76 100644
> --- a/include/linux/virtio_config.h
> +++ b/include/linux/virtio_config.h
> @@ -255,7 +255,7 @@ void virtio_device_ready(struct virtio_device *dev)
> {
> unsigned status = dev->config->get_status(dev);
>
> - BUG_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
> + WARN_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
>
> /*
> * The virtio_synchronize_cbs() makes sure vring_interrupt()
> --
> 2.25.1
>

2022-05-28 19:26:17

by Michael S. Tsirkin

[permalink] [raw]
Subject: Re: [PATCH V6 9/9] virtio: use WARN_ON() to warning illegal status value

At a minimum, I don't see why it's part of the series. Host can always
crash the guest if it wants to ...
The point of BUG_ON is device or driver is already corrupted so we
should not try to drive it. If you still want this in pls come up with
a better commit log explaining the why.

On Fri, May 27, 2022 at 02:01:20PM +0800, Jason Wang wrote:
> We used to use BUG_ON() in virtio_device_ready() to detect illegal

not really, BUG_ON just crashes the kernel. we detect by checking
status.

> status value, this seems sub-optimal since the value is under the
> control of the device. Switch to use WARN_ON() instead.

some people use crash on warn so ...

>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: "Paul E. McKenney" <[email protected]>
> Cc: Marc Zyngier <[email protected]>
> Cc: Halil Pasic <[email protected]>
> Cc: Cornelia Huck <[email protected]>
> Cc: Vineeth Vijayan <[email protected]>
> Cc: Peter Oberparleiter <[email protected]>
> Cc: [email protected]
> Signed-off-by: Jason Wang <[email protected]>

> ---
> include/linux/virtio_config.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> index d4edfd7d91bb..9a36051ceb76 100644
> --- a/include/linux/virtio_config.h
> +++ b/include/linux/virtio_config.h
> @@ -255,7 +255,7 @@ void virtio_device_ready(struct virtio_device *dev)
> {
> unsigned status = dev->config->get_status(dev);
>
> - BUG_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
> + WARN_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
>

we lose debuggability as guest will try to continue.
if we are doing this let us print a helpful message and dump a lot of
state right here.

> /*
> * The virtio_synchronize_cbs() makes sure vring_interrupt()
> --
> 2.25.1


2022-05-30 08:52:26

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH V6 9/9] virtio: use WARN_ON() to warning illegal status value

On Fri, May 27, 2022 at 6:50 PM Michael S. Tsirkin <[email protected]> wrote:
>
> At a minimum, I don't see why it's part of the series. Host can always
> crash the guest if it wants to ...

Probably not with some recent technology. In those cases, a fault will
be generated if the hypervisor tries to access the memory that is
private to the guest.

> The point of BUG_ON is device or driver is already corrupted so we
> should not try to drive it. If you still want this in pls come up with
> a better commit log explaining the why.

A question here, should we always use BUG_ON for the buggy/malicious hypervisor?

The interrupt hardening logic in this series tries to make guest
survive, so did this patch.

>
> On Fri, May 27, 2022 at 02:01:20PM +0800, Jason Wang wrote:
> > We used to use BUG_ON() in virtio_device_ready() to detect illegal
>
> not really, BUG_ON just crashes the kernel. we detect by checking
> status.

We need a kind of notification otherwise there's no way for the user
to know about this expected value.

>
> > status value, this seems sub-optimal since the value is under the
> > control of the device. Switch to use WARN_ON() instead.
>
> some people use crash on warn so ...

Yes, but the policy is under the control of the user.

>
> >
> > Cc: Thomas Gleixner <[email protected]>
> > Cc: Peter Zijlstra <[email protected]>
> > Cc: "Paul E. McKenney" <[email protected]>
> > Cc: Marc Zyngier <[email protected]>
> > Cc: Halil Pasic <[email protected]>
> > Cc: Cornelia Huck <[email protected]>
> > Cc: Vineeth Vijayan <[email protected]>
> > Cc: Peter Oberparleiter <[email protected]>
> > Cc: [email protected]
> > Signed-off-by: Jason Wang <[email protected]>
>
> > ---
> > include/linux/virtio_config.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> > index d4edfd7d91bb..9a36051ceb76 100644
> > --- a/include/linux/virtio_config.h
> > +++ b/include/linux/virtio_config.h
> > @@ -255,7 +255,7 @@ void virtio_device_ready(struct virtio_device *dev)
> > {
> > unsigned status = dev->config->get_status(dev);
> >
> > - BUG_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
> > + WARN_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
> >
>
> we lose debuggability as guest will try to continue.
> if we are doing this let us print a helpful message and dump a lot of
> state right here.

I'm ok with dropping this patch from the series. And revisit it in the future.

Thanks

>
> > /*
> > * The virtio_synchronize_cbs() makes sure vring_interrupt()
> > --
> > 2.25.1
>