linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Tejun Heo <tj@kernel.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	Fr??d??ric Weisbecker <fweisbec@gmail.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Christoph Lameter <cl@linux-foundation.org>,
	linux-next@vger.kernel.org, linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: linux-next: percpu tree build warning
Date: Fri, 27 Nov 2009 07:20:01 +0100	[thread overview]
Message-ID: <20091127062001.GA22149@elte.hu> (raw)
In-Reply-To: <4B0F6A67.9010706@kernel.org>


* Tejun Heo <tj@kernel.org> wrote:

> Hello,
> 
> 11/27/2009 02:41 PM, Ingo Molnar wrote:
> > But allowing &dr7 is outright dangerous - and not particularly clean 
> > either.
> > 
> > Nothing tells us that it's a percpu variable and it blends into the 
> > regular namespace while most of the operators on it are special 
> > (__get_cpu_var(), per_cpu(), __this_cpu(), etc.).
> > 
> > What if someone writes &dr7 in preemptible code? It's dangerous to do it 
> > and a quick review wont catch the mistake. Seeing &per_cpu_dr7 in 
> > clearly preemptible code does raise alarms on the other hand.
> >
> > So i think it should be valid to take the address of it and unify the 
> > static and dynamic percpu space ... if it's prefixed properly: what's 
> > wrong with &per_cpu_dr7?
> 
> DEFINE_PER_CPU(unsigned long, reg0);
> DEFINE_PER_CPU(unsigned long, reg1);
> 
> static void my_fn(void)
> {
> 	unsigned long reg0 = per_cpu_var(reg0);
> 	unsigned long reg1 = per_cpu_var(reg1);
> 	unsigned long *p = &per_cpu_var(reg0);
> 
> 	// blah blah
> 
> 	if (some cond)
> 		p = &reg1;	// oops meant &per_cpu_var(reg1)
> 
> 	// blah blah
> 
> 	this_cpu_inc(p);

At least to me a typo like this would stick out like a sore thumb during 
review.

I'd recognize &reg1 as a stack local variable immediately, and when i 
see it being used in this_cpu_inc() i'd go 'huh' immediately.

OTOH, the two examples of confusion i gave you in my previous mail would 
be far less obvious. The 'visual distance' to a percpu variable 
definition is greater (it's at least file scope in 95% of the cases), so 
i wouldnt be able to 'see' which the percpu variables are, from a code 
context.

Anyway, YMMV.

Thanks,

	Ingo

  reply	other threads:[~2009-11-27  6:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-25 10:42 linux-next: percpu tree build warning Stephen Rothwell
2009-11-25 10:50 ` Ingo Molnar
2009-11-25 11:14   ` Rusty Russell
2009-11-25 11:58     ` Ingo Molnar
2009-11-25 12:39       ` Tejun Heo
2009-11-25 12:31   ` Tejun Heo
2009-11-25 13:40     ` Ingo Molnar
2009-11-25 15:12       ` Tejun Heo
2009-11-26 22:16       ` Rusty Russell
2009-11-27  5:41         ` Ingo Molnar
2009-11-27  5:57           ` Tejun Heo
2009-11-27  6:20             ` Ingo Molnar [this message]
2009-11-27  6:31               ` Tejun Heo
2009-11-27  6:32                 ` Tejun Heo
2009-11-28  9:51           ` Rusty Russell
2009-11-29  6:40             ` Ingo Molnar
2009-11-30  0:31               ` Rusty Russell
2009-11-25 13:24   ` [PATCH] x86: rename global percpu symbol dr7 to cpu_dr7 Tejun Heo
  -- strict thread matches above, loose matches on Subject: below --
2009-11-12  6:45 linux-next: percpu tree build warning Stephen Rothwell
2009-11-12 15:16 ` Christoph Lameter

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=20091127062001.GA22149@elte.hu \
    --to=mingo@elte.hu \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=sfr@canb.auug.org.au \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).