Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4106551pxk; Tue, 8 Sep 2020 10:51:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpWD9zKj4Bl+bZbYaGZ3G/KqH+Udr5MzDeuo+GFf2llNg0p4fRW+T8xXuwZGEvbo5txmq2 X-Received: by 2002:a17:906:b097:: with SMTP id x23mr13314592ejy.21.1599587497675; Tue, 08 Sep 2020 10:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599587497; cv=none; d=google.com; s=arc-20160816; b=1EVWK2x9RC0O4Evbk0EAw+hWdwTktSNka8BXIKANExiVYTVmahSmBdGaFQX8xPHcb2 7Mzf26ylf/vi18EDSEJ3tuQrFUGdgr3xZ7as8q34qh2ZFus+YCR4AGgF5heDLHjWjFe1 V8mNQvFvH0Ryo3U6ugJpfh3ZyNaGAh8yqhjYav2JTH2xZy1ZqcM0s3XIb50DPop8mtNZ WBLF9WTeRKwHNgU6S/cO2pqL3KeFvzgIVygNNoockLPCSfBtsk6nOg8eUG764bmtCHza /QGGTxIhXE8Tibf9B8mUS03NQ4d0Ff06UGM4jbmGl20IZcsBEvCPSNTejIqIm3G9S0z3 9wmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=nPj3+c2dIwhanvH9Blvxwpvfl2eV/3k/Q9aSuFLclYg=; b=DC6aRTOaoLV9FEg0Rmv4MW4nSzTiGcmnvA/y+SJ1YRePynGM2SpJMKQk4hv3ObOeJw V5LjDDvGqrEXThHHnExX2Zk/ozzfF1d2Q+WF9gsVqxKZ+drGl1XpB1kiKKQ97yUza9i6 AP6nfLUMDmZNkhxboDrzRLvGZmN98aA/YE+9GzesQW59suxYPi9iDceLXOKyA75s0e08 CkSPnnft9MF77Mls3TqigF6sc6w9r2FRtPXdF0yK+AVxhN4QPz1io04WTZzZ5D5ZkjuQ WTkigAOWP6+a0H5b2qxVNY7TcIGp51agZgyE7laVJFLZuflmRi23zzphFzzusqWz/qow HVZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="RM/Zx8iH"; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l14si13040810edv.603.2020.09.08.10.51.11; Tue, 08 Sep 2020 10:51:37 -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=@alien8.de header.s=dkim header.b="RM/Zx8iH"; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732146AbgIHRsh (ORCPT + 99 others); Tue, 8 Sep 2020 13:48:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731365AbgIHRqS (ORCPT ); Tue, 8 Sep 2020 13:46:18 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E892EC061573; Tue, 8 Sep 2020 10:46:17 -0700 (PDT) Received: from zn.tnic (p200300ec2f10bf0070b09dfd4356f225.dip0.t-ipconnect.de [IPv6:2003:ec:2f10:bf00:70b0:9dfd:4356:f225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 605F51EC0489; Tue, 8 Sep 2020 19:46:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1599587176; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=nPj3+c2dIwhanvH9Blvxwpvfl2eV/3k/Q9aSuFLclYg=; b=RM/Zx8iHBvG5Eti/FNmYaWgJjIMOyQ4VltylfyxY4IdCEIFAfWH60weezPSlACosueFynJ DKlNyhaAe9DDi+Up/33riZE7n2E7K1VUYzWs+AuxGZl1Bzei/yP0kIDcV8JJzVPAf4HdRS QJYbhpttRw4vRmtimjYS+Qynt7kt/ms= Date: Tue, 8 Sep 2020 19:46:16 +0200 From: Borislav Petkov To: Joerg Roedel , Ard Biesheuvel Cc: x86@kernel.org, Joerg Roedel , Tom Lendacky , hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v7 71/72] x86/efi: Add GHCB mappings when SEV-ES is active Message-ID: <20200908174616.GJ25236@zn.tnic> References: <20200907131613.12703-1-joro@8bytes.org> <20200907131613.12703-72-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200907131613.12703-72-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + Ard so that he can ack the efi bits. On Mon, Sep 07, 2020 at 03:16:12PM +0200, Joerg Roedel wrote: > From: Tom Lendacky > > Calling down to EFI runtime services can result in the firmware performing > VMGEXIT calls. The firmware is likely to use the GHCB of the OS (e.g., for > setting EFI variables), so each GHCB in the system needs to be identity > mapped in the EFI page tables, as unencrypted, to avoid page faults. > > Signed-off-by: Tom Lendacky > [ jroedel@suse.de: Moved GHCB mapping loop to sev-es.c ] > Signed-off-by: Joerg Roedel > --- > arch/x86/boot/compressed/sev-es.c | 1 + > arch/x86/include/asm/sev-es.h | 2 ++ > arch/x86/kernel/sev-es.c | 30 ++++++++++++++++++++++++++++++ > arch/x86/platform/efi/efi_64.c | 10 ++++++++++ > 4 files changed, 43 insertions(+) > > diff --git a/arch/x86/boot/compressed/sev-es.c b/arch/x86/boot/compressed/sev-es.c > index 45702b866c33..0a9a248ca33d 100644 > --- a/arch/x86/boot/compressed/sev-es.c > +++ b/arch/x86/boot/compressed/sev-es.c > @@ -12,6 +12,7 @@ > */ > #include "misc.h" > > +#include > #include > #include > #include > diff --git a/arch/x86/include/asm/sev-es.h b/arch/x86/include/asm/sev-es.h > index e919f09ae33c..cf1d957c7091 100644 > --- a/arch/x86/include/asm/sev-es.h > +++ b/arch/x86/include/asm/sev-es.h > @@ -102,11 +102,13 @@ static __always_inline void sev_es_nmi_complete(void) > if (static_branch_unlikely(&sev_es_enable_key)) > __sev_es_nmi_complete(); > } > +extern int __init sev_es_efi_map_ghcbs(pgd_t *pgd); > #else > static inline void sev_es_ist_enter(struct pt_regs *regs) { } > static inline void sev_es_ist_exit(void) { } > static inline int sev_es_setup_ap_jump_table(struct real_mode_header *rmh) { return 0; } > static inline void sev_es_nmi_complete(void) { } > +static inline int sev_es_efi_map_ghcbs(pgd_t *pgd) { return 0; } > #endif > > #endif > diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c > index 9ab3a4dfecd8..4e2b7e4d9b87 100644 > --- a/arch/x86/kernel/sev-es.c > +++ b/arch/x86/kernel/sev-es.c > @@ -491,6 +491,36 @@ int sev_es_setup_ap_jump_table(struct real_mode_header *rmh) > return 0; > } > > +/* > + * This is needed by the OVMF UEFI firmware which will use whatever it finds in > + * the GHCB MSR as its GHCB to talk to the hypervisor. So make sure the per-cpu > + * runtime GHCBs used by the kernel are also mapped in the EFI page-table. > + */ > +int __init sev_es_efi_map_ghcbs(pgd_t *pgd) > +{ > + struct sev_es_runtime_data *data; > + unsigned long address, pflags; > + int cpu; > + u64 pfn; > + > + if (!sev_es_active()) > + return 0; > + > + pflags = _PAGE_NX | _PAGE_RW; > + > + for_each_possible_cpu(cpu) { > + data = per_cpu(runtime_data, cpu); > + > + address = __pa(&data->ghcb_page); > + pfn = address >> PAGE_SHIFT; > + > + if (kernel_map_pages_in_pgd(pgd, pfn, address, 1, pflags)) > + return 1; > + } > + > + return 0; > +} > + > static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt) > { > struct pt_regs *regs = ctxt->regs; > diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c > index 6af4da1149ba..8f5759df7776 100644 > --- a/arch/x86/platform/efi/efi_64.c > +++ b/arch/x86/platform/efi/efi_64.c > @@ -47,6 +47,7 @@ > #include > #include > #include > +#include > > /* > * We allocate runtime services regions top-down, starting from -4G, i.e. > @@ -229,6 +230,15 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) > return 1; > } > > + /* > + * When SEV-ES is active, the GHCB as set by the kernel will be used > + * by firmware. Create a 1:1 unencrypted mapping for each GHCB. > + */ > + if (sev_es_efi_map_ghcbs(pgd)) { > + pr_err("Failed to create 1:1 mapping for the GHCBs!\n"); > + return 1; > + } > + > /* > * When making calls to the firmware everything needs to be 1:1 > * mapped and addressable with 32-bit pointers. Map the kernel > -- > 2.28.0 > -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette