Skip to contentSkip to conversation

ACPI related fixes

PATCH Superseded [email protected] 4 participants 25 messages Feb 8, 2021 – Feb 10, 2021 Checkpatch

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover ACPI related fixes

From: Isaku Yamahata <[email protected]>

Miscellaneous bug fixes related to ACPI to play nice with guest BIOSes/OSes by conforming to ACPI spec better.

Changes from v1:
- fixed style issue with fixes to checkpatch.pl
- fixed make check breakage
- added ACPI table tests
- update comment message to include acpi table diff

Isaku Yamahata (8):
checkpatch: don't emit warning on newly created acpi data files
qtest: update tests/qtest/bios-tables-test-allowed-diff.h acpi/core: always set SCI_EN when SMM isn't supported
acpi: set fadt.smi_cmd to zero when SMM is not supported
acpi: add test case for smm unsupported -machine smm=off hw/i386: declare ACPI mother board resource for MMCONFIG region
acpi: add test case for -no-hpet qtest/acpi/bios-tables-test: update acpi tables

Sean Christopherson (1):
i386: acpi: Don't build HPET ACPI entry if HPET is disabled

 hw/acpi/core.c                    |  11 +-
 hw/acpi/ich9.c                    |   2 +-
 hw/acpi/piix4.c                   |   3 +-
 hw/i386/acpi-build.c              | 192 +++++++++++++++++++++++++++++-
 hw/isa/vt82c686.c                 |   2 +-
 include/hw/acpi/acpi.h            |   4 +-
 scripts/checkpatch.pl             |   4 +-
 tests/data/acpi/q35/DSDT          | Bin 7801 -> 8083 bytes
 tests/data/acpi/q35/DSDT.acpihmat | Bin 9126 -> 9408 bytes
 tests/data/acpi/q35/DSDT.bridge   | Bin 7819 -> 8101 bytes
 tests/data/acpi/q35/DSDT.cphp     | Bin 8265 -> 8547 bytes
 tests/data/acpi/q35/DSDT.dimmpxm  | Bin 9455 -> 9737 bytes
 tests/data/acpi/q35/DSDT.ipmibt   | Bin 7876 -> 8158 bytes
 tests/data/acpi/q35/DSDT.memhp    | Bin 9160 -> 9442 bytes
 tests/data/acpi/q35/DSDT.mmio64   | Bin 8932 -> 9214 bytes
 tests/data/acpi/q35/DSDT.nohpet   | Bin 0 -> 7941 bytes
 tests/data/acpi/q35/DSDT.nosmm    | Bin 0 -> 8083 bytes
 tests/data/acpi/q35/DSDT.numamem  | Bin 7807 -> 8089 bytes
 tests/data/acpi/q35/DSDT.tis      | Bin 8407 -> 8689 bytes
 tests/data/acpi/q35/FACP.nosmm    | Bin 0 -> 244 bytes
 tests/qtest/bios-tables-test.c    |  24 ++++
 21 files changed, 231 insertions(+), 11 deletions(-)
 create mode 100644 tests/data/acpi/q35/DSDT.nohpet
 create mode 100644 tests/data/acpi/q35/DSDT.nosmm
 create mode 100644 tests/data/acpi/q35/FACP.nosmm
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/9 checkpatch: don't emit warning on newly created acpi data files

From: Isaku Yamahata <[email protected]>

Newly created acpi data files(tests/data/acpi/) cause false positive warning.
If file names are acpi expected file, don't emit warning.

Fixes e625ba2a41 ("checkpatch: fix acpi check with multiple file name")
---
 scripts/checkpatch.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +3 -1
index e47ad878d8..40c9cc7def 100755
@@ -1530,7 +1530,9 @@ sub process {
 		    ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||
 		     $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
 		     ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
-		      (defined($1) || defined($2))))) {
+		      (defined($1) || defined($2)))) &&
+                      !(($realfile ne '') &&
+                        ($realfile eq $acpi_testexpected))) {
 			$reported_maintainer_file = 1;
 			WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
 		}
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/9 qtest: update tests/qtest/bios-tables-test-allowed-diff.h

In reply to [email protected]

From: Isaku Yamahata <[email protected]>

The following tests will modify acpi tables.
prepare qtests to allow acpi table change.
add new tables for new tests.
- tests/data/acpi/q35/DSDT.nosmm
- tests/data/acpi/q35/FACP.nosmm
- tests/data/acpi/q35/DSDT.nohpet

---
 tests/data/acpi/q35/DSDT.nohpet             |  0
 tests/data/acpi/q35/DSDT.nosmm              |  0
 tests/data/acpi/q35/FACP.nosmm              |  0
 tests/qtest/bios-tables-test-allowed-diff.h | 13 +++++++++++++
 4 files changed, 13 insertions(+)
 create mode 100644 tests/data/acpi/q35/DSDT.nohpet
 create mode 100644 tests/data/acpi/q35/DSDT.nosmm
 create mode 100644 tests/data/acpi/q35/FACP.nosmm
tests/data/acpi/q35/DSDT.nohpet new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
tests/data/acpi/q35/DSDT.nosmm new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
tests/data/acpi/q35/FACP.nosmm new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
tests/qtest/bios-tables-test-allowed-diff.h +13 -0
index dfb8523c8b..b79ac495c2 100644
@@ -1 +1,14 @@
 /* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/q35/DSDT",
+"tests/data/acpi/q35/DSDT.tis",
+"tests/data/acpi/q35/DSDT.bridge",
+"tests/data/acpi/q35/DSDT.ipmibt",
+"tests/data/acpi/q35/DSDT.cphp",
+"tests/data/acpi/q35/DSDT.memhp",
+"tests/data/acpi/q35/DSDT.numamem",
+"tests/data/acpi/q35/DSDT.dimmpxm",
+"tests/data/acpi/q35/DSDT.acpihmat",
+"tests/data/acpi/q35/DSDT.mmio64",
+"tests/data/acpi/q35/DSDT.nosmm",
+"tests/data/acpi/q35/FACP.nosmm",
+"tests/data/acpi/q35/DSDT.nohpet",
Signature · 1 line
2.17.1
Acked-by on v2 2/9
#3 lore raw

Re: [PATCH v2 2/9] qtest: update tests/qtest/bios-tables-test-allowed-diff.h

Quoted 10 lines · On Mon, 8 Feb 2021 13:57:21 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

The following tests will modify acpi tables.
prepare qtests to allow acpi table change.
add new tables for new tests.
- tests/data/acpi/q35/DSDT.nosmm
- tests/data/acpi/q35/FACP.nosmm
- tests/data/acpi/q35/DSDT.nohpet

Quoted 38 lines
---
 tests/data/acpi/q35/DSDT.nohpet             |  0
 tests/data/acpi/q35/DSDT.nosmm              |  0
 tests/data/acpi/q35/FACP.nosmm              |  0
 tests/qtest/bios-tables-test-allowed-diff.h | 13 +++++++++++++
 4 files changed, 13 insertions(+)
 create mode 100644 tests/data/acpi/q35/DSDT.nohpet
 create mode 100644 tests/data/acpi/q35/DSDT.nosmm
 create mode 100644 tests/data/acpi/q35/FACP.nosmm
tests/data/acpi/q35/DSDT.nohpet new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
tests/data/acpi/q35/DSDT.nosmm new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
tests/data/acpi/q35/FACP.nosmm new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
tests/qtest/bios-tables-test-allowed-diff.h +13 -0
index dfb8523c8b..b79ac495c2 100644
@@ -1 +1,14 @@
 /* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/q35/DSDT",
+"tests/data/acpi/q35/DSDT.tis",
+"tests/data/acpi/q35/DSDT.bridge",
+"tests/data/acpi/q35/DSDT.ipmibt",
+"tests/data/acpi/q35/DSDT.cphp",
+"tests/data/acpi/q35/DSDT.memhp",
+"tests/data/acpi/q35/DSDT.numamem",
+"tests/data/acpi/q35/DSDT.dimmpxm",
+"tests/data/acpi/q35/DSDT.acpihmat",
+"tests/data/acpi/q35/DSDT.mmio64",
+"tests/data/acpi/q35/DSDT.nosmm",
+"tests/data/acpi/q35/FACP.nosmm",
+"tests/data/acpi/q35/DSDT.nohpet",
#4 lore raw

PATCH v2 3/9 acpi/core: always set SCI_EN when SMM isn't supported

In reply to [email protected]

From: Isaku Yamahata <[email protected]>

If SMM is not supported, ACPI fixed hardware doesn't support legacy-mode. ACPI-only platform. Where SCI_EN in PM1_CNT register is always set.
The bit tells OS legacy mode(SCI_EN cleared) or ACPI mode(SCI_EN set).

ACPI spec 4.8.10.1 PM1 Event Grouping
PM1 Eanble Registers

Quoted 1 line

For ACPI-only platforms (where SCI_EN is always set)

---
 hw/acpi/core.c         | 11 ++++++++++-
 hw/acpi/ich9.c         |  2 +-
 hw/acpi/piix4.c        |  3 ++-
 hw/isa/vt82c686.c      |  2 +-
 include/hw/acpi/acpi.h |  4 +++-
 5 files changed, 17 insertions(+), 5 deletions(-)
hw/acpi/core.c +10 -1
index 7170bff657..1e004d0078 100644
@@ -579,6 +579,10 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
                          bool sci_enable, bool sci_disable)
 {
     /* ACPI specs 3.0, 4.7.2.5 */
+    if (ar->pm1.cnt.acpi_only) {
+        return;
+    }
+
     if (sci_enable) {
         ar->pm1.cnt.cnt |= ACPI_BITMASK_SCI_ENABLE;
     } else if (sci_disable) {
@@ -608,11 +612,13 @@ static const MemoryRegionOps acpi_pm_cnt_ops = {
 };
 
 void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent,
-                       bool disable_s3, bool disable_s4, uint8_t s4_val)
+                       bool disable_s3, bool disable_s4, uint8_t s4_val,
+                       bool acpi_only)
 {
     FWCfgState *fw_cfg;
 
     ar->pm1.cnt.s4_val = s4_val;
+    ar->pm1.cnt.acpi_only = acpi_only;
     ar->wakeup.notify = acpi_notify_wakeup;
     qemu_register_wakeup_notifier(&ar->wakeup);
 
@@ -638,6 +644,9 @@ void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent,
 void acpi_pm1_cnt_reset(ACPIREGS *ar)
 {
     ar->pm1.cnt.cnt = 0;
+    if (ar->pm1.cnt.acpi_only) {
+        ar->pm1.cnt.cnt |= ACPI_BITMASK_SCI_ENABLE;
+    }
 }
 
 /* ACPI GPE */
hw/acpi/ich9.c +1 -1
index 5ff4e01c36..1a34d7f621 100644
@@ -282,7 +282,7 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
     acpi_pm_tmr_init(&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);
     acpi_pm1_evt_init(&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);
     acpi_pm1_cnt_init(&pm->acpi_regs, &pm->io, pm->disable_s3, pm->disable_s4,
-                      pm->s4_val);
+                      pm->s4_val, !smm_enabled);
 
     acpi_gpe_init(&pm->acpi_regs, ICH9_PMIO_GPE0_LEN);
     memory_region_init_io(&pm->io_gpe, OBJECT(lpc_pci), &ich9_gpe_ops, pm,
hw/acpi/piix4.c +2 -1
index 669be5bbf6..0cddf91de5 100644
@@ -496,7 +496,8 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)
 
     acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io);
     acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io);
