netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org, axboe@kernel.dk,
	rusty@rustcorp.com.au, akpm@linux-foundation.org,
	ebiederm@xmission.com, tytso@mit.edu, Trond.Myklebust@netapp.com,
	aelder@sgi.com, hch@infradead.org, viro@zeniv.linux.org.uk,
	davem@davemloft.net, netdev@vger.kernel.org, x86@kernel.org,
	mingo@redhat.com, dan.j.williams@intel.com,
	borislav.petkov@amd.com, ying.huang@intel.com, lenb@kernel.org,
	neilb@suse.de, cl@linux-foundation.org
Subject: Re: [PATCH 7/8] percpu: add __percpu sparse annotations to hw_breakpoint
Date: Tue, 26 Jan 2010 02:02:40 +0100	[thread overview]
Message-ID: <20100126010239.GK5087@nowhere> (raw)
In-Reply-To: <4B5E3BED.6030705@kernel.org>

On Tue, Jan 26, 2010 at 09:48:45AM +0900, Tejun Heo wrote:
> Hello, Frederic.
> 
> On 01/26/2010 09:19 AM, Frederic Weisbecker wrote:
> > On Tue, Jan 26, 2010 at 12:22:14AM +0900, Tejun Heo wrote:
> >> Add __percpu sparse annotations to hw_breakpoint.
> >>
> >> These annotations are to make sparse consider percpu variables to be
> >> in a different address space and warn if accessed without going
> >> through percpu accessors.  This patch doesn't affect normal builds.
> >>
> >> per_cpu(nr_task_bp_pinned, cpu) is replaced with
> >> &per_cpu(nr_task_bp_pinned[0], cpu).  This is the same to the compiler
> >> but allows per_cpu() macro to correctly drop __percpu designation for
> >> the returned pointer.
> > 
> > Ouch... It's unpleasant to see such workaround that messes up the
> > code just to make sparse happy.
> > 
> > I guess __percpu is an address_space attribute? Is there no
> > way to force the address space change directly from the
> > per_cpu() macro?
> 
> Yeah, per_cpu() macro does that but when things get a bit complicated
> with static percpu arrays.  In the above case, the variable is defined
> as
> 
>   static DEFINE_PER_CPU(unsigned int, nr_task_bp_pinned[HBP_NUM]);
> 
> which gets translated to
> 
>   static __attribute__((noderef, address_space(3))) \
> 	 __attribute__((section(.data.percpu))) \
> 	 __typeof__(unsigned int) nr_task_bp_pinned[HBP_NUM];
> 
> The above tells sparse that the members of nr_task_bp_pinned array are
> in address space 3 which is correct.  The problematic dereference was
> 
>   unsigned int *task_pinned = per_cpu(nr_task_bp_pinned, cpu)
> 
> per_cpu() macro changes the address space of the resulting address but
> it does so assuming that the parameter it got passed is the one which
> got declared to be in the percpu address space.  It casts
> nr_task_bp_pinned itself, which to the sparse isn't in the percpu
> address space, to the kernel address space.  So, the workaround is
> basically to give per_cpu() macro the same thing that was defined.
> 
> This type of usage (define as array, dereference the array as address)
> was the only place where I needed to work around to make address space
> change explicit.  There are two places which needed this and hwbreak
> was one.  The options were...
> 
> * Leave it alone.  We can live with a few additional sparse warnings.
> 
> * Make the proposed change.  It is slightly ugly but not cryptic or
>   difficult.
> 
> * Somehow teach per_cpu() macro or sparse how to handle the above
>   right.
> 
> I tried to improve per_cpu() macro but couldn't do it in any sane way.
> Leaving it alone isn't too bad either but given that the workaround is
> not horribly unreadable, I think it's best to use the slightly less
> elegant form in the few places where they are needed.



Ok.

Well, sorry I must be missing something obvious, but is it impossible
to make per_cpu(var, cpu) returning something cast in:

	(typeof(var) __force)

Or I guess you did that already and it is not working with static
arrays, or?

Is there a patch that shows per_cpu() macro changes in the batch?

