Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7898014rwd; Tue, 20 Jun 2023 07:38:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ51uLz3nIJS7adFywYMT2WCzeX3eXUklAByRlJOo7TH3Qmq4QdsMzF3BcV5BoxX0ttE81PN X-Received: by 2002:a05:6a20:8f29:b0:122:c6c4:36b1 with SMTP id b41-20020a056a208f2900b00122c6c436b1mr1325187pzk.4.1687271922136; Tue, 20 Jun 2023 07:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687271922; cv=none; d=google.com; s=arc-20160816; b=y7GOYPmnyyy6b3/vsMoMwb+2BLUrETo6Q20mPDAon4EU0RODloB//+UUt3WC5+aV92 bWAhw00UDcK/+JLI86RK1F64F3x0GBrZ6PRRGal9g0pDUyQgNNsqZZyWYPjSaYjumQwX LkwlHLkQtXgR5WHItON8fiBYSXmkKeFbBcpVMoKKmSTPaSXfhxRBLgiGvelG/946Z5qe xLg9NHeyFKjT8gt6xFfbabX/Ocmxe2rAjo+7Wroa76aEI38g3CI59UyOvCbGaeMfL630 v8S1P61muwbcquJDB4Yi1/dmVk5pX9SBwec1zMskpkfHoKFeD5OcUVZu6j+iY34QxI8J OWnA== 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=VrByPcLlZJlbrBKqAsdOzQ0Sy0EOhnQ6P87fZxDadIk=; b=aMb6gqQwhcRFS1rRyNRGRsMQHX3Q/yPrs8WDUrsewqUfRopizowZlMyJFNARUqGEl6 toGaxMTXOsJyE3fOcxo5X0wDwWD0ob84tHqauTpv++h556odLiP23zLYw8HCYlVZZml5 7QsdZQD8fTFZZ/cmYe7O+Q/xIy+23NL3RPeHx8t4YUXUM5Dcgv+go0epMI2XPCZbzNlc 8BGbIlN9lMRkThP8rVaeLAvcN+dFjbrdjFEWi0sjw5YQgMsZYqf4TZrJ2OQLSsaZTCi4 KJOJgoBhflGIrOHmgbuTkkpCV09EU3g76hdBTCqaZ2TtSjFLt9zMx1d3Ophq5plQr0BN vZSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IWaZ+TXx; 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 k137-20020a636f8f000000b0053fbb36fc65si1866302pgc.382.2023.06.20.07.38.30; Tue, 20 Jun 2023 07:38:42 -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=IWaZ+TXx; 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 S232749AbjFTOKg (ORCPT + 99 others); Tue, 20 Jun 2023 10:10:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233171AbjFTOK2 (ORCPT ); Tue, 20 Jun 2023 10:10:28 -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 8FF5410D5 for ; Tue, 20 Jun 2023 07:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687270186; 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=VrByPcLlZJlbrBKqAsdOzQ0Sy0EOhnQ6P87fZxDadIk=; b=IWaZ+TXxG/E4UhYYb2Blw7BdEG8PL6+0owAFrie92GGbyL0ORfq7913PusoCCM+T257Jqx 2jXek9uB1kgeoeeoRbUtIdSL0IaMpe99MMxArQbsOaPyHHzOjpFGaOVmi1PXVVDOy3OhQh 1u2PoCgsazkq2xQmB90n9ncbxgOW+Ak= 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-466-rhmpZFmgOz-Gw5i0hq2awQ-1; Tue, 20 Jun 2023 10:09:26 -0400 X-MC-Unique: rhmpZFmgOz-Gw5i0hq2awQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BC295104D984; Tue, 20 Jun 2023 14:06:35 +0000 (UTC) Received: from llong.com (unknown [10.22.34.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 078BD425357; Tue, 20 Jun 2023 14:06:34 +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 Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-pm@vger.kernel.org, Robin Jarry , Joe Mario , Waiman Long Subject: [PATCH v2 5/5] x86/idle: Disable IBRS entering mwait idle and enable it on wakeup Date: Tue, 20 Jun 2023 10:06:25 -0400 Message-Id: <20230620140625.1001886-6-longman@redhat.com> In-Reply-To: <20230620140625.1001886-1-longman@redhat.com> References: <20230620140625.1001886-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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_NONE, RCVD_IN_MSPIKE_H5,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 When a user sets "intel_idle.max_cstate=0", it will disable intel_idle and fall back to acpi_idle instead. The acpi_idle code will then call mwait_idle_with_hints() to enter idle state. So when X86_FEATURE_KERNEL_IBRS is enabled, it is necessary to disable IBRS within mwait_idle_with_hints() when IRQ was disabled to avoid performance degradation on silbing thread running user workload. Signed-off-by: Waiman Long --- arch/x86/include/asm/mwait.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h index 778df05f8539..1e36cdc21661 100644 --- a/arch/x86/include/asm/mwait.h +++ b/arch/x86/include/asm/mwait.h @@ -108,15 +108,32 @@ static __always_inline void __sti_mwait(unsigned long eax, unsigned long ecx) static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned long ecx) { if (static_cpu_has_bug(X86_BUG_MONITOR) || !current_set_polling_and_test()) { + bool ibrs_disabled = false; + u64 spec_ctrl; + if (static_cpu_has_bug(X86_BUG_CLFLUSH_MONITOR)) { mb(); clflush((void *)¤t_thread_info()->flags); mb(); } + if (irqs_disabled() && + cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS)) { + /* NMI always enable IBRS on exception entry */ + ibrs_disabled = true; + spec_ctrl = spec_ctrl_current(); + __this_cpu_write(x86_spec_ctrl_current, 0); + native_wrmsrl(MSR_IA32_SPEC_CTRL, 0); + } + __monitor((void *)¤t_thread_info()->flags, 0, 0); if (!need_resched()) __mwait(eax, ecx); + + if (ibrs_disabled) { + native_wrmsrl(MSR_IA32_SPEC_CTRL, spec_ctrl); + __this_cpu_write(x86_spec_ctrl_current, spec_ctrl); + } } current_clr_polling(); } -- 2.31.1