Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3622562pxk; Tue, 29 Sep 2020 01:38:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe0shh/lhW8CZk0qlerLwPi5piY6x1NPogeeXATpV1reOQnvwVOJ8bcEcSkrdIEmIFA8CJ X-Received: by 2002:a50:8e17:: with SMTP id 23mr2008063edw.31.1601368738294; Tue, 29 Sep 2020 01:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601368738; cv=none; d=google.com; s=arc-20160816; b=MVpJYNEhLCTDK29hTlGBg1oTDw3wCsKPiz/GaB0pklxvwZvEuOlP0paKWviwXzDB10 plGvquMcT+T0CKci6KHbPfjvJgZ4xSIKNQd8GiCBfhilBVbtfUFCS1kaec0NX02nT/oI MqTbCy3KpER3YC8URg5KkZhVYl7qw4Uuldk52TBmJjmBxDov+tmKYIspDS9s5D5sumxK oTmJ7LmMXEwZjSeqbVcy8UQEqWNgfNAON+xJ+kYDR8QUdistRKAo0ToUI2EEyHQqGugM b9cAWIpQd0LTqgvVSwYYT264VHX1/dgvsfrl1l+D/B0YSYOFGAkbo0NQqePOFLGKmFL+ IsOQ== 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=v5vnDoRc4ZKtko7VMYgaivypIuJCC2NRDarrflWRAvg=; b=zPCiRjGPC1/JDkEvLNardfCvPM1HUMYaYJgH1jUNsZcW8BvKGaSd1Xv5u7tTOvrH16 D5fxea6EynCFuKjjAWZlqRfXKgCBf1C/lpGqqypYHm1gxkoQ6AoPvT/ayddJPd+iGcAZ DSRglpd9ZM4LwSdgG3jQ0b+TqBA3J29Y60ILkvBV9NXwZHe4xtPWFTkOF6LxEMllDi87 ggkPouY9ctT7t6f5X2omC55seFrqaBmw/JG51FC9v4gI59YhjUsXVNCKwNdqxFd4FyD+ 19PZYDWtj/TLrPi1rXdurOeJGO5GxbBs91Ag7bIarFO1rN+ENDQtXbEkHJHmhQgvujUD Sy+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=wWOWiQjk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l14si2302026eje.378.2020.09.29.01.38.35; Tue, 29 Sep 2020 01:38:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=wWOWiQjk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727756AbgI2Ih2 (ORCPT + 99 others); Tue, 29 Sep 2020 04:37:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727704AbgI2Ih2 (ORCPT ); Tue, 29 Sep 2020 04:37:28 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B99E6C061755; Tue, 29 Sep 2020 01:37:27 -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=v5vnDoRc4ZKtko7VMYgaivypIuJCC2NRDarrflWRAvg=; b=wWOWiQjkvkGZA1s8deLmbxrNC8 pTcycx1AeIheWo8YKmtblar3DRLp4W61abEUjEJyP6RQBpMuYfWiHkySwLN/XA6JkCQXmj8t5s5H/ oFAZHBivV6j7ACxy+E4raYd9VO8ksiOruct0gnGWydfhvRUM+VdKBDXOamN5yEIv4NLtIiPcVUyMf Lb0luWbwFDoxRIZ9VHp2TQDv7OMm2pYTdkcd9xZcVQn+IPU3jabWtekFvK3qKFJfpyUWhIOP/bGYN spFFSPleU3snhac//usQJYmy4VJla5oUw7Oer4n+RZNQ5R+j5pcykZc+j4KpAHiH0jqHzccHH7L3D gdzi9qwg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNB8J-00031e-Pr; Tue, 29 Sep 2020 08:37:12 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 60639303F45; Tue, 29 Sep 2020 10:37:09 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 42614211CC1CA; Tue, 29 Sep 2020 10:37:09 +0200 (CEST) Date: Tue, 29 Sep 2020 10:37:09 +0200 From: Peter Zijlstra To: Lukas Bulwahn Cc: Balbir Singh , Thomas Gleixner , Dave Hansen , Andy Lutomirski , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Nathan Chancellor , Nick Desaulniers , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, kernel-janitors@vger.kernel.org, linux-safety@lists.elisa.tech Subject: Re: [PATCH -next for tip:x86/pti] x86/tlb: drop unneeded local vars in enable_l1d_flush_for_task() Message-ID: <20200929083709.GC2651@hirez.programming.kicks-ass.net> References: <20200928124457.27289-1-lukas.bulwahn@gmail.com> <20200929071211.GJ2628@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200929071211.GJ2628@hirez.programming.kicks-ass.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 29, 2020 at 09:12:11AM +0200, Peter Zijlstra wrote: > On Mon, Sep 28, 2020 at 02:44:57PM +0200, Lukas Bulwahn wrote: > > diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c > > index 6b0f4c88b07c..90515c04d90a 100644 > > --- a/arch/x86/mm/tlb.c > > +++ b/arch/x86/mm/tlb.c > > @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(leave_mm); > > > > int enable_l1d_flush_for_task(struct task_struct *tsk) > > { > > - int cpu, ret = 0, i; > > + int i; > > > > /* > > * Do not enable L1D_FLUSH_OUT if > > @@ -329,7 +329,7 @@ int enable_l1d_flush_for_task(struct task_struct *tsk) > > !static_cpu_has(X86_FEATURE_FLUSH_L1D)) > > return -EINVAL; > > > > - cpu = get_cpu(); > > + get_cpu(); > > > > for_each_cpu(i, &tsk->cpus_mask) { > > if (cpu_data(i).smt_active == true) { > > @@ -340,7 +340,7 @@ int enable_l1d_flush_for_task(struct task_struct *tsk) > > > > set_ti_thread_flag(&tsk->thread_info, TIF_SPEC_L1D_FLUSH); > > put_cpu(); > > - return ret; > > + return 0; > > } > > If you don't use the return value of get_cpu(), then change it over to > preempt_{dis,en}able(), but this got me looking at the function, wtf is > that garbage supposed to do in the first place > > What do we need to disable preemption for? > > Please explain the desired semantics against sched_setaffinity(). Here, I fixed it.. --- arch/x86/mm/tlb.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 6b0f4c88b07c..f02a2f1909da 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -316,31 +316,13 @@ EXPORT_SYMBOL_GPL(leave_mm); int enable_l1d_flush_for_task(struct task_struct *tsk) { - int cpu, ret = 0, i; - - /* - * Do not enable L1D_FLUSH_OUT if - * b. The CPU is not affected by the L1TF bug - * c. The CPU does not have L1D FLUSH feature support - * c. The task's affinity is on cores with SMT on. - */ - if (!boot_cpu_has_bug(X86_BUG_L1TF) || - !static_cpu_has(X86_FEATURE_FLUSH_L1D)) + !boot_cpu_has(X86_FEATURE_FLUSH_L1D) || + sched_smt_active()); return -EINVAL; - cpu = get_cpu(); - - for_each_cpu(i, &tsk->cpus_mask) { - if (cpu_data(i).smt_active == true) { - put_cpu(); - return -EINVAL; - } - } - set_ti_thread_flag(&tsk->thread_info, TIF_SPEC_L1D_FLUSH); - put_cpu(); - return ret; + return 0; } int disable_l1d_flush_for_task(struct task_struct *tsk)