From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.69]) by mx.groups.io with SMTP id smtpd.web10.19160.1627907486769479616 for ; Mon, 02 Aug 2021 05:31:27 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=Too/sZoE; 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.223.69, mailfrom: ashish.kalra@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kreMKumFZtRf7FvR214eEii5ZyZE+LiFA3oUqUHQM7kxt+ymLmAbpDwwiN72CneGptDE/yd0vjRD1TfeAJgxXM8YJxTWF+jsCMZ4U/19bFtVnaXrT+X5ZPonl1ZYcatFTcMfsG8wReoY2i7qSPPyus2ZppNeQhOToVCSVsYKnYTG7lBqOqgkJoJTKzFC85ntTcQytYf0uVz+HwEjcRIkg/VzUDej27B6wDrKAjZAKW92Zg6zOVW2Jt5N5u7QxoxDgTa+s7tf7u2UtZD9rJVTPBzYYWylHbCmryMWimWwOQ6Ka5OkzkPLPUdTJNkBBukAfsG84xRAKukbyI/2o5bWPA== 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=D188VBlKkP4NPriOgJIz66V2oMhywargAvNpOloWTrg=; b=fn1hi+u9QxLh7cbAauTq3OwM5lLE5ITh1PRAy9U3EPoKr1u7zuULHLJmaQV6kgpENqWltQRSJ6RBQGgkPD/rfgI2WPFVMDqwlgUcbm4MKyv1xFQHoJte8BeZTuCgX8/GDgiQxewaXb6lcsn6cOv8kF8ZmXADMFd7L8gAN6joqtvQonU1XsrHCj+TghvbZkH0YRCiMVU7Oy1MS+fEsyT1v7O1dFbxdq448kETyp8rA0LxXFe/FdlTYd/S8XPxrFFFXvLq87B86G+BbtNssHoqSyggGBE2uIFv4z05TyZL+XqH061sgM3WIBdbSoZL/IvcxdBXxHR0H9sHwpECwOqmOg== 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=D188VBlKkP4NPriOgJIz66V2oMhywargAvNpOloWTrg=; b=Too/sZoEv+LgHn+1vHJQ9AlAkORcovHqKqKh4CJlwGSjAvPs74SvkeFEZQSiKUhDC5W6aRj73hUgruDKn26QObCDMPYFFYWxbbzoHfLbmQYIdHO/ZuJCXdY3itSHtK9nbJQPuboYMqtglu6AX+v+Lv0o+iTPMxfMK+WZUBC1AcQ= 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 SA0PR12MB4590.namprd12.prod.outlook.com (2603:10b6:806:93::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.26; Mon, 2 Aug 2021 12:31:25 +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:31:25 +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 0/6] SEV Live Migration support for OVMF. Date: Mon, 2 Aug 2021 12:31:13 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: SN2PR01CA0009.prod.exchangelabs.com (2603:10b6:804:2::19) 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 SN2PR01CA0009.prod.exchangelabs.com (2603:10b6:804:2::19) 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:31:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dc931956-568a-46d1-b058-08d955b17168 X-MS-TrafficTypeDiagnostic: SA0PR12MB4590: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vaBqEP/Bz77K41o1OeD5A2cuzWRvhzJO+gBe+f+DwNwlV/WzEA5vKIKz3hD6jpUrNGm1cBvP6rBYUOIaFMkei5COjhEL/9iWXMqDNKNf13ifzg05yCTxQBP4IWmn/1APt033olAzc3T+u/2k07A32fkjpiuwM+mGox8cHoSKf/IlQet55cGqH7rmHpKUk8LLvpB17vIzZbyqkznInxGTdY9uHiMORTFTU86tzO/dDO8M824PyUdTv8AOLimI0ezFLSEdTNoUo7MtkbRyHnQagaY2lVRJdc+aF3T8JAQny+pY166UZb2HSkvm7Vkx34dTrFIxx1NlVNAyXIvi8ILVuvRol79/+9CtGj5llHoi9ZkSxeMwcfjyAHCX4cQq+KhQxOB9eVaMM7EgFUODRkbn3ryrUN2aKGIBLEXni1aA/PQ5v1UTIvKmAadeLRzgfzXiBTgRXahBzIYrQA2vc4iR5uaLiUZX7t+8O4jz7ffOypRWfPalFOD5Sz6lSqOEz0xfsi7rZ6g/VeG0nwJpxwskeu0alJIOl7ARfZKIypRExtt45JzzCkFilYY07vEHnfC1CMn3xIhPgBRO9reXNs22GwuraHciQlDGUcUXp7Uu0pchifPx3j9QNDakbQ9glZHfxtyWDWJdEqZfljtZe3hJborcqPD63Rmys6PAzFvZ1NO0L+9+NyGgpT0emYX3yq0NlUNeXzph5Pn1035cu8MGfx/bB9DzHtNKg7NKF3EV3lg6KsPKAs28CcKEjr9DJVxzyc6oxAl2bsYI/DGP6rnPzA== 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)(366004)(39860400002)(346002)(396003)(376002)(316002)(38100700002)(2616005)(956004)(2906002)(6916009)(8676002)(86362001)(38350700002)(19627235002)(26005)(8936002)(7696005)(52116002)(186003)(966005)(36756003)(6486002)(83380400001)(478600001)(5660300002)(6666004)(4326008)(66556008)(66946007)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?xwwu6+w+4QUcuHek6oSp3+fEsGzh/Nx1A+fypgYMMAUawYeMTMSCWzsYYJW+?= =?us-ascii?Q?g2Kc43/Plx5E6L/+bGGlg5XvIrDRcGcSpw7ABfkD+zImkMjKFNThfGkmAxC4?= =?us-ascii?Q?WeqaUt5ROhyi/t4vQYS1ihDV//1n0xn7D8vvJ0o4EbfAZLvw+bDuaBK5QpSh?= =?us-ascii?Q?2s0+yn0/4odeD0vwX4EoMC0uDjifDKwB0BWpCGHO3p7Q0YQlHCmbfcLUJ5qG?= =?us-ascii?Q?mY02EswqaYaZcNn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5EbjdC+G?= =?us-ascii?Q?F0x98P567jWEBhUk30ket7kljzT/LD+bflhiGhVOE4GnoOAGMDaVUz47Tfqj?= =?us-ascii?Q?U1SnjkmWbDYDtXNDc7vHdZwOwzJCvyWddA+HnMzWmfe76GS8PEQClLzvcZjC?= =?us-ascii?Q?Vv8xY0oqzkGWTI7U92oRViv6c9uuT1Jf5QpQGDo0NO04A9WzTTpthUQCCeiW?= =?us-ascii?Q?3HzvcSBCnSJznWU1QBrTkQ+t?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc931956-568a-46d1-b058-08d955b17168 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:31:25.1553 (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: Opvz3o6a6kzHYdgRbM5hv9Sg+EsLsUx0kBK8DWftcrL3fqObrQv8A0pUGQ5dadUUuXXCQnTk9n0fnJP+VtFn/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4590 Content-Type: text/plain From: Ashish Kalra BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3467 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. The patch-set detects if it is running under KVM hypervisor and then checks for SEV live migration feature support via KVM_FEATURE_CPUID, if detected setup a new UEFI enviroment variable to indicate OVMF support for SEV live migration. A branch containing these patches is available here: https://github.com/ashkalra/edk2-1/tree/sev_live_migration_v5_10 Changes since v5: - Split first patch into three components, one patch for the MemEncryptSevLiveMigrationIsEnabled() API, one patch for the SetMemoryEncDecHypercall3() API, one patch to make use of the SetMemoryEncDecHypercall3() API. - Fix patch subject, in code and patch comments and additionally add relevant comments. - Replace SetMemoryEncDecHypercall3() API's Status argument with a boolean IsEncrypted argument and corresponding fixes to users of this API call. - Fix AsciiStrCmp() usage in KVM hypervisor detection code. Changes since v4: - Remove MemEncryptHypercallLib Library and add support to issue hypercall in the BaseMemEncryptSevLib library itself. - For SEV-ES, make the VC handler hypercall aware by comparing the hypercall number and add the additional register values in the GHCB. - Fix comments in the hypercall API interface. - The encryption bit is set/clear on the smallest page size, hence use the 4k page size in MAP_GPA_RANGE hypercall. - Make the hypercall expect the guest physical address to be page-aligned. - Add KVM live migration feature flag check in BaseMemEncryptSevLib library similar to how BaseMemEncryptSevLib does for the MemEncryptSevIsEnabled() and check it before invoking HC. Also export the MemEncryptSevLiveMigrationIsEnabled() function as part of the library. - Add error handling on hypercall return, on failure, return error code to caller which potentially will cause an assert() and terminate the boot. Changes since v3: - Fix all DSC files under OvmfPkg except X64 to add support for BaseMemEncryptLib and add NULL instance of BaseMemEncryptLib for 32 bit platforms. - Add the MemEncryptHypercallLib-related files to Maintainers.txt, in section "OvmfPkg: Confidential Computing". - Add support for the new KVM_HC_MAP_GPA_RANGE hypercall interface. - Add patch for SEV live migration support. Changes since v2: - GHCB_BASE setup during reset-vector as decrypted is marked explicitly in the hypervisor page encryption bitmap after setting the PcdSevEsIsEnabled PCD. Changes since v1: - Mark GHCB_BASE setup during reset-vector as decrypted explicitly in the hypervisor page encryption bitmap. - Resending the series with correct shallow threading. Ashish Kalra (6): OvmfPkg/BaseMemEncryptLib: Detect SEV live migration feature. OvmfPkg/BaseMemEncryptLib: Hypercall API for page encryption state change OvmfPkg/BaseMemEncryptLib: Invoke page encryption state change hypercall OvmfPkg/VmgExitLib: Encryption state change hypercall support in VC handler OvmfPkg/PlatformPei: Mark SEC GHCB page as unencrypted via hypercall OvmfPkg/AmdSevDxe: Add support for SEV live migration. OvmfPkg/AmdSevDxe/AmdSevDxe.c | 64 +++++++++++++++++ OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 4 ++ OvmfPkg/Include/Guid/AmdSevMemEncryptLib.h | 20 ++++++ OvmfPkg/Include/Library/MemEncryptSevLib.h | 70 +++++++++++++++++++ .../DxeMemEncryptSevLib.inf | 1 + .../DxeMemEncryptSevLibInternal.c | 39 +++++++++++ .../Ia32/MemEncryptSevLib.c | 27 +++++++ .../PeiDxeMemEncryptSevLibInternal.c | 52 ++++++++++++++ .../PeiMemEncryptSevLib.inf | 1 + .../PeiMemEncryptSevLibInternal.c | 39 +++++++++++ .../SecMemEncryptSevLibInternal.c | 38 ++++++++++ .../X64/AsmHelperStub.nasm | 33 +++++++++ .../X64/MemEncryptSevLib.c | 62 ++++++++++++++++ .../X64/PeiDxeVirtualMemory.c | 20 ++++++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 13 ++++ OvmfPkg/OvmfPkg.dec | 1 + OvmfPkg/PlatformPei/AmdSev.c | 11 +++ 17 files changed, 495 insertions(+) create mode 100644 OvmfPkg/Include/Guid/AmdSevMemEncryptLib.h create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/AsmHelperStub.nasm -- 2.17.1