From mboxrd@z Thu Jan 1 00:00:00 1970 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 8A083C001B3 for ; Mon, 3 Jul 2023 10:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231247AbjGCK2o (ORCPT ); Mon, 3 Jul 2023 06:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjGCK2l (ORCPT ); Mon, 3 Jul 2023 06:28:41 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5889FBE; Mon, 3 Jul 2023 03:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=RdvSBzylMqzcgeZCbeq2y3LzSr6cTTZfwrxa9S1F0VI=; b=l1r8nJk/ekxSCVihjSWivo5+i8 e9fu4b+qujtiOO1HcA00eg2WW2XD4aR9SsRCwszuEFh+NJUx9cpjiZOWVqhJ08TJEk3HnPAATKTSW XctUeu+cTQ4/5hb4aTCqSeQSLKvwWNIh+PqzWqs4PPjZ1wBVxd1LuuyEIYs2+08ZvxE1tMvYJHL0u jBKhkkCTuNZotMTh4xvdWLUHnvkvreZJmAIvLPzb47UvVuHuGTQWNa2GmZ7UM7QQkBETekTt2qqwM 89TsDVd7OxqRPPiqrN23edONltxI3jFNWEsAOn7rp6k5Q62w50xdSr++vS8kMsRbyQnRaYbVdh730 DAmIroQQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qGGn2-00A3td-36; Mon, 03 Jul 2023 10:28:17 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5A36630023F; Mon, 3 Jul 2023 12:28:15 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 35189202A2A17; Mon, 3 Jul 2023 12:28:15 +0200 (CEST) Date: Mon, 3 Jul 2023 12:28:15 +0200 From: Peter Zijlstra To: Waiman Long Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Josh Poimboeuf , Pawan Gupta , Jacob Pan , Len Brown , Jonathan Corbet , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, x86@kernel.org, linux-pm@vger.kernel.org, Robin Jarry , Joe Mario Subject: Re: [PATCH v4 1/4] x86/speculation: Add __update_spec_ctrl() helper Message-ID: <20230703102815.GD4253@hirez.programming.kicks-ass.net> References: <20230628022554.1638318-1-longman@redhat.com> <20230628022554.1638318-2-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230628022554.1638318-2-longman@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 27, 2023 at 10:25:51PM -0400, Waiman Long wrote: > Add a new __update_spec_ctrl() helper which is a variant of > update_spec_ctrl() that can be used in a noinstr function. > > Suggested-by: Peter Zijlstra > Signed-off-by: Waiman Long > --- > arch/x86/include/asm/nospec-branch.h | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h > index 55388c9f7601..1d363fcea207 100644 > --- a/arch/x86/include/asm/nospec-branch.h > +++ b/arch/x86/include/asm/nospec-branch.h > @@ -9,7 +9,7 @@ > > #include > #include > -#include > +#include > #include > #include > #include > @@ -488,6 +488,15 @@ DECLARE_PER_CPU(u64, x86_spec_ctrl_current); > extern void update_spec_ctrl_cond(u64 val); > extern u64 spec_ctrl_current(void); > > +/* > + * This can be used in noinstr function. > + */ > +static __always_inline void __update_spec_ctrl(u64 val) > +{ > + __this_cpu_write(x86_spec_ctrl_current, val); > + native_wrmsrl(MSR_IA32_SPEC_CTRL, val); > +} Should we also use this to implement update_spec_ctrl() ?