From: Qihang <q.h.hack.winter@gmail.com>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>
Cc: Qihang <q.h.hack.winter@gmail.com>,
Robin Murphy <robin.murphy@arm.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH 2/2] iommu/io-pgfault: reject partial faults after the device is removed
Date: Tue, 17 Nov 2026 09:54:09 +0800 [thread overview]
Message-ID: <20261117015409.25492-3-q.h.hack.winter@gmail.com> (raw)
In-Reply-To: <20261117015409.25492-1-q.h.hack.winter@gmail.com>
A report that already holds a reference to the fault_param can still
reach report_partial_fault() after iopf_queue_remove_device() drained
the partial list. The node it queues there leaks: the parameter is no
longer on queue->devices and its final put does not free partial
faults.
Reject late partial insertions under fault_param->lock: add
fault_param->removing, set it in iopf_queue_remove_device() before
the drain, and test it in report_partial_fault() under the same lock
that the insertion takes, so "check" and "link" cannot be separated. A
partial is then either drained or rejected and freed by
report_partial_fault() itself, which returns -ENODEV; as for any
non-last request, no response is sent. removing is never cleared,
since IOPF re-enable allocates a new fault_param.
This only protects partial-list admission; callers must still quiesce
reports for the remaining lifetimes. It is not a general teardown
fix; the cover letter lists the paths it does not cover.
Fixes: a74c077b9021 ("iommu: Use refcount for fault data access")
Cc: stable@vger.kernel.org
Signed-off-by: Qihang <q.h.hack.winter@gmail.com>
---
This applies on top of "iommu/io-pgfault: unlink partial faults before
freeing them".
drivers/iommu/io-pgfault.c | 12 ++++++++++--
include/linux/iommu.h | 3 +++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c
index 55a3c29..51d0d1a 100644
--- a/drivers/iommu/io-pgfault.c
+++ b/drivers/iommu/io-pgfault.c
@@ -64,6 +64,7 @@ static int report_partial_fault(struct iommu_fault_param *fault_param,
struct iommu_fault *fault)
{
struct iopf_fault *iopf;
+ int ret = 0;
iopf = kzalloc_obj(*iopf);
if (!iopf)
@@ -72,10 +73,16 @@ static int report_partial_fault(struct iommu_fault_param *fault_param,
iopf->fault = *fault;
mutex_lock(&fault_param->lock);
- list_add(&iopf->list, &fault_param->partial);
+ if (fault_param->removing)
+ ret = -ENODEV;
+ else
+ list_add(&iopf->list, &fault_param->partial);
mutex_unlock(&fault_param->lock);
- return 0;
+ if (ret)
+ kfree(iopf);
+
+ return ret;
}
static struct iopf_group *iopf_group_alloc(struct iommu_fault_param *iopf_param,
@@ -479,6 +486,7 @@ void iopf_queue_remove_device(struct iopf_queue *queue, struct device *dev)
goto unlock;
mutex_lock(&fault_param->lock);
+ fault_param->removing = true;
list_for_each_entry_safe(partial_iopf, next, &fault_param->partial, list) {
list_del(&partial_iopf->list);
kfree(partial_iopf);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ef50437..5d56e66 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -846,6 +846,8 @@ struct iommu_device {
* @partial: faults that are part of a Page Request Group for which the last
* request hasn't been submitted yet.
* @faults: holds the pending faults which need response
+ * @removing: the device is being removed from the queue, no new partial
+ * faults may be queued
*/
struct iommu_fault_param {
struct mutex lock;
@@ -858,6 +860,7 @@ struct iommu_fault_param {
struct list_head partial;
struct list_head faults;
+ bool removing;
};
/**
prev parent reply other threads:[~2026-11-17 1:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 1:54 [PATCH 0/2] iommu/io-pgfault: reject partial faults after device removal Qihang
2026-11-17 1:54 ` [PATCH 1/2] iommu/io-pgfault: unlink partial faults before freeing them Qihang
2026-11-17 1:54 ` Qihang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117015409.25492-3-q.h.hack.winter@gmail.com \
--to=q.h.hack.winter@gmail.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=stable@vger.kernel.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®