From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.86]) by mx.groups.io with SMTP id smtpd.web12.125.1634144284823218618 for ; Wed, 13 Oct 2021 09:58:05 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=SvB1iK6u; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.220.86, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B2lIjp2wGrDRktbmiK9iTXXjNSmfI/mdyqRtQn4qpTV+Ayzn1HzN+4UFDByuTzNvO6K9JLcxkR/1S9LRtJ+OjVl0cF+hyWzouSrNC4+Glkof2GKJLBcEgMg3sLs9Dup6A7tJWM1x6HD4pkJj2WjY5QNVPuYHQvXSQNama5Dq2msJpLnlZtWgqEZV2FpnkpOL6N50CmIUiny4cRWBuDugUSqxxj/nduRJdUZ+uxFiLcFvjtw4nV3ZANc43aKJQWxPf8QQxk/SJ7CBxjLeS1PlMfre0X9RL+0NYhZy1OZzEY4US7PBU1OmqE97wM1HUrmHyTgvZA4/N9bapxEbzL+9QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ssbYYDRnBzgPINFTwLfD1QN9nBJ41Imrw0w8gRmkrZE=; b=mpdQ09sCZcbVEF+6u6JI8M+2vRFBeIAHFxvZJHnw6OxzR35SgPac/3IHYhEyplJtBUlRNHDRtDRuR9MwedB5+F40qq4Ao/vedf0cYB8Bueq6D43IxF3AUwTMZbJRgEg1us1SIb2orvfFuRZvzJ8TOuvl5EwPCf9bzHzY5rVobIrZKMqF+IyBwNkMy9fM05bpuh7Gm29nLNC15xoucKhRH2CvxfHdUMeecXfeB4CnZ24qhfr/Mi1yezjZLAAcW21NN0+oSG2r9EMfpGB2DUOz9SNWp68CTTBCi1a6pbFtQpMcBtWWXQpl6iVTRPNngUuySPeI5FaSMUiiWCfpy/gH4w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ssbYYDRnBzgPINFTwLfD1QN9nBJ41Imrw0w8gRmkrZE=; b=SvB1iK6uOa6DwkJ10FwUfXjFAv0t86kbSmMo/9e0DQ/zeHtn2KjH7zkufEBgDa6i/fc60wo3fbyZ9VcDa13bXYCj9teayie4Al5aiog5vIw69hMWZnmy1/08ynGQ/SBrmiMXm97N0pRSBVpMahPU+/JjSQCxcqvVdJpKHSnsTGQ= Received: from MWHPR11CA0011.namprd11.prod.outlook.com (2603:10b6:301:1::21) by BN6PR12MB1858.namprd12.prod.outlook.com (2603:10b6:404:fe::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Wed, 13 Oct 2021 16:58:01 +0000 Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::93) by MWHPR11CA0011.outlook.office365.com (2603:10b6:301:1::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:58:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT060.mail.protection.outlook.com (10.13.175.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:58:01 +0000 Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:59 -0500 From: "Brijesh Singh" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [PATCH v9 29/32] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Wed, 13 Oct 2021 11:57:10 -0500 Message-ID: <20211013165713.727815-30-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cc15ee2a-9af9-4be8-6f83-08d98e6a9dac X-MS-TrafficTypeDiagnostic: BN6PR12MB1858: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wCvfZE/I7dAQnly+PhoDGVrgVi5Jt5RIeMsJCDY1QQcQjbqG/wIH3GmI8f2a+xrW/FingypZcBuiloihsF2K950QEoTVlSst2xS811xJvex6f98bdCbKm+mt/sGtor15t4OK/VtHmEr9JmaQz8PWJ3Z1vlyhOH4bBtk0QDZC2gL1fxI45COeVvqe2m0AMNASNhtzNneYrT4uMQpdq1YJA9u4pjTEtut9JCp5rfjxrThFNyE/Xw9dp8i2ZPlvm2nmox1HbO5hwgPMeRDUyoS8WzUbqwSxxFqAUKEVrSLiabQ3kxxdwkbp6A0TMVX7RE8+DImGHpZjEl8NgbkU2cicJq74RNXTV29wQ2kuNcSl9cNsyBCwJLnyb+k7rldA5gB13c2EEtDBsw1hR2lfbRgNqhnTYsIZq6VDhIZEeJ1DX8t6plDX7aePjALmOefDd/K46D1/UXYH5nQ0oIWg0UfNDMLXEMwPoctVRWNpzW5LjRN8Mb9gNQdBS3hGkdbb3ZmOZwK6Q2/MIr1a/JHU6tHOUQokhcWucAw8fWs0Pt2wgCrDG8N55bksgUKyfK4WDWXLjnC8qEuZ/XghSWNOggjybKAxfNrRGJSYYtIcQLYVLtSARcnYkNLBgRyNIelA/fWi7QJUORieC21U8CBrE3NEUFUgNSnYELlo81R0/vLCe0vm/8nAwmNzKX8viCY/o1AxjFwGRaqtHpdREXR/9O9Tufgd/Qm9WEdO0uTbemPo5Oc= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(47076005)(70586007)(44832011)(70206006)(4326008)(6916009)(16526019)(8936002)(83380400001)(5660300002)(81166007)(2906002)(508600001)(2616005)(1076003)(54906003)(426003)(7696005)(6666004)(186003)(36756003)(82310400003)(336012)(86362001)(316002)(356005)(26005)(19627235002)(8676002)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:58:01.1154 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc15ee2a-9af9-4be8-6f83-08d98e6a9dac X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1858 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain The SetMemoryEncDec() is used by the higher level routines to set or clear the page encryption mask for system RAM and Mmio address. When SEV-SNP is active, in addition to set/clear page mask it also updates the RMP table. The RMP table updates are required for the system RAM address and not the Mmio address. Add a new parameter in SetMemoryEncDec() to tell whether the specified address is Mmio. If its Mmio then skip the page state change in the RMP table. Cc: Michael Roth Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Acked-by: Jiewen Yao Signed-off-by: Brijesh Singh --- .../X64/PeiDxeVirtualMemory.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index 56db1e4b6ecf..0bb86d768017 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -673,6 +673,7 @@ InternalMemEncryptSevCreateIdentityMap1G ( @param[in] Mode Set or Clear mode @param[in] CacheFlush Flush the caches before applying the encryption mask + @param[in] Mmio The physical address specified is Mm= io =20 @retval RETURN_SUCCESS The attributes were cleared for the memory region. @@ -688,7 +689,8 @@ SetMemoryEncDec ( IN PHYSICAL_ADDRESS PhysicalAddress, IN UINTN Length, IN MAP_RANGE_MODE Mode, - IN BOOLEAN CacheFlush + IN BOOLEAN CacheFlush, + IN BOOLEAN Mmio ) { PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; @@ -711,14 +713,15 @@ SetMemoryEncDec ( =20 DEBUG (( DEBUG_VERBOSE, - "%a:%a: Cr3Base=3D0x%Lx Physical=3D0x%Lx Length=3D0x%Lx Mode=3D%a Cach= eFlush=3D%u\n", + "%a:%a: Cr3Base=3D0x%Lx Physical=3D0x%Lx Length=3D0x%Lx Mode=3D%a Cach= eFlush=3D%u Mmio=3D%u\n", gEfiCallerBaseName, __FUNCTION__, Cr3BaseAddress, PhysicalAddress, (UINT64)Length, (Mode =3D=3D SetCBit) ? "Encrypt" : "Decrypt", - (UINT32)CacheFlush + (UINT32)CacheFlush, + (UINT32)Mmio )); =20 // @@ -760,7 +763,7 @@ SetMemoryEncDec ( // // The InternalSetPageState() is used for setting the page state in the = RMP table. // - if ((Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { + if (!Mmio && (Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { InternalSetPageState (PhysicalAddress, EFI_SIZE_TO_PAGES (Length), Sev= SnpPageShared, FALSE); } =20 @@ -998,7 +1001,8 @@ InternalMemEncryptSevSetMemoryDecrypted ( PhysicalAddress, Length, ClearCBit, - TRUE + TRUE, + FALSE ); } =20 @@ -1031,7 +1035,8 @@ InternalMemEncryptSevSetMemoryEncrypted ( PhysicalAddress, Length, SetCBit, - TRUE + TRUE, + FALSE ); } =20 @@ -1064,6 +1069,7 @@ InternalMemEncryptSevClearMmioPageEncMask ( PhysicalAddress, Length, ClearCBit, - FALSE + FALSE, + TRUE ); } --=20 2.25.1