-    acpi_pm1_cnt_init(&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val);
+    acpi_pm1_cnt_init(&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val,
+                      !s->smm_enabled);
     acpi_gpe_init(&s->ar, GPE_LEN);
 
     s->powerdown_notifier.notify = piix4_pm_powerdown_req;
hw/isa/vt82c686.c +1 -1
index a6f5a0843d..071b64b497 100644
@@ -240,7 +240,7 @@ static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp)
 
     acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io);
     acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io);
-    acpi_pm1_cnt_init(&s->ar, &s->io, false, false, 2);
+    acpi_pm1_cnt_init(&s->ar, &s->io, false, false, 2, false);
 }
 
 static Property via_pm_properties[] = {
include/hw/acpi/acpi.h +3 -1
index 22b0b65bb2..9e8a76f2e2 100644
@@ -128,6 +128,7 @@ struct ACPIPM1CNT {
     MemoryRegion io;
     uint16_t cnt;
     uint8_t s4_val;
+    bool acpi_only;
 };
 
 struct ACPIGPE {
@@ -163,7 +164,8 @@ void acpi_pm1_evt_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,
 
 /* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
 void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent,
-                       bool disable_s3, bool disable_s4, uint8_t s4_val);
+                       bool disable_s3, bool disable_s4, uint8_t s4_val,
+                       bool acpi_only);
 void acpi_pm1_cnt_update(ACPIREGS *ar,
                          bool sci_enable, bool sci_disable);
 void acpi_pm1_cnt_reset(ACPIREGS *ar);
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH v2 3/9] acpi/core: always set SCI_EN when SMM isn't supported

Quoted 6 lines · On Mon, 8 Feb 2021 13:57:22 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

If SMM is not supported, ACPI fixed hardware doesn't support legacy-mode. ACPI-only platform. Where SCI_EN in PM1_CNT register is always set.
The bit tells OS legacy mode(SCI_EN cleared) or ACPI mode(SCI_EN set).

does it break some specific software?

Quoted 5 lines

ACPI spec 4.8.10.1 PM1 Event Grouping
PM1 Eanble Registers

Quoted 1 line

For ACPI-only platforms (where SCI_EN is always set)

it changes guest ABI for old machine types but it seems to me that it's harmless (in typical use-cases backward and forward migrated guest should work fine).

The only thing that is broken is transitioning to legacy mode when guest was started on old QEMU and then migrated to the new one where disable op will be NOP and qemu always stays in ACPI mode (so guest will hang while it waits for transition to happen).

Can you test this scenario with various guest OSes (old/new/MS Windows) to check if it won't break them.

if we are to be conservative, we need to disable this compliance fix on old machine types.

other than that patch looks good to me.

Quoted 110 lines
---
 hw/acpi/core.c         | 11 ++++++++++-
 hw/acpi/ich9.c         |  2 +-
 hw/acpi/piix4.c        |  3 ++-
 hw/isa/vt82c686.c      |  2 +-
 include/hw/acpi/acpi.h |  4 +++-
 5 files changed, 17 insertions(+), 5 deletions(-)
hw/acpi/core.c +10 -1
index 7170bff657..1e004d0078 100644
@@ -579,6 +579,10 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
                          bool sci_enable, bool sci_disable)
 {
     /* ACPI specs 3.0, 4.7.2.5 */
+    if (ar->pm1.cnt.acpi_only) {
+        return;
+    }
+
     if (sci_enable) {
         ar->pm1.cnt.cnt |= ACPI_BITMASK_SCI_ENABLE;
     } else if (sci_disable) {
@@ -608,11 +612,13 @@ static const MemoryRegionOps acpi_pm_cnt_ops = {
 };
 
 void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent,
-                       bool disable_s3, bool disable_s4, uint8_t s4_val)
+                       bool disable_s3, bool disable_s4, uint8_t s4_val,
+                       bool acpi_only)
 {
     FWCfgState *fw_cfg;
 
     ar->pm1.cnt.s4_val = s4_val;
+    ar->pm1.cnt.acpi_only = acpi_only;
     ar->wakeup.notify = acpi_notify_wakeup;
     qemu_register_wakeup_notifier(&ar->wakeup);
 
@@ -638,6 +644,9 @@ void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent,
 void acpi_pm1_cnt_reset(ACPIREGS *ar)
 {
     ar->pm1.cnt.cnt = 0;
+    if (ar->pm1.cnt.acpi_only) {
+        ar->pm1.cnt.cnt |= ACPI_BITMASK_SCI_ENABLE;
+    }
 }
 
 /* ACPI GPE */
hw/acpi/ich9.c +1 -1
index 5ff4e01c36..1a34d7f621 100644
@@ -282,7 +282,7 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
     acpi_pm_tmr_init(&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);
     acpi_pm1_evt_init(&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);
     acpi_pm1_cnt_init(&pm->acpi_regs, &pm->io, pm->disable_s3, pm->disable_s4,
-                      pm->s4_val);
+                      pm->s4_val, !smm_enabled);
 
     acpi_gpe_init(&pm->acpi_regs, ICH9_PMIO_GPE0_LEN);
     memory_region_init_io(&pm->io_gpe, OBJECT(lpc_pci), &ich9_gpe_ops, pm,
hw/acpi/piix4.c +2 -1
index 669be5bbf6..0cddf91de5 100644
@@ -496,7 +496,8 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)
 
     acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io);
     acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io);
-    acpi_pm1_cnt_init(&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val);
+    acpi_pm1_cnt_init(&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val,
+                      !s->smm_enabled);
     acpi_gpe_init(&s->ar, GPE_LEN);
 
     s->powerdown_notifier.notify = piix4_pm_powerdown_req;
hw/isa/vt82c686.c +1 -1
index a6f5a0843d..071b64b497 100644
@@ -240,7 +240,7 @@ static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp)
 
     acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io);
     acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io);
