lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 10 Aug 2021 14:04:16 +0100
From:   Valentin Schneider <valentin.schneider@....com>
To:     Boqun Feng <boqun.feng@...il.com>
Cc:     Mike Galbraith <efault@....de>, linux-kernel@...r.kernel.org,
        linux-arm-kernel@...ts.infradead.org, rcu@...r.kernel.org,
        linux-rt-users@...r.kernel.org,
        Catalin Marinas <catalin.marinas@....com>,
        Will Deacon <will@...nel.org>, Ingo Molnar <mingo@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Steven Rostedt <rostedt@...dmis.org>,
        Daniel Bristot de Oliveira <bristot@...hat.com>,
        Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
        "Paul E. McKenney" <paulmck@...nel.org>,
        Frederic Weisbecker <frederic@...nel.org>,
        Josh Triplett <josh@...htriplett.org>,
        Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
        Davidlohr Bueso <dave@...olabs.net>,
        Lai Jiangshan <jiangshanlai@...il.com>,
        Joel Fernandes <joel@...lfernandes.org>,
        Anshuman Khandual <anshuman.khandual@....com>,
        Vincenzo Frascino <vincenzo.frascino@....com>,
        Steven Price <steven.price@....com>,
        Ard Biesheuvel <ardb@...nel.org>
Subject: Re: [PATCH v2 2/4] sched: Introduce is_pcpu_safe()

On 10/08/21 20:49, Boqun Feng wrote:
> On Sun, Aug 08, 2021 at 05:15:20PM +0100, Valentin Schneider wrote:
>> On 07/08/21 03:42, Mike Galbraith wrote:
>> > On Sat, 2021-08-07 at 01:58 +0100, Valentin Schneider wrote:
>> >>
>> >> +static inline bool is_pcpu_safe(void)
>> >
>> > Nit: seems odd to avoid spelling it out to save two characters, percpu
>> > is word like, rolls off the ole tongue better than p-c-p-u.
>> >
>> >       -Mike
>> 
>> True. A quick grep says both versions are used, though "percpu" wins by
>> about a factor of 2. I'll tweak that for a v3.
>
> I wonder why is_percpu_safe() is the correct name. The safety of
> accesses to percpu variables means two things to me:
>
> a)	The thread cannot migrate to other CPU in the middle of
> 	accessing a percpu variable, in other words, the following
> 	cannot happen:
>
> 	{ percpu variable X is 0 on CPU 0 and 2 on CPU 1
> 	CPU 0				CPU 1
> 	========			=========
> 	<in thread A>
> 	__this_cpu_inc(X);
> 	  tmp = X; // tmp is 0
> 	  <preempted>
> 	  <migrate to CPU 1>
> 	  				// continue __this_cpu_inc(X);
> 					X = tmp + 1; // CPU 0 miss this
> 						     // increment (this
> 						     // may be OK), and
> 						     // CPU 1's X got
> 						     // corrupted.
>
> b)	The accesses to a percpu variable are exclusive, i.e. no
> 	interrupt or preemption can happen in the middle of accessing,
> 	in other words, the following cannot happen:
>
> 	{ percpu variable X is 0 on CPU 0 }
> 	CPU 0
> 	========
> 	<in thread A>
> 	__this_cpu_inc(X);
> 	  tmp = X; // tmp is 0
> 	  <preempted>
> 	  <in other thread>
> 	  this_cpu_inc(X); // X is 1 afterwards.
> 	  <back to thread A>
> 	  X = tmp + 1; // X is 1, and we have a race condition.
>
> And the is_p{er}cpu_safe() only detects the first, and it doesn't mean
> totally safe for percpu accesses.
>

Right. I do briefly point this out in the changelog (the bit about
"acquiring a sleepable lock if relevant"), but that doesn't do much to
clarify the helper name itself.

> Maybe we can implement a migratable()? Although not sure it's a English
> word.
>

Funnily enough that is exactly how I named the thing in my initial draft,
but then I somehow convinced myself that tailoring the name to per-CPU
accesses would make its intent clearer.

I think you're right that "migratable()" is less confusing at the end of
the day. Oh well, so much for overthinking the naming problem :-)

> Regards,
> Boqun

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