All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pranjal Shrivastava <praan@google.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Nicolin Chen <nicolinc@nvidia.com>,
	Kevin Tian <kevin.tian@intel.com>, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Joerg Roedel <joro@8bytes.org>, Peter Shier <pshier@google.com>,
	iommu@lists.linux.dev
Subject: Re: [PATCH v2] iommu: Honor iommufd uapi for zero entry_num args
Date: Mon, 16 Nov 2026 20:31:35 +0000	[thread overview]
Message-ID: <avtoJ88ELacDrquz@google.com> (raw)
In-Reply-To: <20261116202354.GE2245175@nvidia.com>

On Mon, Nov 16, 2026 at 04:23:54PM -0400, Jason Gunthorpe wrote:
> On Mon, Nov 16, 2026 at 08:21:11PM +0000, Pranjal Shrivastava wrote:
> > On Mon, Nov 16, 2026 at 09:08:32AM -0400, Jason Gunthorpe wrote:
> > > On Mon, Nov 16, 2026 at 11:27:20AM +0000, Pranjal Shrivastava wrote:
> > > > On Fri, Nov 13, 2026 at 09:54:45AM -0800, Nicolin Chen wrote:
> > > > > On Thu, Nov 12, 2026 at 03:10:39PM +0000, Pranjal Shrivastava wrote:
> > > > > > @@ -556,7 +556,8 @@ static inline int __iommu_copy_struct_from_user_array(
> > > > > >   * @data_type: The data type of the @kdst. Must match with @user_array->type
> > > > > >   *
> > > > > >   * Copy the entire user array. kdst must have room for kdst_entry_size *
> > > > > > - * user_array->entry_num bytes. Return 0 for success, otherwise -error.
> > > > > > + * user_array->entry_num bytes. An empty array copies nothing, though its
> > > > > > + * @data_type is still validated. Return 0 for success, otherwise -error.
> > > > > >   */
> > > > > >  static inline int
> > > > > >  iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size,
> > > > > > @@ -569,7 +570,7 @@ iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size,
> > > > > >  	if (user_array->type != data_type)
> > > > > >  		return -EINVAL;
> > > > > >  	if (!user_array->entry_num)
> > > > > > -		return -EINVAL;
> > > > > > +		return 0;
> > > > > 
> > > > > TBH, this doesn't seem very necessary..
> > > > > 
> > > > > Though I don't have a problem so long as Jason is okay with it..
> > > > > 
> > > > 
> > > > I know it looks unnecessary in-tree, but zero-length is the documented
> > > > way to check if a @data_type is supported.
> > > 
> > > Is it? I though it was put in 0 length and look for EOPNOTSUPP,
> > > success is not expected.
> > > 
> > 
> > Reading the uAPI comment [1] gives me that understanding:
> > 
> >  /*
> >   * An empty invalidation request array by setting @entry_num==0 is
> >   * allowed, and @entry_len and @data_uptr would be ignored in this case.
> >   * This can be used to check if the given @data_type is supported or
> >   * not by kernel.
> >   */
> > 
> > Hence, for a supported data_type I expect success..
> 
> No, you can't create most of these viommu types without giving actual
> data.
> 
> The comment is unclear, it should be looking for -EOPNOTSUPP.
> 
> > Also, the selftests check exactly that [2]. An unsupported data_type gets
> > -EINVAL from the drivers today, not -EOPNOTSUPP (happy to switch if you
> > prefer).
> 
> EINVAL should only mean that the data inside the struct is
> invalid, but everything else is understood. If the enum itself is not
> known that has to be EOPNOTSUPP
> 

I see! I'll respin the patch to return -EOPNOTSUPP for an unknown
data_type (copy helpers, intel/selftest invalidation ops and the
selftests) and fix the uAPI comment to say the probe should look for
-EOPNOTSUPP. Does that sound fine?

Thanks,
Praan

  reply	other threads:[~2026-11-16 20:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 15:10 [PATCH v2] iommu: Honor iommufd uapi for zero entry_num args Pranjal Shrivastava
2026-11-13 17:54 ` Nicolin Chen
2026-11-16 11:27   ` Pranjal Shrivastava
2026-11-16 13:08     ` Jason Gunthorpe
2026-11-16 20:21       ` Pranjal Shrivastava
2026-11-16 20:23         ` Jason Gunthorpe
2026-11-16 20:31           ` Pranjal Shrivastava [this message]
2026-11-16 23:41             ` 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=avtoJ88ELacDrquz@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=robin.murphy@arm.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.