Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9465030rwd; Wed, 21 Jun 2023 07:48:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6aYk5/6XijRA5rQI7yxYwn5zNxUEidUpGispOQmDqFwu6RN9GV/uIZkjeNwLQQKR80OzxD X-Received: by 2002:a17:90a:710:b0:25c:1138:d97c with SMTP id l16-20020a17090a071000b0025c1138d97cmr13806930pjl.24.1687358900213; Wed, 21 Jun 2023 07:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687358900; cv=none; d=google.com; s=arc-20160816; b=Cv40DJGFNYkILK4DVt0UEgvKJ2DXgVETZEFIcTXFFCJbDBrk3lQdu3qW3Hb8IzuRSn mmzFNV+e/PuuNMIC/CyJ/03BT79W/xofgvZ1nKqOKDPz+8QkTXRV4kKAWt/5jh39ngWd 81dU/XWPk9Dhy3haJ9luefGbFUSC9R8oUtgytKlxyO7Etxp9+DXlIC+sZBpo2r0ucYQz pMXlO6IFAlKJNuD9PzGuUqv2b5VeKk0xyOO7/yzWDm5JtL3xjaQViK+BD6L55qtCFjkQ ZgZRN20yPpe5dHG8g2ICR2CMWzZ8GoAMruVJGM4rKrUgaRa2DWcVwU6VAeIvpI0ksMq5 O7jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XF6WLknEk00s0CGB8SGhE9Z7BuDNsIowtmxtGqyuqs8=; b=x6+t33xVu1ETBTmpYQu47QlTmTcpzfxwjyN3XcBBIYqrZDyG5Nhfc6ej6QLHfA4oyX TFfh4M3jrLOdLfKYhK8P7eVU+pKEORejwyNaGCEr0ieLy8+PmuXPW/spRFo/kFIFeHrO jf+uAPJqA+DEjV3M6AZ/xyOU5FSE9joVSjmDOF9WftiBV8GBsUhrNgIzjXpE6zlS/XGj N6Bvdu3UxUoeEDTrd3UlOTkxHl/Oo/yQ+zCkhg6RCC7yRIEMtxcdJwMHaTEqrx4+0SkJ Cs4dnUIMNQYy1CqFeK2SMF3cZ3CVrWwVXJY/rs4bezGRdGwGIoIEtdzsI+m58sWVuFHn zExA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Wklw+5s3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j64-20020a638b43000000b005098590f1edsi1692907pge.757.2023.06.21.07.48.06; Wed, 21 Jun 2023 07:48:20 -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=@infradead.org header.s=casper.20170209 header.b=Wklw+5s3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230486AbjFUOg2 (ORCPT + 99 others); Wed, 21 Jun 2023 10:36:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231653AbjFUOgW (ORCPT ); Wed, 21 Jun 2023 10:36:22 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84A421BC1; Wed, 21 Jun 2023 07:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=XF6WLknEk00s0CGB8SGhE9Z7BuDNsIowtmxtGqyuqs8=; b=Wklw+5s3Dy3I7wKwZAAgPkPhsg sDuWCKE8eWay2uz6IPjhYpzDmX37GmUXx0To0MUxRBRMTnpGDlwfF6vdrApfKJ3VJi7AZbjyVwLtg 4igRqurnGpt5927uBDUa7PGOy9EG8kXRILIop2ZL252dIcblNgre9nYNET4VQkEOEr5y76PG/f5wg KXrkkIpMsVrrwjYVS/RB3WuOcRtrn52ZyNzYLmXBK85qeqbMNi2YYKiBNmpBwY4KwW5ivMDfIBX+n yo4MtAms6fa8bjWBN1ysZr/F05PXH2rRjmAd2qXbQpbKuvka+ZYr7zU3DjA2j77Tuw2GVnTFrYr/D HW0WCLnQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qBywF-00ERUK-ML; Wed, 21 Jun 2023 14:36:03 +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 C2AAF3002F0; Wed, 21 Jun 2023 16:36:02 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A10AE2130B4A4; Wed, 21 Jun 2023 16:36:02 +0200 (CEST) Date: Wed, 21 Jun 2023 16:36:02 +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 , linux-kernel@vger.kernel.org, x86@kernel.org, linux-pm@vger.kernel.org, Robin Jarry , Joe Mario Subject: Re: [PATCH v2 2/5] x86/idle: Disable IBRS when cpu is offline Message-ID: <20230621143602.GI2053369@hirez.programming.kicks-ass.net> References: <20230620140625.1001886-1-longman@redhat.com> <20230620140625.1001886-3-longman@redhat.com> <20230621072313.GA2046280@hirez.programming.kicks-ass.net> <7f2424df-1846-6c38-e446-b3d5aa693ecd@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7f2424df-1846-6c38-e446-b3d5aa693ecd@redhat.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 Wed, Jun 21, 2023 at 09:59:52AM -0400, Waiman Long wrote: > > On 6/21/23 03:23, Peter Zijlstra wrote: > > On Tue, Jun 20, 2023 at 10:06:22AM -0400, Waiman Long wrote: > > > Commit bf5835bcdb96 ("intel_idle: Disable IBRS during long idle") > > > disables IBRS when the CPU enters long idle. However, when a CPU becomes > > > offline, the IBRS bit is still set when X86_FEATURE_KERNEL_IBRS is > > > enabled. That will impact the performance of a sibling CPU. Mitigate > > > this performance impact by clearing all the mitigation bits in SPEC_CTRL > > > MSR when offline and restoring the value of the MSR when it becomes > > > online again. > > > > > > Signed-off-by: Waiman Long > > > --- > > > arch/x86/kernel/smpboot.c | 13 +++++++++++++ > > > 1 file changed, 13 insertions(+) > > > > > > diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c > > > index 352f0ce1ece4..5ff82fef413c 100644 > > > --- a/arch/x86/kernel/smpboot.c > > > +++ b/arch/x86/kernel/smpboot.c > > > @@ -84,6 +84,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > /* representing HT siblings of each logical CPU */ > > > DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); > > > @@ -1838,12 +1839,24 @@ void __noreturn hlt_play_dead(void) > > > void native_play_dead(void) > > > { > > > + u64 spec_ctrl = spec_ctrl_current(); > > > + > > > + if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS)) { > > > + this_cpu_write(x86_spec_ctrl_current, 0); > > > + native_wrmsrl(MSR_IA32_SPEC_CTRL, 0); > > > + } > > > + > > > play_dead_common(); > > > tboot_shutdown(TB_SHUTDOWN_WFS); > > > mwait_play_dead(); > > > if (cpuidle_play_dead()) > > > hlt_play_dead(); > > > + > > > + if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS)) { > > > + native_wrmsrl(MSR_IA32_SPEC_CTRL, spec_ctrl); > > > + this_cpu_write(x86_spec_ctrl_current, spec_ctrl); > > > + } > > > } > > play_dead() is marked __noreturn > > There are different versions of play_dead() in the kernel. Some of them are > indeed marked __noreturn like the non-SMP one in arch/x86/kernel/process.c. > The native_play_dead() that I am patching isn't one of those. mostly by accident I think, hlt_play_dead() is, so I'm thinking everybody (all compiler and objtool) managed to figure out native_play_dead() is __noreturn too.