From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.47]) by mx.groups.io with SMTP id smtpd.web08.1335.1632163606435968284 for ; Mon, 20 Sep 2021 11:46:48 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=IPGpe7il; 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.92.47, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kfn6kvE9ZxOvB7sxdATNMA0OLSFaMZPHhNdqGEIGupSMXMEq+o4x5PIqYcKtI6rcVPov2MrpoXwCro+GHBANfdLW0fVeO7THb+/LD5Zrb3LrwhOfN8+KOqjlKSho4mjkWzkKQ7cIUia21JKkkQx0SMUB1ZcYl1hFoTl4o5hxhzopD159tZnpAh0mFSiV2CBCw5m5piA7oILNJb2iV5Ujq60o3vqeYicBphqet8UfuZg2wzbFbwgEmiL7UuvhOANUqxAr9++wZXNivZb0czDvVSU2xRQNbZXp4mKLhrOlsB+BEsCSfmsrN7KzcTm5Nyg3r4wX3qEymOQBNWY315yLlQ== 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; bh=ssbYYDRnBzgPINFTwLfD1QN9nBJ41Imrw0w8gRmkrZE=; b=iby4pAzeFfyq6aF8ENREK4o6ftiBrK4zHAmwoqRyXf/mKuy2B5vF44yA0zqHq+V3nJ443DWC8PxOGecRqM8tuFazuuJU3U2a7SSuiYsIdovhMk+KFfYsrLgID3lY7W7T2Ojmxitv12HOmCtg9D3C4QUXFVywQSPA++2ttu6hmuQHVRemFGUlfPnaOZr/FjsNl1BOCYZ2rhMup2pvKr/vAkbXS+CRTYD9i01qD+1bUeK2T5fxNABF+2FgqbRi9bNBj11dUWFxXnwfgS4+MXd/Pc00rjSm2S+ljtcShQhFCmJboKBVmZJLI2i0PKZw5skcgDOcVrzVvcCWNrrTDFhhZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=IPGpe7ilsQImBGX2uTQ9/8vqCrFFlCqcIL5LXx0D4iHTeWxS5HogVMr7xHLuNw3yOflOkTCdS3prTMmXxZ7OHyg21ed/hwA5quwDS1o8exwJgWC6HrcQMHhTE7Gugmxw3ale8FUvMbrtBBwdJWbbuLD6AXEoIZ1/Wa9q0w5LAKY= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4575.namprd12.prod.outlook.com (2603:10b6:806:73::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Mon, 20 Sep 2021 18:46:44 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4523.018; Mon, 20 Sep 2021 18:46:44 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io 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 v8 29/32] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Mon, 20 Sep 2021 13:46:01 -0500 Message-ID: <20210920184604.31590-30-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210920184604.31590-1-brijesh.singh@amd.com> References: <20210920184604.31590-1-brijesh.singh@amd.com> X-ClientProxiedBy: SN4PR0201CA0034.namprd02.prod.outlook.com (2603:10b6:803:2e::20) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN4PR0201CA0034.namprd02.prod.outlook.com (2603:10b6:803:2e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Mon, 20 Sep 2021 18:46:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8bd60a73-4761-4272-78d9-08d97c66fe12 X-MS-TrafficTypeDiagnostic: SA0PR12MB4575: X-MS-Exchange-Transport-Forked: True 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: /7p4CZru28Ps0NQyanqlOaObgNmIXnjGzar0aoQ3TTVsYzYATcla2tDMPdAHRfPpwxDFYukHLHcMfOPny0cBjoUMYRac09AJwPnQJlqEVGG3D60N2fK+a/KSSALqnUOl99k6AxPae9MDLeuo5qznaNctp6tw2L33bsD9AippO5wt5x6Rer/WcqJ+0sO3aVRNdIifMNyj1SBA751mepWiPn1RM/bVSJU2Z/Rz3O1WHQPzxamKi9ga19KLogiLO19+XWxUeVQNSpa9d+MKyB6X7r1WBWTpX2tzVfBnSabc2eZFhSSellwTrTcZOspRRrJzQm26iY9F6yVJAGOxbddJsaVqJk9XHAlr79GDM7c7S9Z7WNdSjb4MRvTgUiOLhohnmJBmkoNBQhtk1bjF2/1jI5k9OoGU60pwkjzvmmhaiiEpsbglmU//IIzE1+v8/hhEh/gPouTxaVsbx8ZD4PkpPJ46secbjcQvND9XBz8Ctbg/n8ExlzmSv/jGGGed9PmGAz6GRYezq7lIHihVVEYOadsXjvDUMJXf0rQT8h5W/2cWftyQjUBIQ/ojt0eA2eFwOEdDjr/jgJ9NXoj9kU3nOoNJ12OOKwDGoFAQPMYG+gI50WGVURSCQtuMqYq8V3vZPrfxYvh0IWIHeq/7Oskh7nNxSXa4L+uGPC/QLH0yuUySfFhxjW6kX4S7WfEdbtjrZXYLCaCa9l6X4ER6wGplVA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(38350700002)(44832011)(5660300002)(36756003)(83380400001)(38100700002)(8936002)(66946007)(508600001)(6916009)(7696005)(52116002)(1076003)(6666004)(956004)(8676002)(186003)(54906003)(2616005)(2906002)(6486002)(26005)(19627235002)(316002)(66556008)(66476007)(86362001)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?78oEFeQfS7Us8Cur8LsI2ZNMXSRbUW16m9rvtceFB2nYpmjPgiIPXCH1a0Fz?= =?us-ascii?Q?M+l3utm7Ugcby1jaC+ycn+/KSI9WsBYU/G1TcSly1TZ2fqShT7hxwcyzn3SC?= =?us-ascii?Q?44ePURcFwl0T8iiIduyw+fcAMa+KVevq8dOw+upLn3Pbic7FkZbl+FTxZbAA?= =?us-ascii?Q?vdhSPFMkHRb1nWQlpHJ1LXsCcmqAGQ1Ci1tTBZY1Xcr+FvFroI9IGZbHSbMA?= =?us-ascii?Q?Kx0wF08EePw5R6k/fHkR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A/gSnZEEP?= =?us-ascii?Q?NiSC2PG28l5riva50pvfiSS93idUnNIhkXWZ7o+AQvoTYSMBeaFFeuaPNZta?= =?us-ascii?Q?+cEAH+vCujT5yVSoMXSW6I9t77YRkAfqHHgSsVAT7WSAZvTKXrgzcgYiPs1u?= =?us-ascii?Q?iW5A9FEnoDSTs8x9dtdODO3MHQhQ8iGnE0y5N4QxYl+RSm9AMP88WanHDyz9?= =?us-ascii?Q?2KrPzziWGXcntx5+bjkgjo7c?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8bd60a73-4761-4272-78d9-08d97c66fe12 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 18:46:44.3556 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Zso/2vEqo5DeO9cdfpC2WXdKATWLyixBT3iUTnS9Mhr1kRLbh+5DZ6vcBoMVYBJYKemAi1g0RssKbDuTLdob+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4575 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