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.51]) by mx.groups.io with SMTP id smtpd.web11.1556.1606894200121036181 for ; Tue, 01 Dec 2020 23:30:00 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=m+FufoVw; 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.51, mailfrom: ashish.kalra@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d0iQV9llJwS0S8b/wpHs0aAJi4f/4qgsjnQ2Ic/wWlfjiSmzMkFAXSaMWK+AGco2TB5PT8RX7+OzPz/I9IdFdy43g3tl1on2Uyx2WnLQraFCyQoES+mGcfzV3Ru7nWVcMCe4jzA34q3xK4HbvMv3PpMSueFCvO2LEcdgfprY6KIts3knoojAJ1i7QHSjyq0cZBgVMS5+lyJ08QvkTRUL1DpnmBsCIJ9Tp8Wzx4RvgX4TjkbI2ULsQ082boT5Slz03jqtR8ptpERg1aghpzXP30CVU1pao3nRquVnFqN5drpQ68tE+/a13Sa0WJ9/M/DyGnVoT6cPiSAnQTM9PP8BNA== 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=7yhihskd1SvqugHJWQHF0qNIsK1SfTq8j5cFXq+in2Y=; b=WuIimsU4WoP2Lq7TUG8oOrSV7le14Ke642Mo5Tv4Jhb19SKOLQSxCmgIA7wIWqOnx4T7LVHfkkzxKDavWgvHvx+GR2JfcK63zaUfQL1rVoah7yUGdnFb4uYBHpCbsp/q8lvRYVquZzqMI+6ZwxicCnIRomk9f2COgLrf4tvEug9V67pAeUsT48sDq5wzSy87G+odPU2wB+sS2Zln391A64a4l8qN6AK6YH0pYJEMPkTPIrAUQIYYJ90OzDVIWDpTGQ6BuDcNrDJQ93Zb6aHx5AxjgJQEjrh5nMYzUz/dCXEq3QmFbzxwQBlRXCDOzJkN5Oz/I0ztgMWIbcChEy/rjA== 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=7yhihskd1SvqugHJWQHF0qNIsK1SfTq8j5cFXq+in2Y=; b=m+FufoVwHeW3vTl+POmeEXgBLqRQo25fO0BRww/Vnb+i+K6oo7Vq/viN/vNRN+Fk7pho0WMQygzmq2aPQXP8c/GQn7h5eAFC6Y2AjPyV3ymdPlEStQGN70Bi2x08//eESW0dNTbVLZqXBffYDpmLTE3WmvkrjPjQE16OC91rWYM= 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 SA0PR12MB4511.namprd12.prod.outlook.com (2603:10b6:806:95::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17; Wed, 2 Dec 2020 07:29:58 +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; Wed, 2 Dec 2020 07:29:58 +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 v1 2/2] OvmfPkg/BaseMemEncryptLib: Support to issue unencrypted hypercall Date: Wed, 2 Dec 2020 07:29:47 +0000 Message-Id: <20201202072947.12668-1-Ashish.Kalra@amd.com> X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0155.namprd05.prod.outlook.com (2603:10b6:803:2c::33) 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 SN4PR0501CA0155.namprd05.prod.outlook.com (2603:10b6:803:2c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.9 via Frontend Transport; Wed, 2 Dec 2020 07:29:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1745abb4-e795-4258-9277-08d89694123b X-MS-TrafficTypeDiagnostic: SA0PR12MB4511: 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: vGCSAR/YUdSKX5iZdyakOat3+Hz58V1EGcqpqp8KU4DI6Njw41Dk8bcYoz/+ESXngirOd96nV451Vp+bIcI92fuHU+0PePPbgCkm+W9ct3bMQqtMwLV+uWxWFrydGvKi2iEh20/IQWMBOVTlNuq8+PNU5dL/2pYtaxATYJqdpAosowNO3Y2atpZqUbreQ5spaBog71E9oHHVm2zZNw+SZsgqIQameIyW0hmZGdCG9tV8wNZ26rhTU8iJdQMQmW/XF34NcadrNR0CXxco/cUe1SDw3kIoQoWA8qDN5l0B/4JoGskLf0SAgmjEeu+PgIc5uWageBlczp49QcGCWV1PSA== 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)(136003)(39860400002)(346002)(376002)(396003)(186003)(66556008)(4326008)(66476007)(66946007)(478600001)(6916009)(2906002)(52116002)(6666004)(19627235002)(7696005)(83380400001)(26005)(6486002)(86362001)(2616005)(16526019)(956004)(8936002)(5660300002)(8676002)(36756003)(1076003)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?rRAhYpXPxcHX45JE/PN4oe2iwQ1PZJDohIHzUKIL3ok/U3Pe+/zW2V/FSf7f?= =?us-ascii?Q?6vT6FAGt8nySckz7ZBjOy6X3njmBqKZKXfDU0XZgddYmcsHNVJ/hOmR5YnUY?= =?us-ascii?Q?D6DpjtCpWd0EIOrv3EushD+vd6Xz3XiChnAGavpDp/dRqdT+MuZZhr/gav+T?= =?us-ascii?Q?d4LjezNNUodGy6zQMgBAJcHlrkWmxWExpdNHW53w7RXRowxIm/D9kuer5lOW?= =?us-ascii?Q?HYXB9c7M0nHpwGjWHpEX6Y0cYOsJbihz3gGYV20DNRqH4U9qEReRMtoHaRnB?= =?us-ascii?Q?vRJ+3bN5OD0DbSEcuYKomR71/Kxm4d0jC6p78Wrn0yccd66y2h/YXRyfDteb?= =?us-ascii?Q?V5z0xbJIW0VnHemCkGRCjWpoVSoA8OmO8yrTTfIaQg9CET3YBAZNqzadJy4+?= =?us-ascii?Q?ovWwm26PIEm6M1jpNu14ff95K+6eNinuITI4BJ/XZbn0gf1FMDVve6eYU48K?= =?us-ascii?Q?1EKMF+PxApUMDFAGnrhPLu+olLdjhatjZwzJz86tx/B/RPDtUy1dJ4T8ypi4?= =?us-ascii?Q?TV5DS5GOhznEo4iaSAqrYx8O6jxEUR++ctMtschR1PtZM4o/5SeeCJGiH3vB?= =?us-ascii?Q?MwU1xPTe0XHAtb2RnQ9ldyb/f3ypzGbVFDp6OzJwMhTTaIv0Rp/KBDwC8vkJ?= =?us-ascii?Q?yQ1A0LDiGqir+VvMzogJ5c5TxD4BggaF4dZzMp2IH0pgVdsPrjq3JMq6tFJe?= =?us-ascii?Q?u38ZaKDZiQwYJ3tnE1U7JNphDB4zvxWpe09X9F/S6XOU+8Mr2Q6VFnmEdJK5?= =?us-ascii?Q?jDx5pg8WRZBluCf0GzY7fYmarZ+GE3ZJnQdhkyqndJi5Z+TUYodlpvrLOopC?= =?us-ascii?Q?4negUXwDE07O6/uraA6qR+yENBrckYODQ9IYm1dcCuem2UbW130AsoFO8Fxw?= =?us-ascii?Q?L3lQ1dG69/gEEp1xGR52z7Xlv04v6iKZaByhm6fP7IlMKkdLvrArWuxc9hKd?= =?us-ascii?Q?4fS86SD3yBDWj9GdoqFi3+j45VqpoiHuKtsPvwfi5Ow=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1745abb4-e795-4258-9277-08d89694123b X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2020 07:29:58.6560 (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: TnrQLVf3HAqO9A5oDY26pAcB1DR1h+1yp/0Ny7NYTPa53GXARLMyW9nqdLfsp1c2NsDjh38Ob56u57cQCz35rw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4511 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