Feng Liu
2023-Jul-19 15:45 UTC
[PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
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 at nvidia.com> Reviewed-by: Parav Pandit <parav at nvidia.com> Reviewed-by: Jiri Pirko <jiri at 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)
Xuan Zhuo
2023-Jul-20 02:06 UTC
[PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
On Wed, 19 Jul 2023 11:45:50 -0400, Feng Liu <feliu at 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 at nvidia.com> > Reviewed-by: Parav Pandit <parav at nvidia.com> > Reviewed-by: Jiri Pirko <jiri at nvidia.com>Reviewed-by: Xuan Zhuo <xuanzhuo at 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) >
Jason Wang
2023-Jul-20 02:27 UTC
[PATCH v1] virtio-pci: Fix legacy device flag setting error in probe
On Wed, Jul 19, 2023 at 11:46?PM Feng Liu <feliu at 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 at nvidia.com> > Reviewed-by: Parav Pandit <parav at nvidia.com> > Reviewed-by: Jiri Pirko <jiri at 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) >