Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp6268015pxb; Thu, 27 Jan 2022 09:56:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKsNJMjPRLOmhE5pfxQxP0k54Y1UNWGJ40NUXc5dAoYIo9aEHOhPx9esdg7+i80tEjdESo X-Received: by 2002:a17:907:9625:: with SMTP id gb37mr3895844ejc.424.1643306181862; Thu, 27 Jan 2022 09:56:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643306181; cv=none; d=google.com; s=arc-20160816; b=UYbRcsEYftXIKDPdfbG6lYmHBAWlJuwPDghRMOvHzvr4uiZ031nv6iocJzeucoJHT5 YoosQxTHv9TVAtJdLIDYACrnVsBwdDNlGjUnhPZpCT97KvYP/fdqc9PLl3NEOrBtAAef eT1gRGrrEv58UyHmdCWS/1axZ4TFH49TqMuccBZJrHLB9BaV0TeJWppSET6ES/Fm3676 3PWu6azc+OJUB/zhvHO1ARWYS8TGxClD4JWrX6Clcbx3xuUDHPZufh30pjHUZ9nVSxy9 Nqlg2J0HSUoCppDE0WY8DJHTcsgF2dz+JJ0p5zNC+cwTGZMtTpeSAPEAMZMrY+cozIau CDmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=WXuu5vLVGT79PFTKXi5TFqluwWeFbbvMNAsXGw9FLLA=; b=qbc/wzY7AhtByD8XQJydDedYz5luzzNnu1XCdjoliceKU/4RpcL74QSTbPCkL+a9W6 OIgJBkSDWpNGoxzrti6Ea78vBRrt/Vzt0UriOwDJNR657M2Mac+X40FiSx9qC0yYI4q/ PLJf72s/jkts7CPNgcbUFDV2KE+E5qeIanxhJF/BFVEBWthjdsFQ3T4EzF7FoYdDtqTM iUn1UILc+dJnEpDLj+fCAPI9fJIWNPUNVx07QBxe4cIKMbhjx9JktknbbY84l/0omMVE 1C+qApfQrajTxFpGWqEh8AjWipvw2XgHOb3jjLBQxL7mmHVuPMRNXiJpGoJfutlrAHW9 ZNfQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f6si2012368edd.352.2022.01.27.09.55.35; Thu, 27 Jan 2022 09:56:21 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239038AbiA0KLd (ORCPT + 99 others); Thu, 27 Jan 2022 05:11:33 -0500 Received: from 8bytes.org ([81.169.241.247]:47872 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234658AbiA0KLX (ORCPT ); Thu, 27 Jan 2022 05:11:23 -0500 Received: from cap.home.8bytes.org (p549ad610.dip0.t-ipconnect.de [84.154.214.16]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id D545F960; Thu, 27 Jan 2022 11:11:20 +0100 (CET) From: Joerg Roedel To: x86@kernel.org Cc: Joerg Roedel , 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 , Sean Christopherson , Martin Radev , Arvind Sankar , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v3 04/10] x86/sev: Cache AP Jump Table Address Date: Thu, 27 Jan 2022 11:10:38 +0100 Message-Id: <20220127101044.13803-5-joro@8bytes.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127101044.13803-1-joro@8bytes.org> References: <20220127101044.13803-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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) { 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) { 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 */ - if (!jump_table_addr) + if (!pa) return 0; - /* Check if AP Jump Table is page-aligned */ - if (jump_table_addr & ~PAGE_MASK) + /* Check if AP jump table is page-aligned */ + if (pa & ~PAGE_MASK) return -EINVAL; - jump_table_pa = jump_table_addr & PAGE_MASK; - startup_cs = (u16)(rmh->trampoline_start >> 4); startup_ip = (u16)(rmh->sev_es_trampoline_start - rmh->trampoline_start); - jump_table = ioremap_encrypted(jump_table_pa, PAGE_SIZE); + jump_table = ioremap_encrypted(pa, PAGE_SIZE); if (!jump_table) return -EIO; -- 2.34.1