mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Nicholas Mc Guire <hofrat@osadl.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org, Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH] locking: type cleanup when accessing fast_read_ctr
Date: Tue, 19 May 2015 13:11:05 +0200	[thread overview]
Message-ID: <20150519111105.GB3644@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1431971282-21412-1-git-send-email-hofrat@osadl.org>

On Mon, May 18, 2015 at 07:48:02PM +0200, Nicholas Mc Guire wrote:
> static code checking with coccinelle was unhappy with:
> ./kernel/locking/percpu-rwsem.c:113 WARNING: return of wrong type
> 	int != unsigned int
> 
> 
> current state:
> 
> include/linux/percpu-rwsem.h:
> struct percpu_rw_semaphore {
>   unsigned int __percpu   *fast_read_ctr;
>   ...
>   atomic_t                slow_read_ctr;
> 
> allocated as int:
> 
> int __percpu_init_rwsem(struct percpu_rw_semaphore *brw,
>                         const char *name, struct lock_class_key *rwsem_key)
> {
> 	brw->fast_read_ctr = alloc_percpu(int); 
> 
> used compliant with type int in:
> 
> static bool update_fast_ctr(struct percpu_rw_semaphore *brw, 
> 			    unsigned int val)
> usage (2):
>   update_fast_ctr(brw, +1)
>   update_fast_ctr(brw, -1)
>  
> so val should be int here not unsigned int 
> 
> static int clear_fast_ctr(struct percpu_rw_semaphore *brw)
> usage (1):
>   atomic_add(clear_fast_ctr(brw), &brw->slow_read_ctr);
> 
> slow_read_ctr is atomic_t which is int so it would be consistent here to
> have fast_read_ctr being changed to int as well.
> 
> This patch changes:
>   fast_read_ctr to int
>   clear_fast_ctr():sum to int
>   update_fast_ctr():val to int
> to make usage of fast_read_ctr consistent with respect to type.
> 
>   ( Patch was build tested with x86_64_defconfig + 
>     CONFIG_UPROBE_EVENT (implies CONFIG_PERCPU_RWSEM=y))
> 
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>

So the value is unsigned by purpose; that said we should never cross the
2G I think, so it really doesn't matter much.

Cc'ed Oleg who wrote this code, left the rest of the msg for his
convencience.

That said; Oleg, should I post those patches implementing percpu-rwsem
with the stuff we did for the hotplug lock a while back? I think I
actually have those around somewhere.

> ---
>  include/linux/percpu-rwsem.h  |    2 +-
>  kernel/locking/percpu-rwsem.c |    4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h
> index 3e88c9a..ba37dbe 100644
> --- a/include/linux/percpu-rwsem.h
> +++ b/include/linux/percpu-rwsem.h
> @@ -8,7 +8,7 @@
>  #include <linux/lockdep.h>
>  
>  struct percpu_rw_semaphore {
> -	unsigned int __percpu	*fast_read_ctr;
> +	int __percpu		*fast_read_ctr;
>  	atomic_t		write_ctr;
>  	struct rw_semaphore	rw_sem;
>  	atomic_t		slow_read_ctr;
> diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c
> index 652a8ee..002837d 100644
> --- a/kernel/locking/percpu-rwsem.c
> +++ b/kernel/locking/percpu-rwsem.c
> @@ -52,7 +52,7 @@ void percpu_free_rwsem(struct percpu_rw_semaphore *brw)
>   * reader inside the critical section. See the comments in down_write and
>   * up_write below.
>   */
> -static bool update_fast_ctr(struct percpu_rw_semaphore *brw, unsigned int val)
> +static bool update_fast_ctr(struct percpu_rw_semaphore *brw, int val)
>  {
>  	bool success = false;
>  
> @@ -102,7 +102,7 @@ void percpu_up_read(struct percpu_rw_semaphore *brw)
>  
>  static int clear_fast_ctr(struct percpu_rw_semaphore *brw)
>  {
> -	unsigned int sum = 0;
> +	int sum = 0;
>  	int cpu;
>  
>  	for_each_possible_cpu(cpu) {
> -- 
> 1.7.10.4
> 

  reply	other threads:[~2015-05-19 11:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-18 17:48 Nicholas Mc Guire
2015-05-19 11:11 ` Peter Zijlstra [this message]
2015-05-19 11:25   ` Nicholas Mc Guire
2015-05-20 17:44     ` Oleg Nesterov
2015-05-23  6:46       ` Nicholas Mc Guire
2015-05-23  9:23       ` Nicholas Mc Guire
2015-05-24 18:18         ` Oleg Nesterov
2015-05-25  5:46           ` Nicholas Mc Guire
2015-05-20 17:42   ` Oleg Nesterov

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=20150519111105.GB3644@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=hofrat@osadl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.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

all inboxes | Powered by JetHome®