Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10651094rwd; Thu, 22 Jun 2023 02:58:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4w2OdfZr8+mYlne+2y5Ymk1eD9CmoIVEGfvByve3gLc3OtJcNXetfnEJNaFgVf3m/rBWmy X-Received: by 2002:a17:90a:d996:b0:256:d262:e686 with SMTP id d22-20020a17090ad99600b00256d262e686mr16817227pjv.19.1687427932362; Thu, 22 Jun 2023 02:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687427932; cv=none; d=google.com; s=arc-20160816; b=GoRq+hxGUc7myKv71X55dhjM+RE6beoBm2CWcEiT0IDIaBdopKBhraN12hdBmlgcNz s39sYnrOcBTYj0ZY7GnCG+OpOgm9e2X0syNZ06/SS7sFhkwtJnfCP+4b67tSrjZedutV J/Z3yCxHB2DucgCMSg+5b0bFVBmQT2hHzPp3ZR4mF70o4+ne07IrmoCzC+hYbCkkO1HZ mvkgQ6Bg7cWujxQYPzLi8ZDbyp+96JEA91Zb4lCiZWJ50SdClY/4/5UAuTSXewrcU/Io boCiwB7wWRn7cwqAQ86bPtCO/Hw5Hcn+Vzmq+xCi9DbkZ0bHcb5R18gcrwBD+6vFG8dz Dd/g== 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=x38p0gWD91YX2y+SHRO0boRbxDQ/68lnOxCdXK758wM=; b=tU6ziMNixKzklSjmF2Zba0z6SjVZFYHatJnkI6SinafmrriF/Q4aAJ9LH4LJsWTNI0 K8FL/JmUd38zI0rkt+x+L4OCo/UGx/XKmj/9Ffkhbc5i9SqSvZP675ioojbfrqJVD7mp BGXwjGuDPby+iwYkeZcAWleSikoicB9laIPkqo3AXAyi13ID3O/vQatJm04iIRQUng3E Ww/aNpCRRQZHNZCKehCrLZBKDqKOlaZ29KaA0TYYcDVBSR8w41nyvtbKqOqSk4Uduwzw ELJphGkGqRjxR7+D2ad0w6B+21eC+AdqQ5RkPWhfXeLuWV+zUWHRkccTSJrFEaxZKyIf T0ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Ef8ZoPyW; 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 s26-20020a63925a000000b00553ebb05d14si5504337pgn.111.2023.06.22.02.58.39; Thu, 22 Jun 2023 02:58:52 -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=desiato.20200630 header.b=Ef8ZoPyW; 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 S229564AbjFVJtz (ORCPT + 99 others); Thu, 22 Jun 2023 05:49:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbjFVJtV (ORCPT ); Thu, 22 Jun 2023 05:49:21 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2035E3C3D; Thu, 22 Jun 2023 02:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=x38p0gWD91YX2y+SHRO0boRbxDQ/68lnOxCdXK758wM=; b=Ef8ZoPyWi8golq3xJ11Gi7qZj1 GRdhe8lrHWSiYuAriORJh6ygndefQMRS1hl24dEbLYT0FxdGJ8NzfZe3hIQufebq36SUN74rflOko uakxPor+ru5YOVzWDlGCGi6YK67VV4tIJsy6/KNaUnqYIrypufHAWtbDwKHhA3lCH7n9BmwEpIjME lPvIsmdIWc5Vz28QlF0kLuFqJqj5mUUsz09CH0xcp76WePpW1FgpehzQcOjs1clyyKoL59EmapJ9K AGAY48sK9JhEGZpg+hyZUeuAURrbpjYFga7F8iRkjh1CS+W+w4JCu1h7U6gt+CZ5rOdGySSK4Xg0e WpmIBjqg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qCGlq-0018g0-1K; Thu, 22 Jun 2023 09:38:30 +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) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 793E3300338; Thu, 22 Jun 2023 11:38:28 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 448342425A86B; Thu, 22 Jun 2023 11:38:28 +0200 (CEST) Date: Thu, 22 Jun 2023 11:38:28 +0200 From: Peter Zijlstra To: Josh Poimboeuf Cc: Waiman Long , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , 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 v3 2/3] intel_idle: Sync up the SPEC_CTRL MSR value to x86_spec_ctrl_current Message-ID: <20230622093828.GE4253@hirez.programming.kicks-ass.net> References: <20230622003603.1188364-1-longman@redhat.com> <20230622003603.1188364-3-longman@redhat.com> <20230622054633.ulrurzzvzjijvdhn@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230622054633.ulrurzzvzjijvdhn@treble> 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 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 10:46:33PM -0700, Josh Poimboeuf wrote: > On Wed, Jun 21, 2023 at 08:36:02PM -0400, Waiman Long wrote: > > When intel_idle_ibrs() is called, it modifies the SPEC_CTRL MSR to > > 0 in order disable IBRS. However, the new MSR value isn't reflected > > in x86_spec_ctrl_current which is at odd with the other code that > > keep track of its state in that percpu variable. Fix that by updating > > x86_spec_ctrl_current percpu value to always match the content of the > > SPEC_CTRL MSR. > > Is this fixing an actual bug or is there some other reason for doing > this? > > > > > Signed-off-by: Waiman Long > > --- > > drivers/idle/intel_idle.c | 8 ++++++-- > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c > > index aa2d19db2b1d..07fa23707b3c 100644 > > --- a/drivers/idle/intel_idle.c > > +++ b/drivers/idle/intel_idle.c > > @@ -181,13 +181,17 @@ static __cpuidle int intel_idle_ibrs(struct cpuidle_device *dev, > > u64 spec_ctrl = spec_ctrl_current(); > > int ret; > > > > - if (smt_active) > > + if (smt_active) { > > + __this_cpu_write(x86_spec_ctrl_current, 0); > > native_wrmsrl(MSR_IA32_SPEC_CTRL, 0); > > + } > > > > ret = __intel_idle(dev, drv, index); > > > > - if (smt_active) > > + if (smt_active) { > > native_wrmsrl(MSR_IA32_SPEC_CTRL, spec_ctrl); > > + __this_cpu_write(x86_spec_ctrl_current, spec_ctrl); > > + } > > More candidates for update_spec_ctrl()? Both this and the play_dead case can't use update_spec_ctrl() because RCU isn't there anymore and all that is noinstr. Additionally, both sites rely on preemption being off already, where update_spec_ctrl() can't do that. That said, I suppose one could write it like so: static __always_inline __update_spec_ctrl(u64 val) { __this_cpu_write(x86_spec_ctrl_current, val); native_wrmsrl(MSR_IA32_SPEC_CTRL, val); } static void update_spec_ctrl(u64 val) { preempt_disable(); __update_spec_ctrl(val); preempt_enable(); } And then you can use __update_spec_ctrl(). But that would need a wee audit of using native_wrmsrl() in all places, probably ok, IIRC Xen wasn't using our IBRS stuff anyway.