-    acpi_pm1_cnt_init(&s->ar, &s->io, false, false, 2);
+    acpi_pm1_cnt_init(&s->ar, &s->io, false, false, 2, false);
 }
 
 static Property via_pm_properties[] = {
include/hw/acpi/acpi.h +3 -1
index 22b0b65bb2..9e8a76f2e2 100644
@@ -128,6 +128,7 @@ struct ACPIPM1CNT {
     MemoryRegion io;
     uint16_t cnt;
     uint8_t s4_val;
+    bool acpi_only;
 };
 
 struct ACPIGPE {
@@ -163,7 +164,8 @@ void acpi_pm1_evt_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,
 
 /* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
 void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent,
-                       bool disable_s3, bool disable_s4, uint8_t s4_val);
+                       bool disable_s3, bool disable_s4, uint8_t s4_val,
+                       bool acpi_only);
 void acpi_pm1_cnt_update(ACPIREGS *ar,
                          bool sci_enable, bool sci_disable);
 void acpi_pm1_cnt_reset(ACPIREGS *ar);
#6 lore raw

Re: [PATCH v2 3/9] acpi/core: always set SCI_EN when SMM isn't supported

Quoted 11 lines · Igor Mammedov
Quoted 6 lines · On Mon, 8 Feb 2021 13:57:22 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

If SMM is not supported, ACPI fixed hardware doesn't support legacy-mode. ACPI-only platform. Where SCI_EN in PM1_CNT register is always set.
The bit tells OS legacy mode(SCI_EN cleared) or ACPI mode(SCI_EN set).

does it break some specific software?

With the next patch (setting fadt.smi_cmd = 0 when smm isn't supported), guest Linux tries to switch to ACPI mode, finds smi_cmd = 0, and then fails to initialize acpi subsystem.
will update the commit message in next respin.

Quoted 5 lines
Quoted 5 lines

ACPI spec 4.8.10.1 PM1 Event Grouping
PM1 Eanble Registers

Quoted 1 line

For ACPI-only platforms (where SCI_EN is always set)

Quoted 8 lines

it changes guest ABI for old machine types but it seems to me that it's harmless (in typical use-cases backward and forward migrated guest should work fine).

The only thing that is broken is transitioning to legacy mode when guest was started on old QEMU and then migrated to the new one where disable op will be NOP and qemu always stays in ACPI mode (so guest will hang while it waits for transition to happen).

The patch affects guests only when SMM isn't supported. Concretely
- user explicitly specified to disable smm by -machine smm=off or
- underlying kvm doesn't have KVM_CAP_X86_SMM (smm=auto: default) Please refer to x86_machine_is_smm_enabled().
Also Libvirt checks if guest bios requires SMI and enables smm even when user disabling SMM. qemuFirmwareEnableFeatures()

If smm is disabled and legacy-mode is enabled without this patch, SMI won't be injected to guest anyway. Thus guest breaks already.

Quoted 2 lines

Can you test this scenario with various guest OSes (old/new/MS Windows) to check if it won't break them.

Unless -machine smm=off is explicitly passed, this patch won't break guests. And such case is rare as I described above.
My motivation for this patch series is preparation for TDX which disallows SMM mode and SMI injection.

Quoted 2 lines

if we are to be conservative, we need to disable this compliance fix on old machine types.

I'm fine with adding one more knob to be on safe side. -machine smm=off is such knob, though.

Thanks,

Signature · 1 line
Isaku Yamahata <[email protected]>
#7 lore raw

Re: [PATCH v2 3/9] acpi/core: always set SCI_EN when SMM isn't supported

Quoted 45 lines · On Tue, 9 Feb 2021 11:23:05 -0800 Isaku Yamahata <[email protected]>…
Quoted 11 lines · Igor Mammedov
Quoted 6 lines · On Mon, 8 Feb 2021 13:57:22 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

If SMM is not supported, ACPI fixed hardware doesn't support legacy-mode. ACPI-only platform. Where SCI_EN in PM1_CNT register is always set.
The bit tells OS legacy mode(SCI_EN cleared) or ACPI mode(SCI_EN set).

does it break some specific software?

With the next patch (setting fadt.smi_cmd = 0 when smm isn't supported), guest Linux tries to switch to ACPI mode, finds smi_cmd = 0, and then fails to initialize acpi subsystem.
will update the commit message in next respin.

Quoted 5 lines
Quoted 5 lines

ACPI spec 4.8.10.1 PM1 Event Grouping
PM1 Eanble Registers

Quoted 1 line

For ACPI-only platforms (where SCI_EN is always set)

Quoted 8 lines

it changes guest ABI for old machine types but it seems to me that it's harmless (in typical use-cases backward and forward migrated guest should work fine).

The only thing that is broken is transitioning to legacy mode when guest was started on old QEMU and then migrated to the new one where disable op will be NOP and qemu always stays in ACPI mode (so guest will hang while it waits for transition to happen).

The patch affects guests only when SMM isn't supported. Concretely
- user explicitly specified to disable smm by -machine smm=off or
- underlying kvm doesn't have KVM_CAP_X86_SMM (smm=auto: default) Please refer to x86_machine_is_smm_enabled().
Also Libvirt checks if guest bios requires SMI and enables smm even when user disabling SMM. qemuFirmwareEnableFeatures()

Quoted 2 lines

If smm is disabled and legacy-mode is enabled without this patch, SMI won't be injected to guest anyway. Thus guest breaks already.

can you point to code in QEMU that prevents SMI being triggered? (what see is QEMU faking SMM being configured when smm_enable=false, and seabios skipping its smm code based on that, other guest code may behave differently though).

But that's beside point, guest started on old QEMU may believe that it runs on Legacy/ACPI platform even with (smm=off), and hence can try to enable/disable ACPI mode explicitly. Combined with migration to QEMU with this patches it might turn into problem (which is hard to troubleshoot in the wild).

Quoted 5 lines
Quoted 2 lines

Can you test this scenario with various guest OSes (old/new/MS Windows) to check if it won't break them.

Unless -machine smm=off is explicitly passed, this patch won't break guests. And such case is rare as I described above.

yes, it's a corner case but it doesn't guarantee that someone isn't using it it in the wild.

Quoted 9 lines

My motivation for this patch series is preparation for TDX which disallows SMM mode and SMI injection.

Quoted 2 lines

if we are to be conservative, we need to disable this compliance fix on old machine types.

I'm fine with adding one more knob to be on safe side. -machine smm=off is such knob, though.

you can use 2ebc21216f as an example of compat knob that changes behavior depending on machine version. (i.e. to keep old behavior in piix4/ich9 on exiting machine versions)

Quoted 1 line

Thanks,

#8 lore raw

PATCH v2 4/9 acpi: set fadt.smi_cmd to zero when SMM is not supported

In reply to [email protected]

From: Isaku Yamahata <[email protected]>

From table 5.9 SMI_CMD of ACPI spec

Quoted 2 lines

This field is reserved and must be zero on system
that does not support System Management mode.

When smm is not enabled, set it to zero to comform to the spec. When -machine smm=off is passed, the change to FACP is as follows.

@@ -1,46 +1,46 @@
/*
* Intel ACPI Component Architecture
* AML/ASL+ Disassembler version 20180105 (64-bit version)
* Copyright (c) 2000 - 2018 Intel Corporation
*
- * Disassembly of tests/data/acpi/q35/FACP, Fri Feb 5 16:57:04 2021
+ * Disassembly of /tmp/aml-1OQYX0, Fri Feb 5 16:57:04 2021 *
* ACPI Data Table [FACP]
*
* Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue */

 [000h 0000   4]                    Signature : "FACP"    [Fixed ACPI Description Table (FADT)]
 [004h 0004   4]                 Table Length : 000000F4
 [008h 0008   1]                     Revision : 03
-[009h 0009   1]                     Checksum : 1F
+[009h 0009   1]                     Checksum : D6
 [00Ah 0010   6]                       Oem ID : "BOCHS "
 [010h 0016   8]                 Oem Table ID : "BXPCFACP"
 [018h 0024   4]                 Oem Revision : 00000001
 [01Ch 0028   4]              Asl Compiler ID : "BXPC"
 [020h 0032   4]        Asl Compiler Revision : 00000001
 [024h 0036   4]                 FACS Address : 00000000
 [028h 0040   4]                 DSDT Address : 00000000
 [02Ch 0044   1]                        Model : 01
 [02Dh 0045   1]                   PM Profile : 00 [Unspecified]
 [02Eh 0046   2]                SCI Interrupt : 0009
-[030h 0048   4]             SMI Command Port : 000000B2
-[034h 0052   1]            ACPI Enable Value : 02
-[035h 0053   1]           ACPI Disable Value : 03
+[030h 0048   4]             SMI Command Port : 00000000
+[034h 0052   1]            ACPI Enable Value : 00
+[035h 0053   1]           ACPI Disable Value : 00
 [036h 0054   1]               S4BIOS Command : 00
 [037h 0055   1]              P-State Control : 00
 [038h 0056   4]     PM1A Event Block Address : 00000600
 [03Ch 0060   4]     PM1B Event Block Address : 00000000
 [040h 0064   4]   PM1A Control Block Address : 00000604
 [044h 0068   4]   PM1B Control Block Address : 00000000
 [048h 0072   4]    PM2 Control Block Address : 00000000
 [04Ch 0076   4]       PM Timer Block Address : 00000608
 [050h 0080   4]           GPE0 Block Address : 00000620
 [054h 0084   4]           GPE1 Block Address : 00000000
 [058h 0088   1]       PM1 Event Block Length : 04
 [059h 0089   1]     PM1 Control Block Length : 02
 [05Ah 0090   1]     PM2 Control Block Length : 00
 [05Bh 0091   1]        PM Timer Block Length : 04
 [05Ch 0092   1]            GPE0 Block Length : 10
 [05Dh 0093   1]            GPE1 Block Length : 00
---
 hw/i386/acpi-build.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
hw/i386/acpi-build.c +9 -3
index f56d699c7f..c2f11d95d8 100644
@@ -139,6 +139,8 @@ const struct AcpiGenericAddress x86_nvdimm_acpi_dsmio = {
 static void init_common_fadt_data(MachineState *ms, Object *o,
                                   AcpiFadtData *data)
 {
+    X86MachineState *x86ms = X86_MACHINE(ms);
+    bool smm_enabled = x86_machine_is_smm_enabled(x86ms);
     uint32_t io = object_property_get_uint(o, ACPI_PM_PROP_PM_IO_BASE, NULL);
     AmlAddressSpace as = AML_AS_SYSTEM_IO;
     AcpiFadtData fadt = {
@@ -159,12 +161,16 @@ static void init_common_fadt_data(MachineState *ms, Object *o,
         .rtc_century = RTC_CENTURY,
         .plvl2_lat = 0xfff /* C2 state not supported */,
         .plvl3_lat = 0xfff /* C3 state not supported */,
-        .smi_cmd = ACPI_PORT_SMI_CMD,
+        .smi_cmd = smm_enabled ? ACPI_PORT_SMI_CMD : 0,
         .sci_int = object_property_get_uint(o, ACPI_PM_PROP_SCI_INT, NULL),
         .acpi_enable_cmd =
-            object_property_get_uint(o, ACPI_PM_PROP_ACPI_ENABLE_CMD, NULL),
+            smm_enabled ?
+            object_property_get_uint(o, ACPI_PM_PROP_ACPI_ENABLE_CMD, NULL) :
+            0,
         .acpi_disable_cmd =
-            object_property_get_uint(o, ACPI_PM_PROP_ACPI_DISABLE_CMD, NULL),
+            smm_enabled ?
+            object_property_get_uint(o, ACPI_PM_PROP_ACPI_DISABLE_CMD, NULL) :
+            0,
         .pm1a_evt = { .space_id = as, .bit_width = 4 * 8, .address = io },
         .pm1a_cnt = { .space_id = as, .bit_width = 2 * 8,
                       .address = io + 0x04 },
Signature · 1 line
2.17.1
Reviewed-by on v2 4/9
#9 lore raw

Re: [PATCH v2 4/9] acpi: set fadt.smi_cmd to zero when SMM is not supported

Quoted 62 lines · On Mon, 8 Feb 2021 13:57:23 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

From table 5.9 SMI_CMD of ACPI spec

Quoted 2 lines

This field is reserved and must be zero on system
that does not support System Management mode.

When smm is not enabled, set it to zero to comform to the spec. When -machine smm=off is passed, the change to FACP is as follows.

(quoted diff) +5 -5
@@ -1,46 +1,46 @@
 /*
  * Intel ACPI Component Architecture
  * AML/ASL+ Disassembler version 20180105 (64-bit version)
  * Copyright (c) 2000 - 2018 Intel Corporation
  *
- * Disassembly of tests/data/acpi/q35/FACP, Fri Feb  5 16:57:04 2021
+ * Disassembly of /tmp/aml-1OQYX0, Fri Feb  5 16:57:04 2021
  *
  * ACPI Data Table [FACP]
  *
  * Format: [HexOffset DecimalOffset ByteLength]  FieldName : FieldValue
  */
 
 [000h 0000   4]                    Signature : "FACP"    [Fixed ACPI Description Table (FADT)]
 [004h 0004   4]                 Table Length : 000000F4
 [008h 0008   1]                     Revision : 03
-[009h 0009   1]                     Checksum : 1F
+[009h 0009   1]                     Checksum : D6
 [00Ah 0010   6]                       Oem ID : "BOCHS "
 [010h 0016   8]                 Oem Table ID : "BXPCFACP"
 [018h 0024   4]                 Oem Revision : 00000001
 [01Ch 0028   4]              Asl Compiler ID : "BXPC"
 [020h 0032   4]        Asl Compiler Revision : 00000001
 
 [024h 0036   4]                 FACS Address : 00000000
 [028h 0040   4]                 DSDT Address : 00000000
 [02Ch 0044   1]                        Model : 01
 [02Dh 0045   1]                   PM Profile : 00 [Unspecified]
 [02Eh 0046   2]                SCI Interrupt : 0009
-[030h 0048   4]             SMI Command Port : 000000B2
-[034h 0052   1]            ACPI Enable Value : 02
-[035h 0053   1]           ACPI Disable Value : 03
+[030h 0048   4]             SMI Command Port : 00000000
+[034h 0052   1]            ACPI Enable Value : 00
+[035h 0053   1]           ACPI Disable Value : 00
 [036h 0054   1]               S4BIOS Command : 00
 [037h 0055   1]              P-State Control : 00
 [038h 0056   4]     PM1A Event Block Address : 00000600
 [03Ch 0060   4]     PM1B Event Block Address : 00000000
 [040h 0064   4]   PM1A Control Block Address : 00000604
 [044h 0068   4]   PM1B Control Block Address : 00000000
 [048h 0072   4]    PM2 Control Block Address : 00000000
 [04Ch 0076   4]       PM Timer Block Address : 00000608
 [050h 0080   4]           GPE0 Block Address : 00000620
 [054h 0084   4]           GPE1 Block Address : 00000000
 [058h 0088   1]       PM1 Event Block Length : 04
 [059h 0089   1]     PM1 Control Block Length : 02
 [05Ah 0090   1]     PM2 Control Block Length : 00
 [05Bh 0091   1]        PM Timer Block Length : 04
 [05Ch 0092   1]            GPE0 Block Length : 10
 [05Dh 0093   1]            GPE1 Block Length : 00
Quoted 1 line

when migrated to old QEMU, and VM after that is reset it regenerate ACPI tables for old QEMU, so guest should be able to turn on ACPI.

Quoted 37 lines
---
 hw/i386/acpi-build.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
hw/i386/acpi-build.c +9 -3
index f56d699c7f..c2f11d95d8 100644
@@ -139,6 +139,8 @@ const struct AcpiGenericAddress x86_nvdimm_acpi_dsmio = {
 static void init_common_fadt_data(MachineState *ms, Object *o,
                                   AcpiFadtData *data)
 {
+    X86MachineState *x86ms = X86_MACHINE(ms);
+    bool smm_enabled = x86_machine_is_smm_enabled(x86ms);
     uint32_t io = object_property_get_uint(o, ACPI_PM_PROP_PM_IO_BASE, NULL);
     AmlAddressSpace as = AML_AS_SYSTEM_IO;
     AcpiFadtData fadt = {
@@ -159,12 +161,16 @@ static void init_common_fadt_data(MachineState *ms, Object *o,
         .rtc_century = RTC_CENTURY,
         .plvl2_lat = 0xfff /* C2 state not supported */,
         .plvl3_lat = 0xfff /* C3 state not supported */,
-        .smi_cmd = ACPI_PORT_SMI_CMD,
+        .smi_cmd = smm_enabled ? ACPI_PORT_SMI_CMD : 0,
         .sci_int = object_property_get_uint(o, ACPI_PM_PROP_SCI_INT, NULL),
         .acpi_enable_cmd =
-            object_property_get_uint(o, ACPI_PM_PROP_ACPI_ENABLE_CMD, NULL),
+            smm_enabled ?
+            object_property_get_uint(o, ACPI_PM_PROP_ACPI_ENABLE_CMD, NULL) :
+            0,
         .acpi_disable_cmd =
-            object_property_get_uint(o, ACPI_PM_PROP_ACPI_DISABLE_CMD, NULL),
+            smm_enabled ?
+            object_property_get_uint(o, ACPI_PM_PROP_ACPI_DISABLE_CMD, NULL) :
+            0,
         .pm1a_evt = { .space_id = as, .bit_width = 4 * 8, .address = io },
         .pm1a_cnt = { .space_id = as, .bit_width = 2 * 8,
                       .address = io + 0x04 },
#10 lore raw

PATCH v2 5/9 acpi: add test case for smm unsupported -machine smm=off

In reply to [email protected]

From: Isaku Yamahata <[email protected]>

---
 tests/qtest/bios-tables-test.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tests/qtest/bios-tables-test.c +12 -0
index 669202fc95..096d15db68 100644
@@ -969,6 +969,17 @@ static void test_acpi_q35_tcg_numamem(void)
     free_test_data(&data);
 }
 
+static void test_acpi_q35_tcg_nosmm(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".nosmm";
+    test_acpi_one("-machine smm=off", &data);
+    free_test_data(&data);
+}
+
 static void test_acpi_piix4_tcg_numamem(void)
 {
     test_data data;
@@ -1325,6 +1336,7 @@ int main(int argc, char *argv[])
         qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
         qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
         qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
+        qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm);
         qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
         qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
         qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat);
Signature · 1 line
2.17.1
Reviewed-by on v2 5/9
#11 lore raw

Re: [PATCH v2 5/9] acpi: add test case for smm unsupported -machine smm=off

Quoted 3 lines · On Mon, 8 Feb 2021 13:57:24 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

Quoted 34 lines
---
 tests/qtest/bios-tables-test.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tests/qtest/bios-tables-test.c +12 -0
index 669202fc95..096d15db68 100644
@@ -969,6 +969,17 @@ static void test_acpi_q35_tcg_numamem(void)
     free_test_data(&data);
 }
 
+static void test_acpi_q35_tcg_nosmm(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".nosmm";
+    test_acpi_one("-machine smm=off", &data);
+    free_test_data(&data);
+}
+
 static void test_acpi_piix4_tcg_numamem(void)
 {
     test_data data;
@@ -1325,6 +1336,7 @@ int main(int argc, char *argv[])
         qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
         qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
         qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
+        qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm);
         qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
         qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
         qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat);
#12 lore raw

PATCH v2 6/9 hw/i386: declare ACPI mother board resource for MMCONFIG region

In reply to [email protected]

From: Isaku Yamahata <[email protected]>

Declare PNP0C01 device to reserve MMCONFIG region to conform to the spec better and play nice with guest BIOSes/OSes.

According to PCI Firmware Specification, MMCONFIG region must be reserved by declaring a motherboard resource. It's optional to reserve the region in memory map by Int 15 E820h or EFIGetMemoryMap. If guest BIOS doesn't reserve the region in memory map without the reservation by mother board resource, guest linux abandons to use MMCFG.

TDVF [0] [1] doesn't reserve MMCONFIG the region in memory map. On the other hand OVMF reserves it in memory map without declaring a motherboard resource. With memory map reservation, linux guest uses MMCONFIG region. However it doesn't comply to PCI Firmware specification.

[0] TDX: Intel Trust Domain Extension
https://software.intel.com/content/www/us/en/develop/articles/intel-trust-domain-extensions.html
[1] TDX Virtual Firmware
https://github.com/tianocore/edk2-staging/tree/TDVF

The change to DSDT is as follows.
@@ -68,32 +68,90 @@

                     If ((CDW3 != Local0))
                     {
                         CDW1 |= 0x10
                     }

                     CDW3 = Local0
                 }
                 Else
                 {
                     CDW1 |= 0x04
                 }

                 Return (Arg3)
             }
         }
+
+        Device (DRAC)
+        {
+            Name (_HID, "PNP0C01" /* System Board */)  // _HID: Hardware ID
+            OperationRegion (DRR0, PCI_Config, 0x60, 0x08)
+            Field (DRR0, DWordAcc, NoLock, Preserve)
+            {
+                PEBL,   32,
+                PEBH,   32

+ }
+
+ Name (RBUF, ResourceTemplate ()
+ {
+ QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,

+                    0x0000000000000000, // Granularity
+                    0x0000000000000000, // Range Minimum
+                    0x0000000000000000, // Range Maximum
+                    0x0000000000000000, // Translation Offset
+                    0x0000000000000000, // Length
+                    ,, _Y00, AddressRangeMemory, TypeStatic)
+            })
+            Method (_CRS, 0, Serialized)  // _CRS: Current Resource Settings
+            {
+                CreateDWordField (RBUF, \_SB.DRAC._Y00._MIN, MINL)  // _MIN: Minimum Base Address
+                CreateDWordField (RBUF, 0x12, MINH)
+                CreateDWordField (RBUF, \_SB.DRAC._Y00._MAX, MAXL)  // _MAX: Maximum Base Address
+                CreateDWordField (RBUF, 0x1A, MAXH)
+                CreateQWordField (RBUF, \_SB.DRAC._Y00._LEN, _LEN)  // _LEN: Length
+                Local0 = PEBL /* \_SB_.DRAC.PEBL */
+                Local1 = (Local0 & One)
+                Local2 = (Local0 & 0x06)
+                Local3 = (Local0 & 0xFFFFFFF8)
+                Local4 = PEBH /* \_SB_.DRAC.PEBH */
+                If ((Local1 == One))
+                {
+                    MINL = Local3
+                    MINH = Local4
+                    MAXL = Local3
+                    MAXH = Local4
+                    If ((Local2 == Zero))
+                    {

+ _LEN = 0x10000000
+ }
+
+ If ((Local2 == 0x02))
+ {
+ _LEN = 0x08000000
+ }
+
+ If ((Local2 == 0x04))
+ {
+ _LEN = 0x04000000
+ }
+ }
+
+ Return (RBUF) /* \_SB_.DRAC.RBUF */
+ }
+ }

     }

     Scope (_SB)
     {
         Device (HPET)
         {
             Name (_HID, EisaId ("PNP0103") /* HPET System Timer */)  // _HID: Hardware ID
             Name (_UID, Zero)  // _UID: Unique ID
             OperationRegion (HPTM, SystemMemory, 0xFED00000, 0x0400)
             Field (HPTM, DWordAcc, Lock, Preserve)
             {
                 VEND,   32,
                 PRD,    32
             }

             Method (_STA, 0, NotSerialized)  // _STA: Status
---
 hw/i386/acpi-build.c | 172 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 172 insertions(+)
hw/i386/acpi-build.c +172 -0
index c2f11d95d8..bcb1f65c1d 100644
@@ -1066,6 +1066,177 @@ static void build_q35_pci0_int(Aml *table)
     aml_append(table, sb_scope);
 }
 
+static Aml *build_q35_dram_controller(void)
+{
+    /*
+     * DSDT is created with revision 1 which means 32bit integer.
+     * When the method of _CRS is called to determine MMCONFIG region,
+     * only port io is allowed to access PCI configuration space.
+     * It means qword access isn't allowed.
+     *
+     * Device(DRAC)
+     * {
+     *     Name(_HID, EisaId("PNP0C01"))
+     *     OperationRegion(DRR0, PCI_Config, 0x0000000000000060, 0x8)
+     *     Field(DRR0, DWordAcc, Lock, Preserve)
+     *     {
+     *         PEBL, 4,
+     *         PEBH, 4
+     *     }
+     *     Name(RBUF, ResourceTemplate()
+     *     {
+     *         QWordMemory(ResourceConsumer,
+     *                     PosDecode,
+     *                     MinFixed,
+     *                     MaxFixed,
+     *                     NonCacheable,
+     *                     ReadWrite,
+     *                     0x0000000000000000, // Granularity
+     *                     0x0000000000000000, // Range Minimum
+     *                     0x0000000000000000, // Range Maxium
+     *                     0x0000000000000000, // Translation Offset,
+     *                     0x0000000000000000, // Length,
+     *                     ,,
+     *                     _MCF,
+     *                     AddressRangeMemory,
+     *                     TypeStatic
+     *                     )
+     *     })
+     *     Method(_CRS, 0x0, NotSerialized)
+     *     {
+     *         CreateDWordField(RBUF, DRAC._MCF._MIN, MINL)
+     *         CreateDWordField(RBUF, DRAC._MCF._MIN + 4, MINH)
+     *         CreateDWordField(RBUF, DRAC._MCF._MAX, MAXL)
+     *         CreateDWordField(RBUF, DRAC._MCF._MAX + 4, MAXH)
+     *         CreateQWordField(RBUF, DRAC._MCF._LEN, _LEN)
+     *
+     *         Local0 = PEBL
+     *         Local1 = Local0 & 0x1  // PCIEXBAR PCIEBAREN
+     *         Local2 = Local0 & 0x6  // PCIEXBAR LENGTH
+     *         Local3 = Local0 & ~0x7 // PCIEXBAR base address low 32bit
+     *         Local4 = PEBH          // PCIEXBAR base address high 32bit
+     *         If (Local1 == 1) {
+     *             MINL = Local3
+     *             MINH = Local4
+     *             MAXL = Local3
+     *             MAXH = Local4
+     *
+     *             If (Local2 == 0) {
+     *                 _LEN = 256 * 1024 * 1024
+     *             }
+     *             If (Local2 == 0x2) {
+     *                 _LEN = 128 * 1024 * 1024
+     *             }
+     *             If (Local2 == 0x4) {
+     *                 _LEN = 64 * 1024 * 1024
+     *             }
+     *         }
+     *         return (RBUF)
+     *     }
+     * }
+     */
+
+    Aml *dev;
+    Aml *field;
+    Aml *rbuf;
+    Aml *resource_template;
+    Aml *crs;
+
+    /* DRAM controller */
+    dev = aml_device("DRAC");
+
+    aml_append(dev, aml_name_decl("_HID", aml_string("PNP0C01")));
+    /* 5.1.6 PCIEXBAR: Bus 0:Device 0:Function 0:offset 0x60 */
+    aml_append(dev, aml_operation_region("DRR0", AML_PCI_CONFIG,
+                                         aml_int(0x0000000000000060), 0x8));
+    field = aml_field("DRR0", AML_DWORD_ACC, AML_NOLOCK, AML_PRESERVE);
+    aml_append(field, aml_named_field("PEBL", 32));
+    aml_append(field, aml_named_field("PEBH", 32));
+    aml_append(dev, field);
+
+    resource_template = aml_resource_template();
+    aml_append(resource_template, aml_qword_memory(AML_POS_DECODE,
+                                                   AML_MIN_FIXED,
+                                                   AML_MAX_FIXED,
+                                                   AML_NON_CACHEABLE,
+                                                   AML_READ_WRITE,
+                                                   0x0000000000000000,
+                                                   0x0000000000000000,
+                                                   0x0000000000000000,
+                                                   0x0000000000000000,
+                                                   0x0000000000000000));
+    rbuf = aml_name_decl("RBUF", resource_template);
+    aml_append(dev, rbuf);
+
+    crs = aml_method("_CRS", 0, AML_SERIALIZED);
+    {
+        Aml *rbuf_name;
+        Aml *local0;
+        Aml *local1;
+        Aml *local2;
+        Aml *local3;
+        Aml *local4;
+        Aml *ifc;
+
+        rbuf_name = aml_name("RBUF");
+        aml_append(crs, aml_create_dword_field(rbuf_name,
+                                               aml_int(14), "MINL"));
+        aml_append(crs, aml_create_dword_field(rbuf_name,
+                                               aml_int(14 + 4), "MINH"));
+        aml_append(crs, aml_create_dword_field(rbuf_name,
+                                               aml_int(22), "MAXL"));
+        aml_append(crs, aml_create_dword_field(rbuf_name,
+                                               aml_int(22 + 4), "MAXH"));
+        aml_append(crs, aml_create_qword_field(rbuf_name,
+                                               aml_int(38), "_LEN"));
+
+        local0 = aml_local(0);
+        aml_append(crs, aml_store(aml_name("PEBL"), local0));
+        local1 = aml_local(1);
+        aml_append(crs, aml_and(local0, aml_int(0x1), local1));
+        local2 = aml_local(2);
+        aml_append(crs, aml_and(local0, aml_int(0x6), local2));
+        local3 = aml_local(3);
+        aml_append(crs, aml_and(local0, aml_int((uint32_t)~0x7), local3));
+        local4 = aml_local(4);
+        aml_append(crs, aml_store(aml_name("PEBH"), local4));
+
+        ifc = aml_if(aml_equal(local1, aml_int(0x1)));
+        {
+            Aml *_len;
+            Aml *ifc0;
+            Aml *ifc2;
+            Aml *ifc4;
+
+            aml_append(ifc, aml_store(local3, aml_name("MINL")));
+            aml_append(ifc, aml_store(local4, aml_name("MINH")));
+            aml_append(ifc, aml_store(local3, aml_name("MAXL")));
+            aml_append(ifc, aml_store(local4, aml_name("MAXH")));
+
+            _len = aml_name("_LEN");
+            ifc0 = aml_if(aml_equal(local2, aml_int(0x0)));
+            aml_append(ifc0,
+                       aml_store(aml_int(256 * 1024 * 1024), _len));
+            aml_append(ifc, ifc0);
+
+            ifc2 = aml_if(aml_equal(local2, aml_int(0x2)));
+            aml_append(ifc2,
+                       aml_store(aml_int(128 * 1024 * 1024), _len));
+            aml_append(ifc, ifc2);
+
+            ifc4 = aml_if(aml_equal(local2, aml_int(0x4)));
+            aml_append(ifc4,
+                       aml_store(aml_int(64 * 1024 * 1024), _len));
+            aml_append(ifc, ifc4);
+        }
+        aml_append(crs, ifc);
+        aml_append(crs, aml_return(rbuf_name));
+    }
+    aml_append(dev, crs);
+
+    return dev;
+}
+
 static void build_q35_isa_bridge(Aml *table)
 {
     Aml *dev;
@@ -1250,6 +1421,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         aml_append(dev, aml_name_decl("_UID", aml_int(0)));
         aml_append(dev, build_q35_osc_method());
         aml_append(sb_scope, dev);
+        aml_append(sb_scope, build_q35_dram_controller());
 
         if (pm->smi_on_cpuhp) {
             /* reserve SMI block resources, IO ports 0xB2, 0xB3 */
Signature · 1 line
2.17.1
#13 lore raw

Re: [PATCH v2 6/9] hw/i386: declare ACPI mother board resource for MMCONFIG region

Quoted 7 lines · On Mon, 8 Feb 2021 13:57:25 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

Declare PNP0C01 device to reserve MMCONFIG region to conform to the spec better and play nice with guest BIOSes/OSes.

According to PCI Firmware Specification, MMCONFIG region must be reserved by declaring a motherboard resource.

could you point to concrete spec version/chapter where it stated. (should be part of commit message)

Quoted 6 lines

It's optional to reserve
the region in memory map by Int 15 E820h or EFIGetMemoryMap.

If guest BIOS doesn't reserve the region in memory map without the reservation by mother board resource, guest linux abandons to use MMCFG.

can parse this, can you rephrase and avoid double negation, please?

Quoted 115 lines

TDVF [0] [1] doesn't reserve MMCONFIG the region in memory map. On the other hand OVMF reserves it in memory map without declaring a motherboard resource. With memory map reservation, linux guest uses MMCONFIG region. However it doesn't comply to PCI Firmware specification.

[0] TDX: Intel Trust Domain Extension
https://software.intel.com/content/www/us/en/develop/articles/intel-trust-domain-extensions.html
[1] TDX Virtual Firmware
https://github.com/tianocore/edk2-staging/tree/TDVF

The change to DSDT is as follows.

(quoted diff) +58 -0
@@ -68,32 +68,90 @@
 
                     If ((CDW3 != Local0))
                     {
                         CDW1 |= 0x10
                     }
 
                     CDW3 = Local0
                 }
                 Else
                 {
                     CDW1 |= 0x04
                 }
 
                 Return (Arg3)
             }
         }
+
+        Device (DRAC)
+        {
+            Name (_HID, "PNP0C01" /* System Board */)  // _HID: Hardware ID
+            OperationRegion (DRR0, PCI_Config, 0x60, 0x08)
+            Field (DRR0, DWordAcc, NoLock, Preserve)
+            {
+                PEBL,   32,
+                PEBH,   32
+            }
+
+            Name (RBUF, ResourceTemplate ()
+            {
+                QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
+                    0x0000000000000000, // Granularity
+                    0x0000000000000000, // Range Minimum
+                    0x0000000000000000, // Range Maximum
+                    0x0000000000000000, // Translation Offset
+                    0x0000000000000000, // Length
+                    ,, _Y00, AddressRangeMemory, TypeStatic)
+            })
+            Method (_CRS, 0, Serialized)  // _CRS: Current Resource Settings
+            {
+                CreateDWordField (RBUF, \_SB.DRAC._Y00._MIN, MINL)  // _MIN: Minimum Base Address
+                CreateDWordField (RBUF, 0x12, MINH)
+                CreateDWordField (RBUF, \_SB.DRAC._Y00._MAX, MAXL)  // _MAX: Maximum Base Address
+                CreateDWordField (RBUF, 0x1A, MAXH)
+                CreateQWordField (RBUF, \_SB.DRAC._Y00._LEN, _LEN)  // _LEN: Length
+                Local0 = PEBL /* \_SB_.DRAC.PEBL */
+                Local1 = (Local0 & One)
+                Local2 = (Local0 & 0x06)
+                Local3 = (Local0 & 0xFFFFFFF8)
+                Local4 = PEBH /* \_SB_.DRAC.PEBH */
+                If ((Local1 == One))
+                {
+                    MINL = Local3
+                    MINH = Local4
+                    MAXL = Local3
+                    MAXH = Local4
+                    If ((Local2 == Zero))
+                    {
+                        _LEN = 0x10000000
+                    }
+
+                    If ((Local2 == 0x02))
+                    {
+                        _LEN = 0x08000000
+                    }
+
+                    If ((Local2 == 0x04))
+                    {
+                        _LEN = 0x04000000
+                    }
+                }
+
+                Return (RBUF) /* \_SB_.DRAC.RBUF */
+            }
+        }
     }
 
     Scope (_SB)
     {
         Device (HPET)
         {
             Name (_HID, EisaId ("PNP0103") /* HPET System Timer */)  // _HID: Hardware ID
             Name (_UID, Zero)  // _UID: Unique ID
             OperationRegion (HPTM, SystemMemory, 0xFED00000, 0x0400)
             Field (HPTM, DWordAcc, Lock, Preserve)
             {
                 VEND,   32,
                 PRD,    32
             }
 
             Method (_STA, 0, NotSerialized)  // _STA: Status
---
 hw/i386/acpi-build.c | 172 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 172 insertions(+)
hw/i386/acpi-build.c +0 -0
index c2f11d95d8..bcb1f65c1d 100644

hw/i386/acpi-build.c static void build_q35_pci0_int(Aml *table) · line 1072

Quoted 7 lines
hw/i386/acpi-build.c +4 -0
@@ -1066,6 +1066,177 @@ static void build_q35_pci0_int(Aml *table)
     aml_append(table, sb_scope);
 }
 
+static Aml *build_q35_dram_controller(void)
+{
+    /*
+     * DSDT is created with revision 1 which means 32bit integer.

version 1, is kept for Windows XP sake which is EOLed long ago, and it even will boot with v2 as long as AML doesn't contain non v1 terms or those are hidden behind dynamic method which are not evaluated. Perhaps we should bump dsdt revision to v2.
And anyways with this patch XP probably will trip over, if it tries to parse 64bit CRS, but we probably don't care about XP on q35.

hw/i386/acpi-build.c static void build_q35_pci0_int(Aml *table) · line 1085

Quoted 13 lines
hw/i386/acpi-build.c +13 -0
+     * When the method of _CRS is called to determine MMCONFIG region,
+     * only port io is allowed to access PCI configuration space.
+     * It means qword access isn't allowed.
+     *
+     * Device(DRAC)
+     * {
+     *     Name(_HID, EisaId("PNP0C01"))
+     *     OperationRegion(DRR0, PCI_Config, 0x0000000000000060, 0x8)
+     *     Field(DRR0, DWordAcc, Lock, Preserve)
+     *     {
+     *         PEBL, 4,
+     *         PEBH, 4
+     *     }

why are you trying to fetch it dynamically?
what prevents you from getting MMCONFIG address in QEMU when building ACPI tables and encode _CRS statically at that time?

Quoted 165 lines
hw/i386/acpi-build.c +155 -0
+     *     Name(RBUF, ResourceTemplate()
+     *     {
+     *         QWordMemory(ResourceConsumer,
+     *                     PosDecode,
+     *                     MinFixed,
+     *                     MaxFixed,
+     *                     NonCacheable,
+     *                     ReadWrite,
+     *                     0x0000000000000000, // Granularity
+     *                     0x0000000000000000, // Range Minimum
+     *                     0x0000000000000000, // Range Maxium
+     *                     0x0000000000000000, // Translation Offset,
+     *                     0x0000000000000000, // Length,
+     *                     ,,
+     *                     _MCF,
+     *                     AddressRangeMemory,
+     *                     TypeStatic
+     *                     )
+     *     })
+     *     Method(_CRS, 0x0, NotSerialized)
+     *     {
+     *         CreateDWordField(RBUF, DRAC._MCF._MIN, MINL)
+     *         CreateDWordField(RBUF, DRAC._MCF._MIN + 4, MINH)
+     *         CreateDWordField(RBUF, DRAC._MCF._MAX, MAXL)
+     *         CreateDWordField(RBUF, DRAC._MCF._MAX + 4, MAXH)
+     *         CreateQWordField(RBUF, DRAC._MCF._LEN, _LEN)
+     *
+     *         Local0 = PEBL
+     *         Local1 = Local0 & 0x1  // PCIEXBAR PCIEBAREN
+     *         Local2 = Local0 & 0x6  // PCIEXBAR LENGTH
+     *         Local3 = Local0 & ~0x7 // PCIEXBAR base address low 32bit
+     *         Local4 = PEBH          // PCIEXBAR base address high 32bit
+     *         If (Local1 == 1) {
+     *             MINL = Local3
+     *             MINH = Local4
+     *             MAXL = Local3
+     *             MAXH = Local4
+     *
+     *             If (Local2 == 0) {
+     *                 _LEN = 256 * 1024 * 1024
+     *             }
+     *             If (Local2 == 0x2) {
+     *                 _LEN = 128 * 1024 * 1024
+     *             }
+     *             If (Local2 == 0x4) {
+     *                 _LEN = 64 * 1024 * 1024
+     *             }
+     *         }
+     *         return (RBUF)
+     *     }
+     * }
+     */
+
+    Aml *dev;
+    Aml *field;
+    Aml *rbuf;
+    Aml *resource_template;
+    Aml *crs;
+
+    /* DRAM controller */
+    dev = aml_device("DRAC");
+
+    aml_append(dev, aml_name_decl("_HID", aml_string("PNP0C01")));
+    /* 5.1.6 PCIEXBAR: Bus 0:Device 0:Function 0:offset 0x60 */
+    aml_append(dev, aml_operation_region("DRR0", AML_PCI_CONFIG,
+                                         aml_int(0x0000000000000060), 0x8));
+    field = aml_field("DRR0", AML_DWORD_ACC, AML_NOLOCK, AML_PRESERVE);
+    aml_append(field, aml_named_field("PEBL", 32));
+    aml_append(field, aml_named_field("PEBH", 32));
+    aml_append(dev, field);
+
+    resource_template = aml_resource_template();
+    aml_append(resource_template, aml_qword_memory(AML_POS_DECODE,
+                                                   AML_MIN_FIXED,
+                                                   AML_MAX_FIXED,
+                                                   AML_NON_CACHEABLE,
+                                                   AML_READ_WRITE,
+                                                   0x0000000000000000,
+                                                   0x0000000000000000,
+                                                   0x0000000000000000,
+                                                   0x0000000000000000,
+                                                   0x0000000000000000));
+    rbuf = aml_name_decl("RBUF", resource_template);
+    aml_append(dev, rbuf);
+
+    crs = aml_method("_CRS", 0, AML_SERIALIZED);
+    {
+        Aml *rbuf_name;
+        Aml *local0;
+        Aml *local1;
+        Aml *local2;
+        Aml *local3;
+        Aml *local4;
+        Aml *ifc;
+
+        rbuf_name = aml_name("RBUF");
+        aml_append(crs, aml_create_dword_field(rbuf_name,
+                                               aml_int(14), "MINL"));
+        aml_append(crs, aml_create_dword_field(rbuf_name,
+                                               aml_int(14 + 4), "MINH"));
+        aml_append(crs, aml_create_dword_field(rbuf_name,
+                                               aml_int(22), "MAXL"));
+        aml_append(crs, aml_create_dword_field(rbuf_name,
+                                               aml_int(22 + 4), "MAXH"));
+        aml_append(crs, aml_create_qword_field(rbuf_name,
+                                               aml_int(38), "_LEN"));
+
+        local0 = aml_local(0);
+        aml_append(crs, aml_store(aml_name("PEBL"), local0));
+        local1 = aml_local(1);
+        aml_append(crs, aml_and(local0, aml_int(0x1), local1));
+        local2 = aml_local(2);
+        aml_append(crs, aml_and(local0, aml_int(0x6), local2));
+        local3 = aml_local(3);
+        aml_append(crs, aml_and(local0, aml_int((uint32_t)~0x7), local3));
+        local4 = aml_local(4);
+        aml_append(crs, aml_store(aml_name("PEBH"), local4));
+
+        ifc = aml_if(aml_equal(local1, aml_int(0x1)));
+        {
+            Aml *_len;
+            Aml *ifc0;
+            Aml *ifc2;
+            Aml *ifc4;
+
+            aml_append(ifc, aml_store(local3, aml_name("MINL")));
+            aml_append(ifc, aml_store(local4, aml_name("MINH")));
+            aml_append(ifc, aml_store(local3, aml_name("MAXL")));
+            aml_append(ifc, aml_store(local4, aml_name("MAXH")));
+
+            _len = aml_name("_LEN");
+            ifc0 = aml_if(aml_equal(local2, aml_int(0x0)));
+            aml_append(ifc0,
+                       aml_store(aml_int(256 * 1024 * 1024), _len));
+            aml_append(ifc, ifc0);
+
+            ifc2 = aml_if(aml_equal(local2, aml_int(0x2)));
+            aml_append(ifc2,
+                       aml_store(aml_int(128 * 1024 * 1024), _len));
+            aml_append(ifc, ifc2);
+
+            ifc4 = aml_if(aml_equal(local2, aml_int(0x4)));
+            aml_append(ifc4,
+                       aml_store(aml_int(64 * 1024 * 1024), _len));
+            aml_append(ifc, ifc4);
+        }
+        aml_append(crs, ifc);
+        aml_append(crs, aml_return(rbuf_name));
+    }
+    aml_append(dev, crs);
+
+    return dev;
+}
+
 static void build_q35_isa_bridge(Aml *table)
 {
     Aml *dev;
@@ -1250,6 +1421,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         aml_append(dev, aml_name_decl("_UID", aml_int(0)));
         aml_append(dev, build_q35_osc_method());
         aml_append(sb_scope, dev);
+        aml_append(sb_scope, build_q35_dram_controller());
 
         if (pm->smi_on_cpuhp) {
             /* reserve SMI block resources, IO ports 0xB2, 0xB3 */
#14 lore raw

Re: [PATCH v2 6/9] hw/i386: declare ACPI mother board resource for MMCONFIG region

Quoted 5 lines · Igor Mammedov
Quoted 2 lines · On Mon, 8 Feb 2021 13:57:25 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

Quoted 7 lines
Quoted 5 lines

Declare PNP0C01 device to reserve MMCONFIG region to conform to the spec better and play nice with guest BIOSes/OSes.

According to PCI Firmware Specification, MMCONFIG region must be reserved by declaring a motherboard resource.

could you point to concrete spec version/chapter where it stated. (should be part of commit message)

PCI Firmware specification Revision 3.2
4.1.2 MCFG Table Description
table 4-2 NOTE 2
If the operating system does not natively comprehend reserving the MMCFG region, The MMCFG region must e reserved by firmware. ...
For most systems, the mortheroard resource would appear at the root of the ACPI namespace (under \_SB)...
The resource can optionally be returned in Int15 E820h or EFIGetMemoryMap as reserved memory but must always be reported through ACPI as a motherboard resource

Will include it in next respin.

Quoted 8 lines
Quoted 7 lines

It's optional to reserve
the region in memory map by Int 15 E820h or EFIGetMemoryMap.

If guest BIOS doesn't reserve the region in memory map without the reservation by mother board resource, guest linux abandons to use MMCFG.

can parse this, can you rephrase and avoid double negation, please?

How about this?
Guest Linux checks if the MMCFG region is reserved by bios memory map or ACPI resource. It failed, it falls back to legacy PCI configuraiton access.

Quoted 14 lines

hw/i386/acpi-build.c static void build_q35_pci0_int(Aml *table) · line 1085

Quoted 13 lines
hw/i386/acpi-build.c +13 -0
+     * When the method of _CRS is called to determine MMCONFIG region,
+     * only port io is allowed to access PCI configuration space.
+     * It means qword access isn't allowed.
+     *
+     * Device(DRAC)
+     * {
+     *     Name(_HID, EisaId("PNP0C01"))
+     *     OperationRegion(DRR0, PCI_Config, 0x0000000000000060, 0x8)
+     *     Field(DRR0, DWordAcc, Lock, Preserve)
+     *     {
+     *         PEBL, 4,
+     *         PEBH, 4
+     *     }
Quoted 3 lines

why are you trying to fetch it dynamically?
what prevents you from getting MMCONFIG address in QEMU when building ACPI tables and encode _CRS statically at that time?

My motivation is to prepare for TDX where ACPI tables will be part of measurement. I wanted ACPI tables to remain same irrelevant of chipset configuration which guest can change.

Thanks,

Signature · 1 line
Isaku Yamahata <[email protected]>
#15 lore raw

Re: [PATCH v2 6/9] hw/i386: declare ACPI mother board resource for MMCONFIG region

Quoted 14 lines · Isaku Yamahata
Quoted 14 lines
Quoted 13 lines
hw/i386/acpi-build.c +13 -0
+     * When the method of _CRS is called to determine MMCONFIG region,
+     * only port io is allowed to access PCI configuration space.
+     * It means qword access isn't allowed.
+     *
+     * Device(DRAC)
+     * {
+     *     Name(_HID, EisaId("PNP0C01"))
+     *     OperationRegion(DRR0, PCI_Config, 0x0000000000000060, 0x8)
+     *     Field(DRR0, DWordAcc, Lock, Preserve)
+     *     {
+     *         PEBL, 4,
+     *         PEBH, 4
+     *     }
Quoted 7 lines
Quoted 3 lines

why are you trying to fetch it dynamically?
what prevents you from getting MMCONFIG address in QEMU when building ACPI tables and encode _CRS statically at that time?

My motivation is to prepare for TDX where ACPI tables will be part of measurement. I wanted ACPI tables to remain same irrelevant of chipset configuration which guest can change.

I mean we are encoding lots of things like PCI description which is guest controllable. Is there reason to think mmconfig specifically will change after measurement?

Signature · 1 line
MST
#16 lore raw

Re: [PATCH v2 6/9] hw/i386: declare ACPI mother board resource for MMCONFIG region

Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Isaku Yamahata
Quoted 17 lines

hw/i386/acpi-build.c static void build_q35_pci0_int(Aml *table) · line 1085

Quoted 13 lines
hw/i386/acpi-build.c +13 -0
+     * When the method of _CRS is called to determine MMCONFIG region,
+     * only port io is allowed to access PCI configuration space.
+     * It means qword access isn't allowed.
+     *
+     * Device(DRAC)
+     * {
+     *     Name(_HID, EisaId("PNP0C01"))
+     *     OperationRegion(DRR0, PCI_Config, 0x0000000000000060, 0x8)
+     *     Field(DRR0, DWordAcc, Lock, Preserve)
+     *     {
+     *         PEBL, 4,
+     *         PEBH, 4
+     *     }

why are you trying to fetch it dynamically?
what prevents you from getting MMCONFIG address in QEMU when building ACPI tables and encode _CRS statically at that time?

Quoted 7 lines
Quoted 3 lines

My motivation is to prepare for TDX where ACPI tables will be part of measurement. I wanted ACPI tables to remain same irrelevant of chipset configuration which guest can change.

I mean we are encoding lots of things like PCI description which is guest controllable. Is there reason to think mmconfig specifically will change after measurement?

No in fact.
I'll switch to use MMCONFIG address in qemu.

Signature · 1 line
Isaku Yamahata <[email protected]>
#17 lore raw

Re: [PATCH v2 6/9] hw/i386: declare ACPI mother board resource for MMCONFIG region

In reply to Isaku Yamahata
Quoted 36 lines · On Tue, 9 Feb 2021 12:02:58 -0800 Isaku Yamahata <[email protected]>…
Quoted 5 lines · Igor Mammedov
Quoted 2 lines · On Mon, 8 Feb 2021 13:57:25 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

Quoted 7 lines
Quoted 5 lines

Declare PNP0C01 device to reserve MMCONFIG region to conform to the spec better and play nice with guest BIOSes/OSes.

According to PCI Firmware Specification, MMCONFIG region must be reserved by declaring a motherboard resource.

could you point to concrete spec version/chapter where it stated. (should be part of commit message)

PCI Firmware specification Revision 3.2
4.1.2 MCFG Table Description
table 4-2 NOTE 2
If the operating system does not natively comprehend reserving the MMCFG region, The MMCFG region must e reserved by firmware. ...
For most systems, the mortheroard resource would appear at the root of the ACPI namespace (under \_SB)...
The resource can optionally be returned in Int15 E820h or EFIGetMemoryMap as reserved memory but must always be reported through ACPI as a motherboard resource

Will include it in next respin.

Quoted 7 lines
Quoted 7 lines

It's optional to reserve
the region in memory map by Int 15 E820h or EFIGetMemoryMap.

If guest BIOS doesn't reserve the region in memory map without the reservation by mother board resource, guest linux abandons to use MMCFG.

Quoted 7 lines
Quoted 1 line

can parse this, can you rephrase and avoid double negation, please?

How about this?
Guest Linux checks if the MMCFG region is reserved by bios memory map or ACPI resource.

It failed, it falls back to legacy PCI configuraiton access.

clarify what/how failed, pls.

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
hw/i386/acpi-build.c +13 -0
+     * When the method of _CRS is called to determine MMCONFIG region,
+     * only port io is allowed to access PCI configuration space.
+     * It means qword access isn't allowed.
+     *
+     * Device(DRAC)
+     * {
+     *     Name(_HID, EisaId("PNP0C01"))
+     *     OperationRegion(DRR0, PCI_Config, 0x0000000000000060, 0x8)
+     *     Field(DRR0, DWordAcc, Lock, Preserve)
+     *     {
+     *         PEBL, 4,
+     *         PEBH, 4
+     *     }  
Quoted 7 lines
Quoted 3 lines

why are you trying to fetch it dynamically?
what prevents you from getting MMCONFIG address in QEMU when building ACPI tables and encode _CRS statically at that time?

My motivation is to prepare for TDX where ACPI tables will be part of measurement. I wanted ACPI tables to remain same irrelevant of chipset configuration which guest can change.

ACPI tables are supposed to be read from QEMU after firmware configured PCI subsystem, including MMCONFIG.
If configuration is changed after that MCFG table won't be correct anymore. Given MCFG is statically generated, I see no reason to fetch the same info dynamically from DSDT.

PS:
goal of having fixed ACPI tables is hard to achieve in QEMU,
it might be possible within single QEMU version for a concrete CLI configuration, but any deviation from that may trigger ACPI tables change.

Quoted 1 line

Thanks,

#18 lore raw

Re: [PATCH v2 6/9] hw/i386: declare ACPI mother board resource for MMCONFIG region

Quoted 39 lines · Igor Mammedov
Quoted 36 lines · On Tue, 9 Feb 2021 12:02:58 -0800 Isaku Yamahata <[email protected]>…
Quoted 5 lines · Igor Mammedov
Quoted 2 lines · On Mon, 8 Feb 2021 13:57:25 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

Quoted 7 lines
Quoted 5 lines

Declare PNP0C01 device to reserve MMCONFIG region to conform to the spec better and play nice with guest BIOSes/OSes.

According to PCI Firmware Specification, MMCONFIG region must be reserved by declaring a motherboard resource.

could you point to concrete spec version/chapter where it stated. (should be part of commit message)

PCI Firmware specification Revision 3.2
4.1.2 MCFG Table Description
table 4-2 NOTE 2
If the operating system does not natively comprehend reserving the MMCFG region, The MMCFG region must e reserved by firmware. ...
For most systems, the mortheroard resource would appear at the root of the ACPI namespace (under \_SB)...
The resource can optionally be returned in Int15 E820h or EFIGetMemoryMap as reserved memory but must always be reported through ACPI as a motherboard resource

Will include it in next respin.

Quoted 7 lines
Quoted 7 lines

It's optional to reserve
the region in memory map by Int 15 E820h or EFIGetMemoryMap.

If guest BIOS doesn't reserve the region in memory map without the reservation by mother board resource, guest linux abandons to use MMCFG.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

can parse this, can you rephrase and avoid double negation, please?

How about this?
Guest Linux checks if the MMCFG region is reserved by bios memory map or ACPI resource.

It failed, it falls back to legacy PCI configuraiton access.

clarify what/how failed, pls.

It should be "If it's not reserved".

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

hw/i386/acpi-build.c static void build_q35_pci0_int(Aml *table) · line 1085

Quoted 13 lines
hw/i386/acpi-build.c +13 -0
+     * When the method of _CRS is called to determine MMCONFIG region,
+     * only port io is allowed to access PCI configuration space.
+     * It means qword access isn't allowed.
+     *
+     * Device(DRAC)
+     * {
+     *     Name(_HID, EisaId("PNP0C01"))
+     *     OperationRegion(DRR0, PCI_Config, 0x0000000000000060, 0x8)
+     *     Field(DRR0, DWordAcc, Lock, Preserve)
+     *     {
+     *         PEBL, 4,
+     *         PEBH, 4
+     *     }  

why are you trying to fetch it dynamically?
what prevents you from getting MMCONFIG address in QEMU when building ACPI tables and encode _CRS statically at that time?

Quoted 8 lines
Quoted 3 lines

My motivation is to prepare for TDX where ACPI tables will be part of measurement. I wanted ACPI tables to remain same irrelevant of chipset configuration which guest can change.

ACPI tables are supposed to be read from QEMU after firmware configured PCI subsystem, including MMCONFIG.
If configuration is changed after that MCFG table won't be correct anymore. Given MCFG is statically generated, I see no reason to fetch the same info dynamically from DSDT.

Ok, given that other part of ACPI table generation code, I'll switch to use MMCONFIG address in qemu.

Quoted 7 lines

PS:
goal of having fixed ACPI tables is hard to achieve in QEMU,
it might be possible within single QEMU version for a concrete CLI configuration, but any deviation from that may trigger ACPI tables change.

Quoted 1 line

Thanks,

Thanks,

Signature · 1 line
Isaku Yamahata <[email protected]>
#19 lore raw

Re: [PATCH v2 6/9] hw/i386: declare ACPI mother board resource for MMCONFIG region

In reply to Igor Mammedov
Quoted 12 lines · Igor Mammedov
Quoted 12 lines
---
 hw/i386/acpi-build.c | 172 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 172 insertions(+)
hw/i386/acpi-build.c +0 -0
index c2f11d95d8..bcb1f65c1d 100644
@@ -1066,6 +1066,177 @@ static void build_q35_pci0_int(Aml *table)
     aml_append(table, sb_scope);
 }
 
Quoted 7 lines

hw/i386/acpi-build.c static void build_q35_pci0_int(Aml *table) · line 1072

Quoted 4 lines
hw/i386/acpi-build.c +4 -0
+static Aml *build_q35_dram_controller(void)
+{
+    /*
+     * DSDT is created with revision 1 which means 32bit integer.

version 1, is kept for Windows XP sake which is EOLed long ago, and it even will boot with v2 as long as AML doesn't contain non v1 terms or those are hidden behind dynamic method which are not evaluated.

right, this are doing lots of dynamic stuff, generally it is easy to hide things there. E.g.

if (high != 0) return qword else return dword

Quoted 1 line

Perhaps we should bump dsdt revision to v2.

I agree that bumping up to v2 is likely safe ...

Quoted 2 lines

And anyways with this patch XP probably will trip over, if it tries to parse 64bit CRS, but we probably don't care about XP on q35.

Yea I'm not sure why are we using qword here.

Signature · 1 line
MST
#20 lore raw

PATCH v2 7/9 i386: acpi: Don't build HPET ACPI entry if HPET is disabled

In reply to [email protected]

From: Sean Christopherson <[email protected]>

Omit HPET AML if the HPET is disabled, QEMU is not emulating it and the guest may get confused by seeing HPET in the ACPI tables without a "physical" device present.

The change of DSDT when -no-hpet is as follows.

@@ -141,47 +141,6 @@ DefinitionBlock ("", "DSDT", 1, "BOCHS "

         }
     }

- Scope (_SB)
- {
- Device (HPET)
- {

-            Name (_HID, EisaId ("PNP0103") /* HPET System Timer */)  // _HID: Hardware ID
-            Name (_UID, Zero)  // _UID: Unique ID
-            OperationRegion (HPTM, SystemMemory, 0xFED00000, 0x0400)
-            Field (HPTM, DWordAcc, Lock, Preserve)
-            {
-                VEND,   32,
-                PRD,    32

- }
-
- Method (_STA, 0, NotSerialized) // _STA: Status
- {

-                Local0 = VEND /* \_SB_.HPET.VEND */
-                Local1 = PRD /* \_SB_.HPET.PRD_ */
-                Local0 >>= 0x10
-                If (((Local0 == Zero) || (Local0 == 0xFFFF)))
-                {

- Return (Zero)
- }
-
- If (((Local1 == Zero) || (Local1 > 0x05F5E100)))
- {
- Return (Zero)
- }
-
- Return (0x0F)
- }
-
- Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
- {
- Memory32Fixed (ReadOnly,

-                    0xFED00000,         // Address Base
-                    0x00000400,         // Address Length
-                    )

- })
- }
- }
-

     Scope (_SB.PCI0)
     {
         Device (ISA)
---
 hw/i386/acpi-build.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
hw/i386/acpi-build.c +6 -2
index bcb1f65c1d..73ec0b6d32 100644
@@ -1405,7 +1405,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         aml_append(sb_scope, dev);
         aml_append(dsdt, sb_scope);
 
-        build_hpet_aml(dsdt);
+        if (misc->has_hpet) {
+            build_hpet_aml(dsdt);
+        }
         build_piix4_isa_bridge(dsdt);
         build_isa_devices_aml(dsdt);
         if (pm->pcihp_bridge_en || pm->pcihp_root_en) {
@@ -1450,7 +1452,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 
         aml_append(dsdt, sb_scope);
 
-        build_hpet_aml(dsdt);
+        if (misc->has_hpet) {
+            build_hpet_aml(dsdt);
+        }
         build_q35_isa_bridge(dsdt);
         build_isa_devices_aml(dsdt);
         build_q35_pci0_int(dsdt);
Signature · 1 line
2.17.1
Reviewed-by on v2 7/9
#21 lore raw

Re: [PATCH v2 7/9] i386: acpi: Don't build HPET ACPI entry if HPET is disabled

Quoted 57 lines · On Mon, 8 Feb 2021 13:57:26 -0800 [email protected] wrote:

From: Sean Christopherson <[email protected]>

Omit HPET AML if the HPET is disabled, QEMU is not emulating it and the guest may get confused by seeing HPET in the ACPI tables without a "physical" device present.

The change of DSDT when -no-hpet is as follows.

(quoted diff) +0 -41
@@ -141,47 +141,6 @@ DefinitionBlock ("", "DSDT", 1, "BOCHS "
         }
     }
 
-    Scope (_SB)
-    {
-        Device (HPET)
-        {
-            Name (_HID, EisaId ("PNP0103") /* HPET System Timer */)  // _HID: Hardware ID
-            Name (_UID, Zero)  // _UID: Unique ID
-            OperationRegion (HPTM, SystemMemory, 0xFED00000, 0x0400)
-            Field (HPTM, DWordAcc, Lock, Preserve)
-            {
-                VEND,   32,
-                PRD,    32
-            }
-
-            Method (_STA, 0, NotSerialized)  // _STA: Status
-            {
-                Local0 = VEND /* \_SB_.HPET.VEND */
-                Local1 = PRD /* \_SB_.HPET.PRD_ */
-                Local0 >>= 0x10
-                If (((Local0 == Zero) || (Local0 == 0xFFFF)))
-                {
-                    Return (Zero)
-                }
-
-                If (((Local1 == Zero) || (Local1 > 0x05F5E100)))
-                {
-                    Return (Zero)
-                }
-
-                Return (0x0F)
-            }
-
-            Name (_CRS, ResourceTemplate ()  // _CRS: Current Resource Settings
-            {
-                Memory32Fixed (ReadOnly,
-                    0xFED00000,         // Address Base
-                    0x00000400,         // Address Length
-                    )
-            })
-        }
-    }
-
     Scope (_SB.PCI0)
     {
         Device (ISA)
Quoted 2 lines
Quoted 30 lines
---
 hw/i386/acpi-build.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
hw/i386/acpi-build.c +6 -2
index bcb1f65c1d..73ec0b6d32 100644
@@ -1405,7 +1405,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         aml_append(sb_scope, dev);
         aml_append(dsdt, sb_scope);
 
-        build_hpet_aml(dsdt);
+        if (misc->has_hpet) {
+            build_hpet_aml(dsdt);
+        }
         build_piix4_isa_bridge(dsdt);
         build_isa_devices_aml(dsdt);
         if (pm->pcihp_bridge_en || pm->pcihp_root_en) {
@@ -1450,7 +1452,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 
         aml_append(dsdt, sb_scope);
 
-        build_hpet_aml(dsdt);
+        if (misc->has_hpet) {
+            build_hpet_aml(dsdt);
+        }
         build_q35_isa_bridge(dsdt);
         build_isa_devices_aml(dsdt);
         build_q35_pci0_int(dsdt);
#22 lore raw

PATCH v2 8/9 acpi: add test case for -no-hpet

In reply to [email protected]

From: Isaku Yamahata <[email protected]>

---
 tests/qtest/bios-tables-test.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tests/qtest/bios-tables-test.c +12 -0
index 096d15db68..72c8765baf 100644
@@ -980,6 +980,17 @@ static void test_acpi_q35_tcg_nosmm(void)
     free_test_data(&data);
 }
 
+static void test_acpi_q35_tcg_nohpet(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".nohpet";
+    test_acpi_one(" -no-hpet", &data);
+    free_test_data(&data);
+}
+
 static void test_acpi_piix4_tcg_numamem(void)
 {
     test_data data;
@@ -1337,6 +1348,7 @@ int main(int argc, char *argv[])
         qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
         qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
         qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm);
+        qtest_add_func("acpi/q35/nohpet", test_acpi_q35_tcg_nohpet);
         qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
         qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
         qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat);
Signature · 1 line
2.17.1
Reviewed-by on v2 8/9
#23 lore raw

Re: [PATCH v2 8/9] acpi: add test case for -no-hpet

Quoted 3 lines · On Mon, 8 Feb 2021 13:57:27 -0800 [email protected] wrote:

From: Isaku Yamahata <[email protected]>

Quoted 34 lines
---
 tests/qtest/bios-tables-test.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tests/qtest/bios-tables-test.c +12 -0
index 096d15db68..72c8765baf 100644
@@ -980,6 +980,17 @@ static void test_acpi_q35_tcg_nosmm(void)
     free_test_data(&data);
 }
 
+static void test_acpi_q35_tcg_nohpet(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".nohpet";
+    test_acpi_one(" -no-hpet", &data);
+    free_test_data(&data);
+}
+
 static void test_acpi_piix4_tcg_numamem(void)
 {
     test_data data;
@@ -1337,6 +1348,7 @@ int main(int argc, char *argv[])
         qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
         qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
         qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm);
+        qtest_add_func("acpi/q35/nohpet", test_acpi_q35_tcg_nohpet);
         qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
         qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
         qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat);
#24 lore raw

PATCH v2 9/9 qtest/acpi/bios-tables-test: update acpi tables

In reply to [email protected]

From: Isaku Yamahata <[email protected]>

update golden master acpi tables and empty
bios-tables-test-allowed-diff.h.

---
 tests/data/acpi/q35/DSDT                    | Bin 7801 -> 8083 bytes
 tests/data/acpi/q35/DSDT.acpihmat           | Bin 9126 -> 9408 bytes
 tests/data/acpi/q35/DSDT.bridge             | Bin 7819 -> 8101 bytes
 tests/data/acpi/q35/DSDT.cphp               | Bin 8265 -> 8547 bytes
 tests/data/acpi/q35/DSDT.dimmpxm            | Bin 9455 -> 9737 bytes
 tests/data/acpi/q35/DSDT.ipmibt             | Bin 7876 -> 8158 bytes
 tests/data/acpi/q35/DSDT.memhp              | Bin 9160 -> 9442 bytes
 tests/data/acpi/q35/DSDT.mmio64             | Bin 8932 -> 9214 bytes
 tests/data/acpi/q35/DSDT.nohpet             | Bin 0 -> 7941 bytes
 tests/data/acpi/q35/DSDT.nosmm              | Bin 0 -> 8083 bytes
 tests/data/acpi/q35/DSDT.numamem            | Bin 7807 -> 8089 bytes
 tests/data/acpi/q35/DSDT.tis                | Bin 8407 -> 8689 bytes
 tests/data/acpi/q35/FACP.nosmm              | Bin 0 -> 244 bytes
 tests/qtest/bios-tables-test-allowed-diff.h |  13 -------------
 14 files changed, 13 deletions(-)
tests/data/acpi/q35/DSDT binary +0 -0
index d25cd7072932886d6967f4023faac1e1fa6e836c..00c60fca65ec37200fc0a17db2d6eb895a1553d2 100644
GIT binary patch
tests/data/acpi/q35/DSDT.acpihmat binary +0 -0
index 722e06af83abcde203a2b96a8ec81fd3bab9fc98..47547fa043d102578f6613cb7f19009a1ee5a868 100644
GIT binary patch
tests/data/acpi/q35/DSDT.bridge binary +0 -0
index 06bac139d668ddfc7914e258b471a303c9dbd192..ab0d94da7d3dce23d18d5868760f5fd5ac6f7958 100644
GIT binary patch
tests/data/acpi/q35/DSDT.cphp binary +0 -0
index 2b933ac482e6883efccbd7d6c96089602f2c0b4d..19f75894abfc33762dc4e2b973f17bb9e989e82e 100644
GIT binary patch
tests/data/acpi/q35/DSDT.dimmpxm binary +0 -0
index bd8f8305b028ef20f9b6d1a0c69ac428d027e3d1..d7344a4e1328318510fe26508a608a985b5d44eb 100644
GIT binary patch
tests/data/acpi/q35/DSDT.ipmibt binary +0 -0
index a8f868e23c25688ab1c0371016c071f23e9d732f..57c32c31a3fd40f5df01f743f062a5dcaa9b8231 100644
GIT binary patch
tests/data/acpi/q35/DSDT.memhp binary +0 -0
index 9a802e4c67022386442976d5cb997ea3fc57b58f..ae63519a139cf287cd6a1484c8298d17ee8c70dd 100644
GIT binary patch
tests/data/acpi/q35/DSDT.mmio64 binary +0 -0
index 948c2dc7264c31932b490ca00691a7c4d9aefdb0..689ff7d5a75bb3a1f98b81e6c0e5748528e3720e 100644
GIT binary patch
tests/data/acpi/q35/DSDT.nohpet binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..73a7826f92a3ac99855c1d1ff1e9d72104e13e3a 100644
GIT binary patch
tests/data/acpi/q35/DSDT.nosmm binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..00c60fca65ec37200fc0a17db2d6eb895a1553d2 100644
GIT binary patch
tests/data/acpi/q35/DSDT.numamem binary +0 -0
index 44ec1b0af400da6d298284aa959aa38add7e6dd5..d1f45e46a95a98f720a5d8774c3e7a4cedb6adc5 100644
GIT binary patch
tests/data/acpi/q35/DSDT.tis binary +0 -0
index 30da3ec27958881801dacc954a343321ba26a2ae..eb66aff05a8a88aab07eda12a18e4bb4e3f11e5f 100644
GIT binary patch
tests/data/acpi/q35/FACP.nosmm binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..891450367cbd1aca397d296831ebeb5cc0788f0f 100644
GIT binary patch
tests/qtest/bios-tables-test-allowed-diff.h +0 -13
index b79ac495c2..dfb8523c8b 100644
@@ -1,14 +1 @@
 /* List of comma-separated changed AML files to ignore */
-"tests/data/acpi/q35/DSDT",
-"tests/data/acpi/q35/DSDT.tis",
-"tests/data/acpi/q35/DSDT.bridge",
-"tests/data/acpi/q35/DSDT.ipmibt",
-"tests/data/acpi/q35/DSDT.cphp",
-"tests/data/acpi/q35/DSDT.memhp",
-"tests/data/acpi/q35/DSDT.numamem",
-"tests/data/acpi/q35/DSDT.dimmpxm",
-"tests/data/acpi/q35/DSDT.acpihmat",
-"tests/data/acpi/q35/DSDT.mmio64",
-"tests/data/acpi/q35/DSDT.nosmm",
-"tests/data/acpi/q35/FACP.nosmm",
-"tests/data/acpi/q35/DSDT.nohpet",
Signature · 1 line
2.17.1