From patchwork Tue Aug 9 07:17:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Elmously X-Patchwork-Id: 1664774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=ZAvLXHjk; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4M24Ck6gQdz9sGP for ; Tue, 9 Aug 2022 17:17:54 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oLJUn-00012N-4v; Tue, 09 Aug 2022 07:17:45 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oLJUj-00011I-O9 for kernel-team@lists.ubuntu.com; Tue, 09 Aug 2022 07:17:41 +0000 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 6CE273F135 for ; Tue, 9 Aug 2022 07:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1660029461; bh=UjWylry388588kZUxkIle4OVi6EvgMErtUd6OjEA9mM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZAvLXHjk5jlhBD+RhVIamwppyXsibxsp5EKpoKKB8i/rQDczYoGioM4noE9GdYyIH KEiZR/o5Oco5KdBj8QH3gSjr1UdyRlgmQpWsskqYKjUNCqlcESHsYlIM5Mkfm8T6Uo dHp8D/EYju5AjF3oanNmzGxQcPn3VGQpd8X6htKcLIi8NIKQSS8uW6FSkKkOzRyWFS JMaQZrGvHuzVXWCPgrWrx8U+FJEXxb8RXgrrto1C0gGVwaix44Jwo9y1MjkuGgYmh9 Y0dYlaJmrhk2/mkMa/r84r3OeuOZ+DgwWH8tTjZ1lJIY8unnRcTCUOPnmtlIvKpofV Y7GQG2GTHbShA== Received: by mail-qt1-f199.google.com with SMTP id fy18-20020a05622a5a1200b0033e5b56f031so8442890qtb.15 for ; Tue, 09 Aug 2022 00:17:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=UjWylry388588kZUxkIle4OVi6EvgMErtUd6OjEA9mM=; b=O1SmSjISfmviHwk50KuvSinRRAQNOizKCI6EM7ivL0GUIvKpnbgIOxP4lXah22f54d AcFgB6dQ+F8j+B2zLsVz45dHabtINGVb4oOyWv6NcM5xRZPPuSr4dp6x7D/8l/XgvfCA O77UFh9vB6kNPmnR4nNLo0SKoEuQ9fUDkNnQWwPWzotismeBz2caT9Sf0IymZj7akxIk rGudZ+pNXEVz2QjcYE92Lp5nQAWP6ny4ritXKm+tIw8QOgErUPHlAIVXC+QnkGj92M6K wi8hSn+MaDM5Un89Z4s7NcCTW27J18HMqg3MrBrtbnBG6/UfAc9cBLImxhJ6XOPXj87M gczA== X-Gm-Message-State: ACgBeo3osZHG/f5rjSXE8s7DhPE8Q3DfLG+GMDXRmli6mK9dqv/aXKD8 L08cNXkiUjIWPMHk6bqdQL6Zu93HJLjlztMVSa1spht2pISRGNuhjmWAbW0V8nbvTQsDF2+v/fG SRr0WLuTl+LyOAqxF2w0KuML4i94Ilrr5loJSmwVwdg== X-Received: by 2002:ac8:5c8e:0:b0:339:21a6:22d1 with SMTP id r14-20020ac85c8e000000b0033921a622d1mr19314726qta.552.1660029460344; Tue, 09 Aug 2022 00:17:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR6KnBkxr5D3XsEl12JZtKLQE8tmIoz2dyFKa/sf1oUrrDZjDRI+9+VZySC31yW7rBtq+hpDFg== X-Received: by 2002:ac8:5c8e:0:b0:339:21a6:22d1 with SMTP id r14-20020ac85c8e000000b0033921a622d1mr19314713qta.552.1660029460076; Tue, 09 Aug 2022 00:17:40 -0700 (PDT) Received: from k2.fuzzbuzz.org ([38.147.253.164]) by smtp.gmail.com with ESMTPSA id s11-20020a05622a1a8b00b0031d283f4c4dsm10118227qtc.60.2022.08.09.00.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 00:17:39 -0700 (PDT) From: Khalid Elmously To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 5/5] x86/kvm: Add kexec support for SEV Live Migration. Date: Tue, 9 Aug 2022 03:17:30 -0400 Message-Id: <20220809071730.124247-6-khalid.elmously@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220809071730.124247-1-khalid.elmously@canonical.com> References: <20220809071730.124247-1-khalid.elmously@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Ashish Kalra BugLink: https://launchpad.net/bugs/1984034 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 Message-Id: <3e051424ab839ea470f88333273d7a185006754f.1629726117.git.ashish.kalra@amd.com> Signed-off-by: Paolo Bonzini (cherry picked from commit 73f1b4fece216c2e72be74c4d0d0f71a0b944bec) Signed-off-by: Khalid Elmously --- 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 fdb4fd291fe7..72c4f7c66989 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -885,10 +885,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_sev_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.