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.89]) by mx.groups.io with SMTP id smtpd.web09.69880.1629381899541307554 for ; Thu, 19 Aug 2021 07:04:59 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=MxG8saq7; 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.89, mailfrom: ashish.kalra@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FScUwsqzdnPcx8smOJ6rYjFkfnipKtMI7CLiIuuNOyDajf4zUR5RvNITaotHhYQFFtScdnX8c4CxH+AcMrk7FWvn/sTCheaLr6hmnYk265d3iVDsd/pcpYn2u42tAeFwg6mS5JQePLG+z1QfPC0+QcgsKR2UI6O4aM+GSsidmy+kS9+9v8wbyMUgLCC3SOnjq6uXDvN+vmHYvPM3NUWmAqYF4AKZErb9GZ6DWNMXkdl+zvb4OGJZZG2PtEq4BKLG5oEZLiQ+1ez0BbhaFD7aBQ79d/1D3/ENsSgRDe7wlGPou2+x8R1J+/E4lzXIFJAGxShGHgdXHWSbM36NVTx/Sg== 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=XfXwNx7cnYeErCXlgzIiyz2FmbL9KGK3WdHx8tgbyoA=; b=Wpuhq3cwS+kHBzTt3TBfZKM//BkcwWtDx1+wkaqaIWQNRJklOZKUVJIXcCcaoTw4h6kTSuDF4g+1Gzq3R+sfDpjrP0lr3MRwEQnaQBH/dktYY/NVGNCne83ENJTuY/CY+P4how8T6a4xC2N/+VlcLmCxuuzIxvj3P2DH8GfbAB6v/a+DRY+CXKo1wypBq5lmpXumekaSKLk9eMbBqqmYtjwYLUcbbT9m0e5VYfB56tBKIlGBAfTLQuIhGioMM+4JQ2DA02FFoBH3UzcqL7QLQ6ryBKijIp6EXTpSvYJoEtNfeVXHB9X4dha8e8nmTDXx9zltujuNaEZWuJnQvblhgw== 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=XfXwNx7cnYeErCXlgzIiyz2FmbL9KGK3WdHx8tgbyoA=; b=MxG8saq7IcK95Tb/cB/e8oI1/K6Bw79kWceDVftf6sibzl4pBhnrRpgFU6m4usC1gLhEyO3kR7gDxTn4xxKdQD54oHJLnHNHZbfm5uhiejR5jtwiZQKlAWon0RjUxEhs/B2GGEhSibYHSj/wJY9lvtP9C5sBHxZSjpGaqqElhbE= 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 SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB2685.namprd12.prod.outlook.com (2603:10b6:805:67::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.21; Thu, 19 Aug 2021 14:04:57 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::491e:2642:bae2:8b73]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::491e:2642:bae2:8b73%7]) with mapi id 15.20.4415.024; Thu, 19 Aug 2021 14:04:57 +0000 From: "Ashish Kalra" To: devel@edk2.groups.io Cc: dovmurik@linux.vnet.ibm.com, brijesh.singh@amd.com, tobin@ibm.com, Thomas.Lendacky@amd.com, jejb@linux.ibm.com, erdemaktas@google.com, jiewen.yao@intel.com, min.m.xu@intel.com, jordan.l.justen@intel.com, ard.biesheuvel@arm.com Subject: [PATCH v7 3/6] OvmfPkg/BaseMemEncryptLib: Invoke page encryption state change hypercall Date: Thu, 19 Aug 2021 14:04:46 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR01CA0018.prod.exchangelabs.com (2603:10b6:805:b6::31) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) Return-Path: Ashish.Kalra@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN6PR01CA0018.prod.exchangelabs.com (2603:10b6:805:b6::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.18 via Frontend Transport; Thu, 19 Aug 2021 14:04:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7705292e-d5b4-4bc5-112b-08d9631a5329 X-MS-TrafficTypeDiagnostic: SN6PR12MB2685: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2887; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J1XQEPXHfZGVma9ZzM8uD1LuQVih9ucNKN49IFEaOlksVEJdi/OvwPuV8M/kRLVVnyKdcM2E00bl5zZTdwJjcTXAgNNWeT3R/j9tgXyMEuCOk/qkFj8AiTisZsITIvSv0BU0wvw3IH4H3mNVHNcbuKLl8AzBye4c8mjk/UnhJxT5ZXm93gTmG8+Xg+BwLtiUBh1zEIDAvErEHRbp5MDhMtsuHC/HdZNGZ43MChWterY5VSdYaa5i3MR2b/VunHDa4somXKIlfIvZPfbD2vljHcCGR+K0+C7haXXcta4OkxBskMQUggwBI0D+R4dzwoA3iTPIX7GGqjZ2xrkEfMHQ4OZmxDuDr+E9JPz9BJ2Xt/DdIyd3Wj/hW4OLwoQ0DEwfw6+OOHRILZSkP24Kdtzmr39sQBLdsZ6gOcckQOUaD4Qik6aRSrsEOdBJH/QfKAG6YBzQCl7GZUlSeBJ1PG40wAFXd4VwXwQ+LznkP+BAWl8tSbpY6IiNZetHssGPaS2SWADjUU0BdplhE5LBx/0I+ogPXvKuAhs3W1nLG4vFokwllRTo1uSOnx208s2LgtsKOfK7vW5GI/oYJNeW93OqRudC3zP4ENrrkqjZwAPi8UtG7DFKAQ1LVlmiEYzYG5wRGUJ0lQjIHU9z0ULAWPn1pbWE172d2sxeFV87d/RAFpTw9I3KPI3c+ipFV0ClCu+gncw/zf0xrIoA9xB8w99yRg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(346002)(136003)(396003)(376002)(38350700002)(38100700002)(6486002)(4326008)(6916009)(478600001)(52116002)(66946007)(7696005)(186003)(66556008)(956004)(19627235002)(2616005)(26005)(8936002)(5660300002)(316002)(36756003)(8676002)(2906002)(86362001)(83380400001)(66476007)(6666004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?3+cyo6wO9RzJoXgzKZHlER6vu0lGs8XlG3vdG1sKbt7a98OnElWm8pAnXfmz?= =?us-ascii?Q?4rHedsFkuE3wMohGSlLcLsbX7aQKtwLcBOlblFH/YfLkXkbfxhGDHfEqCEXf?= =?us-ascii?Q?n5SOV2d8L2LagDDyu9sWbwNrl64kCMKp9mUzx2mMgK6t2a6fpOBDEzku/Twb?= =?us-ascii?Q?qWpM31FcvHvpwlyZtu/ZhaX07n2kw+hj7iK/WamupSAqNGZ6h3cxrvFhnopZ?= =?us-ascii?Q?Ylmv4e/+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cx1bY/x0ViC/YsNe5nzOg50?= =?us-ascii?Q?9+dD1PExZcPCG/ALDK13uttyPrOD7Qd5sMos+xqPuglniO9Qaad3XhYlap+7?= =?us-ascii?Q?luw4GODObLTswvERbxswXoOkuCcYqNRRTs4ntXzA2wiOpfAX47r1+t0LhDen?= =?us-ascii?Q?aPND5k/YVrVgCZlzp3wIMgKb4nLAO21Ha/x+jV2K01mtNW7BkGu3IdNS+UdJ?= =?us-ascii?Q?5mCHfNtBJaxxNO3dH4paQSdu?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7705292e-d5b4-4bc5-112b-08d9631a5329 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2021 14:04:56.9243 (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: TxKOet3xtskd4jF1J4tjSDBTGngRgUQ+LPqytdqt2nYXx1VfNExfJj2OC53gZpPwX7uNvaDGhFncZOuGFpWxEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2685 Content-Type: text/plain From: Ashish Kalra Invoke the hypercall API to notify hypervisor when the page's encryption state changes. Cc: Jordan Justen Cc: Ard Biesheuvel Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index c696745f9d..f562e16fc2 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -585,6 +585,9 @@ SetMemoryEncDec ( UINT64 AddressEncMask; BOOLEAN IsWpEnabled; RETURN_STATUS Status; + UINTN Size; + BOOLEAN CBitChanged; + PHYSICAL_ADDRESS OrigPhysicalAddress; // // Set PageMapLevel4Entry to suppress incorrect compiler/analyzer warnings. @@ -636,6 +639,9 @@ SetMemoryEncDec ( Status = EFI_SUCCESS; + Size = Length; + CBitChanged = FALSE; + OrigPhysicalAddress = PhysicalAddress; while (Length != 0) { // @@ -695,6 +701,7 @@ SetMemoryEncDec ( )); PhysicalAddress += BIT30; Length -= BIT30; + CBitChanged = TRUE; } else { // // We must split the page @@ -749,6 +756,7 @@ SetMemoryEncDec ( SetOrClearCBit (&PageDirectory2MEntry->Uint64, Mode); PhysicalAddress += BIT21; Length -= BIT21; + CBitChanged = TRUE; } else { // // We must split up this page into 4K pages @@ -791,6 +799,7 @@ SetMemoryEncDec ( SetOrClearCBit (&PageTableEntry->Uint64, Mode); PhysicalAddress += EFI_PAGE_SIZE; Length -= EFI_PAGE_SIZE; + CBitChanged = TRUE; } } } @@ -808,6 +817,17 @@ SetMemoryEncDec ( // CpuFlushTlb(); + // + // Notify Hypervisor on C-bit status + // + if (CBitChanged) { + Status = SetMemoryEncDecHypercall3 ( + OrigPhysicalAddress, + EFI_SIZE_TO_PAGES(Size), + (Mode == SetCBit) ? TRUE : FALSE + ); + } + Done: // // Restore page table write protection, if any. -- 2.17.1