iommu/arm-smmu-v3: Add NVIDIA implementation
Subsystems (3)
cover iommu/arm-smmu-v3: Add NVIDIA implementation
From: Nicolin Chen <[email protected]>
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 patch series adds CMDQV support to the arm-smmu-v3 driver by first borrowing the implementation infrastructure from the arm-smmu driver. The NVIDIA implementation is then introduced along with hooks allowing implmentations to specify custom issue_cmdlist methods. Additionally, the original issue_cmdlist and supporting methods in the arm-smmu-v3 driver are reworked to support alternative CMDQs.
[ nicolinc: this v1 is more of base changes for CMDQV driver; while I
am still integrating incremental features based on VFIO mdev, I sent these two out in order to collect comments and suggestions to see if the overall structure is promising. I will add more changes in v2 or later versions for more detailed implementations. Thank you! ]
Nate Watterson (2):
iommu/arm-smmu-v3: Add implementation infrastructure iommu/arm-smmu-v3: Add support for NVIDIA CMDQ-Virtualization hw
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 | 71 +-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 15 + .../iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c | 425 ++++++++++++++++++ 6 files changed, 503 insertions(+), 27 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 1/2 iommu/arm-smmu-v3: Add implementation infrastructure
From: Nate Watterson <[email protected]>
Copy the 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
@@ -3771,6 +3771,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
@@ -806,4 +806,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 2/2 iommu/arm-smmu-v3: Add support for NVIDIA CMDQ-Virtualization hw
In reply to Nicolin ChenFrom: Nate Watterson <[email protected]>
NVIDIA's Grace SoC includes custom CMDQ-Virtualization (CMDQV) hardware, which adds multiple VCMDQ interfaces to supplement the architected SMMU_CMDQ in an effort to reduce contention.
To make use of these supplemental CMDQs in arm-smmu-v3 driver, we borrow the "implementation infrastructure" design from the arm-smmu driver, and add support for implementation defined issue_cmdlist methods.
--- 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 | 67 +-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 11 + .../iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c | 425 ++++++++++++++++++ 6 files changed, 487 insertions(+), 27 deletions(-) create mode 100644 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c
MAINTAINERS +2 -0
@@ -18240,8 +18240,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 +41 -26
196 lines not on this page · raw message
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +11 -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;
@@ -807,7 +809,16 @@ 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 */ +int arm_smmu_cmdq_issue_cmdlist (struct arm_smmu_device *smmu,u64 *cmds,int n,bool sync, +struct arm_smmu_cmdq *cmdq); +/* Implementation details */ +struct arm_smmu_impl { +int (*device_reset)(struct arm_smmu_device *smmu); +int (*issue_cmdlist)(struct arm_smmu_device *smmu,u64 *cmds,int n,bool sync); +}; +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 +425 -0
425 lines not on this page · raw message
Signature · 1 line
2.17.1
kernel test robot
build botRe: [RFC][Patch v1 2/2] 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 tegra/for-next tegra-drm/drm/tegra/for-next linus/master v5.14-rc2 next-20210723] [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/20210724-033346 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) 10.3.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/3c3adc4970f0dd2ff7ffeadadbf16d9b85315712
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/20210724-033346 git checkout 3c3adc4970f0dd2ff7ffeadadbf16d9b85315712
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.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:368:21: warning: no previous prototype for 'nvidia_smmu_create' [-Wmissing-prototypes]
368 | struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
| ^~~~~~~~~~~~~~~~~~
vim +/nvidia_smmu_create +368 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c
366
367 #ifdef CONFIG_ACPI
> 368 struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
369 {
370 struct nvidia_smmu *nsmmu = NULL;
371 struct acpi_iort_node *node;
372 struct acpi_device *adev;
373 struct device *cmdqv_dev;
374 const char *match_uid;
375
376 if (acpi_disabled)
377 return NULL;
378
379 /* Look for a device in the DSDT whose _UID matches the SMMU's iort_node identifier */
380 node = *(struct acpi_iort_node **)dev_get_platdata(smmu->dev);
381 match_uid = kasprintf(GFP_KERNEL, "%u", node->identifier);
382 adev = acpi_dev_get_first_match_dev(NVIDIA_SMMU_CMDQV_HID, match_uid, -1);
383 kfree(match_uid);
384
385 if (!adev)
386 return NULL;
387
388 cmdqv_dev = bus_find_device_by_acpi_dev(&platform_bus_type, adev);
389 if (!cmdqv_dev)
390 return NULL;
391
392 dev_info(smmu->dev, "found companion CMDQV device, %s", dev_name(cmdqv_dev));
393
394 nsmmu = devm_krealloc(smmu->dev, smmu, sizeof(*nsmmu), GFP_KERNEL);
395 if (!nsmmu)
396 return ERR_PTR(-ENOMEM);
397
398 nsmmu->cmdqv_dev = cmdqv_dev;
399
400 return nsmmu;
401 }
402 #else
403 struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
404 {
405 return NULL;
406 }
407 #endif
408
---
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 v1 2/2] 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 ERROR on iommu/next]
[also build test ERROR on tegra/for-next tegra-drm/drm/tegra/for-next linus/master v5.14-rc2 next-20210723] [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/20210724-033346 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next config: arm64-randconfig-r025-20210723 (attached as .config) compiler: aarch64-linux-gcc (GCC) 10.3.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/3c3adc4970f0dd2ff7ffeadadbf16d9b85315712
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/20210724-033346
git checkout 3c3adc4970f0dd2ff7ffeadadbf16d9b85315712
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/iommu/arm/arm-smmu-v3/ drivers/scsi/pm8001/ kernel/cgroup/
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:96:8: error: unknown type name 'irqreturn_t'
96 | static irqreturn_t nvidia_smmu_cmdqv_isr(int irq, void *devid)
| ^~~~~~~~~~~
drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c: In function 'nvidia_smmu_cmdqv_isr':
>> drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:126:9: error: 'IRQ_HANDLED' undeclared (first use in this function)
126 | return IRQ_HANDLED;
| ^~~~~~~~~~~
drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:126:9: note: each undeclared identifier is reported only once for each function it appears in
drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c: In function 'nvidia_smmu_device_reset':
>> drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:346:9: error: implicit declaration of function 'devm_request_irq'; did you mean 'devm_request_region'? [-Werror=implicit-function-declaration]
346 | ret = devm_request_irq(nsmmu->cmdqv_dev, nsmmu->cmdqv_irq, nvidia_smmu_cmdqv_isr,
| ^~~~~~~~~~~~~~~~
| devm_request_region
>> drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:347:12: error: 'IRQF_SHARED' undeclared (first use in this function)
347 | IRQF_SHARED, "nvidia-smmu-cmdqv", nsmmu);
| ^~~~~~~~~~~ drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c: At top level:
drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c:403:21: warning: no previous prototype for 'nvidia_smmu_create' [-Wmissing-prototypes]
403 | struct nvidia_smmu *nvidia_smmu_create(struct arm_smmu_device *smmu)
| ^~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/irqreturn_t +96 drivers/iommu/arm/arm-smmu-v3/nvidia-smmu-v3.c
95
> 96 static irqreturn_t nvidia_smmu_cmdqv_isr(int irq, void *devid)
97 {
98 struct nvidia_smmu *nsmmu = (struct nvidia_smmu *)devid;
99 struct nvidia_smmu_vintf *vintf0 = &nsmmu->vintf0;
100 u32 vintf_err_map[2];
101 u32 vcmdq_err_map[4];
102
103 vintf_err_map[0] = readl_relaxed(nsmmu->cmdqv_base + NVIDIA_CMDQV_VINTF_ERR_MAP);
104 vintf_err_map[1] = readl_relaxed(nsmmu->cmdqv_base + NVIDIA_CMDQV_VINTF_ERR_MAP + 0x4);
105
106 vcmdq_err_map[0] = readl_relaxed(nsmmu->cmdqv_base + NVIDIA_CMDQV_VCMDQ_ERR_MAP);
107 vcmdq_err_map[1] = readl_relaxed(nsmmu->cmdqv_base + NVIDIA_CMDQV_VCMDQ_ERR_MAP + 0x4);
108 vcmdq_err_map[2] = readl_relaxed(nsmmu->cmdqv_base + NVIDIA_CMDQV_VCMDQ_ERR_MAP + 0x8);
109 vcmdq_err_map[3] = readl_relaxed(nsmmu->cmdqv_base + NVIDIA_CMDQV_VCMDQ_ERR_MAP + 0xC);
110
111 dev_warn(nsmmu->cmdqv_dev,
112 "Unexpected cmdqv error reported: vintf_map %08X %08X, vcmdq_map %08X %08X %08X %08X\n",
113 vintf_err_map[0], vintf_err_map[1], vcmdq_err_map[0], vcmdq_err_map[1],
114 vcmdq_err_map[2], vcmdq_err_map[3]);
115
116 /* If the error was reported by vintf0, avoid using any of its VCMDQs */
117 if (vintf_err_map[vintf0->idx / 32] & (1 << (vintf0->idx % 32))) {
118 vintf0->status = readl_relaxed(vintf0->base + NVIDIA_VINTF_STATUS);
119
120 dev_warn(nsmmu->cmdqv_dev, "error (0x%lX) reported by host vintf0 - disabling its vcmdqs\n",
121 FIELD_GET(VINTF_STATUS, vintf0->status));
122 } else if (vintf_err_map[0] || vintf_err_map[1]) {
123 dev_err(nsmmu->cmdqv_dev, "cmdqv error interrupt triggered by unassigned vintf!\n");
124 }
125
> 126 return IRQ_HANDLED; 127 }
128
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org