Skip to contentSkip to conversation

iommu/vt-d: Set SSADE when attaching to a parent with dirty tracking

PATCH In review Yi Liu 4 participants 6 messages Feb 8, 2024 – Feb 19, 2024

Subsystems (4)
lore
Share & tools
lore

Yi Liu

author
#0 lore raw

PATCH 1/1 iommu/vt-d: Set SSADE when attaching to a parent with dirty tracking

Should set the SSADE (Second Stage Access/Dirty bit Enable) bit of the pasid entry when attaching a device to a nested domain if its parent has already enabled dirty tracking.

Fixes 111bf85c68f6 ("iommu/vt-d: Add helper to setup pasid nested translation")

---
base commit: 547ab8fc4cb04a1a6b34377dd8fad34cd2c8a8e3

---
 drivers/iommu/intel/pasid.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/intel/pasid.c +2 -0
index 3239cefa4c33..9be24bb762cf 100644
@@ -658,6 +658,8 @@ int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev,
 	pasid_set_domain_id(pte, did);
 	pasid_set_address_width(pte, s2_domain->agaw);
 	pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
+	if (s2_domain->dirty_tracking)
+		pasid_set_ssade(pte);
 	pasid_set_translation_type(pte, PASID_ENTRY_PGTT_NESTED);
 	pasid_set_present(pte);
 	spin_unlock(&iommu->lock);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Yi Liu

Should set the SSADE (Second Stage Access/Dirty bit Enable) bit of the pasid entry when attaching a device to a nested domain if its parent has already enabled dirty tracking.

Fixes 111bf85c68f6 ("iommu/vt-d: Add helper to setup pasid nested translation")
Quoted 19 lines

---
base commit: 547ab8fc4cb04a1a6b34377dd8fad34cd2c8a8e3

---
 drivers/iommu/intel/pasid.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/intel/pasid.c +2 -0
index 3239cefa4c33..9be24bb762cf 100644
@@ -658,6 +658,8 @@ int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev,
 	pasid_set_domain_id(pte, did);
 	pasid_set_address_width(pte, s2_domain->agaw);
 	pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
+	if (s2_domain->dirty_tracking)
+		pasid_set_ssade(pte);
 	pasid_set_translation_type(pte, PASID_ENTRY_PGTT_NESTED);
 	pasid_set_present(pte);
 	spin_unlock(&iommu->lock);
#2 lore raw
Quoted 10 lines · Joao Martins
Quoted 6 lines · Yi Liu

Should set the SSADE (Second Stage Access/Dirty bit Enable) bit of the pasid entry when attaching a device to a nested domain if its parent has already enabled dirty tracking.

Fixes 111bf85c68f6 ("iommu/vt-d: Add helper to setup pasid nested translation")

