virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
@ 2023-07-19 15:45 Feng Liu via Virtualization
  2023-07-20  2:06 ` Xuan Zhuo
  2023-07-20  2:27 ` Jason Wang
  0 siblings, 2 replies; 9+ messages in thread
From: Feng Liu via Virtualization @ 2023-07-19 15:45 UTC (permalink / raw)
  To: virtualization, linux-kernel
  Cc: Xuan Zhuo, Michael S . Tsirkin, Jiri Pirko, Bodong Wang

The 'is_legacy' flag is used to differentiate between legacy vs modern
device. Currently, it is based on the value of vp_dev->ldev.ioaddr.
However, due to the shared memory of the union between struct
virtio_pci_legacy_device and struct virtio_pci_modern_device, when
virtio_pci_modern_probe modifies the content of struct
virtio_pci_modern_device, it affects the content of struct
virtio_pci_legacy_device, and ldev.ioaddr is no longer zero, causing
the 'is_legacy' flag to be set as true. To resolve issue, when legacy
device is probed, mark 'is_legacy' as true, when modern device is
probed, keep 'is_legacy' as false.

Fixes: 4f0fc22534e3 ("virtio_pci: Optimize virtio_pci_device structure size")
Signed-off-by: Feng Liu <feliu@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 drivers/virtio/virtio_pci_common.c | 2 --
 drivers/virtio/virtio_pci_legacy.c | 1 +
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index a6c86f916dbd..c2524a7207cf 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -557,8 +557,6 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 
 	pci_set_master(pci_dev);
 
-	vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
-
 	rc = register_virtio_device(&vp_dev->vdev);
 	reg_dev = vp_dev;
 	if (rc)
diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
index 2257f1b3d8ae..d9cbb02b35a1 100644
--- a/drivers/virtio/virtio_pci_legacy.c
+++ b/drivers/virtio/virtio_pci_legacy.c
@@ -223,6 +223,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
 	vp_dev->config_vector = vp_config_vector;
 	vp_dev->setup_vq = setup_vq;
 	vp_dev->del_vq = del_vq;
+	vp_dev->is_legacy = true;
 
 	return 0;
 }
