Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1705964ybh; Tue, 14 Jul 2020 05:19:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/02dIeG1TnlBUM1vhIH+SsxzS+bTxHT6fWIMAYbLKaKHK+5aUKBLaElN1R8SogB9H5Rer X-Received: by 2002:a17:907:11db:: with SMTP id va27mr4357339ejb.175.1594729198280; Tue, 14 Jul 2020 05:19:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594729198; cv=none; d=google.com; s=arc-20160816; b=nqMvLOulhmbSonwFmapuFFLrRD6QEjN9o/U1wgxA1ejkeR12xErGWleCrj89+UZmUB 7mey/N1R3oiWl83P+ouKFp20WuSv0RrWAuTfoMeDZe297uEPF1JcEhf4dXGzDic2znOl 5Mp3MI/Sl7obBedmafsUFW2xHHHyV7y8Ya5hvrga+zUapkMxYoT0bVZpOP/8AQTpuSY1 INYjpd8ZKuhUxW0+UuBct0AoTbmjKGgds8hYwE+kNg54fSri5XTPxphW84yShhGNMcwX ozK/r0DDsTHesC0Prv+cUvCWooghpu40p09Ppge2x5Yt3rERCRRlWl41vW85Uz7g8FKo kCZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=GQQDbpMjnt+NWmjc4qUYmmszAJWR5OC98uegNabF7uI=; b=QBRN1jOscHyki2fIXenXg6PdBkxHzU11wAQkQ+/OtXhY5Pef6sxY5ThIBVBX2iRosL ClaR71S7mWXr2/pX/NSu0V+njAKZcTycTCQOcTMCcKk9O3i8YIKEHDj57ZQSgv4A6htU Ere5eqkD7aMB4Or8YK2vZDT/Yxpg6AbQ6AfIG2tU7XvOHEWq7SsJZtiF7zKNJ7UCBchc j1q5XiNqLmNPJ+PLB09CCQE0K8/nmKtJiZyBGxpkxcjKE6mPVwh70n173lBbcoz2dFUU b9voyfDF8MYFnZCdTaiynYbwxvhfeVbj9IMpl5V6RHiFNAU0QSU0bqJ9TgmvJ5lqA4vr DCXQ== 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 o12si11190994ejh.340.2020.07.14.05.19.31; Tue, 14 Jul 2020 05:19:58 -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; 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 S1728592AbgGNMQ4 (ORCPT + 99 others); Tue, 14 Jul 2020 08:16:56 -0400 Received: from 8bytes.org ([81.169.241.247]:52864 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728246AbgGNMKp (ORCPT ); Tue, 14 Jul 2020 08:10:45 -0400 Received: from cap.home.8bytes.org (p5b006776.dip0.t-ipconnect.de [91.0.103.118]) (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 2E6786B4; Tue, 14 Jul 2020 14:10:43 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org Cc: Joerg Roedel , Joerg Roedel , 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 , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v4 19/75] x86/boot/compressed/64: Call set_sev_encryption_mask earlier Date: Tue, 14 Jul 2020 14:08:21 +0200 Message-Id: <20200714120917.11253-20-joro@8bytes.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714120917.11253-1-joro@8bytes.org> References: <20200714120917.11253-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Call set_sev_encryption_mask() while still on the stage 1 #VC-handler, because the stage 2 handler needs our own page-tables to be set up, to which calling set_sev_encryption_mask() is a prerequisite. Signed-off-by: Joerg Roedel --- arch/x86/boot/compressed/head_64.S | 8 +++++++- arch/x86/boot/compressed/ident_map_64.c | 3 --- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 36f18d5592f4..963bf2ce11cf 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -543,9 +543,15 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) rep stosq /* - * Load stage2 IDT and switch to our own page-table + * If running as an SEV guest, the encryption mask is required in the + * page-table setup code below. When the guest also has SEV-ES enabled + * set_sev_encryption_mask() will cause #VC exceptions, but the stage2 + * handler can't map its GHCB because the page-table is not set up yet. + * So set up the encryption mask here while still on the stage1 #VC + * handler. Then load stage2 IDT and switch to our own page-table. */ pushq %rsi + call set_sev_encryption_mask call load_stage2_idt call initialize_identity_maps popq %rsi diff --git a/arch/x86/boot/compressed/ident_map_64.c b/arch/x86/boot/compressed/ident_map_64.c index 62e42c11a336..b4f2a5f503cd 100644 --- a/arch/x86/boot/compressed/ident_map_64.c +++ b/arch/x86/boot/compressed/ident_map_64.c @@ -105,9 +105,6 @@ static void add_identity_map(unsigned long start, unsigned long end) /* Locates and clears a region for a new top level page table. */ void initialize_identity_maps(void) { - /* If running as an SEV guest, the encryption mask is required. */ - set_sev_encryption_mask(); - /* Exclude the encryption mask from __PHYSICAL_MASK */ physical_mask &= ~sme_me_mask; -- 2.27.0