Linux IOMMU Development
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Steve Sistare <steven.sistare@oracle.com>
Cc: iommu@lists.linux.dev, Kevin Tian <kevin.tian@intel.com>,
	Nicolin Chen <nicolinc@nvidia.com>
Subject: Re: [PATCH V2 5/9] iommufd: IOMMU_IOAS_MAP_FILE implementation
Date: Tue, 1 Oct 2024 17:05:33 -0300	[thread overview]
Message-ID: <20241001200533.GM1365916@nvidia.com> (raw)
In-Reply-To: <1727190338-385692-6-git-send-email-steven.sistare@oracle.com>

On Tue, Sep 24, 2024 at 08:05:34AM -0700, Steve Sistare wrote:

> @@ -199,7 +200,44 @@ static int conv_iommu_prot(u32 map_flags)
>  
>  int iommufd_ioas_map_file(struct iommufd_ucmd *ucmd)
>  {
> -	return -ENOTTY;
> +	struct iommu_ioas_map_file *cmd = ucmd->cmd;
> +	unsigned long iova = cmd->iova;
> +	struct iommufd_ioas *ioas;
> +	unsigned int flags = 0;
> +	int rc;
> +	struct file *file;
> +	unsigned long end;
> +
> +	if (cmd->iova >= ULONG_MAX || cmd->length >= ULONG_MAX)
> +		return -EOVERFLOW;
> +
> +	if (check_add_overflow(cmd->start, cmd->length - 1, &end))
> +		return -EOVERFLOW;

Do we check that length != 0 before doing this math someplace?

> +	ioas = iommufd_get_ioas(ucmd->ictx, cmd->ioas_id);
> +	if (IS_ERR(ioas))
> +		return PTR_ERR(ioas);
> +
> +	if (!(cmd->flags & IOMMU_IOAS_MAP_FIXED_IOVA))
> +		flags = IOPT_ALLOC_IOVA;
> +
> +	file = fget(cmd->fd);
> +	if (!file)
> +		return -EBADF;
> +
> +	rc = iopt_map_file_pages(ucmd->ictx, &ioas->iopt, &iova,
> +				 file, cmd->start,
> +				 cmd->length,
> +				 conv_iommu_prot(cmd->flags), flags);
> +	if (rc)
> +		goto out_put;
> +
> +	cmd->iova = iova;
> +	rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
> +out_put:
> +	iommufd_put_object(ucmd->ictx, &ioas->obj);
> +	fput(file);

I don't see a second fput, what does fput on the success path?

>  int iommufd_ioas_map(struct iommufd_ucmd *ucmd)
> diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c
> index df5ba4f..0a432dc2 100644
> --- a/drivers/iommu/iommufd/pages.c
> +++ b/drivers/iommu/iommufd/pages.c
> @@ -902,7 +902,8 @@ static int update_mm_locked_vm(struct iopt_pages *pages, unsigned long npages,
>  		mmap_read_unlock(pages->source_mm);
>  		user->locked = 0;
>  		/* If we had the lock then we also have a get */
> -	} else if ((!user || !user->upages) &&
> +
> +	} else if ((!user || (!user->upages && !user->ufolios)) &&
>  		   pages->source_mm != current->mm) {
>  		if (!mmget_not_zero(pages->source_mm))
>  			return -EINVAL;

Does this hunk go in an earlier previous patch?

Jason

  parent reply	other threads:[~2024-10-01 20:05 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-24 15:05 [PATCH V2 0/9] iommu_ioas_map_file Steve Sistare
2024-09-24 15:05 ` [PATCH V2 1/9] iommufd: rename uptr in iopt_alloc_iova Steve Sistare
2024-09-27 15:59   ` Jason Gunthorpe
2024-09-24 15:05 ` [PATCH V2 2/9] iommufd: generalize iopt_pages address Steve Sistare
2024-09-24 20:31   ` Nicolin Chen
2024-09-25 22:43     ` Jason Gunthorpe
2024-09-25 23:04       ` Nicolin Chen
2024-09-26 14:48         ` Jason Gunthorpe
2024-09-26 15:48           ` Steven Sistare
2024-10-01 19:54   ` Jason Gunthorpe
2024-09-24 15:05 ` [PATCH V2 3/9] iommufd: pfn reader for file mappings Steve Sistare
2024-09-24 20:53   ` Nicolin Chen
2024-09-26 15:59     ` Steven Sistare
2024-09-25  1:32   ` kernel test robot
2024-09-25  1:55   ` kernel test robot
2024-09-26 14:10   ` Steven Sistare
2024-09-24 15:05 ` [PATCH V2 4/9] iommufd: IOMMU_IOAS_MAP_FILE interface Steve Sistare
2024-10-01 19:58   ` Jason Gunthorpe
2024-09-24 15:05 ` [PATCH V2 5/9] iommufd: IOMMU_IOAS_MAP_FILE implementation Steve Sistare
2024-09-24 21:08   ` Nicolin Chen
2024-09-26 15:50     ` Steven Sistare
2024-10-01 20:05   ` Jason Gunthorpe [this message]
2024-10-02 17:26     ` Steven Sistare
2024-09-24 15:05 ` [PATCH V2 6/9] iommufd: file mappings for mdev Steve Sistare
2024-10-01 20:09   ` Jason Gunthorpe
2024-10-02 17:26     ` Steven Sistare
2024-09-24 15:05 ` [PATCH V2 7/9] iommufd: pfn reader local variables Steve Sistare
2024-10-02 17:29   ` Steven Sistare
2024-10-04 12:16     ` Jason Gunthorpe
2024-09-24 15:05 ` [PATCH V2 8/9] iommufd: optimize file mapping Steve Sistare
2024-10-01 21:03   ` Jason Gunthorpe
2024-10-02 17:26     ` Steven Sistare
2024-10-02 17:29       ` Jason Gunthorpe
2024-10-02 17:51         ` Steven Sistare
2024-09-24 15:05 ` [PATCH V2 9/9] iommufd: map file selftest Steve Sistare
2024-10-01 21:05   ` Jason Gunthorpe
2024-10-02 17:26     ` Steven Sistare
2024-10-02 17:29       ` 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=20241001200533.GM1365916@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=iommu@lists.linux.dev \
    --cc=kevin.tian@intel.com \
    --cc=nicolinc@nvidia.com \
    --cc=steven.sistare@oracle.com \
    /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