iommu/arm-smmu-v3: Add NVIDIA implementation
Subsystems (6)
v2 cover iommu/arm-smmu-v3: Add NVIDIA implementation
The SMMUv3 devices implemented in the Grace SoC support NVIDIA's custom CMDQ-Virtualization (CMDQV) hardware. Like the new ECMDQ feature first introduced in the ARM SMMUv3.3 specification, CMDQV adds multiple VCMDQ interfaces to supplement the single architected SMMU_CMDQ in an effort to reduce contention.
This series of patches add CMDQV support with its preparational changes:
* PATCH-1 to PATCH-8 are related to shared VMID feature: they are used first to improve TLB utilization, second to bind a shared VMID with a VCMDQ interface for hardware configuring requirement.
* PATCH-9 and PATCH-10 are to accommodate the NVIDIA implementation with the existing arm-smmu-v3 driver.
* PATCH-11 borrows the "implementation infrastructure" from the arm-smmu driver so later change can build upon it.
* PATCH-12 adds an initial NVIDIA implementation related to host feature, and also adds implementation specific ->device_reset() and ->get_cmdq() callback functions.
* PATCH-13 adds virtualization features using VFIO mdev interface, which allows user space hypervisor to map and get access to one of the VCMDQ interfaces of CMDQV module.
( Thinking that reviewers can get a better view of this implementation,
I am attaching QEMU changes here for reference purpose:
https://github.com/nicolinc/qemu/commits/dev/cmdqv_v6.0.0-rc2
The branch has all preparational changes, while I'm still integrating device model and ARM-VIRT changes, and will push them these two days, although they might not be in a good shape of being sent to review yet )
Above all, I marked RFC for this series, as I feel that we may come up some better solution. So please kindly share your reviews and insights.
Thank you!
Changelogv1->v2:
* Added mdev interface support for hypervisor and VMs.
* Added preparational changes for mdev interface implementation.
* PATCH-12 Changed ->issue_cmdlist() to ->get_cmdq() for a better integration with recently merged ECMDQ-related changes.
Nate Watterson (3):
iommu/arm-smmu-v3: Add implementation infrastructure iommu/arm-smmu-v3: Add support for NVIDIA CMDQ-Virtualization hw iommu/nvidia-smmu-v3: Add mdev interface support
Nicolin Chen (10):
iommu: Add set_nesting_vmid/get_nesting_vmid functions
vfio: add VFIO_IOMMU_GET_VMID and VFIO_IOMMU_SET_VMID
vfio: Document VMID control for IOMMU Virtualization
vfio: add set_vmid and get_vmid for vfio_iommu_type1 vfio/type1: Implement set_vmid and get_vmid
vfio/type1: Set/get VMID to/from iommu driver iommu/arm-smmu-v3: Add shared VMID support for NESTING iommu/arm-smmu-v3: Add VMID alloc/free helpers iommu/arm-smmu-v3: Pass dev pointer to arm_smmu_detach_dev iommu/arm-smmu-v3: Pass cmdq pointer in arm_smmu_cmdq_issue_cmdlist()
Documentation/driver-api/vfio.rst | 34 + MAINTAINERS | 2 + drivers/iommu/arm/arm-smmu-v3/Makefile | 2 +- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-impl.c | 15 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 121 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 18 + .../iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c | 1249 +++++++++++++++++ drivers/iommu/iommu.c | 20 + drivers/vfio/vfio.c | 25 + drivers/vfio/vfio_iommu_type1.c | 37 + include/linux/iommu.h | 5 + include/linux/vfio.h | 2 + include/uapi/linux/vfio.h | 26 + 13 files changed, 1537 insertions(+), 19 deletions(-) create mode 100644 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-impl.c create mode 100644 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c
Signature · 1 line
2.17.1
RFC PATCH v2 1/13 iommu: Add set_nesting_vmid/get_nesting_vmid functions
VMID stands for Virtual Machine Identifier, being used to tag TLB entries to indicate which VM they belong to. This is used by some IOMMU like SMMUv3 for virtualization case, in nesting mode.
So this patch adds a pair of new iommu_ops callback functions with a pair of exported set/get functions to allow VFIO core to get access of the VMID value in an IOMMU driver.
--- drivers/iommu/iommu.c | 20 ++++++++++++++++++++ include/linux/iommu.h | 5 +++++ 2 files changed, 25 insertions(+)
drivers/iommu/iommu.c +20 -0
@@ -2774,6 +2774,26 @@ int iommu_enable_nesting(struct iommu_domain *domain) }EXPORT_SYMBOL_GPL (iommu_enable_nesting); +int iommu_set_nesting_vmid (struct iommu_domain *domain,u32 vmid) +{ +if (domain->type !=IOMMU_DOMAIN_UNMANAGED ) +return -EINVAL ; +if (!domain->ops->set_nesting_vmid) +return -EINVAL ; +return domain->ops->set_nesting_vmid (domain, vmid); +} +EXPORT_SYMBOL_GPL (iommu_set_nesting_vmid); + +int iommu_get_nesting_vmid (struct iommu_domain *domain,u32 *vmid) +{ +if (domain->type !=IOMMU_DOMAIN_UNMANAGED ) +return -EINVAL ; +if (!domain->ops->get_nesting_vmid) +return -EINVAL ; +return domain->ops->get_nesting_vmid (domain, vmid); +} +EXPORT_SYMBOL_GPL (iommu_get_nesting_vmid); +int iommu_set_pgtable_quirks (struct iommu_domain *domain,unsigned long quirk) {
include/linux/iommu.h +5 -0
@@ -163,6 +163,7 @@ enum iommu_dev_features { };#define IOMMU_PASID_INVALID (-1U) +#define IOMMU_VMID_INVALID (-1U)#ifdef CONFIG_IOMMU_API
@@ -269,6 +270,8 @@ struct iommu_ops {void (*probe_finalize)(struct device *dev);struct iommu_group *(*device_group)(struct device *dev);int (*enable_nesting)(struct iommu_domain *domain); +int (*set_nesting_vmid)(struct iommu_domain *domain,u32 vmid); +int (*get_nesting_vmid)(struct iommu_domain *domain,u32 *vmid);int (*set_pgtable_quirks)(struct iommu_domain *domain,unsigned long quirks);
@@ -500,6 +503,8 @@ extern int iommu_group_id(struct iommu_group *group);extern struct iommu_domain *iommu_group_default_domain (struct iommu_group *);int iommu_enable_nesting (struct iommu_domain *domain); +int iommu_set_nesting_vmid (struct iommu_domain *domain,u32 vmid); +int iommu_get_nesting_vmid (struct iommu_domain *domain,u32 *vmid);int iommu_set_pgtable_quirks (struct iommu_domain *domain,unsigned long quirks);
Signature · 6 lines
2.17.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
RFC PATCH v2 2/13 vfio: add VFIO_IOMMU_GET_VMID and VFIO_IOMMU_SET_VMID
In reply to Nicolin ChenThis 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.
--- drivers/vfio/vfio.c | 13 +++++++++++++ include/uapi/linux/vfio.h | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
drivers/vfio/vfio.c +13 -0
@@ -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 ;
include/uapi/linux/vfio.h +26 -0
@@ -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 -------- */ /*
Signature · 1 line
2.17.1
RFC PATCH v2 3/13 vfio: Document VMID control for IOMMU Virtualization
In reply to Nicolin ChenThe VFIO API was enhanced to support VMID control with two new iotcls to set and get VMID between the kernel and the virtual machine hypervisor. So updating the document.
--- Documentation/driver-api/vfio.rst | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
Documentation/driver-api/vfio.rst +34 -0
@@ -239,6 +239,40 @@ group and can access them as follows:: /* Gratuitous device reset and go... */ ioctl(device, VFIO_DEVICE_RESET); +IOMMU Virtual Machine Identifier (VMID) +------------------------ +In case of virtualization, each VM is assigned a Virtual Machine Identifier +(VMID). This VMID is used to tag translation lookaside buffer (TLB) entries, +to identify which VM each entry belongs to. This tagging allows translations +for multiple different VMs to be present in the TLBs at the same time. + +The IOMMU Kernel driver is responsible for allocating a VMID. However, only +a hypervisor knows what physical devices get assigned to the same VM. Thus, +when the first physical device gets assigned to the VM, once the hypervisor +finishes its IOCTL call of VFIO_SET_IOMMU, it should call the following: + +struct vm { + int iommu_type; + uint32_t vmid; /* initial value is VFIO_IOMMU_VMID_INVALID */ +} vm0; + + /* ... */ + ioctl(container->fd, VFIO_SET_IOMMU, vm0->iommu_type); + /* ... */ + if (vm0->vmid == VFIO_IOMMU_VMID_INVALID) + ioctl(container->fd, VFIO_IOMMU_GET_VMID, &vm0->vmid); + +This VMID would be the shared value, across the entire VM, between all the +physical devices that are assigned to it. So, when other physical devices +get assigned to the VM, before the hypervisor runs into the IOCTL call of +VFIO_IOMMU_SET_VMID, it should call the following: + + /* ... */ + ioctl(container->fd, VFIO_SET_IOMMU, vm0->iommu_type); + /* ... */ + if (vm0->vmid != VFIO_IOMMU_VMID_INVALID) + ioctl(container->fd, VFIO_IOMMU_SET_VMID, vmid); + VFIO User API -------------------------------------------------------------------------------
Signature · 1 line
2.17.1
RFC PATCH v2 4/13 vfio: add set_vmid and get_vmid for vfio_iommu_type1
In reply to Nicolin ChenA VMID is generated in an IOMMU driver, being called from this ->attach_group() callback. So call ->get_vmid() right after it creates a new VMID, and call ->set_vmid() before it, to let it reuse the same VMID.
--- drivers/vfio/vfio.c | 12 ++++++++++++ include/linux/vfio.h | 2 ++ 2 files changed, 14 insertions(+)
drivers/vfio/vfio.c +12 -0
@@ -1080,9 +1080,21 @@ static int __vfio_container_attach_groups(struct vfio_container *container,int ret = -ENODEV ;list_for_each_entry (group, &container->group_list, container_next) { +if (driver->ops->set_vmid && container->vmid !=VFIO_IOMMU_VMID_INVALID ) { + ret = driver->ops->set_vmid (data, container->vmid); +if (ret) + goto unwind; + } + ret = driver->ops->attach_group (data, group->iommu_group);if (ret) goto unwind; + +if (driver->ops->get_vmid && container->vmid ==VFIO_IOMMU_VMID_INVALID ) { + ret = driver->ops->get_vmid (data, &container->vmid); +if (ret) + goto unwind; + } }return ret;
include/linux/vfio.h +2 -0
@@ -126,6 +126,8 @@ struct vfio_iommu_driver_ops { struct iommu_group *group);void (*notify)(void *iommu_data,enum vfio_iommu_notify_type event); +int (*set_vmid)(void *iommu_data,u32 vmid); +int (*get_vmid)(void *iommu_data,u32 *vmid); };extern int vfio_register_iommu_driver (const struct vfio_iommu_driver_ops *ops);
Signature · 1 line
2.17.1
RFC PATCH v2 5/13 vfio/type1: Implement set_vmid and get_vmid
In reply to Nicolin ChenNow we have a pair of ->set_vmid() and ->get_vmid() function pointers. This patch implements them, to exchange VMID value between vfio container and vfio_iommu_type1.
--- drivers/vfio/vfio_iommu_type1.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/vfio/vfio_iommu_type1.c +25 -0
@@ -74,6 +74,7 @@ struct vfio_iommu {uint64_t pgsize_bitmap;uint64_t num_non_pinned_groups;wait_queue_head_t vaddr_wait; +uint32_t vmid;bool v2;bool nesting;bool dirty_page_tracking;
@@ -2674,6 +2675,7 @@ static void *vfio_iommu_type1_open(unsigned long arg) iommu->dma_list =RB_ROOT ; iommu->dma_avail = dma_entry_limit; iommu->container_open = true; + iommu->vmid =VFIO_IOMMU_VMID_INVALID ;mutex_init (&iommu->lock);BLOCKING_INIT_NOTIFIER_HEAD (&iommu->notifier);init_waitqueue_head (&iommu->vaddr_wait);
@@ -3255,6 +3257,27 @@ static void vfio_iommu_type1_notify(void *iommu_data,wake_up_all (&iommu->vaddr_wait); } +static int vfio_iommu_type1_get_vmid (void *iommu_data,u32 *vmid) +{ +struct vfio_iommu *iommu = iommu_data; + + *vmid = iommu->vmid; + +return 0 ; +} + +static int vfio_iommu_type1_set_vmid (void *iommu_data,u32 vmid) +{ +struct vfio_iommu *iommu = iommu_data; + +if (vmid ==VFIO_IOMMU_VMID_INVALID ) +return -EINVAL ; + + iommu->vmid = vmid; + +return 0 ; +} +static const struct vfio_iommu_driver_ops vfio_iommu_driver_ops_type1 = { .name ="vfio-iommu-type1" , .owner =THIS_MODULE ,
@@ -3270,6 +3293,8 @@ static const struct vfio_iommu_driver_ops vfio_iommu_driver_ops_type1 = { .dma_rw = vfio_iommu_type1_dma_rw, .group_iommu_domain = vfio_iommu_type1_group_iommu_domain, .notify = vfio_iommu_type1_notify, + .set_vmid = vfio_iommu_type1_set_vmid, + .get_vmid = vfio_iommu_type1_get_vmid, };static int __init vfio_iommu_type1_init (void )
Signature · 1 line
2.17.1
RFC PATCH v2 6/13 vfio/type1: Set/get VMID to/from iommu driver
In reply to Nicolin ChenThis patch adds a pair of callbacks of iommu_set_nesting_vmid() and iommu_get_nesting_vmid() to exchange VMID with the IOMMU core (then an IOMMU driver).
As a VMID is generated in an IOMMU driver, which is called from the vfio_iommu_attach_group() function call, add iommu_get_nesting_vmid right after it creates a VMID and add iommu_set_nesting_vmid before it to let IOMMU driver reuse it.
--- drivers/vfio/vfio_iommu_type1.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/vfio/vfio_iommu_type1.c +12 -0
@@ -2322,12 +2322,24 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, ret =iommu_enable_nesting (domain->domain);if (ret) goto out_domain; + +if (iommu->vmid !=VFIO_IOMMU_VMID_INVALID ) { + ret =iommu_set_nesting_vmid (domain->domain, iommu->vmid); +if (ret) + goto out_domain; + } } ret =vfio_iommu_attach_group (domain, group);if (ret) goto out_domain; +if (iommu->nesting && iommu->vmid ==VFIO_IOMMU_VMID_INVALID ) { + ret =iommu_get_nesting_vmid (domain->domain, &iommu->vmid); +if (ret) + goto out_domain; + } +/* Get aperture info */ geo = &domain->domain->geometry; if (vfio_iommu_aper_conflict(iommu, geo->aperture_start,
Signature · 1 line
2.17.1
RFC PATCH v2 7/13 iommu/arm-smmu-v3: Add shared VMID support for NESTING
In reply to Nicolin ChenA VMID can be shared among iommu domains being attached to the same Virtual Machine in order to improve utilization of TLB cache.
This patch implements ->set_nesting_vmid() and ->get_nesting_vmid() to set/get s2_cfg->vmid for nesting cases, and then changes to reuse the VMID.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 65 +++++++++++++++++++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 60 insertions(+), 6 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +59 -6
@@ -2051,7 +2051,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)mutex_unlock (&arm_smmu_asid_lock); }else {struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; -if (cfg->vmid) +if (cfg->vmid && !atomic_dec_return (&smmu->vmid_refcnts[cfg->vmid]))arm_smmu_bitmap_free (smmu->vmid_map, cfg->vmid); }
@@ -2121,17 +2121,28 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain,struct arm_smmu_master *master, struct io_pgtable_cfg *pgtbl_cfg) { - int vmid; struct arm_smmu_device *smmu = smmu_domain->smmu;struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; typeof(&pgtbl_cfg->arm_lpae_s2_cfg.vtcr) vtcr; - vmid =arm_smmu_bitmap_alloc (smmu->vmid_map, smmu->vmid_bits); -if (vmid <0 ) -return vmid; +/* +* For a nested case where there are multiple passthrough devices to a +* VM, they share a commond VMID, allocated when the first passthrough +* device is attached to the VM. So the cfg->vmid might be already set +* in arm_smmu_set_nesting_vmid(), reported from the hypervisor. In this +* case, simply reuse the shared VMID and increase its refcount. +*/ +if (!cfg->vmid) { +int vmid =arm_smmu_bitmap_alloc (smmu->vmid_map, smmu->vmid_bits); + +if (vmid <0 ) +return vmid; + cfg->vmid = (u16 )vmid; + } + +atomic_inc (&smmu->vmid_refcnts[cfg->vmid]); vtcr = &pgtbl_cfg->arm_lpae_s2_cfg.vtcr; - cfg->vmid = (u16 )vmid; cfg->vttbr = pgtbl_cfg->arm_lpae_s2_cfg.vttbr; cfg->vtcr =FIELD_PREP (STRTAB_STE_2_VTCR_S2T0SZ , vtcr->tsz) | FIELD_PREP(STRTAB_STE_2_VTCR_S2SL0, vtcr->sl) |
@@ -2731,6 +2742,44 @@ static int arm_smmu_enable_nesting(struct iommu_domain *domain)return ret; } +static int arm_smmu_set_nesting_vmid (struct iommu_domain *domain,u32 vmid) +{ +struct arm_smmu_domain *smmu_domain =to_smmu_domain (domain); +struct arm_smmu_s2_cfg *s2_cfg = &smmu_domain->s2_cfg; +int ret =0 ; + +if (vmid ==IOMMU_VMID_INVALID ) +return -EINVAL ; + +mutex_lock (&smmu_domain->init_mutex); +if (smmu_domain->smmu || smmu_domain->stage !=ARM_SMMU_DOMAIN_NESTED ) + ret = -EPERM ; +else + s2_cfg->vmid = vmid; +mutex_unlock (&smmu_domain->init_mutex); + +return ret; +} + +static int arm_smmu_get_nesting_vmid (struct iommu_domain *domain,u32 *vmid) +{ +struct arm_smmu_domain *smmu_domain =to_smmu_domain (domain); +struct arm_smmu_s2_cfg *s2_cfg = &smmu_domain->s2_cfg; +int ret =0 ; + +if (!vmid) +return -EINVAL ; + +mutex_lock (&smmu_domain->init_mutex); +if (smmu_domain->smmu || smmu_domain->stage !=ARM_SMMU_DOMAIN_NESTED ) + ret = -EPERM ; +else + *vmid = s2_cfg->vmid; +mutex_unlock (&smmu_domain->init_mutex); + +return ret; +} +static int arm_smmu_of_xlate (struct device *dev,struct of_phandle_args *args) {return iommu_fwspec_add_ids (dev, args->args,1 );
@@ -2845,6 +2894,8 @@ static struct iommu_ops arm_smmu_ops = { .release_device = arm_smmu_release_device, .device_group = arm_smmu_device_group, .enable_nesting = arm_smmu_enable_nesting, + .set_nesting_vmid = arm_smmu_set_nesting_vmid, + .get_nesting_vmid = arm_smmu_get_nesting_vmid, .of_xlate = arm_smmu_of_xlate, .get_resv_regions = arm_smmu_get_resv_regions, .put_resv_regions = generic_iommu_put_resv_regions,
@@ -3530,6 +3581,8 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu)/* ASID/VMID sizes */ smmu->asid_bits = reg &IDR0_ASID16 ?16 :8 ; smmu->vmid_bits = reg &IDR0_VMID16 ?16 :8 ; + smmu->vmid_refcnts =devm_kcalloc (smmu->dev,1 << smmu->vmid_bits, +sizeof (*smmu->vmid_refcnts),GFP_KERNEL );/* IDR1 */ reg =readl_relaxed (smmu->base +ARM_SMMU_IDR1 );
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +1 -0
@@ -664,6 +664,7 @@ struct arm_smmu_device {#define ARM_SMMU_MAX_VMIDS (1 << 16)unsigned int vmid_bits;DECLARE_BITMAP (vmid_map,ARM_SMMU_MAX_VMIDS ); +atomic_t *vmid_refcnts;unsigned int ssid_bits;unsigned int sid_bits;
Signature · 1 line
2.17.1
RFC PATCH v2 8/13 iommu/arm-smmu-v3: Add VMID alloc/free helpers
In reply to Nicolin ChenNVIDIA implementation needs to link its Virtual Interface to a VMID, before a device gets attached to the corresponding iommu domain. One way to ensure that is to allocate a VMID from impl side and to pass it down to virtual machine hypervisor so that later it can set it back to passthrough devices' iommu domains calling newly added arm_smmu_set/get_nesting_vmid() functions.
This patch adds a pair of helpers to allocate and free VMID in the bitmap.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 ++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 +++ 2 files changed, 13 insertions(+)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +10 -0
@@ -2032,6 +2032,16 @@ static void arm_smmu_bitmap_free(unsigned long *map, int idx)clear_bit (idx, map); } +int arm_smmu_vmid_alloc (struct arm_smmu_device *smmu) +{ +return arm_smmu_bitmap_alloc (smmu->vmid_map, smmu->vmid_bits); +} + +void arm_smmu_vmid_free (struct arm_smmu_device *smmu,u16 vmid) +{ +arm_smmu_bitmap_free (smmu->vmid_map, vmid); +} +static void arm_smmu_domain_free (struct iommu_domain *domain) {struct arm_smmu_domain *smmu_domain =to_smmu_domain (domain);
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +3 -0
@@ -749,6 +749,9 @@ bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd);int arm_smmu_atc_inv_domain (struct arm_smmu_domain *smmu_domain,int ssid,unsigned long iova,size_t size); +int arm_smmu_vmid_alloc (struct arm_smmu_device *smmu); +void arm_smmu_vmid_free (struct arm_smmu_device *smmu,u16 vmid); +#ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported (struct arm_smmu_device *smmu);bool arm_smmu_master_sva_supported (struct arm_smmu_master *master);
Signature · 6 lines
2.17.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
RFC PATCH v2 9/13 iommu/arm-smmu-v3: Pass dev pointer to arm_smmu_detach_dev
In reply to Nicolin ChenWe are adding NVIDIA implementation that will need a ->detach_dev() callback along with the dev pointer to grab client information.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +3 -3
@@ -2377,7 +2377,7 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master)pci_disable_pasid (pdev); } -static void arm_smmu_detach_dev (struct arm_smmu_master *master) +static void arm_smmu_detach_dev (struct arm_smmu_master *master,struct device *dev) {unsigned long flags;struct arm_smmu_domain *smmu_domain = master->domain;
@@ -2421,7 +2421,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)return -EBUSY ; } -arm_smmu_detach_dev (master); +arm_smmu_detach_dev (master, dev);mutex_lock (&smmu_domain->init_mutex);
@@ -2713,7 +2713,7 @@ static void arm_smmu_release_device(struct device *dev) master =dev_iommu_priv_get (dev);if (WARN_ON (arm_smmu_master_sva_enabled (master)))iopf_queue_remove_device (master->smmu->evtq.iopf, dev); -arm_smmu_detach_dev (master); +arm_smmu_detach_dev (master, dev);arm_smmu_disable_pasid (master);arm_smmu_remove_master (master);kfree (master);
Signature · 1 line
2.17.1
RFC PATCH v2 10/13 iommu/arm-smmu-v3: Pass cmdq pointer in arm_smmu_cmdq_issue_cmdlist()
In reply to Nicolin ChenThe driver currently calls arm_smmu_get_cmdq() helper internally in different places, though they are all actually called from the same source -- arm_smmu_cmdq_issue_cmdlist() function.
This patch changes this to pass the cmdq pointer to these functions instead of calling arm_smmu_get_cmdq() every time.
This also helps NVIDIA implementation, which maintains its own cmdq pointers and needs to redirect the cmdq pointer from arm_smmu->cmdq pointer to its own, upon scanning the illegal commands by checking the opcode of the cmdlist.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +8 -7
@@ -584,11 +584,11 @@ static void arm_smmu_cmdq_poll_valid_map(struct arm_smmu_cmdq *cmdq,/* Wait for the command queue to become non-full */ static int arm_smmu_cmdq_poll_until_not_full (struct arm_smmu_device *smmu, +struct arm_smmu_cmdq *cmdq,struct arm_smmu_ll_queue *llq) {unsigned long flags;struct arm_smmu_queue_poll qp; -struct arm_smmu_cmdq *cmdq =arm_smmu_get_cmdq (smmu);int ret =0 ;/*
@@ -619,11 +619,11 @@ static int arm_smmu_cmdq_poll_until_not_full(struct arm_smmu_device *smmu,* Must be called with the cmdq lock held in some capacity. */ static int __arm_smmu_cmdq_poll_until_msi (struct arm_smmu_device *smmu, +struct arm_smmu_cmdq *cmdq,struct arm_smmu_ll_queue *llq) {int ret =0 ;struct arm_smmu_queue_poll qp; -struct arm_smmu_cmdq *cmdq =arm_smmu_get_cmdq (smmu);u32 *cmd = (u32 *)(Q_ENT (&cmdq->q, llq->prod));queue_poll_init (smmu, &qp);
@@ -643,10 +643,10 @@ static int __arm_smmu_cmdq_poll_until_msi(struct arm_smmu_device *smmu,* Must be called with the cmdq lock held in some capacity. */ static int __arm_smmu_cmdq_poll_until_consumed (struct arm_smmu_device *smmu, +struct arm_smmu_cmdq *cmdq,struct arm_smmu_ll_queue *llq) {struct arm_smmu_queue_poll qp; -struct arm_smmu_cmdq *cmdq =arm_smmu_get_cmdq (smmu);u32 prod = llq->prod;int ret =0 ;
@@ -693,12 +693,13 @@ static int __arm_smmu_cmdq_poll_until_consumed(struct arm_smmu_device *smmu, }static int arm_smmu_cmdq_poll_until_sync (struct arm_smmu_device *smmu, +struct arm_smmu_cmdq *cmdq,struct arm_smmu_ll_queue *llq) {if (smmu->options &ARM_SMMU_OPT_MSIPOLL ) -return __arm_smmu_cmdq_poll_until_msi (smmu, llq); +return __arm_smmu_cmdq_poll_until_msi (smmu, cmdq, llq); -return __arm_smmu_cmdq_poll_until_consumed (smmu, llq); +return __arm_smmu_cmdq_poll_until_consumed (smmu, cmdq, llq); } static void arm_smmu_cmdq_write_entries(struct arm_smmu_cmdq *cmdq, u64 *cmds,
@@ -755,7 +756,7 @@ static int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu,while (!queue_has_space (&llq, n + sync)) {local_irq_restore (flags); -if (arm_smmu_cmdq_poll_until_not_full (smmu, &llq)) +if (arm_smmu_cmdq_poll_until_not_full (smmu, cmdq, &llq))dev_err_ratelimited (smmu->dev,"CMDQ timeout\n" );local_irq_save (flags); }
@@ -831,7 +832,7 @@ static int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu,/* 5. If we are inserting a CMD_SYNC, we must wait for it to complete */ if (sync) { llq.prod =queue_inc_prod_n (&llq, n); - ret =arm_smmu_cmdq_poll_until_sync (smmu, &llq); + ret =arm_smmu_cmdq_poll_until_sync (smmu, cmdq, &llq);if (ret) { dev_err_ratelimited(smmu->dev, "CMD_SYNC timeout at 0x%08x [hwprod 0x%08x, hwcons 0x%08x]\n",
Signature · 1 line
2.17.1
RFC PATCH v2 11/13 iommu/arm-smmu-v3: Add implementation infrastructure
In reply to Nicolin ChenFrom: Nate Watterson <[email protected]>
Follow arm-smmu driver's infrastructure for handling implementation specific details outside the flow of architectural code.
--- drivers/iommu/arm/arm-smmu-v3/Makefile | 2 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-impl.c | 8 ++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-impl.c
drivers/iommu/arm/arm-smmu-v3/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_ARM_SMMU_V3) += arm_smmu_v3.o -arm_smmu_v3-objs-y += arm-smmu-v3.o +arm_smmu_v3-objs-y += arm-smmu-v3.o arm-smmu-v3-impl.o arm_smmu_v3-objs-$(CONFIG_ARM_SMMU_V3_SVA) += arm-smmu-v3-sva.o arm_smmu_v3-objs := $(arm_smmu_v3-objs-y)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-impl.c new file +8 -0
@@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include "arm-smmu-v3.h" + +struct arm_smmu_device *arm_smmu_v3_impl_init (struct arm_smmu_device *smmu) +{ +return smmu; +}
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +4 -0
@@ -3844,6 +3844,10 @@ static int arm_smmu_device_probe(struct platform_device *pdev)return ret; } + smmu =arm_smmu_v3_impl_init (smmu); +if (IS_ERR (smmu)) +return PTR_ERR (smmu); +/* Set bypass mode according to firmware probing result */ bypass = !!ret;
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +4 -0
@@ -810,4 +810,8 @@ static inline u32 arm_smmu_sva_get_pasid(struct iommu_sva *handle)static inline void arm_smmu_sva_notifier_synchronize (void ) {}#endif /* CONFIG_ARM_SMMU_V3_SVA */ + +/* Implementation details */ +struct arm_smmu_device *arm_smmu_v3_impl_init (struct arm_smmu_device *smmu); +#endif /* _ARM_SMMU_V3_H */
Signature · 1 line
2.17.1
RFC PATCH v2 12/13 iommu/arm-smmu-v3: Add support for NVIDIA CMDQ-Virtualization hw
In reply to Nicolin ChenFrom: Nate Watterson <[email protected]>
NVIDIA's Grace SoC has a CMDQ-Virtualization (CMDQV) hardware, which adds multiple VCMDQ interfaces (VINTFs) to supplement the architected SMMU_CMDQ in an effort to reduce contention.
To make use of these supplemental CMDQs in arm-smmu-v3 driver, this patch borrows the "implemenatation infrastructure" design from the arm-smmu driver, and then adds implementation specific supports for ->device_reset() and ->get_cmdq() functions. Since nvidia's ->get_cmdq() implemenatation needs to check the first command of the cmdlist to determine whether to redirect to its own vcmdq, this patch also adds augments to arm_smmu_get_cmdq() function.
For the CMDQV driver itself, this patch only adds the essential parts for the host kernel, in terms of virtualization use cases. VINTF0 is being reserved for host kernel use, so is initialized with the driver also.
Note that, for the current plan, the CMDQV driver only supports ACPI configuration.
--- MAINTAINERS | 2 + drivers/iommu/arm/arm-smmu-v3/Makefile | 2 +- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-impl.c | 7 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 15 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 8 + .../iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c | 432 ++++++++++++++++++ 6 files changed, 463 insertions(+), 3 deletions(-) create mode 100644 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c
MAINTAINERS +2 -0
@@ -18428,8 +18428,10 @@ F: drivers/i2c/busses/i2c-tegra.c TEGRA IOMMU DRIVERS M: Thierry Reding <[email protected]> R: Krishna Reddy <[email protected]> +R: Nicolin Chen <[email protected]> L: [email protected] S: Supported +F: drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c F: drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c F: drivers/iommu/tegra*
drivers/iommu/arm/arm-smmu-v3/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_ARM_SMMU_V3) += arm_smmu_v3.o -arm_smmu_v3-objs-y += arm-smmu-v3.o arm-smmu-v3-impl.o +arm_smmu_v3-objs-y += arm-smmu-v3.o arm-smmu-v3-impl.o nvidia-smmu-v3.o arm_smmu_v3-objs-$(CONFIG_ARM_SMMU_V3_SVA) += arm-smmu-v3-sva.o arm_smmu_v3-objs := $(arm_smmu_v3-objs-y)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-impl.c +7 -0
@@ -4,5 +4,12 @@struct arm_smmu_device *arm_smmu_v3_impl_init (struct arm_smmu_device *smmu) { +/* +* Nvidia implementation supports ACPI only, so calling its init() +* unconditionally to walk through ACPI tables to probe the device. +* It will keep the smmu pointer intact, if it fails. +*/ + smmu =nvidia_smmu_v3_impl_init (smmu); +return smmu; }
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +13 -2
@@ -335,8 +335,11 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent)return 0 ; } -static struct arm_smmu_cmdq *arm_smmu_get_cmdq (struct arm_smmu_device *smmu) +static struct arm_smmu_cmdq *arm_smmu_get_cmdq (struct arm_smmu_device *smmu,u64 *cmds,int n) { +if (smmu->impl && smmu->impl->get_cmdq) +return smmu->impl->get_cmdq (smmu, cmds, n); +return &smmu->cmdq; }
@@ -742,7 +745,7 @@ static int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu,u32 prod;unsigned long flags;bool owner; -struct arm_smmu_cmdq *cmdq =arm_smmu_get_cmdq (smmu); +struct arm_smmu_cmdq *cmdq =arm_smmu_get_cmdq (smmu, cmds, n);struct arm_smmu_ll_queue llq, head;int ret =0 ;
@@ -3487,6 +3490,14 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass)return ret; } +if (smmu->impl && smmu->impl->device_reset) { + ret = smmu->impl->device_reset (smmu); +if (ret) { +dev_err (smmu->dev,"failed at implementation specific device_reset\n" ); +return ret; + } + } +return 0 ; }
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +8 -0
@@ -647,6 +647,8 @@ struct arm_smmu_device {#define ARM_SMMU_OPT_MSIPOLL (1 << 2)u32 options; +const struct arm_smmu_impl *impl; +struct arm_smmu_cmdq cmdq;struct arm_smmu_evtq evtq;struct arm_smmu_priq priq;
@@ -812,6 +814,12 @@ static inline void arm_smmu_sva_notifier_synchronize(void) {}#endif /* CONFIG_ARM_SMMU_V3_SVA */ /* Implementation details */ +struct arm_smmu_impl { +int (*device_reset)(struct arm_smmu_device *smmu); +struct arm_smmu_cmdq *(*get_cmdq)(struct arm_smmu_device *smmu,u64 *cmds,int n); +}; +struct arm_smmu_device *arm_smmu_v3_impl_init (struct arm_smmu_device *smmu); +struct arm_smmu_device *nvidia_smmu_v3_impl_init (struct arm_smmu_device *smmu);#endif /* _ARM_SMMU_V3_H */
drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c new file +432 -0
432 lines not on this page · raw message
Signature · 1 line
2.17.1
kernel test robot
build botRe: [RFC][PATCH v2 12/13] iommu/arm-smmu-v3: Add support for NVIDIA CMDQ-Virtualization hw
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Nicolin,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on iommu/next]
[also build test WARNING on next-20210830]
[cannot apply to vfio/next linus/master v5.14]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Nicolin-Chen/iommu-arm-smmu-v3-Add-NVIDIA-implementation/20210831-111013 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next config: arm64-allyesconfig (attached as .config) compiler: aarch64-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/9a22c788ed0320df4a0fb8689c3113d0bd0a91da
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nicolin-Chen/iommu-arm-smmu-v3-Add-NVIDIA-implementation/20210831-111013 git checkout 9a22c788ed0320df4a0fb8689c3113d0bd0a91da
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:375:21: warning: no previous prototype for 'nvidia_smmu_create' [-Wmissing-prototypes]
375 | struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
| ^~~~~~~~~~~~~~~~~~
vim +/nvidia_smmu_create +375 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c
373
374 #ifdef CONFIG_ACPI
> 375 struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
376 {
377 struct nvidia_smmu *nsmmu = NULL;
378 struct acpi_iort_node *node;
379 struct acpi_device *adev;
380 struct device *cmdqv_dev;
381 const char *match_uid;
382
383 if (acpi_disabled)
384 return NULL;
385
386 /* Look for a device in the DSDT whose _UID matches the SMMU's iort_node identifier */
387 node = *(struct acpi_iort_node **)dev_get_platdata(smmu->dev);
388 match_uid = kasprintf(GFP_KERNEL, "%u", node->identifier);
389 adev = acpi_dev_get_first_match_dev(NVIDIA_SMMU_CMDQV_HID, match_uid, -1);
390 kfree(match_uid);
391
392 if (!adev)
393 return NULL;
394
395 cmdqv_dev = bus_find_device_by_acpi_dev(&platform_bus_type, adev);
396 if (!cmdqv_dev)
397 return NULL;
398
399 dev_info(smmu->dev, "found companion CMDQV device, %s", dev_name(cmdqv_dev));
400
401 nsmmu = devm_krealloc(smmu->dev, smmu, sizeof(*nsmmu), GFP_KERNEL);
402 if (!nsmmu)
403 return ERR_PTR(-ENOMEM);
404
405 nsmmu->cmdqv_dev = cmdqv_dev;
406
407 return nsmmu;
408 }
409 #else
410 struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
411 {
412 return NULL;
413 }
414 #endif
415
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [RFC][PATCH v2 12/13] iommu/arm-smmu-v3: Add support for NVIDIA CMDQ-Virtualization hw
In reply to Nicolin Chen[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Nicolin,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on iommu/next]
[also build test WARNING on next-20210830]
[cannot apply to vfio/next linus/master v5.14]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Nicolin-Chen/iommu-arm-smmu-v3-Add-NVIDIA-implementation/20210831-111013 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next config: arm64-randconfig-r015-20210831 (attached as .config) compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 4b1fde8a2b681dad2ce0c082a5d6422caa06b0bc)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/9a22c788ed0320df4a0fb8689c3113d0bd0a91da
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nicolin-Chen/iommu-arm-smmu-v3-Add-NVIDIA-implementation/20210831-111013 git checkout 9a22c788ed0320df4a0fb8689c3113d0bd0a91da
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:410:21: warning: no previous prototype for function 'nvidia_smmu_create' [-Wmissing-prototypes]
struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
^ drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:410:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
^
static
1 warning generated.
vim +/nvidia_smmu_create +410 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c
373
374 #ifdef CONFIG_ACPI
375 struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
376 {
377 struct nvidia_smmu *nsmmu = NULL;
378 struct acpi_iort_node *node;
379 struct acpi_device *adev;
380 struct device *cmdqv_dev;
381 const char *match_uid;
382
383 if (acpi_disabled)
384 return NULL;
385
386 /* Look for a device in the DSDT whose _UID matches the SMMU's iort_node identifier */
387 node = *(struct acpi_iort_node **)dev_get_platdata(smmu->dev);
388 match_uid = kasprintf(GFP_KERNEL, "%u", node->identifier);
389 adev = acpi_dev_get_first_match_dev(NVIDIA_SMMU_CMDQV_HID, match_uid, -1);
390 kfree(match_uid);
391
392 if (!adev)
393 return NULL;
394
395 cmdqv_dev = bus_find_device_by_acpi_dev(&platform_bus_type, adev);
396 if (!cmdqv_dev)
397 return NULL;
398
399 dev_info(smmu->dev, "found companion CMDQV device, %s", dev_name(cmdqv_dev));
400
401 nsmmu = devm_krealloc(smmu->dev, smmu, sizeof(*nsmmu), GFP_KERNEL);
402 if (!nsmmu)
403 return ERR_PTR(-ENOMEM);
404
405 nsmmu->cmdqv_dev = cmdqv_dev;
406
407 return nsmmu;
408 }
409 #else
> 410 struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
411 {
412 return NULL;
413 }
414 #endif
415
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH v2 13/13 iommu/nvidia-smmu-v3: Add mdev interface support
In reply to Nicolin ChenFrom: Nate Watterson <[email protected]>
This patch adds initial mdev interface support for NVIDIA SMMU CMDQV driver.
The NVIDIA SMMU CMDQV module has multiple virtual interfaces (VINTFs), designed to be exposed to virtual machines running on the user space, while each VINTF can allocate dedicated VCMDQs for TLB invalidations.
The hypervisor can import, to a VM, one of these interfaces via VFIO mdev interface, to get access to VINTF registers in the host kernel.
Each VINTF has two pages of MMIO regions: PAGE0 and PAGE1. PAGE0 has performance sensitive registers such as CONS_INDX and PROD_INDX that should be programmed by the guest directly, so the driver has a mmap implementation via the mdev interface to let user space get acces to PAGE0 directly. PAGE1 then has two base address configuring registers where the addresses should be translated from guest PAs to host PAs, so they are handled via mdev read/write() to trap for replacements.
As previous patch mentioned, VINTF0 is reserved for the host kernel (or hypervisor) use, a VINTFx (x > 0) should be allocated to a guest VM. And from the guest perspective, the VINTFx (host) is seen as the VINTF0 of the guest. Beside the two MMIO regions of VINTF0, the guest VM also has the global configuration MMIO region as the host kernel does, and this global region is also handled via mdev read/write() to limit the guest to access the bits of its own.
Additionally, there were a couple of issues for this implementation:
1) Setting into VINTF CONFIG register the same VMID as SMMU's s2_cfg.
2) Before enabling the VINTF, programing up-to-16 sets of SID_REPLACE and SID_MATCH registers that stores physical stream IDs of host's and corresponding virtual stream IDs of guest's respectively.
And in this patch, we add a pair of ->attach_dev and ->detach_dev and implement them in the following ways:
1) For each VINTF, pre-allocating a VMID on the bitmap of arm_smmu_v3 driver to create a link between VINTF index and VMID, so either of them can be quickly looked up using the counterpart later.
2) Programming PHY_SID into SID_REPLACE (corresponding register), yet writing iommu_group_id (a fake VIRT_SID) into SID_MATCH, as it is the only shared information of a passthrough device between a host kernel and a hypervisor. So the hypervisor is responsible to match the iommu_group_id and then to replace it with a virtual SID.
3) Note that, by doing (1) the VMID is now created along with a VINTF in the nvidia_smmu_cmdqv_mdev_create() function, which is executed before a hypervisor or VM starts, comparing to previous situation:
we added a few patches to let arm-smmu-v3 driver allocate a shared VMID in arm_smmu_attach_dev() function, when the first passthrough device is added to the VM. This means that, in the new situation, the shared VMID needs to be passed to the hypervisor, before any passthrough device gets attached. So, we reuse VFIO_IOMMU_GET_VMID command via the mdev ioctl interface to pass the VMID to the CMDQV device model, then to the SMMUv3 device model, so that hypervisor can set the same VMID to all IOMMU domains of passthrough devices using the previous pathway via VFIO core back to SMMUv3 driver.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 6 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 + .../iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c | 817 ++++++++++++++++++ 3 files changed, 825 insertions(+)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +6 -0
@@ -2389,6 +2389,9 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master, struct device *dif (!smmu_domain)return ; +if (master->smmu->impl && master->smmu->impl->detach_dev) + master->smmu->impl->detach_dev (smmu_domain, dev); +arm_smmu_disable_ats (master);spin_lock_irqsave (&smmu_domain->devices_lock, flags);
@@ -2471,6 +2474,9 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)arm_smmu_enable_ats (master); +if (smmu->impl && smmu->impl->attach_dev) + ret = smmu->impl->attach_dev (smmu_domain, dev); + out_unlock:mutex_unlock (&smmu_domain->init_mutex);return ret;
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +2 -0
@@ -817,6 +817,8 @@ static inline void arm_smmu_sva_notifier_synchronize(void) {}struct arm_smmu_impl {int (*device_reset)(struct arm_smmu_device *smmu);struct arm_smmu_cmdq *(*get_cmdq)(struct arm_smmu_device *smmu,u64 *cmds,int n); +int (*attach_dev)(struct arm_smmu_domain *smmu_domain,struct device *dev); +void (*detach_dev)(struct arm_smmu_domain *smmu_domain,struct device *dev); };struct arm_smmu_device *arm_smmu_v3_impl_init (struct arm_smmu_device *smmu);
drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c +817 -0
913 lines not on this page · raw message
Signature · 1 line
2.17.1
kernel test robot
build botRe: [RFC][PATCH v2 13/13] iommu/nvidia-smmu-v3: Add mdev interface support
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Nicolin,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on iommu/next]
[also build test WARNING on next-20210830]
[cannot apply to vfio/next linus/master v5.14]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Nicolin-Chen/iommu-arm-smmu-v3-Add-NVIDIA-implementation/20210831-111013 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next config: arm64-allyesconfig (attached as .config) compiler: aarch64-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f0498366ced0e3160486087e3d218fd519092545
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nicolin-Chen/iommu-arm-smmu-v3-Add-NVIDIA-implementation/20210831-111013 git checkout f0498366ced0e3160486087e3d218fd519092545
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:251:5: warning: no previous prototype for 'nvidia_smmu_cmdqv_mdev_init' [-Wmissing-prototypes]
251 | int nvidia_smmu_cmdqv_mdev_init(struct nvidia_smmu *nsmmu)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:629:21: warning: no previous prototype for 'nvidia_smmu_create' [-Wmissing-prototypes]
629 | struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
| ^~~~~~~~~~~~~~~~~~
vim +/nvidia_smmu_cmdqv_mdev_init +251 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c
204
205 int nvidia_smmu_cmdqv_mdev_init(struct nvidia_smmu *nsmmu)
206 {
207 struct nvidia_cmdqv_mdev *cmdqv_mdev;
208 int ret;
209
210 /* Skip mdev init unless there are available VINTFs */
211 if (nsmmu->num_total_vintfs <= 1)
212 return 0;
213
214 nsmmu->vintf_mdev = devm_kcalloc(nsmmu->cmdqv_dev, nsmmu->num_total_vintfs,
215 sizeof(*nsmmu->vintf_mdev), GFP_KERNEL);
216 if (!nsmmu->vintf_mdev)
217 return -ENOMEM;
218
219 nsmmu->vcmdq_regcache = devm_kcalloc(nsmmu->cmdqv_dev, nsmmu->num_total_vcmdqs,
220 sizeof(*nsmmu->vcmdq_regcache), GFP_KERNEL);
221 if (!nsmmu->vcmdq_regcache)
222 return -ENOMEM;
223
224 nsmmu->vmid_mappings = devm_kcalloc(nsmmu->cmdqv_dev, 1 << nsmmu->smmu.vmid_bits,
225 sizeof(*nsmmu->vmid_mappings), GFP_KERNEL);
226 if (!nsmmu->vmid_mappings)
227 return -ENOMEM;
228
229 mutex_init(&nsmmu->mdev_lock);
230 mutex_init(&nsmmu->vmid_lock);
231
232 /* Add a dummy mdev instance to represent vintf0 */
233 cmdqv_mdev = devm_kzalloc(nsmmu->cmdqv_dev, sizeof(*cmdqv_mdev), GFP_KERNEL);
234 if (!cmdqv_mdev)
235 return -ENOMEM;
236
237 cmdqv_mdev->nsmmu = nsmmu;
238 nsmmu->vintf_mdev[0] = cmdqv_mdev;
239
240 ret = mdev_register_device(nsmmu->cmdqv_dev, &nvidia_smmu_cmdqv_mdev_ops);
241 if (ret) {
242 dev_err(nsmmu->cmdqv_dev, "failed to register mdev device: %d\n", ret);
243 return ret;
244 }
245
246 platform_set_drvdata(to_platform_device(nsmmu->cmdqv_dev), nsmmu);
247
248 return ret;
249 }
250 #else
> 251 int nvidia_smmu_cmdqv_mdev_init(struct nvidia_smmu *nsmmu)
252 {
253 return 0;
254 }
255 #endif
256
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [RFC][PATCH v2 13/13] iommu/nvidia-smmu-v3: Add mdev interface support
In reply to Nicolin Chen[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Nicolin,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on iommu/next]
[also build test WARNING on next-20210830]
[cannot apply to vfio/next linus/master v5.14]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Nicolin-Chen/iommu-arm-smmu-v3-Add-NVIDIA-implementation/20210831-111013 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next config: arm64-randconfig-r015-20210831 (attached as .config) compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 4b1fde8a2b681dad2ce0c082a5d6422caa06b0bc)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/f0498366ced0e3160486087e3d218fd519092545
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nicolin-Chen/iommu-arm-smmu-v3-Add-NVIDIA-implementation/20210831-111013 git checkout f0498366ced0e3160486087e3d218fd519092545
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:251:5: warning: no previous prototype for function 'nvidia_smmu_cmdqv_mdev_init' [-Wmissing-prototypes]
int nvidia_smmu_cmdqv_mdev_init(struct nvidia_smmu *nsmmu)
^
drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:251:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int nvidia_smmu_cmdqv_mdev_init(struct nvidia_smmu *nsmmu)
^
static
drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:664:21: warning: no previous prototype for function 'nvidia_smmu_create' [-Wmissing-prototypes]
struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
^ drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:664:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
^
static
2 warnings generated.
vim +/nvidia_smmu_cmdqv_mdev_init +251 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c
204
205 int nvidia_smmu_cmdqv_mdev_init(struct nvidia_smmu *nsmmu)
206 {
207 struct nvidia_cmdqv_mdev *cmdqv_mdev;
208 int ret;
209
210 /* Skip mdev init unless there are available VINTFs */
211 if (nsmmu->num_total_vintfs <= 1)
212 return 0;
213
214 nsmmu->vintf_mdev = devm_kcalloc(nsmmu->cmdqv_dev, nsmmu->num_total_vintfs,
215 sizeof(*nsmmu->vintf_mdev), GFP_KERNEL);
216 if (!nsmmu->vintf_mdev)
217 return -ENOMEM;
218
219 nsmmu->vcmdq_regcache = devm_kcalloc(nsmmu->cmdqv_dev, nsmmu->num_total_vcmdqs,
220 sizeof(*nsmmu->vcmdq_regcache), GFP_KERNEL);
221 if (!nsmmu->vcmdq_regcache)
222 return -ENOMEM;
223
224 nsmmu->vmid_mappings = devm_kcalloc(nsmmu->cmdqv_dev, 1 << nsmmu->smmu.vmid_bits,
225 sizeof(*nsmmu->vmid_mappings), GFP_KERNEL);
226 if (!nsmmu->vmid_mappings)
227 return -ENOMEM;
228
229 mutex_init(&nsmmu->mdev_lock);
230 mutex_init(&nsmmu->vmid_lock);
231
232 /* Add a dummy mdev instance to represent vintf0 */
233 cmdqv_mdev = devm_kzalloc(nsmmu->cmdqv_dev, sizeof(*cmdqv_mdev), GFP_KERNEL);
234 if (!cmdqv_mdev)
235 return -ENOMEM;
236
237 cmdqv_mdev->nsmmu = nsmmu;
238 nsmmu->vintf_mdev[0] = cmdqv_mdev;
239
240 ret = mdev_register_device(nsmmu->cmdqv_dev, &nvidia_smmu_cmdqv_mdev_ops);
241 if (ret) {
242 dev_err(nsmmu->cmdqv_dev, "failed to register mdev device: %d\n", ret);
243 return ret;
244 }
245
246 platform_set_drvdata(to_platform_device(nsmmu->cmdqv_dev), nsmmu);
247
248 return ret;
249 }
250 #else
> 251 int nvidia_smmu_cmdqv_mdev_init(struct nvidia_smmu *nsmmu)
252 {
253 return 0;
254 }
255 #endif
256
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 11 lines · On Mon, 30 Aug 2021 19:59:10 -0700 Nicolin Chen <[email protected]> wrote:
The SMMUv3 devices implemented in the Grace SoC support NVIDIA's custom CMDQ-Virtualization (CMDQV) hardware. Like the new ECMDQ feature first introduced in the ARM SMMUv3.3 specification, CMDQV adds multiple VCMDQ interfaces to supplement the single architected
SMMU_CMDQin an effort to reduce contention.This series of patches add CMDQV support with its preparational changes:
* PATCH-1 to PATCH-8 are related to shared VMID feature: they are used first to improve TLB utilization, second to bind a shared VMID with a VCMDQ interface for hardware configuring requirement.
The vfio changes would need to be implemented in alignment with the /dev/iommu proposals[1]. AIUI, the VMID is essentially binding multiple containers together for TLB invalidation, which I expect in the proposal below is largely already taken care of in that a single iommu-fd can support multiple I/O address spaces and it's largely expected that a hypervisor would use a single iommu-fd so this explicit connection by userspace across containers wouldn't be necessary.
We're expecting to talk more about the /dev/iommu approach at Plumbers in few weeks. Thanks,
Alex
Quoted 67 lines
* PATCH-9 and PATCH-10 are to accommodate the NVIDIA implementation with the existing arm-smmu-v3 driver.
* PATCH-11 borrows the "implementation infrastructure" from the arm-smmu driver so later change can build upon it.
* PATCH-12 adds an initial NVIDIA implementation related to host feature, and also adds implementation specific ->device_reset() and ->get_cmdq() callback functions.
* PATCH-13 adds virtualization features using VFIO mdev interface, which allows user space hypervisor to map and get access to one of the VCMDQ interfaces of CMDQV module.
( Thinking that reviewers can get a better view of this implementation,
I am attaching QEMU changes here for reference purpose:https://github.com/nicolinc/qemu/commits/dev/cmdqv_v6.0.0-rc2The branch has all preparational changes, while I'm still integrating device model and ARM-VIRT changes, and will push them these two days, although they might not be in a good shape of being sent to review yet )
Above all, I marked RFC for this series, as I feel that we may come up some better solution. So please kindly share your reviews and insights.
Thank you!
Changelog
v1->v2:
* Added mdev interface support for hypervisor and VMs.
* Added preparational changes for mdev interface implementation.
* PATCH-12 Changed ->issue_cmdlist() to ->get_cmdq() for a better integration with recently merged ECMDQ-related changes.Nate Watterson (3):
iommu/arm-smmu-v3: Add implementation infrastructure iommu/arm-smmu-v3: Add support for NVIDIA CMDQ-Virtualization hw iommu/nvidia-smmu-v3: Add mdev interface supportNicolin Chen (10):
iommu: Add set_nesting_vmid/get_nesting_vmid functions
vfio: addVFIO_IOMMU_GET_VMIDandVFIO_IOMMU_SET_VMID
vfio: Document VMID control for IOMMU Virtualization
vfio: addset_vmidandget_vmidforvfio_iommu_type1vfio/type1: Implementset_vmidandget_vmid
vfio/type1: Set/get VMID to/from iommu driver iommu/arm-smmu-v3: Add shared VMID support for NESTING iommu/arm-smmu-v3: Add VMID alloc/free helpers iommu/arm-smmu-v3: Pass dev pointer toarm_smmu_detach_deviommu/arm-smmu-v3: Pass cmdq pointer inarm_smmu_cmdq_issue_cmdlist()Documentation/driver-api/vfio.rst | 34 + MAINTAINERS | 2 + drivers/iommu/arm/arm-smmu-v3/Makefile | 2 +- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-impl.c | 15 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 121 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 18 + .../iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c | 1249 +++++++++++++++++ drivers/iommu/iommu.c | 20 + drivers/vfio/vfio.c | 25 + drivers/vfio/vfio_iommu_type1.c | 37 + include/linux/iommu.h | 5 + include/linux/vfio.h | 2 + include/uapi/linux/vfio.h | 26 + 13 files changed, 1537 insertions(+), 19 deletions(-) create mode 100644 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-impl.c create mode 100644 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c
Quoted 20 lines
From: Alex Williamson
Sent: Wednesday, September 1, 2021 12:16 AMQuoted 1 line · On Mon, 30 Aug 2021 19:59:10 -0700 Nicolin Chen <[email protected]> wrote:
The SMMUv3 devices implemented in the Grace SoC support NVIDIA's
custom
Quoted 2 lines
CMDQ-Virtualization (CMDQV) hardware. Like the new ECMDQ feature first introduced in the ARM SMMUv3.3 specification, CMDQV adds multiple
VCMDQ
Quoted 8 lines
interfaces to supplement the single architected
SMMU_CMDQin an effort to reduce contention.This series of patches add CMDQV support with its preparational changes:
* PATCH-1 to PATCH-8 are related to shared VMID feature: they are used first to improve TLB utilization, second to bind a shared VMID with a VCMDQ interface for hardware configuring requirement.
Quoted 7 lines
The vfio changes would need to be implemented in alignment with the
/dev/iommuproposals[1]. AIUI, the VMID is essentially binding multiple containers together for TLB invalidation, which I expect in the proposal below is largely already taken care of in that a single iommu-fd can support multiple I/O address spaces and it's largely expected that a hypervisor would use a single iommu-fd so this explicit connection by userspace across containers wouldn't be necessary.
Agree. VMID is equivalent to DID (domain id) in other vendor iommus. with /dev/iommu multiple I/O address spaces can share the same VMID via nesting. No need of exposing VMID to userspace to build the connection.
Thanks,
Kevin
Quoted 87 lines
We're expecting to talk more about the
/dev/iommuapproach at Plumbers in few weeks. Thanks,Alex
[1]https://lore.kernel.org/kvm/BN9PR11MB5433B1E4AE5B0480369F97178C1 [email protected]/
Quoted 1 line
* PATCH-9 and PATCH-10 are to accommodate the NVIDIA implementation
with
Quoted 3 lines
the existing arm-smmu-v3 driver.
* PATCH-11 borrows the "implementation infrastructure" from the arm-
smmu
Quoted 34 lines
driver so later change can build upon it.
* PATCH-12 adds an initial NVIDIA implementation related to host feature, and also adds implementation specific ->device_reset() and ->get_cmdq() callback functions.
* PATCH-13 adds virtualization features using VFIO mdev interface, which allows user space hypervisor to map and get access to one of the VCMDQ interfaces of CMDQV module.
( Thinking that reviewers can get a better view of this implementation,
I am attaching QEMU changes here for reference purpose:https://github.com/nicolinc/qemu/commits/dev/cmdqv_v6.0.0-rc2The branch has all preparational changes, while I'm still integrating device model and ARM-VIRT changes, and will push them these two days, although they might not be in a good shape of being sent to review yet )
Above all, I marked RFC for this series, as I feel that we may come up some better solution. So please kindly share your reviews and insights.
Thank you!
Changelog
v1->v2:
* Added mdev interface support for hypervisor and VMs.
* Added preparational changes for mdev interface implementation.
* PATCH-12 Changed ->issue_cmdlist() to ->get_cmdq() for a better integration with recently merged ECMDQ-related changes.Nate Watterson (3):
iommu/arm-smmu-v3: Add implementation infrastructure iommu/arm-smmu-v3: Add support for NVIDIA CMDQ-Virtualization hw iommu/nvidia-smmu-v3: Add mdev interface supportQuoted 11 lines
Nicolin Chen (10):
iommu: Add set_nesting_vmid/get_nesting_vmid functions
vfio: addVFIO_IOMMU_GET_VMIDandVFIO_IOMMU_SET_VMID
vfio: Document VMID control for IOMMU Virtualization
vfio: addset_vmidandget_vmidforvfio_iommu_type1vfio/type1: Implementset_vmidandget_vmidvfio/type1: Set/get VMID to/from iommu driver iommu/arm-smmu-v3: Add shared VMID support for NESTING iommu/arm-smmu-v3: Add VMID alloc/free helpers iommu/arm-smmu-v3: Pass dev pointer toarm_smmu_detach_deviommu/arm-smmu-v3: Pass cmdq pointer in
arm_smmu_cmdq_issue_cmdlist()Quoted 8 lines
Documentation/driver-api/vfio.rst | 34 + MAINTAINERS | 2 + drivers/iommu/arm/arm-smmu-v3/Makefile | 2 +- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-impl.c | 15 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 121 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 18 + .../iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c | 1249+++++++++++++++++
Quoted 8 lines
drivers/iommu/iommu.c | 20 + drivers/vfio/vfio.c | 25 + drivers/vfio/vfio_iommu_type1.c | 37 + include/linux/iommu.h | 5 + include/linux/vfio.h | 2 + include/uapi/linux/vfio.h | 26 + 13 files changed, 1537 insertions(+), 19 deletions(-) create mode 100644 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-
impl.cQuoted 2 lines
create mode 100644 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 28 lines · Kevin
Quoted 20 lines
From: Alex Williamson
Sent: Wednesday, September 1, 2021 12:16 AMQuoted 1 line · On Mon, 30 Aug 2021 19:59:10 -0700 Nicolin Chen <[email protected]> wrote:
The SMMUv3 devices implemented in the Grace SoC support NVIDIA's
custom
Quoted 2 lines
CMDQ-Virtualization (CMDQV) hardware. Like the new ECMDQ feature first introduced in the ARM SMMUv3.3 specification, CMDQV adds multiple
VCMDQ
Quoted 8 lines
interfaces to supplement the single architected
SMMU_CMDQin an effort to reduce contention.This series of patches add CMDQV support with its preparational changes:
* PATCH-1 to PATCH-8 are related to shared VMID feature: they are used first to improve TLB utilization, second to bind a shared VMID with a VCMDQ interface for hardware configuring requirement.
Quoted 7 lines
The vfio changes would need to be implemented in alignment with the
/dev/iommuproposals[1]. AIUI, the VMID is essentially binding multiple containers together for TLB invalidation, which I expect in the proposal below is largely already taken care of in that a single iommu-fd can support multiple I/O address spaces and it's largely expected that a hypervisor would use a single iommu-fd so this explicit connection by userspace across containers wouldn't be necessary.
Quoted 4 lines
Agree. VMID is equivalent to DID (domain id) in other vendor iommus. with
/dev/iommumultiple I/O address spaces can share the same VMID via nesting. No need of exposing VMID to userspace to build the connection.
Indeed, this looks like a flavour of the accelerated invalidation stuff we've talked about already.
I would see it probably exposed as some HW specific IOCTL on the iommu fd to get access to the accelerated invalidation for IOASID's in the FD.
Indeed, this seems like a further example of why /dev/iommu is looking like a good idea as this RFC is very complicated to do something fairly simple.
Where are thing on the /dev/iommu work these days?
Thanks,
Jason
Quoted 48 lines
From: Jason Gunthorpe <[email protected]>
Sent: Thursday, September 2, 2021 10:45 PMQuoted 9 lines · Kevin
Quoted 9 lines
From: Alex Williamson
Sent: Wednesday, September 1, 2021 12:16 AMQuoted 1 line · On Mon, 30 Aug 2021 19:59:10 -0700 Nicolin Chen <[email protected]> wrote:
The SMMUv3 devices implemented in the Grace SoC support NVIDIA's
custom
Quoted 1 line
CMDQ-Virtualization (CMDQV) hardware. Like the new ECMDQ feature
first
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
introduced in the ARM SMMUv3.3 specification, CMDQV adds multiple
VCMDQ
Quoted 1 line
interfaces to supplement the single architected
SMMU_CMDQin aneffort
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
to reduce contention.
This series of patches add CMDQV support with its preparational
changes:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
* PATCH-1 to PATCH-8 are related to shared VMID feature: they are
used
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines
first to improve TLB utilization, second to bind a shared VMID with a VCMDQ interface for hardware configuring requirement.
The vfio changes would need to be implemented in alignment with the
/dev/iommuproposals[1]. AIUI, the VMID is essentially binding multiple containers together for TLB invalidation, which I expect in the proposal below is largely already taken care of in that a single iommu-fd can support multiple I/O address spaces and it's largely expected that a hypervisor would use a single iommu-fd so this explicit connection by userspace across containers wouldn't be necessary.Quoted 4 lines
Agree. VMID is equivalent to DID (domain id) in other vendor iommus. with
/dev/iommumultiple I/O address spaces can share the same VMID via nesting. No need of exposing VMID to userspace to build the connection.Indeed, this looks like a flavour of the accelerated invalidation stuff we've talked about already.
I would see it probably exposed as some HW specific IOCTL on the iommu fd to get access to the accelerated invalidation for IOASID's in the FD.
Quoted 6 lines
Indeed, this seems like a further example of why
/dev/iommuis looking like a good idea as this RFC is very complicated to do something fairly simple.Where are thing on the
/dev/iommuwork these days?
We are actively working on the basic skeleton. Our original plan is to send out the 1st draft before LPC, with support of vfio type1 semantics and and pci dev only (single-device group). But later we realized that adding multi-devices group support is also necessary even in the 1st draft to avoid some dirty hacks and build the complete picture. This will add some time though. If things go well, we'll still try hit the original plan. If not, it will be soon after LPC.
Thanks
Kevin
Hi Kevin,
Quoted 13 lines · Kevin
Quoted 7 lines
Indeed, this looks like a flavour of the accelerated invalidation stuff we've talked about already.
I would see it probably exposed as some HW specific IOCTL on the iommu fd to get access to the accelerated invalidation for IOASID's in the FD.
Quoted 5 lines
Indeed, this seems like a further example of why
/dev/iommuis looking like a good idea as this RFC is very complicated to do something fairly simple.Where are thing on the
/dev/iommuwork these days?
Quoted 7 lines
We are actively working on the basic skeleton. Our original plan is to send out the 1st draft before LPC, with support of vfio type1 semantics and and pci dev only (single-device group). But later we realized that adding multi-devices group support is also necessary even in the 1st draft to avoid some dirty hacks and build the complete picture. This will add some time though. If things go well, we'll still try hit the original plan. If not, it will be soon after LPC.
As I also want to take a look at your work for this implementation, would you please CC me when you send out your patches? Thank you!
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu