From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web12.10908.1647132088165160377 for ; Sat, 12 Mar 2022 16:41:50 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Wwi0+YRD; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647132109; x=1678668109; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u0EPjnh6vOg1x0zQdZAcNknmlyheFEon+T4cd7TBzjw=; b=Wwi0+YRDQpMDt8GJ3LcJxJYI3iFeLpkr3Q8Q2cp6nyX52yA/y6zaZ7te iPvlo+OdzAMZ3xaJ4jzt8paw+8l8XaFspxIZKASMr8Pxf8khB/tXacOsO Z/jsTxSmZZHyfVc+gM82eVnOdb/PZ2cULlFR3pjaaVUR4BdH4RIMvorHZ oz6PFk12Dad+qeFplGfx8yARqBNquUKm7YmJE0KLIqQV3V6r896Z/Z4dk S6c5t3ZleFE5fpVhGoHX5H0uo649UvNrGYuSn5oM2Tj6ZqEdwYwLRY4LL zxZcsIPaZWlPy+377OCvojOkF6dlJgQqmyWWpLbm7VU76UmS75UlAAUQm Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10284"; a="319056949" X-IronPort-AV: E=Sophos;i="5.90,177,1643702400"; d="scan'208";a="319056949" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2022 16:41:49 -0800 X-IronPort-AV: E=Sophos;i="5.90,177,1643702400"; d="scan'208";a="539479383" Received: from xshi3x-mobl.ccr.corp.intel.com (HELO mxu9-mobl1.ccr.corp.intel.com) ([10.249.171.182]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2022 16:41:47 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Michael D Kinney , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [PATCH V5 08/10] OvmfPkg/IncompatiblePciDeviceSupportDxe: Ignore OptionRom in Td guest Date: Sun, 13 Mar 2022 08:41:09 +0800 Message-Id: <20220313004111.388-9-min.m.xu@intel.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20220313004111.388-1-min.m.xu@intel.com> References: <20220313004111.388-1-min.m.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Host VMM may inject OptionRom which is untrusted in Td guest. So PCI OptionRom needs to be ignored if it is Td guest. According to "Table 20. ACPI 2.0 & 3.0 QWORD Address Space Descriptor Usage" PI spec 1.7, type-specific flags can be set to 0 when Address Translation Offset == 6 to skip device option ROM. Cc: Michael D Kinney Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Min Xu --- .../IncompatiblePciDeviceSupport.c | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.c b/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.c index f5c03bdf6dd6..2d385d26ef28 100644 --- a/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.c +++ b/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.c @@ -71,6 +71,40 @@ STATIC CONST EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR mMmio64Configuration = { // use probed BAR size }; +// +// mOptionRomConfiguration is present only in Td guest. +// Host VMM can inject option ROM which is untrusted in Td guest, +// so PCI option ROM needs to be ignored. +// According to "Table 20. ACPI 2.0 & 3.0 QWORD Address Space Descriptor Usage" +// PI spec 1.7, type-specific flags can be set to 0 when +// Address Translation Offset == 6 to skip device option ROM. +// +STATIC CONST EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR mOptionRomConfiguration = { + ACPI_ADDRESS_SPACE_DESCRIPTOR, // Desc + (UINT16)( // Len + sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - + OFFSET_OF ( + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR, + ResType + ) + ), + ACPI_ADDRESS_SPACE_TYPE_MEM, // ResType + 0, // GenFlag + 0, // Disable option roms SpecificFlag + 64, // AddrSpaceGranularity: + // aperture selection hint + // for BAR allocation + MAX_UINT64, // AddrRangeMin + MAX_UINT64, // AddrRangeMax: + // no special alignment + // for affected BARs + 6, // AddrTranslationOffset: + // hint covers all + // eligible BARs + 0 // AddrLen: + // use probed BAR size +}; + STATIC CONST EFI_ACPI_END_TAG_DESCRIPTOR mEndDesc = { ACPI_END_TAG_DESCRIPTOR, // Desc 0 // Checksum: to be ignored @@ -227,6 +261,13 @@ CheckDevice ( // Length = sizeof mMmio64Configuration + sizeof mEndDesc; + // + // In Td guest OptionRom is not allowed. + // + if (TdIsEnabled ()) { + Length += sizeof mOptionRomConfiguration; + } + *Configuration = AllocateZeroPool (Length); if (*Configuration == NULL) { @@ -245,6 +286,11 @@ CheckDevice ( CopyMem (Ptr, &mMmio64Configuration, sizeof mMmio64Configuration); Length = sizeof mMmio64Configuration; + if (TdIsEnabled ()) { + CopyMem (Ptr + Length, &mOptionRomConfiguration, sizeof mOptionRomConfiguration); + Length += sizeof mOptionRomConfiguration; + } + CopyMem (Ptr + Length, &mEndDesc, sizeof mEndDesc); return EFI_SUCCESS; -- 2.29.2.windows.2