From nobody Tue Jun 23 07:10:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 096B6C433EF for ; Wed, 9 Mar 2022 07:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230431AbiCIH44 (ORCPT ); Wed, 9 Mar 2022 02:56:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbiCIH4O (ORCPT ); Wed, 9 Mar 2022 02:56:14 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37559163D6C; Tue, 8 Mar 2022 23:54:59 -0800 (PST) Date: Wed, 09 Mar 2022 07:54:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1646812498; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ccy4XzjRvU3p/tZbIiRcB/c7TDX5BH03yivR98VrUfM=; b=xiPcvJ6vFoIGI3+hVVaP3yslkyTHO9cFYCzBLHx69hh8xaEEVWXtDWr5OgnrlPUWv6un+/ 4NSJw2WyNjSFAHgZGVXD/0bW14aPpGtXtplzGKdU0v6yRSAoJel6+Ma4MEOvDFQqJ9dSZX ctR93/QehbpMEnZbTtRJRHvdvlk9cZT558O00WrewViVP9p7j09Wrn2BcGAT5o4tHtvikn HTsmbqZuNaLDcmzQmKzOQw0EhSPk3p8LtINsmy14rEgFzM90cxu5tjENhJrJK4AW/+ne6T W8T3yGS18UqK5u2/qKJFJa9go2g8PY0hcF1gcJ4ABoizxwv2I2QFOKGm7IL8KQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1646812498; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ccy4XzjRvU3p/tZbIiRcB/c7TDX5BH03yivR98VrUfM=; b=MQ+XtpjxK5I+MYqEZpQ6sRipbyHf4CbuyFhOqPTwgngdmXyN7jYTvaptlvsrVUSgOHDGDL xB3dI4JVAXYSOQDg== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] x86/ibt,kexec: Disable CET on kexec Cc: "Peter Zijlstra (Intel)" , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220308154318.641454603@infradead.org> References: <20220308154318.641454603@infradead.org> MIME-Version: 1.0 Message-ID: <164681249728.16921.12285536796767172459.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/core branch of tip: Commit-ID: f9a08abb06d0abe51295479118f1f8e4a4325798 Gitweb: https://git.kernel.org/tip/f9a08abb06d0abe51295479118f1f8e4a= 4325798 Author: Peter Zijlstra AuthorDate: Tue, 08 Mar 2022 16:30:36 +01:00 Committer: Peter Zijlstra CommitterDate: Tue, 08 Mar 2022 23:53:33 +01:00 x86/ibt,kexec: Disable CET on kexec Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf Link: https://lore.kernel.org/r/20220308154318.641454603@infradead.org --- arch/x86/include/asm/cpu.h | 3 +++ arch/x86/kernel/cpu/common.c | 6 ++++++ arch/x86/kernel/machine_kexec_64.c | 4 +++- arch/x86/kernel/relocate_kernel_64.S | 8 ++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index a60025f..86e5e4e 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -73,4 +73,7 @@ void init_ia32_feat_ctl(struct cpuinfo_x86 *c); #else static inline void init_ia32_feat_ctl(struct cpuinfo_x86 *c) {} #endif + +extern __noendbr void cet_disable(void); + #endif /* _ASM_X86_CPU_H */ diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index db1f149..709acab 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -535,6 +535,12 @@ static __always_inline void setup_cet(struct cpuinfo_x= 86 *c) } } =20 +__noendbr void cet_disable(void) +{ + if (cpu_feature_enabled(X86_FEATURE_IBT)) + wrmsrl(MSR_IA32_S_CET, 0); +} + /* * Some CPU features depend on higher CPUID levels, which may not always * be available due to CPUID level capping or broken virtualization diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_k= exec_64.c index f5da4a1..566bb8e 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -27,6 +27,7 @@ #include #include #include +#include =20 #ifdef CONFIG_ACPI /* @@ -310,6 +311,7 @@ void machine_kexec(struct kimage *image) /* Interrupts aren't acceptable while we reboot */ local_irq_disable(); hw_breakpoint_disable(); + cet_disable(); =20 if (image->preserve_context) { #ifdef CONFIG_X86_IO_APIC @@ -325,7 +327,7 @@ void machine_kexec(struct kimage *image) } =20 control_page =3D page_address(image->control_code_page) + PAGE_SIZE; - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE); + __memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE); =20 page_list[PA_CONTROL_PAGE] =3D virt_to_phys(control_page); page_list[VA_CONTROL_PAGE] =3D (unsigned long)control_page; diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index 399f075..5b65f6e 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -115,6 +115,14 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) pushq %rdx =20 /* + * Clear X86_CR4_CET (if it was set) such that we can clear CR0_WP + * below. + */ + movq %cr4, %rax + andq $~(X86_CR4_CET), %rax + movq %rax, %cr4 + + /* * Set cr0 to a known state: * - Paging enabled * - Alignment check disabled