From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.63]) by mx.groups.io with SMTP id smtpd.web12.5236.1607034439424739402 for ; Thu, 03 Dec 2020 14:27:19 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=SFuWNlIe; 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.93.63, mailfrom: ashish.kalra@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c58EGtbtiMvEIxxr5gHs/GI9W5dj/lPW6qOJzxhcZoFNUOekjVmkxUscSPD/Sd5z6kMTqEAoEldcEjuRyJQxAbycsx6ZRuJiklZu4Gn1mQEpbRbxw0qO3+ovQ56A4JWNwiSWyM2RIUup4qHynqVmalcaGJviE+R/YwHlbn2QWlTzQZ/E5Fsa2sEk7Tjm8IJ5UUdAFOyhG5yoTcPRinlYJZ4Z82uZgDPC3G8HXfyqxS3LUQ6HxiZ0NieKt/o6KZfCACoE9wRPxsbGojfkFv2SZO1TFLonLqe9olTgEFwZebTmHIpaREZE7bPfVCclR5k4YYYEvbGNewNb8ivUPTXzEg== 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=AxkrvoeA6g6BZr3blkQMWG+ec+9wiOxZH0+O51jEq2wQOh3DhI+zBlBsPwdGJk02U9NGm5qgv5w6hO2QVaWr5oedw5GLwUkTGijYnAHOvjIELzLTuRFPKKfqWQgMOxoh34khG0BV4b3W0QwAvBP/AJK8ZgLBg9n0O4b7B5Bcu3pSUu2riKnR8wUlrm2gm7ml64QsH+zL2c4nPabZSI7wgBL45GoQ54pwJwuCWB0UwuW4caFudL1gF13IHgzm3IoEhysHqNQPTPWHPt7A83jVUnUNnTCYSPBhC9vTskXx0kt3pV4tshtL4pOrND+j7eWk3RQcg8NmwTRP8i6SQ3iuiQ== 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=SFuWNlIehwLqugr+KcnoNH0zJPewDJml66qpOQXvXC8ABFXjWK3I4EMU7Hz3/g0ZqxR/LojGo9d//DuGHyC2tQkeVfw30SwpTT/q+fIQaLSD23fb+biWTwDUlNg37rK23cOBPV2rEpTzgZQ5LvOF58y3kybBqwIJcxxFXCD2cpk= 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 SN1PR12MB2446.namprd12.prod.outlook.com (2603:10b6:802:26::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.20; Thu, 3 Dec 2020 22:27:16 +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; Thu, 3 Dec 2020 22:27:16 +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 v2 2/3] OvmfPkg/BaseMemEncryptLib: Support to issue unencrypted hypercall Date: Thu, 3 Dec 2020 22:27:05 +0000 Message-Id: <2ebeb0332fa0a077e10fa93a50f9de7ef3029249.1607032888.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: DM5PR22CA0016.namprd22.prod.outlook.com (2603:10b6:3:101::26) 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 DM5PR22CA0016.namprd22.prod.outlook.com (2603:10b6:3:101::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.18 via Frontend Transport; Thu, 3 Dec 2020 22:27:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: dc51016b-ee65-418d-bcb3-08d897da96fc X-MS-TrafficTypeDiagnostic: SN1PR12MB2446: 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: 1LwqeoG8wYMg29AtzCq17opaHAjquc4thIT1sVn3u8HVy8YETrda4DBayQTNXqdbWuzRgDLxHqfbhZSy8ZqBNDXN/WrHt+nxktUy41xQNyFbyZ6sn1bAIQusfMARKhtjWZvke863c3tiyghfniczQh0s2/onCHL6+hi05lvmZD6wrmUXZe6dQJfYjEeaDi6Gd+cy3Hchq8yvjRElu3kAu6bEAARZbReBV6EiOXrGhTOvP///uTlx8Gj+CF0bHyVO3vcw6/BEG4lwEZs4Qvwv1OFCl1SBbkx7PNXCRbkBX62/h35nl+e1BiHOgWtp5guWtV55fug1v38r+SCGEIPmAw== 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)(396003)(136003)(39860400002)(346002)(376002)(2906002)(478600001)(86362001)(186003)(52116002)(6486002)(16526019)(66946007)(66556008)(66476007)(26005)(6916009)(36756003)(2616005)(5660300002)(83380400001)(6666004)(4326008)(8936002)(8676002)(956004)(19627235002)(7696005)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?NgvLerNb6qRsVPUKk7hSrctvnTTK2M42c7OdCRZfHy0RmGA04gO2O3GGxqd6?= =?us-ascii?Q?ukmad5bJR2KJbrBQPTCh8n8nI/D0ycwPbysTyg1oTzn89cQK/gEE8bA6C5zb?= =?us-ascii?Q?xvakSeVOm+BfaFppbjap6SeCq6Qn4Sl4lbl5051xtjKnA7FBxUpE9V0pKN6/?= =?us-ascii?Q?cS+oqkh84EuYlqceIyhdgEkvQwEvfLla8Ba22Evdy/gI76ET0CCaVqLHKZqw?= =?us-ascii?Q?sNQtiO6DBljmkEwvBRqW+1vv3KW9kJi2w02+dvW5DbYGGRp5dbBTXLiS/0TB?= =?us-ascii?Q?xjUNhWstCAw4xsxkgs2vXNlsoc+5uR1d5b2APVB3FL2geUFTZBnCWBannhmF?= =?us-ascii?Q?dhtaCdtbam4+PAXi64XAw1UnMH1jERdQyqYQaUmkytKTQ/dXaNKhCvRBYsk+?= =?us-ascii?Q?3wkpoMdVcuXtZE7yui18AfWRk2jxbAat99uu+QajJHeajYj1KBRNG/3Kh5IW?= =?us-ascii?Q?SmSL/7nQbfLYMx2rehgpnjjuQ5ck29hlFIAvCXlSmxgQ5tL6uA2QMKKrrw8s?= =?us-ascii?Q?s7MHnphGbdDfu93Fu1Y7hf49ogYsKuYZQQMS0bACe8+vwKRrsiqLUSslCQCx?= =?us-ascii?Q?nfMfl8KgQMAF/Dv1ywE9x/8N9Dmqs+mAu5l9AyCmDIt5IceH0rg8yGwuKROr?= =?us-ascii?Q?/OFaaZH2GBpCwl0tXVSdxbXYHC10jlYQzTcqq2iLoa8rSIww0+nKitfyoCvr?= =?us-ascii?Q?QQTnxuBzqah60l8uMqUkbyw+bi8QXnafif4AbyAyBdAedOiX6tr9mb1DHMy6?= =?us-ascii?Q?VVY+8kwTpduXTsEZmI7wj0bhKKbptoaC0/XOsnbn+wV8rHHdNSU0YQZuvZ+t?= =?us-ascii?Q?XL0cq0k4JwWbHpRSjbyEmWQb7t6Kax7HN8rfzawgIkXGGdxE/vCKRykD85wo?= =?us-ascii?Q?Hu490HAwmDCS6Lg0kaW1skK+l7njtg+VyjkGaxcHnYa60+/DM6m/TFhIileS?= =?us-ascii?Q?iTAENovDKQ4vd3bSk8RdznV+kJ6HB+kC8uMvSaARdO8=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc51016b-ee65-418d-bcb3-08d897da96fc X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2020 22:27:16.6224 (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: gYojb35bdg6JyTYxN9t6EpZ+ZPZp4fJzn1vT0wB4Vznbp53Bg5Qgs3mvu1bbY+OGIFdYQcUTcmZzG/DAL6V3BA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2446 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