From: Pranjal Shrivastava <praan@google.com>
To: Nicolin Chen <nicolinc@nvidia.com>
Cc: iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
Will Deacon <will@kernel.org>, Jason Gunthorpe <jgg@nvidia.com>,
Kevin Tian <kevin.tian@intel.com>,
Samiullah Khawaja <skhawaja@google.com>,
Peter Shier <pshier@google.com>
Subject: Re: [PATCH] iommu: Honor iommufd uapi for zero entry_num args
Date: Wed, 2 Sep 2026 16:04:15 +0000 [thread overview]
Message-ID: <aphI_yNLYA64iOrw@google.com> (raw)
In-Reply-To: <apg9KNnBSjej2deN@nvidia.com>
On Wed, Sep 02, 2026 at 08:13:44AM -0700, Nicolin Chen wrote:
> On Wed, Sep 02, 2026 at 12:43:33PM +0000, Pranjal Shrivastava wrote:
> > The IOMMU_HWPT_INVALIDATE ioctl uAPI explicitly allows an empty
> > invalidation request array by setting entry_num == 0. The uAPI
> > documentation in include/uapi/linux/iommufd.h mentions:
> >
> > " An empty invalidation request array by setting @entry_num==0
> > is allowed, and @entry_len and @data_uptr would be ignored in
> > this case."
> >
> > While the core iommufd_hwpt_invalidate() handler honors this by
> > skipping its bounds checks, the generic array copy helper
> > iommu_copy_struct_from_full_user_array() incorrectly rejects it
> > by returning -EINVAL, breaking the uAPI.
> >
> > Fix this by returning 0 instead of -EINVAL when entry_num is 0.
>
> I think the caller of this API should be aware of that and check
> the entry_num. I have submitted an SMMU patch doing so:
> https://lore.kernel.org/linux-iommu/5223275dbc8ef00af233f3fee01efa09e45f26b5.1788127877.git.nicolinc@nvidia.com/
>
> Not very sure this API should be changed though..
Ack. Yes, I remember the smmuv3 fix. However, I think other IOMMUs would
trip over this while adding support for invalidation. If not this API,
should we add a note above the cache_invalidate op to remind them?
Furthermore, users of the item-by-item helper (like intel/nested.c) get
entry_num == 0 support naturally because their loop:
for (index = 0; index < array->entry_num; index++)
simply skips execution.
I'm not sure if we should be returning -EINVAL for 0 because nothing's
*really* invalid (and we check index >= src_array->entry_num at places
where it is). It's like getting -EINVAL from copy_from_user for len=0.
I'm okay either way but it feels wrong to have specific users to check
if (entry_num == 0). Would like to discuss this behaviour?
- Praan
prev parent reply other threads:[~2026-09-02 16:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 12:43 [PATCH] iommu: Honor iommufd uapi for zero entry_num args Pranjal Shrivastava
2026-09-02 15:13 ` Nicolin Chen
2026-09-02 16:04 ` Pranjal Shrivastava [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=aphI_yNLYA64iOrw@google.com \
--to=praan@google.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=nicolinc@nvidia.com \
--cc=pshier@google.com \
--cc=skhawaja@google.com \
--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 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.