]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu/arm-smmu-v3: Support IOMMU_GET_HW_INFO via struct arm_smmu_hw_info
authorNicolin Chen <nicolinc@nvidia.com>
Thu, 31 Oct 2024 00:20:49 +0000 (21:20 -0300)
committerWill Deacon <will@kernel.org>
Tue, 5 Nov 2024 10:24:17 +0000 (10:24 +0000)
For virtualization cases the IDR/IIDR/AIDR values of the actual SMMU
instance need to be available to the VMM so it can construct an
appropriate vSMMUv3 that reflects the correct HW capabilities.

For userspace page tables these values are required to constrain the valid
values within the CD table and the IOPTEs.

The kernel does not sanitize these values. If building a VMM then
userspace is required to only forward bits into a VM that it knows it can
implement. Some bits will also require a VMM to detect if appropriate
kernel support is available such as for ATS and BTM.

Start a new file and kconfig for the advanced iommufd support. This lets
it be compiled out for kernels that are not intended to support
virtualization, and allows distros to leave it disabled until they are
shipping a matching qemu too.

Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: Donald Dutile <ddutile@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/5-v4-9e99b76f3518+3a8-smmuv3_nesting_jgg@nvidia.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/iommu/Kconfig
drivers/iommu/arm/arm-smmu-v3/Makefile
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c [new file with mode: 0644]
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
include/uapi/linux/iommufd.h

index b3aa1f5d53218b0468e2b646289c82396f6ed4aa..0c9bceb1653d5f6019396ab1d87d921f20ec1ffb 100644 (file)
@@ -415,6 +415,15 @@ config ARM_SMMU_V3_SVA
          Say Y here if your system supports SVA extensions such as PCIe PASID
          and PRI.
 
+config ARM_SMMU_V3_IOMMUFD
+       bool "Enable IOMMUFD features for ARM SMMUv3 (EXPERIMENTAL)"
+       depends on IOMMUFD
+       help
+         Support for IOMMUFD features intended to support virtual machines
+         with accelerated virtual IOMMUs.
+
+         Say Y here if you are doing development and testing on this feature.
+
 config ARM_SMMU_V3_KUNIT_TEST
        tristate "KUnit tests for arm-smmu-v3 driver"  if !KUNIT_ALL_TESTS
        depends on KUNIT
index dc98c88b48c827084faecc0e847af262b1e17373..493a659cc66bb226d9dac855857b8ee406def00f 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_ARM_SMMU_V3) += arm_smmu_v3.o
 arm_smmu_v3-y := arm-smmu-v3.o
