* [RFC PATCH] x86/delay: Do not use cpu_tss in preemptible ctxt in delay_mwaitx()
@ 2016-03-09 11:37 Borislav Petkov
2016-03-09 17:56 ` Andy Lutomirski
0 siblings, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2016-03-09 11:37 UTC (permalink / raw)
To: X86 ML; +Cc: Peter Zijlstra, LKML, Andy Lutomirski, Huang Rui, spg_linux_kernel
From: Borislav Petkov <bp@suse.de>
So Andy had a good idea about using a cacheline-aligned, seldomly used
per-cpu var as the MONITORX target but we can't use it in preemptible
context. The first simple idea I have is to disable preemption around us
dereffing it.
Better ideas?
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Huang Rui <ray.huang@amd.com>
Cc: spg_linux_kernel@amd.com
---
arch/x86/lib/delay.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
index e912b2f6d36e..c1810afcd2ea 100644
--- a/arch/x86/lib/delay.c
+++ b/arch/x86/lib/delay.c
@@ -92,17 +92,22 @@ static void delay_tsc(unsigned long __loops)
static void delay_mwaitx(unsigned long __loops)
{
u64 start, end, delay, loops = __loops;
+ struct tss_struct *t;
+
+ /*
+ * Use cpu_tss as a cacheline-aligned, seldomly accessed per-cpu
+ * variable as the monitor target.
+ */
+ preempt_disable();
+ t = this_cpu_ptr(&cpu_tss);
+ preempt_enable();
start = rdtsc_ordered();
for (;;) {
delay = min_t(u64, MWAITX_MAX_LOOPS, loops);
- /*
- * Use cpu_tss as a cacheline-aligned, seldomly
- * accessed per-cpu variable as the monitor target.
- */
- __monitorx(this_cpu_ptr(&cpu_tss), 0, 0);
+ __monitorx(t, 0, 0);
/*
* AMD, like Intel, supports the EAX hint and EAX=0xf
--
2.3.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] x86/delay: Do not use cpu_tss in preemptible ctxt in delay_mwaitx()
2016-03-09 11:37 [RFC PATCH] x86/delay: Do not use cpu_tss in preemptible ctxt in delay_mwaitx() Borislav Petkov
@ 2016-03-09 17:56 ` Andy Lutomirski
2016-03-09 18:10 ` Borislav Petkov
0 siblings, 1 reply; 5+ messages in thread
From: Andy Lutomirski @ 2016-03-09 17:56 UTC (permalink / raw)
To: Borislav Petkov; +Cc: Huang Rui, Peter Zijlstra, spg_linux_kernel, X86 ML, LKML
On Mar 9, 2016 3:38 AM, "Borislav Petkov" <bp@alien8.de> wrote:
>
> From: Borislav Petkov <bp@suse.de>
>
> So Andy had a good idea about using a cacheline-aligned, seldomly used
> per-cpu var as the MONITORX target but we can't use it in preemptible
> context. The first simple idea I have is to disable preemption around us
> dereffing it.
What's the actual problem? Is it the preempt warnings and, if so,
would raw_cpu_ptr fix it?
It may pay to move it into the loop, though.
--Andy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] x86/delay: Do not use cpu_tss in preemptible ctxt in delay_mwaitx()
2016-03-09 17:56 ` Andy Lutomirski
@ 2016-03-09 18:10 ` Borislav Petkov
2016-03-09 20:56 ` [PATCH] x86/delay: Avoid preemptible context checks " Borislav Petkov
0 siblings, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2016-03-09 18:10 UTC (permalink / raw)
To: Andy Lutomirski; +Cc: Huang Rui, Peter Zijlstra, spg_linux_kernel, X86 ML, LKML
On Wed, Mar 09, 2016 at 09:56:39AM -0800, Andy Lutomirski wrote:
> On Mar 9, 2016 3:38 AM, "Borislav Petkov" <bp@alien8.de> wrote:
> >
> > From: Borislav Petkov <bp@suse.de>
> >
> > So Andy had a good idea about using a cacheline-aligned, seldomly used
> > per-cpu var as the MONITORX target but we can't use it in preemptible
> > context. The first simple idea I have is to disable preemption around us
> > dereffing it.
>
> What's the actual problem? Is it the preempt warnings and, if so,
> would raw_cpu_ptr fix it?
Yeah, it is the warning:
[ 1.565876] BUG: using smp_processor_id() in preemptible [00000000] code: udevd/312
[ 1.566123] caller is delay_mwaitx+0x40/0xa0
and yes, I think so. I don't think we care about being in preemptible
context since we're going idle anyway and doesn't matter which cpu_tss
we touch.
Yeah, I'll use raw_cpu_ptr...
> It may pay to move it into the loop, though.
... and won't need to do that.
Thanks for the idea.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] x86/delay: Avoid preemptible context checks in delay_mwaitx()
2016-03-09 18:10 ` Borislav Petkov
@ 2016-03-09 20:56 ` Borislav Petkov
2016-03-10 11:07 ` [tip:x86/urgent] " tip-bot for Borislav Petkov
0 siblings, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2016-03-09 20:56 UTC (permalink / raw)
To: Andy Lutomirski; +Cc: Huang Rui, Peter Zijlstra, spg_linux_kernel, X86 ML, LKML
We do use this_cpu_ptr(&cpu_tss) as a cacheline-aligned, seldomly
accessed per-cpu var as the MONITORX target in delay_mwaitx(). However,
when called in preemptible context, this_cpu_ptr -> smp_processor_id() ->
debug_smp_processor_id() fires:
BUG: using smp_processor_id() in preemptible [00000000] code: udevd/312
caller is delay_mwaitx+0x40/0xa0
But we don't care about that check - we only need cpu_tss as a MONITORX
target and it doesn't really matter which CPU's var we're touching as
we're going idle anyway. Fix that.
Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Huang Rui <ray.huang@amd.com>
Cc: spg_linux_kernel@amd.com
---
arch/x86/lib/delay.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
index e912b2f6d36e..2f07c291dcc8 100644
--- a/arch/x86/lib/delay.c
+++ b/arch/x86/lib/delay.c
@@ -102,7 +102,7 @@ static void delay_mwaitx(unsigned long __loops)
* Use cpu_tss as a cacheline-aligned, seldomly
* accessed per-cpu variable as the monitor target.
*/
- __monitorx(this_cpu_ptr(&cpu_tss), 0, 0);
+ __monitorx(raw_cpu_ptr(&cpu_tss), 0, 0);
/*
* AMD, like Intel, supports the EAX hint and EAX=0xf
--
2.3.5
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip:x86/urgent] x86/delay: Avoid preemptible context checks in delay_mwaitx()
2016-03-09 20:56 ` [PATCH] x86/delay: Avoid preemptible context checks " Borislav Petkov
@ 2016-03-10 11:07 ` tip-bot for Borislav Petkov
0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Borislav Petkov @ 2016-03-10 11:07 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, luto, luto, hpa, torvalds, mingo, bp, bp,
ray.huang, peterz, tglx, a.p.zijlstra
Commit-ID: 84477336ec03f8061ffd6908da341e063e5d6d1f
Gitweb: http://git.kernel.org/tip/84477336ec03f8061ffd6908da341e063e5d6d1f
Author: Borislav Petkov <bp@alien8.de>
AuthorDate: Wed, 9 Mar 2016 21:56:22 +0100
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 10 Mar 2016 11:27:12 +0100
x86/delay: Avoid preemptible context checks in delay_mwaitx()
We do use this_cpu_ptr(&cpu_tss) as a cacheline-aligned, seldomly
accessed per-cpu var as the MONITORX target in delay_mwaitx(). However,
when called in preemptible context, this_cpu_ptr -> smp_processor_id() ->
debug_smp_processor_id() fires:
BUG: using smp_processor_id() in preemptible [00000000] code: udevd/312
caller is delay_mwaitx+0x40/0xa0
But we don't care about that check - we only need cpu_tss as a MONITORX
target and it doesn't really matter which CPU's var we're touching as
we're going idle anyway. Fix that.
Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: spg_linux_kernel@amd.com
Link: http://lkml.kernel.org/r/20160309205622.GG6564@pd.tnic
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/lib/delay.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
index e912b2f..2f07c29 100644
--- a/arch/x86/lib/delay.c
+++ b/arch/x86/lib/delay.c
@@ -102,7 +102,7 @@ static void delay_mwaitx(unsigned long __loops)
* Use cpu_tss as a cacheline-aligned, seldomly
* accessed per-cpu variable as the monitor target.
*/
- __monitorx(this_cpu_ptr(&cpu_tss), 0, 0);
+ __monitorx(raw_cpu_ptr(&cpu_tss), 0, 0);
/*
* AMD, like Intel, supports the EAX hint and EAX=0xf
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-03-10 11:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-09 11:37 [RFC PATCH] x86/delay: Do not use cpu_tss in preemptible ctxt in delay_mwaitx() Borislav Petkov
2016-03-09 17:56 ` Andy Lutomirski
2016-03-09 18:10 ` Borislav Petkov
2016-03-09 20:56 ` [PATCH] x86/delay: Avoid preemptible context checks " Borislav Petkov
2016-03-10 11:07 ` [tip:x86/urgent] " tip-bot for Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).