diff mbox series

virtio: fix get_config / set_config for legacy VirtIO targets

Message ID 20240212073708.4161197-1-dmitry.baryshkov@linaro.org
State Accepted
Commit 3098115155ca9226502e39c5ad3401c25dae64fd
Headers show
Series virtio: fix get_config / set_config for legacy VirtIO targets | expand

Commit Message

Dmitry Baryshkov Feb. 12, 2024, 7:37 a.m. UTC
The functions virtio_pci_get_config() and virtio_pci_set_config() don't
take the offset into account when reading the config space. For example
this manifests when U-Boot tries to read the MAC address of the VirtIO
networking device. It reads 6 equa bytes instead of the proper addess.

Fix those functions by taking the offset in the config space into
account.

Fixes: 4135e10732a0 ("virtio: Add virtio over pci transport driver")
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/virtio/virtio_pci_legacy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Dmitry Baryshkov Feb. 17, 2024, 8:09 p.m. UTC | #1
On Mon, 12 Feb 2024 at 09:37, Dmitry Baryshkov
<dmitry.baryshkov@linaro.org> wrote:
>
> The functions virtio_pci_get_config() and virtio_pci_set_config() don't
> take the offset into account when reading the config space. For example
> this manifests when U-Boot tries to read the MAC address of the VirtIO
> networking device. It reads 6 equa bytes instead of the proper addess.
>
> Fix those functions by taking the offset in the config space into
> account.
>
> Fixes: 4135e10732a0 ("virtio: Add virtio over pci transport driver")
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

Gracious ping

> ---
>  drivers/virtio/virtio_pci_legacy.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
> index cf5dfb17a94d..aa89604ae84d 100644
> --- a/drivers/virtio/virtio_pci_legacy.c
> +++ b/drivers/virtio/virtio_pci_legacy.c
> @@ -107,7 +107,7 @@ static int virtio_pci_get_config(struct udevice *udev, unsigned int offset,
>         int i;
>
>         for (i = 0; i < len; i++)
> -               ptr[i] = ioread8(ioaddr + i);
> +               ptr[i] = ioread8(ioaddr + offset + i);
>
>         return 0;
>  }
> @@ -121,7 +121,7 @@ static int virtio_pci_set_config(struct udevice *udev, unsigned int offset,
>         int i;
>
>         for (i = 0; i < len; i++)
> -               iowrite8(ptr[i], ioaddr + i);
> +               iowrite8(ptr[i], ioaddr + offset + i);
>
>         return 0;
>  }
> --
> 2.39.2
>
Tom Rini Feb. 19, 2024, 8:49 p.m. UTC | #2
On Sat, Feb 17, 2024 at 10:09:12PM +0200, Dmitry Baryshkov wrote:
> On Mon, 12 Feb 2024 at 09:37, Dmitry Baryshkov
> <dmitry.baryshkov@linaro.org> wrote:
> >
> > The functions virtio_pci_get_config() and virtio_pci_set_config() don't
> > take the offset into account when reading the config space. For example
> > this manifests when U-Boot tries to read the MAC address of the VirtIO
> > networking device. It reads 6 equa bytes instead of the proper addess.
> >
> > Fix those functions by taking the offset in the config space into
> > account.
> >
> > Fixes: 4135e10732a0 ("virtio: Add virtio over pci transport driver")
> > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> 
> Gracious ping
> 
> > ---
> >  drivers/virtio/virtio_pci_legacy.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
> > index cf5dfb17a94d..aa89604ae84d 100644
> > --- a/drivers/virtio/virtio_pci_legacy.c
> > +++ b/drivers/virtio/virtio_pci_legacy.c
> > @@ -107,7 +107,7 @@ static int virtio_pci_get_config(struct udevice *udev, unsigned int offset,
> >         int i;
> >
> >         for (i = 0; i < len; i++)
> > -               ptr[i] = ioread8(ioaddr + i);
> > +               ptr[i] = ioread8(ioaddr + offset + i);
> >
> >         return 0;
> >  }
> > @@ -121,7 +121,7 @@ static int virtio_pci_set_config(struct udevice *udev, unsigned int offset,
> >         int i;
> >
> >         for (i = 0; i < len; i++)
> > -               iowrite8(ptr[i], ioaddr + i);
> > +               iowrite8(ptr[i], ioaddr + offset + i);
> >
> >         return 0;
> >  }

I'll take this for -next when it opens.
Tom Rini March 5, 2024, 4:02 p.m. UTC | #3
On Mon, 12 Feb 2024 09:37:08 +0200, Dmitry Baryshkov wrote:

> The functions virtio_pci_get_config() and virtio_pci_set_config() don't
> take the offset into account when reading the config space. For example
> this manifests when U-Boot tries to read the MAC address of the VirtIO
> networking device. It reads 6 equa bytes instead of the proper addess.
> 
> Fix those functions by taking the offset in the config space into
> account.
> 
> [...]

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
index cf5dfb17a94d..aa89604ae84d 100644
--- a/drivers/virtio/virtio_pci_legacy.c
+++ b/drivers/virtio/virtio_pci_legacy.c
@@ -107,7 +107,7 @@  static int virtio_pci_get_config(struct udevice *udev, unsigned int offset,
 	int i;
 
 	for (i = 0; i < len; i++)
-		ptr[i] = ioread8(ioaddr + i);
+		ptr[i] = ioread8(ioaddr + offset + i);
 
 	return 0;
 }
@@ -121,7 +121,7 @@  static int virtio_pci_set_config(struct udevice *udev, unsigned int offset,
 	int i;
 
 	for (i = 0; i < len; i++)
-		iowrite8(ptr[i], ioaddr + i);
+		iowrite8(ptr[i], ioaddr + offset + i);
 
 	return 0;
 }