Skip to contentSkip to conversation

iommu/arm-smmu-v3: Add a configurable tlbi_range_max_n_shift for TLBI

PATCH In review Nicolin Chen 2 participants 5 messages Aug 14, 2023 – Aug 16, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/arm-smmu-v3: Add a configurable tlbi_range_max_n_shift for TLBI

When receiving an __arm_smmu_tlb_inv_range() call with a large size, there could be a long latency at this function call: one part is coming from a large software overhead in the routine of building commands, and the other part is coming from CMDQ hardware consuming the large number of commands. This latency could be significantly large on an SMMU that does not support range invalidation commands, i.e. no ARM_SMMU_FEAT_RANGE_INV.

One way to optimize this is to replace a large number of VA invalidation commands with one single per-asid invalidation command, when the requested size is above a threshold. This threshold can be configurable depending on the SMMU implementaion, and its default value can be VA_BITS, so it'd even make sense for SMMUs with ARM_SMMU_FEAT_RANGE_INV to do such a replacement.

Add a tlbi_range_max_n_shift threshold per SMMU device and allow it to be configured via an SYSFS node, and then add an ABI doc for this new node.

---
 .../ABI/testing/sysfs-class-iommu-arm-smmu-v3 |  8 +++
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c   | 54 ++++++++++++++++++-
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h   |  3 ++
 3 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-iommu-arm-smmu-v3
Documentation/ABI/testing/sysfs-class-iommu-arm-smmu-v3 new file +8 -0
new file mode 100644
index 000000000000..ed1a8ead82d3
@@ -0,0 +1,8 @@
+What:		/sys/class/iommu/<iommu>/arm-smmu-v3/tlbi_range_max_n_shift
+Date:		August 2023
+KernelVersion:	6.6
+Contact:	Nicolin Chen <[email protected]>
+Description:
+		Max number of shift to set up a threshold for SMMU to replace
+		VA invalidation commands with a single per-asid invalidation.
+		Format: %u
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +53 -1

83 lines not on this page · raw message

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +3 -0
index dcab85698a4e..07636d596901 100644
@@ -665,6 +665,9 @@ struct arm_smmu_device {
 	unsigned long			oas; /* PA */
 	unsigned long			pgsize_bitmap;
 
+	/* Threshold to convert VA range TLBI to asid TLBI */
+	unsigned int			tlbi_range_max_n_shift;
+
 #define ARM_SMMU_MAX_ASIDS		(1 << 16)
 	unsigned int			asid_bits;
 
Signature · 1 line
2.41.0
#1 lore raw

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) · line 3829

Quoted 8 lines · Nicolin Chen
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +8 -0
+static ssize_t tlbi_range_max_n_shift_show(struct device *dev,
+					   struct device_attribute *attr,
+					   char *buf)
+{
+	struct arm_smmu_device *smmu = dev_get_drvdata(dev->parent);
+
+	return sprintf(buf, "%u\n", smmu->tlbi_range_max_n_shift);
+}

sysfs_emit and missing newline

Quoted 5 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +5 -0
+static ssize_t tlbi_range_max_n_shift_store(struct device *dev,
+					    struct device_attribute *attr,
+					    const char *buf, size_t size)
+{
+	struct arm_smmu_device *smmu = dev_get_drvdata(dev->parent);

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) · line 3844

Quoted 10 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +10 -0
+	unsigned int max_n_shift;
+	int ret;
+
+	ret = kstrtou32(buf, 0, &max_n_shift);
+	if (ret)
+		return ret;
+	if (max_n_shift > VA_BITS || max_n_shift < PAGE_SHIFT)
+		return -EINVAL;
+	smmu->tlbi_range_max_n_shift = max_n_shift;
+	return size;

This seems convoluted for a uapi, you should just make it 'invalidate_threshold' in bytes or something simpler.

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) · line 3856

Quoted 5 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +5 -0
+
+static struct attribute_group arm_smmu_group = {
+	.name = "arm-smmu-v3",
+	.attrs = arm_smmu_attrs,
+};

Do we really need the subdirectory?

Jason

#2 lore raw
Quoted 11 lines · Jason Gunthorpe

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) · line 3829

Quoted 8 lines · Nicolin Chen
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +8 -0
+static ssize_t tlbi_range_max_n_shift_show(struct device *dev,
+					   struct device_attribute *attr,
+					   char *buf)
+{
+	struct arm_smmu_device *smmu = dev_get_drvdata(dev->parent);
+
+	return sprintf(buf, "%u\n", smmu->tlbi_range_max_n_shift);
+}

sysfs_emit and missing newline

Will replace and add a new line.

Quoted 10 lines
Quoted 10 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +10 -0
+static ssize_t tlbi_range_max_n_shift_store(struct device *dev,
+					    struct device_attribute *attr,
+					    const char *buf, size_t size)
+{
+	struct arm_smmu_device *smmu = dev_get_drvdata(dev->parent);
+	unsigned int max_n_shift;
+	int ret;
+
+	ret = kstrtou32(buf, 0, &max_n_shift);
+	if (ret)
Quoted 8 lines

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) · line 3844

Quoted 5 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +5 -0
+		return ret;
+	if (max_n_shift > VA_BITS || max_n_shift < PAGE_SHIFT)
+		return -EINVAL;
+	smmu->tlbi_range_max_n_shift = max_n_shift;
+	return size;

This seems convoluted for a uapi, you should just make it 'invalidate_threshold' in bytes or something simpler.

Hmm. That'd be a direct 64-bit size configuration, and very likely to be at upper 32-bit range, so I feel the value would be very big that might be hard to read.

With that said, I can rename the uAPI, yet still keep the bitshift configuration.

Quoted 6 lines

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) · line 3856

Quoted 4 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +4 -0
+static struct attribute_group arm_smmu_group = {
+	.name = "arm-smmu-v3",
+	.attrs = arm_smmu_attrs,
+};

Do we really need the subdirectory?

OK. Let me try unfolding it.

Thanks!
Nicolin

#3 lore raw
Quoted 6 lines · Nicolin Chen
Quoted 2 lines

This seems convoluted for a uapi, you should just make it 'invalidate_threshold' in bytes or something simpler.

Hmm. That'd be a direct 64-bit size configuration, and very likely to be at upper 32-bit range, so I feel the value would be very big that might be hard to read.

hard to read is fine, it is sysfs

Jason

#4 lore raw
Quoted 9 lines · Jason Gunthorpe
Quoted 6 lines · Nicolin Chen
Quoted 2 lines

This seems convoluted for a uapi, you should just make it 'invalidate_threshold' in bytes or something simpler.

Hmm. That'd be a direct 64-bit size configuration, and very likely to be at upper 32-bit range, so I feel the value would be very big that might be hard to read.

hard to read is fine, it is sysfs

OK. I'd just do it in size then.

Thanks
Nic