audk/OvmfPkg/AcpiPlatformDxe
Laszlo Ersek 9e2a8e9289 OvmfPkg/AcpiPlatformDxe: short-circuit the transfer of an empty S3_CONTEXT
In commit 8057622527 ("OvmfPkg/AcpiPlatformDxe: save fw_cfg boot script
with QemuFwCfgS3Lib", 2017-02-23), we replaced the explicit S3 boot script
manipulation in TransferS3ContextToBootScript() with a call to
QemuFwCfgS3CallWhenBootScriptReady(). (Passing AppendFwCfgBootScript() as
callback.)

QemuFwCfgS3CallWhenBootScriptReady() checks for fw_cfg DMA up-front, and
bails with RETURN_NOT_FOUND if fw_cfg DMA is missing.

(This is justified as the goal of QemuFwCfgS3Lib is to "enable[] driver
modules [...] to produce fw_cfg DMA operations that are to be replayed at
S3 resume time".)

In turn, if QemuFwCfgS3CallWhenBootScriptReady() fails, then
OvmfPkg/AcpiPlatformDxe rolls back any earlier linker/loader script
processing, and falls back to the built-in ACPI tables.

(This is also justified because failure to save WRITE_POINTER commands for
replaying at S3 resume implies failure to process the linker/loader script
comprehensively.)

Calling QemuFwCfgS3CallWhenBootScriptReady() from
TransferS3ContextToBootScript() *unconditionally* is wrong however. For
the case when the linker/loader script contains no WRITE_POINTER commands,
the call perpetuated an earlier side effect, and introduced another one:

(1) On machine types that provide fw_cfg DMA (i.e., 2.5+),
    QemuFwCfgS3CallWhenBootScriptReady() would succeed, and allocate
    workspace for the boot script opcodes in reserved memory. However, no
    opcodes would actually be produced in the AppendFwCfgBootScript()
    callback, due to lack of any WRITE_POINTER commands.

    This waste of reserved memory had been introduced in earlier commit
    df73df138d ("OvmfPkg/AcpiPlatformDxe: replay
    QEMU_LOADER_WRITE_POINTER commands at S3", 2017-02-09).

(2) On machine types that lack fw_cfg DMA (i.e., 2.4 and earlier),
    TransferS3ContextToBootScript() would now fail the linker/loader
    script for no reason.

    (Note that QEMU itself prevents adding devices that depend on
    WRITE_POINTER if the machine type lacks fw_cfg DMA:

    $ qemu-system-x86_64 -M pc-q35-2.4 -device vmgenid

    qemu-system-x86_64: -device vmgenid: vmgenid requires DMA write
    support in fw_cfg, which this machine type does not provide)

Short-circuit an empty S3_CONTEXT in TransferS3ContextToBootScript() by
dropping S3_CONTEXT on the floor. This is compatible with the current
contract of the function as it constitutes a transfer of ownership.

Regression (2) was found and reported by Dhiru Kholia as an OSX guest boot
failure on the "pc-q35-2.4" machine type:

http://mid.mail-archive.com/CANO7a6x6EaWNZ8y=MvLU=w_LjRLXserO3NmsgHvaYE0aUCCWzg@mail.gmail.com

Dhiru bisected the issue to commit 8057622527.

Cc: Dhiru Kholia <dhiru.kholia@gmail.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Fixes: df73df138d
Fixes: 8057622527
Reported-by: Dhiru Kholia <dhiru.kholia@gmail.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Dhiru Kholia <dhiru.kholia@gmail.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2017-08-08 15:10:45 +02:00
..
AcpiPlatform.c OvmfPkg: AcpiPlatformDxe: extract common entry point 2015-02-19 23:45:57 +00:00
AcpiPlatform.h OvmfPkg/AcpiPlatformDxe: save fw_cfg boot script with QemuFwCfgS3Lib 2017-03-14 21:49:38 +01:00
AcpiPlatformDxe.inf OvmfPkg/AcpiPlatformDxe: save fw_cfg boot script with QemuFwCfgS3Lib 2017-03-14 21:49:38 +01:00
BootScript.c OvmfPkg/AcpiPlatformDxe: short-circuit the transfer of an empty S3_CONTEXT 2017-08-08 15:10:45 +02:00
EntryPoint.c OvmfPkg: AcpiPlatformDxe: when PCI is enabled, wait for Platform BDS's cue 2016-03-23 17:39:35 +01:00
PciDecoding.c OvmfPkg: AcpiPlatformDxe: Don't enable unsupported PCI attributes 2016-04-19 13:18:34 +02:00
Qemu.c OvmfPkg/AcpiPlatformDxe: Split QEMU fw-cfg into a new file 2015-02-02 19:08:57 +00:00
QemuFwCfgAcpi.c OvmfPkg/AcpiPlatformDxe: fix spurious uninitialized var warning 2017-06-09 08:57:39 +00:00
QemuFwCfgAcpiPlatform.c OvmfPkg: AcpiPlatformDxe: extract common entry point 2015-02-19 23:45:57 +00:00
QemuFwCfgAcpiPlatformDxe.inf OvmfPkg/AcpiPlatformDxe: save fw_cfg boot script with QemuFwCfgS3Lib 2017-03-14 21:49:38 +01:00
QemuLoader.h OvmfPkg/AcpiPlatformDxe: add QEMU_LOADER_WRITE_POINTER definitions 2017-02-21 13:10:33 +01:00
Xen.c OvmfPkg/AcpiPlatformDxe: Fix Visual Studio build issues 2012-08-09 23:27:05 +00:00