+arm_smmu_v3-$(CONFIG_ARM_SMMU_V3_IOMMUFD) += arm-smmu-v3-iommufd.o
 arm_smmu_v3-$(CONFIG_ARM_SMMU_V3_SVA) += arm-smmu-v3-sva.o
 arm_smmu_v3-$(CONFIG_TEGRA241_CMDQV) += tegra241-cmdqv.o
 
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
new file mode 100644 (file)
index 0000000..3d26710
--- /dev/null
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES
+ */
+
+#include <uapi/linux/iommufd.h>
+
+#include "arm-smmu-v3.h"
+
+void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type)
+{
+       struct arm_smmu_master *master = dev_iommu_priv_get(dev);
+       struct iommu_hw_info_arm_smmuv3 *info;
+       u32 __iomem *base_idr;
+       unsigned int i;
+
+       info = kzalloc(sizeof(*info), GFP_KERNEL);
+       if (!info)
+               return ERR_PTR(-ENOMEM);
+
+       base_idr = master->smmu->base + ARM_SMMU_IDR0;
+       for (i = 0; i <= 5; i++)
+               info->idr[i] = readl_relaxed(base_idr + i);
+       info->iidr = readl_relaxed(master->smmu->base + ARM_SMMU_IIDR);
+       info->aidr = readl_relaxed(master->smmu->base + ARM_SMMU_AIDR);
+
+       *length = sizeof(*info);
+       *type = IOMMU_HW_INFO_TYPE_ARM_SMMUV3;
+
+       return info;
+}
index 38725810c14eebf7d87c0f9f84d7807e22fdcff9..996774d461aea20708c34a760f4d82a4ccfb68ca 100644 (file)
@@ -3506,6 +3506,7 @@ static struct iommu_ops arm_smmu_ops = {
        .identity_domain        = &arm_smmu_identity_domain,
        .blocked_domain         = &arm_smmu_blocked_domain,
        .capable                = arm_smmu_capable,
+       .hw_info                = arm_smmu_hw_info,
        .domain_alloc_paging    = arm_smmu_domain_alloc_paging,
        .domain_alloc_sva       = arm_smmu_sva_domain_alloc,
        .domain_alloc_user      = arm_smmu_domain_alloc_user,
index 06e3d88932df1212920ee8de1298f384f1afcabc..66261fd5bfb2d2c21b128d7a59b6e4e173fe69af 100644 (file)
@@ -81,6 +81,8 @@ struct arm_smmu_device;
 #define IIDR_REVISION                  GENMASK(15, 12)
 #define IIDR_IMPLEMENTER               GENMASK(11, 0)
 
+#define ARM_SMMU_AIDR                  0x1C
+
 #define ARM_SMMU_CR0                   0x20
 #define CR0_ATSCHK                     (1 << 4)
 #define CR0_CMDQEN                     (1 << 3)
@@ -956,4 +958,11 @@ tegra241_cmdqv_probe(struct arm_smmu_device *smmu)
        return ERR_PTR(-ENODEV);
 }
 #endif /* CONFIG_TEGRA241_CMDQV */
+
+#if IS_ENABLED(CONFIG_ARM_SMMU_V3_IOMMUFD)
+void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type);
+#else
+#define arm_smmu_hw_info NULL
+#endif /* CONFIG_ARM_SMMU_V3_IOMMUFD */
+
 #endif /* _ARM_SMMU_V3_H */
index 72010f71c5e479e26be02435fdc45e990832b687..b5c94fecb94ca5f09a85184c3f009b55582179f4 100644 (file)
@@ -484,15 +484,50 @@ struct iommu_hw_info_vtd {
        __aligned_u64 ecap_reg;
 };
 
+/**
+ * struct iommu_hw_info_arm_smmuv3 - ARM SMMUv3 hardware information
+ *                                   (IOMMU_HW_INFO_TYPE_ARM_SMMUV3)
+ *
+ * @flags: Must be set to 0
+ * @__reserved: Must be 0
+ * @idr: Implemented features for ARM SMMU Non-secure programming interface
+ * @iidr: Information about the implementation and implementer of ARM SMMU,
+ *        and architecture version supported
+ * @aidr: ARM SMMU architecture version
+ *
+ * For the details of @idr, @iidr and @aidr, please refer to the chapters
+ * from 6.3.1 to 6.3.6 in the SMMUv3 Spec.
+ *
+ * User space should read the underlying ARM SMMUv3 hardware information for
+ * the list of supported features.
+ *
+ * Note that these values reflect the raw HW capability, without any insight if
+ * any required kernel driver support is present. Bits may be set indicating the
+ * HW has functionality that is lacking kernel software support, such as BTM. If
+ * a VMM is using this information to construct emulated copies of these
+ * registers it should only forward bits that it knows it can support.
+ *
+ * In future, presence of required kernel support will be indicated in flags.
+ */
+struct iommu_hw_info_arm_smmuv3 {
+       __u32 flags;
+       __u32 __reserved;
+       __u32 idr[6];
+       __u32 iidr;
+       __u32 aidr;
+};
+
 /**
  * enum iommu_hw_info_type - IOMMU Hardware Info Types
  * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware
  *                           info
  * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type
+ * @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type
  */
 enum iommu_hw_info_type {
        IOMMU_HW_INFO_TYPE_NONE = 0,
        IOMMU_HW_INFO_TYPE_INTEL_VTD = 1,
+       IOMMU_HW_INFO_TYPE_ARM_SMMUV3 = 2,
 };
 
 /**