Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35815084rwd; Mon, 10 Jul 2023 13:05:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlHRF/mS/LMCOZ70zHL4DO6Y+ghJAfnJy/yYwbPnVmUS0fumYIqIkh1pogZUSdlmu8g+ICQC X-Received: by 2002:a17:907:cc9a:b0:992:b3a3:81f4 with SMTP id up26-20020a170907cc9a00b00992b3a381f4mr14109715ejc.50.1689019546638; Mon, 10 Jul 2023 13:05:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689019546; cv=none; d=google.com; s=arc-20160816; b=YYbzp9vQRYkX+GEjAk111XccNk92Xu68oX8LvAMexo2dPU4S14pQhczNz2XKl1ZWfU rme0QwkYatpt4q0KbtgpCHbE9kp4qVmcHr4pFYJYsSgtBMaPKMtqOKh735rPZWHPlP5r bZA1pdJWhFdz0uZZg1o7NVORD2DkQwiNyF1xPWhETFba797EPu1s34dHEN3c7L7KafyP 7qXS4tATWmnbgOjZhjWkQcaTIy+jRlqUo3K77FD8M8BHCOZPuJ0B+yvYxWEqtZvq0EYa nicUqdSYQIrSUuQ6KM0S6Ke44m9fjfomiakGmwY4Bz1GMIF+Jii9NMAZlJhu+c7IlYP6 3+lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ynX4xs1ia0vVamnWxq7T+G8TSAYpJrKtW6apk2sxnag=; fh=O5hGN+g8auw9Ax2YMVhoIJ+3XXizvyZrFj7plzReJck=; b=Q+zuOYighCZUaOCYOa9xic5qty/ba+u6TkSWRQWESNaAjI4Vw44GDFn4jADgcpXu8E JZRhsqLOGl6CDILBeicFLyxzeJzynLZ6s0pTip7RgksFQuiufarmDxYG2ddpiBuI+eop RHFKhdzG6kDr8nwDB48BBVequTz6fvzlrVF0+gtgdanwiMQVJFTy8nYUL3/dkynynNLH KK409cjfqkQrcF/Gz75ApcRSl4ElfSdQw7ewD4+qcB0iO44Y5PfAqfX3+ZNEa4J9dpPf hlEMmNncCgCOyKuB/ZeW7vDMkDCDcnztKAv241OXBAPwGswm3wj3yK8qbPw8Sc4vSPgq w/Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P0eUdjAx; 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 g12-20020a170906394c00b0098804fbcff0si303077eje.709.2023.07.10.13.05.21; Mon, 10 Jul 2023 13:05:46 -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=P0eUdjAx; 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 S229732AbjGJTum (ORCPT + 99 others); Mon, 10 Jul 2023 15:50:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbjGJTul (ORCPT ); Mon, 10 Jul 2023 15:50:41 -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 1280019A for ; Mon, 10 Jul 2023 12:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689018554; 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=P0eUdjAxZioTKb5IfZw19wdYdfOaa0g1CdtMTq1BZKc7xW+w+ePNn2BO92GesnH4jNiu2K Re/Q45QEgFWJxWreSBTJf89rK0ZJ1VeyNMMmxxhWPHY5AnxQjWSsjjtNUD5fc6q9lXy3zn smPWAGBE4EZup/pAI8SfzI1V3YcSh1E= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 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. -- 2.31.1