From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.66]) by mx.groups.io with SMTP id smtpd.web10.6611.1607040234513862741 for ; Thu, 03 Dec 2020 16:03:54 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=eZlvZRFY; 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.70.66, mailfrom: ashish.kalra@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cvr2ZxjOM/Z5dJhwR55FkvLUXy7Dp/K62R/+BsAmXgKQICffMeYn11sBc7u/k6cB6EcrxKkUJT+FjXhmvRroXKPGjSFqpVIKqoezQrV91b0K47ijhzisz0HD+pLT3zkwCL9sLjqKAy0J1/nZhtxSGwrheyjWwLLdal3blFXaHcsZHZxRCKAB369jgTkm3uTszaQ3xF8QHO9ALxEohETYUcuCCAQcExrCh1tvvneiOKfTRDaEJaBRMz3JBYqJdjP+wmg/GzMLHUH+Bs3/JbZ2IrR/gFpdev0m2iZyTMBlRKq1u2JMeJPF07DxVB81DW0OOpwGGLzd1viFUFCp+cXO+w== 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=p3E/A7M3DwEfsOb1I+VpU+KO/a7vwmEBAoBN+RmnkOU=; b=AbHI1Uov65awLLvifQlK7Jd+6PAy0+c2rEXCWhnOD46SMfj/OBqspyDkP2eNiRDj/hrA7f4lnMzXGAH5oQ99RcrZlbob/M/e0YjCMzPvdakPOyDZk/N698W4u93S5DNmcUzr/81D93JuXFwB7geDBRqLkZVPEsYjx/N802HR+u2S/CSJ/SUgMjEnLbLjE/EFFi8JOytRwJabxgwyacQHOApRcm73SMoSMVTe35qfyDeP8gFNsBFh6z1q+HPBuLidv7pjerX1qeyifc1qiVCGaZWd8XbZcWjDCYHbbb28UmN1jcOv+8vbeeQVJagf1FtKIJolLBDh9fXt/Wl2KmNi9w== 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=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p3E/A7M3DwEfsOb1I+VpU+KO/a7vwmEBAoBN+RmnkOU=; b=eZlvZRFYgCfgKhFsOlEo2Es+v8eTPfyGuPbIndBRS4OGzuEDRdcHDr6n1gx6jwOW69V3Wl8XInDP5ushD1znY4FonmE2MXq006Ces4mKfKmNoOz9wm0dS0SqFNjXfcVBAQSB05R1jwBmUMuDlp8Ah6txVIrhYqc7xXCz/f9M9mU= 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 SN6PR12MB2783.namprd12.prod.outlook.com (2603:10b6:805:78::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.25; Fri, 4 Dec 2020 00:03:51 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::d8f2:fde4:5e1d:afec]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::d8f2:fde4:5e1d:afec%3]) with mapi id 15.20.3611.025; Fri, 4 Dec 2020 00:03:51 +0000 From: "Ashish Kalra" To: devel@edk2.groups.io Cc: dovmurik@linux.vnet.ibm.com, brijesh.singh@amd.com, tobin@ibm.com, Jon.Grimm@amd.com, Thomas.Lendacky@amd.com, jejb@linux.ibm.com, frankeh@us.ibm.com, dgilbert@redhat.com, lersek@redhat.com, jordan.l.justen@intel.com, ard.biesheuvel@arm.com Subject: [PATCH v3 2/3] OvmfPkg/BaseMemEncryptLib: Support to issue unencrypted hypercall Date: Fri, 4 Dec 2020 00:03:42 +0000 Message-Id: <2ebeb0332fa0a077e10fa93a50f9de7ef3029249.1607038824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0021.namprd05.prod.outlook.com (2603:10b6:803:40::34) 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 SN4PR0501CA0021.namprd05.prod.outlook.com (2603:10b6:803:40::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.7 via Frontend Transport; Fri, 4 Dec 2020 00:03:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: de8b1334-4b70-40ea-20ba-08d897e814fd X-MS-TrafficTypeDiagnostic: SN6PR12MB2783: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6xBwEqFyxEjmlvJ47QIA5hfm9rG0Kimlc0Lj4icWh5U8SYZLoXT9f3hd/XpuhaYOn+uMqozQV7pJmxDksXV2TVb+6XeICuxAtvDhDr5rcu1Wdl4hx5c2BHcSmdMPJ38FnAHnuRgk1pTmZA1mesZ8EYEaMMWyucwUcfZB9XSq6W3KevYtBw9zwa4uNxQghxcQvz1/GzTDUhXNqt0KK/SkFwM6OGwBlPs83gyo8L3+r3yb/R6KkBXoO6tfKG2Tm1xgqe9bcQslfkKg4NxO/6SsZV9OfzTbirfYlULfp4tLLwwQKqtrO6Qv8jETVBPc+3sDqCEz1Pr+t2Kr1RNg4pG+DA== 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)(39860400002)(376002)(346002)(136003)(396003)(366004)(478600001)(86362001)(66476007)(5660300002)(6666004)(66946007)(66556008)(956004)(19627235002)(2616005)(83380400001)(7696005)(316002)(52116002)(2906002)(16526019)(8676002)(186003)(6916009)(6486002)(26005)(8936002)(36756003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?Gpi4WSyGHdRhivG+924C6H5UXm1Fhzgj4P5uYx1XkdRxC3br0RS8ndh3Aql+?= =?us-ascii?Q?ZcO7EENwXo2YGnoSzjDU8ClrHxMTFa+1Sx7vg9vxzCw0LB8wzTyydJDSmeI0?= =?us-ascii?Q?ZQ87ajdKwb40J0GY6GTxnMnEoz1ifXxDbfMvTyBiVV6Rg9aHL1bbkSholC3U?= =?us-ascii?Q?WWGp5mbQjrcVKpF7R9Ik7jC+BKdK1oDxQFxANgYz6uptfPtBIAPhQs562K9I?= =?us-ascii?Q?5s0ig2R2gQPlCavHcB+UL15b/TyHIS827OGHZhCSpZqKtXCUSV6Jm7cybb/l?= =?us-ascii?Q?DKc7iytyzn2zkBQ6mw1FQnKL0bO6VdtpUW798vsLEWv8YATWYF2KnMO9/iR0?= =?us-ascii?Q?DvWv0cys6AgFFMs/qLYiue/3AkTr9183/Js3o1rU3IuxAp63/VijcyEXJQBT?= =?us-ascii?Q?UNdYxhbIkEG9QLQ7O3vSHc4dYjxjnfXveWuZK8Gi9ED8eJouclow10iX4hIX?= =?us-ascii?Q?nGqV+kyZxrv9OPEc0cw5vlik/3hY7KYSmWGqCnklDqxlMD0mC3Qpjq7zr1Pl?= =?us-ascii?Q?bsH/9KHIXBVQqZ8Lw384IobyR1r8pE/6cU34+Boq2EajgLH1S3yJmG6rCc64?= =?us-ascii?Q?UEt2fDFOJY98fi+X5XIN2eOsHgnlqSINwXAOBvAEgZeimSwaqXbKYmL2PtIi?= =?us-ascii?Q?v8qnbeOebDiv45A/+UgoQBpQbAs9MJUu1qTGaGPvcVPfzbcyaGLxkURA7v0v?= =?us-ascii?Q?MVNpTJ91lerVIhvmjbLxH/o3qwvxanTCeU0imonqSXCEquK3u+8VnPuftR5k?= =?us-ascii?Q?fK/23flTd9e1AwEXsPRa2oDvsOZsvTPudW3C4/dIHc14dwHCNg2x6k++mgT3?= =?us-ascii?Q?0ouuP0gO6l+QeioEq9tAlpTjRf8fqjC210LMnR6ICVmGDfJWmohiQGaQPw9X?= =?us-ascii?Q?8g431zJLH8cCLXuRxg0McIls14+XmO+xzoptW2sDtD2c0SU2Qh+Ubb85KmDk?= =?us-ascii?Q?xa7tmwxJMYIX29h4lleo+eDwhEbaQ6TZKB5WWc0YJCQDpfsMv+PIlHm+2wgw?= =?us-ascii?Q?h583?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: de8b1334-4b70-40ea-20ba-08d897e814fd X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2020 00:03:51.4904 (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: hd+fNPMNewkSc3Htrxh9JXW6ESojBSTN1u9lXKBUqrKoTWQD8g7W41RrSY749QJQf5fz6YsmMOmWYG0cXwIM9Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2783 Content-Type: text/plain From: Brijesh Singh By default all the SEV guest memory regions are considered encrypted, if a guest changes the encryption attribute of the page (e.g mark a page as decrypted) then notify hypervisor. Hypervisor will need to track the unencrypted pages. The information will be used during guest live migration, guest page migration and guest debugging. Invoke hypercall via the new hypercall library. This hypercall is used to notify hypervisor when a page is marked as 'decrypted' (i.e C-bit removed). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf | 1 + OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf index 7c44d09528..95ee707918 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf @@ -46,6 +46,7 @@ DebugLib MemoryAllocationLib PcdLib + MemEncryptHypercallLib [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c index 5e110c84ff..1e670b6200 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "VirtualMemory.h" @@ -589,6 +590,9 @@ SetMemoryEncDec ( UINT64 AddressEncMask; BOOLEAN IsWpEnabled; RETURN_STATUS Status; + UINTN Size; + BOOLEAN CBitChanged; + PHYSICAL_ADDRESS OrigPhysicalAddress; // // Set PageMapLevel4Entry to suppress incorrect compiler/analyzer warnings. @@ -640,6 +644,10 @@ SetMemoryEncDec ( Status = EFI_SUCCESS; + Size = Length; + CBitChanged = FALSE; + OrigPhysicalAddress = PhysicalAddress; + while (Length) { // @@ -699,6 +707,7 @@ SetMemoryEncDec ( )); PhysicalAddress += BIT30; Length -= BIT30; + CBitChanged = TRUE; } else { // // We must split the page @@ -753,6 +762,7 @@ SetMemoryEncDec ( SetOrClearCBit (&PageDirectory2MEntry->Uint64, Mode); PhysicalAddress += BIT21; Length -= BIT21; + CBitChanged = TRUE; } else { // // We must split up this page into 4K pages @@ -795,6 +805,7 @@ SetMemoryEncDec ( SetOrClearCBit (&PageTableEntry->Uint64, Mode); PhysicalAddress += EFI_PAGE_SIZE; Length -= EFI_PAGE_SIZE; + CBitChanged = TRUE; } } } @@ -812,6 +823,13 @@ SetMemoryEncDec ( // CpuFlushTlb(); + // + // Notify Hypervisor on C-bit status + // + if (CBitChanged) { + SetMemoryEncDecHypercall3 (OrigPhysicalAddress, EFI_SIZE_TO_PAGES(Size), !Mode); + } + Done: // // Restore page table write protection, if any. -- 2.17.1