Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp15685908rwb; Mon, 28 Nov 2022 14:58:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf7MIh4wiwPCxoCWq7yjDCwDutcCjggb0T531bpkz/GN/2FNVmPVqWyEMfygvTD0BI08GpP4 X-Received: by 2002:a17:902:b692:b0:188:fc5f:84f2 with SMTP id c18-20020a170902b69200b00188fc5f84f2mr35694483pls.137.1669676334423; Mon, 28 Nov 2022 14:58:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669676334; cv=none; d=google.com; s=arc-20160816; b=lDdwy+zKezYAcZmJE/HQrWEV+85I19G4jpkylGmwyVs0bWcDjsxt6I+CqX65GwZxyb k/0vbJw8ry43BFNyspky0j2k1Y9IG9GXer4OAW0aEttRrTyLDOWUZSnk9/1J1dq0603D T8ul0FoddW76CR8q8jE/TxdHpIYDB8dR6R5OxaYgtfRojgfHaMwDuF1QJvzgXPRI1fwz 5H6o1krD5uJe/4o3a/XOCBQQj2MGQ/b4s2guAgIO5vBXCxAx0EmAr3/83U0fJZhprszR 3r2AzAFcLCD6dbM1mKrRCItah6rMV+JAmUdDt4ws78ekXfYaVUeZnbLUB7Rw01ksHcva ao7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=lZmQ7j7zgK9JHgQnY7ydnqQbz44P4Bhdp+DPFB7I0JE=; b=CA+en4JOzydvq9GdYJvQ9sloQ208LDBOXSWO0ptHobF622VH+5saTjWtfnpUSeJRpz Ds+NZzKXEiQJ4r7T8VZ7p8Yx1ZjTEw7Tu4TYQN4woGKZfeux4krUqoIGnxVtEdG1uG1c tg46KIVMy7tdMn8u8y5X339WuzLpuUIXT1q4D8ngcR5iOC6u/fWgIfaKkYQZ/cFsx/Gc DrWXvw8ajtxZVCn4LTlRWqQWPociSW7/nKWCb8axpjuZq4VAQhf+YqOvttY6OHpv38U9 xg6B8i8zhMbNai61p5gLp3roWit2hXI8f+drtzJ7kdvEmilXVSquyy4repMcJfVo9FtX e15w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=JmX75N2b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a170902ea0100b0018554535de8si14204461plg.83.2022.11.28.14.58.44; Mon, 28 Nov 2022 14:58:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=JmX75N2b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234251AbiK1Wk1 (ORCPT + 83 others); Mon, 28 Nov 2022 17:40:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233219AbiK1Wk0 (ORCPT ); Mon, 28 Nov 2022 17:40:26 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 307FD27B0E for ; Mon, 28 Nov 2022 14:40:25 -0800 (PST) Received: from zn.tnic (p5de8e9fe.dip0.t-ipconnect.de [93.232.233.254]) (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 646F81EC042F; Mon, 28 Nov 2022 23:40:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1669675223; 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=lZmQ7j7zgK9JHgQnY7ydnqQbz44P4Bhdp+DPFB7I0JE=; b=JmX75N2bOGozIbq6a9mlp2lFnrW28dA6Bv62M/XaNO5nThh4xGC/EVb1FYs0RDQPA2dXpG mNTFLP+uVGAJLyMlCnqGzgeD3+qsXBcJSX2X6Wu2RSoDIcazWV9/lb6/xZ+MFrEdH0RjLw +ggtTzGAP56gM6H7IkB3AiLfjFKJgHo= Date: Mon, 28 Nov 2022 23:40:19 +0100 From: Borislav Petkov To: Pawan Gupta Cc: Breno Leitao , tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, hpa@zytor.com, jpoimboe@kernel.org, peterz@infradead.org, x86@kernel.org, cascardo@canonical.com, leit@meta.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] x86/bugs: Explicitly clear speculative MSR bits Message-ID: References: <20221124104650.533427-1-leitao@debian.org> <20221128220358.n5vk6youcdl2er35@desk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221128220358.n5vk6youcdl2er35@desk> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 28, 2022 at 02:03:58PM -0800, Pawan Gupta wrote: > diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c > index 3e3230cccaa7..cfc2ed2661fc 100644 > --- a/arch/x86/kernel/cpu/bugs.c > +++ b/arch/x86/kernel/cpu/bugs.c > @@ -66,7 +66,7 @@ static DEFINE_MUTEX(spec_ctrl_mutex); > */ > void write_spec_ctrl_current(u64 val, bool force) > { > - if (this_cpu_read(x86_spec_ctrl_current) == val) > + if (!force && this_cpu_read(x86_spec_ctrl_current) == val) > return; > this_cpu_write(x86_spec_ctrl_current, val); Still looks hacky to me. I think it would be a lot cleaner if MSR_IA32_SPEC_CTRL gets cleaned of the speculation bits in init_speculation_control() which gets run on *every* CPU. So by the time check_bugs() gets to setup stuff, the MSR will be ready to go regardless. I.e., something like this (not supposed to work - just to show what I mean): diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 73cc546e024d..367732c92942 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -993,9 +993,19 @@ static void init_speculation_control(struct cpuinfo_x86 *c) * Intel CPUs, for finer-grained selection of what's available. */ if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) { + u64 msr; + set_cpu_cap(c, X86_FEATURE_IBRS); set_cpu_cap(c, X86_FEATURE_IBPB); set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL); + + /* + * Clear speculation control settings from a previous kernel + * run, i.e., kexec. + */ + rdmsrl(MSR_IA32_SPEC_CTRL, msr); + if (msr & SPEC_CTRL_MASK) + wrmsr (MSR_IA32_SPEC_CTRL, msr & ~SPEC_CTRL_MASK); } if (cpu_has(c, X86_FEATURE_INTEL_STIBP)) -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette