Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1731832pxb; Wed, 9 Feb 2022 03:21:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjwu0WkkSYEPUeTdWjERo0D+kb9PYOaYP+3xFKOv19skPaIyncw2MvMa/hUJ2pFncdFylU X-Received: by 2002:a17:90b:3907:: with SMTP id ob7mr2837700pjb.29.1644405693658; Wed, 09 Feb 2022 03:21:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644405693; cv=none; d=google.com; s=arc-20160816; b=CMnULjdfHTcVaw0DSuOvFMNCJ1zdJQsqo5MUCDHWix+5RqkBF/WMid7vyilFX/Y8Mq MArvbnHIlfI0C3c/FsJ5koS1EuhueDFvAxFVqp3BY7MGGZpDGczQlZkfcK+hUa1uA7N8 G7rF+PHxtce20ivHR6jUgGwKuYMnfqbfJ25Qo2lX+ocHe8osyOxFjlYf3SL3FSnF1yMU dNt9mPqDPgEoS+RX/1mRUYSngs6Jl0B91baBdonw/1fhf+92a/rI5EJbt+pr6im3jrXY p+yoHtzPZSxsqud71BOzdGEd3fhk3p+ZNYSPP8vX0Nc+UzuWd5+rfulMYQWzyEx3lOqp fEWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UPy7lygPxr90ipECLkuZI1hGfjCl5QQ8FuHy0YowhSc=; b=S22OQX7BLpYbpZ7BVeemu8GdPCFJ+jcEcPhNbHiHcETkOUoKt8WfSm7yz8rIB1vgea /2txzwlsN9t4I3ukJs6a0vRMrTlLLkT6JPX0XUTVVLQb1kOw3OrlXlcc5Q+s4oCqAIzY bQsyZlK9G87fTlkmkl26FD9l8WSM0Grf6+asBg/pe8P8SqbELZtv5g6bjJUhMYysBLc6 cDJunQnkRTEYWlIVrEvFrtOR3pJol++N3aRhr5T8EAzt+zLujp3PhjIvEz9+TiTo9wiG MVYZFJIELzOyk7yz1PWFKNFqdoGl8vJS67zw9PPu//A3jHU9RZ9k0LIj2PWfxJA0zHIT 1Ddw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RCgXhswV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e6si1031771plh.181.2022.02.09.03.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 03:21:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RCgXhswV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 353CAE0C8F91; Wed, 9 Feb 2022 01:47:15 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242008AbiBGWD6 (ORCPT + 99 others); Mon, 7 Feb 2022 17:03:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239911AbiBGWD5 (ORCPT ); Mon, 7 Feb 2022 17:03:57 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32351C0612A4 for ; Mon, 7 Feb 2022 14:03:57 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id u130so15407278pfc.2 for ; Mon, 07 Feb 2022 14:03:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=UPy7lygPxr90ipECLkuZI1hGfjCl5QQ8FuHy0YowhSc=; b=RCgXhswVoMfKJgmEInLACfKtrGVLqOCKWZNQ41sxN5QDiS7VwL/G07y2oU0WB8ztNR Y0S/kH1ShxVpYYabvAnlMUsDkJFODoyyY5dzhb1Fd7mnBLqXM9Rec01w4aj7PGNdeL5n RWuK3IpF25Z9D8lhRsyEZAKgCsMiGAZNHpKo086hki4ByVDihSrUinUl2fJl0XC9tujL PNBkTL6RuaWSjX1S5vLoYvoof4pfeRaDyEpdC+mVVVIu7XPHvEn4en4/Y4pIL4hV6rr1 Cdy78LZyRztbpdzjvMGH8T8h9AbVd0QzBozwz2j0qazz4F8EmAc5xBhZNFYgkPpM1Tn/ gMUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=UPy7lygPxr90ipECLkuZI1hGfjCl5QQ8FuHy0YowhSc=; b=mNjk4qIyKYAw9Z+6UbNOuEiiZ7AtOd/HHqUc5Wh8UJxgS+2rk6+91pd71ZU4YaNs0z MU1K/a90Om4xBMDpRUzbFE6FxNU6u4VWrRLXWaHSczFi5wyTEJuz+X7AW4jqRaO9ZcB9 nWTtW6wWJeZZNAPpcVrKYBkc/9JL23p0X3KdM86quYBo7uhCeCRRNnHEjBSoLuOc6pW/ YXE5AIcTr2VZkaICnMS2axMAUYSIflbgNDdRkl41QoThx5C4L5Zx461FEb5TAy0AwnJy bY43SshQ+oGdTVWKqE0jgafVYiws25d4rA7zTt0lUxB4C5x7kSyqLvNA+24KL7CY5e6X cedQ== X-Gm-Message-State: AOAM532kDYZIAcktDa1GXwq4hQcOXrMeO5HCASGpD1ZOrwcBXvHhjD9C 1Q29Ny7gF/AGVe/WtSWGK5Vchg== X-Received: by 2002:a63:2c83:: with SMTP id s125mr1103589pgs.265.1644271436434; Mon, 07 Feb 2022 14:03:56 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id q2sm13779245pfj.94.2022.02.07.14.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 14:03:55 -0800 (PST) Date: Mon, 7 Feb 2022 22:03:52 +0000 From: Sean Christopherson To: Joerg Roedel Cc: x86@kernel.org, Joerg Roedel , Eric Biederman , kexec@lists.infradead.org, hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Martin Radev , Arvind Sankar , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v3 04/10] x86/sev: Cache AP Jump Table Address Message-ID: References: <20220127101044.13803-1-joro@8bytes.org> <20220127101044.13803-5-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220127101044.13803-5-joro@8bytes.org> X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 27, 2022, Joerg Roedel wrote: > From: Joerg Roedel > > Store the physical address of the AP jump table in kernel memory so > that it does not need to be fetched from the Hypervisor again. This doesn't explain why the kernel would retrieve the jump table more than once, e.g. at this point in the series, this can only ever be called once. > Signed-off-by: Joerg Roedel > --- > arch/x86/kernel/sev.c | 28 +++++++++++++++------------- > 1 file changed, 15 insertions(+), 13 deletions(-) > > diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c > index 8a4317fa699a..969ef9855bb5 100644 > --- a/arch/x86/kernel/sev.c > +++ b/arch/x86/kernel/sev.c > @@ -43,6 +43,9 @@ static struct ghcb boot_ghcb_page __bss_decrypted __aligned(PAGE_SIZE); > */ > static struct ghcb __initdata *boot_ghcb; > > +/* Cached AP jump table Address */ > +static phys_addr_t jump_table_pa; > + > /* #VC handler runtime per-CPU data */ > struct sev_es_runtime_data { > struct ghcb ghcb_page; > @@ -523,12 +526,14 @@ void noinstr __sev_es_nmi_complete(void) > __sev_put_ghcb(&state); > } > > -static u64 get_jump_table_addr(void) > +static phys_addr_t get_jump_table_addr(void) Not new, but I believe this can be tagged __init. > { > struct ghcb_state state; > unsigned long flags; > struct ghcb *ghcb; > - u64 ret = 0; > + > + if (jump_table_pa) > + return jump_table_pa; > > local_irq_save(flags); > > @@ -544,39 +549,36 @@ static u64 get_jump_table_addr(void) > > if (ghcb_sw_exit_info_1_is_valid(ghcb) && > ghcb_sw_exit_info_2_is_valid(ghcb)) > - ret = ghcb->save.sw_exit_info_2; > + jump_table_pa = (phys_addr_t)ghcb->save.sw_exit_info_2; > > __sev_put_ghcb(&state); > > local_irq_restore(flags); > > - return ret; > + return jump_table_pa; > } > > int sev_es_setup_ap_jump_table(struct real_mode_header *rmh) __init here too. > { > u16 startup_cs, startup_ip; > - phys_addr_t jump_table_pa; > - u64 jump_table_addr; > u16 __iomem *jump_table; > + phys_addr_t pa; > > - jump_table_addr = get_jump_table_addr(); > + pa = get_jump_table_addr(); > > /* On UP guests there is no jump table so this is not a failure */ Does anything actually check that the jump table is valid for SMP guests? > - if (!jump_table_addr) > + if (!pa) Using '0' for "not valid" is funky because '0' isn't technically an illegal GPA, and because it means the address (or lack thereof) isn't cached on a single-vCPU guest.