Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1198738pxb; Wed, 10 Feb 2021 02:35:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWLq8eHpzth4SSpFs1gcvNoubg6ChGhatKq/kkS63b/GWFub2RE7uYM75l26GrHF3aR0Dg X-Received: by 2002:a17:906:688f:: with SMTP id n15mr2292913ejr.71.1612953309153; Wed, 10 Feb 2021 02:35:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612953309; cv=none; d=google.com; s=arc-20160816; b=QU3pf2587GaQGzeUXLQCe3ReK6t0fEOBrEoTvXZywcOw8bA9n9sNjFteorI9AI2ksf c9I8+bwUyM0xJYImPoUafLtja/0M/MLSuU3ozqv0xlRx1noZ8QhX3n9gfcTuVPHL0XgE hdRRF3wNurEvoWK+aANopQe1Ev2MXU7xo5htpo4zkKYtzHw81PrtWZBTKd7w+u/MObyt 2vtlKjtE/t2qLuTWOYAoZoU3YbeEh5N0MxM/7oxmiQhII2EEPyFx6ctDAuRCKo2M8Deo x7y6VbPa3r1Z0paiMngaeutR7tt0ks64DW91e25a+Jf24icte1WmrgXS0M090Gj/8RFu uGqg== 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=VJZ9WkYrFCwTnLw4GWVFzkjuq23q4NVw4T8fmpnl/3w=; b=mOLsbcvX1fkVJC4KrGvT4EA8N0X1PttGjLKlxq1rUY4OZg/8xcCevtp6TKF+ipL3Wm IKJPVSCF7M0o51veoDvyu17nIai4ml8HPlZkgffA1PIIUJ/khcZJ57D10aM6HP558UrT dF13O86nYl3QCNHGRytdQJ613ALHRm7dS2fdM0IZV52D1jy67q+gceZFrzf0saec4GLv +sisQhzv1kXxYh2a74TKk+vu3QUQS44GcODmiFq7u7TIpNpz5snws5GTkDF+igLagbxZ Q+DHIzyNvjjEBKItZ4085tBlMbXZvowwBeFJY/3DXh6WSD2wLsvfeAt7fwAbjL15IqTO uYwQ== 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 y30si1126869ede.60.2021.02.10.02.34.46; Wed, 10 Feb 2021 02:35:09 -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 S230401AbhBJKdh (ORCPT + 99 others); Wed, 10 Feb 2021 05:33:37 -0500 Received: from 8bytes.org ([81.169.241.247]:55072 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbhBJKWj (ORCPT ); Wed, 10 Feb 2021 05:22:39 -0500 Received: from cap.home.8bytes.org (p549adcf6.dip0.t-ipconnect.de [84.154.220.246]) (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 720283A7; Wed, 10 Feb 2021 11:21:55 +0100 (CET) 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 , Arvind Sankar , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH 1/7] x86/boot/compressed/64: Cleanup exception handling before booting kernel Date: Wed, 10 Feb 2021 11:21:29 +0100 Message-Id: <20210210102135.30667-2-joro@8bytes.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210210102135.30667-1-joro@8bytes.org> References: <20210210102135.30667-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 Disable the exception handling before booting the kernel to make sure any exceptions that happen during early kernel boot are not directed to the pre-decompression code. Signed-off-by: Joerg Roedel --- arch/x86/boot/compressed/idt_64.c | 14 ++++++++++++++ arch/x86/boot/compressed/misc.c | 7 ++----- arch/x86/boot/compressed/misc.h | 6 ++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/arch/x86/boot/compressed/idt_64.c b/arch/x86/boot/compressed/idt_64.c index 804a502ee0d2..9b93567d663a 100644 --- a/arch/x86/boot/compressed/idt_64.c +++ b/arch/x86/boot/compressed/idt_64.c @@ -52,3 +52,17 @@ void load_stage2_idt(void) load_boot_idt(&boot_idt_desc); } + +void cleanup_exception_handling(void) +{ + /* + * Flush GHCB from cache and map it encrypted again when running as + * SEV-ES guest. + */ + sev_es_shutdown_ghcb(); + + /* Set a null-idt, disabling #PF and #VC handling */ + boot_idt_desc.size = 0; + boot_idt_desc.address = 0; + load_boot_idt(&boot_idt_desc); +} diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index 267e7f93050e..cc9fd0e8766a 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -443,11 +443,8 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, handle_relocations(output, output_len, virt_addr); debug_putstr("done.\nBooting the kernel.\n"); - /* - * Flush GHCB from cache and map it encrypted again when running as - * SEV-ES guest. - */ - sev_es_shutdown_ghcb(); + /* Disable exception handling before booting the kernel */ + cleanup_exception_handling(); return output; } diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 901ea5ebec22..e5612f035498 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -155,6 +155,12 @@ extern pteval_t __default_kernel_pte_mask; extern gate_desc boot_idt[BOOT_IDT_ENTRIES]; extern struct desc_ptr boot_idt_desc; +#ifdef CONFIG_X86_64 +void cleanup_exception_handling(void); +#else +static inline void cleanup_exception_handling(void) { } +#endif + /* IDT Entry Points */ void boot_page_fault(void); void boot_stage1_vc(void); -- 2.30.0