On a second thought, while the patch looks fine if this is what we wanna do, just a quick clarification on the why (that's also applicable to the last patch of your other series[0]). I am sure I am missing something :)

Shouldn't the nested domain be subdued to whatever features guest idea of ecap/cap instead of host's view? Or is this because guest first-stage page table on Intel is supposed to be always-enabled dirty tracking (per SDM) ? If it's the latter, it probably should be sprinkled in the commit message(s).

[0] https://lore.kernel.org/linux-iommu/[email protected]/

Quoted 20 lines
Quoted 19 lines

---
base commit: 547ab8fc4cb04a1a6b34377dd8fad34cd2c8a8e3

---
 drivers/iommu/intel/pasid.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/intel/pasid.c +2 -0
index 3239cefa4c33..9be24bb762cf 100644
@@ -658,6 +658,8 @@ int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev,
 	pasid_set_domain_id(pte, did);
 	pasid_set_address_width(pte, s2_domain->agaw);
 	pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
+	if (s2_domain->dirty_tracking)
+		pasid_set_ssade(pte);
 	pasid_set_translation_type(pte, PASID_ENTRY_PGTT_NESTED);
 	pasid_set_present(pte);
 	spin_unlock(&iommu->lock);
#3 lore raw
Quoted 19 lines

From: Joao Martins <[email protected]>
Sent: Friday, February 9, 2024 6:36 PM

Quoted 6 lines · Joao Martins
Quoted 5 lines · Yi Liu

Should set the SSADE (Second Stage Access/Dirty bit Enable) bit of the pasid entry when attaching a device to a nested domain if its parent has already enabled dirty tracking.

Fixes 111bf85c68f6 ("iommu/vt-d: Add helper to setup pasid nested

translation")

Quoted 4 lines
Quoted 1 line

On a second thought, while the patch looks fine if this is what we wanna do, just a quick clarification on the why (that's also applicable to the last patch of your other series[0]). I am sure I am missing something :)

Quoted 9 lines

Shouldn't the nested domain be subdued to whatever features guest idea of ecap/cap instead of host's view? Or is this because guest first-stage page table
on Intel is supposed to be always-enabled dirty tracking (per SDM) ? If it's the latter, it probably should be sprinkled in the commit message(s).

[0] https://lore.kernel.org/linux-iommu/20240208082307.15759-9-
[email protected]/

first-stage dirty tracking is always enabled. but the real point here is that the host has enabled dirty-tracking in second-stage so when a device is attached to a nested domain on top of that second-stage we should set SSADE in the pasid entry for that device.

even if there is a guest ecap/cap for first-stage dirty tracking that shouldn't affect the host setting for second-stage which is invisible to the guest.

maintainer
#4 lore raw
In reply to Yi Liu
Quoted 17 lines · Yi Liu

Should set the SSADE (Second Stage Access/Dirty bit Enable) bit of the pasid entry when attaching a device to a nested domain if its parent has already enabled dirty tracking.

Fixes 111bf85c68f6 ("iommu/vt-d: Add helper to setup pasid nested translation")

---
base commit: 547ab8fc4cb04a1a6b34377dd8fad34cd2c8a8e3

---
  drivers/iommu/intel/pasid.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/iommu/intel/pasid.c +0 -0
index 3239cefa4c33..9be24bb762cf 100644

drivers/iommu/intel/pasid.c int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev, · line 665

Quoted 8 lines
drivers/iommu/intel/pasid.c +2 -0
@@ -658,6 +658,8 @@ int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev,
  	pasid_set_domain_id(pte, did);
  	pasid_set_address_width(pte, s2_domain->agaw);
  	pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
+	if (s2_domain->dirty_tracking)
+		pasid_set_ssade(pte);
  	pasid_set_translation_type(pte, PASID_ENTRY_PGTT_NESTED);
  	pasid_set_present(pte);
  	spin_unlock(&iommu->lock);

The same fix should also be applied to the intel_pasid_setup_second() path. Specifically, if a second-stage domain with dirty tracking enabled attaches to a device, the corresponding entry in the pasid table should also have the SSADE bit set.

Best regards,
baolu

#5 lore raw
Quoted 24 lines · Baolu Lu
Quoted 23 lines · Yi Liu

Should set the SSADE (Second Stage Access/Dirty bit Enable) bit of the pasid entry when attaching a device to a nested domain if its parent has already enabled dirty tracking.

Fixes 111bf85c68f6 ("iommu/vt-d: Add helper to setup pasid nested translation")

---
base commit: 547ab8fc4cb04a1a6b34377dd8fad34cd2c8a8e3
---
  drivers/iommu/intel/pasid.c | 2 ++

  1 file changed, 2 insertions(+)
drivers/iommu/intel/pasid.c +2 -0
index 3239cefa4c33..9be24bb762cf 100644
@@ -658,6 +658,8 @@ int intel_pasid_setup_nested(struct intel_iommu *iommu,
 struct device *dev,
       pasid_set_domain_id(pte, did);
       pasid_set_address_width(pte, s2_domain->agaw);
       pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
+    if (s2_domain->dirty_tracking)
+        pasid_set_ssade(pte);
Quoted 9 lines
Quoted 3 lines
drivers/iommu/intel/pasid.c +0 -0
       pasid_set_translation_type(pte, PASID_ENTRY_PGTT_NESTED);
       pasid_set_present(pte);

      spin_unlock(&iommu->lock);

The same fix should also be applied to the intel_pasid_setup_second() path. Specifically, if a second-stage domain with dirty tracking enabled attaches to a device, the corresponding entry in the pasid table should also have the SSADE bit set.

I think that's already done, see below.

/*
* Set up the scalable mode pasid entry for second only translation type. */
int intel_pasid_setup_second_level(struct intel_iommu *iommu,
struct dmar_domain *domain, struct device *dev, u32 pasid)
{
(...)

	pasid_clear_entry(pte);
	pasid_set_domain_id(pte, did);
	pasid_set_slptr(pte, pgd_val);
	pasid_set_address_width(pte, agaw);
	pasid_set_translation_type(pte, PASID_ENTRY_PGTT_SL_ONLY);
	pasid_set_fault_enable(pte);
	pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
	if (domain->dirty_tracking)
		pasid_set_ssade(pte);

(...)
}