[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <BN9PR11MB527664BDB7933FA0B7981EE68CB82@BN9PR11MB5276.namprd11.prod.outlook.com>
Date: Mon, 21 Apr 2025 08:16:54 +0000
From: "Tian, Kevin" <kevin.tian@...el.com>
To: Nicolin Chen <nicolinc@...dia.com>, "jgg@...dia.com" <jgg@...dia.com>,
"corbet@....net" <corbet@....net>, "will@...nel.org" <will@...nel.org>
CC: "robin.murphy@....com" <robin.murphy@....com>, "joro@...tes.org"
<joro@...tes.org>, "thierry.reding@...il.com" <thierry.reding@...il.com>,
"vdumpa@...dia.com" <vdumpa@...dia.com>, "jonathanh@...dia.com"
<jonathanh@...dia.com>, "shuah@...nel.org" <shuah@...nel.org>,
"praan@...gle.com" <praan@...gle.com>, "nathan@...nel.org"
<nathan@...nel.org>, "peterz@...radead.org" <peterz@...radead.org>, "Liu, Yi
L" <yi.l.liu@...el.com>, "jsnitsel@...hat.com" <jsnitsel@...hat.com>,
"mshavit@...gle.com" <mshavit@...gle.com>, "zhangzekun11@...wei.com"
<zhangzekun11@...wei.com>, "iommu@...ts.linux.dev" <iommu@...ts.linux.dev>,
"linux-doc@...r.kernel.org" <linux-doc@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>, "linux-tegra@...r.kernel.org"
<linux-tegra@...r.kernel.org>, "linux-kselftest@...r.kernel.org"
<linux-kselftest@...r.kernel.org>, "patches@...ts.linux.dev"
<patches@...ts.linux.dev>
Subject: RE: [PATCH v1 10/16] iommufd: Add mmap interface
> From: Nicolin Chen <nicolinc@...dia.com>
> Sent: Friday, April 11, 2025 2:38 PM
>
> For vIOMMU passing through HW resources to user space (VMs), add an
> mmap
> infrastructure to map a region of hardware MMIO pages. The addr and size
> should be given previously via a prior IOMMU_VIOMMU_ALLOC ioctl in some
> output fields of the structure.
According to the code the addr must be the immap_id given by previous
alloc but size can be any as long as it doesn't exceed the physical length.
>
> +/* Entry for iommufd_ctx::mt_mmap */
> +struct iommufd_mmap {
> + unsigned long pfn_start;
> + unsigned long pfn_end;
> + bool is_io;
> +};
what is the point of 'is_io' here? Do you intend to allow userspace to
mmap anonymous memory via iommufd?
anyway for now the only user in this series always sets it to true.
I'd suggest to remove it until there is a real need.
>
> +/*
> + * The pfn and size carried in @vma from the user space mmap call should
> be
there is no 'pfn' carried in the mmap call. It's vm_pgoff.
> + * previously given to user space via a prior ioctl output.
> + */
> +static int iommufd_fops_mmap(struct file *filp, struct vm_area_struct *vma)
> +{
> + struct iommufd_ctx *ictx = filp->private_data;
> + size_t size = vma->vm_end - vma->vm_start;
> + struct iommufd_mmap *immap;
> +
> + if (size & ~PAGE_MASK)
> + return -EINVAL;
> + if (!(vma->vm_flags & VM_SHARED))
> + return -EINVAL;
> + if (vma->vm_flags & VM_EXEC)
> + return -EPERM;
> +
> + /* vm_pgoff carries an index of an mtree entry/immap */
> + immap = mtree_load(&ictx->mt_mmap, vma->vm_pgoff);
> + if (!immap)
> + return -EINVAL;
> + if (size >> PAGE_SHIFT > immap->pfn_end - immap->pfn_start + 1)
> + return -EINVAL;
Do we want to document in uAPI that iommufd mmap allows to map
a sub-region (starting from offset zero) of the reported size from earlier
alloc ioctl, but not from random offset (of course impossible by forcing
vm_pgoff to be a mtree index)?
Powered by blists - more mailing lists