From: Peter Zijlstra <peterz@infradead.org>
To: Nadav Amit <nadav.amit@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>,
Vlastimil Babka <vbabka@suse.cz>, Linux-MM <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>, X86 ML <x86@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Andy Lutomirski <luto@kernel.org>
Subject: Re: Should this_cpu_read() be volatile?
Date: Mon, 10 Dec 2018 09:55:32 +0100 [thread overview]
Message-ID: <20181210085532.GG5289@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <5DE00B41-835C-4E68-B192-2A3C7ACB4392@gmail.com>
On Sun, Dec 09, 2018 at 04:57:43PM -0800, Nadav Amit wrote:
> > On Dec 8, 2018, at 2:52 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> > My patch proposed here:
> >
> > https://marc.info/?l=linux-mm&m=154409548410209
> >
> > would actually fix that one I think, preempt_count() uses
> > raw_cpu_read_4() which will loose the volatile with that patch.
> I tested the patch you referenced, and it certainly improves the situation
> for reads, but there are still small and big issues lying around.
I'm sure :-(, this has been 'festering' for a long while it seems. And
esp. on x86 specific code, where for a long time we all assumed the
various per-cpu APIs were in fact the same (which turns out to very much
not be true).
> The biggest one is that (I think) smp_processor_id() should apparently use
> __this_cpu_read().
Agreed, and note that this will also improve code generation on !x86.
However, I'm not sure the current !debug definition:
#define smp_processor_id() raw_smp_processor_id()
is actually correct. Where raw_smp_processor_id() must be
this_cpu_read() to avoid CSE, we actually want to allow CSE on
smp_processor_id() etc..
> There are all kind of other smaller issues, such as set_irq_regs() and
> get_irq_regs(), which should run with disabled interrupts. They affect the
> generated code in do_IRQ() and others.
>
> But beyond that, there are so many places in the code that use
> this_cpu_read() while IRQs are guaranteed to be disabled. For example
> arch/x86/mm/tlb.c is full with this_cpu_read/write() and almost(?) all
> should be running with interrupts disabled. Having said that, in my build
> only flush_tlb_func_common() was affected.
This all feels like something static analysis could help with; such
tools would also make sense for !x86 where the difference between the
various per-cpu accessors is even bigger.
next prev parent reply other threads:[~2018-12-10 8:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-28 14:01 Number of arguments in vmalloc.c Matthew Wilcox
2018-12-03 13:59 ` Vlastimil Babka
2018-12-03 16:13 ` Matthew Wilcox
2018-12-03 22:04 ` Nadav Amit
2018-12-03 22:49 ` Matthew Wilcox
2018-12-04 3:12 ` Nadav Amit
2018-12-06 8:28 ` Nadav Amit
2018-12-06 10:25 ` Peter Zijlstra
2018-12-06 11:24 ` Peter Zijlstra
2018-12-06 17:26 ` Nadav Amit
2018-12-07 8:45 ` Peter Zijlstra
2018-12-07 23:12 ` Nadav Amit
2018-12-08 0:40 ` Should this_cpu_read() be volatile? Nadav Amit
2018-12-08 10:52 ` Peter Zijlstra
2018-12-10 0:57 ` Nadav Amit
2018-12-10 8:55 ` Peter Zijlstra [this message]
2018-12-11 17:11 ` Nadav Amit
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=20181210085532.GG5289@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=nadav.amit@gmail.com \
--cc=tglx@linutronix.de \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox