From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (NAM02-BN1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web09.45.1622070715669955813 for ; Wed, 26 May 2021 16:11:57 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=J7k+Upbo; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: , mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WSfpOTTb/A585BZYUBcYKdL7C08VM+buJJQPmCGXVsd1Uo+d7bRkjTZDr5EFY1TPHJc8+ktZWrLF7YZULNSUAFnDRORunTHO4Kuxyn0qy2cBm91Vq4r+MIA1/VPcpMlu0EkqpbkxKCkxTNQozEBZ7nc43U5ShWZDie2bRjntkrw+7erOv8Gu3xxpD812+g2LopdUIttHA0GF1JmpUPgdSI0yUpys84jiXXAt9MIIoc2t20AAO9KHhdV1nX7+9GufN8GwLIq+peNVWErn7L4vwlUB13vCed52rKg693dOn2g/mF29dZUtphK5/jVgeh4he40jYkNpRDcobUVg3g4USA== 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-SenderADCheck; bh=feKMnXykpClFn+Z1vy3jA1qLSrIH3miIPsLQ6vxuftw=; b=N32KKwkbn/mwLfRVllgXAGB/UqU2e5UpbH0XEZ/u6kJ1YY3vv8rLPBfRD2iJuUlwUAihghNu/g6rEObsDG7dEUUdzBxS2sxqiwyX2BCdbZ3ARhka3zsqzfELHJqmYZ0ZW1MvIRj3YVDkUt0XIBtugkYcvXjgAEDPT66pDiUM0vfaZXe6cg+kuwFe6NltHNz7esEgY1R8sYdxfVMhtZofHUFGidc+KGJ/3AYSgjWMUePXOKeCEKpwYquBo0hog/hqkRuoPPxTsQXDDquT3L4hpQZZbmSXv/CkwzBabJltYPaLoc1JTkFHHpitjKm7YP+wwGdHborEB3cC78ty0OhDYw== 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=feKMnXykpClFn+Z1vy3jA1qLSrIH3miIPsLQ6vxuftw=; b=J7k+Upbo2DXUAY1OStSqrFH799fCUOBbRtBtiJoz42bTzF2hK55GG+fWyRd0HDYjI3yhmh2/x6gAo5N0SMdf3r5md1AeYDMW1Yv4MEGJ5PbFiM4D6tu8RITUjMOd2tOsAogqdrhsEfADXcgg0z3m/9LqSTjT4/5Me/kkjWM4dHI= Authentication-Results: linux.ibm.com; dkim=none (message not signed) header.d=none;linux.ibm.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN6PR12MB2782.namprd12.prod.outlook.com (2603:10b6:805:73::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.28; Wed, 26 May 2021 23:11:53 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94%6]) with mapi id 15.20.4150.023; Wed, 26 May 2021 23:11:53 +0000 From: "Brijesh Singh" To: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Laszlo Ersek , Erdem Aktas , Eric Dong , Ray Ni , Rahul Kumar , devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel Subject: [PATCH RFC v3 19/22] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Wed, 26 May 2021 18:11:15 -0500 Message-ID: <20210526231118.12946-20-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210526231118.12946-1-brijesh.singh@amd.com> References: <20210526231118.12946-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0202.namprd11.prod.outlook.com (2603:10b6:806:1bc::27) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SA0PR11CA0202.namprd11.prod.outlook.com (2603:10b6:806:1bc::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21 via Frontend Transport; Wed, 26 May 2021 23:11:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3c56579d-22c9-4d39-4d1b-08d9209ba684 X-MS-TrafficTypeDiagnostic: SN6PR12MB2782: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yN+Z+retd6ZB85D/Ql5PTdCGS2V+k4rjKqq3Hu7Ua8MiqnI+eaDbrBSAGvDBBr0an06Ee3M+5IHkcS/bMv9MonnawfEkDEXsJ8DLHrq56Ef0doB8dXTeGKzwDCDJ45pUTAuIyijgFC5hk8j8ProxFN7rnOUPPZIK/eeP7qXqnRM+pMAd4cypuGn/PRsbZuu53u5jVBntv5x7NOiAV4ilHaszZoRMgzV3ao6mNcfYgClzUvkEUvRSjAQX7CilZGSUcB+WHnESnU6ZBAv0Cnq1N34KP+v1B4fX7VnvIDGEnq2DOUm/QyaBcSDwfg9vXXtAuHJMONqhc+UE3uFgN7LElbiPuPpLCGs0fnIK03Yz03C/sWIn8fqJWKQL88NsGCOTH5q2ZhAqx13L2fLn8NA11JlvBzkgn1ti6WtO8Fk+n1z9Ar/lctpGMys8khN4Sg3xse5GQSEk6zyYnoUftfVA63UB/pv1SfQNfAitZb5W/zM826UQbuilWxMpwdAmoX07NcqrFSwDsVXxll8KWuYj+AmEX9XszKYBIjfpBvdbEafjJ9y9L2lcl0EG3IVnXJcvtQIsjd1ND/6APsOU7HRZzkQL+4Of02z9EvzPK/rgjq9gbGzbzagJyzkZlUVjxuPYIUSwqaRcMKTO4FfPOuGp14459R/pSz29HMJUpbz3CIw= 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)(39860400002)(346002)(396003)(376002)(136003)(26005)(316002)(5660300002)(8676002)(83380400001)(186003)(38350700002)(16526019)(478600001)(54906003)(36756003)(4326008)(86362001)(6666004)(7416002)(2616005)(110136005)(44832011)(2906002)(52116002)(66476007)(66556008)(7696005)(921005)(19627235002)(6486002)(8936002)(38100700002)(66946007)(1076003)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?j8B54/MBO6qxEfdzrg2r+Gtn04OFqaN/3ZrkNZaQbaJqxNfgtayUuBEKnnZe?= =?us-ascii?Q?lDpDhexCpqq8hccCQGiAeNSjyDyXZz5zESupHteLoYRcRexmYAGLxl2zMS/5?= =?us-ascii?Q?ldDZhEiYHrDQdNjKKC5xgIelRYHykcaDVVRWGNLv+GpZJ53PAGlKCP0M64l2?= =?us-ascii?Q?8mQJkqmb6dPvqtXO7JxKat0DfWI5+XSnjL0r/hIJtuR9seBfOsBr6k7PeNBS?= =?us-ascii?Q?UBD1W+knsGTpa2TNfJkHu5iGOPJnTHdTw9K5yjxoESKTr11vlNEr9LP9cvMQ?= =?us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33GO6E7PqFhE?= =?us-ascii?Q?wP/S80sP/ff2BHnQS2j3CkOeSDGGEeKBMWf4dTA6cVz7Qcl3MoCSp5IR9Q0m?= =?us-ascii?Q?BsjzG2wwAd6/JGmAIKuwl4WR9licO7AXwD7ITyRfxG9jp1fc+FoVwPYngp3e?= =?us-ascii?Q?JkDb8BXvFlhW5I9RdrPPwvgM?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3c56579d-22c9-4d39-4d1b-08d9209ba684 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2021 23:11:53.6623 (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: rY50z9mjR7tbpk1eLnmcwYGgn+Q0YdbdY+po5CFoXi4QW8z5mTh9uppvUEDZKuMUETB6GpQgp6jFxyMnrYPdBA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2782 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: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Erdem Aktas 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.17.1