Thanks.

  reply	other threads:[~2010-01-26  1:02 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1264432935-10453-1-git-send-email-tj@kernel.org>
2010-01-25 15:22 ` [PATCH 1/8] percpu: add __percpu sparse annotations to core kernel subsystems Tejun Heo
2010-01-25 15:22 ` [PATCH 2/8] percpu: add __percpu sparse annotations to fs Tejun Heo
2010-01-25 15:22 ` [PATCH 3/8] percpu: add __percpu sparse annotations to net Tejun Heo
2010-01-25 21:32   ` David Miller
2010-01-25 15:22 ` [PATCH 4/8] percpu: add __percpu sparse annotations to net drivers Tejun Heo
2010-01-25 15:22 ` [PATCH 5/8] percpu: add __percpu sparse annotations to x86 Tejun Heo
2010-01-25 15:22 ` [PATCH 6/8] percpu: add __percpu sparse annotations to trace Tejun Heo
2010-01-25 15:35   ` Steven Rostedt
2010-01-25 15:22 ` [PATCH 7/8] percpu: add __percpu sparse annotations to hw_breakpoint Tejun Heo
2010-01-26  0:19   ` Frederic Weisbecker
2010-01-26  0:48     ` Tejun Heo
2010-01-26  1:02       ` Frederic Weisbecker [this message]
2010-01-26  1:19         ` Tejun Heo
2010-01-26  2:01           ` Frederic Weisbecker
2010-01-26  2:10             ` Frederic Weisbecker
2010-01-26  2:13             ` Tejun Heo
2010-01-26  2:18               ` Frederic Weisbecker
2010-01-26  2:22                 ` Frederic Weisbecker
2010-01-26  2:34                   ` Tejun Heo
2010-01-26  2:35                     ` Frederic Weisbecker
2010-01-26  2:47                       ` Tejun Heo
2010-01-26  1:02     ` H. Peter Anvin
2010-01-26  2:06       ` Tejun Heo
2010-01-26  2:04         ` Al Viro
2010-01-26  2:16           ` Tejun Heo
2010-01-26  2:32             ` Al Viro
2010-01-26  2:43               ` Tejun Heo
2010-01-26  2:48                 ` Al Viro
2010-01-26  3:10                   ` Tejun Heo
2010-01-26  3:56                     ` Al Viro
2010-01-26  1:06     ` H. Peter Anvin
2010-01-26  1:12       ` Frederic Weisbecker
2010-01-26  2:10       ` Tejun Heo
2010-01-25 15:22 ` [PATCH 8/8] percpu: add __percpu sparse annotations to what's left Tejun Heo
     [not found] ` <1264432935-10453-9-git-send-email-tj@kernel.org>
2010-01-25 15:54   ` Borislav Petkov
     [not found] ` <1264432935-10453-5-git-send-email-tj@kernel.org>
2010-01-25 21:33   ` [PATCH 4/8] percpu: add __percpu sparse annotations to net drivers David Miller
2010-01-25 23:14 ` [PATCHSET] percpu: add __percpu sparse annotations Al Viro
2010-01-26  0:30   ` Tejun Heo
     [not found] ` <1264432935-10453-6-git-send-email-tj@kernel.org>
2010-01-26  1:06   ` [PATCH 5/8] percpu: add __percpu sparse annotations to x86 H. Peter Anvin
2010-01-26  2:17     ` Tejun Heo
2010-02-01  3:30       ` H. Peter Anvin
     [not found] ` <1264432935-10453-2-git-send-email-tj@kernel.org>
2010-01-25 21:58   ` [PATCH 1/8] percpu: add __percpu sparse annotations to core kernel subsystems Christoph Lameter
2010-01-31 11:42   ` Paul E. McKenney
2010-02-02  5:37 ` [PATCHSET] percpu: add __percpu sparse annotations Tejun Heo

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=20100126010239.GK5087@nowhere \
    --to=fweisbec@gmail.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=aelder@sgi.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=borislav.petkov@amd.com \
    --cc=cl@linux-foundation.org \
    --cc=dan.j.williams@intel.com \
    --cc=davem@davemloft.net \
    --cc=ebiederm@xmission.com \
    --cc=hch@infradead.org \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=neilb@suse.de \
    --cc=netdev@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tj@kernel.org \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    --cc=x86@kernel.org \
    --cc=ying.huang@intel.com \
    /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).