From: Nicolin Chen <nicolinc@nvidia.com>
To: <jgg@nvidia.com>, <kevin.tian@intel.com>
Cc: <joro@8bytes.org>, <baolu.lu@linux.intel.com>,
<iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>
Subject: [PATCH v1 3/7] iommufd: Propagate allocation failure in iommufd_veventq_deliver_fetch()
Date: Mon, 1 Jun 2026 13:42:34 -0700 [thread overview]
Message-ID: <25d29feac909e36f78c145fa99ef2d4cb7a415da.1780343944.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1780343944.git.nicolinc@nvidia.com>
When the kzalloc_obj() fails in iommufd_veventq_deliver_fetch(), it returns
NULL, falsely advertising to userspace that the queue is empty.
Propagate the -ENOMEM properly to the caller.
Fixes: e36ba5ab808e ("iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC")
Cc: stable@vger.kernel.org
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/iommufd/eventq.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/iommufd/eventq.c b/drivers/iommu/iommufd/eventq.c
index ac485d010a439..f55d173c59f61 100644
--- a/drivers/iommu/iommufd/eventq.c
+++ b/drivers/iommu/iommufd/eventq.c
@@ -264,8 +264,10 @@ iommufd_veventq_deliver_fetch(struct iommufd_veventq *veventq)
/* Make a copy of the lost_events_header for copy_to_user */
if (next == &veventq->lost_events_header) {
vevent = kzalloc_obj(*vevent, GFP_ATOMIC);
- if (!vevent)
+ if (!vevent) {
+ vevent = ERR_PTR(-ENOMEM);
goto out_unlock;
+ }
}
list_del(&next->node);
if (vevent)
@@ -315,6 +317,12 @@ static ssize_t iommufd_veventq_fops_read(struct file *filep, char __user *buf,
return -EINVAL;
while ((cur = iommufd_veventq_deliver_fetch(veventq))) {
+ if (IS_ERR(cur)) {
+ if (done == 0)
+ rc = PTR_ERR(cur);
+ break;
+ }
+
/* Validate the remaining bytes against the header size */
if (done >= count || sizeof(*hdr) > count - done) {
iommufd_veventq_deliver_restore(veventq, cur);
--
2.43.0
next prev parent reply other threads:[~2026-06-01 20:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-01 20:42 [PATCH v1 0/7] iommufd: Fix bugs in eventq fops_read paths Nicolin Chen
2026-06-01 20:42 ` [PATCH v1 1/7] iommufd: Rewind header length in done if iommufd_veventq_fops_read() fails Nicolin Chen
2026-06-03 14:01 ` Pranjal Shrivastava
2026-06-01 20:42 ` [PATCH v1 2/7] iommufd: Reject invalid read count in iommufd_veventq_fops_read() Nicolin Chen
2026-06-03 14:08 ` Pranjal Shrivastava
2026-06-01 20:42 ` Nicolin Chen [this message]
2026-06-03 14:13 ` [PATCH v1 3/7] iommufd: Propagate allocation failure in iommufd_veventq_deliver_fetch() Pranjal Shrivastava
2026-06-01 20:42 ` [PATCH v1 4/7] iommufd: Reject invalid read count in iommufd_fault_fops_read() Nicolin Chen
2026-06-03 14:15 ` Pranjal Shrivastava
2026-06-01 20:42 ` [PATCH v1 5/7] iommufd: Break the loop on failure " Nicolin Chen
2026-06-03 14:18 ` Pranjal Shrivastava
2026-06-01 20:42 ` [PATCH v1 6/7] iommufd: Avoid partial fault group delivery " Nicolin Chen
2026-06-03 14:26 ` Pranjal Shrivastava
2026-06-01 20:42 ` [PATCH v1 7/7] iommufd/selftest: Cover invalid read counts on vEVENTQ FD Nicolin Chen
2026-06-03 14:46 ` Pranjal Shrivastava
2026-06-02 6:27 ` [PATCH v1 0/7] iommufd: Fix bugs in eventq fops_read paths Nicolin Chen
2026-06-03 6:59 ` Tian, Kevin
2026-06-05 14:30 ` Jason Gunthorpe
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=25d29feac909e36f78c145fa99ef2d4cb7a415da.1780343944.git.nicolinc@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.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®