From patchwork Mon Jul 10 19:48:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 13307544 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 48006EB64DC for ; Mon, 10 Jul 2023 19:50:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231319AbjGJTuA (ORCPT ); Mon, 10 Jul 2023 15:50:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbjGJTt7 (ORCPT ); Mon, 10 Jul 2023 15:49:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAE7D197 for ; Mon, 10 Jul 2023 12:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689018553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ynX4xs1ia0vVamnWxq7T+G8TSAYpJrKtW6apk2sxnag=; b=Vn1lcn6Kh5qxUrC2z/m43BkqCc/Xl8L4w9MRDHFa9WgEdki6PiLdWfU9Rx0LP7KQZGdM+k nmVGlcnAUYoSUSvvOeaBGn5j9FiZ/GYm0SjjDxJk1lp68VXQtN9fIsFAm7rSHfo6liS+/U b9xT1Ass0X2a0p+HK+rJG+5tAcsKC3g= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-250-CSDJodKQPdmD9xBscMj83Q-1; Mon, 10 Jul 2023 15:49:09 -0400 X-MC-Unique: CSDJodKQPdmD9xBscMj83Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28DFB185A791; Mon, 10 Jul 2023 19:49:08 +0000 (UTC) Received: from llong.com (unknown [10.22.18.171]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D32F111E3E6; Mon, 10 Jul 2023 19:49:07 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Josh Poimboeuf , Pawan Gupta , Jacob Pan , Len Brown , Jonathan Corbet , "Rafael J . Wysocki" Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, x86@kernel.org, linux-pm@vger.kernel.org, Robin Jarry , Joe Mario , Randy Dunlap , Waiman Long Subject: [PATCH v5 1/4] x86/speculation: Add __update_spec_ctrl() helper Date: Mon, 10 Jul 2023 15:48:54 -0400 Message-Id: <20230710194857.2898284-2-longman@redhat.com> In-Reply-To: <20230710194857.2898284-1-longman@redhat.com> References: <20230710194857.2898284-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 Acked-by: Rafael J. Wysocki --- arch/x86/include/asm/nospec-branch.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index 55388c9f7601..06ceacfd1fe2 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,16 @@ 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 & should only be called in bare + * metal context. + */ +static __always_inline void __update_spec_ctrl(u64 val) +{ + __this_cpu_write(x86_spec_ctrl_current, val); + native_wrmsrl(MSR_IA32_SPEC_CTRL, val); +} + /* * With retpoline, we must use IBRS to restrict branch prediction * before calling into firmware.