All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] iommu/virtio: Probe fixes for proper driver state
       [not found] <20260714025913.2042-1-xiongweimin@kylinos.cn>
@ 2026-07-23  3:24 ` Xiong Weimin
  2026-07-23 11:44   ` Will Deacon
  2026-07-24  2:33 ` Xiong Weimin
       [not found] ` <20260724023549.GA2036@myrica>
  2 siblings, 1 reply; 4+ messages in thread
From: Xiong Weimin @ 2026-07-23  3:24 UTC (permalink / raw)
  To: iommu; +Cc: will, robin.murphy, linux-kernel, joro

[-- Attachment #1: 0000-cover-letter.patch --]
[-- Type: text/plain, Size: 834 bytes --]

From: Xiong Weimin <xiongweimin@kylinos.cn>
Subject: [PATCH v3 0/2] iommu/virtio: Probe fixes for proper driver state
In-Reply-To: <20260714025913.2042-1-xiongweimin@kylinos.cn>
References: <20260714025913.2042-1-xiongweimin@kylinos.cn>

This is v3 of the patch series. v2 is now obsolete.

Changes since v2:
- Rebased onto latest upstream
- Patch 3 ("Reject short event buffers") has been dropped as it was
  independently submitted by Xu Rao
- As suggested by Will Deacon, modified viommu_init_vqs() to take vdev
  instead of viommu, since they are now linked via vdev->priv

---

Xiong Weimin (2):
  iommu/virtio: Set driver data before enabling virtqueues
  iommu/virtio: Handle iommu_device_register() failures

 drivers/iommu/virtio-iommu.c | 17 +++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

--

2.43.0


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

* Re: [PATCH v3 0/2] iommu/virtio: Probe fixes for proper driver state
  2026-07-23  3:24 ` [PATCH v3 0/2] iommu/virtio: Probe fixes for proper driver state Xiong Weimin
@ 2026-07-23 11:44   ` Will Deacon
  0 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2026-07-23 11:44 UTC (permalink / raw)
  To: Xiong Weimin; +Cc: iommu, robin.murphy, linux-kernel, joro

On Thu, Jul 23, 2026 at 11:24:46AM +0800, Xiong Weimin wrote:
> From: Xiong Weimin <xiongweimin@kylinos.cn>
> Subject: [PATCH v3 0/2] iommu/virtio: Probe fixes for proper driver state
> In-Reply-To: <20260714025913.2042-1-xiongweimin@kylinos.cn>
> References: <20260714025913.2042-1-xiongweimin@kylinos.cn>
> 
> This is v3 of the patch series. v2 is now obsolete.

Sorry, I'm going to ignore this until you figure out your mail setup. This
is a cover letter with no patches in reply to it but meanwhile you've also
sent some new v2 patches at [1], one of which has already been rejected by
Jean-Philippe in a previous (identical) posting [2].

Will

[1] https://lore.kernel.org/r/20260723095100.1-xiongweimin@kylinos.cn
[2] https://lore.kernel.org/all/20260709095518.GA1752964@myrica/

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

* [PATCH v3 0/2] iommu/virtio: Probe fixes for proper driver state
       [not found] <20260714025913.2042-1-xiongweimin@kylinos.cn>
  2026-07-23  3:24 ` [PATCH v3 0/2] iommu/virtio: Probe fixes for proper driver state Xiong Weimin
@ 2026-07-24  2:33 ` Xiong Weimin
       [not found] ` <20260724023549.GA2036@myrica>
  2 siblings, 0 replies; 4+ messages in thread
From: Xiong Weimin @ 2026-07-24  2:33 UTC (permalink / raw)
  To: iommu; +Cc: will, robin.murphy, joro

[-- Attachment #1: 0000-cover-letter.patch --]
[-- Type: text/plain, Size: 917 bytes --]

From: Xiong Weimin <xiongweimin@kylinos.cn>
Subject: [PATCH v3 0/2] iommu/virtio: Probe fixes for proper driver state
To: iommu@lists.linux.dev
Cc: will@kernel.org, robin.murphy@arm.com, joro@8bytes.org
In-Reply-To: <20260714025913.2042-1-xiongweimin@kylinos.cn>
References: <20260714025913.2042-1-xiongweimin@kylinos.cn>

This is v3 of the patch series. v2 is now obsolete.

Changes since v2:
- Rebased onto latest upstream
- Patch 3 ("Reject short event buffers") has been dropped as it was
  independently submitted by Xu Rao
- As suggested by Will Deacon, modified viommu_init_vqs() to take vdev
  instead of viommu, since they are now linked via vdev->priv

---

Xiong Weimin (2):
  iommu/virtio: Set driver data before enabling virtqueues
  iommu/virtio: Handle iommu_device_register() failures

 drivers/iommu/virtio-iommu.c | 17 +++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

--
2.43.0

[-- Attachment #2: 0001-iommu-virtio-Set-driver-data-before-enabling-virtque.patch --]
[-- Type: text/plain, Size: 2251 bytes --]

From fda59717330fd907f1cd3fdbba7e0b0888b54524 Mon Sep 17 00:00:00 2001
From: xiongweimin <xiongweimin@kylinos.cn>
Date: Thu, 23 Jul 2026 11:18:50 +0800
Subject: [PATCH v3 1/2] iommu/virtio: Set driver data before enabling
 virtqueues
To: iommu@lists.linux.dev
Cc: will@kernel.org,
    robin.murphy@arm.com,
    joro@8bytes.org

The event virtqueue callback retrieves the driver state through
vq->vdev->priv. viommu_probe() currently initializes that pointer only
after virtio_device_ready() and after the event queue is populated.

Store the driver data before creating the virtqueues so callbacks always
see initialized driver state once the device is made ready. Clear the
pointer again on probe failure.

As suggested by Will Deacon, pass vdev instead of viommu to
viommu_init_vqs(), since we already linked them together.

Suggested-by: Will Deacon <will@kernel.org>
Signed-off-by: Xiong Weimin <xiongweimin@kylinos.cn>
Reviewed-by: Will Deacon <will@kernel.org>
---
 drivers/iommu/virtio-iommu.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index 587fc1319..f3f74fdc1 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -1110,9 +1110,9 @@ static const struct iommu_ops viommu_ops = {
 	}
 };
 
-static int viommu_init_vqs(struct viommu_dev *viommu)
+static int viommu_init_vqs(struct virtio_device *vdev)
 {
-	struct virtio_device *vdev = dev_to_virtio(viommu->dev);
+	struct viommu_dev *viommu = vdev->priv;
 	struct virtqueue_info vqs_info[] = {
 		{ "request" },
 		{ "event", viommu_event_handler },
@@ -1169,11 +1169,12 @@ static int viommu_probe(struct virtio_device *vdev)
 	ida_init(&viommu->domain_ids);
 	viommu->dev = dev;
 	viommu->vdev = vdev;
+	vdev->priv = viommu;
 	INIT_LIST_HEAD(&viommu->requests);
 
-	ret = viommu_init_vqs(viommu);
+	ret = viommu_init_vqs(vdev);
 	if (ret)
-		return ret;
+		goto err_clear_priv;
 
 	virtio_cread_le(vdev, struct virtio_iommu_config, page_size_mask,
 			&viommu->pgsize_bitmap);
@@ -1246,6 +1247,8 @@ static int viommu_probe(struct virtio_device *vdev)
 
 err_free_vqs:
 	vdev->config->del_vqs(vdev);
+err_clear_priv:
+	vdev->priv = NULL;
 
 	return ret;
 }
-- 
2.43.0


[-- Attachment #3: 0002-iommu-virtio-Handle-iommu_device_register-failures.patch --]
[-- Type: text/plain, Size: 1466 bytes --]

From 3f94f2266bc35c31234b19c1e9acb847ff7e445c Mon Sep 17 00:00:00 2001
From: xiongweimin <xiongweimin@kylinos.cn>
Date: Thu, 23 Jul 2026 11:19:07 +0800
Subject: [PATCH v3 2/2] iommu/virtio: Handle iommu_device_register() failures
To: iommu@lists.linux.dev
Cc: will@kernel.org,
    robin.murphy@arm.com,
    joro@8bytes.org

Check the return value of iommu_device_register() and properly clean up
sysfs entries on failure. This ensures that the device sysfs directory
is removed if registration fails.

Reviewed-by: Will Deacon <will@kernel.org>
Signed-off-by: Xiong Weimin <xiongweimin@kylinos.cn>
---
 drivers/iommu/virtio-iommu.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index f3f74fdc1..288eea386 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -1237,7 +1237,9 @@ static int viommu_probe(struct virtio_device *vdev)
 
 	vdev->priv = viommu;
 
-	iommu_device_register(&viommu->iommu, &viommu_ops, parent_dev);
+	ret = iommu_device_register(&viommu->iommu, &viommu_ops, parent_dev);
+	if (ret)
+		goto err_free_sysfs;
 
 	dev_info(dev, "input address: %u bits\n",
 		 order_base_2(viommu->geometry.aperture_end));
@@ -1245,6 +1247,8 @@ static int viommu_probe(struct virtio_device *vdev)
 
 	return 0;
 
+err_free_sysfs:
+	iommu_device_sysfs_remove(&viommu->iommu);
 err_free_vqs:
 	vdev->config->del_vqs(vdev);
 err_clear_priv:
-- 
2.43.0


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

* [PATCH] iommu/virtio: Fix probe error handling and driver state initialization
       [not found] ` <20260724023549.GA2036@myrica>
@ 2026-07-24  2:42   ` Xiong Weimin
  0 siblings, 0 replies; 4+ messages in thread
From: Xiong Weimin @ 2026-07-24  2:42 UTC (permalink / raw)
  To: iommu; +Cc: will, robin.murphy, joro

[-- Attachment #1: Type: text/plain, Size: 3793 bytes --]

Hi Will,

Thank you for your patience and I'm really sorry for the email mess earlier.

The previous emails had issues with my sending script, which caused:
1. Cover letter sent without patch content
2. Duplicate v2 patches that should have been marked obsolete

I've now fixed the script and combined the two probe fixes into a single
patch. Here's what the new patch does:

1. Store vdev->priv before creating virtqueues so the event callback
   always sees initialized driver state

2. Check the return value of iommu_device_register() and clean up sysfs
   entries on failure

3. As you suggested, pass vdev instead of viommu to viommu_init_vqs()

I've also dropped the "Reject short event buffers" patch since Xu Rao
independently submitted an identical fix.

The patch is attached below. Could you please take another look?

Sorry again for the confusion.

Best regards,
Xiong Weimin

---

From: Xiong Weimin <xiongweimin@kylinos.cn>
Subject: [PATCH] iommu/virtio: Fix probe error handling and driver state initialization
To: iommu@lists.linux.dev
Cc: will@kernel.org, robin.murphy@arm.com, joro@8bytes.org

The event virtqueue callback retrieves the driver state through
vq->vdev->priv. viommu_probe() currently initializes that pointer only
after virtio_device_ready() and after the event queue is populated.

Store the driver data before creating the virtqueues so callbacks always
see initialized driver state once the device is made ready. Clear the
pointer again on probe failure.

Also check the return value of iommu_device_register() and properly
clean up sysfs entries on failure. This ensures that the device sysfs
directory is removed if registration fails.

As suggested by Will Deacon, pass vdev instead of viommu to
viommu_init_vqs(), since we already linked them together.

Note: The "Reject short event buffers" patch has been dropped as Xu Rao
independently submitted an identical fix.

Suggested-by: Will Deacon <will@kernel.org>
Signed-off-by: Xiong Weimin <xiongweimin@kylinos.cn>
Reviewed-by: Will Deacon <will@kernel.org>
---
 drivers/iommu/virtio-iommu.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index 587fc1319..288eea386 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -1110,9 +1110,9 @@ static const struct iommu_ops viommu_ops = {
 	}
 };
 
-static int viommu_init_vqs(struct viommu_dev *viommu)
+static int viommu_init_vqs(struct virtio_device *vdev)
 {
-	struct virtio_device *vdev = dev_to_virtio(viommu->dev);
+	struct viommu_dev *viommu = vdev->priv;
 	struct virtqueue_info vqs_info[] = {
 		{ "request" },
 		{ "event", viommu_event_handler },
@@ -1169,11 +1169,12 @@ static int viommu_probe(struct virtio_device *vdev)
 	ida_init(&viommu->domain_ids);
 	viommu->dev = dev;
 	viommu->vdev = vdev;
+	vdev->priv = viommu;
 	INIT_LIST_HEAD(&viommu->requests);
 
-	ret = viommu_init_vqs(viommu);
+	ret = viommu_init_vqs(vdev);
 	if (ret)
-		return ret;
+		goto err_clear_priv;
 
 	virtio_cread_le(vdev, struct virtio_iommu_config, page_size_mask,
 			&viommu->pgsize_bitmap);
@@ -1236,7 +1237,9 @@ static int viommu_probe(struct virtio_device *vdev)
 
 	vdev->priv = viommu;
 
-	iommu_device_register(&viommu->iommu, &viommu_ops, parent_dev);
+	ret = iommu_device_register(&viommu->iommu, &viommu_ops, parent_dev);
+	if (ret)
+		goto err_free_sysfs;
 
 	dev_info(dev, "input address: %u bits\n",
 		 order_base_2(viommu->geometry.aperture_end));
@@ -1244,8 +1247,12 @@ static int viommu_probe(struct virtio_device *vdev)
 
 	return 0;
 
+err_free_sysfs:
+	iommu_device_sysfs_remove(&viommu->iommu);
 err_free_vqs:
 	vdev->config->del_vqs(vdev);
+err_clear_priv:
+	vdev->priv = NULL;
 
 	return ret;
 }
-- 
2.43.0

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

end of thread, other threads:[~2026-07-24  2:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260714025913.2042-1-xiongweimin@kylinos.cn>
2026-07-23  3:24 ` [PATCH v3 0/2] iommu/virtio: Probe fixes for proper driver state Xiong Weimin
2026-07-23 11:44   ` Will Deacon
2026-07-24  2:33 ` Xiong Weimin
     [not found] ` <20260724023549.GA2036@myrica>
2026-07-24  2:42   ` [PATCH] iommu/virtio: Fix probe error handling and driver state initialization Xiong Weimin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.