[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <BN9PR11MB52762B5DAD68943C4C4AB0DD8C90A@BN9PR11MB5276.namprd11.prod.outlook.com>
Date: Thu, 15 May 2025 06:41:04 +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: "bagasdotme@...il.com" <bagasdotme@...il.com>, "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>, "jsnitsel@...hat.com"
<jsnitsel@...hat.com>, "nathan@...nel.org" <nathan@...nel.org>,
"peterz@...radead.org" <peterz@...radead.org>, "Liu, Yi L"
<yi.l.liu@...el.com>, "mshavit@...gle.com" <mshavit@...gle.com>,
"praan@...gle.com" <praan@...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>, "mochs@...dia.com" <mochs@...dia.com>,
"alok.a.tiwari@...cle.com" <alok.a.tiwari@...cle.com>, "vasant.hegde@....com"
<vasant.hegde@....com>
Subject: RE: [PATCH v4 14/23] iommufd: Add mmap interface
> From: Nicolin Chen <nicolinc@...dia.com>
> Sent: Friday, May 9, 2025 11:03 AM
>
> +/*
> + * Kernel driver must first use the for-driver helpers to register an
> mmappable
> + * MMIO region to the iommufd core to allocate an offset. Then, it should
> report
> + * to user space this offset and the length of the MMIO region for mmap
> syscall,
> + * via a prior IOMMU_VIOMMU_ALLOC ioctl.
> + */
this comment better suits _iommufd_alloc_mmap()
> +static int iommufd_fops_mmap(struct file *filp, struct vm_area_struct *vma)
> +{
> + struct iommufd_ctx *ictx = filp->private_data;
> + size_t length = vma->vm_end - vma->vm_start;
> + struct iommufd_mmap *immap;
> + int rc;
> +
> + if (!PAGE_ALIGNED(length))
> + return -EINVAL;
> + if (!(vma->vm_flags & VM_SHARED))
> + return -EINVAL;
> + if (vma->vm_flags & VM_EXEC)
> + return -EPERM;
> +
> + /* vma->vm_pgoff carries an index to an mtree entry (immap) */
> + immap = mtree_load(&ictx->mt_mmap, vma->vm_pgoff);
> + if (!immap)
> + return -ENXIO;
> + if (length >> PAGE_SHIFT != immap->num_pfns)
> + return -ENXIO;
> +
> + vma->vm_pgoff = 0;
> + vma->vm_private_data = immap;
> + vma->vm_ops = &iommufd_vma_ops;
> + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
> + vm_flags_set(vma, VM_PFNMAP | VM_DONTEXPAND |
> VM_DONTDUMP | VM_IO);
> +
> + rc = remap_pfn_range(vma, vma->vm_start, immap->base_pfn,
> length,
> + vma->vm_page_prot);
> + if (!rc) /* vm_ops.open won't be called for mmap itself. */
> + refcount_inc(&immap->owner->users);
> + return rc;
let's add some words for this refcnt thing in the commit msg.
Reviewed-by: Kevin Tian <kevin.tian@...el.com>
Powered by blists - more mailing lists