From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (NAM02-SN1-obe.outbound.protection.outlook.com [40.107.96.83]) by mx.groups.io with SMTP id smtpd.web12.19066.1627907532354264513 for ; Mon, 02 Aug 2021 05:32:12 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=KIMPbwQo; 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.96.83, mailfrom: ashish.kalra@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CFCt2FoRo1Awzci5tYUW9Sf2S3EG4JZ8yM13yL5i5JP1D60k5E8XbH09UHxgBvk4N8FjoTiZuQMLQmgbX4rZKdDh6yIRQb9DcxHIcGG5Smhyb838zppqbIFGqg0PRoPmMRAyY3Aijazwhe2h6qQwENiT3jkEim8abH1Gxzih6gqQw3nAAWEp9eqgrXHOD34XOaOYswO1RaqrAxF064WKFjxoldDj3h/sGwQejkWupXLdFpZ4YpT+CvGcLbzrfcdSkbDVytMDHUFqXxU/MlfzGyu58WbiGiQCCZ05rc8R1vxnYQ0YuyrJEjOpFR0IkuVw0tueiV3C0OzTTUJZXIitlw== 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=wvK0ttbk61F+d13uO5S1PLCXGi7YIKzJXwWbvF9+hx0=; b=A+9DkDQcarGHf9r+0V//tIusXD9dgFniM+KOkjdCT/lF5D7Ue5aobhS1n1YstGKCYMyXdF1aRg/CcmU2sNcyu5mcAlMh7pYSQjxopmoFZbBel0TQjNLj5kqmMzB4t5zXLqq38W+XPz/U61W61eCOt8SSiTEhNdpwVKsBuO54ViIHIks0+tmaEpC442gN8ytf0TypZrDQ5V7SmWP8TZPb37E67NUBpWFKalwxUmMvo/RMJg2yGWEtLaS836hGsLvHa8srU8eCVBhdpy5su626WwF0g7UIqlTdQcR3DnHwCPr2hjcyTgKfgM2RwQwq8GgVDiyp748kFVuFx1ij5xofGg== 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=wvK0ttbk61F+d13uO5S1PLCXGi7YIKzJXwWbvF9+hx0=; b=KIMPbwQoW93k5535K91lLDaQyHoXBkHXWE5suCvwbh9DnytDCGC32SIlMzA52ZcFqAXMdMbnws8TIhZOj8zO1jOnZfBRwp9fQIK80NIqjKf225P1iw5K7VdIuFwbmKoSxw3taQpauS6qTBBUysPGj2Xcwa9bHsrJ33LezlCHIXc= 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 SN1PR12MB2445.namprd12.prod.outlook.com (2603:10b6:802:31::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.25; Mon, 2 Aug 2021 12:32:09 +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.4373.026; Mon, 2 Aug 2021 12:32:09 +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, jordan.l.justen@intel.com, ard.biesheuvel@arm.com, erdemaktas@google.com, jiewen.yao@intel.com, min.m.xu@intel.com Subject: [PATCH v6 2/6] OvmfPkg/BaseMemEncryptLib: Hypercall API for page encryption state change Date: Mon, 2 Aug 2021 12:31:57 +0000 Message-Id: <13cc36f3dbb0e5a0d10b241ef23ff67b7bd507b7.1627906232.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0091.namprd12.prod.outlook.com (2603:10b6:802:21::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 SN1PR12CA0091.namprd12.prod.outlook.com (2603:10b6:802:21::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18 via Frontend Transport; Mon, 2 Aug 2021 12:32:08 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b9073d30-5186-4e3a-4f22-08d955b18b80 X-MS-TrafficTypeDiagnostic: SN1PR12MB2445: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6buYr5pzsLYABJSE2d32gRxHxSTkYK47gNgIszlL725Io+MDxleuxJDVdFJjaqkaVB0/XY4PYAt9squZmMr45hT52nufEJGJK3hqc1WsbWflEy9gd53cymyCRTMcv3VpYMhQYzFXGNJAaBNjBGd8a7IeFIAk2Gb5D/hpyfalE/bGU1RMHvA7bWxaLPlUH3K2+5+HiVuy8hbjg1JgUQY71EbuaH3E//E+ZmeB2beFaJEalpIiKGTcZpHgX5ugg8NpBOhVVB0+o4pKHmRzi7H0hdX/7agL3a++JQ8BGBIoBFzgo9muQUw+aesf/RaYFKuOKnshOcc9ZrI+LmBwUxUDip9SUF9fSKpiKi5Z3TMQ33+5Ka/GknnwnKWl6Z18qrw8k4r+MSq+F81yAv8WOOLoo50H/tfpYYd7gaxn2rO8YLOarGugRbJd3B1dv9lh9AkTLovSWUsznTnSadKqtZtzcMJnetBPqVrMDTjjdZnLyQmMABnxkQZ6fGKOJ+DQWIR8xPz4rvNnFCMiDDQS5Joza5cX7I9YxpfkD/fs93gCyxP5Oa8QIVBvhZxnISAKLfRobKE0wppHdZoJaxRP5eNJATAcTUnIv2q9w0kY9JReYFxR1XJeOZtxnqtC2otd/dcW7VUXVeNQCzbS3OdVuyRDpWtQq0hEGzdX2URrd+Nc7ncNfyu9Ky0aVm1OVx7tloqhow+z4eCqadA4Ofu4v/i28A== 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)(136003)(396003)(376002)(366004)(39860400002)(346002)(956004)(6916009)(5660300002)(4326008)(316002)(7696005)(66946007)(66556008)(66476007)(6486002)(8676002)(478600001)(36756003)(19627235002)(86362001)(52116002)(8936002)(38100700002)(6666004)(83380400001)(38350700002)(2906002)(2616005)(186003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?kVxqRmET0TF+r31oSyymy200EBGFjF+2YYtJc3uDxuww3I4o/zz0sFXAuSns?= =?us-ascii?Q?LjAsinH47uux1Jafn93xXfrfz3frnpkuq7SNmPDneRfT3/2o+Z8J5iUu0tyF?= =?us-ascii?Q?J4VvKbMhvHjR9QTuqtXE3wXuRuK5uS9UARXoxpZhQxD4jd1j3jl98nr493mB?= =?us-ascii?Q?xSj4rZxLvEzLzwnVd3t3ncir+wvvt1gRLX9hPbiG8KF4VxVFhELqXATb4gzD?= =?us-ascii?Q?/uRkUQc5vdEGjgjU4wSuoTgjP+3ZW3n1gVCjk4lRLOFelTglNaeL1JSTpfPK?= =?us-ascii?Q?fUpOhoTKR4C/Bcb8GuAA+5cLq8TeSfc27jisfXwDPnL9bgVioMjIpntCclES?= =?us-ascii?Q?Y9AFZjuK7VbpaRuYYtVbJmXX7NzRPJYYKQimMWC6ekkHc9wm3/S2CpQ6VXxh?= =?us-ascii?Q?wJEohSSCi2X13k8IpaI5VxfbjohQhWFZ7SjbTESTd5vTiIB+YTm3x37n0tc4?= =?us-ascii?Q?crs1ErvMR/GB+dQN53XG0LkJj3ivpop85U/DGeC/zLX80l1IUa1Fd9aTk5xG?= =?us-ascii?Q?LdRPwfqjyQcCUByrVUMZQxnLA/IJXI7WBcz2QcTv1qzCPtPXyGC2VujqfWQp?= =?us-ascii?Q?J+o4KlIs26juY7rRiPzxsqBwBgAuKTOxY9vE3pZ4+nZ1HLkjFdgHSdKWzlB5?= =?us-ascii?Q?dVhtwDP3dTc1GzcHHVrIVUp4KPx+1rLqkrmLAH08vvgqm8R8ZZ0zwFHINeJr?= =?us-ascii?Q?TAwIi1dgPjq5HKayEyXsmQFmwviGd+YFiGZfNtXgM7iqkQE4Ufy372z8es8X?= =?us-ascii?Q?ho2NaO/6nLbuptCD2jBb3A1Bxx+7J1HjeMmfXqPF0lkIxtxgFWzYWHSaIC30?= =?us-ascii?Q?GbBNyoj8K/rHf3EKu/zfmtrFWPy26GBW5DrqJDQWsAJ1D279UywdN9SQcBnS?= =?us-ascii?Q?SVNRLFobQ+6gRUegMcdajlsm+XsZFi+1qdKTEisu4jMmxnZfFHXzSY4kQT0d?= =?us-ascii?Q?U+l5RawaIdJi4qJB6sOMwY4blwlIr5QGm3WHz5+tpzGLcE8VfCY5Kuuc5yyR?= =?us-ascii?Q?gewoMDt2b+nq/KqfsFYvruqZoa1zrP5WwSi2e3AYazk2PFgDMvglpTUjXEOt?= =?us-ascii?Q?srqw4FjMFKzcObssbKYsyOoY0ep0XytNwlvyU1W6m5PbwmCsfqYT8NkzroKZ?= =?us-ascii?Q?otrmlO5YYIGo7wVXiUBRG643sM+Lq8Sd7zo/zGraZlUu8MuesRQGxvOeQw7I?= =?us-ascii?Q?PfnjnR1pG+GlMj+/RJaBK8zjR1nIvMAyKPYyJkfcrvyii6hMGx/ksngBwW9J?= =?us-ascii?Q?QzGILFL4rJ8h4ZplhPBd0WWVWfHZRM7njmlolkabJ0AjlqwxHlMFg55o1yeB?= =?us-ascii?Q?6rEgHFSNMgF3w4B9OY83xEm+?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9073d30-5186-4e3a-4f22-08d955b18b80 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2021 12:32:08.9119 (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: 2zrb+mYFgztPn++0K+GD64+IdWgXj9FsNQs/DEwI3WIK1f2NO4JloDT2bO4IAgOjA6m25RtXo+u1PTUDhW/CQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2445 Content-Type: text/plain From: Ashish Kalra Add API to issue hypercall on page encryption state change. 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. This hypercall is used 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/Include/Library/MemEncryptSevLib.h | 43 +++++++++++++ OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf | 1 + OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c | 27 +++++++++ OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf | 1 + OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c | 20 ++++++ OvmfPkg/Library/BaseMemEncryptSevLib/X64/AsmHelperStub.nasm | 33 ++++++++++ OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c | 64 ++++++++++++++++++++ 7 files changed, 189 insertions(+) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/Library/MemEncryptSevLib.h index 59f694fb8a..56cc7bb958 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -249,4 +249,47 @@ KvmDetectSevLiveMigrationFeature( VOID ); +/** + This hypercall is used to notify hypervisor when the page's encryption + state changes. + + @param[in] PhysicalAddress The physical address that is the start address + of a memory region. + @param[in] Pages Number of pages in memory region. + @param[in] IsEncrypted Encrypted or Decrypted. + + @retval RETURN_SUCCESS Hypercall returned success. + @retval RETURN_UNSUPPORTED Hypercall not supported. + @retval RETURN_NO_MAPPING Hypercall returned error. +**/ +RETURN_STATUS +EFIAPI +SetMemoryEncDecHypercall3 ( + IN UINTN PhysicalAddress, + IN UINTN Pages, + IN BOOLEAN IsEncrypted + ); + +#define KVM_HC_MAP_GPA_RANGE 12 +#define KVM_MAP_GPA_RANGE_PAGE_SZ_4K 0 +#define KVM_MAP_GPA_RANGE_PAGE_SZ_2M BIT0 +#define KVM_MAP_GPA_RANGE_PAGE_SZ_1G BIT1 +#define KVM_MAP_GPA_RANGE_ENC_STAT(n) ((n) << 4) +#define KVM_MAP_GPA_RANGE_ENCRYPTED KVM_MAP_GPA_RANGE_ENC_STAT(1) +#define KVM_MAP_GPA_RANGE_DECRYPTED KVM_MAP_GPA_RANGE_ENC_STAT(0) + +/** + Interface exposed by the ASM implementation of the core hypercall + + @retval Hypercall returned status. +**/ +UINTN +EFIAPI +SetMemoryEncDecHypercall3AsmStub ( + IN UINTN HypercallNum, + IN UINTN PhysicalAddress, + IN UINTN Pages, + IN UINTN Attributes + ); + #endif // _MEM_ENCRYPT_SEV_LIB_H_ diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf index f2e162d680..0c28afadee 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf @@ -38,6 +38,7 @@ X64/PeiDxeVirtualMemory.c X64/VirtualMemory.c X64/VirtualMemory.h + X64/AsmHelperStub.nasm [Sources.IA32] Ia32/MemEncryptSevLib.c diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c index be260e0d10..516d639489 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c @@ -136,3 +136,30 @@ MemEncryptSevClearMmioPageEncMask ( // return RETURN_UNSUPPORTED; } + +/** + This hyercall is used to notify hypervisor when the page's encryption + state changes. + + @param[in] PhysicalAddress The physical address that is the start address + of a memory region. + @param[in] Pages Number of Pages in the memory region. + @param[in] IsEncrypted Encrypted or Decrypted. + + @retval RETURN_SUCCESS Hypercall returned success. + @retval RETURN_UNSUPPORTED Hypercall not supported. + @retval RETURN_NO_MAPPING Hypercall returned error. +**/ +RETURN_STATUS +EFIAPI +SetMemoryEncDecHypercall3 ( + IN UINTN PhysicalAddress, + IN UINTN Pages, + IN BOOLEAN IsEncrypted + ) +{ + // + // Memory encryption bit is not accessible in 32-bit mode + // + return RETURN_UNSUPPORTED; +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index 03a78c32df..3233ca7979 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -38,6 +38,7 @@ X64/PeiDxeVirtualMemory.c X64/VirtualMemory.c X64/VirtualMemory.h + X64/AsmHelperStub.nasm [Sources.IA32] Ia32/MemEncryptSevLib.c diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c index d9f7befcd2..ebb1c39319 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c @@ -118,6 +118,26 @@ MemEncryptSevLiveMigrationIsEnabled ( return FALSE; } +/** + Interface exposed by the ASM implementation of the core hypercall + + @retval Hypercall returned status. +**/ +UINTN +EFIAPI +SetMemoryEncDecHypercall3AsmStub ( + IN UINTN HypercallNum, + IN UINTN PhysicalAddress, + IN UINTN Pages, + IN UINTN Attributes + ) +{ + // + // Not used in SEC phase. + // + return RETURN_UNSUPPORTED; +} + /** Returns the SEV encryption mask. diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/AsmHelperStub.nasm b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/AsmHelperStub.nasm new file mode 100644 index 0000000000..0ec35dd9b6 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/AsmHelperStub.nasm @@ -0,0 +1,33 @@ +/** @file + + ASM helper stub to invoke hypercall + + Copyright (c) 2021, AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +DEFAULT REL +SECTION .text + +; UINTN +; EFIAPI +; SetMemoryEncDecHypercall3AsmStub ( +; IN UINTN HypercallNum, +; IN UINTN Arg1, +; IN UINTN Arg2, +; IN UINTN Arg3 +; ); +global ASM_PFX(SetMemoryEncDecHypercall3AsmStub) +ASM_PFX(SetMemoryEncDecHypercall3AsmStub): + ; UEFI calling conventions require RBX to + ; be nonvolatile/callee-saved. + push rbx + mov rax, rcx ; Copy HypercallNumber to rax + mov rbx, rdx ; Copy Arg1 to the register expected by KVM + mov rcx, r8 ; Copy Arg2 to register expected by KVM + mov rdx, r9 ; Copy Arg3 to register expected by KVM + vmmcall ; Call VMMCALL + pop rbx + ret diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c index a57e8fd37f..fa679c9fc9 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c @@ -143,3 +143,67 @@ MemEncryptSevClearMmioPageEncMask ( ); } + +/** + This hyercall is used to notify hypervisor when the page's encryption + state changes. + + @param[in] PhysicalAddress The physical address that is the start address + of a memory region. + @param[in] Pages Number of Pages in the memory region. + @param[in] IsEncrypted Encrypted or Decrypted. + + @retval RETURN_SUCCESS Hypercall returned success. + @retval RETURN_UNSUPPORTED Hypercall not supported. + @retval RETURN_NO_MAPPING Hypercall returned error. +**/ +RETURN_STATUS +EFIAPI +SetMemoryEncDecHypercall3 ( + IN UINTN PhysicalAddress, + IN UINTN Pages, + IN BOOLEAN IsEncrypted + ) +{ + RETURN_STATUS Ret; + UINTN Error; + UINTN EncryptMask; + + Ret = RETURN_UNSUPPORTED; + + if (MemEncryptSevLiveMigrationIsEnabled ()) { + Ret = RETURN_SUCCESS; + // + // The encryption bit is set/clear on the smallest page size, hence + // use the 4k page size in MAP_GPA_RANGE hypercall below. + // + // Also, when the GCD map is being walked and the c-bit being cleared + // from MMIO and NonExistent memory spaces, the physical address + // range being passed may not be page-aligned and adding an assert + // here prevents booting. Hence, rounding it down when calling + // SetMemoryEncDecHypercall3AsmStub below. + // + + EncryptMask = IsEncrypted ? KVM_MAP_GPA_RANGE_ENCRYPTED : + KVM_MAP_GPA_RANGE_DECRYPTED; + + Error = SetMemoryEncDecHypercall3AsmStub ( + KVM_HC_MAP_GPA_RANGE, + PhysicalAddress & ~EFI_PAGE_MASK, + Pages, + KVM_MAP_GPA_RANGE_PAGE_SZ_4K | EncryptMask + ); + + if (Error != 0) { + DEBUG ((DEBUG_ERROR, + "SetMemoryEncDecHypercall3 failed, Phys = %Lx, Pages = %Ld, Err = %Ld\n", + PhysicalAddress, + Pages, + (INT64)Error)); + + Ret = RETURN_NO_MAPPING; + } + } + + return Ret; +} -- 2.17.1