From patchwork Thu Feb 4 00:40:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12065907 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.7 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,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 C22CFC43381 for ; Thu, 4 Feb 2021 00:51:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8697364E0F for ; Thu, 4 Feb 2021 00:51:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234434AbhBDAm6 (ORCPT ); Wed, 3 Feb 2021 19:42:58 -0500 Received: from mail-bn7nam10on2071.outbound.protection.outlook.com ([40.107.92.71]:5024 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234292AbhBDAms (ORCPT ); Wed, 3 Feb 2021 19:42:48 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hZadKX8P/igw2ZHvJIMZ5u7MqvcscncOsAaI2RXAB358PdNijjx7F7VUgp/D2xEe5c3nF++2xMlgRR8tm7YxoQHbWSxIC67/MRx6hMKV62FOs97CxQ1m0HCNuMicrgA35P5kNK9S6IyiEljUKtmY/v0k8bs3GUnXwcJQZf1kEZgemYlP+UWwGwPCV3GRprlQ+t2tAB+jdKgOORjUQPLscWB2AXiuPFRvef7z0IrrXDjbZw8y0Rz7QHk9ajxn0MAcHBJ3QgML/xc9jQ47IMVsr4iwvgb361pBQUoiBCLaAo4uVOGoK8Nf25iwB2DHbDHy0uIJ+1G9ZlA9IUrF5Xzz3Q== 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=NVsZ6f30A6ym2d3RuBlKkyWNYJE4Ap9qCyiyezbM+18=; b=eLYP8LSLt7jog0ZEkxIb8656AkBu81XHQRu2bUH2whYRU7XtDZczOyYnKSZGjB0hbQk0WJ9H6AQkjgAvbyiO7tLkxlncYpB29QNGFzvw6/cmAa3BaDuPr4K/Q2l6cz3u2RWi5zltwBZO81TE8hcZujbX902zss/UnE/DelCuVLZ4p2/1vbi6cstdZXVaTGWW4M6w5HaHqwozv88f0BuJN0VUcodcKid3YTPZjz0DeBSFzPv86Cd4Snd7eiMLt90mj9sDkq6ewjgbXGtZODbngLT/hNnohI6OUXyWBOVEf8zrKniT8JVt3rOdaJpC7gnxdIhCf2EzcJKWhLIR91uiLQ== 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=NVsZ6f30A6ym2d3RuBlKkyWNYJE4Ap9qCyiyezbM+18=; b=hlZd4nCru+jA2FM+jvdR3JdSZqv4Xi0Us5V2K6ypld3BrEtOJjvXEOnO+mH1NqTRG3TW2uoIvSK7+XjeAG+Gqv0msty4sHYvSUcb4C7s/K7VVA3BXXUjhkWD7KcD0hq3CRGKFwLR7UWpvJVXDKiFx/Fhi3QmuebdvarXIPIwgTM= 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 SA0PR12MB4384.namprd12.prod.outlook.com (2603:10b6:806:9f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.16; Thu, 4 Feb 2021 00:40:43 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3805.028; Thu, 4 Feb 2021 00:40:43 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, rkrcmar@redhat.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v10 15/16] KVM: x86: Add kexec support for SEV Live Migration. Date: Thu, 4 Feb 2021 00:40:33 +0000 Message-Id: <11de0243f7991ebe2b6a2acd4992cd7dcc5afb61.1612398155.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: SN7PR04CA0296.namprd04.prod.outlook.com (2603:10b6:806:123::31) 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 SN7PR04CA0296.namprd04.prod.outlook.com (2603:10b6:806:123::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.21 via Frontend Transport; Thu, 4 Feb 2021 00:40:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4fad794d-243f-47d5-b733-08d8c8a58077 X-MS-TrafficTypeDiagnostic: SA0PR12MB4384: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 44rV3XQjWoeSahV5L3/l2PjNuQ04ZgkevkN+kUywZgs9ZNM154GvXyZHvqBN4r947WvYi6uQRQaeLqL88YnHR0VtMHa9oELFM9bFE/ZfU0dOcMmnNPDj/0u0Aqwxgzu0Cv1T3bNyLQq4a0cTt9j1WbqRJh77+d8aCneIcQmcTSaCDKGh+9mcRBD02hxY5816lGcRCN8q32cqKGFB7Qm9M2Bl2dJk/KKEH2wU/Ww8SWxwLrOWm8+bOMC/roHybmaeHiiIYvOnxpDDNuVG0bNkGPrY/AJFSDlniOKg9umZlVjBeOgoyab/hU1h+nLoS+pCsDIBqFEiKUCBhYJG8Sq55uWUNttVY4658kAfsa3Menc6MO/w2XISUrs9xd2+tRzqMe8FhWwASfmdiT6id9SYkrbogI3CdbZmsGvcu/yvtAiRvd6kqF6UV2YijTeGczW259Jr4SyhelwOWNr+4xDu6g8a4uWw/cVuz/26pBwwHj8yOog/Jj81JiQCtlhpqLos5SZ5YQ2/i048sPtKq0Dngg== 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)(39850400004)(366004)(346002)(376002)(396003)(8936002)(4326008)(66556008)(86362001)(6666004)(66476007)(2906002)(186003)(478600001)(26005)(6916009)(6486002)(5660300002)(52116002)(16526019)(36756003)(7696005)(7416002)(66946007)(8676002)(956004)(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v845F5Jj8rRcgwrCE2/ivBbi3ji97thnblhtSySj9H/HyocFMAWVUqosq7ROnNJh4dSSW89I8lkz4461ddEtG/60wcj+Xq2nMqcV/KnV+4W05jOFjF0WvdCmn4z8pYfSHI/fP496EKb8tos6IjTg7oPu0PzQfRm9ZC+ehp2q7ODbwD0SBVMy6FK6nsvk0eZsG4OLF6gD4fyZvMyaArBIzMtEiGpCIKLmcDOOi+DKVewCgi08SfwTEOdL4TbpI5pmHonwli6QMnYMEGso/KQAvD+WEEMaKfV5NoeF6OH+Wl+HRw0XbYQgeU X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4fad794d-243f-47d5-b733-08d8c8a58077 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2021 00:40:43.0249 (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: cCTcsq2PBGdiJmUWnKH1ipQtZ0pgP4WApxDMr4H/RsM7j3mCIWOST/67bjk6IuRfaPaMTkANHrS1wFZLrz+ehg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4384 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 Reported-by: kernel test robot --- arch/x86/kernel/kvm.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index c4b8029c1442..d61156db7797 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -39,6 +39,7 @@ #include #include #include +#include DEFINE_STATIC_KEY_FALSE(kvm_async_pf_enabled); @@ -384,6 +385,33 @@ static void kvm_pv_guest_cpu_reboot(void *unused) */ if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) wrmsrl(MSR_KVM_PV_EOI_EN, 0); + /* + * Reset the host's shared pages list related to kernel + * specific page encryption status settings before we load a + * new kernel by kexec. NOTE: We cannot reset the complete + * shared pages list here as we need to retain the + * UEFI/OVMF firmware specific settings. + */ + if (sev_live_migration_enabled & (smp_processor_id() == 0)) { + int i; + unsigned long nr_pages; + + for (i = 0; i < e820_table->nr_entries; i++) { + struct e820_entry *entry = &e820_table->entries[i]; + unsigned long start_pfn; + unsigned long end_pfn; + + if (entry->type != E820_TYPE_RAM) + continue; + + start_pfn = entry->addr >> PAGE_SHIFT; + end_pfn = (entry->addr + entry->size) >> PAGE_SHIFT; + nr_pages = DIV_ROUND_UP(entry->size, PAGE_SIZE); + + kvm_sev_hypercall3(KVM_HC_PAGE_ENC_STATUS, + entry->addr, nr_pages, 1); + } + } kvm_pv_disable_apf(); kvm_disable_steal_time(); }