Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp248601pxt; Wed, 4 Aug 2021 21:41:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOkEQvSEXAgBcoFvukRdcFd4z4rStCkrO4Gf5tOGVtCLA9aNMJ7nVifXBusdAS4F9vIX4g X-Received: by 2002:a50:ef0d:: with SMTP id m13mr4000419eds.98.1628138512969; Wed, 04 Aug 2021 21:41:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628138512; cv=none; d=google.com; s=arc-20160816; b=zVZJgT+aymXqBJUaKo3XhSIvjtfWWLerWrnR6lrmsNbTPbQ4PuJfpiQPl2pdo/L947 NZ8pAvX+TlkbSgSNYHaJdIvKnoIi54Hxf83t3N83pmpZSqj5k58ImBvICqwcFo0mFart 3vqoTUFubIlIvwD0PKfDzjbdRhW7pYyN8InNnclde/uMrEaqx3HuSAIoT85m3IS0G2gD eMJ96OmPBs6ZvTsIcQcpzKWKsukPBGbaj2t2ZL7fMCmAtW8xHxn1pYGHrPVkFZWmWUYh 1wCTYOYsaJNCzI4WbHATDB54UHpCSw99yjsMI6yRsOgHAi3BpXMNbCAriyroJDgMlK4p 6igQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8t/9JoKQ84VqwJveoASuBq/SiF9ShqKfSF5avleoS2Y=; b=ioaHuuXYwGsFqB7oeM+F6gRQ3+bT+2AcyS6/acEuuiJ3QFk/NtaV0DT1SWz++3E2pt +4I7I6Y3KLkuHIHHqHHUcm14GW9GqdxE8vGRP9ujDb71U8oe+SI26TZ+bgj8ymoM06La bYEaL9zsqnWkHOYUvgJKkBexYHvfxbYRX2BjuXMQPhp5EUlT5PW3Rmrh4cL1a9rSt7pb 2ZtG2swRtCLp39ofTy7NTT8AVWR8TrnJInbJw7JSfRnbFyCpUZl/2/rkJoBi6UcZTqyV M81qi6hwYo/5nmxWJZaguG55z+VeVNfNFdbCkuCxAw4CYUaLtjmH0bpAAR075eZ+Roml ZbEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=C3RFGN7u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si4373449ejp.76.2021.08.04.21.41.28; Wed, 04 Aug 2021 21:41:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=C3RFGN7u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237428AbhHEBc0 (ORCPT + 99 others); Wed, 4 Aug 2021 21:32:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231964AbhHEBcY (ORCPT ); Wed, 4 Aug 2021 21:32:24 -0400 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB2B6C061765 for ; Wed, 4 Aug 2021 18:32:10 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id a13so4736407iol.5 for ; Wed, 04 Aug 2021 18:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8t/9JoKQ84VqwJveoASuBq/SiF9ShqKfSF5avleoS2Y=; b=C3RFGN7uI0MtXGUlkyPzFRzTC7Jzkn64LIwBYM7TWUhOmBbdsUpjtSCMzkohdYtoVT iN0+5LFxboXB/T7fqk5b8IgBrBYIVEZXMGY2Ad4Q4kaZdI+ZGQ2QxkI+rkwGnEQ6s7K5 /L3qGhmGAxscO5B/+LDX9PbWsXhF9XaRPttrghAWkUq8Q6ZyAss+q8Eu/ASKSokft8M2 oMxe4CGA+y76Az387YSOjUjZQHFJQwE0sPC4XyrzkG+vBmg0/178+fuEBJUkdlxQwJC9 c+9xby+JIzF1vDElt1CCimQyz/jC9TcSV5iGPeoYe+eVsc7dMoOTOWdAHO5j/riHwxbl ty/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8t/9JoKQ84VqwJveoASuBq/SiF9ShqKfSF5avleoS2Y=; b=e8A5UPGqmMgoCs2T33DPpgdtSK4cbuHrKBLRacE89Upe8fJgbFBCJfCZSAxBLWqj9E m48pUl6Mr0z1lXRDdatW6hWcLDILF34XxjfmJ14v9JwlO2qRkhLSiiRQ8ytSUGPe1EQW pJyNoxHpnmUdISaEVmFcXGRkTrnhb+ziIuGHcu78vA3G6J3RxXV2qyNxCdv0ZEdEWsH+ NlALKplCVL319525hXqA+Z1QQZ5J5ISmkUnKQ+MXBAdmSNaW+BsjEKza6dVi9pWet8CM 9J0VySnuwexOlrAo9WlmtaZ0gFfGpv7gOX+gEqFG/uKhj1kPe+ROwQf2ON2dCtzC+HXA ScIQ== X-Gm-Message-State: AOAM532IfqVojAtuPTi7ZSvCtmEKhJJr1v3YjIIKQitJg16qAn8fbKeb 4ySpdzz8+lVA37y7Isvep5EGDCxvgKNYsLAI69kAoQ== X-Received: by 2002:a02:5d0a:: with SMTP id w10mr2158883jaa.47.1628127129927; Wed, 04 Aug 2021 18:32:09 -0700 (PDT) MIME-Version: 1.0 References: <8fce27b8477073b9c7750f7cfc0c68f7ebd3a97d.1624978790.git.ashish.kalra@amd.com> In-Reply-To: <8fce27b8477073b9c7750f7cfc0c68f7ebd3a97d.1624978790.git.ashish.kalra@amd.com> From: Steve Rutherford Date: Wed, 4 Aug 2021 18:31:34 -0700 Message-ID: Subject: Re: [PATCH v5 6/6] x86/kvm: Add kexec support for SEV Live Migration. To: Ashish Kalra Cc: pbonzini@redhat.com, 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 29, 2021 at 8:14 AM Ashish Kalra wrote: > > 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 > --- > 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. > -- > 2.17.1 > Re-reading things, I've convinced myself that kexec is fine. I was previously concerned with KEXEC_PRESERVE_CONTEXT. In particular, since the guest does not re-call the encryption status hypercalls after it jumps back, the host will be out of the loop, and continue believing the guest is in the same state as it was while running the intermediate kernel. As a result, it would have an inaccurate list of which pages are shared/private after a kexecing and jumping back. The bit that I neglected is that the new kernel (just like the original kernel) will disable live migration before jumping back (if it enabled live migration at all). And the original kernel will never re-enable. This is sub-optimal, since a VM that previously supported migration can reach a state where it will stop supporting live migration. But that's unavoidable. Kexecing a kernel that does not support live migration does the same thing. This looks good to me. Reviewed-by: Steve Rutherford