Re: [PATCH v2 11/12] iommu/amd: Add support for nested domain attach/detach
From: Sairaj Kodilkar
Date: Thu Oct 09 2025 - 03:19:07 EST
On 10/8/2025 5:13 AM, Jason Gunthorpe wrote:
On Tue, Oct 07, 2025 at 02:22:30PM -0500, Suthikulpanit, Suravee wrote:An alternative can be to introduce a struct which only contains relevant fields.
Sorry some make_ste_v1()
On 10/6/2025 9:59 AM, Jason Gunthorpe wrote:
On Wed, Oct 01, 2025 at 06:09:53AM +0000, Suravee Suthikulpanit wrote:Not sure what you mean. This logic was in set_dte_entry(), and duplicated
....This sequence should be in some set_dte_gcr3() ??
+ if (WARN_ON(!ndom || !pdom || (pdom->iop.mode == PAGE_MODE_NONE)))
+ return;
+
+ amd_iommu_make_clear_dte(dev_data, &new);
+
+ new.data[0] |= iommu_virt_to_phys(pdom->iop.root);
+ new.data[0] |= FIELD_PREP(DTE_MODE_MASK, pdom->iop.mode);
+ new.data[0] |= DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_TV;
+ new.data[0] |= (DTE_FLAG_PPR & gdte->data[0]);
+ if (pdom->dirty_tracking)
+ new.data[0] |= DTE_FLAG_HAD;
+
+ if (dev_data->ats_enabled)
+ new.data[1] |= DTE_FLAG_IOTLB;
here in the set_dte_nested() since we no longer calling set_dte_entry() from
the nested path. Also, it's not really related to GCR3 table.
This logic should be the same for any v1 page table.
Yes, but it seems like that is the right behavior?Currently, the amd_iommu_make_clear_dte() clears all the DTE bits and set+ /*This should go into amd_iommu_make_clear_dte() I think, and refactor
+ * Restore cached persistent DTE bits, which can be set by information
+ * in IVRS table. See set_dev_entry_from_acpi().
+ */
+ initial_dte = amd_iommu_get_ivhd_dte_flags(iommu->pci_seg->id, dev_data->devid);
+ if (initial_dte) {
+ new.data128[0] |= initial_dte->data128[0];
+ new.data128[1] |= initial_dte->data128[1];
+ }
it out of iommu_update_dte256() ?
Every created DTE needs these bits set, right?
the DTE[V] (valid) bit. This is used when preparing the DTE for programming,
detaching domain, and when setting the blocking domain. Putting this logic
in the function would change the behavior.
These bits affect Interrupt remapping (Lint0/Lint1/NMI/INIT/ExtInt interruptBecause these bits shouldn't be cleared on a blocking domain!
pass-through) and System management message behavior.
Interrupts are still expected to work.
You have to validate gdte has only valid bits.Not sure which on are you referring to.+I didn't see anything validating gdte has only permitted set bits in
+ /* Guest translation stuff */
+ new.data[0] |= (gdte->data[0] &
+ (DTE_GLX | DTE_FLAG_GV | DTE_FLAG_GIOV));
+
+ /* GCR3 table */
+ new.data[0] |= (gdte->data[0] & DTE_GCR3_14_12);
+ new.data[1] |= (gdte->data[1] & (DTE_GCR3_30_15 | DTE_GCR3_51_31));
+
+ /* Guest paging mode */
+ new.data[2] |= (gdte->data[2] & DTE_GPT_LEVEL_MASK);
the prior patch?
The appropriate type is the userspace type if you don't actually everIf this is goint to decode array item by item then why not use structThe struct dev_table_entry *gdte is basically the same information as in the
iommu_hwpt_amd_guest in the nested_domain ?
struct iommu_hwpt_amd_guest.dte that we copied from the userspace into the
more appropriate in-kernel data structure type, which is used within the
driver.
use anything unique to the kernel type. You can avoid the special
assert/etc since this way of accessing it is not sensitive to layout.
Here, we just select only what we needed for configuring guest page tableEverything you don't pick up should be checked to be 0. VMM needs to
specifically to be programmed onto the host DTE.
filter out unsuopported things or generate a bad DTE error.
Something similar to -->
struct iommu_hwpt_amd_guest {
void *gcr3;
unsigned char guest_paging_mode;
}
VMM can take care of writing to these fields.
Thanks
Sairaj