Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp26341547rwd; Mon, 3 Jul 2023 08:25:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlFF9C/iPF3+tnMaQUcsVeBqOR801Jncjn2vLEb5Am0nMPhihiP+EyehzJC2UtawO2Z0yw6k X-Received: by 2002:a17:90a:ea81:b0:262:df91:cdce with SMTP id h1-20020a17090aea8100b00262df91cdcemr9090172pjz.23.1688397915417; Mon, 03 Jul 2023 08:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688397915; cv=none; d=google.com; s=arc-20160816; b=srLqPAF3ZmC6Oyif8Sh9pex4KVdJfIPoPslGG1rg3/XcP66fwaqqf5aXN141IsmAP0 z81yuixpZc94DSH21q/a3NK0/8SyJb1JrMtyNrNMS+9TbPdAXp5fDLA9EK3/+xd2bXyf 5iWdB+IzpJ8LMUNLkAAyTszEt0fmqoBm+1oN2Rp/L2naLTgEAr5zI4yZ53UueK+BQ8P9 FhmbGOKwamJwylMj16nZ7gU26xKOCIBb0xRzs/b4DxmXGH4uYpXjUFF2HuEP48o3Fadk I8ZCSZWnTee3o7VOmJRye2vytthsauULJPbtRVzg30RhZxfr2d4MgP2nqnD2xt34GVt6 FV9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=AUHibEWJur7T9M8HkspJ2AIEO95dTbGY2F8uwaeIXwk=; fh=U/gSxzc9VQ+zVkkbMy/a5FJGwEWttLtrG6VYSeJP4dw=; b=F5oWCQ2Uf6LtpEG+8AVf6NbvraPGb06yZFnnZ9wVKaq+HIHZ8mEG59UX5cMy8VFfNN KXsjTbWeOgaqi3hmgMi/m912pzVukgFDpYViVTGXMciYhcLI3PMRvUyg7uZnf33fZs6R cIOx1RFSxKWoiEXsgSX0GRUI00QU7bwTdVbE170VImLPzDlSXaZPOZyl9IdYQ+HSUwkV lzJTCuSLX6zj1YDNNhZp8v59cCOtHyQ4doMl7uQndzVUJ92w6h1eFFEi5mPsftmf6T6H 8QU/5GVF2R70V3Owhmk8hQF1p0lTmnQlWe1kHk6ZpdNwHygNt8LnDV2px+xTSDz+Xc4z RolA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A4iIh0ru; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx16-20020a17090b4b1000b00262f937bf93si15940827pjb.77.2023.07.03.08.25.02; Mon, 03 Jul 2023 08:25:15 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=A4iIh0ru; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229853AbjGCPIv (ORCPT + 99 others); Mon, 3 Jul 2023 11:08:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231299AbjGCPIu (ORCPT ); Mon, 3 Jul 2023 11:08:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C640E6B for ; Mon, 3 Jul 2023 08:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688396886; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AUHibEWJur7T9M8HkspJ2AIEO95dTbGY2F8uwaeIXwk=; b=A4iIh0ruDYVZyHAZrRcsgja8+SBtT/jaoU4c7qHNGLn+ddfe+kW4nrF0IuoS+vX9baSyIj dFr42bgaD6/jecJPAe/feTIVKAYbG3VnbbEt2yhuKRQ5D+OEImJJOw4Q4jEWA+QYYrscYp r22GIxrGbqzD8e0mvFhJVTqUgCaqc/8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-9-NFofb2wYMNu_ZVe_IxIOIA-1; Mon, 03 Jul 2023 11:08:02 -0400 X-MC-Unique: NFofb2wYMNu_ZVe_IxIOIA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7F891C08DA7; Mon, 3 Jul 2023 15:08:01 +0000 (UTC) Received: from [10.22.17.92] (unknown [10.22.17.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 752C3492B01; Mon, 3 Jul 2023 15:08:00 +0000 (UTC) Message-ID: <5727a163-c72a-9632-b497-1011689aaa75@redhat.com> Date: Mon, 3 Jul 2023 11:08:00 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH v4 1/4] x86/speculation: Add __update_spec_ctrl() helper Content-Language: en-US To: Peter Zijlstra 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 References: <20230628022554.1638318-1-longman@redhat.com> <20230628022554.1638318-2-longman@redhat.com> <20230703102815.GD4253@hirez.programming.kicks-ass.net> From: Waiman Long In-Reply-To: <20230703102815.GD4253@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 7/3/23 06:28, Peter Zijlstra wrote: > 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() ? I also thought about that. However, I am a bit worry about losing some additional check done in this_cpu_write() and the paravirt support in wrmsrl(). I have no problem making update_spec_ctrl() an instrument-able wrapper on __update_spec_ctrl() if you think these are not valid concerns. Cheers, Longman