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.42]) by mx.groups.io with SMTP id smtpd.web10.70312.1629381784769098397 for ; Thu, 19 Aug 2021 07:03:05 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=gj2WDUVn; 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.42, mailfrom: ashish.kalra@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Nsggzmz5loDi9GGtfLAFqJNZRtDEJaJCEZEBfcDvjo/PRzVwWvvGSl3gVyj8LrKSPw9ga3MZw3aG+kuMHTULXZzF5C9hUUd8Xrs08yuyxZB1NFhHoT/1o13wGiuQ+PIk85wR7hwsJrVOlMjlUyECTjhjx3YGlP6PF/jVVGWIWQizcQF9QfLo3OlPhrfgXWncQG//D2YJaWEywFzmAYwTsd30yAp708M1SNrKess3069rGFvOlW13NVr19zIm+K3davvvKSzrK3qpg1hz3aeXRZiApxrBD9uf8ZzQqWZ20y2Aw7JNKekV2iLzhEcfsfpj54swLWilHovVoWT7PUaoSA== 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=Z/5njz5zlW6sGYFVL+ZOZqkPtB4R41hvaZrcYQZJpy8=; b=cIeZPlPPt3Ml46MIPceYUTmZkJybA5Oc4UIp7Eb/HewmR6PJra3ZGIre0fSsuAsqoxSWNSBLT/9sKuisRkMZiEU+ctp7DcueW5Dwu7AGcE7Nu1dL46TKvhdq21Rw6NU0jcmPiMMmqFFo6ntgQoud3Ag/DVhvR947PuVZ60ZbU0s7ir79cGUylZs9u46ACsNijW8fQbggpIEPiiDXeKpwOEqgP2mpFYBmx9N4U2GBLDzc62Z8OgFnBCU4PjetM2Jtnn2EMQhgtH5j5EHJUiwWUYRFjnu4RsHG0Ilh5QqUJnULz7hw7sAS8Vipp+u/t7c/G4Sc5IuVKf94181wpNIETw== 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=Z/5njz5zlW6sGYFVL+ZOZqkPtB4R41hvaZrcYQZJpy8=; b=gj2WDUVnXeQmaxQiCRikv2QekfCh+0HLDzGqzMX8rbrZf8uggYUeFEjV9eZVl8/0LIonjKMFNRIHqp6pnAc6BrBMGaAldiqm7LEiNQKeK69S+s4HvlmmFpKhA7zA9wrbJvdkVAzOwRoPkcGuujTnS9lXcwf6cTh28oGJWqAJduI= 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 SA0PR12MB4512.namprd12.prod.outlook.com (2603:10b6:806:71::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.17; Thu, 19 Aug 2021 14:03:03 +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.4415.024; Thu, 19 Aug 2021 14:03:03 +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, erdemaktas@google.com, jiewen.yao@intel.com, min.m.xu@intel.com, jordan.l.justen@intel.com, ard.biesheuvel@arm.com Subject: [PATCH v7 0/6] SEV Live Migration support for OVMF. Date: Thu, 19 Aug 2021 14:02:52 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: SN4PR0501CA0077.namprd05.prod.outlook.com (2603:10b6:803:22::15) 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 SN4PR0501CA0077.namprd05.prod.outlook.com (2603:10b6:803:22::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.6 via Frontend Transport; Thu, 19 Aug 2021 14:03:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 85d10a0c-799c-4f36-d12d-08d9631a0f81 X-MS-TrafficTypeDiagnostic: SA0PR12MB4512: 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: B+VfffNJbwEPz2jAeAfUfJfDohuzesUujAjIABuEfzNvT0x7DB8xPppUbAnv6U/Mzzl9wrQk8omzwhHBbBFLSYFM09zIfY7c3kznFKV6PgMDGfnD8/eqj2XzIXtqQPsVBqbw+X1Xqg43wPrJqR8ieceWK04IrM6qq7XOYw7S/VWPmIwF5PL0Zk7O1Xgg9i/AFhQkFUhpdxVTX07aDdpvGrOi2exZxaglHCY0HBVhKFqJlYY0/j3Xtfc53UF/QOqUn5pyLMpEzzkIGiCGRVwUxES+0lQK21dByMHwlnBPLyAOudlVA4tVq0qX+Vt9fQKPIHSiro4ih2m6nXJm8oZhC5bkFwrEbHVTq0+J5iWIVtPlN8dqaFVlc7+qR8WTKxjMtLrr5LRpthfxImopALEqGuxh4ai1wIXm80hfGvjwGnHEE+EnD34JYGHDFG6/FfDlxcc43voNyeWKHtdjZn3Jul6GXVJNh1M6uLLcbCqwmGnMcaJxB6dtOvqw2nTTO3Y6yMu81KZWpEM3w0QxI2CEP740kyk54wGCh5g+bIRBJIWD+ONRIzfsDQqwDxxlQa0IhrUWPMN46UBA6bdJ59NLHv4xcMdz0/Y1Pv1SI2UzLqm303qqHIWS3x9Jr+1cYqgKDHZeFR2gm+xpsAlBMOxhYGqNCTA6fe6Eak/sQf6WD0WfL9WJifBJHHua+Yx37n7MeuFujd6X6z+i4dLBj2YcV4VoAzcPRcCqekUoeRoS0TmYftSry0sgmPILAfTzoNlrMqADc9Vp9r/3aeRLlUccbn91o/Nh7Kkpy/+C0ovPW4U= 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)(396003)(346002)(136003)(366004)(39860400002)(376002)(6486002)(966005)(316002)(19627235002)(52116002)(186003)(38100700002)(66476007)(36756003)(86362001)(66946007)(2616005)(7696005)(83380400001)(38350700002)(66556008)(26005)(956004)(8936002)(6666004)(2906002)(4326008)(5660300002)(6916009)(8676002)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?8uG9Ugc7sn2cFnmoElOGTiI6kXrwoMcdOc5VOILF0het4hHtHFZnFuk4GuNF?= =?us-ascii?Q?Qd9ZiLgZrxFBzjcO9I2MLwMzc5oESb8Coc9vURtu+uEnV2ALvJwbF2d73agg?= =?us-ascii?Q?YzbB4OaOz55zT6T1LWYPTz6k94aqMVgU8AKcMf3SgLsZjefZN4I4hedjESRe?= =?us-ascii?Q?gEbqnn836UUTiFEVQJOOv57+SCNEM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QVDGXlfIPR2TbAboVj4SoW7tCwKWewBfOcpwy73BZdIkhCqvJPB8Jkq3Uxdm?= =?us-ascii?Q?u+itIx5zvOaQaN91BWpc5BrHlOXlzpBGTG2kDc6BA1+hnGtbFECYHWPfT7Ts?= =?us-ascii?Q?FOhrKuV+wPII4Hmn8cGepeqXccxufidtBosoUey4cL6GkdIscEqYTp3qWlsS?= =?us-ascii?Q?dJiYoQphDx2kFr4GxvtmO+8C4joy6TD5Ui2iu6oZxSigkuJ9eJbmcR4di+1c?= =?us-ascii?Q?SpJgos1CtuuY16lL4YJkRuOA?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 85d10a0c-799c-4f36-d12d-08d9631a0f81 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2021 14:03:03.1730 (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: OtPrq4zIOF+UTWATHfdIUkpYf+ASmlVjh956tjMJnvty1HTMlCx0159hlXOodCn9vg/CY38PNg22K6C8NBxYew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4512 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. This environment variable is created by UEFI but consumed by the (guest) linux kernel. This is actually part of a 3-way negotiation of the live migration feature between hypervisor, guest OVMF and guest kernel. Host indicates support for live migration, which is detected by OVMF and correspondingly OVMF sets this SetLiveMigrationEnabled UEFI variable, which is read by the guest kernel and it indicates to the guest kernel that both host and OVMF support and have enabled the live migration feature. A branch containing these patches is available here: https://github.com/ashkalra/edk2-1/tree/sev_live_migration_v5_11 Changes since v6: - Move KvmDetectSevLiveMigrationFeature() function in a new header file PeiDxeMemEncryptSevLibInternal.h as this function is only used internally. - Code Style fixes. - More descriptive comments for use of SetLiveMigrationEnabled UEFI variable. 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 | 64 +++++++++++++++++++ .../DxeMemEncryptSevLib.inf | 1 + .../DxeMemEncryptSevLibInternal.c | 41 ++++++++++++ .../Ia32/MemEncryptSevLib.c | 27 ++++++++ .../PeiDxeMemEncryptSevLibInternal.c | 57 +++++++++++++++++ .../PeiDxeMemEncryptSevLibInternal.h | 31 +++++++++ .../PeiMemEncryptSevLib.inf | 1 + .../PeiMemEncryptSevLibInternal.c | 41 ++++++++++++ .../SecMemEncryptSevLibInternal.c | 38 +++++++++++ .../X64/AsmHelperStub.nasm | 33 ++++++++++ .../X64/MemEncryptSevLib.c | 64 +++++++++++++++++++ .../X64/PeiDxeVirtualMemory.c | 20 ++++++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 13 ++++ OvmfPkg/OvmfPkg.dec | 1 + OvmfPkg/PlatformPei/AmdSev.c | 11 ++++ 18 files changed, 531 insertions(+) create mode 100644 OvmfPkg/Include/Guid/AmdSevMemEncryptLib.h create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/PeiDxeMemEncryptSevLibInternal.h create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/AsmHelperStub.nasm -- 2.17.1