VT-d: avoid PCI device lookup / other tidying
cover VT-d: avoid PCI device lookup / other tidying
1: tidy <X>_to_<Y>() functions
2: avoid PCI device lookup
3: ATS: tidy device_in_domain()
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/3 VT-d: tidy <X>_to_<Y>() functions
Drop iommu_to_drhd() altogether - there's no need for a loop here, the corresponding DRHD is a field in struct intel_iommu.
Constify drhd_to_rhsa()'s parameter and adjust style.
xen/drivers/passthrough/vtd/dmar.c +3 -17
@@ -128,7 +128,7 @@ static int acpi_ioapic_device_match(return 0 ; } -struct acpi_drhd_unit *ioapic_to_drhd (unsigned int apic_id) +struct acpi_drhd_unit *ioapic_to_drhd (unsigned int apic_id) {struct acpi_drhd_unit *drhd;list_for_each_entry ( drhd, &acpi_drhd_units, list )
@@ -137,21 +137,7 @@ struct acpi_drhd_unit * ioapic_to_drhd(ureturn NULL ; } -struct acpi_drhd_unit *iommu_to_drhd (struct iommu *iommu) -{ -struct acpi_drhd_unit *drhd; - -if ( iommu ==NULL ) -return NULL ; - -list_for_each_entry ( drhd, &acpi_drhd_units, list ) -if ( drhd->iommu == iommu ) -return drhd; - -return NULL ; -} - -struct iommu *ioapic_to_iommu (unsigned int apic_id) +struct iommu *ioapic_to_iommu (unsigned int apic_id) {struct acpi_drhd_unit *drhd;
@@ -265,7 +251,7 @@ struct acpi_atsr_unit *acpi_find_matchedreturn all_ports; } -struct acpi_rhsa_unit *drhd_to_rhsa (struct acpi_drhd_unit *drhd) +struct acpi_rhsa_unit *drhd_to_rhsa (const struct acpi_drhd_unit *drhd) {struct acpi_rhsa_unit *rhsa;
xen/drivers/passthrough/vtd/extern.h +5 -6
@@ -52,12 +52,11 @@ int iommu_flush_iec_global(struct iommuint iommu_flush_iec_index (struct iommu *iommu,u8 im,u16 iidx);void clear_fault_bits (struct iommu *iommu); -struct iommu *ioapic_to_iommu (unsigned int apic_id); -struct iommu *hpet_to_iommu (unsigned int hpet_id); -struct acpi_drhd_unit *ioapic_to_drhd (unsigned int apic_id); -struct acpi_drhd_unit *hpet_to_drhd (unsigned int hpet_id); -struct acpi_drhd_unit *iommu_to_drhd (struct iommu *iommu); -struct acpi_rhsa_unit *drhd_to_rhsa (struct acpi_drhd_unit *drhd); +struct iommu *ioapic_to_iommu (unsigned int apic_id); +struct iommu *hpet_to_iommu (unsigned int hpet_id); +struct acpi_drhd_unit *ioapic_to_drhd (unsigned int apic_id); +struct acpi_drhd_unit *hpet_to_drhd (unsigned int hpet_id); +struct acpi_rhsa_unit *drhd_to_rhsa (const struct acpi_drhd_unit *drhd);struct acpi_drhd_unit *find_ats_dev_drhd (struct iommu *iommu);
xen/drivers/passthrough/vtd/intremap.c +2 -3
@@ -760,7 +760,6 @@ int __init intel_setup_hpet_msi(struct mint enable_intremap (struct iommu *iommu,int eim) { -struct acpi_drhd_unit *drhd;struct ir_ctrl *ir_ctrl;u32 sts, gcmd;unsigned long flags;
@@ -796,8 +795,8 @@ int enable_intremap(struct iommu *iommu,if ( ir_ctrl->iremap_maddr ==0 ) { - drhd =iommu_to_drhd (iommu); - ir_ctrl->iremap_maddr =alloc_pgtable_maddr (drhd,IREMAP_ARCH_PAGE_NR ); + ir_ctrl->iremap_maddr =alloc_pgtable_maddr (iommu->intel->drhd, +IREMAP_ARCH_PAGE_NR );if ( ir_ctrl->iremap_maddr ==0 ) { dprintk(XENLOG_WARNING VTDPREFIX,
xen/drivers/passthrough/vtd/iommu.c +1 -3
@@ -224,7 +224,6 @@ void free_pgtable_maddr(u64 maddr)/* context entry handling */ static u64 bus_to_context_maddr (struct iommu *iommu,u8 bus) { -struct acpi_drhd_unit *drhd;struct root_entry *root, *root_entries;u64 maddr;
@@ -233,8 +232,7 @@ static u64 bus_to_context_maddr(struct i root = &root_entries[bus];if ( !root_present (*root) ) { - drhd =iommu_to_drhd (iommu); - maddr =alloc_pgtable_maddr (drhd,1 ); + maddr =alloc_pgtable_maddr (iommu->intel->drhd,1 );if ( maddr ==0 ) {unmap_vtd_domain_page (root_entries);
xen/drivers/passthrough/vtd/qinval.c +2 -3
@@ -397,7 +397,6 @@ static int __must_check flush_iotlb_qi(vint enable_qinval (struct iommu *iommu) { -struct acpi_drhd_unit *drhd;struct qi_ctrl *qi_ctrl;struct iommu_flush *flush;u32 sts;
@@ -416,8 +415,8 @@ int enable_qinval(struct iommu *iommu)if ( qi_ctrl->qinval_maddr ==0 ) { - drhd =iommu_to_drhd (iommu); - qi_ctrl->qinval_maddr =alloc_pgtable_maddr (drhd,QINVAL_ARCH_PAGE_NR ); + qi_ctrl->qinval_maddr =alloc_pgtable_maddr (iommu->intel->drhd, +QINVAL_ARCH_PAGE_NR );if ( qi_ctrl->qinval_maddr ==0 ) { dprintk(XENLOG_WARNING VTDPREFIX,
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/3] VT-d: tidy <X>_to_<Y>() functions
Quoted 10 lines
From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, September 4, 2019 9:27 PMDrop
iommu_to_drhd()altogether - there's no need for a loop here, the corresponding DRHD is a field in structintel_iommu.Constify drhd_to_rhsa()'s parameter and adjust style.
Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/3 VT-d: avoid PCI device lookup
In reply to Jan BeulichThe two uses of pci_get_pdev_by_domain() lack proper locking, but are also only used to get hold of a NUMA node ID. Calculate and store the node ID earlier on and remove the lookups (in lieu of fixing the locking).
While doing this it became apparent that iommu_alloc()'s use of alloc_pgtable_maddr() would occur before RHSAs would have been parsed:iommu_alloc() gets called from the DRHD parsing routine, which - on spec conforming platforms - happens strictly before RHSA parsing. Defer the allocation until after all ACPI table parsing has finished, established the node ID there first.
xen/drivers/passthrough/iommu.c +4 -0
@@ -151,6 +151,10 @@ int iommu_domain_init(struct domain *d)struct domain_iommu *hd =dom_iommu (d);int ret =0 ; +#ifdef CONFIG_NUMA + hd->node =NUMA_NO_NODE ; +#endif + ret =arch_iommu_domain_init (d);if ( ret )return ret;
xen/drivers/passthrough/vtd/dmar.c +16 -0
@@ -965,6 +965,7 @@ int __init acpi_dmar_init(void) {acpi_physical_address dmar_addr;acpi_native_uint dmar_len; +const struct acpi_drhd_unit *drhd;int ret; if ( ACPI_SUCCESS(acpi_get_table_phys(ACPI_SIG_DMAR, 0,
@@ -978,6 +979,21 @@ int __init acpi_dmar_init(void) ret =parse_dmar_table (acpi_parse_dmar); +for_each_drhd_unit ( drhd ) + { +const struct acpi_rhsa_unit *rhsa =drhd_to_rhsa (drhd); +struct iommu *iommu = drhd->iommu; + +if ( ret ) +break ; + +if ( rhsa ) + iommu->intel->node =pxm_to_node (rhsa->proximity_domain); + +if ( !(iommu->root_maddr =alloc_pgtable_maddr (1 , iommu->intel->node)) ) + ret = -ENOMEM ; + } +if ( !ret ) { iommu_init_ops = &intel_iommu_init_ops;
xen/drivers/passthrough/vtd/extern.h +1 -1
@@ -73,7 +73,7 @@ unsigned int get_cache_line_size(void);void cacheline_flush (char *);void flush_all_cache (void ); -u64 alloc_pgtable_maddr (struct acpi_drhd_unit *drhd,unsigned long npages); +uint64_t alloc_pgtable_maddr (unsigned long npages,nodeid_t node);void free_pgtable_maddr (u64 maddr);void *map_vtd_domain_page (u64 maddr);void unmap_vtd_domain_page (void *va);
xen/drivers/passthrough/vtd/intremap.c +2 -2
@@ -795,8 +795,8 @@ int enable_intremap(struct iommu *iommu,if ( ir_ctrl->iremap_maddr ==0 ) { - ir_ctrl->iremap_maddr =alloc_pgtable_maddr (iommu->intel->drhd, -IREMAP_ARCH_PAGE_NR ); + ir_ctrl->iremap_maddr =alloc_pgtable_maddr (IREMAP_ARCH_PAGE_NR , + iommu->intel->node);if ( ir_ctrl->iremap_maddr ==0 ) { dprintk(XENLOG_WARNING VTDPREFIX,
xen/drivers/passthrough/vtd/iommu.c +19 -27
95 lines not on this page · raw message
xen/drivers/passthrough/vtd/iommu.h +1 -0
@@ -530,6 +530,7 @@ struct intel_iommu {struct ir_ctrl ir_ctrl;struct iommu_flush flush;struct acpi_drhd_unit *drhd; +nodeid_t node; };struct iommu {
xen/drivers/passthrough/vtd/qinval.c +2 -2
@@ -415,8 +415,8 @@ int enable_qinval(struct iommu *iommu)if ( qi_ctrl->qinval_maddr ==0 ) { - qi_ctrl->qinval_maddr =alloc_pgtable_maddr (iommu->intel->drhd, -QINVAL_ARCH_PAGE_NR ); + qi_ctrl->qinval_maddr =alloc_pgtable_maddr (QINVAL_ARCH_PAGE_NR , + iommu->intel->node);if ( qi_ctrl->qinval_maddr ==0 ) { dprintk(XENLOG_WARNING VTDPREFIX,
xen/include/xen/iommu.h +5 -0
@@ -266,6 +266,11 @@ struct domain_iommu {struct list_head dt_devices;#endif +#ifdef CONFIG_NUMA +/* NUMA node to do IOMMU related allocations against. */ +nodeid_t node; +#endif +/* Features supported by the IOMMU */ DECLARE_BITMAP (features, IOMMU_FEAT_count);
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/3] VT-d: avoid PCI device lookup
xen/drivers/passthrough/vtd/iommu.h struct intel_iommu { · line 534
Quoted 8 lines · Jan Beulich
xen/drivers/passthrough/vtd/iommu.h +1
-0@@ -530,6 +530,7 @@ struct intel_iommu {struct ir_ctrl ir_ctrl;struct iommu_flush flush;struct acpi_drhd_unit *drhd; +nodeid_t node; };
Can I talk you into putting this into "struct iommu" immediately?
It will collide far less with the series I've got that folds all of these redundant structs together.
~Andrew
https://lore.kernel.org/xen-devel/[email protected]/
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/3] VT-d: avoid PCI device lookup
Quoted 11 lines · Andrew Cooper
xen/drivers/passthrough/vtd/iommu.h struct intel_iommu { · line 534
Quoted 8 lines · Jan Beulich
xen/drivers/passthrough/vtd/iommu.h +1
-0@@ -530,6 +530,7 @@ struct intel_iommu {struct ir_ctrl ir_ctrl;struct iommu_flush flush;struct acpi_drhd_unit *drhd; +nodeid_t node; };Can I talk you into putting this into "struct iommu" immediately?
Of course. It's this way simply because I forgot ...
Quoted 6 lines
It will collide far less with the series I've got that folds all of these redundant structs together.
~Andrew
... that this is all Intel-specific; without further checking I did imply that struct iommu is some generic abstraction that was already broken out. And I didn't want to fiddle with non- VT-d code here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/3] VT-d: avoid PCI device lookup
In reply to Jan BeulichQuoted 15 lines
From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, September 4, 2019 9:28 PMThe two uses of
pci_get_pdev_by_domain()lack proper locking, but are also only used to get hold of a NUMA node ID. Calculate and store the node ID earlier on and remove the lookups (in lieu of fixing the locking).While doing this it became apparent that iommu_alloc()'s use of
alloc_pgtable_maddr()would occur before RHSAs would have been parsed:iommu_alloc()gets called from the DRHD parsing routine, which - on spec conforming platforms - happens strictly before RHSA parsing. Defer the allocation until after all ACPI table parsing has finished, established the node ID there first.
Quoted 3 lines
Suggested-by Kevin Tian <[email protected]>Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/3 VT-d/ATS: tidy device_in_domain()
In reply to Jan BeulichUse appropriate types. Drop unnecessary casts. Check for failures which can (at least in theory because of non-obvious breakage elsewhere) occur, instead of ones which really can't (map_domain_page() won't return NULL).
xen/drivers/passthrough/vtd/x86/ats.c +14 -12
@@ -71,23 +71,25 @@ int ats_device(const struct pci_dev *pdereturn pos; } -static int device_in_domain (const struct iommu *iommu, -const struct pci_dev *pdev,u16 did) +static bool device_in_domain (const struct iommu *iommu, +const struct pci_dev *pdev,uint16_t did) { -struct root_entry *root_entry =NULL ; +struct root_entry *root_entry;struct context_entry *ctxt_entry =NULL ; -int tt, found =0 ; +unsigned int tt; +bool found = false; - root_entry = (struct root_entry *)map_vtd_domain_page (iommu->root_maddr); -if ( !root_entry || !root_present (root_entry[pdev->bus]) ) - goto out; - - ctxt_entry = (struct context_entry *) -map_vtd_domain_page (root_entry[pdev->bus].val); +if (unlikely (!iommu->root_maddr) ) + { +ASSERT_UNREACHABLE (); +return false; + } -if ( ctxt_entry ==NULL ) + root_entry =map_vtd_domain_page (iommu->root_maddr); +if ( !root_present (root_entry[pdev->bus]) ) goto out; + ctxt_entry =map_vtd_domain_page (root_entry[pdev->bus].val);if (context_domain_id (ctxt_entry[pdev->devfn]) != did ) goto out;
@@ -95,7 +97,7 @@ static int device_in_domain(const structif ( tt !=CONTEXT_TT_DEV_IOTLB ) goto out; - found =1 ; + found = true; out:if ( root_entry )unmap_vtd_domain_page (root_entry);
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 3/3] VT-d/ATS: tidy device_in_domain()
Quoted 10 lines
From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, September 4, 2019 9:28 PMUse appropriate types. Drop unnecessary casts. Check for failures which can (at least in theory because of non-obvious breakage elsewhere) occur, instead of ones which really can't (
map_domain_page()won't return NULL).Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel