hw/i386: amd-iommu: add FCH stub at 00:14.0
PATCH 2/4 hw/i386: amd-iommu: add FCH stub at 00:14.0
In reply to Ankit SoniQEMU IVRS type 0x48 names 00:14.0 as the southbridge IOAPIC SID. q35 puts the ICH9 southbridge at 00:1f.x, and the PCI class at 00:14.0 is empty.
The Linux driver takes the SID from IVRS and reads PCI class at that address [1]. SMBus or ISA bridge there means a valid FCH. Any other class, including an empty slot (0xffff), fails. QEMU leaves that SID empty, so the guest fails the check and interrupt remapping stays off. Linux does that because a wrong SID with remapping left on panics the timer at boot [2].
When amd-iommu is realized, create an SMBus-class PCI stub at 00:14.0 with no BARs. Use vendor/device 1022:790b, the FCH SMBus at 00:14.0 on AMD hardware. Do that before AMDVI-PCI auto-assign. If 00:14.0 is already occupied, realize fails.
Leave ICH9 at 00:1f.x. q35 still needs it for ISA, ACPI, and GSI. Replacing it with an FCH would be a new machine type.
[1] https://git.kernel.org/linus/16f52863b2ec
("iommu/amd: Dynamically verify Southbridge IOAPIC via PCI config space")
[2] https://git.kernel.org/linus/c2ff5cf5294b
("iommu/amd: Work around wrong IOAPIC device-id in IVRS table")
--- hw/i386/amd_iommu.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 2 ++ 2 files changed, 54 insertions(+)
hw/i386/amd_iommu.c +52 -0
@@ -2725,6 +2725,22 @@ out:return bus; } +/* +* IVRS names 00:14.0 as the southbridge IOAPIC SID. That is an FCH +* function on AMD. q35 still has ICH9 LPC/SMBus at 00:1f.x for ISA +* and ACPI. +* +* Guest software treats this SID as the southbridge IOAPIC only when +* PCI class is SMBus or ISA bridge. Put an SMBus-class stub here with +* AMD FCH SMBus ids and no BARs. +*/ +static bool amdvi_realize_fch_stub (PCIBus *bus,Error **errp) +{ +PCIDevice *stub =pci_new (PCI_DEVFN (0x14 ,0 ),TYPE_AMDVI_FCH_STUB ); + +return pci_realize_and_unref (stub, bus, errp); +} +static void amdvi_sysbus_realize (DeviceState *dev,Error **errp) {DeviceClass *dc = (DeviceClass *)object_get_class (OBJECT (dev));
@@ -2734,6 +2750,14 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp)X86MachineState *x86ms =X86_MACHINE (ms);PCIBus *iommu_bus; +/* +* Claim 00:14.0 before AMDVI-PCI is realized. That PCI function +* is auto-assigned; fixed DEVFN devices, then auto-assign. +*/ +if (!amdvi_realize_fch_stub (pcms->pcibus, errp)) { +return ; + } +if (s->pci_id) {PCIDevice *pdev =NULL ;int ret =pci_qdev_find_device (s->pci_id, &pdev);
@@ -2876,6 +2900,33 @@ static const TypeInfo amdvi_pci = { }, }; +static void amdvi_fch_stub_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + + k->vendor_id =PCI_VENDOR_ID_AMD ; + k->device_id =0x790b ;/* FCH SMBus at 00:14.0 */ + k->class_id =PCI_CLASS_SERIAL_SMBUS ; + k->revision =0 ; + +set_bit (DEVICE_CATEGORY_MISC , dc->categories); + dc->desc ="AMD FCH identity stub at 00:14.0" ; + dc->user_creatable = false; + dc->vmsd = &vmstate_pci_device; +} + +static const TypeInfo amdvi_fch_stub = { + .name =TYPE_AMDVI_FCH_STUB , + .parent =TYPE_PCI_DEVICE , + .instance_size =sizeof (PCIDevice), + .class_init = amdvi_fch_stub_class_init, + .interfaces = (const InterfaceInfo []) { + {INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, +}; +static void amdvi_iommu_memory_region_class_init (ObjectClass *klass,const void *data) {
@@ -2895,6 +2946,7 @@ static const TypeInfo amdvi_iommu_memory_region_info = {static void amdvi_register_types (void ) {type_register_static (&amdvi_pci); +type_register_static (&amdvi_fch_stub);type_register_static (&amdvi_sysbus);type_register_static (&amdvi_iommu_memory_region_info); }
hw/i386/amd_iommu.h +2 -0
@@ -312,6 +312,8 @@ OBJECT_DECLARE_SIMPLE_TYPE(AMDVIState, AMD_IOMMU_DEVICE)#define TYPE_AMD_IOMMU_PCI "AMDVI-PCI" OBJECT_DECLARE_SIMPLE_TYPE(AMDVIPCIState, AMD_IOMMU_PCI) +#define TYPE_AMDVI_FCH_STUB "amdvi-fch-stub" +#define TYPE_AMD_IOMMU_MEMORY_REGION "amd-iommu-iommu-memory-region"typedef struct AMDVIAddressSpace AMDVIAddressSpace ;
Signature · 1 line
2.43.0
PATCH 3/4 tests/qtest: amd-iommu: test FCH stub at 00:14.0
In reply to Ankit SoniCheck that q35 with amd-iommu has the FCH stub at 00:14.0: AMD vendor ID, device ID 0x790b, and SMBus class.
--- tests/qtest/amd-iommu-test.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
tests/qtest/amd-iommu-test.c +30 -0
@@ -4,6 +4,8 @@#include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/pci.h" +#include "libqos/pci-pc.h" #include "hw/i386/amd_iommu.h" #define CMDBUF_ADDR 0x200000
@@ -68,9 +70,37 @@ static void test_cmdbuf_head_wrap(void)qtest_quit (s); } +static void test_fch_stub (void ) +{ +QTestState *s; +QPCIBus *bus; +QPCIDevice *dev; + +if (!qtest_has_machine ("q35" )) { +g_test_skip ("q35 machine not available" ); +return ; + } + + s =qtest_init ("-M q35 -device amd-iommu" ); + bus =qpci_new_pc (s,NULL ); + dev =qpci_device_find (bus,QPCI_DEVFN (0x14 ,0 )); +g_assert_nonnull (dev); + + g_assert_cmphex(qpci_config_readw(dev, PCI_VENDOR_ID), ==, +PCI_VENDOR_ID_AMD ); + g_assert_cmphex(qpci_config_readw(dev, PCI_DEVICE_ID), ==, 0x790b); + g_assert_cmphex(qpci_config_readw(dev, PCI_CLASS_DEVICE), ==, +PCI_CLASS_SERIAL_SMBUS ); + +g_free (dev); +qpci_free_pc (bus); +qtest_quit (s); +} +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );qtest_add_func ("/q35/amd-iommu/cmdbuf-head-wrap" , test_cmdbuf_head_wrap); +qtest_add_func ("/q35/amd-iommu/fch-stub" , test_fch_stub);return g_test_run (); }
Signature · 1 line
2.43.0
cover hw/i386: amd-iommu: add FCH stub at 00:14.0
Linux AMD IOMMU interrupt remapping needs an FCH at the IVRS southbridge IOAPIC SID. q35 leaves 00:14.0 empty, so the guest class check fails and remapping stays off.
This series puts an SMBus-class stub at 00:14.0 when amd-iommu is realized. ICH9 stays at 00:1f.x. Occupied 00:14.0 fails realize.
QEMU ACPI tests require the usual three-step blob update:
1. whitelist DSDT.ivrs and IVRS.ivrs
2. FCH stub, vmstate, add a qtest
3. new expected blobs, empty whitelist
The stub uses AMD FCH SMBus ids (1022:790b) so it looks like an FCH. Linux IOMMU only checks class. i2c-piix4 may still match the id and fail probe. That is dmesg noise, not a timer hang.
Ankit Soni (4):
tests/acpi: allow q35 IVRS DSDT/IVRS blob updates hw/i386: amd-iommu: add FCH stub at 00:14.0 tests/qtest: amd-iommu: test FCH stub at 00:14.0 tests/acpi: update q35 IVRS expected blobs
hw/i386/amd_iommu.c | 52 ++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 2 ++ tests/data/acpi/x86/q35/DSDT.ivrs | Bin 8445 -> 8462 bytes tests/data/acpi/x86/q35/IVRS.ivrs | Bin 176 -> 184 bytes tests/qtest/amd-iommu-test.c | 30 +++++++++++++++++ 5 files changed, 84 insertions(+)
Signature · 1 line
2.43.0
PATCH 4/4 tests/acpi: update q35 IVRS expected blobs
The FCH stub at 00:14.0 adds a PCI function, so the q35 IVRS test tables change.
DSDT gains Device (SA0) at _ADR 0x00140000. IVHD type 0x10 and 0x11 each gain a Select entry for Device ID 00A0 (00:14.0). Table length 0xB0 -> 0xB8. Later IVRS offsets move by four bytes; type 0x48 IOAPIC SID is still 00A0.
Differences between disassembled ASL files for DSDT.ivrs:
--- tests/data/acpi/x86/q35/DSDT.ivrs
+++ DSDT.ivrs
@@ -9,9 +9,9 @@
*
* Original Table Header:
* Signature "DSDT"
- * Length 0x000020FD (8445)
+ * Length 0x0000210E (8462)
* Revision 0x01 **** 32-bit table (V1), no 64-bit math support
- * Checksum 0x45
+ * Checksum 0xD1
* OEM ID "BOCHS "
* OEM Table ID "BXPC "
* OEM Revision 0x00000001 (1)
@@ -3210,6 +3210,11 @@
Name (_ADR, 0x00020000) // _ADR: Address
} + Device (SA0)
+ {
+ Name (_ADR, 0x00140000) // _ADR: Address
+ }
+
Device (SF8)
{
Name (_ADR, 0x001F0000) // _ADR: AddressDifferences between disassembled ASL files for IVRS:
--- tests/data/acpi/x86/q35/IVRS.ivrs
+++ IVRS.ivrs
@@ -11,9 +11,9 @@
*/
[000h 0000 004h] Signature : "IVRS" [I/O Virtualization Reporting Structure]
-[004h 0004 004h] Table Length : 000000B0
+[004h 0004 004h] Table Length : 000000B8
[008h 0008 001h] Revision : 01 -[009h 0009 001h] Checksum : CB +[009h 0009 001h] Checksum : 77
[00Ah 0010 006h] Oem ID : "BOCHS "
[010h 0016 008h] Oem Table ID : "BXPC "
[018h 0024 004h] Oem Revision : 00000001
@@ -33,7 +33,7 @@
Coherent : 0
Prefetch Support : 1
PPR Support : 0
-[032h 0050 002h] Length : 0038
+[032h 0050 002h] Length : 003C
[034h 0052 002h] DeviceId : 0010
[036h 0054 002h] Capability Offset : 0040
[038h 0056 008h] Base Address : 00000000FED80000
@@ -75,7 +75,7 @@
LINT1 Pass : 0
[054h 0084 001h] Subtable Type : 02 [Device Entry: Select One Device]
-[055h 0085 002h] Device ID : 00F8
+[055h 0085 002h] Device ID : 00A0
[057h 0087 001h] Data Setting (decoded below) : 00
INITPass : 0 EIntPass : 0
@@ -86,7 +86,7 @@
LINT1 Pass : 0
[058h 0088 001h] Subtable Type : 02 [Device Entry: Select One Device]
-[059h 0089 002h] Device ID : 00FA
+[059h 0089 002h] Device ID : 00F8
[05Bh 0091 001h] Data Setting (decoded below) : 00
INITPass : 0 EIntPass : 0
@@ -97,7 +97,7 @@
LINT1 Pass : 0
[05Ch 0092 001h] Subtable Type : 02 [Device Entry: Select One Device]
-[05Dh 0093 002h] Device ID : 00FB
+[05Dh 0093 002h] Device ID : 00FA
[05Fh 0095 001h] Data Setting (decoded below) : 00
INITPass : 0 EIntPass : 0
@@ -107,8 +107,8 @@
LINT0 Pass : 0 LINT1 Pass : 0
-[060h 0096 001h] Subtable Type : 48 [Device Entry: Special Device]
-[061h 0097 002h] Device ID : 0000
+[060h 0096 001h] Subtable Type : 02 [Device Entry: Select One Device]
+[061h 0097 002h] Device ID : 00FB
[063h 0099 001h] Data Setting (decoded below) : 00
INITPass : 0 EIntPass : 0
@@ -117,12 +117,23 @@
System MGMT : 0
LINT0 Pass : 0 LINT1 Pass : 0
-[064h 0100 001h] Handle : 00
-[065h 0101 002h] Source Used Device ID : 00A0
-[067h 0103 001h] Variety : 01
-[068h 0104 001h] Subtable Type : 11 [Hardware Definition Block (IVHD)]
-[069h 0105 001h] Flags (decoded below) : 11
+[064h 0100 001h] Subtable Type : 48 [Device Entry: Special Device]
+[065h 0101 002h] Device ID : 0000
+[067h 0103 001h] Data Setting (decoded below) : 00
+ INITPass : 0
+ EIntPass : 0
+ NMIPass : 0
+ Reserved : 0
+ System MGMT : 0
+ LINT0 Pass : 0
+ LINT1 Pass : 0
+[068h 0104 001h] Handle : 00
+[069h 0105 002h] Source Used Device ID : 00A0
+[06Bh 0107 001h] Variety : 01
+
+[06Ch 0108 001h] Subtable Type : 11 [Hardware Definition Block (IVHD)]
+[06Dh 0109 001h] Flags (decoded below) : 11
HtTunEn : 1
PassPW : 0
ResPassPW : 0
@@ -131,29 +142,18 @@
Coherent : 0
Prefetch Support : 0
PPR Support : 0
-[06Ah 0106 002h] Length : 0048
-[06Ch 0108 002h] DeviceId : 0010
-[06Eh 0110 002h] Capability Offset : 0040
-[070h 0112 008h] Base Address : 00000000FED80000
-[078h 0120 002h] PCI Segment Group : 0000
-[07Ah 0122 002h] Virtualization Info : 0000
-[07Ch 0124 004h] Attributes : 00000000
-[080h 0128 008h] EFR Image : 00000000000028D1
-[088h 0136 008h] Reserved : 0000000000000000
-
-[090h 0144 001h] Subtable Type : 02 [Device Entry: Select One Device]
-[091h 0145 002h] Device ID : 0000
-[093h 0147 001h] Data Setting (decoded below) : 00
- INITPass : 0
- EIntPass : 0
- NMIPass : 0
- Reserved : 0
- System MGMT : 0
- LINT0 Pass : 0
- LINT1 Pass : 0
+[06Eh 0110 002h] Length : 004C
+[070h 0112 002h] DeviceId : 0010
+[072h 0114 002h] Capability Offset : 0040
+[074h 0116 008h] Base Address : 00000000FED80000
+[07Ch 0124 002h] PCI Segment Group : 0000
+[07Eh 0126 002h] Virtualization Info : 0000
+[080h 0128 004h] Attributes : 00000000
+[084h 0132 008h] EFR Image : 00000000000028D1
+[08Ch 0140 008h] Reserved : 0000000000000000
[094h 0148 001h] Subtable Type : 02 [Device Entry: Select One Device]
-[095h 0149 002h] Device ID : 0008
+[095h 0149 002h] Device ID : 0000
[097h 0151 001h] Data Setting (decoded below) : 00
INITPass : 0 EIntPass : 0
@@ -164,7 +164,7 @@
LINT1 Pass : 0
[098h 0152 001h] Subtable Type : 02 [Device Entry: Select One Device]
-[099h 0153 002h] Device ID : 0010
+[099h 0153 002h] Device ID : 0008
[09Bh 0155 001h] Data Setting (decoded below) : 00
INITPass : 0 EIntPass : 0
@@ -175,7 +175,7 @@
LINT1 Pass : 0
[09Ch 0156 001h] Subtable Type : 02 [Device Entry: Select One Device]
-[09Dh 0157 002h] Device ID : 00F8
+[09Dh 0157 002h] Device ID : 0010
[09Fh 0159 001h] Data Setting (decoded below) : 00
INITPass : 0 EIntPass : 0
@@ -186,7 +186,7 @@
LINT1 Pass : 0
[0A0h 0160 001h] Subtable Type : 02 [Device Entry: Select One Device]
-[0A1h 0161 002h] Device ID : 00FA
+[0A1h 0161 002h] Device ID : 00A0
[0A3h 0163 001h] Data Setting (decoded below) : 00
INITPass : 0 EIntPass : 0
@@ -197,7 +197,7 @@
LINT1 Pass : 0
[0A4h 0164 001h] Subtable Type : 02 [Device Entry: Select One Device]
-[0A5h 0165 002h] Device ID : 00FB
+[0A5h 0165 002h] Device ID : 00F8
[0A7h 0167 001h] Data Setting (decoded below) : 00
INITPass : 0 EIntPass : 0
@@ -207,8 +207,8 @@
LINT0 Pass : 0 LINT1 Pass : 0
-[0A8h 0168 001h] Subtable Type : 48 [Device Entry: Special Device]
-[0A9h 0169 002h] Device ID : 0000
+[0A8h 0168 001h] Subtable Type : 02 [Device Entry: Select One Device]
+[0A9h 0169 002h] Device ID : 00FA
[0ABh 0171 001h] Data Setting (decoded below) : 00
INITPass : 0 EIntPass : 0
@@ -217,6 +217,28 @@
System MGMT : 0
LINT0 Pass : 0 LINT1 Pass : 0
-[0ACh 0172 001h] Handle : 00
-[0ADh 0173 002h] Source Used Device ID : 00A0
-[0AFh 0175 001h] Variety : 01
+
+[0ACh 0172 001h] Subtable Type : 02 [Device Entry: Select One Device]
+[0ADh 0173 002h] Device ID : 00FB
+[0AFh 0175 001h] Data Setting (decoded below) : 00
+ INITPass : 0
+ EIntPass : 0
+ NMIPass : 0
+ Reserved : 0
+ System MGMT : 0
+ LINT0 Pass : 0
+ LINT1 Pass : 0
+
+[0B0h 0176 001h] Subtable Type : 48 [Device Entry: Special Device]
+[0B1h 0177 002h] Device ID : 0000
+[0B3h 0179 001h] Data Setting (decoded below) : 00
+ INITPass : 0
+ EIntPass : 0
+ NMIPass : 0
+ Reserved : 0
+ System MGMT : 0
+ LINT0 Pass : 0
+ LINT1 Pass : 0
+[0B4h 0180 001h] Handle : 00
+[0B5h 0181 002h] Source Used Device ID : 00A0
+[0B7h 0183 001h] Variety : 01
--- tests/data/acpi/x86/q35/DSDT.ivrs | Bin 8445 -> 8462 bytes tests/data/acpi/x86/q35/IVRS.ivrs | Bin 176 -> 184 bytes tests/qtest/bios-tables-test-allowed-diff.h | 2 -- 3 files changed, 2 deletions(-)
tests/data/acpi/x86/q35/DSDT.ivrs binary +0 -0
tests/data/acpi/x86/q35/IVRS.ivrs binary +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +0 -2
@@ -1,3 +1 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/x86/q35/DSDT.ivrs" , -"tests/data/acpi/x86/q35/IVRS.ivrs",
Signature · 1 line
2.43.0
PATCH 1/4 tests/acpi: allow q35 IVRS DSDT/IVRS blob updates
In reply to Ankit SoniThe next patch adds an FCH PCI stub at 00:14.0. That changes the q35 IVRS test tables.
--- tests/qtest/bios-tables-test-allowed-diff.h | 2 ++ 1 file changed, 2 insertions(+)
tests/qtest/bios-tables-test-allowed-diff.h +2 -0
@@ -1 +1,3 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/x86/q35/DSDT.ivrs" , +"tests/data/acpi/x86/q35/IVRS.ivrs",
Signature · 1 line
2.43.0