File 5d80e80d-AMD-IOMMU-valid-flag-for-IVRS-mappings.patch of Package xen.17316
References: bsc#1135799
# Commit 34c0dcf84ff6347424808d2740398c892b8ff8e4
# Date 2019-09-17 16:05:01 +0200
# Author Jan Beulich <jbeulich@suse.com>
# Committer Jan Beulich <jbeulich@suse.com>
AMD/IOMMU: introduce a "valid" flag for IVRS mappings
For us to no longer blindly allocate interrupt remapping tables for
everything the ACPI tables name, we can't use struct ivrs_mappings'
intremap_table field anymore to also have the meaning of "this entry
is valid". Add a separate boolean field instead.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
--- a/xen/drivers/passthrough/amd/iommu_acpi.c
+++ b/xen/drivers/passthrough/amd/iommu_acpi.c
@@ -88,6 +88,8 @@ static void __init add_ivrs_mapping_entr
}
}
+ ivrs_mappings[alias_id].valid = true;
+
/* Assign IOMMU hardware. */
ivrs_mappings[bdf].iommu = iommu;
}
--- a/xen/drivers/passthrough/amd/iommu_init.c
+++ b/xen/drivers/passthrough/amd/iommu_init.c
@@ -1247,7 +1247,6 @@ static int __init amd_iommu_setup_device
u16 seg, struct ivrs_mappings *ivrs_mappings)
{
unsigned int bdf;
- void *intr_tb, *dte;
BUG_ON( (ivrs_bdf_entries == 0) );
@@ -1267,16 +1266,17 @@ static int __init amd_iommu_setup_device
/* Add device table entries */
for ( bdf = 0; bdf < ivrs_bdf_entries; bdf++ )
{
- intr_tb = ivrs_mappings[bdf].intremap_table;
-
- if ( intr_tb )
+ if ( ivrs_mappings[bdf].valid )
{
+ void *dte;
+
/* add device table entry */
dte = device_table.buffer + (bdf * IOMMU_DEV_TABLE_ENTRY_SIZE);
iommu_dte_add_device_entry(dte, &ivrs_mappings[bdf]);
amd_iommu_set_intremap_table(
- dte, (u64)virt_to_maddr(intr_tb), iommu_intremap);
+ dte, virt_to_maddr(ivrs_mappings[bdf].intremap_table),
+ iommu_intremap);
}
}
--- a/xen/drivers/passthrough/amd/pci_amd_iommu.c
+++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c
@@ -69,8 +69,8 @@ struct amd_iommu *find_iommu_for_device(
* table and I/O page table respectively. Such devices will have
* both alias entry and select entry in IVRS structure.
*
- * Return original device id, if device has valid interrupt remapping
- * table setup for both select entry and alias entry.
+ * Return original device id if both the specific entry and the alias entry
+ * have been marked valid.
*/
int get_dma_requestor_id(u16 seg, u16 bdf)
{
@@ -79,8 +79,7 @@ int get_dma_requestor_id(u16 seg, u16 bd
BUG_ON ( bdf >= ivrs_bdf_entries );
req_id = ivrs_mappings[bdf].dte_requestor_id;
- if ( (ivrs_mappings[bdf].intremap_table != NULL) &&
- (ivrs_mappings[req_id].intremap_table != NULL) )
+ if ( ivrs_mappings[bdf].valid && ivrs_mappings[req_id].valid )
req_id = bdf;
return req_id;
--- a/xen/include/asm-x86/amd-iommu.h
+++ b/xen/include/asm-x86/amd-iommu.h
@@ -116,6 +116,7 @@ struct ivrs_mappings {
u8 unity_map_enable;
u8 write_permission;
u8 read_permission;
+ bool valid;
unsigned long addr_range_start;
unsigned long addr_range_length;
struct amd_iommu *iommu;