From: Peter Zijlstra <peterz@infradead.org>
To: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Cc: Balbir Singh <sblbir@amazon.com>,
Thomas Gleixner <tglx@linutronix.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Nathan Chancellor <natechancellor@gmail.com>,
Nick Desaulniers <ndesaulniers@google.com>,
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()
Date: Tue, 29 Sep 2020 08:37:09 +0000 [thread overview]
Message-ID: <20200929083709.GC2651@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200929071211.GJ2628@hirez.programming.kicks-ass.net>
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)
WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Cc: Balbir Singh <sblbir@amazon.com>,
Thomas Gleixner <tglx@linutronix.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Nathan Chancellor <natechancellor@gmail.com>,
Nick Desaulniers <ndesaulniers@google.com>,
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()
Date: Tue, 29 Sep 2020 10:37:09 +0200 [thread overview]
Message-ID: <20200929083709.GC2651@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200929071211.GJ2628@hirez.programming.kicks-ass.net>
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)
next prev parent reply other threads:[~2020-09-29 8:37 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-28 12:44 [PATCH -next for tip:x86/pti] x86/tlb: drop unneeded local vars in enable_l1d_flush_for_task() Lukas Bulwahn
2020-09-28 12:44 ` Lukas Bulwahn
2020-09-28 20:43 ` Nathan Chancellor
2020-09-28 20:43 ` Nathan Chancellor
2020-09-29 7:12 ` Peter Zijlstra
2020-09-29 7:12 ` Peter Zijlstra
2020-09-29 8:33 ` Lukas Bulwahn
2020-09-29 8:33 ` Lukas Bulwahn
2020-09-29 8:37 ` Peter Zijlstra [this message]
2020-09-29 8:37 ` Peter Zijlstra
2020-09-30 15:40 ` Thomas Gleixner
2020-09-30 15:40 ` Thomas Gleixner
2020-09-30 16:53 ` Lukas Bulwahn
2020-09-30 16:53 ` Lukas Bulwahn
2020-09-30 17:03 ` Peter Zijlstra
2020-09-30 17:03 ` Peter Zijlstra
2020-09-30 18:00 ` Thomas Gleixner
2020-09-30 18:00 ` Thomas Gleixner
2020-09-30 18:35 ` Peter Zijlstra
2020-09-30 18:35 ` Peter Zijlstra
2020-09-30 21:38 ` Thomas Gleixner
2020-09-30 21:38 ` Thomas Gleixner
2020-09-30 22:59 ` Singh, Balbir
2020-09-30 22:59 ` Singh, Balbir
2020-09-30 23:49 ` Singh, Balbir
2020-09-30 23:49 ` Singh, Balbir
2020-10-01 0:48 ` Singh, Balbir
2020-10-01 0:48 ` Singh, Balbir
2020-10-01 8:17 ` Thomas Gleixner
2020-10-01 8:17 ` Thomas Gleixner
2020-10-01 8:19 ` Peter Zijlstra
2020-10-01 8:19 ` Peter Zijlstra
2020-09-30 22:46 ` Singh, Balbir
2020-09-30 22:46 ` Singh, Balbir
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200929083709.GC2651@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bp@alien8.de \
--cc=clang-built-linux@googlegroups.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-safety@lists.elisa.tech \
--cc=lukas.bulwahn@gmail.com \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
--cc=sblbir@amazon.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.