-- 
2.37.1 (Apple Git-137.1)

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
  2023-07-19 15:45 [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe Feng Liu via Virtualization
@ 2023-07-20  2:06 ` Xuan Zhuo
  2023-07-20  2:27 ` Jason Wang
  1 sibling, 0 replies; 9+ messages in thread
From: Xuan Zhuo @ 2023-07-20  2:06 UTC (permalink / raw)
  To: Feng Liu
  Cc: Michael S . Tsirkin, linux-kernel, virtualization, Jiri Pirko,
	Bodong Wang

On Wed, 19 Jul 2023 11:45:50 -0400, Feng Liu <feliu@nvidia.com> wrote:
> The 'is_legacy' flag is used to differentiate between legacy vs modern
> device. Currently, it is based on the value of vp_dev->ldev.ioaddr.
> However, due to the shared memory of the union between struct
> virtio_pci_legacy_device and struct virtio_pci_modern_device, when
> virtio_pci_modern_probe modifies the content of struct
> virtio_pci_modern_device, it affects the content of struct
> virtio_pci_legacy_device, and ldev.ioaddr is no longer zero, causing
> the 'is_legacy' flag to be set as true. To resolve issue, when legacy
> device is probed, mark 'is_legacy' as true, when modern device is
> probed, keep 'is_legacy' as false.
>
> Fixes: 4f0fc22534e3 ("virtio_pci: Optimize virtio_pci_device structure size")
> Signed-off-by: Feng Liu <feliu@nvidia.com>
> Reviewed-by: Parav Pandit <parav@nvidia.com>
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>

Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>


> ---
>  drivers/virtio/virtio_pci_common.c | 2 --
>  drivers/virtio/virtio_pci_legacy.c | 1 +
>  2 files changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> index a6c86f916dbd..c2524a7207cf 100644
> --- a/drivers/virtio/virtio_pci_common.c
> +++ b/drivers/virtio/virtio_pci_common.c
> @@ -557,8 +557,6 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
>
>  	pci_set_master(pci_dev);
>
> -	vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
> -
>  	rc = register_virtio_device(&vp_dev->vdev);
>  	reg_dev = vp_dev;
>  	if (rc)
> diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
> index 2257f1b3d8ae..d9cbb02b35a1 100644
> --- a/drivers/virtio/virtio_pci_legacy.c
> +++ b/drivers/virtio/virtio_pci_legacy.c
> @@ -223,6 +223,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
>  	vp_dev->config_vector = vp_config_vector;
>  	vp_dev->setup_vq = setup_vq;
>  	vp_dev->del_vq = del_vq;
> +	vp_dev->is_legacy = true;
>
>  	return 0;
>  }
> --
> 2.37.1 (Apple Git-137.1)
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
  2023-07-19 15:45 [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe Feng Liu via Virtualization
  2023-07-20  2:06 ` Xuan Zhuo
@ 2023-07-20  2:27 ` Jason Wang
  2023-07-20  2:46   ` Feng Liu via Virtualization
                     ` (2 more replies)
  1 sibling, 3 replies; 9+ messages in thread
From: Jason Wang @ 2023-07-20  2:27 UTC (permalink / raw)
  To: Feng Liu
  Cc: Xuan Zhuo, Michael S . Tsirkin, linux-kernel, virtualization,
	Jiri Pirko, Bodong Wang

On Wed, Jul 19, 2023 at 11:46 PM Feng Liu <feliu@nvidia.com> wrote:
>
> The 'is_legacy' flag is used to differentiate between legacy vs modern
> device. Currently, it is based on the value of vp_dev->ldev.ioaddr.
> However, due to the shared memory of the union between struct
> virtio_pci_legacy_device and struct virtio_pci_modern_device, when
> virtio_pci_modern_probe modifies the content of struct
> virtio_pci_modern_device, it affects the content of struct
> virtio_pci_legacy_device, and ldev.ioaddr is no longer zero, causing
> the 'is_legacy' flag to be set as true. To resolve issue, when legacy
> device is probed, mark 'is_legacy' as true, when modern device is
> probed, keep 'is_legacy' as false.
>
> Fixes: 4f0fc22534e3 ("virtio_pci: Optimize virtio_pci_device structure size")
> Signed-off-by: Feng Liu <feliu@nvidia.com>
> Reviewed-by: Parav Pandit <parav@nvidia.com>
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
> ---
>  drivers/virtio/virtio_pci_common.c | 2 --
>  drivers/virtio/virtio_pci_legacy.c | 1 +
>  2 files changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> index a6c86f916dbd..c2524a7207cf 100644
> --- a/drivers/virtio/virtio_pci_common.c
> +++ b/drivers/virtio/virtio_pci_common.c
> @@ -557,8 +557,6 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
>
>         pci_set_master(pci_dev);
>
> -       vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
> -
>         rc = register_virtio_device(&vp_dev->vdev);
>         reg_dev = vp_dev;
>         if (rc)
> diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
> index 2257f1b3d8ae..d9cbb02b35a1 100644
> --- a/drivers/virtio/virtio_pci_legacy.c
> +++ b/drivers/virtio/virtio_pci_legacy.c
> @@ -223,6 +223,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
>         vp_dev->config_vector = vp_config_vector;
>         vp_dev->setup_vq = setup_vq;
>         vp_dev->del_vq = del_vq;
> +       vp_dev->is_legacy = true;

This seems break force_legacy for modern device:

        if (force_legacy) {
                rc = virtio_pci_legacy_probe(vp_dev);
                /* Also try modern mode if we can't map BAR0 (no IO space). */
                if (rc == -ENODEV || rc == -ENOMEM)
                        rc = virtio_pci_modern_probe(vp_dev);

Thanks

>
>         return 0;
>  }
> --
> 2.37.1 (Apple Git-137.1)
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
  2023-07-20  2:27 ` Jason Wang
@ 2023-07-20  2:46   ` Feng Liu via Virtualization
  2023-07-20 16:43   ` Feng Liu via Virtualization
  2023-07-20 17:14   ` Michael S. Tsirkin
  2 siblings, 0 replies; 9+ messages in thread
From: Feng Liu via Virtualization @ 2023-07-20  2:46 UTC (permalink / raw)
  To: Jason Wang
  Cc: Xuan Zhuo, Michael S . Tsirkin, linux-kernel, virtualization,
	Jiri Pirko, Bodong Wang



On 2023-07-19 p.m.10:27, Jason Wang wrote:
> External email: Use caution opening links or attachments
> 
> 
> On Wed, Jul 19, 2023 at 11:46 PM Feng Liu <feliu@nvidia.com> wrote:
>>
>> The 'is_legacy' flag is used to differentiate between legacy vs modern
>> device. Currently, it is based on the value of vp_dev->ldev.ioaddr.
>> However, due to the shared memory of the union between struct
>> virtio_pci_legacy_device and struct virtio_pci_modern_device, when
>> virtio_pci_modern_probe modifies the content of struct
>> virtio_pci_modern_device, it affects the content of struct
>> virtio_pci_legacy_device, and ldev.ioaddr is no longer zero, causing
>> the 'is_legacy' flag to be set as true. To resolve issue, when legacy
>> device is probed, mark 'is_legacy' as true, when modern device is
>> probed, keep 'is_legacy' as false.
>>
>> Fixes: 4f0fc22534e3 ("virtio_pci: Optimize virtio_pci_device structure size")
>> Signed-off-by: Feng Liu <feliu@nvidia.com>
>> Reviewed-by: Parav Pandit <parav@nvidia.com>
>> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
>> ---
>>   drivers/virtio/virtio_pci_common.c | 2 --
>>   drivers/virtio/virtio_pci_legacy.c | 1 +
>>   2 files changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
>> index a6c86f916dbd..c2524a7207cf 100644
>> --- a/drivers/virtio/virtio_pci_common.c
>> +++ b/drivers/virtio/virtio_pci_common.c
>> @@ -557,8 +557,6 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
>>
>>          pci_set_master(pci_dev);
>>
>> -       vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
>> -
>>          rc = register_virtio_device(&vp_dev->vdev);
>>          reg_dev = vp_dev;
>>          if (rc)
>> diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
>> index 2257f1b3d8ae..d9cbb02b35a1 100644
>> --- a/drivers/virtio/virtio_pci_legacy.c
>> +++ b/drivers/virtio/virtio_pci_legacy.c
>> @@ -223,6 +223,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
>>          vp_dev->config_vector = vp_config_vector;
>>          vp_dev->setup_vq = setup_vq;
>>          vp_dev->del_vq = del_vq;
>> +       vp_dev->is_legacy = true;
> 
> This seems break force_legacy for modern device:
> 
>          if (force_legacy) {
>                  rc = virtio_pci_legacy_probe(vp_dev);
>                  /* Also try modern mode if we can't map BAR0 (no IO space). */
>                  if (rc == -ENODEV || rc == -ENOMEM)
>                          rc = virtio_pci_modern_probe(vp_dev);
> 
> Thanks
> 
Will do, thanks

>>
>>          return 0;
>>   }
>> --
>> 2.37.1 (Apple Git-137.1)
>>
> 
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
  2023-07-20  2:27 ` Jason Wang
  2023-07-20  2:46   ` Feng Liu via Virtualization
@ 2023-07-20 16:43   ` Feng Liu via Virtualization
  2023-07-20 17:14   ` Michael S. Tsirkin
  2 siblings, 0 replies; 9+ messages in thread
From: Feng Liu via Virtualization @ 2023-07-20 16:43 UTC (permalink / raw)
  To: Jason Wang
  Cc: Xuan Zhuo, Michael S . Tsirkin, linux-kernel, virtualization,
	Jiri Pirko, Bodong Wang



On 2023-07-19 p.m.10:27, Jason Wang wrote:
> External email: Use caution opening links or attachments
> 
> 
> On Wed, Jul 19, 2023 at 11:46 PM Feng Liu <feliu@nvidia.com> wrote:
>>
>> The 'is_legacy' flag is used to differentiate between legacy vs modern
>> device. Currently, it is based on the value of vp_dev->ldev.ioaddr.
>> However, due to the shared memory of the union between struct
>> virtio_pci_legacy_device and struct virtio_pci_modern_device, when
>> virtio_pci_modern_probe modifies the content of struct
>> virtio_pci_modern_device, it affects the content of struct
>> virtio_pci_legacy_device, and ldev.ioaddr is no longer zero, causing
>> the 'is_legacy' flag to be set as true. To resolve issue, when legacy
>> device is probed, mark 'is_legacy' as true, when modern device is
>> probed, keep 'is_legacy' as false.
>>
>> Fixes: 4f0fc22534e3 ("virtio_pci: Optimize virtio_pci_device structure size")
>> Signed-off-by: Feng Liu <feliu@nvidia.com>
>> Reviewed-by: Parav Pandit <parav@nvidia.com>
>> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
>> ---
>>   drivers/virtio/virtio_pci_common.c | 2 --
>>   drivers/virtio/virtio_pci_legacy.c | 1 +
>>   2 files changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
>> index a6c86f916dbd..c2524a7207cf 100644
>> --- a/drivers/virtio/virtio_pci_common.c
>> +++ b/drivers/virtio/virtio_pci_common.c
>> @@ -557,8 +557,6 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
>>
>>          pci_set_master(pci_dev);
>>
>> -       vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
>> -
>>          rc = register_virtio_device(&vp_dev->vdev);
>>          reg_dev = vp_dev;
>>          if (rc)
>> diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
>> index 2257f1b3d8ae..d9cbb02b35a1 100644
>> --- a/drivers/virtio/virtio_pci_legacy.c
>> +++ b/drivers/virtio/virtio_pci_legacy.c
>> @@ -223,6 +223,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
>>          vp_dev->config_vector = vp_config_vector;
>>          vp_dev->setup_vq = setup_vq;
>>          vp_dev->del_vq = del_vq;
>> +       vp_dev->is_legacy = true;
> 
> This seems break force_legacy for modern device:
> 
>          if (force_legacy) {
>                  rc = virtio_pci_legacy_probe(vp_dev);
>                  /* Also try modern mode if we can't map BAR0 (no IO space). */
>                  if (rc == -ENODEV || rc == -ENOMEM)
>                          rc = virtio_pci_modern_probe(vp_dev);
> 
> Thanks
> 

Hi, Jason

In the case of force_legacy, if no IO space occurs, function will return 
directly after vp_legacy_probe, and will not run vp_dev->is_legacy = 
true; because vp_dev is allocated through kzalloc, the default 
vp_dev->is_legacy is false, which It is expected for modern device, so 
it will not break modern device.

What do you think?

int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
{
[...]

	rc = vp_legacy_probe(ldev);
	if (rc)
		return rc;  /* if no IO space, function will return from here */

[...]
	vp_dev->is_legacy = true;
}


>>
>>          return 0;
>>   }
>> --
>> 2.37.1 (Apple Git-137.1)
>>
> 
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
  2023-07-20  2:27 ` Jason Wang
  2023-07-20  2:46   ` Feng Liu via Virtualization
  2023-07-20 16:43   ` Feng Liu via Virtualization
@ 2023-07-20 17:14   ` Michael S. Tsirkin
  2023-07-24 13:14     ` Feng Liu via Virtualization
  2 siblings, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2023-07-20 17:14 UTC (permalink / raw)
  To: Jason Wang
  Cc: Xuan Zhuo, linux-kernel, virtualization, Jiri Pirko, Bodong Wang

On Thu, Jul 20, 2023 at 10:27:04AM +0800, Jason Wang wrote:
> On Wed, Jul 19, 2023 at 11:46 PM Feng Liu <feliu@nvidia.com> wrote:
> >
> > The 'is_legacy' flag is used to differentiate between legacy vs modern
> > device. Currently, it is based on the value of vp_dev->ldev.ioaddr.
> > However, due to the shared memory of the union between struct
> > virtio_pci_legacy_device and struct virtio_pci_modern_device, when
> > virtio_pci_modern_probe modifies the content of struct
> > virtio_pci_modern_device, it affects the content of struct
> > virtio_pci_legacy_device, and ldev.ioaddr is no longer zero, causing
> > the 'is_legacy' flag to be set as true. To resolve issue, when legacy
> > device is probed, mark 'is_legacy' as true, when modern device is
> > probed, keep 'is_legacy' as false.
> >
> > Fixes: 4f0fc22534e3 ("virtio_pci: Optimize virtio_pci_device structure size")
> > Signed-off-by: Feng Liu <feliu@nvidia.com>
> > Reviewed-by: Parav Pandit <parav@nvidia.com>
> > Reviewed-by: Jiri Pirko <jiri@nvidia.com>
> > ---
> >  drivers/virtio/virtio_pci_common.c | 2 --
> >  drivers/virtio/virtio_pci_legacy.c | 1 +
> >  2 files changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> > index a6c86f916dbd..c2524a7207cf 100644
> > --- a/drivers/virtio/virtio_pci_common.c
> > +++ b/drivers/virtio/virtio_pci_common.c
> > @@ -557,8 +557,6 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
> >
> >         pci_set_master(pci_dev);
> >
> > -       vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
> > -
> >         rc = register_virtio_device(&vp_dev->vdev);
> >         reg_dev = vp_dev;
> >         if (rc)
> > diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
> > index 2257f1b3d8ae..d9cbb02b35a1 100644
> > --- a/drivers/virtio/virtio_pci_legacy.c
> > +++ b/drivers/virtio/virtio_pci_legacy.c
> > @@ -223,6 +223,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
> >         vp_dev->config_vector = vp_config_vector;
> >         vp_dev->setup_vq = setup_vq;
> >         vp_dev->del_vq = del_vq;
> > +       vp_dev->is_legacy = true;
> 
> This seems break force_legacy for modern device:
> 
>         if (force_legacy) {
>                 rc = virtio_pci_legacy_probe(vp_dev);
>                 /* Also try modern mode if we can't map BAR0 (no IO space). */
>                 if (rc == -ENODEV || rc == -ENOMEM)
>                         rc = virtio_pci_modern_probe(vp_dev);
> 
> Thanks

don't see the breakage here - can you explain a bit more?

> >
> >         return 0;
> >  }
> > --
> > 2.37.1 (Apple Git-137.1)
> >

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
  2023-07-20 17:14   ` Michael S. Tsirkin
@ 2023-07-24 13:14     ` Feng Liu via Virtualization
  2023-07-25  3:41       ` Jason Wang
  0 siblings, 1 reply; 9+ messages in thread
From: Feng Liu via Virtualization @ 2023-07-24 13:14 UTC (permalink / raw)
  To: Michael S. Tsirkin, Jason Wang
  Cc: Xuan Zhuo, linux-kernel, virtualization, Jiri Pirko, Bodong Wang



On 2023-07-20 p.m.1:14, Michael S. Tsirkin wrote:
> External email: Use caution opening links or attachments
> 
> 
> On Thu, Jul 20, 2023 at 10:27:04AM +0800, Jason Wang wrote:
>> On Wed, Jul 19, 2023 at 11:46 PM Feng Liu <feliu@nvidia.com> wrote:
>>>
>>> The 'is_legacy' flag is used to differentiate between legacy vs modern
>>> device. Currently, it is based on the value of vp_dev->ldev.ioaddr.
>>> However, due to the shared memory of the union between struct
>>> virtio_pci_legacy_device and struct virtio_pci_modern_device, when
>>> virtio_pci_modern_probe modifies the content of struct
>>> virtio_pci_modern_device, it affects the content of struct
>>> virtio_pci_legacy_device, and ldev.ioaddr is no longer zero, causing
>>> the 'is_legacy' flag to be set as true. To resolve issue, when legacy
>>> device is probed, mark 'is_legacy' as true, when modern device is
>>> probed, keep 'is_legacy' as false.
>>>
>>> Fixes: 4f0fc22534e3 ("virtio_pci: Optimize virtio_pci_device structure size")
>>> Signed-off-by: Feng Liu <feliu@nvidia.com>
>>> Reviewed-by: Parav Pandit <parav@nvidia.com>
>>> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
>>> ---
>>>   drivers/virtio/virtio_pci_common.c | 2 --
>>>   drivers/virtio/virtio_pci_legacy.c | 1 +
>>>   2 files changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
>>> index a6c86f916dbd..c2524a7207cf 100644
>>> --- a/drivers/virtio/virtio_pci_common.c
>>> +++ b/drivers/virtio/virtio_pci_common.c
>>> @@ -557,8 +557,6 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
>>>
>>>          pci_set_master(pci_dev);
>>>
>>> -       vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
>>> -
>>>          rc = register_virtio_device(&vp_dev->vdev);
>>>          reg_dev = vp_dev;
>>>          if (rc)
>>> diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
>>> index 2257f1b3d8ae..d9cbb02b35a1 100644
>>> --- a/drivers/virtio/virtio_pci_legacy.c
>>> +++ b/drivers/virtio/virtio_pci_legacy.c
>>> @@ -223,6 +223,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
>>>          vp_dev->config_vector = vp_config_vector;
>>>          vp_dev->setup_vq = setup_vq;
>>>          vp_dev->del_vq = del_vq;
>>> +       vp_dev->is_legacy = true;
>>
>> This seems break force_legacy for modern device:
>>
>>          if (force_legacy) {
>>                  rc = virtio_pci_legacy_probe(vp_dev);
>>                  /* Also try modern mode if we can't map BAR0 (no IO space). */
>>                  if (rc == -ENODEV || rc == -ENOMEM)
>>                          rc = virtio_pci_modern_probe(vp_dev);
>>
>> Thanks
> 
> don't see the breakage here - can you explain a bit more?
> 
Hi, Jason

I also think there is no breakage herea and gave an explanation in 
another email, please have a see.

So are there any comments about this bug fix patch? Can this patch pass 
the review?

Thanks
Feng

>>>
>>>          return 0;
>>>   }
>>> --
>>> 2.37.1 (Apple Git-137.1)
>>>
> 
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
  2023-07-24 13:14     ` Feng Liu via Virtualization
@ 2023-07-25  3:41       ` Jason Wang
  2023-07-25  4:18         ` Feng Liu via Virtualization
  0 siblings, 1 reply; 9+ messages in thread
From: Jason Wang @ 2023-07-25  3:41 UTC (permalink / raw)
  To: Feng Liu
  Cc: Xuan Zhuo, Michael S. Tsirkin, linux-kernel, virtualization,
	Jiri Pirko, Bodong Wang

On Mon, Jul 24, 2023 at 9:14 PM Feng Liu <feliu@nvidia.com> wrote:
>
>
>
> On 2023-07-20 p.m.1:14, Michael S. Tsirkin wrote:
> > External email: Use caution opening links or attachments
> >
> >
> > On Thu, Jul 20, 2023 at 10:27:04AM +0800, Jason Wang wrote:
> >> On Wed, Jul 19, 2023 at 11:46 PM Feng Liu <feliu@nvidia.com> wrote:
> >>>
> >>> The 'is_legacy' flag is used to differentiate between legacy vs modern
> >>> device. Currently, it is based on the value of vp_dev->ldev.ioaddr.
> >>> However, due to the shared memory of the union between struct
> >>> virtio_pci_legacy_device and struct virtio_pci_modern_device, when
> >>> virtio_pci_modern_probe modifies the content of struct
> >>> virtio_pci_modern_device, it affects the content of struct
> >>> virtio_pci_legacy_device, and ldev.ioaddr is no longer zero, causing
> >>> the 'is_legacy' flag to be set as true. To resolve issue, when legacy
> >>> device is probed, mark 'is_legacy' as true, when modern device is
> >>> probed, keep 'is_legacy' as false.
> >>>
> >>> Fixes: 4f0fc22534e3 ("virtio_pci: Optimize virtio_pci_device structure size")
> >>> Signed-off-by: Feng Liu <feliu@nvidia.com>
> >>> Reviewed-by: Parav Pandit <parav@nvidia.com>
> >>> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
> >>> ---
> >>>   drivers/virtio/virtio_pci_common.c | 2 --
> >>>   drivers/virtio/virtio_pci_legacy.c | 1 +
> >>>   2 files changed, 1 insertion(+), 2 deletions(-)
> >>>
> >>> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> >>> index a6c86f916dbd..c2524a7207cf 100644
> >>> --- a/drivers/virtio/virtio_pci_common.c
> >>> +++ b/drivers/virtio/virtio_pci_common.c
> >>> @@ -557,8 +557,6 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
> >>>
> >>>          pci_set_master(pci_dev);
> >>>
> >>> -       vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
> >>> -
> >>>          rc = register_virtio_device(&vp_dev->vdev);
> >>>          reg_dev = vp_dev;
> >>>          if (rc)
> >>> diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
> >>> index 2257f1b3d8ae..d9cbb02b35a1 100644
> >>> --- a/drivers/virtio/virtio_pci_legacy.c
> >>> +++ b/drivers/virtio/virtio_pci_legacy.c
> >>> @@ -223,6 +223,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
> >>>          vp_dev->config_vector = vp_config_vector;
> >>>          vp_dev->setup_vq = setup_vq;
> >>>          vp_dev->del_vq = del_vq;
> >>> +       vp_dev->is_legacy = true;
> >>
> >> This seems break force_legacy for modern device:
> >>
> >>          if (force_legacy) {
> >>                  rc = virtio_pci_legacy_probe(vp_dev);
> >>                  /* Also try modern mode if we can't map BAR0 (no IO space). */
> >>                  if (rc == -ENODEV || rc == -ENOMEM)
> >>                          rc = virtio_pci_modern_probe(vp_dev);
> >>
> >> Thanks
> >
> > don't see the breakage here - can you explain a bit more?
> >
> Hi, Jason
>
> I also think there is no breakage herea and gave an explanation in
> another email, please have a see.

I think I've made a mistake, the patch should be fine.

>
> So are there any comments about this bug fix patch? Can this patch pass
> the review?

Yes.

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

>
> Thanks
> Feng
>
> >>>
> >>>          return 0;
> >>>   }
> >>> --
> >>> 2.37.1 (Apple Git-137.1)
> >>>
> >
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
  2023-07-25  3:41       ` Jason Wang
@ 2023-07-25  4:18         ` Feng Liu via Virtualization
  0 siblings, 0 replies; 9+ messages in thread
From: Feng Liu via Virtualization @ 2023-07-25  4:18 UTC (permalink / raw)
  To: Jason Wang
  Cc: Xuan Zhuo, Yishai Hadas, Michael S. Tsirkin, linux-kernel,
	virtualization, Jiri Pirko, Bodong Wang



On 2023-07-24 p.m.11:41, Jason Wang wrote:
> External email: Use caution opening links or attachments
> 
> 
> On Mon, Jul 24, 2023 at 9:14 PM Feng Liu <feliu@nvidia.com> wrote:
>>
>>
>>
>> On 2023-07-20 p.m.1:14, Michael S. Tsirkin wrote:
>>> External email: Use caution opening links or attachments
>>>
>>>
>>> On Thu, Jul 20, 2023 at 10:27:04AM +0800, Jason Wang wrote:
>>>> On Wed, Jul 19, 2023 at 11:46 PM Feng Liu <feliu@nvidia.com> wrote:
>>>>>
>>>>> The 'is_legacy' flag is used to differentiate between legacy vs modern
>>>>> device. Currently, it is based on the value of vp_dev->ldev.ioaddr.
>>>>> However, due to the shared memory of the union between struct
>>>>> virtio_pci_legacy_device and struct virtio_pci_modern_device, when
>>>>> virtio_pci_modern_probe modifies the content of struct
>>>>> virtio_pci_modern_device, it affects the content of struct
>>>>> virtio_pci_legacy_device, and ldev.ioaddr is no longer zero, causing
>>>>> the 'is_legacy' flag to be set as true. To resolve issue, when legacy
>>>>> device is probed, mark 'is_legacy' as true, when modern device is
>>>>> probed, keep 'is_legacy' as false.
>>>>>
>>>>> Fixes: 4f0fc22534e3 ("virtio_pci: Optimize virtio_pci_device structure size")
>>>>> Signed-off-by: Feng Liu <feliu@nvidia.com>
>>>>> Reviewed-by: Parav Pandit <parav@nvidia.com>
>>>>> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
>>>>> ---
>>>>>    drivers/virtio/virtio_pci_common.c | 2 --
>>>>>    drivers/virtio/virtio_pci_legacy.c | 1 +
>>>>>    2 files changed, 1 insertion(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
>>>>> index a6c86f916dbd..c2524a7207cf 100644
>>>>> --- a/drivers/virtio/virtio_pci_common.c
>>>>> +++ b/drivers/virtio/virtio_pci_common.c
>>>>> @@ -557,8 +557,6 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
>>>>>
>>>>>           pci_set_master(pci_dev);
>>>>>
>>>>> -       vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
>>>>> -
>>>>>           rc = register_virtio_device(&vp_dev->vdev);
>>>>>           reg_dev = vp_dev;
>>>>>           if (rc)
>>>>> diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
>>>>> index 2257f1b3d8ae..d9cbb02b35a1 100644
>>>>> --- a/drivers/virtio/virtio_pci_legacy.c
>>>>> +++ b/drivers/virtio/virtio_pci_legacy.c
>>>>> @@ -223,6 +223,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
>>>>>           vp_dev->config_vector = vp_config_vector;
>>>>>           vp_dev->setup_vq = setup_vq;
>>>>>           vp_dev->del_vq = del_vq;
>>>>> +       vp_dev->is_legacy = true;
>>>>
>>>> This seems break force_legacy for modern device:
>>>>
>>>>           if (force_legacy) {
>>>>                   rc = virtio_pci_legacy_probe(vp_dev);
>>>>                   /* Also try modern mode if we can't map BAR0 (no IO space). */
>>>>                   if (rc == -ENODEV || rc == -ENOMEM)
>>>>                           rc = virtio_pci_modern_probe(vp_dev);
>>>>
>>>> Thanks
>>>
>>> don't see the breakage here - can you explain a bit more?
>>>
>> Hi, Jason
>>
>> I also think there is no breakage herea and gave an explanation in
>> another email, please have a see.
> 
> I think I've made a mistake, the patch should be fine.
> 
>>
>> So are there any comments about this bug fix patch? Can this patch pass
>> the review?
> 
> Yes.
> 
> Acked-by: Jason Wang <jasowang@redhat.com>
> 
> Thanks
> 

Thanks Jason

>>
>> Thanks
>> Feng
>>
>>>>>
>>>>>           return 0;
>>>>>    }
>>>>> --
>>>>> 2.37.1 (Apple Git-137.1)
>>>>>
>>>
>>
> 
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

end of thread, other threads:[~2023-07-25  4:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-19 15:45 [PATCH v1] virtio-pci: Fix legacy device flag setting error in probe Feng Liu via Virtualization
2023-07-20  2:06 ` Xuan Zhuo
2023-07-20  2:27 ` Jason Wang
2023-07-20  2:46   ` Feng Liu via Virtualization
2023-07-20 16:43   ` Feng Liu via Virtualization
2023-07-20 17:14   ` Michael S. Tsirkin
2023-07-24 13:14     ` Feng Liu via Virtualization
2023-07-25  3:41       ` Jason Wang
2023-07-25  4:18         ` Feng Liu via Virtualization

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).