From patchwork Tue Jun 29 15:12:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12350183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49606C11F69 for ; Tue, 29 Jun 2021 15:12:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3041E61DCB for ; Tue, 29 Jun 2021 15:12:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234658AbhF2PPB (ORCPT ); Tue, 29 Jun 2021 11:15:01 -0400 Received: from mail-bn8nam12on2052.outbound.protection.outlook.com ([40.107.237.52]:21856 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234613AbhF2PO5 (ORCPT ); Tue, 29 Jun 2021 11:14:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oUE0Clgrzhi8yvUriqzHvanMpVx3wiifbrxZ1Ixfk7IMuydmsdYxPdPhdHZ+azSVEdEedwvjsCH2Ylov5v7CPGzU8AibGRmRW6KwLrvYQXIHulE2HaFllc43Ph48or+tsfrew6SoofqCBlwTZ/uSiyweSYa5DQN46tuUSwkwkV+8VDQGTtKalHI4vCi7usbUnQ8UG8AkDe6S8zmwh0vW45/3LWBZR1pYEwcazsYvqy0wYwLhTWHsfxDaCEOnqbcKujwlBMdDIOCnCpm8ubbRuRumfpGRoWAnOLS4waeII/pILmaGNvsBhi74jC/jtSDYTxa+X3FBEuRXWLRNxKuB1Q== 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=gxv5u9AjEffeO1GiR0PBJhW7kpWnSHjYiN4f3WYMI3o=; b=G2WuHCQDX9Blqdi8bhD+Bvpfhp1SXGjE0ImF298AHA2Mq9NXgTfrTc7pC6tfl7nHaQosb10HNMpB5HX6Mo1r3krF4hxn8uBKzXnkP19NQnBGt4lsfec9YnSRFlYQduFm1mgFaRGbkSnyVWX8tiEyML4A9b8WIY6UtqOUbLOgAK/kJMb6X52mPeSrNp8n7v4zgl844FCZvvLNE/Bh+qmtn/9yZz/8NPgb2xJlVPsqmYsummPjeRX83AvBd4Z1Xu9E7bHRFM6lPJdmF1MOfhbPphA5fdbJ/iwnS4BZ6e1pcXNWZkyVgN8b4w4UgZzaR5YyI2ZXxKaH65YGZHBL8gBGNg== 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=gxv5u9AjEffeO1GiR0PBJhW7kpWnSHjYiN4f3WYMI3o=; b=Y3mCi58wY4Ba1t+u7XKzoQLr7sZKpdaFgUfLZte7K55Qd+SLheoIFeXkEdo4GKRCEwGlkoS7hmkOb8Yvwsc2hxSwOXQ2psf7RvlWa2LeM+UQn3WI71xj6tZzij2OSG2MPB70cfusv4pkaV8mIgZOUoGyXnMKSUq3TKDEBcpRIbg= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB4671.namprd12.prod.outlook.com (2603:10b6:805:e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.23; Tue, 29 Jun 2021 15:12:28 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::958d:2e44:518c:744c]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::958d:2e44:518c:744c%7]) with mapi id 15.20.4264.026; Tue, 29 Jun 2021 15:12:28 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: seanjc@google.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@alien8.de, Thomas.Lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, brijesh.singh@amd.com, srutherford@google.com Subject: [PATCH v5 5/6] x86/kvm: Add guest support for detecting and enabling SEV Live Migration feature. Date: Tue, 29 Jun 2021 15:12:17 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9P221CA0006.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::11) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA9P221CA0006.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.21 via Frontend Transport; Tue, 29 Jun 2021 15:12:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 698210f5-b35b-4947-0a75-08d93b104efc X-MS-TrafficTypeDiagnostic: SN6PR12MB4671: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:238; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bYeXjDFhfYlWEzBMTVCwj4Bs77tfzAwdSUXoGZioL3i8uQKG3iR4cw9J93QpfvrwdqZ/NtvZGBqWTgc1L2v8qc/UKlCR1BFHt2enAT52cTS2OKF5uwaBoajTwaCpJfk/fKXPf9LN9sd7vfYuSHm74SjhZMX/dBzfZjb/zaXZUBstxLHNuU64mPPgDshh5UJLcDl0Nxuai+P5eLl7djKVyyJRF33c9SZFHLVhqtxfKAVTxKVRR39Uxx8bU/46SDGcX3fpPSz2tUCKKURPLG35b45b0DGp+jDrRHB/ZoFEYXffy3L2Wu33YFUG7yeYNu8KmI6M/sNA/4oXyyjQ0zwKappuA/jMDb7cvHVDKZJWFi61KYI5+5c83GYmOJnAFHY3BVkI2tYjlDp/wREca44l/LfWJ6mtubagUFy0nYPpJpxWLDCEXWsZJU2dEh7mwlkehw/u9oK7sLQkyWXwx/tMVeqt21aIySvngMaYP9v3/VwqUCtP58eS6eIWCtSi/U4xqFyPlb97imICiICTpHuh3xaZ/D2FhppHy/GkhRlH0pIz1pqRKtsLy4CyAm82+n8VWWzIRwTzY/k2i6dv3CprhfO+20k6FJgOxQpGhaFkqjN0C2YCiQZ2nDXUk9kdMXNQR/f+vWKpt+kr7URu/xKxg/h+IW2ue30xKESR8HVQDiLQ0jH765pBNIxGgDxc4GydTNp4fWPWR90uxlqa+jrnPg== 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)(376002)(346002)(39860400002)(396003)(366004)(8936002)(316002)(4326008)(6916009)(5660300002)(7416002)(186003)(38350700002)(83380400001)(16526019)(7696005)(8676002)(26005)(6486002)(36756003)(38100700002)(6666004)(52116002)(956004)(66946007)(478600001)(86362001)(66476007)(2906002)(66556008)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PMi8m2pirZ6fRGyNMytZ6bJsCzIX/SsHxLfoxcRvNtf9xVrjI7RE/1/vuPeEVqmJqHGjq5wWQwqfho9wvOFQEbXuLELapYAB+JRqPbkxKbYyMsYO3ffazFs58FNgGhFxktXy9kc+Yhm+wYBkcxDruZ1+JBW1ZWnZpPIh92VgbSKV3jbJZtiGRiZeYa3yW/9nxqgijT0u81bE8kC2LcIsdZShpkTvOldShtBU80ASPTtHPlk2PxT91TSfVuSnuaFmE4V7Qq5RLo3e9Xizvz+71XH75bARbJyi6CHQ5e2nWgQXlSmjKF3zRfjGw7qxBMWVE1FtCf8XSVEq9vJqFjBZ30CVDj/Nnl0bk2XMSzp1KrfxGVOEV4sqPRbdaCj1CuzG50adB5qVrSv6PkptQt8zxsE6cepjRe+cmaXFCwGtaFrHCXOE76GlEkKEJ0QO82fBzw5ILcJbXD9E3+KWGZgD5s3BYLbz1nlJRnpHqGuH/OY8lPZp1fi0brI7f+gItp8sRpVRNi+8hGSta5OEFY6xEMlLIT5cYeoedM1xz1liV74Mr2fHVy7EYih40oPlWwA1WWbLkH1jxGBWo7GHLh9BOYnNjGLfSWyNIukSir0uGAWq8FFgU/QSJHFAjI/RNmdNlv2rXL9ffEjgWb2bVAnjQvf7Iq4Sl8lo2D5KtBIm9ccYa+pg4IRVHQ61miH9sEjWSlHenWNaYUdXdeYV203DI4rDpDum7+41L/pFE9c21pBP+tZauCaL4neba+4Z2o6ZnqRSVUNg18OtwXGb8FqqXZDaOyzpxk19M0Vifh0iF2lTa1x0qPXbU3ZSQ6MAp0b6AcciHGqIqTSrHW6VPOMVqo8CJo8HvJhZAAGNBOjOqwCEP18zArjfPKIPeyDOjxLUlHQvXWxQxg/B9dD93Y+uA0B42HzHTgesZjWI84IpxNCAD/bGp+1wgjvGLhUBzzZ0hY3yfcvc2g/v1O907Y7lbLOc+4+mHE6oOmulUyefgBHwPrzhokRLVb2fXq6NgdVD6Tez06h2DDrVqT3nAyao2/3NufSzUgVOhPTwQphfGe8zYDz8+khBXs0WzJScWksqHBHWh2u+UskY8f9YTnYJFBaXgN2JjdrQLIkBaBfKERoq8JxJfybtLe2O3otDYvRF64oUoUA/XF97RgAnmpWAo5uGUsEQsZCuHfqWT9ulb/6A6JcqpqQFCQGnz5KsHhtDGlQ7ndrrXR0o3Kdn+GHEwjsJf0yRtNgIDGM9p9XB+exhPHXBAJdTej2+UC3zzDixFqYfLYXGAXBhsQMZnP2xmzLQIJKCfK+8aRkiMBQdpbDg8TDqJBXXH/MOyZsw9PC3 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 698210f5-b35b-4947-0a75-08d93b104efc X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2021 15:12:28.2010 (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: knkgjINXdubzcg8HCVP4LC01s0Zpd7uPzzy98t7vfnxe7S9XgRvNzBFUiIO9tCh8J4SKctxpB4+ioxXpDZyekQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB4671 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra The guest support for detecting and enabling SEV Live migration feature uses the following logic : - kvm_init_plaform() checks if its booted under the EFI - If not EFI, i) if kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL), issue a wrmsrl() to enable the SEV live migration support - If EFI, i) If kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL), read the UEFI variable which indicates OVMF support for live migration ii) the variable indicates live migration is supported, issue a wrmsrl() to enable the SEV live migration support The EFI live migration check is done using a late_initcall() callback. Also, ensure that _bss_decrypted section is marked as decrypted in the shared pages list. v5 of this patch splits the guest kernel support for SEV live migration and kexec support for live migration into separate patches. Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- arch/x86/include/asm/mem_encrypt.h | 4 ++ arch/x86/kernel/kvm.c | 82 ++++++++++++++++++++++++++++++ arch/x86/mm/mem_encrypt.c | 5 ++ 3 files changed, 91 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 9c80c68d75b5..8dd373cc8b66 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -43,6 +43,8 @@ void __init sme_enable(struct boot_params *bp); int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size); int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size); +void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc); void __init mem_encrypt_free_decrypted_mem(void); @@ -83,6 +85,8 @@ static inline int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0; } static inline int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; } +static inline void __init +early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, bool enc) {} static inline void mem_encrypt_free_decrypted_mem(void) { } diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index a26643dc6bd6..a014c9bb5066 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include #include +#include DEFINE_STATIC_KEY_FALSE(kvm_async_pf_enabled); @@ -433,6 +435,8 @@ static void kvm_guest_cpu_offline(bool shutdown) kvm_disable_steal_time(); if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) wrmsrl(MSR_KVM_PV_EOI_EN, 0); + if (kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL)) + wrmsrl(MSR_KVM_MIGRATION_CONTROL, 0); kvm_pv_disable_apf(); if (!shutdown) apf_task_wake_all(); @@ -547,6 +551,55 @@ static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector) __send_ipi_mask(local_mask, vector); } +static int __init setup_efi_kvm_sev_migration(void) +{ + efi_char16_t efi_sev_live_migration_enabled[] = L"SevLiveMigrationEnabled"; + efi_guid_t efi_variable_guid = AMD_SEV_MEM_ENCRYPT_GUID; + efi_status_t status; + unsigned long size; + bool enabled; + + if (!sev_active() || + !kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL)) + return 0; + + if (!efi_enabled(EFI_BOOT)) + return 0; + + if (!efi_enabled(EFI_RUNTIME_SERVICES)) { + pr_info("%s : EFI runtime services are not enabled\n", __func__); + return 0; + } + + size = sizeof(enabled); + + /* Get variable contents into buffer */ + status = efi.get_variable(efi_sev_live_migration_enabled, + &efi_variable_guid, NULL, &size, &enabled); + + if (status == EFI_NOT_FOUND) { + pr_info("%s : EFI live migration variable not found\n", __func__); + return 0; + } + + if (status != EFI_SUCCESS) { + pr_info("%s : EFI variable retrieval failed\n", __func__); + return 0; + } + + if (enabled == 0) { + pr_info("%s: live migration disabled in EFI\n", __func__); + return 0; + } + + pr_info("%s : live migration enabled in EFI\n", __func__); + wrmsrl(MSR_KVM_MIGRATION_CONTROL, KVM_MIGRATION_READY); + + return 1; +} + +late_initcall(setup_efi_kvm_sev_migration); + /* * Set the IPI entry points */ @@ -805,8 +858,37 @@ static bool __init kvm_msi_ext_dest_id(void) return kvm_para_has_feature(KVM_FEATURE_MSI_EXT_DEST_ID); } +static void kvm_sev_hc_page_enc_status(unsigned long pfn, int npages, bool enc) +{ + kvm_hypercall3(KVM_HC_MAP_GPA_RANGE, pfn << PAGE_SHIFT, npages, + KVM_MAP_GPA_RANGE_ENC_STAT(enc) | KVM_MAP_GPA_RANGE_PAGE_SZ_4K); +} + static void __init kvm_init_platform(void) { + if (sev_active() && + kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL)) { + unsigned long nr_pages; + + pv_ops.mmu.notify_page_enc_status_changed = + kvm_sev_hc_page_enc_status; + + /* + * Ensure that _bss_decrypted section is marked as decrypted in the + * shared pages list. + */ + nr_pages = DIV_ROUND_UP(__end_bss_decrypted - __start_bss_decrypted, + PAGE_SIZE); + early_set_mem_enc_dec_hypercall((unsigned long)__start_bss_decrypted, + nr_pages, 0); + + /* + * If not booted using EFI, enable Live migration support. + */ + if (!efi_enabled(EFI_BOOT)) + wrmsrl(MSR_KVM_MIGRATION_CONTROL, + KVM_MIGRATION_READY); + } kvmclock_init(); x86_platform.apic_post_init = kvm_apic_init; } diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 455ac487cb9d..2673a89d17d9 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -409,6 +409,11 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size) return early_set_memory_enc_dec(vaddr, size, true); } +void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, bool enc) +{ + notify_range_enc_status_changed(vaddr, npages, enc); +} + /* * SME and SEV are very similar but they are not the same, so there are * times that the kernel will need to distinguish between SME and SEV. The From patchwork Tue Jun 29 15:14:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12350185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0352C11F67 for ; Tue, 29 Jun 2021 15:14:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A45D61CE4 for ; Tue, 29 Jun 2021 15:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234682AbhF2PQt (ORCPT ); Tue, 29 Jun 2021 11:16:49 -0400 Received: from mail-mw2nam12on2055.outbound.protection.outlook.com ([40.107.244.55]:41441 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234642AbhF2PQr (ORCPT ); Tue, 29 Jun 2021 11:16:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YSPra1eaNBXOqWWLouH2iuJqKl6HmaEozIhXfwwXHZ0l4R8AXwjRCIYBwZ5Z/0xpAWsOL7+etA/JdwWGOWQCdCurqBnGfQ+jfXYVjaEZo99bX33i0eEOc8cMjrw8lESMzJRRyTKzdJcanmFGQsjc5Vt9YRkWewstFvHT8ZYs/8wOkgOT9bNVbMkBqNbh/q3EX6KdN+l97x8hl4hCjv0emPASVQnzRQFGgUutOYpTxL7t4uhV1G4MCfzcS16cG94Fvzx/hYpgIpv6bg4GRpC/iZtoffZ32KYEud0TvaEOK3GBfk6SliWhya4ih7h8qJPxyGIp6Orm8YE/ivxkwYicLA== 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=8zTW3gIaN5xuLG9gnYJybBASVdTG0s5L9dAdAX3I1Dw=; b=f1AEkcOen0YcWzIGECkAxA3l0/h6d1vpMs6EUatPIMdPOwjU0RTD9ekssmHAneyQPGJzLz/tj2Gld1S/nz9jy7KtEIUHNAyckUAAP9PWF2TVmYTJwEJdnuzrGu+0/SBBEsICFyxKQ5n6bzj/qqSH5biMv6C+iVaDgdACzHsm8PJa1xN1U89XkwfEQtgeEstx5pftv4EfTX2CReYT4qE7YkBlpBtazqaDwbpWhLaxq/xgfzQD3vf6ihXWCyqgW/UacFJj0/2KTk9EaGwzRMXDlK3ieZnjYPy+wRe2keIX7MwR5NfaedqoMIejijl53bs2Ky+Re4y4aqqyC03oMfpsGQ== 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=8zTW3gIaN5xuLG9gnYJybBASVdTG0s5L9dAdAX3I1Dw=; b=gkgvXSbxEZYVcfLUi//iRwNl6wM1uzlkBGvkDCLaJleJh4jQ2ToNwfN41Ex15ZOlP2YxxAzubA5E3kcDwII39EY1nlO2l0gg9OqKfgMVO+uFM81mkYVkDL5D/z5Erh0RQ9VJA0BRJdzU1ows8YAHYBaWjC34ILD/mYYEpieknMM= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4413.namprd12.prod.outlook.com (2603:10b6:806:9e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.20; Tue, 29 Jun 2021 15:14:18 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::958d:2e44:518c:744c]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::958d:2e44:518c:744c%7]) with mapi id 15.20.4264.026; Tue, 29 Jun 2021 15:14:18 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: seanjc@google.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@alien8.de, Thomas.Lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, brijesh.singh@amd.com, srutherford@google.com Subject: [PATCH v5 6/6] x86/kvm: Add kexec support for SEV Live Migration. Date: Tue, 29 Jun 2021 15:14:09 +0000 Message-Id: <8fce27b8477073b9c7750f7cfc0c68f7ebd3a97d.1624978790.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: SA0PR11CA0008.namprd11.prod.outlook.com (2603:10b6:806:d3::13) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR11CA0008.namprd11.prod.outlook.com (2603:10b6:806:d3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.19 via Frontend Transport; Tue, 29 Jun 2021 15:14:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 228246eb-0d2b-4b0d-8ef0-08d93b1090d8 X-MS-TrafficTypeDiagnostic: SA0PR12MB4413: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9b4TnzSciORtaeAqWIJWTGSg2oWTbd6JELNotPBpcwoLI3LTCbdNjxugOhFlEQUJJjFmwr9o+Rh1r4Bt+Li2ruybkpaBdx2AmV7ZorIFYtxak5gQ9vdh4nxyJ9alcjE6PUbPLfsoXCPHQ34OcjMlho/vOwS150tjId9HyAoc/25Z9TRE1ulVTkNJEQ4uyqwMoImc8NgrX3J2Th/scdHlBDZGbRFI8zhDrGEGOTFb966/a26wYnGZ5BqZmHEoU2a5s5n3f+lGZeMrouOQw0A+LykkVeTku5SArawkK43NoqaFrUN5RDRPwMx5M9fmB5927qdviSDUDfMHeaewOHHnexBGSbMv6z53Wp4zprHsxjcwlSZtp+gg933Vfg4tZHvwEg1G9ypYL9cOJ8pshOT5HmnVmzLF0P8PEAM78IkMTXntpkkGFvkogj5K3Mg4MttpoPhhDakgAoRferpe6u15iIejEtFJ5fkTHwP0PEmz5kBypUtXoMmDkrbOZLyNWcwndV5eCD2gD108lVuCrOn7oMjqy/3vWe30rwrUAaQT9sN1UDDARGOtDEa1INDyxAsM9xyloROP/5hDK/SS3a6khicaCzJERuRD7rRTWa8cm2zL9vrmj4FeSWs/Wm+rmvnrJUmdKaMLrp+vqQmOwJSehAPmWzSZz/pUuSZOhvzWDOagXhTgSG/AtmO+mzIPTOL15IOdaxUspdRwz/ad2GZuBA== 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)(376002)(346002)(39850400004)(396003)(366004)(6666004)(6486002)(316002)(7416002)(26005)(16526019)(186003)(38100700002)(38350700002)(4326008)(2906002)(478600001)(66556008)(66476007)(5660300002)(7696005)(52116002)(956004)(2616005)(66946007)(86362001)(8936002)(36756003)(6916009)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PNQA0uyti88+OEsg1xNxaqJz7QIHpUS05skmiPiAKkp2Dep5sgAkj4Q2rO3eM/IiYy8ceGu24s3HQXGbVW87Nnu/HcDugcjCvF44DtVUJvtvdjq4Xi6zwpCusuh86CTh4D3dGISUDB4BvCNp0gvTM3d/2dtobzx5XIVg4FfPqLmRO4Y6Kr1Xvwre9QMwhDj1HNTtYzds/3/f511HzVn8HynRwLrn3BOkT3gFyvdAkGYcuDwMX1V2vsCCqZtLoY+H8R7HJzWHc8TEyz2nExXRiNk1+AKmkdE1by655GH7HIzIbrlJWfQyB7nd2CsUPeWrupaugLMWOIIhXeFuLpTlrT9c1oRRBiysCg3f5hp3PCYhD/HOJ/ztrwWyqnIZlHx2ap60Vs0g2ZTEyQV3VjragIqXsrkMfZWIJTIa+MW1Ht329ZjBGRG3mG34hJumBtWHiaF1XCnoQb28960Yh8EcLPx3iV9MG0qXMnAL79jd6hLp6d3cEBd52wOTcKRMIaIs4W/yQIPQontu7FsnZfoJmJ5/KXnNXNujpMFLEcCrH3M0Ai5anpDx8ZIOrADz02k22CnUIkX0P4Uf5wtnoKDIpNGhOuzFOSnxKlu6ELO7h3nvjdWpfGQptR7Oeaw4jSydxTcO6YfP7iyHUazZHQw9bX7QIoe0GrUexC703xDdxVK1YTn3o9H0qkEEKqCqwtbQloUKzS48C8jipFKiW5Dvs2OvcTwuW+HcG1ZlIlwwu+L7qG6qzY4GE8dvS+WCXQERL2/DuhZ0lcZbpdCOwmhqz5xdRk4VyfEJnXT5RIB+nLMDEi2YJEtaaP7m713dd7UVIzT6VKCkIngi3dzd0a6UN1wGt0tfQwYSyOW/nroTVE364gBRLS5/bbv+mefJP3Z0vVmi4jZrh1MhGApxaRvSC9wrGaZAXnDAibs/94M/MXiboyavTv5xLd02YgPbC4sU6sOcOpc72M/KTrcXfJjtaBfS5lLB05LPJbpqIrVjrI5IHgdZ7PyVGM+OvBQ8k4eT1EenwhC/8nb6l39l3JwO4MbeCAQ2OsZ53YnMYkcnpWNjaWA857xrojH+wWb87EJbEKmdfPsJ7VHn9vMD4MVYSztX1zEyAHInRRv+I5kS6BmTzxCiLmv3Y2R2fiFgrFQiJYttoD7kCUyxKeMmUIdMBpxhNWTGRTv9b89hDr9Jkr1jNuxBSaF9Cfh+Jr7nw5aKESYDtwpTG32k38JBrvbee57QSMkOncrV8VG38uKB0pjHbTUOdwPWmWViyp9nDbtaNDDNcXKJj1ytXMftGulkmm6NtdF+17oionoLASuy/lHhbBqBjlg0WpaAqzsiJWBP X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 228246eb-0d2b-4b0d-8ef0-08d93b1090d8 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2021 15:14:18.6751 (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: Jiey+Bf4wSuVI32OSZ288aIz2fhZLZJ8fl5H5Vl2gvIjuRJZIDBqa04FF/NqOB6krr1QFEtTdcXN7BTXxuEkVw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4413 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Reset the host's shared pages list related to kernel specific page encryption status settings before we load a new kernel by kexec. We cannot reset the complete shared pages list here as we need to retain the UEFI/OVMF firmware specific settings. The host's shared pages list is maintained for the guest to keep track of all unencrypted guest memory regions, therefore we need to explicitly mark all shared pages as encrypted again before rebooting into the new guest kernel. Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- arch/x86/kernel/kvm.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index a014c9bb5066..a55712ee58a1 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -869,10 +869,35 @@ static void __init kvm_init_platform(void) if (sev_active() && kvm_para_has_feature(KVM_FEATURE_MIGRATION_CONTROL)) { unsigned long nr_pages; + int i; pv_ops.mmu.notify_page_enc_status_changed = kvm_sev_hc_page_enc_status; + /* + * Reset the host's shared pages list related to kernel + * specific page encryption status settings before we load a + * new kernel by kexec. Reset the page encryption status + * during early boot intead of just before kexec to avoid SMP + * races during kvm_pv_guest_cpu_reboot(). + * NOTE: We cannot reset the complete shared pages list + * here as we need to retain the UEFI/OVMF firmware + * specific settings. + */ + + for (i = 0; i < e820_table->nr_entries; i++) { + struct e820_entry *entry = &e820_table->entries[i]; + + if (entry->type != E820_TYPE_RAM) + continue; + + nr_pages = DIV_ROUND_UP(entry->size, PAGE_SIZE); + + kvm_hypercall3(KVM_HC_MAP_GPA_RANGE, entry->addr, + nr_pages, + KVM_MAP_GPA_RANGE_ENCRYPTED | KVM_MAP_GPA_RANGE_PAGE_SZ_4K); + } + /* * Ensure that _bss_decrypted section is marked as decrypted in the * shared pages list.