LKML Archive on lore.kernel.org help / color / mirror / Atom feed
From: Nicolin Chen <nicolinc@nvidia.com> To: <will@kernel.org>, <robin.murphy@arm.com>, <joro@8bytes.org>, <alex.williamson@redhat.com>, <cohuck@redhat.com>, <corbet@lwn.net> Cc: <nicoleotsuka@gmail.com>, <vdumpa@nvidia.com>, <thierry.reding@gmail.com>, <linux-tegra@vger.kernel.org>, <nwatterson@nvidia.com>, <Jonathan.Cameron@huawei.com>, <jean-philippe@linaro.org>, <song.bao.hua@hisilicon.com>, <eric.auger@redhat.com>, <thunder.leizhen@huawei.com>, <yuzenghui@huawei.com>, <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <iommu@lists.linux-foundation.org>, <kvm@vger.kernel.org>, <linux-doc@vger.kernel.org> Subject: [RFC][PATCH v2 02/13] vfio: add VFIO_IOMMU_GET_VMID and VFIO_IOMMU_SET_VMID Date: Mon, 30 Aug 2021 19:59:12 -0700 [thread overview] Message-ID: <20210831025923.15812-3-nicolinc@nvidia.com> (raw) In-Reply-To: <20210831025923.15812-1-nicolinc@nvidia.com> This patch adds a pair of new ioctl commands to communicate with user space (virtual machine hypervisor) to get and set VMID that indicates a Virtual Machine Identifier, being used by some IOMMU to tag TLB entries -- similar to CPU MMU, using this VMID number allows IOMMU to invalidate at the same time TLBs of the same VM. Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> --- drivers/vfio/vfio.c | 13 +++++++++++++ include/uapi/linux/vfio.h | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 3c034fe14ccb..c17b25c127a2 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -59,6 +59,7 @@ struct vfio_container { struct rw_semaphore group_lock; struct vfio_iommu_driver *iommu_driver; void *iommu_data; + u32 vmid; bool noiommu; }; @@ -1190,6 +1191,16 @@ static long vfio_fops_unl_ioctl(struct file *filep, case VFIO_SET_IOMMU: ret = vfio_ioctl_set_iommu(container, arg); break; + case VFIO_IOMMU_GET_VMID: + ret = copy_to_user((void __user *)arg, &container->vmid, + sizeof(u32)) ? -EFAULT : 0; + break; + case VFIO_IOMMU_SET_VMID: + if ((u32)arg == VFIO_IOMMU_VMID_INVALID) + return -EINVAL; + container->vmid = (u32)arg; + ret = 0; + break; default: driver = container->iommu_driver; data = container->iommu_data; @@ -1213,6 +1224,8 @@ static int vfio_fops_open(struct inode *inode, struct file *filep) init_rwsem(&container->group_lock); kref_init(&container->kref); + container->vmid = VFIO_IOMMU_VMID_INVALID; + filep->private_data = container; return 0; diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index ef33ea002b0b..58c5fa6aaca6 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -1216,6 +1216,32 @@ struct vfio_iommu_type1_dirty_bitmap_get { #define VFIO_IOMMU_DIRTY_PAGES _IO(VFIO_TYPE, VFIO_BASE + 17) +/** + * VFIO_IOMMU_GET_VMID - _IOWR(VFIO_TYPE, VFIO_BASE + 22, __u32 *vmid) + * VFIO_IOMMU_SET_VMID - _IOWR(VFIO_TYPE, VFIO_BASE + 23, __u32 vmid) + * + * IOCTLs are used for VMID alignment between Kernel and User Space hypervisor. + * In a virtualization use case, a guest owns the first stage translation, and + * the hypervisor owns the second stage translation. VMID is an Virtual Machine + * Identifier that is to tag TLB entries of a VM. If a VM has multiple physical + * devices being assigned to it, while these devices are under different IOMMU + * domains, the VMIDs in the second stage configurations of these IOMMU domains + * could be aligned to a unified VMID value. This could be achieved by using + * these two IOCTLs. + * + * Caller should get VMID upon its initial value when the first physical device + * is assigned to the VM. + * + * Caller then should set VMID to share the same VMID value with other physical + * devices being assigned to the same VM. + * + */ +#define VFIO_IOMMU_VMID_INVALID (-1U) + +#define VFIO_IOMMU_GET_VMID _IO(VFIO_TYPE, VFIO_BASE + 22) + +#define VFIO_IOMMU_SET_VMID _IO(VFIO_TYPE, VFIO_BASE + 23) + /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */ /* -- 2.17.1
next prev parent reply other threads:[~2021-08-31 3:07 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-31 2:59 [RFC][PATCH v2 00/13] iommu/arm-smmu-v3: Add NVIDIA implementation Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 01/13] iommu: Add set_nesting_vmid/get_nesting_vmid functions Nicolin Chen 2021-08-31 2:59 ` Nicolin Chen [this message] 2021-08-31 2:59 ` [RFC][PATCH v2 03/13] vfio: Document VMID control for IOMMU Virtualization Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 04/13] vfio: add set_vmid and get_vmid for vfio_iommu_type1 Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 05/13] vfio/type1: Implement set_vmid and get_vmid Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 06/13] vfio/type1: Set/get VMID to/from iommu driver Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 07/13] iommu/arm-smmu-v3: Add shared VMID support for NESTING Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 08/13] iommu/arm-smmu-v3: Add VMID alloc/free helpers Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 09/13] iommu/arm-smmu-v3: Pass dev pointer to arm_smmu_detach_dev Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 10/13] iommu/arm-smmu-v3: Pass cmdq pointer in arm_smmu_cmdq_issue_cmdlist() Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 11/13] iommu/arm-smmu-v3: Add implementation infrastructure Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 12/13] iommu/arm-smmu-v3: Add support for NVIDIA CMDQ-Virtualization hw Nicolin Chen 2021-08-31 2:59 ` [RFC][PATCH v2 13/13] iommu/nvidia-smmu-v3: Add mdev interface support Nicolin Chen 2021-08-31 16:15 ` [RFC][PATCH v2 00/13] iommu/arm-smmu-v3: Add NVIDIA implementation Alex Williamson 2021-09-01 6:55 ` Tian, Kevin 2021-09-02 14:45 ` Jason Gunthorpe 2021-09-02 22:27 ` Tian, Kevin 2021-09-16 18:21 ` Nicolin Chen
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=20210831025923.15812-3-nicolinc@nvidia.com \ --to=nicolinc@nvidia.com \ --cc=Jonathan.Cameron@huawei.com \ --cc=alex.williamson@redhat.com \ --cc=cohuck@redhat.com \ --cc=corbet@lwn.net \ --cc=eric.auger@redhat.com \ --cc=iommu@lists.linux-foundation.org \ --cc=jean-philippe@linaro.org \ --cc=joro@8bytes.org \ --cc=kvm@vger.kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-doc@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-tegra@vger.kernel.org \ --cc=nicoleotsuka@gmail.com \ --cc=nwatterson@nvidia.com \ --cc=robin.murphy@arm.com \ --cc=song.bao.hua@hisilicon.com \ --cc=thierry.reding@gmail.com \ --cc=thunder.leizhen@huawei.com \ --cc=vdumpa@nvidia.com \ --cc=will@kernel.org \ --cc=yuzenghui@huawei.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: linkBe 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; as well as URLs for NNTP newsgroup(s).