From mboxrd@z Thu Jan 1 00:00:00 1970 From: Suravee Suthikulpanit Subject: Re: [PATCH RFC 2/2] AMD IOMMU: allow command line overrides for broken IVRS tables Date: Wed, 28 Aug 2013 09:59:23 -0500 Message-ID: <521E104B.4060607@amd.com> References: <1831656044.20130722225004@eikelenboom.it> <51FF74E502000078000E9267@nat28.tlf.novell.com> <52011A78.2040701@amd.com> <757500547.20130815164341@eikelenboom.it> <520D0CBF02000078000EC4FF@nat28.tlf.novell.com> <1182640844.20130816012228@eikelenboom.it> <33876223.20130816014116@eikelenboom.it> <520DEEFD02000078000EC76F@nat28.tlf.novell.com> <208201973.20130816094246@eikelenboom.it> <520DF8F302000078000EC7AD@nat28.tlf.novell.com> <1157392160.20130816104005@eikelenboom.it> <520E0AA002000078000EC82B@nat28.tlf.novell.com> <451541998.20130816124429@eikelenboom.it> <520E422602000078000EC94D@nat28.tlf.novell.com> <1834274604.20130823005128@eikelenboom.it> <521C78A602000078000EEA44@nat28.tlf.novell.com> <521C79F502000078000EEA56@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030102020105020003050508" Return-path: In-Reply-To: <521C79F502000078000EEA56@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: Sander Eikelenboom , Andrew Cooper , Keir Fraser , xen-devel List-Id: xen-devel@lists.xenproject.org --------------030102020105020003050508 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Jan, The current patch does not handle the case where the "handle" value is mis-configured in the IVRS. I have also included the patch which has additional check. Below is the output from the patch. (XEN) AMD-Vi: IVHD Device Entry: type 0x48 id 0 flags 0xd7 (XEN) AMD-Vi: IVHD Special: 0000:00:14.0 variety 0x1 handle 0xff used_id 0xa0 (XEN) AMD-Vi: IVHD Special: Usinging command override value for IO-APIC 0x8, bdf=0xa0 (XEN) AMD-Vi: IVHD Device Entry: type 0x48 id 0 flags 0xd7 (XEN) AMD-Vi: IVHD Special: 0000:00:14.0 variety 0x2 handle 0 used_id 0xa0 (XEN) AMD-Vi: IVHD Device Entry: type 0x48 id 0 flags 0 (XEN) AMD-Vi: IVHD Special: 0000:00:00.1 variety 0x1 handle 0xff used_id 0x1 (XEN) AMD-Vi: IVHD Special: Usinging command override value for IO-APIC 0x8, bdf=0xa0 (XEN) AMD-Vi: IOMMU 0 Enabled. (XEN) I/O virtualisation enabled Suravee ------- PATCH SNIPPET------- From 86bf8c318a43e409d404377f4534fe586785a5c4 Mon Sep 17 00:00:00 2001 From: Suravee Suthikulpanit Date: Wed, 28 Aug 2013 09:49:32 -0500 Subject: [PATCH] Add additional check invalid special->handle This patch add an additional logic to check for the case when the speciail->handle is invalid due to firmware bugs, and use the overide value instead. Signed-off: Suravee Suthikulpanit --- xen/drivers/passthrough/amd/iommu_acpi.c | 53 ++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_acpi.c b/xen/drivers/passthrough/amd/iommu_acpi.c index 89b359c..8fb4c3f 100644 --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -698,14 +698,16 @@ static u16 __init parse_ivhd_device_special( return 0; } - AMD_IOMMU_DEBUG("IVHD Special: %04x:%02x:%02x.%u variety %#x handle %#x\n", + AMD_IOMMU_DEBUG("IVHD Special: %04x:%02x:%02x.%u variety %#x handle %#x used_id %#x\n", seg, PCI_BUS(bdf), PCI_SLOT(bdf), PCI_FUNC(bdf), - special->variety, special->handle); + special->variety, special->handle, special->used_id); add_ivrs_mapping_entry(bdf, bdf, special->header.data_setting, iommu); switch ( special->variety ) { case ACPI_IVHD_IOAPIC: + { + unsigned int apic_id = 0; if ( !iommu_intremap ) break; /* @@ -715,29 +717,43 @@ static u16 __init parse_ivhd_device_special( */ for ( apic = 0; apic < nr_ioapics; apic++ ) { - if ( IO_APIC_ID(apic) != special->handle ) - continue; + apic_id = special->handle; - if ( special->handle >= ARRAY_SIZE(ioapic_sbdf) ) + if ( IO_APIC_ID(apic) != apic_id ) + { + /* Some BIOSes have invalid value in the special->handle. + * Here we check to see if the user is overiding them from commandline + */ + if ( test_bit(IO_APIC_ID(apic), ioapic_cmdline) ) + { + apic_id = IO_APIC_ID(apic); + AMD_IOMMU_DEBUG ("IVHD Special: Usinging command override " + "value for IO-APIC %#x, bdf=%#x\n", + apic_id, ioapic_sbdf[apic_id].bdf); + } + else + continue; + } + + if ( apic_id >= ARRAY_SIZE(ioapic_sbdf) ) { printk(XENLOG_ERR "IVHD Error: IO-APIC %#x entry beyond bounds\n", - special->handle); + apic_id); return 0; } - if ( test_bit(special->handle, ioapic_cmdline) ) - AMD_IOMMU_DEBUG("IVHD: Command line override present for IO-APIC %#x\n", - special->handle); - else if ( ioapic_sbdf[special->handle].pin_2_idx ) + if ( test_bit(apic_id, ioapic_cmdline) ) + break; + else if ( ioapic_sbdf[apic_id].pin_2_idx ) { - if ( ioapic_sbdf[special->handle].bdf == bdf && - ioapic_sbdf[special->handle].seg == seg ) + if ( ioapic_sbdf[apic_id].bdf == bdf && + ioapic_sbdf[apic_id].seg == seg ) AMD_IOMMU_DEBUG("IVHD Warning: Duplicate IO-APIC %#x entries\n", - special->handle); + apic_id); else { printk(XENLOG_ERR "IVHD Error: Conflicting IO-APIC %#x entries\n", - special->handle); + apic_id); if ( amd_iommu_perdev_intremap ) return 0; } @@ -745,10 +761,10 @@ static u16 __init parse_ivhd_device_special( else { /* set device id of ioapic */ - ioapic_sbdf[special->handle].bdf = bdf; - ioapic_sbdf[special->handle].seg = seg; + ioapic_sbdf[apic_id].bdf = bdf; + ioapic_sbdf[apic_id].seg = seg; - ioapic_sbdf[special->handle].pin_2_idx = xmalloc_array( + ioapic_sbdf[apic_id].pin_2_idx = xmalloc_array( u16, nr_ioapic_entries[apic]); if ( nr_ioapic_entries[apic] && !ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx ) @@ -765,10 +781,11 @@ static u16 __init parse_ivhd_device_special( if ( apic == nr_ioapics ) { printk(XENLOG_ERR "IVHD Error: Invalid IO-APIC %#x\n", - special->handle); + apic_id); return 0; } break; + } case ACPI_IVHD_HPET: /* set device id of hpet */ if ( hpet_sbdf.iommu || -- 1.7.10.4 --------------030102020105020003050508 Content-Type: text/plain; charset="windows-1252"; name="0001-Add-additional-check-for-when-the-handle-is-mis-conf.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Add-additional-check-for-when-the-handle-is-mis-conf.pa"; filename*1="tch" >>From 86bf8c318a43e409d404377f4534fe586785a5c4 Mon Sep 17 00:00:00 2001 From: Suravee Suthikulpanit Date: Wed, 28 Aug 2013 09:49:32 -0500 Subject: [PATCH] Add additional check invalid special->handle This patch add an additional logic to check for the case when the speciail->handle is invalid due to firmware bugs, and use the overide value instead. Signed-off: Suravee Suthikulpanit --- xen/drivers/passthrough/amd/iommu_acpi.c | 53 ++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_acpi.c b/xen/drivers/passthrough/amd/iommu_acpi.c index 89b359c..8fb4c3f 100644 --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -698,14 +698,16 @@ static u16 __init parse_ivhd_device_special( return 0; } - AMD_IOMMU_DEBUG("IVHD Special: %04x:%02x:%02x.%u variety %#x handle %#x\n", + AMD_IOMMU_DEBUG("IVHD Special: %04x:%02x:%02x.%u variety %#x handle %#x used_id %#x\n", seg, PCI_BUS(bdf), PCI_SLOT(bdf), PCI_FUNC(bdf), - special->variety, special->handle); + special->variety, special->handle, special->used_id); add_ivrs_mapping_entry(bdf, bdf, special->header.data_setting, iommu); switch ( special->variety ) { case ACPI_IVHD_IOAPIC: + { + unsigned int apic_id = 0; if ( !iommu_intremap ) break; /* @@ -715,29 +717,43 @@ static u16 __init parse_ivhd_device_special( */ for ( apic = 0; apic < nr_ioapics; apic++ ) { - if ( IO_APIC_ID(apic) != special->handle ) - continue; + apic_id = special->handle; - if ( special->handle >= ARRAY_SIZE(ioapic_sbdf) ) + if ( IO_APIC_ID(apic) != apic_id ) + { + /* Some BIOSes have invalid value in the special->handle. + * Here we check to see if the user is overiding them from commandline + */ + if ( test_bit(IO_APIC_ID(apic), ioapic_cmdline) ) + { + apic_id = IO_APIC_ID(apic); + AMD_IOMMU_DEBUG ("IVHD Special: Usinging command override " + "value for IO-APIC %#x, bdf=%#x\n", + apic_id, ioapic_sbdf[apic_id].bdf); + } + else + continue; + } + + if ( apic_id >= ARRAY_SIZE(ioapic_sbdf) ) { printk(XENLOG_ERR "IVHD Error: IO-APIC %#x entry beyond bounds\n", - special->handle); + apic_id); return 0; } - if ( test_bit(special->handle, ioapic_cmdline) ) - AMD_IOMMU_DEBUG("IVHD: Command line override present for IO-APIC %#x\n", - special->handle); - else if ( ioapic_sbdf[special->handle].pin_2_idx ) + if ( test_bit(apic_id, ioapic_cmdline) ) + break; + else if ( ioapic_sbdf[apic_id].pin_2_idx ) { - if ( ioapic_sbdf[special->handle].bdf == bdf && - ioapic_sbdf[special->handle].seg == seg ) + if ( ioapic_sbdf[apic_id].bdf == bdf && + ioapic_sbdf[apic_id].seg == seg ) AMD_IOMMU_DEBUG("IVHD Warning: Duplicate IO-APIC %#x entries\n", - special->handle); + apic_id); else { printk(XENLOG_ERR "IVHD Error: Conflicting IO-APIC %#x entries\n", - special->handle); + apic_id); if ( amd_iommu_perdev_intremap ) return 0; } @@ -745,10 +761,10 @@ static u16 __init parse_ivhd_device_special( else { /* set device id of ioapic */ - ioapic_sbdf[special->handle].bdf = bdf; - ioapic_sbdf[special->handle].seg = seg; + ioapic_sbdf[apic_id].bdf = bdf; + ioapic_sbdf[apic_id].seg = seg; - ioapic_sbdf[special->handle].pin_2_idx = xmalloc_array( + ioapic_sbdf[apic_id].pin_2_idx = xmalloc_array( u16, nr_ioapic_entries[apic]); if ( nr_ioapic_entries[apic] && !ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx ) @@ -765,10 +781,11 @@ static u16 __init parse_ivhd_device_special( if ( apic == nr_ioapics ) { printk(XENLOG_ERR "IVHD Error: Invalid IO-APIC %#x\n", - special->handle); + apic_id); return 0; } break; + } case ACPI_IVHD_HPET: /* set device id of hpet */ if ( hpet_sbdf.iommu || -- 1.7.10.4 --------------030102020105020003050508 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --------------030102020105020003050508--