linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/1] gpio: virtio: Fix config space reading.
@ 2025-07-17 14:09 Harald Mommer
  2025-07-17 14:09 ` [PATCH v1 1/1] " Harald Mommer
  0 siblings, 1 reply; 4+ messages in thread
From: Harald Mommer @ 2025-07-17 14:09 UTC (permalink / raw)
  To: Enrico Weigelt, Viresh Kumar, Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, virtualization, linux-kernel

The Virtio GPIO Linux driver reads the configuration space in a way not
conformant with the virtio specification. The hypervisor we are using is
strict in what it accepts so the current behavior causes a problem.

Builds on top of gpio/for-next, tested on Linux v6.5.7.

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

* [PATCH v1 1/1] gpio: virtio: Fix config space reading.
  2025-07-17 14:09 [PATCH v1 0/1] gpio: virtio: Fix config space reading Harald Mommer
@ 2025-07-17 14:09 ` Harald Mommer
  2025-07-18  8:11   ` Bartosz Golaszewski
  2025-07-18  8:15   ` Viresh Kumar
  0 siblings, 2 replies; 4+ messages in thread
From: Harald Mommer @ 2025-07-17 14:09 UTC (permalink / raw)
  To: Enrico Weigelt, Viresh Kumar, Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, virtualization, linux-kernel

Quote from the virtio specification chapter 4.2.2.2:

"For the device-specific configuration space, the driver MUST use 8 bit
wide accesses for 8 bit wide fields, 16 bit wide and aligned accesses
for 16 bit wide fields and 32 bit wide and aligned accesses for 32 and
64 bit wide fields."

Signed-off-by: Harald Mommer <harald.mommer@oss.qualcomm.com>
---
 drivers/gpio/gpio-virtio.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-virtio.c b/drivers/gpio/gpio-virtio.c
index 92b456475d89..07552611da98 100644
--- a/drivers/gpio/gpio-virtio.c
+++ b/drivers/gpio/gpio-virtio.c
@@ -527,7 +527,6 @@ static const char **virtio_gpio_get_names(struct virtio_gpio *vgpio,
 
 static int virtio_gpio_probe(struct virtio_device *vdev)
 {
-	struct virtio_gpio_config config;
 	struct device *dev = &vdev->dev;
 	struct virtio_gpio *vgpio;
 	struct irq_chip *gpio_irq_chip;
@@ -540,9 +539,11 @@ static int virtio_gpio_probe(struct virtio_device *vdev)
 		return -ENOMEM;
 
 	/* Read configuration */
-	virtio_cread_bytes(vdev, 0, &config, sizeof(config));
-	gpio_names_size = le32_to_cpu(config.gpio_names_size);
-	ngpio = le16_to_cpu(config.ngpio);
+	gpio_names_size =
+		virtio_cread32(vdev, offsetof(struct virtio_gpio_config,
+					      gpio_names_size));
+	ngpio =  virtio_cread16(vdev, offsetof(struct virtio_gpio_config,
+					       ngpio));
 	if (!ngpio) {
 		dev_err(dev, "Number of GPIOs can't be zero\n");
 		return -EINVAL;
-- 
2.43.0


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

* Re: [PATCH v1 1/1] gpio: virtio: Fix config space reading.
  2025-07-17 14:09 ` [PATCH v1 1/1] " Harald Mommer
@ 2025-07-18  8:11   ` Bartosz Golaszewski
  2025-07-18  8:15   ` Viresh Kumar
  1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2025-07-18  8:11 UTC (permalink / raw)
  To: Harald Mommer
  Cc: Enrico Weigelt, Viresh Kumar, Linus Walleij, linux-gpio,
	virtualization, linux-kernel

On Thu, Jul 17, 2025 at 4:10 PM Harald Mommer
<harald.mommer@oss.qualcomm.com> wrote:
>
> Quote from the virtio specification chapter 4.2.2.2:
>
> "For the device-specific configuration space, the driver MUST use 8 bit
> wide accesses for 8 bit wide fields, 16 bit wide and aligned accesses
> for 16 bit wide fields and 32 bit wide and aligned accesses for 32 and
> 64 bit wide fields."
>
> Signed-off-by: Harald Mommer <harald.mommer@oss.qualcomm.com>
> ---

I guess this needs a Fixes tag? And possibly Cc: stable?

Viresh, does this look ok to you?

Bart

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

* Re: [PATCH v1 1/1] gpio: virtio: Fix config space reading.
  2025-07-17 14:09 ` [PATCH v1 1/1] " Harald Mommer
  2025-07-18  8:11   ` Bartosz Golaszewski
@ 2025-07-18  8:15   ` Viresh Kumar
  1 sibling, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2025-07-18  8:15 UTC (permalink / raw)
  To: Harald Mommer
  Cc: Enrico Weigelt, Viresh Kumar, Linus Walleij, Bartosz Golaszewski,
	linux-gpio, virtualization, linux-kernel

On 17-07-25, 16:09, Harald Mommer wrote:
> Quote from the virtio specification chapter 4.2.2.2:
> 
> "For the device-specific configuration space, the driver MUST use 8 bit
> wide accesses for 8 bit wide fields, 16 bit wide and aligned accesses
> for 16 bit wide fields and 32 bit wide and aligned accesses for 32 and
> 64 bit wide fields."
> 
> Signed-off-by: Harald Mommer <harald.mommer@oss.qualcomm.com>
> ---
>  drivers/gpio/gpio-virtio.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

end of thread, other threads:[~2025-07-18  8:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-17 14:09 [PATCH v1 0/1] gpio: virtio: Fix config space reading Harald Mommer
2025-07-17 14:09 ` [PATCH v1 1/1] " Harald Mommer
2025-07-18  8:11   ` Bartosz Golaszewski
2025-07-18  8:15   ` Viresh Kumar

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