Re: [RFC PATCH] set_mb: Use smp_store_release() instead of set_mb()

2014-11-30 Thread Pranith Kumar
On Wed, Nov 26, 2014 at 11:57 AM, Pranith Kumar bobby.pr...@gmail.com wrote:
 set_mb() and smp_store_release() perform the same function. Also there are 
 only
 a few users of set_mb(). We can convert these users to use smp_store_release()
 and delete the set_mb() definition.

 The following patch changes the users and if this is OK I will go ahead and
 delete the set_mb() definition. Comments and suggestions welcome.

 Thanks!
 Pranith

 Signed-off-by: Pranith Kumar bobby.pr...@gmail.com

Please disregard this patch. I just realized that I read the code
wrong. Sorry for the noise.

Thanks!


 ---
  fs/select.c   |  6 +++---
  include/linux/sched.h | 14 +++---
  kernel/futex.c|  4 ++--
  kernel/sched/wait.c   |  4 ++--
  4 files changed, 14 insertions(+), 14 deletions(-)

 diff --git a/fs/select.c b/fs/select.c
 index 467bb1c..959a908 100644
 --- a/fs/select.c
 +++ b/fs/select.c
 @@ -189,7 +189,7 @@ static int __pollwake(wait_queue_t *wait, unsigned mode, 
 int sync, void *key)
  * doesn't imply write barrier and the users expect write
  * barrier semantics on wakeup functions.  The following
  * smp_wmb() is equivalent to smp_wmb() in try_to_wake_up()
 -* and is paired with set_mb() in poll_schedule_timeout.
 +* and is paired with smp_store_release() in poll_schedule_timeout.
  */
 smp_wmb();
 pwq-triggered = 1;
 @@ -244,7 +244,7 @@ int poll_schedule_timeout(struct poll_wqueues *pwq, int 
 state,
 /*
  * Prepare for the next iteration.
  *
 -* The following set_mb() serves two purposes.  First, it's
 +* The following smp_store_release() serves two purposes.  First, it's
  * the counterpart rmb of the wmb in pollwake() such that data
  * written before wake up is always visible after wake up.
  * Second, the full barrier guarantees that triggered clearing
 @@ -252,7 +252,7 @@ int poll_schedule_timeout(struct poll_wqueues *pwq, int 
 state,
  * this problem doesn't exist for the first iteration as
  * add_wait_queue() has full barrier semantics.
  */
 -   set_mb(pwq-triggered, 0);
 +   smp_store_release(pwq-triggered, 0);

 return rc;
  }
 diff --git a/include/linux/sched.h b/include/linux/sched.h
 index 8db31ef..4621d0b 100644
 --- a/include/linux/sched.h
 +++ b/include/linux/sched.h
 @@ -253,7 +253,7 @@ extern char ___assert_task_state[1 - 2*!!(
  #define set_task_state(tsk, state_value)   \
 do {\
 (tsk)-task_state_change = _THIS_IP_;   \
 -   set_mb((tsk)-state, (state_value));\
 +   smp_store_release((tsk)-state, (state_value)); \
 } while (0)

  /*
 @@ -272,10 +272,10 @@ extern char ___assert_task_state[1 - 2*!!(
 current-task_state_change = _THIS_IP_; \
 current-state = (state_value); \
 } while (0)
 -#define set_current_state(state_value) \
 -   do {\
 -   current-task_state_change = _THIS_IP_; \
 -   set_mb(current-state, (state_value));  \
 +#define set_current_state(state_value) \
 +   do {\
 +   current-task_state_change = _THIS_IP_; \
 +   smp_store_release(current-state, (state_value));   \
 } while (0)

  #else
 @@ -283,7 +283,7 @@ extern char ___assert_task_state[1 - 2*!!(
  #define __set_task_state(tsk, state_value) \
 do { (tsk)-state = (state_value); } while (0)
  #define set_task_state(tsk, state_value)   \
 -   set_mb((tsk)-state, (state_value))
 +   smp_store_release((tsk)-state, (state_value))

  /*
   * set_current_state() includes a barrier so that the write of current-state
 @@ -299,7 +299,7 @@ extern char ___assert_task_state[1 - 2*!!(
  #define __set_current_state(state_value)   \
 do { current-state = (state_value); } while (0)
  #define set_current_state(state_value) \
 -   set_mb(current-state, (state_value))
 +   smp_store_release(current-state, (state_value))

  #endif

 diff --git a/kernel/futex.c b/kernel/futex.c
 index 63678b5..0604355 100644
 --- a/kernel/futex.c
 +++ b/kernel/futex.c
 @@ -2055,8 +2055,8 @@ static void futex_wait_queue_me(struct 
 futex_hash_bucket *hb, struct futex_q *q,
  {
 /*
  * The task state is guaranteed to be set before another task can
 -* wake it. set_current_state() is implemented using set_mb() and
 -* queue_me() calls spin_unlock() upon completion, both serializing
 +* wake it. set_current_state() is implemented using 
 smp_store_release

[RFC PATCH] set_mb: Use smp_store_release() instead of set_mb()

2014-11-26 Thread Pranith Kumar
set_mb() and smp_store_release() perform the same function. Also there are only
a few users of set_mb(). We can convert these users to use smp_store_release()
and delete the set_mb() definition.

The following patch changes the users and if this is OK I will go ahead and
delete the set_mb() definition. Comments and suggestions welcome.

Thanks!
Pranith

Signed-off-by: Pranith Kumar 
---
 fs/select.c   |  6 +++---
 include/linux/sched.h | 14 +++---
 kernel/futex.c|  4 ++--
 kernel/sched/wait.c   |  4 ++--
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/fs/select.c b/fs/select.c
index 467bb1c..959a908 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -189,7 +189,7 @@ static int __pollwake(wait_queue_t *wait, unsigned mode, 
int sync, void *key)
 * doesn't imply write barrier and the users expect write
 * barrier semantics on wakeup functions.  The following
 * smp_wmb() is equivalent to smp_wmb() in try_to_wake_up()
-* and is paired with set_mb() in poll_schedule_timeout.
+* and is paired with smp_store_release() in poll_schedule_timeout.
 */
smp_wmb();
pwq->triggered = 1;
@@ -244,7 +244,7 @@ int poll_schedule_timeout(struct poll_wqueues *pwq, int 
state,
/*
 * Prepare for the next iteration.
 *
-* The following set_mb() serves two purposes.  First, it's
+* The following smp_store_release() serves two purposes.  First, it's
 * the counterpart rmb of the wmb in pollwake() such that data
 * written before wake up is always visible after wake up.
 * Second, the full barrier guarantees that triggered clearing
@@ -252,7 +252,7 @@ int poll_schedule_timeout(struct poll_wqueues *pwq, int 
state,
 * this problem doesn't exist for the first iteration as
 * add_wait_queue() has full barrier semantics.
 */
-   set_mb(pwq->triggered, 0);
+   smp_store_release(pwq->triggered, 0);
 
return rc;
 }
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 8db31ef..4621d0b 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -253,7 +253,7 @@ extern char ___assert_task_state[1 - 2*!!(
 #define set_task_state(tsk, state_value)   \
do {\
(tsk)->task_state_change = _THIS_IP_;   \
-   set_mb((tsk)->state, (state_value));\
+   smp_store_release((tsk)->state, (state_value)); \
} while (0)
 
 /*
@@ -272,10 +272,10 @@ extern char ___assert_task_state[1 - 2*!!(
current->task_state_change = _THIS_IP_; \
current->state = (state_value); \
} while (0)
-#define set_current_state(state_value) \
-   do {\
-   current->task_state_change = _THIS_IP_; \
-   set_mb(current->state, (state_value));  \
+#define set_current_state(state_value) \
+   do {\
+   current->task_state_change = _THIS_IP_; \
+   smp_store_release(current->state, (state_value));   \
} while (0)
 
 #else
@@ -283,7 +283,7 @@ extern char ___assert_task_state[1 - 2*!!(
 #define __set_task_state(tsk, state_value) \
do { (tsk)->state = (state_value); } while (0)
 #define set_task_state(tsk, state_value)   \
-   set_mb((tsk)->state, (state_value))
+   smp_store_release((tsk)->state, (state_value))
 
 /*
  * set_current_state() includes a barrier so that the write of current->state
@@ -299,7 +299,7 @@ extern char ___assert_task_state[1 - 2*!!(
 #define __set_current_state(state_value)   \
do { current->state = (state_value); } while (0)
 #define set_current_state(state_value) \
-   set_mb(current->state, (state_value))
+   smp_store_release(current->state, (state_value))
 
 #endif
 
diff --git a/kernel/futex.c b/kernel/futex.c
index 63678b5..0604355 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2055,8 +2055,8 @@ static void futex_wait_queue_me(struct futex_hash_bucket 
*hb, struct futex_q *q,
 {
/*
 * The task state is guaranteed to be set before another task can
-* wake it. set_current_state() is implemented using set_mb() and
-* queue_me() calls spin_unlock() upon completion, both serializing
+* wake it. set_current_state() is implemented using smp_store_release()
+* and queue_me() calls spin_unlock() upon completion, both serializing
 * access to the hash list and forcing another memory barrier.
 */
set_current_state(TASK_INTERRUPTIBLE);
diff --git a/kernel/sched/w

[RFC PATCH] set_mb: Use smp_store_release() instead of set_mb()

2014-11-26 Thread Pranith Kumar
set_mb() and smp_store_release() perform the same function. Also there are only
a few users of set_mb(). We can convert these users to use smp_store_release()
and delete the set_mb() definition.

The following patch changes the users and if this is OK I will go ahead and
delete the set_mb() definition. Comments and suggestions welcome.

Thanks!
Pranith

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 fs/select.c   |  6 +++---
 include/linux/sched.h | 14 +++---
 kernel/futex.c|  4 ++--
 kernel/sched/wait.c   |  4 ++--
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/fs/select.c b/fs/select.c
index 467bb1c..959a908 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -189,7 +189,7 @@ static int __pollwake(wait_queue_t *wait, unsigned mode, 
int sync, void *key)
 * doesn't imply write barrier and the users expect write
 * barrier semantics on wakeup functions.  The following
 * smp_wmb() is equivalent to smp_wmb() in try_to_wake_up()
-* and is paired with set_mb() in poll_schedule_timeout.
+* and is paired with smp_store_release() in poll_schedule_timeout.
 */
smp_wmb();
pwq-triggered = 1;
@@ -244,7 +244,7 @@ int poll_schedule_timeout(struct poll_wqueues *pwq, int 
state,
/*
 * Prepare for the next iteration.
 *
-* The following set_mb() serves two purposes.  First, it's
+* The following smp_store_release() serves two purposes.  First, it's
 * the counterpart rmb of the wmb in pollwake() such that data
 * written before wake up is always visible after wake up.
 * Second, the full barrier guarantees that triggered clearing
@@ -252,7 +252,7 @@ int poll_schedule_timeout(struct poll_wqueues *pwq, int 
state,
 * this problem doesn't exist for the first iteration as
 * add_wait_queue() has full barrier semantics.
 */
-   set_mb(pwq-triggered, 0);
+   smp_store_release(pwq-triggered, 0);
 
return rc;
 }
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 8db31ef..4621d0b 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -253,7 +253,7 @@ extern char ___assert_task_state[1 - 2*!!(
 #define set_task_state(tsk, state_value)   \
do {\
(tsk)-task_state_change = _THIS_IP_;   \
-   set_mb((tsk)-state, (state_value));\
+   smp_store_release((tsk)-state, (state_value)); \
} while (0)
 
 /*
@@ -272,10 +272,10 @@ extern char ___assert_task_state[1 - 2*!!(
current-task_state_change = _THIS_IP_; \
current-state = (state_value); \
} while (0)
-#define set_current_state(state_value) \
-   do {\
-   current-task_state_change = _THIS_IP_; \
-   set_mb(current-state, (state_value));  \
+#define set_current_state(state_value) \
+   do {\
+   current-task_state_change = _THIS_IP_; \
+   smp_store_release(current-state, (state_value));   \
} while (0)
 
 #else
@@ -283,7 +283,7 @@ extern char ___assert_task_state[1 - 2*!!(
 #define __set_task_state(tsk, state_value) \
do { (tsk)-state = (state_value); } while (0)
 #define set_task_state(tsk, state_value)   \
-   set_mb((tsk)-state, (state_value))
+   smp_store_release((tsk)-state, (state_value))
 
 /*
  * set_current_state() includes a barrier so that the write of current-state
@@ -299,7 +299,7 @@ extern char ___assert_task_state[1 - 2*!!(
 #define __set_current_state(state_value)   \
do { current-state = (state_value); } while (0)
 #define set_current_state(state_value) \
-   set_mb(current-state, (state_value))
+   smp_store_release(current-state, (state_value))
 
 #endif
 
diff --git a/kernel/futex.c b/kernel/futex.c
index 63678b5..0604355 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2055,8 +2055,8 @@ static void futex_wait_queue_me(struct futex_hash_bucket 
*hb, struct futex_q *q,
 {
/*
 * The task state is guaranteed to be set before another task can
-* wake it. set_current_state() is implemented using set_mb() and
-* queue_me() calls spin_unlock() upon completion, both serializing
+* wake it. set_current_state() is implemented using smp_store_release()
+* and queue_me() calls spin_unlock() upon completion, both serializing
 * access to the hash list and forcing another memory barrier.
 */
set_current_state(TASK_INTERRUPTIBLE);
diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
index 852143a..7d990c0 100644

Re: [PATCH tip/core/rcu 3/9] drivers/md: Use rcu_dereference() for accessing rcu pointer

2014-11-23 Thread Pranith Kumar
On Fri, Nov 21, 2014 at 9:58 AM, Kirill A. Shutemov
 wrote:
> On Fri, Nov 21, 2014 at 09:30:36AM -0500, Pranith Kumar wrote:
>> On 11/21/2014 08:31 AM, Kirill A. Shutemov wrote:
>> > On Tue, Oct 28, 2014 at 03:09:56PM -0700, Paul E. McKenney wrote:
>> >> From: Pranith Kumar 
>> >>
>> >> Got Paul's email wrong the first time.
>> >>
>> >> The map field in 'struct mapped_device' is an rcu pointer. Use 
>> >> rcu_dereference()
>> >> while accessing it.
>> >>
>> >> Signed-off-by: Pranith Kumar 
>> >> Signed-off-by: Paul E. McKenney 
>> >
>> > On current -next I see this:
>> >
>> > [6.388264] ===
>> > [6.389571] [ INFO: suspicious RCU usage. ]
>> > [6.390869] 3.18.0-rc5-next-20141121-08303-g44cae4530372 #2 Not tainted
>> > [6.392185] ---
>> > [6.393479] /home/kas/git/public/linux/drivers/md/dm.c:2853 suspicious 
>> > rcu_dereference_check() usage!
>> > [6.394801]
>> > other info that might help us debug this:
>> >
>>
>> Hi Kirill,
>>
>> We are dereferencing an RCU pointer with the suspend_lock held which is 
>> causing this warning.
>>
>> Can you please check if the following patch helps? Thanks!
>
> Nope. The same issue.
>
> IIUC, the problem is that you dereference pointer outside rcu_read_lock()
> section, not that suspend_lock is held.
>

I am not sure we should be taking rcu_read_lock() there as I am not
sure how long that critical section might last. Can someone who is
more familiar with the code take a look?

I will try to look for a solution too in the mean time.

Thanks!
-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 3/9] drivers/md: Use rcu_dereference() for accessing rcu pointer

2014-11-23 Thread Pranith Kumar
On Fri, Nov 21, 2014 at 9:58 AM, Kirill A. Shutemov
kir...@shutemov.name wrote:
 On Fri, Nov 21, 2014 at 09:30:36AM -0500, Pranith Kumar wrote:
 On 11/21/2014 08:31 AM, Kirill A. Shutemov wrote:
  On Tue, Oct 28, 2014 at 03:09:56PM -0700, Paul E. McKenney wrote:
  From: Pranith Kumar bobby.pr...@gmail.com
 
  Got Paul's email wrong the first time.
 
  The map field in 'struct mapped_device' is an rcu pointer. Use 
  rcu_dereference()
  while accessing it.
 
  Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
  Signed-off-by: Paul E. McKenney paul...@linux.vnet.ibm.com
 
  On current -next I see this:
 
  [6.388264] ===
  [6.389571] [ INFO: suspicious RCU usage. ]
  [6.390869] 3.18.0-rc5-next-20141121-08303-g44cae4530372 #2 Not tainted
  [6.392185] ---
  [6.393479] /home/kas/git/public/linux/drivers/md/dm.c:2853 suspicious 
  rcu_dereference_check() usage!
  [6.394801]
  other info that might help us debug this:
 

 Hi Kirill,

 We are dereferencing an RCU pointer with the suspend_lock held which is 
 causing this warning.

 Can you please check if the following patch helps? Thanks!

 Nope. The same issue.

 IIUC, the problem is that you dereference pointer outside rcu_read_lock()
 section, not that suspend_lock is held.


I am not sure we should be taking rcu_read_lock() there as I am not
sure how long that critical section might last. Can someone who is
more familiar with the code take a look?

I will try to look for a solution too in the mean time.

Thanks!
-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
On Fri, Nov 21, 2014 at 7:05 PM, Eric Dumazet  wrote:
>
> On Fri, 2014-11-21 at 16:57 -0500, Pranith Kumar wrote:
>
>> Hi Eric,
>>
>> Thanks for looking at this patch.
>>
>> I've been scratching my head since morning trying to find out what was
>> so obviously wrong with this patch. Alas, I don't see what you do.
>>
>> Could you point it out and show me how incompetent I am, please?
>>
>> Thanks!
>
> Well, even it the code is _not_ broken, I don't see any value with this
> patch.

Phew. Not being broken itself is a win :)

>
> If I use git blame on current code, line containing
> smp_read_barrier_depends() exactly points to the relevant commit [1]

And that is an opinion I will respect. I don't want to muck the git
history where it is significant.

This effort is to eventually replace the uses of
smp_read_barrier_depends() and to use either rcu or
lockless_dereference() as documented in memory-barriers.txt.

>
> After your change, it will point to some cleanup, which makes little
> sense to me, considering you did not change the smp_wmb() in
> xt_replace_table().

That does not need to change as it is fine as it is. It still pairs
with the smp_read_barrier_depends() in lockless_dereference().

>
> I, as a netfilter contributor would like to keep current code as is,
> because it is how I feel safe with it.
>
> We have a proliferation of interfaces, but this does not help to
> understand the issues and code maintenance.
>
> smp_read_barrier_depends() better documents the read barrier than
> lockless_dereference().

I think this is a matter of opinion. But in the current effort I've
seen cases where it is not clear what the barrier is actually
guaranteeing. I am glad that the current code is not one of those and
it has reasonable comments.

lockless_dereference() on the other hand makes the dependency explicit.

>
> The point of having a lock or not is irrelevant here.
>
> [1]
> http://git.kernel.org/cgit/linux/kernel/git/davem/net.git/commit/?id=b416c144f46af1a30ddfa4e4319a8f077381ad63
>
>
>
>


Thanks!
-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
On Fri, Nov 21, 2014 at 11:12 AM, Eric Dumazet  wrote:
> On Fri, 2014-11-21 at 10:06 -0500, Pranith Kumar wrote:
>> Recently lockless_dereference() was added which can be used in place of
>> hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
>>
>> Signed-off-by: Pranith Kumar 
>> ---
>>  net/ipv4/netfilter/arp_tables.c | 3 +--
>>  net/ipv4/netfilter/ip_tables.c  | 3 +--
>>  net/ipv6/netfilter/ip6_tables.c | 3 +--
>>  3 files changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/net/ipv4/netfilter/arp_tables.c 
>> b/net/ipv4/netfilter/arp_tables.c
>> index f95b6f9..fc7533d 100644
>> --- a/net/ipv4/netfilter/arp_tables.c
>> +++ b/net/ipv4/netfilter/arp_tables.c
>> @@ -270,12 +270,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,
>>
>>   local_bh_disable();
>>   addend = xt_write_recseq_begin();
>> - private = table->private;
>>   /*
>>* Ensure we load private-> members after we've fetched the base
>>* pointer.
>>*/
>> - smp_read_barrier_depends();
>> + private = lockless_dereference(table->private);
>>   table_base = private->entries[smp_processor_id()];
>>
>
>
> Please carefully read the code, before and after your change, then
> you'll see this change broke the code.
>
> Problem is that a bug like that can be really hard to diagnose and fix
> later, so really you have to be very careful doing these mechanical
> changes.
>
> IMO, current code+comment is better than with this
> lockless_dereference() which in this particular case obfuscates the
> code. more than anything.
>
> In this case we do have a lock (sort of), so lockless_dereference() is
> quite misleading.
>

Hi Eric,

Thanks for looking at this patch.

I've been scratching my head since morning trying to find out what was
so obviously wrong with this patch. Alas, I don't see what you do.

Could you point it out and show me how incompetent I am, please?

Thanks!
-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 7/9] seccomp: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar

On 11/21/2014 11:33 AM, Kees Cook wrote:
> On Fri, Nov 21, 2014 at 7:06 AM, Pranith Kumar  wrote:
>> Recently lockless_dereference() was added which can be used in place of
>> hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
>>
>> Signed-off-by: Pranith Kumar 
>> ---
>>  kernel/seccomp.c | 7 +++
>>  1 file changed, 3 insertions(+), 4 deletions(-)
> Thanks!
>
> Acked-by: Kees Cook 
>
> Do you need me to carry this patch in the seccomp tree, or will
> someone else be taking your entire series?
>
> -Kees

Please take this patch individually into your tree. There are discussions about 
the other patches and I will drop the accepted patches and iterate for the next 
version.

Thanks!

>> diff --git a/kernel/seccomp.c b/kernel/seccomp.c
>> index 4ef9687..3729b06 100644
>> --- a/kernel/seccomp.c
>> +++ b/kernel/seccomp.c
>> @@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter 
>> *filter, unsigned int flen)
>>   */
>>  static u32 seccomp_run_filters(struct seccomp_data *sd)
>>  {
>> -   struct seccomp_filter *f = ACCESS_ONCE(current->seccomp.filter);
>> struct seccomp_data sd_local;
>> u32 ret = SECCOMP_RET_ALLOW;
>> +   /* Make sure cross-thread synced filter points somewhere sane. */
>> +   struct seccomp_filter *f =
>> +   lockless_dereference(current->seccomp.filter);
>>
>> /* Ensure unexpected behavior doesn't result in failing open. */
>> if (unlikely(WARN_ON(f == NULL)))
>> return SECCOMP_RET_KILL;
>>
>> -   /* Make sure cross-thread synced filter points somewhere sane. */
>> -   smp_read_barrier_depends();
>> -
>> if (!sd) {
>> populate_seccomp_data(_local);
>> sd = _local;
>> --
>> 1.9.1
>>
>
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 0/9] Replace smp_read_barrier_depends() with lockless_derefrence()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). 

http://lkml.iu.edu/hypermail/linux/kernel/1410.3/04561.html

The following series tries to do this.

There are still some hard-coded locations which I was not sure how to replace
with. I will send in separate patches/questions regarding them.

Pranith Kumar (9):
  doc: memory-barriers.txt: Document use of lockless_dereference()
  drivers: dma: Replace smp_read_barrier_depends() with
lockless_dereference()
  dcache: Replace smp_read_barrier_depends() with lockless_dereference()
  hyperv: Replace smp_read_barrier_depends() with lockless_dereference()
  percpu: Replace smp_read_barrier_depends() with lockless_dereference()
  perf: Replace smp_read_barrier_depends() with lockless_dereference()
  seccomp: Replace smp_read_barrier_depends() with
lockless_dereference()
  task_work: Replace smp_read_barrier_depends() with
lockless_dereference()
  netfilter: Replace smp_read_barrier_depends() with
lockless_dereference()

 Documentation/memory-barriers.txt | 4 ++--
 drivers/dma/ioat/dma_v2.c | 3 +--
 drivers/dma/ioat/dma_v3.c | 3 +--
 fs/dcache.c   | 7 ++-
 include/linux/hyperv.h| 9 -
 include/linux/percpu-refcount.h   | 4 +---
 kernel/events/core.c  | 3 +--
 kernel/events/uprobes.c   | 8 
 kernel/seccomp.c  | 7 +++
 kernel/task_work.c| 3 +--
 net/ipv4/netfilter/arp_tables.c   | 3 +--
 net/ipv4/netfilter/ip_tables.c| 3 +--
 net/ipv6/netfilter/ip6_tables.c   | 3 +--
 13 files changed, 23 insertions(+), 37 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 6/9] perf: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 kernel/events/core.c| 3 +--
 kernel/events/uprobes.c | 8 
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index d59fdc0..9dd5920 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3400,14 +3400,13 @@ static void perf_remove_from_owner(struct perf_event 
*event)
struct task_struct *owner;
 
rcu_read_lock();
-   owner = ACCESS_ONCE(event->owner);
/*
 * Matches the smp_wmb() in perf_event_exit_task(). If we observe
 * !owner it means the list deletion is complete and we can indeed
 * free this event, otherwise we need to serialize on
 * owner->perf_event_mutex.
 */
-   smp_read_barrier_depends();
+   owner = lockless_dereference(event->owner);
if (owner) {
/*
 * Since delayed_put_task_struct() also drops the last
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 6158a64b..c070949 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1212,8 +1212,8 @@ static struct xol_area *get_xol_area(void)
if (!mm->uprobes_state.xol_area)
__create_xol_area(0);
 
-   area = mm->uprobes_state.xol_area;
-   smp_read_barrier_depends(); /* pairs with wmb in xol_add_vma() */
+   /* pairs with wmb in xol_add_vma() */
+   area = lockless_dereference(mm->uprobes_state.xol_area);
return area;
 }
 
@@ -1507,8 +1507,8 @@ static unsigned long get_trampoline_vaddr(void)
struct xol_area *area;
unsigned long trampoline_vaddr = -1;
 
-   area = current->mm->uprobes_state.xol_area;
-   smp_read_barrier_depends();
+   area = lockless_dereference(current->mm->uprobes_state.xol_area);
+
if (area)
trampoline_vaddr = area->vaddr;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 5/9] percpu: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 include/linux/percpu-refcount.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index 494ab05..3cf6759 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -128,10 +128,8 @@ static inline void percpu_ref_kill(struct percpu_ref *ref)
 static inline bool __ref_is_percpu(struct percpu_ref *ref,
  unsigned long __percpu 
**percpu_countp)
 {
-   unsigned long percpu_ptr = ACCESS_ONCE(ref->percpu_count_ptr);
-
/* paired with smp_store_release() in percpu_ref_reinit() */
-   smp_read_barrier_depends();
+   unsigned long percpu_ptr = lockless_dereference(ref->percpu_count_ptr);
 
if (unlikely(percpu_ptr & __PERCPU_REF_ATOMIC))
return false;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 4/9] hyperv: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 include/linux/hyperv.h | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 08cfaff..06418b1 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -127,13 +127,12 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info 
*rbi,
  u32 *read, u32 *write)
 {
u32 read_loc, write_loc, dsize;
-
-   smp_read_barrier_depends();
+   struct hv_ring_buffer_info *rbi_p = lockless_dereference(rbi);
 
/* Capture the read/write indices before they changed */
-   read_loc = rbi->ring_buffer->read_index;
-   write_loc = rbi->ring_buffer->write_index;
-   dsize = rbi->ring_datasize;
+   read_loc = rbi_p->ring_buffer->read_index;
+   write_loc = rbi_p->ring_buffer->write_index;
+   dsize = rbi_p->ring_datasize;
 
*write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
read_loc - write_loc;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 8/9] task_work: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 kernel/task_work.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/task_work.c b/kernel/task_work.c
index 8727032..b5599ce 100644
--- a/kernel/task_work.c
+++ b/kernel/task_work.c
@@ -62,8 +62,7 @@ task_work_cancel(struct task_struct *task, task_work_func_t 
func)
 * we raced with task_work_run(), *pprev == NULL/exited.
 */
raw_spin_lock_irqsave(>pi_lock, flags);
-   while ((work = ACCESS_ONCE(*pprev))) {
-   smp_read_barrier_depends();
+   while ((work = lockless_dereference(*pprev))) {
if (work->func != func)
pprev = >next;
else if (cmpxchg(pprev, work, work->next) == work)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 7/9] seccomp: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 kernel/seccomp.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 4ef9687..3729b06 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter 
*filter, unsigned int flen)
  */
 static u32 seccomp_run_filters(struct seccomp_data *sd)
 {
-   struct seccomp_filter *f = ACCESS_ONCE(current->seccomp.filter);
struct seccomp_data sd_local;
u32 ret = SECCOMP_RET_ALLOW;
+   /* Make sure cross-thread synced filter points somewhere sane. */
+   struct seccomp_filter *f =
+   lockless_dereference(current->seccomp.filter);
 
/* Ensure unexpected behavior doesn't result in failing open. */
if (unlikely(WARN_ON(f == NULL)))
return SECCOMP_RET_KILL;
 
-   /* Make sure cross-thread synced filter points somewhere sane. */
-   smp_read_barrier_depends();
-
if (!sd) {
populate_seccomp_data(_local);
sd = _local;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 net/ipv4/netfilter/arp_tables.c | 3 +--
 net/ipv4/netfilter/ip_tables.c  | 3 +--
 net/ipv6/netfilter/ip6_tables.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index f95b6f9..fc7533d 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -270,12 +270,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,
 
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table->private;
/*
 * Ensure we load private-> members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table->private);
table_base = private->entries[smp_processor_id()];
 
e = get_entry(table_base, private->hook_entry[hook]);
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 99e810f..e0fd044 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -325,13 +325,12 @@ ipt_do_table(struct sk_buff *skb,
IP_NF_ASSERT(table->valid_hooks & (1 << hook));
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table->private;
cpu= smp_processor_id();
/*
 * Ensure we load private-> members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table->private);
table_base = private->entries[cpu];
jumpstack  = (struct ipt_entry **)private->jumpstack[cpu];
stackptr   = per_cpu_ptr(private->stackptr, cpu);
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index e080fbb..0459d6a 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -348,12 +348,11 @@ ip6t_do_table(struct sk_buff *skb,
 
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table->private;
/*
 * Ensure we load private-> members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table->private);
cpu= smp_processor_id();
table_base = private->entries[cpu];
jumpstack  = (struct ip6t_entry **)private->jumpstack[cpu];
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 3/9] dcache: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 fs/dcache.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index a6c5d7e..27b8b5b 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -230,8 +230,7 @@ static inline int dentry_cmp(const struct dentry *dentry, 
const unsigned char *c
 * early because the data cannot match (there can
 * be no NUL in the ct/tcount data)
 */
-   cs = ACCESS_ONCE(dentry->d_name.name);
-   smp_read_barrier_depends();
+   cs = lockless_dereference(dentry->d_name.name);
return dentry_string_cmp(cs, ct, tcount);
 }
 
@@ -2714,10 +2713,8 @@ static int prepend(char **buffer, int *buflen, const 
char *str, int namelen)
 static int prepend_name(char **buffer, int *buflen, struct qstr *name)
 {
const char *dname = ACCESS_ONCE(name->name);
-   u32 dlen = ACCESS_ONCE(name->len);
char *p;
-
-   smp_read_barrier_depends();
+   u32 dlen = lockless_dereference(name->len);
 
*buflen -= dlen + 1;
if (*buflen < 0)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/9] drivers: dma: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 drivers/dma/ioat/dma_v2.c | 3 +--
 drivers/dma/ioat/dma_v3.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/ioat/dma_v2.c b/drivers/dma/ioat/dma_v2.c
index 695483e..0f94d72 100644
--- a/drivers/dma/ioat/dma_v2.c
+++ b/drivers/dma/ioat/dma_v2.c
@@ -142,10 +142,9 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
 
active = ioat2_ring_active(ioat);
for (i = 0; i < active && !seen_current; i++) {
-   smp_read_barrier_depends();
prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
desc = ioat2_get_ring_ent(ioat, idx + i);
-   tx = >txd;
+   tx = _dereference(desc)->txd;
dump_desc_dbg(ioat, desc);
if (tx->cookie) {
dma_descriptor_unmap(tx);
diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
index 895f869..cbd0537 100644
--- a/drivers/dma/ioat/dma_v3.c
+++ b/drivers/dma/ioat/dma_v3.c
@@ -389,7 +389,6 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
for (i = 0; i < active && !seen_current; i++) {
struct dma_async_tx_descriptor *tx;
 
-   smp_read_barrier_depends();
prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
desc = ioat2_get_ring_ent(ioat, idx + i);
dump_desc_dbg(ioat, desc);
@@ -398,7 +397,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
if (device->cap & IOAT_CAP_DWBES)
desc_get_errstat(ioat, desc);
 
-   tx = >txd;
+   tx = _dereference(desc)->txd;
if (tx->cookie) {
dma_cookie_complete(tx);
dma_descriptor_unmap(tx);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/9] doc: memory-barriers.txt: Document use of lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 Documentation/memory-barriers.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/memory-barriers.txt 
b/Documentation/memory-barriers.txt
index 7ee2ae6..d33aab3 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -203,8 +203,8 @@ There are some minimal guarantees that may be expected of a 
CPU:
  and always in that order.  On most systems, smp_read_barrier_depends()
  does nothing, but it is required for DEC Alpha.  The ACCESS_ONCE()
  is required to prevent compiler mischief.  Please note that you
- should normally use something like rcu_dereference() instead of
- open-coding smp_read_barrier_depends().
+ should normally use something like rcu_dereference() or
+ lockless_dereference() instead of open-coding smp_read_barrier_depends().
 
  (*) Overlapping loads and stores within a particular CPU will appear to be
  ordered within that CPU.  This means that for:
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 3/9] drivers/md: Use rcu_dereference() for accessing rcu pointer

2014-11-21 Thread Pranith Kumar
On 11/21/2014 08:31 AM, Kirill A. Shutemov wrote:
> On Tue, Oct 28, 2014 at 03:09:56PM -0700, Paul E. McKenney wrote:
>> From: Pranith Kumar 
>>
>> Got Paul's email wrong the first time.
>>
>> The map field in 'struct mapped_device' is an rcu pointer. Use 
>> rcu_dereference()
>> while accessing it.
>>
>> Signed-off-by: Pranith Kumar 
>> Signed-off-by: Paul E. McKenney 
> 
> On current -next I see this:
> 
> [6.388264] ===
> [6.389571] [ INFO: suspicious RCU usage. ]
> [6.390869] 3.18.0-rc5-next-20141121-08303-g44cae4530372 #2 Not tainted
> [6.392185] ---
> [6.393479] /home/kas/git/public/linux/drivers/md/dm.c:2853 suspicious 
> rcu_dereference_check() usage!
> [6.394801] 
> other info that might help us debug this:
> 

Hi Kirill,

We are dereferencing an RCU pointer with the suspend_lock held which is causing 
this warning.

Can you please check if the following patch helps? Thanks!

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index a0ece87..e584e66 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2830,7 +2830,7 @@ static int __dm_suspend(struct mapped_device *md, struct 
dm_table *map,
  */
 int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
 {
-   struct dm_table *map = NULL;
+   struct dm_table *map = rcu_dereference(md->map);
int r = 0;
 
 retry:
@@ -2850,8 +2850,6 @@ retry:
goto retry;
}
 
-   map = rcu_dereference(md->map);
-
r = __dm_suspend(md, map, suspend_flags, TASK_INTERRUPTIBLE);
if (r)
goto out_unlock;



> [6.398714] 
> rcu_scheduler_active = 1, debug_locks = 0
> [6.401247] 1 lock held by cryptsetup/159:
> [6.402522]  #0:  (>suspend_lock/1){+.+...}, at: [] 
> dm_suspend+0x3d/0x140
> [6.403848] 
> stack backtrace:
> [6.406448] CPU: 3 PID: 159 Comm: cryptsetup Not tainted 
> 3.18.0-rc5-next-20141121-08303-g44cae4530372 #2
> [6.407726] Hardware name: LENOVO 3460CC6/3460CC6, BIOS G6ET93WW (2.53 ) 
> 02/04/2013
> [6.408982]  0001 8800d3ac7c38 81b00bbd 
> 0011
> [6.410249]  8800d301a560 8800d3ac7c68 81153be7 
> 8800d3928800
> [6.411548]  8800d3928970 8800d3928aa0 0001 
> 8800d3ac7ca8
> [6.412780] Call Trace:
> [6.413980]  [] dump_stack+0x4c/0x6e
> [6.415178]  [] lockdep_rcu_suspicious+0xe7/0x120
> [6.416364]  [] dm_suspend+0x13d/0x140
> [6.417535]  [] ? table_load+0x340/0x340
> [6.418749]  [] dev_suspend+0x1ab/0x260
> [6.419901]  [] ? table_load+0x340/0x340
> [6.421038]  [] ctl_ioctl+0x251/0x540
> [6.422164]  [] ? mntput_no_expire+0x5/0x360
> [6.423280]  [] dm_ctl_ioctl+0x13/0x20
> [6.424389]  [] do_vfs_ioctl+0x308/0x540
> [6.425515]  [] ? rcu_read_lock_held+0x6d/0x70
> [6.426601]  [] ? __fget_light+0xbe/0xd0
> [6.427686]  [] SyS_ioctl+0x81/0xa0
> [6.428760]  [] system_call_fastpath+0x16/0x1b
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 3/9] drivers/md: Use rcu_dereference() for accessing rcu pointer

2014-11-21 Thread Pranith Kumar
On 11/21/2014 08:31 AM, Kirill A. Shutemov wrote:
 On Tue, Oct 28, 2014 at 03:09:56PM -0700, Paul E. McKenney wrote:
 From: Pranith Kumar bobby.pr...@gmail.com

 Got Paul's email wrong the first time.

 The map field in 'struct mapped_device' is an rcu pointer. Use 
 rcu_dereference()
 while accessing it.

 Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
 Signed-off-by: Paul E. McKenney paul...@linux.vnet.ibm.com
 
 On current -next I see this:
 
 [6.388264] ===
 [6.389571] [ INFO: suspicious RCU usage. ]
 [6.390869] 3.18.0-rc5-next-20141121-08303-g44cae4530372 #2 Not tainted
 [6.392185] ---
 [6.393479] /home/kas/git/public/linux/drivers/md/dm.c:2853 suspicious 
 rcu_dereference_check() usage!
 [6.394801] 
 other info that might help us debug this:
 

Hi Kirill,

We are dereferencing an RCU pointer with the suspend_lock held which is causing 
this warning.

Can you please check if the following patch helps? Thanks!

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index a0ece87..e584e66 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2830,7 +2830,7 @@ static int __dm_suspend(struct mapped_device *md, struct 
dm_table *map,
  */
 int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
 {
-   struct dm_table *map = NULL;
+   struct dm_table *map = rcu_dereference(md-map);
int r = 0;
 
 retry:
@@ -2850,8 +2850,6 @@ retry:
goto retry;
}
 
-   map = rcu_dereference(md-map);
-
r = __dm_suspend(md, map, suspend_flags, TASK_INTERRUPTIBLE);
if (r)
goto out_unlock;



 [6.398714] 
 rcu_scheduler_active = 1, debug_locks = 0
 [6.401247] 1 lock held by cryptsetup/159:
 [6.402522]  #0:  (md-suspend_lock/1){+.+...}, at: [8179dd1d] 
 dm_suspend+0x3d/0x140
 [6.403848] 
 stack backtrace:
 [6.406448] CPU: 3 PID: 159 Comm: cryptsetup Not tainted 
 3.18.0-rc5-next-20141121-08303-g44cae4530372 #2
 [6.407726] Hardware name: LENOVO 3460CC6/3460CC6, BIOS G6ET93WW (2.53 ) 
 02/04/2013
 [6.408982]  0001 8800d3ac7c38 81b00bbd 
 0011
 [6.410249]  8800d301a560 8800d3ac7c68 81153be7 
 8800d3928800
 [6.411548]  8800d3928970 8800d3928aa0 0001 
 8800d3ac7ca8
 [6.412780] Call Trace:
 [6.413980]  [81b00bbd] dump_stack+0x4c/0x6e
 [6.415178]  [81153be7] lockdep_rcu_suspicious+0xe7/0x120
 [6.416364]  [8179de1d] dm_suspend+0x13d/0x140
 [6.417535]  [817a2d80] ? table_load+0x340/0x340
 [6.418749]  [817a2f2b] dev_suspend+0x1ab/0x260
 [6.419901]  [817a2d80] ? table_load+0x340/0x340
 [6.421038]  [817a3781] ctl_ioctl+0x251/0x540
 [6.422164]  [812b6415] ? mntput_no_expire+0x5/0x360
 [6.423280]  [817a3a83] dm_ctl_ioctl+0x13/0x20
 [6.424389]  [812a6f98] do_vfs_ioctl+0x308/0x540
 [6.425515]  [81175d2d] ? rcu_read_lock_held+0x6d/0x70
 [6.426601]  [812b324e] ? __fget_light+0xbe/0xd0
 [6.427686]  [812a7251] SyS_ioctl+0x81/0xa0
 [6.428760]  [81b0d6ad] system_call_fastpath+0x16/0x1b
 

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/9] doc: memory-barriers.txt: Document use of lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 Documentation/memory-barriers.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/memory-barriers.txt 
b/Documentation/memory-barriers.txt
index 7ee2ae6..d33aab3 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -203,8 +203,8 @@ There are some minimal guarantees that may be expected of a 
CPU:
  and always in that order.  On most systems, smp_read_barrier_depends()
  does nothing, but it is required for DEC Alpha.  The ACCESS_ONCE()
  is required to prevent compiler mischief.  Please note that you
- should normally use something like rcu_dereference() instead of
- open-coding smp_read_barrier_depends().
+ should normally use something like rcu_dereference() or
+ lockless_dereference() instead of open-coding smp_read_barrier_depends().
 
  (*) Overlapping loads and stores within a particular CPU will appear to be
  ordered within that CPU.  This means that for:
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/9] drivers: dma: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 drivers/dma/ioat/dma_v2.c | 3 +--
 drivers/dma/ioat/dma_v3.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/ioat/dma_v2.c b/drivers/dma/ioat/dma_v2.c
index 695483e..0f94d72 100644
--- a/drivers/dma/ioat/dma_v2.c
+++ b/drivers/dma/ioat/dma_v2.c
@@ -142,10 +142,9 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
 
active = ioat2_ring_active(ioat);
for (i = 0; i  active  !seen_current; i++) {
-   smp_read_barrier_depends();
prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
desc = ioat2_get_ring_ent(ioat, idx + i);
-   tx = desc-txd;
+   tx = lockless_dereference(desc)-txd;
dump_desc_dbg(ioat, desc);
if (tx-cookie) {
dma_descriptor_unmap(tx);
diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
index 895f869..cbd0537 100644
--- a/drivers/dma/ioat/dma_v3.c
+++ b/drivers/dma/ioat/dma_v3.c
@@ -389,7 +389,6 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
for (i = 0; i  active  !seen_current; i++) {
struct dma_async_tx_descriptor *tx;
 
-   smp_read_barrier_depends();
prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
desc = ioat2_get_ring_ent(ioat, idx + i);
dump_desc_dbg(ioat, desc);
@@ -398,7 +397,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
if (device-cap  IOAT_CAP_DWBES)
desc_get_errstat(ioat, desc);
 
-   tx = desc-txd;
+   tx = lockless_dereference(desc)-txd;
if (tx-cookie) {
dma_cookie_complete(tx);
dma_descriptor_unmap(tx);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 net/ipv4/netfilter/arp_tables.c | 3 +--
 net/ipv4/netfilter/ip_tables.c  | 3 +--
 net/ipv6/netfilter/ip6_tables.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index f95b6f9..fc7533d 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -270,12 +270,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,
 
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table-private;
/*
 * Ensure we load private- members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table-private);
table_base = private-entries[smp_processor_id()];
 
e = get_entry(table_base, private-hook_entry[hook]);
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 99e810f..e0fd044 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -325,13 +325,12 @@ ipt_do_table(struct sk_buff *skb,
IP_NF_ASSERT(table-valid_hooks  (1  hook));
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table-private;
cpu= smp_processor_id();
/*
 * Ensure we load private- members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table-private);
table_base = private-entries[cpu];
jumpstack  = (struct ipt_entry **)private-jumpstack[cpu];
stackptr   = per_cpu_ptr(private-stackptr, cpu);
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index e080fbb..0459d6a 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -348,12 +348,11 @@ ip6t_do_table(struct sk_buff *skb,
 
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table-private;
/*
 * Ensure we load private- members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table-private);
cpu= smp_processor_id();
table_base = private-entries[cpu];
jumpstack  = (struct ip6t_entry **)private-jumpstack[cpu];
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 3/9] dcache: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 fs/dcache.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index a6c5d7e..27b8b5b 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -230,8 +230,7 @@ static inline int dentry_cmp(const struct dentry *dentry, 
const unsigned char *c
 * early because the data cannot match (there can
 * be no NUL in the ct/tcount data)
 */
-   cs = ACCESS_ONCE(dentry-d_name.name);
-   smp_read_barrier_depends();
+   cs = lockless_dereference(dentry-d_name.name);
return dentry_string_cmp(cs, ct, tcount);
 }
 
@@ -2714,10 +2713,8 @@ static int prepend(char **buffer, int *buflen, const 
char *str, int namelen)
 static int prepend_name(char **buffer, int *buflen, struct qstr *name)
 {
const char *dname = ACCESS_ONCE(name-name);
-   u32 dlen = ACCESS_ONCE(name-len);
char *p;
-
-   smp_read_barrier_depends();
+   u32 dlen = lockless_dereference(name-len);
 
*buflen -= dlen + 1;
if (*buflen  0)
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 8/9] task_work: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 kernel/task_work.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/task_work.c b/kernel/task_work.c
index 8727032..b5599ce 100644
--- a/kernel/task_work.c
+++ b/kernel/task_work.c
@@ -62,8 +62,7 @@ task_work_cancel(struct task_struct *task, task_work_func_t 
func)
 * we raced with task_work_run(), *pprev == NULL/exited.
 */
raw_spin_lock_irqsave(task-pi_lock, flags);
-   while ((work = ACCESS_ONCE(*pprev))) {
-   smp_read_barrier_depends();
+   while ((work = lockless_dereference(*pprev))) {
if (work-func != func)
pprev = work-next;
else if (cmpxchg(pprev, work, work-next) == work)
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 4/9] hyperv: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 include/linux/hyperv.h | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 08cfaff..06418b1 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -127,13 +127,12 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info 
*rbi,
  u32 *read, u32 *write)
 {
u32 read_loc, write_loc, dsize;
-
-   smp_read_barrier_depends();
+   struct hv_ring_buffer_info *rbi_p = lockless_dereference(rbi);
 
/* Capture the read/write indices before they changed */
-   read_loc = rbi-ring_buffer-read_index;
-   write_loc = rbi-ring_buffer-write_index;
-   dsize = rbi-ring_datasize;
+   read_loc = rbi_p-ring_buffer-read_index;
+   write_loc = rbi_p-ring_buffer-write_index;
+   dsize = rbi_p-ring_datasize;
 
*write = write_loc = read_loc ? dsize - (write_loc - read_loc) :
read_loc - write_loc;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 7/9] seccomp: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 kernel/seccomp.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 4ef9687..3729b06 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter 
*filter, unsigned int flen)
  */
 static u32 seccomp_run_filters(struct seccomp_data *sd)
 {
-   struct seccomp_filter *f = ACCESS_ONCE(current-seccomp.filter);
struct seccomp_data sd_local;
u32 ret = SECCOMP_RET_ALLOW;
+   /* Make sure cross-thread synced filter points somewhere sane. */
+   struct seccomp_filter *f =
+   lockless_dereference(current-seccomp.filter);
 
/* Ensure unexpected behavior doesn't result in failing open. */
if (unlikely(WARN_ON(f == NULL)))
return SECCOMP_RET_KILL;
 
-   /* Make sure cross-thread synced filter points somewhere sane. */
-   smp_read_barrier_depends();
-
if (!sd) {
populate_seccomp_data(sd_local);
sd = sd_local;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 6/9] perf: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 kernel/events/core.c| 3 +--
 kernel/events/uprobes.c | 8 
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index d59fdc0..9dd5920 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3400,14 +3400,13 @@ static void perf_remove_from_owner(struct perf_event 
*event)
struct task_struct *owner;
 
rcu_read_lock();
-   owner = ACCESS_ONCE(event-owner);
/*
 * Matches the smp_wmb() in perf_event_exit_task(). If we observe
 * !owner it means the list deletion is complete and we can indeed
 * free this event, otherwise we need to serialize on
 * owner-perf_event_mutex.
 */
-   smp_read_barrier_depends();
+   owner = lockless_dereference(event-owner);
if (owner) {
/*
 * Since delayed_put_task_struct() also drops the last
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 6158a64b..c070949 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1212,8 +1212,8 @@ static struct xol_area *get_xol_area(void)
if (!mm-uprobes_state.xol_area)
__create_xol_area(0);
 
-   area = mm-uprobes_state.xol_area;
-   smp_read_barrier_depends(); /* pairs with wmb in xol_add_vma() */
+   /* pairs with wmb in xol_add_vma() */
+   area = lockless_dereference(mm-uprobes_state.xol_area);
return area;
 }
 
@@ -1507,8 +1507,8 @@ static unsigned long get_trampoline_vaddr(void)
struct xol_area *area;
unsigned long trampoline_vaddr = -1;
 
-   area = current-mm-uprobes_state.xol_area;
-   smp_read_barrier_depends();
+   area = lockless_dereference(current-mm-uprobes_state.xol_area);
+
if (area)
trampoline_vaddr = area-vaddr;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 5/9] percpu: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 include/linux/percpu-refcount.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index 494ab05..3cf6759 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -128,10 +128,8 @@ static inline void percpu_ref_kill(struct percpu_ref *ref)
 static inline bool __ref_is_percpu(struct percpu_ref *ref,
  unsigned long __percpu 
**percpu_countp)
 {
-   unsigned long percpu_ptr = ACCESS_ONCE(ref-percpu_count_ptr);
-
/* paired with smp_store_release() in percpu_ref_reinit() */
-   smp_read_barrier_depends();
+   unsigned long percpu_ptr = lockless_dereference(ref-percpu_count_ptr);
 
if (unlikely(percpu_ptr  __PERCPU_REF_ATOMIC))
return false;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 0/9] Replace smp_read_barrier_depends() with lockless_derefrence()

2014-11-21 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). 

http://lkml.iu.edu/hypermail/linux/kernel/1410.3/04561.html

The following series tries to do this.

There are still some hard-coded locations which I was not sure how to replace
with. I will send in separate patches/questions regarding them.

Pranith Kumar (9):
  doc: memory-barriers.txt: Document use of lockless_dereference()
  drivers: dma: Replace smp_read_barrier_depends() with
lockless_dereference()
  dcache: Replace smp_read_barrier_depends() with lockless_dereference()
  hyperv: Replace smp_read_barrier_depends() with lockless_dereference()
  percpu: Replace smp_read_barrier_depends() with lockless_dereference()
  perf: Replace smp_read_barrier_depends() with lockless_dereference()
  seccomp: Replace smp_read_barrier_depends() with
lockless_dereference()
  task_work: Replace smp_read_barrier_depends() with
lockless_dereference()
  netfilter: Replace smp_read_barrier_depends() with
lockless_dereference()

 Documentation/memory-barriers.txt | 4 ++--
 drivers/dma/ioat/dma_v2.c | 3 +--
 drivers/dma/ioat/dma_v3.c | 3 +--
 fs/dcache.c   | 7 ++-
 include/linux/hyperv.h| 9 -
 include/linux/percpu-refcount.h   | 4 +---
 kernel/events/core.c  | 3 +--
 kernel/events/uprobes.c   | 8 
 kernel/seccomp.c  | 7 +++
 kernel/task_work.c| 3 +--
 net/ipv4/netfilter/arp_tables.c   | 3 +--
 net/ipv4/netfilter/ip_tables.c| 3 +--
 net/ipv6/netfilter/ip6_tables.c   | 3 +--
 13 files changed, 23 insertions(+), 37 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 7/9] seccomp: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar

On 11/21/2014 11:33 AM, Kees Cook wrote:
 On Fri, Nov 21, 2014 at 7:06 AM, Pranith Kumar bobby.pr...@gmail.com wrote:
 Recently lockless_dereference() was added which can be used in place of
 hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

 Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
 ---
  kernel/seccomp.c | 7 +++
  1 file changed, 3 insertions(+), 4 deletions(-)
 Thanks!

 Acked-by: Kees Cook keesc...@chromium.org

 Do you need me to carry this patch in the seccomp tree, or will
 someone else be taking your entire series?

 -Kees

Please take this patch individually into your tree. There are discussions about 
the other patches and I will drop the accepted patches and iterate for the next 
version.

Thanks!

 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
 index 4ef9687..3729b06 100644
 --- a/kernel/seccomp.c
 +++ b/kernel/seccomp.c
 @@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter 
 *filter, unsigned int flen)
   */
  static u32 seccomp_run_filters(struct seccomp_data *sd)
  {
 -   struct seccomp_filter *f = ACCESS_ONCE(current-seccomp.filter);
 struct seccomp_data sd_local;
 u32 ret = SECCOMP_RET_ALLOW;
 +   /* Make sure cross-thread synced filter points somewhere sane. */
 +   struct seccomp_filter *f =
 +   lockless_dereference(current-seccomp.filter);

 /* Ensure unexpected behavior doesn't result in failing open. */
 if (unlikely(WARN_ON(f == NULL)))
 return SECCOMP_RET_KILL;

 -   /* Make sure cross-thread synced filter points somewhere sane. */
 -   smp_read_barrier_depends();
 -
 if (!sd) {
 populate_seccomp_data(sd_local);
 sd = sd_local;
 --
 1.9.1




--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
On Fri, Nov 21, 2014 at 11:12 AM, Eric Dumazet eric.duma...@gmail.com wrote:
 On Fri, 2014-11-21 at 10:06 -0500, Pranith Kumar wrote:
 Recently lockless_dereference() was added which can be used in place of
 hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

 Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
 ---
  net/ipv4/netfilter/arp_tables.c | 3 +--
  net/ipv4/netfilter/ip_tables.c  | 3 +--
  net/ipv6/netfilter/ip6_tables.c | 3 +--
  3 files changed, 3 insertions(+), 6 deletions(-)

 diff --git a/net/ipv4/netfilter/arp_tables.c 
 b/net/ipv4/netfilter/arp_tables.c
 index f95b6f9..fc7533d 100644
 --- a/net/ipv4/netfilter/arp_tables.c
 +++ b/net/ipv4/netfilter/arp_tables.c
 @@ -270,12 +270,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,

   local_bh_disable();
   addend = xt_write_recseq_begin();
 - private = table-private;
   /*
* Ensure we load private- members after we've fetched the base
* pointer.
*/
 - smp_read_barrier_depends();
 + private = lockless_dereference(table-private);
   table_base = private-entries[smp_processor_id()];



 Please carefully read the code, before and after your change, then
 you'll see this change broke the code.

 Problem is that a bug like that can be really hard to diagnose and fix
 later, so really you have to be very careful doing these mechanical
 changes.

 IMO, current code+comment is better than with this
 lockless_dereference() which in this particular case obfuscates the
 code. more than anything.

 In this case we do have a lock (sort of), so lockless_dereference() is
 quite misleading.


Hi Eric,

Thanks for looking at this patch.

I've been scratching my head since morning trying to find out what was
so obviously wrong with this patch. Alas, I don't see what you do.

Could you point it out and show me how incompetent I am, please?

Thanks!
-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-21 Thread Pranith Kumar
On Fri, Nov 21, 2014 at 7:05 PM, Eric Dumazet eric.duma...@gmail.com wrote:

 On Fri, 2014-11-21 at 16:57 -0500, Pranith Kumar wrote:

 Hi Eric,

 Thanks for looking at this patch.

 I've been scratching my head since morning trying to find out what was
 so obviously wrong with this patch. Alas, I don't see what you do.

 Could you point it out and show me how incompetent I am, please?

 Thanks!

 Well, even it the code is _not_ broken, I don't see any value with this
 patch.

Phew. Not being broken itself is a win :)


 If I use git blame on current code, line containing
 smp_read_barrier_depends() exactly points to the relevant commit [1]

And that is an opinion I will respect. I don't want to muck the git
history where it is significant.

This effort is to eventually replace the uses of
smp_read_barrier_depends() and to use either rcu or
lockless_dereference() as documented in memory-barriers.txt.


 After your change, it will point to some cleanup, which makes little
 sense to me, considering you did not change the smp_wmb() in
 xt_replace_table().

That does not need to change as it is fine as it is. It still pairs
with the smp_read_barrier_depends() in lockless_dereference().


 I, as a netfilter contributor would like to keep current code as is,
 because it is how I feel safe with it.

 We have a proliferation of interfaces, but this does not help to
 understand the issues and code maintenance.

 smp_read_barrier_depends() better documents the read barrier than
 lockless_dereference().

I think this is a matter of opinion. But in the current effort I've
seen cases where it is not clear what the barrier is actually
guaranteeing. I am glad that the current code is not one of those and
it has reasonable comments.

lockless_dereference() on the other hand makes the dependency explicit.


 The point of having a lock or not is irrelevant here.

 [1]
 http://git.kernel.org/cgit/linux/kernel/git/davem/net.git/commit/?id=b416c144f46af1a30ddfa4e4319a8f077381ad63






Thanks!
-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 08/16] rcupdate: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-18 Thread Pranith Kumar

On 11/18/2014 12:16 PM, Paul E. McKenney wrote:
> On Thu, Nov 13, 2014 at 02:24:14PM -0500, Pranith Kumar wrote:
>> Recently lockless_dereference() was added which can be used in place of
>> hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
>>
>> Signed-off-by: Pranith Kumar 
> Queued for 3.20, thank you!  I was wondering about your removing the
> "_" from "_p1", but see that this allowed you to avoid the
> checkpatch.pl warning.  ;-)
>
Yes, that was the easiest way I could think of to avoid the warning with adding 
more lines.

I will send the rest of the patches updated with comments.

Thanks,
Pranith

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 08/16] rcupdate: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-18 Thread Pranith Kumar

On 11/18/2014 12:16 PM, Paul E. McKenney wrote:
 On Thu, Nov 13, 2014 at 02:24:14PM -0500, Pranith Kumar wrote:
 Recently lockless_dereference() was added which can be used in place of
 hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

 Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
 Queued for 3.20, thank you!  I was wondering about your removing the
 _ from _p1, but see that this allowed you to avoid the
 checkpatch.pl warning.  ;-)

Yes, that was the easiest way I could think of to avoid the warning with adding 
more lines.

I will send the rest of the patches updated with comments.

Thanks,
Pranith

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH] cpuidle: Use a lighter barrier in snooze_loop()

2014-11-15 Thread Pranith Kumar
Using smp_mb() here so that the bit clear is not reordered is an overkill.

It is more appropriate to use smp_mb__after_atomic() which ensures that the
bit clear is not reordered.

Signed-off-by: Pranith Kumar 
---
 drivers/cpuidle/cpuidle-powernv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/cpuidle/cpuidle-powernv.c 
b/drivers/cpuidle/cpuidle-powernv.c
index 7d3a349..b0bfcbe 100644
--- a/drivers/cpuidle/cpuidle-powernv.c
+++ b/drivers/cpuidle/cpuidle-powernv.c
@@ -48,7 +48,8 @@ static int snooze_loop(struct cpuidle_device *dev,
HMT_medium();
ppc64_runlatch_on();
clear_thread_flag(TIF_POLLING_NRFLAG);
-   smp_mb();
+   /* ensure bit clear is not reordered */
+   smp_mb__after_atomic();
return index;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH] cpuidle: Use a lighter barrier in snooze_loop()

2014-11-15 Thread Pranith Kumar
Using smp_mb() here so that the bit clear is not reordered is an overkill.

It is more appropriate to use smp_mb__after_atomic() which ensures that the
bit clear is not reordered.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 drivers/cpuidle/cpuidle-powernv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/cpuidle/cpuidle-powernv.c 
b/drivers/cpuidle/cpuidle-powernv.c
index 7d3a349..b0bfcbe 100644
--- a/drivers/cpuidle/cpuidle-powernv.c
+++ b/drivers/cpuidle/cpuidle-powernv.c
@@ -48,7 +48,8 @@ static int snooze_loop(struct cpuidle_device *dev,
HMT_medium();
ppc64_runlatch_on();
clear_thread_flag(TIF_POLLING_NRFLAG);
-   smp_mb();
+   /* ensure bit clear is not reordered */
+   smp_mb__after_atomic();
return index;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH] printk: Use ACCESS_ONCE() instead of a volatile type

2014-11-14 Thread Pranith Kumar

On 11/14/2014 11:39 AM, Alex Elder wrote:
> On 11/13/2014 11:24 PM, Steven Rostedt wrote:
>> On Thu, 13 Nov 2014 23:57:22 -0500
>> Steven Rostedt  wrote:
>>
>>> That assignment is what it is initialized to at boot up. I can't see
>>> any optimization that would cause gcc to modify that. Especially since
>>> we are hiding its accesses within the ACCESS_ONCE(). That alone should
>>> confuse gcc enough to leave it a hell alone J.
>>
>> I'm actually wondering if the ACCESS_ONCE or volatile is even needed.
>>
>> static variables are used to maintain state, and that goes for
>> recursive functions. gcc should not touch it.
> I think you're right.
>
> Here's some extra analysis.  I may be wrong on a detail or
> two but see if it makes sense.
>
> The logbuf_cpu variable has static storage duration, so will
> be initialized before program startup.
>
> This function (vprintk_emit()) can be called on multiple
> CPUs concurrently.  So we can assume that there is more than
> one thread executing in window from the start of the function
> until the raw_spin_lock(_lock) call is made.
>
> The only writes to logbuf_lock are made under protection
> of the spinlock.  It is initially UINT_MAX; it is changed
> to the current processor id right after taking the lock;
> and it is reverted to UINT_MAX right before releasing the
> lock.  So logbuf_cpu will either contain UINT_MAX, or will
> hold the processor id of the CPU that is holding logbuf_lock.
> The spinlock barrier ensures that the only value a CPU will
> see is UINT_MAX, unless it is the CPU that holds the spinlock.
>
> There is only one read of logbuf_cpu:
> if (unlikely(logbuf_cpu == this_cpu)) {
> This is called only while local interrupts are disabled, so
> if this condition holds it cannot be due to an interrupt--it
> must be due to simple recursion into printk() while inside
> the spinlock-protected critical section.
>
> We *can* recurse into printk() via a function call within
> the protected section--through vscnprintf(), which can
> descend into printk() via WARN() calls in format_decode().
> (There may be others after that point, but up to there it
> looks like no other function call in that section can fail.)
> So it *is* possible to hit this recursion (I wanted to
> verify that...).
>
> OK.  So back to the original issue...  How do we ensure
> the value of logbuf_cpu is in fact the last set value,
> and is not affected by any compiler reordering?
>
> If its value is anything other than UINT_MAX, it will
> be the current CPU's processor id, which will have been
> set by the current CPU.  There are no issues related to
> caches or barriers.
>
> Since vprintk_emit() is a public entry point there's no
> magic inter-function optimization or inlining that could
> allow the value of the static logbuf_cpu to be preserved
> between calls.  So the first read of logbuf_cpu in a given
> function call will have to fetch its current value from memory
> (regardless of whether there's a "volatile" qualifier).
>
> And therefore the one read of that value will involve
> fetching the "real" value from memory, and it will
> either be UINT_MAX or the CPU's own processor id.
>
> So there should be no need to declare the variable
> volatile, nor to access it with ACCESS_ONCE().
>
> QED.  (Well, please correct me where I'm wrong...)
>

Thanks Alex, for the in-depth analysis. Please drop my patch in favour of 
removing volatile and without ACCESS_ONCE(). Will you send in such a patch?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 09/16] percpu: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-14 Thread Pranith Kumar
On Fri, Nov 14, 2014 at 8:14 AM, Tejun Heo  wrote:
>
> How should this be routed?  There's a pending change on the same
> region of code and if this patch is routed outside percpu tree it'd
> cause a conflict and I can't route this as lockless_dereference()
> isn't in the mainline yet.  Maybe expose a git branch which contaisn
> lockless_dereference() so that percpu can pull it in?
>

I do not have access to git hosting (except github, but I think that
is not acceptable). May be once the patches are final, I can send in a
version which you can put in a branch on kernel.org?

-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 09/16] percpu: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-14 Thread Pranith Kumar
On Fri, Nov 14, 2014 at 8:14 AM, Tejun Heo t...@kernel.org wrote:

 How should this be routed?  There's a pending change on the same
 region of code and if this patch is routed outside percpu tree it'd
 cause a conflict and I can't route this as lockless_dereference()
 isn't in the mainline yet.  Maybe expose a git branch which contaisn
 lockless_dereference() so that percpu can pull it in?


I do not have access to git hosting (except github, but I think that
is not acceptable). May be once the patches are final, I can send in a
version which you can put in a branch on kernel.org?

-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH] printk: Use ACCESS_ONCE() instead of a volatile type

2014-11-14 Thread Pranith Kumar

On 11/14/2014 11:39 AM, Alex Elder wrote:
 On 11/13/2014 11:24 PM, Steven Rostedt wrote:
 On Thu, 13 Nov 2014 23:57:22 -0500
 Steven Rostedt rost...@goodmis.org wrote:

 That assignment is what it is initialized to at boot up. I can't see
 any optimization that would cause gcc to modify that. Especially since
 we are hiding its accesses within the ACCESS_ONCE(). That alone should
 confuse gcc enough to leave it a hell alone J.

 I'm actually wondering if the ACCESS_ONCE or volatile is even needed.

 static variables are used to maintain state, and that goes for
 recursive functions. gcc should not touch it.
 I think you're right.

 Here's some extra analysis.  I may be wrong on a detail or
 two but see if it makes sense.

 The logbuf_cpu variable has static storage duration, so will
 be initialized before program startup.

 This function (vprintk_emit()) can be called on multiple
 CPUs concurrently.  So we can assume that there is more than
 one thread executing in window from the start of the function
 until the raw_spin_lock(logbuf_lock) call is made.

 The only writes to logbuf_lock are made under protection
 of the spinlock.  It is initially UINT_MAX; it is changed
 to the current processor id right after taking the lock;
 and it is reverted to UINT_MAX right before releasing the
 lock.  So logbuf_cpu will either contain UINT_MAX, or will
 hold the processor id of the CPU that is holding logbuf_lock.
 The spinlock barrier ensures that the only value a CPU will
 see is UINT_MAX, unless it is the CPU that holds the spinlock.

 There is only one read of logbuf_cpu:
 if (unlikely(logbuf_cpu == this_cpu)) {
 This is called only while local interrupts are disabled, so
 if this condition holds it cannot be due to an interrupt--it
 must be due to simple recursion into printk() while inside
 the spinlock-protected critical section.

 We *can* recurse into printk() via a function call within
 the protected section--through vscnprintf(), which can
 descend into printk() via WARN() calls in format_decode().
 (There may be others after that point, but up to there it
 looks like no other function call in that section can fail.)
 So it *is* possible to hit this recursion (I wanted to
 verify that...).

 OK.  So back to the original issue...  How do we ensure
 the value of logbuf_cpu is in fact the last set value,
 and is not affected by any compiler reordering?

 If its value is anything other than UINT_MAX, it will
 be the current CPU's processor id, which will have been
 set by the current CPU.  There are no issues related to
 caches or barriers.

 Since vprintk_emit() is a public entry point there's no
 magic inter-function optimization or inlining that could
 allow the value of the static logbuf_cpu to be preserved
 between calls.  So the first read of logbuf_cpu in a given
 function call will have to fetch its current value from memory
 (regardless of whether there's a volatile qualifier).

 And therefore the one read of that value will involve
 fetching the real value from memory, and it will
 either be UINT_MAX or the CPU's own processor id.

 So there should be no need to declare the variable
 volatile, nor to access it with ACCESS_ONCE().

 QED.  (Well, please correct me where I'm wrong...)


Thanks Alex, for the in-depth analysis. Please drop my patch in favour of 
removing volatile and without ACCESS_ONCE(). Will you send in such a patch?
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH] printk: Use ACCESS_ONCE() instead of a volatile type

2014-11-13 Thread Pranith Kumar
On Thu, Nov 13, 2014 at 10:47 PM, Steven Rostedt  wrote:
> On Thu, 13 Nov 2014 22:21:21 -0500
> Pranith Kumar  wrote:
>
>> Remove volatile type qualifier and use ACCESS_ONCE() in its place for each
>> access. Using volatile is not recommended as documented in
>> Documentation/volatile-considered-harmful.txt.
>>
>> Here logbuf_cpu is a local variable and it is not clear how it is being 
>> accessed
>> concurrently. We should remove volatile accesses entirely here, but for now 
>> make
>> a safer change of using ACCESS_ONCE().
>
> I'm a little confused by the above paragraph about it's not clear how
> it is being accessed concurrently. Do you mean the code is unclear, or
> your understanding of it is unclear?

It is definitely got to do with my understanding. recursion explains
how it can be concurrently accessed. Thanks!

>
> Regardless of your answer, this patch is correct. logbuf_cpu is used to
> determine if printk has recursed on itself before it takes the
> logbuf_lock and deadlocks. Your ACCESS_ONCE keeps the compiler from
> optimizing out the logbuf_cpu as it will see that this function is the
> only one that can touch it and may try to do weird things to it.
>
> Reviewed-by: Steven Rostedt 
>
> -- Steve
>
>
>>
>> Signed-off-by: Pranith Kumar 
>> ---
>>  kernel/printk/printk.c | 8 
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
>> index e748971..4790191 100644
>> --- a/kernel/printk/printk.c
>> +++ b/kernel/printk/printk.c
>> @@ -1624,7 +1624,7 @@ asmlinkage int vprintk_emit(int facility, int level,
>>   int printed_len = 0;
>>   bool in_sched = false;
>>   /* cpu currently holding logbuf_lock in this function */
>> - static volatile unsigned int logbuf_cpu = UINT_MAX;
>> + static unsigned int logbuf_cpu = UINT_MAX;
>>
>>   if (level == LOGLEVEL_SCHED) {
>>   level = LOGLEVEL_DEFAULT;
>> @@ -1641,7 +1641,7 @@ asmlinkage int vprintk_emit(int facility, int level,
>>   /*
>>* Ouch, printk recursed into itself!
>>*/
>> - if (unlikely(logbuf_cpu == this_cpu)) {
>> + if (unlikely(ACCESS_ONCE(logbuf_cpu) == this_cpu)) {
>>   /*
>>* If a crash is occurring during printk() on this CPU,
>>* then try to get the crash message out but make sure
>> @@ -1659,7 +1659,7 @@ asmlinkage int vprintk_emit(int facility, int level,
>>
>>   lockdep_off();
>>   raw_spin_lock(_lock);
>> - logbuf_cpu = this_cpu;
>> + ACCESS_ONCE(logbuf_cpu) = this_cpu;
>>
>>   if (unlikely(recursion_bug)) {
>>   static const char recursion_msg[] =
>> @@ -1754,7 +1754,7 @@ asmlinkage int vprintk_emit(int facility, int level,
>>dict, dictlen, text, 
>> text_len);
>>   }
>>
>> - logbuf_cpu = UINT_MAX;
>> + ACCESS_ONCE(logbuf_cpu) = UINT_MAX;
>>   raw_spin_unlock(_lock);
>>   lockdep_on();
>>   local_irq_restore(flags);
>



-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH] printk: Use ACCESS_ONCE() instead of a volatile type

2014-11-13 Thread Pranith Kumar
Remove volatile type qualifier and use ACCESS_ONCE() in its place for each
access. Using volatile is not recommended as documented in
Documentation/volatile-considered-harmful.txt.

Here logbuf_cpu is a local variable and it is not clear how it is being accessed
concurrently. We should remove volatile accesses entirely here, but for now make
a safer change of using ACCESS_ONCE().

Signed-off-by: Pranith Kumar 
---
 kernel/printk/printk.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index e748971..4790191 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1624,7 +1624,7 @@ asmlinkage int vprintk_emit(int facility, int level,
int printed_len = 0;
bool in_sched = false;
/* cpu currently holding logbuf_lock in this function */
-   static volatile unsigned int logbuf_cpu = UINT_MAX;
+   static unsigned int logbuf_cpu = UINT_MAX;
 
if (level == LOGLEVEL_SCHED) {
level = LOGLEVEL_DEFAULT;
@@ -1641,7 +1641,7 @@ asmlinkage int vprintk_emit(int facility, int level,
/*
 * Ouch, printk recursed into itself!
 */
-   if (unlikely(logbuf_cpu == this_cpu)) {
+   if (unlikely(ACCESS_ONCE(logbuf_cpu) == this_cpu)) {
/*
 * If a crash is occurring during printk() on this CPU,
 * then try to get the crash message out but make sure
@@ -1659,7 +1659,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 
lockdep_off();
raw_spin_lock(_lock);
-   logbuf_cpu = this_cpu;
+   ACCESS_ONCE(logbuf_cpu) = this_cpu;
 
if (unlikely(recursion_bug)) {
static const char recursion_msg[] =
@@ -1754,7 +1754,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 dict, dictlen, text, text_len);
}
 
-   logbuf_cpu = UINT_MAX;
+   ACCESS_ONCE(logbuf_cpu) = UINT_MAX;
raw_spin_unlock(_lock);
lockdep_on();
local_irq_restore(flags);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 16/16] rxrpc: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
On 11/13/2014 03:47 PM, David Howells wrote:
> Pranith Kumar  wrote:
> 
>> Recently lockless_dereference() was added which can be used in place of
>> hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
> 
> Actually, the use of smp_read_barrier_depends() is wrong in circular
> buffering.  See Documentation/circular-buffers.txt
> 

OK. Should I send in a patch removing these barriers then?

--
Pranith

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 01/16] crypto: caam - Remove unnecessary smp_read_barrier_depends()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 drivers/crypto/caam/jr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index bae20d8..9b3ef1bc 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -181,8 +181,6 @@ static void caam_jr_dequeue(unsigned long devarg)
for (i = 0; CIRC_CNT(head, tail + i, JOBR_DEPTH) >= 1; i++) {
sw_idx = (tail + i) & (JOBR_DEPTH - 1);
 
-   smp_read_barrier_depends();
-
if (jrp->outring[hw_idx].desc ==
jrp->entinfo[sw_idx].desc_addr_dma)
break; /* found */
@@ -218,7 +216,6 @@ static void caam_jr_dequeue(unsigned long devarg)
if (sw_idx == tail) {
do {
tail = (tail + 1) & (JOBR_DEPTH - 1);
-   smp_read_barrier_depends();
} while (CIRC_CNT(head, tail, JOBR_DEPTH) >= 1 &&
 jrp->entinfo[tail].desc_addr_dma == 0);
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 05/16] overlayfs: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 fs/overlayfs/super.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 08b704c..b0f050e 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -84,12 +84,10 @@ enum ovl_path_type ovl_path_type(struct dentry *dentry)
 
 static struct dentry *ovl_upperdentry_dereference(struct ovl_entry *oe)
 {
-   struct dentry *upperdentry = ACCESS_ONCE(oe->__upperdentry);
/*
 * Make sure to order reads to upperdentry wrt ovl_dentry_update()
 */
-   smp_read_barrier_depends();
-   return upperdentry;
+   return lockless_dereference(oe->__upperdentry);
 }
 
 void ovl_path_upper(struct dentry *dentry, struct path *path)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/16] doc: memory-barriers.txt: Document use of lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 Documentation/memory-barriers.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/memory-barriers.txt 
b/Documentation/memory-barriers.txt
index 3d5f49b..841ac36 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -203,7 +203,7 @@ There are some minimal guarantees that may be expected of a 
CPU:
  and always in that order.  On most systems, smp_read_barrier_depends()
  does nothing, but it is required for DEC Alpha.  The ACCESS_ONCE()
  is required to prevent compiler mischief.  Please note that you
- should normally use something like rcu_dereference() instead of
+ should normally use something like lockless_dereference() instead of
  open-coding smp_read_barrier_depends().
 
  (*) Overlapping loads and stores within a particular CPU will appear to be
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 03/16] drivers: dma: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 drivers/dma/ioat/dma_v2.c | 3 +--
 drivers/dma/ioat/dma_v3.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/ioat/dma_v2.c b/drivers/dma/ioat/dma_v2.c
index 695483e..0f94d72 100644
--- a/drivers/dma/ioat/dma_v2.c
+++ b/drivers/dma/ioat/dma_v2.c
@@ -142,10 +142,9 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
 
active = ioat2_ring_active(ioat);
for (i = 0; i < active && !seen_current; i++) {
-   smp_read_barrier_depends();
prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
desc = ioat2_get_ring_ent(ioat, idx + i);
-   tx = >txd;
+   tx = _dereference(desc)->txd;
dump_desc_dbg(ioat, desc);
if (tx->cookie) {
dma_descriptor_unmap(tx);
diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
index 895f869..cbd0537 100644
--- a/drivers/dma/ioat/dma_v3.c
+++ b/drivers/dma/ioat/dma_v3.c
@@ -389,7 +389,6 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
for (i = 0; i < active && !seen_current; i++) {
struct dma_async_tx_descriptor *tx;
 
-   smp_read_barrier_depends();
prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
desc = ioat2_get_ring_ent(ioat, idx + i);
dump_desc_dbg(ioat, desc);
@@ -398,7 +397,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
if (device->cap & IOAT_CAP_DWBES)
desc_get_errstat(ioat, desc);
 
-   tx = >txd;
+   tx = _dereference(desc)->txd;
if (tx->cookie) {
dma_cookie_complete(tx);
dma_descriptor_unmap(tx);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 08/16] rcupdate: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 include/linux/rcupdate.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index ed4f593..386ba28 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -582,11 +582,11 @@ static inline void rcu_preempt_sleep_check(void)
 })
 #define __rcu_dereference_check(p, c, space) \
 ({ \
-   typeof(*p) *_p1 = (typeof(*p) *__force)ACCESS_ONCE(p); \
+   /* Dependency order vs. p above. */ \
+   typeof(*p) *p1 = (typeof(*p) *__force)lockless_dereference(p); \
rcu_lockdep_assert(c, "suspicious rcu_dereference_check() usage"); \
rcu_dereference_sparse(p, space); \
-   smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
-   ((typeof(*p) __force __kernel *)(_p1)); \
+   ((typeof(*p) __force __kernel *)(p1)); \
 })
 #define __rcu_dereference_protected(p, c, space) \
 ({ \
@@ -603,10 +603,10 @@ static inline void rcu_preempt_sleep_check(void)
 })
 #define __rcu_dereference_index_check(p, c) \
 ({ \
-   typeof(p) _p1 = ACCESS_ONCE(p); \
+   /* Dependency order vs. p above. */ \
+   typeof(p) _p1 = lockless_dereference(p); \
rcu_lockdep_assert(c, \
   "suspicious rcu_dereference_index_check() usage"); \
-   smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
(_p1); \
 })
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 06/16] assoc_array: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

I replaced the inline functions dereferencing pointer 'x' to use
lockless_dereference() because of which we do not need to litter the code with
smp_read_barrier_depends().

Signed-off-by: Pranith Kumar 
---
 include/linux/assoc_array_priv.h | 11 +++
 lib/assoc_array.c|  7 ---
 security/keys/keyring.c  |  6 --
 3 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/include/linux/assoc_array_priv.h b/include/linux/assoc_array_priv.h
index 711275e..96449c3 100644
--- a/include/linux/assoc_array_priv.h
+++ b/include/linux/assoc_array_priv.h
@@ -118,7 +118,8 @@ struct assoc_array_edit {
 
 static inline bool assoc_array_ptr_is_meta(const struct assoc_array_ptr *x)
 {
-   return (unsigned long)x & ASSOC_ARRAY_PTR_TYPE_MASK;
+   return (unsigned long)lockless_dereference(x) &
+   ASSOC_ARRAY_PTR_TYPE_MASK;
 }
 static inline bool assoc_array_ptr_is_leaf(const struct assoc_array_ptr *x)
 {
@@ -126,7 +127,8 @@ static inline bool assoc_array_ptr_is_leaf(const struct 
assoc_array_ptr *x)
 }
 static inline bool assoc_array_ptr_is_shortcut(const struct assoc_array_ptr *x)
 {
-   return (unsigned long)x & ASSOC_ARRAY_PTR_SUBTYPE_MASK;
+   return (unsigned long)lockless_dereference(x) &
+   ASSOC_ARRAY_PTR_SUBTYPE_MASK;
 }
 static inline bool assoc_array_ptr_is_node(const struct assoc_array_ptr *x)
 {
@@ -135,13 +137,14 @@ static inline bool assoc_array_ptr_is_node(const struct 
assoc_array_ptr *x)
 
 static inline void *assoc_array_ptr_to_leaf(const struct assoc_array_ptr *x)
 {
-   return (void *)((unsigned long)x & ~ASSOC_ARRAY_PTR_TYPE_MASK);
+   return (void *)((unsigned long)lockless_dereference(x) &
+   ~ASSOC_ARRAY_PTR_TYPE_MASK);
 }
 
 static inline
 unsigned long __assoc_array_ptr_to_meta(const struct assoc_array_ptr *x)
 {
-   return (unsigned long)x &
+   return (unsigned long)lockless_dereference(x) &
~(ASSOC_ARRAY_PTR_SUBTYPE_MASK | ASSOC_ARRAY_PTR_TYPE_MASK);
 }
 static inline
diff --git a/lib/assoc_array.c b/lib/assoc_array.c
index 2404d03..5b62033 100644
--- a/lib/assoc_array.c
+++ b/lib/assoc_array.c
@@ -37,12 +37,10 @@ begin_node:
if (assoc_array_ptr_is_shortcut(cursor)) {
/* Descend through a shortcut */
shortcut = assoc_array_ptr_to_shortcut(cursor);
-   smp_read_barrier_depends();
cursor = ACCESS_ONCE(shortcut->next_node);
}
 
node = assoc_array_ptr_to_node(cursor);
-   smp_read_barrier_depends();
slot = 0;
 
/* We perform two passes of each node.
@@ -85,7 +83,6 @@ begin_node:
 
 continue_node:
node = assoc_array_ptr_to_node(cursor);
-   smp_read_barrier_depends();
 
for (; slot < ASSOC_ARRAY_FAN_OUT; slot++) {
ptr = ACCESS_ONCE(node->slots[slot]);
@@ -104,7 +101,6 @@ finished_node:
 
if (assoc_array_ptr_is_shortcut(parent)) {
shortcut = assoc_array_ptr_to_shortcut(parent);
-   smp_read_barrier_depends();
cursor = parent;
parent = ACCESS_ONCE(shortcut->back_pointer);
slot = shortcut->parent_slot;
@@ -215,7 +211,6 @@ jumped:
 
 consider_node:
node = assoc_array_ptr_to_node(cursor);
-   smp_read_barrier_depends();
 
slot = segments >> (level & ASSOC_ARRAY_KEY_CHUNK_MASK);
slot &= ASSOC_ARRAY_FAN_MASK;
@@ -253,7 +248,6 @@ consider_node:
cursor = ptr;
 follow_shortcut:
shortcut = assoc_array_ptr_to_shortcut(cursor);
-   smp_read_barrier_depends();
pr_devel("shortcut to %d\n", shortcut->skip_to_level);
sc_level = level + ASSOC_ARRAY_LEVEL_STEP;
BUG_ON(sc_level > shortcut->skip_to_level);
@@ -343,7 +337,6 @@ void *assoc_array_find(const struct assoc_array *array,
 * actually going to dereference it.
 */
leaf = assoc_array_ptr_to_leaf(ptr);
-   smp_read_barrier_depends();
if (ops->compare_object(leaf, index_key))
return (void *)leaf;
}
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index 8177010..48d3464 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -683,7 +683,6 @@ descend_to_keyring:
 * doesn't contain any keyring pointers.
 */
shortcut = assoc_array_ptr_to_shortcut(ptr);
-   smp_read_barrier_depends();
if ((shortcut->index_key[0] & ASSOC_ARRAY_FAN_MASK) != 

[PATCH 12/16] task_work: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 kernel/task_work.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/task_work.c b/kernel/task_work.c
index 8727032..b5599ce 100644
--- a/kernel/task_work.c
+++ b/kernel/task_work.c
@@ -62,8 +62,7 @@ task_work_cancel(struct task_struct *task, task_work_func_t 
func)
 * we raced with task_work_run(), *pprev == NULL/exited.
 */
raw_spin_lock_irqsave(>pi_lock, flags);
-   while ((work = ACCESS_ONCE(*pprev))) {
-   smp_read_barrier_depends();
+   while ((work = lockless_dereference(*pprev))) {
if (work->func != func)
pprev = >next;
else if (cmpxchg(pprev, work, work->next) == work)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/16] hyperv: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 include/linux/hyperv.h | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 08cfaff..06418b1 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -127,13 +127,12 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info 
*rbi,
  u32 *read, u32 *write)
 {
u32 read_loc, write_loc, dsize;
-
-   smp_read_barrier_depends();
+   struct hv_ring_buffer_info *rbi_p = lockless_dereference(rbi);
 
/* Capture the read/write indices before they changed */
-   read_loc = rbi->ring_buffer->read_index;
-   write_loc = rbi->ring_buffer->write_index;
-   dsize = rbi->ring_datasize;
+   read_loc = rbi_p->ring_buffer->read_index;
+   write_loc = rbi_p->ring_buffer->write_index;
+   dsize = rbi_p->ring_datasize;
 
*write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
read_loc - write_loc;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 09/16] percpu: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 include/linux/percpu-refcount.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index 494ab05..3cf6759 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -128,10 +128,8 @@ static inline void percpu_ref_kill(struct percpu_ref *ref)
 static inline bool __ref_is_percpu(struct percpu_ref *ref,
  unsigned long __percpu 
**percpu_countp)
 {
-   unsigned long percpu_ptr = ACCESS_ONCE(ref->percpu_count_ptr);
-
/* paired with smp_store_release() in percpu_ref_reinit() */
-   smp_read_barrier_depends();
+   unsigned long percpu_ptr = lockless_dereference(ref->percpu_count_ptr);
 
if (unlikely(percpu_ptr & __PERCPU_REF_ATOMIC))
return false;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 11/16] seccomp: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 kernel/seccomp.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 4ef9687..3729b06 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter 
*filter, unsigned int flen)
  */
 static u32 seccomp_run_filters(struct seccomp_data *sd)
 {
-   struct seccomp_filter *f = ACCESS_ONCE(current->seccomp.filter);
struct seccomp_data sd_local;
u32 ret = SECCOMP_RET_ALLOW;
+   /* Make sure cross-thread synced filter points somewhere sane. */
+   struct seccomp_filter *f =
+   lockless_dereference(current->seccomp.filter);
 
/* Ensure unexpected behavior doesn't result in failing open. */
if (unlikely(WARN_ON(f == NULL)))
return SECCOMP_RET_KILL;
 
-   /* Make sure cross-thread synced filter points somewhere sane. */
-   smp_read_barrier_depends();
-
if (!sd) {
populate_seccomp_data(_local);
sd = _local;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 13/16] ksm: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 mm/ksm.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mm/ksm.c b/mm/ksm.c
index d247efa..a67de79 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -542,15 +542,14 @@ static struct page *get_ksm_page(struct stable_node 
*stable_node, bool lock_it)
expected_mapping = (void *)stable_node +
(PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
 again:
-   kpfn = ACCESS_ONCE(stable_node->kpfn);
-   page = pfn_to_page(kpfn);
-
/*
 * page is computed from kpfn, so on most architectures reading
 * page->mapping is naturally ordered after reading node->kpfn,
 * but on Alpha we need to be more careful.
 */
-   smp_read_barrier_depends();
+   kpfn = lockless_dereference(stable_node->kpfn);
+   page = pfn_to_page(kpfn);
+
if (ACCESS_ONCE(page->mapping) != expected_mapping)
goto stale;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/16] perf: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 kernel/events/core.c| 3 +--
 kernel/events/uprobes.c | 8 
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index d59fdc0..9dd5920 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3400,14 +3400,13 @@ static void perf_remove_from_owner(struct perf_event 
*event)
struct task_struct *owner;
 
rcu_read_lock();
-   owner = ACCESS_ONCE(event->owner);
/*
 * Matches the smp_wmb() in perf_event_exit_task(). If we observe
 * !owner it means the list deletion is complete and we can indeed
 * free this event, otherwise we need to serialize on
 * owner->perf_event_mutex.
 */
-   smp_read_barrier_depends();
+   owner = lockless_dereference(event->owner);
if (owner) {
/*
 * Since delayed_put_task_struct() also drops the last
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 6158a64b..c070949 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1212,8 +1212,8 @@ static struct xol_area *get_xol_area(void)
if (!mm->uprobes_state.xol_area)
__create_xol_area(0);
 
-   area = mm->uprobes_state.xol_area;
-   smp_read_barrier_depends(); /* pairs with wmb in xol_add_vma() */
+   /* pairs with wmb in xol_add_vma() */
+   area = lockless_dereference(mm->uprobes_state.xol_area);
return area;
 }
 
@@ -1507,8 +1507,8 @@ static unsigned long get_trampoline_vaddr(void)
struct xol_area *area;
unsigned long trampoline_vaddr = -1;
 
-   area = current->mm->uprobes_state.xol_area;
-   smp_read_barrier_depends();
+   area = lockless_dereference(current->mm->uprobes_state.xol_area);
+
if (area)
trampoline_vaddr = area->vaddr;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 15/16] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 net/ipv4/netfilter/arp_tables.c | 3 +--
 net/ipv4/netfilter/ip_tables.c  | 3 +--
 net/ipv6/netfilter/ip6_tables.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index f95b6f9..fc7533d 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -270,12 +270,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,
 
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table->private;
/*
 * Ensure we load private-> members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table->private);
table_base = private->entries[smp_processor_id()];
 
e = get_entry(table_base, private->hook_entry[hook]);
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 99e810f..e0fd044 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -325,13 +325,12 @@ ipt_do_table(struct sk_buff *skb,
IP_NF_ASSERT(table->valid_hooks & (1 << hook));
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table->private;
cpu= smp_processor_id();
/*
 * Ensure we load private-> members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table->private);
table_base = private->entries[cpu];
jumpstack  = (struct ipt_entry **)private->jumpstack[cpu];
stackptr   = per_cpu_ptr(private->stackptr, cpu);
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index e080fbb..0459d6a 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -348,12 +348,11 @@ ip6t_do_table(struct sk_buff *skb,
 
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table->private;
/*
 * Ensure we load private-> members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table->private);
cpu= smp_processor_id();
table_base = private->entries[cpu];
jumpstack  = (struct ip6t_entry **)private->jumpstack[cpu];
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 16/16] rxrpc: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 net/rxrpc/ar-ack.c | 22 +-
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
index c6be17a..9237448 100644
--- a/net/rxrpc/ar-ack.c
+++ b/net/rxrpc/ar-ack.c
@@ -234,8 +234,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
 loop != call->acks_head || stop;
 loop = (loop + 1) &  (call->acks_winsz - 1)
 ) {
-   p_txb = call->acks_window + loop;
-   smp_read_barrier_depends();
+   p_txb = lockless_dereference(call)->acks_window + loop;
if (*p_txb & 1)
continue;
 
@@ -303,8 +302,7 @@ static void rxrpc_resend_timer(struct rxrpc_call *call)
 loop != call->acks_head;
 loop = (loop + 1) &  (call->acks_winsz - 1)
 ) {
-   p_txb = call->acks_window + loop;
-   smp_read_barrier_depends();
+   p_txb = lockless_dereference(call)->acks_window + loop;
txb = (struct sk_buff *) (*p_txb & ~1);
sp = rxrpc_skb(txb);
 
@@ -354,9 +352,10 @@ static int rxrpc_process_soft_ACKs(struct rxrpc_call *call,
resend = 0;
resend_at = 0;
for (loop = 0; loop < ack->nAcks; loop++) {
-   p_txb = call->acks_window;
-   p_txb += (call->acks_tail + loop) & (call->acks_winsz - 1);
-   smp_read_barrier_depends();
+   struct rxrpc_call *callp = lockless_dereference(call);
+
+   p_txb = callp->acks_window;
+   p_txb += (callp->acks_tail + loop) & (callp->acks_winsz - 1);
txb = (struct sk_buff *) (*p_txb & ~1);
sp = rxrpc_skb(txb);
 
@@ -385,8 +384,7 @@ static int rxrpc_process_soft_ACKs(struct rxrpc_call *call,
 loop != call->acks_head;
 loop = (loop + 1) &  (call->acks_winsz - 1)
 ) {
-   p_txb = call->acks_window + loop;
-   smp_read_barrier_depends();
+   p_txb = lockless_dereference(call)->acks_window + loop;
txb = (struct sk_buff *) (*p_txb & ~1);
sp = rxrpc_skb(txb);
 
@@ -432,8 +430,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, 
u32 hard)
ASSERTCMP(hard - call->acks_hard, <=, win);
 
while (call->acks_hard < hard) {
-   smp_read_barrier_depends();
-   _skb = call->acks_window[tail] & ~1;
+   _skb = lockless_dereference(call)->acks_window[tail] & ~1;
rxrpc_free_skb((struct sk_buff *) _skb);
old_tail = tail;
tail = (tail + 1) & (call->acks_winsz - 1);
@@ -577,8 +574,7 @@ static void rxrpc_zap_tx_window(struct rxrpc_call *call)
call->acks_window = NULL;
 
while (CIRC_CNT(call->acks_head, call->acks_tail, winsz) > 0) {
-   tail = call->acks_tail;
-   smp_read_barrier_depends();
+   tail = lockless_dereference(call)->acks_tail;
_skb = acks_window[tail] & ~1;
smp_mb();
call->acks_tail = (call->acks_tail + 1) & (winsz - 1);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 04/16] dcache: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 fs/dcache.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index a6c5d7e..27b8b5b 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -230,8 +230,7 @@ static inline int dentry_cmp(const struct dentry *dentry, 
const unsigned char *c
 * early because the data cannot match (there can
 * be no NUL in the ct/tcount data)
 */
-   cs = ACCESS_ONCE(dentry->d_name.name);
-   smp_read_barrier_depends();
+   cs = lockless_dereference(dentry->d_name.name);
return dentry_string_cmp(cs, ct, tcount);
 }
 
@@ -2714,10 +2713,8 @@ static int prepend(char **buffer, int *buflen, const 
char *str, int namelen)
 static int prepend_name(char **buffer, int *buflen, struct qstr *name)
 {
const char *dname = ACCESS_ONCE(name->name);
-   u32 dlen = ACCESS_ONCE(name->len);
char *p;
-
-   smp_read_barrier_depends();
+   u32 dlen = lockless_dereference(name->len);
 
*buflen -= dlen + 1;
if (*buflen < 0)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 14/16] slab: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar 
---
 mm/slab.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/slab.h b/mm/slab.h
index 3347fd7..1cf40054 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -209,15 +209,15 @@ cache_from_memcg_idx(struct kmem_cache *s, int idx)
 
rcu_read_lock();
params = rcu_dereference(s->memcg_params);
-   cachep = params->memcg_caches[idx];
-   rcu_read_unlock();
 
/*
 * Make sure we will access the up-to-date value. The code updating
 * memcg_caches issues a write barrier to match this (see
 * memcg_register_cache()).
 */
-   smp_read_barrier_depends();
+   cachep = lockless_dereference(params->memcg_caches[idx]);
+   rcu_read_unlock();
+
return cachep;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH 00/16] Replace smp_read_barrier_depends() with lockless_derefrence()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). 

http://lkml.iu.edu/hypermail/linux/kernel/1410.3/04561.html

The following series tries to do this.

There are still some hard-coded locations which I was not sure how to replace
with. I will send in separate patches/questions regarding them.

Pranith Kumar (16):
  crypto: caam - Remove unnecessary smp_read_barrier_depends()
  doc: memory-barriers.txt: Document use of lockless_dereference()
  drivers: dma: Replace smp_read_barrier_depends() with
lockless_dereference()
  dcache: Replace smp_read_barrier_depends() with lockless_dereference()
  overlayfs: Replace smp_read_barrier_depends() with
lockless_dereference()
  assoc_array: Replace smp_read_barrier_depends() with
lockless_dereference()
  hyperv: Replace smp_read_barrier_depends() with lockless_dereference()
  rcupdate: Replace smp_read_barrier_depends() with
lockless_dereference()
  percpu: Replace smp_read_barrier_depends() with lockless_dereference()
  perf: Replace smp_read_barrier_depends() with lockless_dereference()
  seccomp: Replace smp_read_barrier_depends() with
lockless_dereference()
  task_work: Replace smp_read_barrier_depends() with
lockless_dereference()
  ksm: Replace smp_read_barrier_depends() with lockless_dereference()
  slab: Replace smp_read_barrier_depends() with lockless_dereference()
  netfilter: Replace smp_read_barrier_depends() with
lockless_dereference()
  rxrpc: Replace smp_read_barrier_depends() with lockless_dereference()

 Documentation/memory-barriers.txt |  2 +-
 drivers/crypto/caam/jr.c  |  3 ---
 drivers/dma/ioat/dma_v2.c |  3 +--
 drivers/dma/ioat/dma_v3.c |  3 +--
 fs/dcache.c   |  7 ++-
 fs/overlayfs/super.c  |  4 +---
 include/linux/assoc_array_priv.h  | 11 +++
 include/linux/hyperv.h|  9 -
 include/linux/percpu-refcount.h   |  4 +---
 include/linux/rcupdate.h  | 10 +-
 kernel/events/core.c  |  3 +--
 kernel/events/uprobes.c   |  8 
 kernel/seccomp.c  |  7 +++
 kernel/task_work.c|  3 +--
 lib/assoc_array.c |  7 ---
 mm/ksm.c  |  7 +++
 mm/slab.h |  6 +++---
 net/ipv4/netfilter/arp_tables.c   |  3 +--
 net/ipv4/netfilter/ip_tables.c|  3 +--
 net/ipv6/netfilter/ip6_tables.c   |  3 +--
 net/rxrpc/ar-ack.c| 22 +-
 security/keys/keyring.c   |  6 --
 22 files changed, 50 insertions(+), 84 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH 00/16] Replace smp_read_barrier_depends() with lockless_derefrence()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). 

http://lkml.iu.edu/hypermail/linux/kernel/1410.3/04561.html

The following series tries to do this.

There are still some hard-coded locations which I was not sure how to replace
with. I will send in separate patches/questions regarding them.

Pranith Kumar (16):
  crypto: caam - Remove unnecessary smp_read_barrier_depends()
  doc: memory-barriers.txt: Document use of lockless_dereference()
  drivers: dma: Replace smp_read_barrier_depends() with
lockless_dereference()
  dcache: Replace smp_read_barrier_depends() with lockless_dereference()
  overlayfs: Replace smp_read_barrier_depends() with
lockless_dereference()
  assoc_array: Replace smp_read_barrier_depends() with
lockless_dereference()
  hyperv: Replace smp_read_barrier_depends() with lockless_dereference()
  rcupdate: Replace smp_read_barrier_depends() with
lockless_dereference()
  percpu: Replace smp_read_barrier_depends() with lockless_dereference()
  perf: Replace smp_read_barrier_depends() with lockless_dereference()
  seccomp: Replace smp_read_barrier_depends() with
lockless_dereference()
  task_work: Replace smp_read_barrier_depends() with
lockless_dereference()
  ksm: Replace smp_read_barrier_depends() with lockless_dereference()
  slab: Replace smp_read_barrier_depends() with lockless_dereference()
  netfilter: Replace smp_read_barrier_depends() with
lockless_dereference()
  rxrpc: Replace smp_read_barrier_depends() with lockless_dereference()

 Documentation/memory-barriers.txt |  2 +-
 drivers/crypto/caam/jr.c  |  3 ---
 drivers/dma/ioat/dma_v2.c |  3 +--
 drivers/dma/ioat/dma_v3.c |  3 +--
 fs/dcache.c   |  7 ++-
 fs/overlayfs/super.c  |  4 +---
 include/linux/assoc_array_priv.h  | 11 +++
 include/linux/hyperv.h|  9 -
 include/linux/percpu-refcount.h   |  4 +---
 include/linux/rcupdate.h  | 10 +-
 kernel/events/core.c  |  3 +--
 kernel/events/uprobes.c   |  8 
 kernel/seccomp.c  |  7 +++
 kernel/task_work.c|  3 +--
 lib/assoc_array.c |  7 ---
 mm/ksm.c  |  7 +++
 mm/slab.h |  6 +++---
 net/ipv4/netfilter/arp_tables.c   |  3 +--
 net/ipv4/netfilter/ip_tables.c|  3 +--
 net/ipv6/netfilter/ip6_tables.c   |  3 +--
 net/rxrpc/ar-ack.c| 22 +-
 security/keys/keyring.c   |  6 --
 22 files changed, 50 insertions(+), 84 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 14/16] slab: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 mm/slab.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/slab.h b/mm/slab.h
index 3347fd7..1cf40054 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -209,15 +209,15 @@ cache_from_memcg_idx(struct kmem_cache *s, int idx)
 
rcu_read_lock();
params = rcu_dereference(s-memcg_params);
-   cachep = params-memcg_caches[idx];
-   rcu_read_unlock();
 
/*
 * Make sure we will access the up-to-date value. The code updating
 * memcg_caches issues a write barrier to match this (see
 * memcg_register_cache()).
 */
-   smp_read_barrier_depends();
+   cachep = lockless_dereference(params-memcg_caches[idx]);
+   rcu_read_unlock();
+
return cachep;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 04/16] dcache: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 fs/dcache.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index a6c5d7e..27b8b5b 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -230,8 +230,7 @@ static inline int dentry_cmp(const struct dentry *dentry, 
const unsigned char *c
 * early because the data cannot match (there can
 * be no NUL in the ct/tcount data)
 */
-   cs = ACCESS_ONCE(dentry-d_name.name);
-   smp_read_barrier_depends();
+   cs = lockless_dereference(dentry-d_name.name);
return dentry_string_cmp(cs, ct, tcount);
 }
 
@@ -2714,10 +2713,8 @@ static int prepend(char **buffer, int *buflen, const 
char *str, int namelen)
 static int prepend_name(char **buffer, int *buflen, struct qstr *name)
 {
const char *dname = ACCESS_ONCE(name-name);
-   u32 dlen = ACCESS_ONCE(name-len);
char *p;
-
-   smp_read_barrier_depends();
+   u32 dlen = lockless_dereference(name-len);
 
*buflen -= dlen + 1;
if (*buflen  0)
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 16/16] rxrpc: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 net/rxrpc/ar-ack.c | 22 +-
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
index c6be17a..9237448 100644
--- a/net/rxrpc/ar-ack.c
+++ b/net/rxrpc/ar-ack.c
@@ -234,8 +234,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
 loop != call-acks_head || stop;
 loop = (loop + 1)   (call-acks_winsz - 1)
 ) {
-   p_txb = call-acks_window + loop;
-   smp_read_barrier_depends();
+   p_txb = lockless_dereference(call)-acks_window + loop;
if (*p_txb  1)
continue;
 
@@ -303,8 +302,7 @@ static void rxrpc_resend_timer(struct rxrpc_call *call)
 loop != call-acks_head;
 loop = (loop + 1)   (call-acks_winsz - 1)
 ) {
-   p_txb = call-acks_window + loop;
-   smp_read_barrier_depends();
+   p_txb = lockless_dereference(call)-acks_window + loop;
txb = (struct sk_buff *) (*p_txb  ~1);
sp = rxrpc_skb(txb);
 
@@ -354,9 +352,10 @@ static int rxrpc_process_soft_ACKs(struct rxrpc_call *call,
resend = 0;
resend_at = 0;
for (loop = 0; loop  ack-nAcks; loop++) {
-   p_txb = call-acks_window;
-   p_txb += (call-acks_tail + loop)  (call-acks_winsz - 1);
-   smp_read_barrier_depends();
+   struct rxrpc_call *callp = lockless_dereference(call);
+
+   p_txb = callp-acks_window;
+   p_txb += (callp-acks_tail + loop)  (callp-acks_winsz - 1);
txb = (struct sk_buff *) (*p_txb  ~1);
sp = rxrpc_skb(txb);
 
@@ -385,8 +384,7 @@ static int rxrpc_process_soft_ACKs(struct rxrpc_call *call,
 loop != call-acks_head;
 loop = (loop + 1)   (call-acks_winsz - 1)
 ) {
-   p_txb = call-acks_window + loop;
-   smp_read_barrier_depends();
+   p_txb = lockless_dereference(call)-acks_window + loop;
txb = (struct sk_buff *) (*p_txb  ~1);
sp = rxrpc_skb(txb);
 
@@ -432,8 +430,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, 
u32 hard)
ASSERTCMP(hard - call-acks_hard, =, win);
 
while (call-acks_hard  hard) {
-   smp_read_barrier_depends();
-   _skb = call-acks_window[tail]  ~1;
+   _skb = lockless_dereference(call)-acks_window[tail]  ~1;
rxrpc_free_skb((struct sk_buff *) _skb);
old_tail = tail;
tail = (tail + 1)  (call-acks_winsz - 1);
@@ -577,8 +574,7 @@ static void rxrpc_zap_tx_window(struct rxrpc_call *call)
call-acks_window = NULL;
 
while (CIRC_CNT(call-acks_head, call-acks_tail, winsz)  0) {
-   tail = call-acks_tail;
-   smp_read_barrier_depends();
+   tail = lockless_dereference(call)-acks_tail;
_skb = acks_window[tail]  ~1;
smp_mb();
call-acks_tail = (call-acks_tail + 1)  (winsz - 1);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 15/16] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 net/ipv4/netfilter/arp_tables.c | 3 +--
 net/ipv4/netfilter/ip_tables.c  | 3 +--
 net/ipv6/netfilter/ip6_tables.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index f95b6f9..fc7533d 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -270,12 +270,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,
 
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table-private;
/*
 * Ensure we load private- members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table-private);
table_base = private-entries[smp_processor_id()];
 
e = get_entry(table_base, private-hook_entry[hook]);
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 99e810f..e0fd044 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -325,13 +325,12 @@ ipt_do_table(struct sk_buff *skb,
IP_NF_ASSERT(table-valid_hooks  (1  hook));
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table-private;
cpu= smp_processor_id();
/*
 * Ensure we load private- members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table-private);
table_base = private-entries[cpu];
jumpstack  = (struct ipt_entry **)private-jumpstack[cpu];
stackptr   = per_cpu_ptr(private-stackptr, cpu);
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index e080fbb..0459d6a 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -348,12 +348,11 @@ ip6t_do_table(struct sk_buff *skb,
 
local_bh_disable();
addend = xt_write_recseq_begin();
-   private = table-private;
/*
 * Ensure we load private- members after we've fetched the base
 * pointer.
 */
-   smp_read_barrier_depends();
+   private = lockless_dereference(table-private);
cpu= smp_processor_id();
table_base = private-entries[cpu];
jumpstack  = (struct ip6t_entry **)private-jumpstack[cpu];
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/16] perf: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 kernel/events/core.c| 3 +--
 kernel/events/uprobes.c | 8 
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index d59fdc0..9dd5920 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3400,14 +3400,13 @@ static void perf_remove_from_owner(struct perf_event 
*event)
struct task_struct *owner;
 
rcu_read_lock();
-   owner = ACCESS_ONCE(event-owner);
/*
 * Matches the smp_wmb() in perf_event_exit_task(). If we observe
 * !owner it means the list deletion is complete and we can indeed
 * free this event, otherwise we need to serialize on
 * owner-perf_event_mutex.
 */
-   smp_read_barrier_depends();
+   owner = lockless_dereference(event-owner);
if (owner) {
/*
 * Since delayed_put_task_struct() also drops the last
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 6158a64b..c070949 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1212,8 +1212,8 @@ static struct xol_area *get_xol_area(void)
if (!mm-uprobes_state.xol_area)
__create_xol_area(0);
 
-   area = mm-uprobes_state.xol_area;
-   smp_read_barrier_depends(); /* pairs with wmb in xol_add_vma() */
+   /* pairs with wmb in xol_add_vma() */
+   area = lockless_dereference(mm-uprobes_state.xol_area);
return area;
 }
 
@@ -1507,8 +1507,8 @@ static unsigned long get_trampoline_vaddr(void)
struct xol_area *area;
unsigned long trampoline_vaddr = -1;
 
-   area = current-mm-uprobes_state.xol_area;
-   smp_read_barrier_depends();
+   area = lockless_dereference(current-mm-uprobes_state.xol_area);
+
if (area)
trampoline_vaddr = area-vaddr;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 11/16] seccomp: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 kernel/seccomp.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 4ef9687..3729b06 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter 
*filter, unsigned int flen)
  */
 static u32 seccomp_run_filters(struct seccomp_data *sd)
 {
-   struct seccomp_filter *f = ACCESS_ONCE(current-seccomp.filter);
struct seccomp_data sd_local;
u32 ret = SECCOMP_RET_ALLOW;
+   /* Make sure cross-thread synced filter points somewhere sane. */
+   struct seccomp_filter *f =
+   lockless_dereference(current-seccomp.filter);
 
/* Ensure unexpected behavior doesn't result in failing open. */
if (unlikely(WARN_ON(f == NULL)))
return SECCOMP_RET_KILL;
 
-   /* Make sure cross-thread synced filter points somewhere sane. */
-   smp_read_barrier_depends();
-
if (!sd) {
populate_seccomp_data(sd_local);
sd = sd_local;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 13/16] ksm: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 mm/ksm.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mm/ksm.c b/mm/ksm.c
index d247efa..a67de79 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -542,15 +542,14 @@ static struct page *get_ksm_page(struct stable_node 
*stable_node, bool lock_it)
expected_mapping = (void *)stable_node +
(PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
 again:
-   kpfn = ACCESS_ONCE(stable_node-kpfn);
-   page = pfn_to_page(kpfn);
-
/*
 * page is computed from kpfn, so on most architectures reading
 * page-mapping is naturally ordered after reading node-kpfn,
 * but on Alpha we need to be more careful.
 */
-   smp_read_barrier_depends();
+   kpfn = lockless_dereference(stable_node-kpfn);
+   page = pfn_to_page(kpfn);
+
if (ACCESS_ONCE(page-mapping) != expected_mapping)
goto stale;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 09/16] percpu: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 include/linux/percpu-refcount.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index 494ab05..3cf6759 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -128,10 +128,8 @@ static inline void percpu_ref_kill(struct percpu_ref *ref)
 static inline bool __ref_is_percpu(struct percpu_ref *ref,
  unsigned long __percpu 
**percpu_countp)
 {
-   unsigned long percpu_ptr = ACCESS_ONCE(ref-percpu_count_ptr);
-
/* paired with smp_store_release() in percpu_ref_reinit() */
-   smp_read_barrier_depends();
+   unsigned long percpu_ptr = lockless_dereference(ref-percpu_count_ptr);
 
if (unlikely(percpu_ptr  __PERCPU_REF_ATOMIC))
return false;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/16] hyperv: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 include/linux/hyperv.h | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 08cfaff..06418b1 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -127,13 +127,12 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info 
*rbi,
  u32 *read, u32 *write)
 {
u32 read_loc, write_loc, dsize;
-
-   smp_read_barrier_depends();
+   struct hv_ring_buffer_info *rbi_p = lockless_dereference(rbi);
 
/* Capture the read/write indices before they changed */
-   read_loc = rbi-ring_buffer-read_index;
-   write_loc = rbi-ring_buffer-write_index;
-   dsize = rbi-ring_datasize;
+   read_loc = rbi_p-ring_buffer-read_index;
+   write_loc = rbi_p-ring_buffer-write_index;
+   dsize = rbi_p-ring_datasize;
 
*write = write_loc = read_loc ? dsize - (write_loc - read_loc) :
read_loc - write_loc;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 12/16] task_work: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 kernel/task_work.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/task_work.c b/kernel/task_work.c
index 8727032..b5599ce 100644
--- a/kernel/task_work.c
+++ b/kernel/task_work.c
@@ -62,8 +62,7 @@ task_work_cancel(struct task_struct *task, task_work_func_t 
func)
 * we raced with task_work_run(), *pprev == NULL/exited.
 */
raw_spin_lock_irqsave(task-pi_lock, flags);
-   while ((work = ACCESS_ONCE(*pprev))) {
-   smp_read_barrier_depends();
+   while ((work = lockless_dereference(*pprev))) {
if (work-func != func)
pprev = work-next;
else if (cmpxchg(pprev, work, work-next) == work)
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 06/16] assoc_array: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

I replaced the inline functions dereferencing pointer 'x' to use
lockless_dereference() because of which we do not need to litter the code with
smp_read_barrier_depends().

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 include/linux/assoc_array_priv.h | 11 +++
 lib/assoc_array.c|  7 ---
 security/keys/keyring.c  |  6 --
 3 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/include/linux/assoc_array_priv.h b/include/linux/assoc_array_priv.h
index 711275e..96449c3 100644
--- a/include/linux/assoc_array_priv.h
+++ b/include/linux/assoc_array_priv.h
@@ -118,7 +118,8 @@ struct assoc_array_edit {
 
 static inline bool assoc_array_ptr_is_meta(const struct assoc_array_ptr *x)
 {
-   return (unsigned long)x  ASSOC_ARRAY_PTR_TYPE_MASK;
+   return (unsigned long)lockless_dereference(x) 
+   ASSOC_ARRAY_PTR_TYPE_MASK;
 }
 static inline bool assoc_array_ptr_is_leaf(const struct assoc_array_ptr *x)
 {
@@ -126,7 +127,8 @@ static inline bool assoc_array_ptr_is_leaf(const struct 
assoc_array_ptr *x)
 }
 static inline bool assoc_array_ptr_is_shortcut(const struct assoc_array_ptr *x)
 {
-   return (unsigned long)x  ASSOC_ARRAY_PTR_SUBTYPE_MASK;
+   return (unsigned long)lockless_dereference(x) 
+   ASSOC_ARRAY_PTR_SUBTYPE_MASK;
 }
 static inline bool assoc_array_ptr_is_node(const struct assoc_array_ptr *x)
 {
@@ -135,13 +137,14 @@ static inline bool assoc_array_ptr_is_node(const struct 
assoc_array_ptr *x)
 
 static inline void *assoc_array_ptr_to_leaf(const struct assoc_array_ptr *x)
 {
-   return (void *)((unsigned long)x  ~ASSOC_ARRAY_PTR_TYPE_MASK);
+   return (void *)((unsigned long)lockless_dereference(x) 
+   ~ASSOC_ARRAY_PTR_TYPE_MASK);
 }
 
 static inline
 unsigned long __assoc_array_ptr_to_meta(const struct assoc_array_ptr *x)
 {
-   return (unsigned long)x 
+   return (unsigned long)lockless_dereference(x) 
~(ASSOC_ARRAY_PTR_SUBTYPE_MASK | ASSOC_ARRAY_PTR_TYPE_MASK);
 }
 static inline
diff --git a/lib/assoc_array.c b/lib/assoc_array.c
index 2404d03..5b62033 100644
--- a/lib/assoc_array.c
+++ b/lib/assoc_array.c
@@ -37,12 +37,10 @@ begin_node:
if (assoc_array_ptr_is_shortcut(cursor)) {
/* Descend through a shortcut */
shortcut = assoc_array_ptr_to_shortcut(cursor);
-   smp_read_barrier_depends();
cursor = ACCESS_ONCE(shortcut-next_node);
}
 
node = assoc_array_ptr_to_node(cursor);
-   smp_read_barrier_depends();
slot = 0;
 
/* We perform two passes of each node.
@@ -85,7 +83,6 @@ begin_node:
 
 continue_node:
node = assoc_array_ptr_to_node(cursor);
-   smp_read_barrier_depends();
 
for (; slot  ASSOC_ARRAY_FAN_OUT; slot++) {
ptr = ACCESS_ONCE(node-slots[slot]);
@@ -104,7 +101,6 @@ finished_node:
 
if (assoc_array_ptr_is_shortcut(parent)) {
shortcut = assoc_array_ptr_to_shortcut(parent);
-   smp_read_barrier_depends();
cursor = parent;
parent = ACCESS_ONCE(shortcut-back_pointer);
slot = shortcut-parent_slot;
@@ -215,7 +211,6 @@ jumped:
 
 consider_node:
node = assoc_array_ptr_to_node(cursor);
-   smp_read_barrier_depends();
 
slot = segments  (level  ASSOC_ARRAY_KEY_CHUNK_MASK);
slot = ASSOC_ARRAY_FAN_MASK;
@@ -253,7 +248,6 @@ consider_node:
cursor = ptr;
 follow_shortcut:
shortcut = assoc_array_ptr_to_shortcut(cursor);
-   smp_read_barrier_depends();
pr_devel(shortcut to %d\n, shortcut-skip_to_level);
sc_level = level + ASSOC_ARRAY_LEVEL_STEP;
BUG_ON(sc_level  shortcut-skip_to_level);
@@ -343,7 +337,6 @@ void *assoc_array_find(const struct assoc_array *array,
 * actually going to dereference it.
 */
leaf = assoc_array_ptr_to_leaf(ptr);
-   smp_read_barrier_depends();
if (ops-compare_object(leaf, index_key))
return (void *)leaf;
}
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index 8177010..48d3464 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -683,7 +683,6 @@ descend_to_keyring:
 * doesn't contain any keyring pointers.
 */
shortcut = assoc_array_ptr_to_shortcut(ptr);
-   smp_read_barrier_depends();
if ((shortcut-index_key[0]  ASSOC_ARRAY_FAN_MASK) != 0)
goto not_this_keyring;
 
@@ -693,7 +692,6 @@ descend_to_keyring

[PATCH 08/16] rcupdate: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 include/linux/rcupdate.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index ed4f593..386ba28 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -582,11 +582,11 @@ static inline void rcu_preempt_sleep_check(void)
 })
 #define __rcu_dereference_check(p, c, space) \
 ({ \
-   typeof(*p) *_p1 = (typeof(*p) *__force)ACCESS_ONCE(p); \
+   /* Dependency order vs. p above. */ \
+   typeof(*p) *p1 = (typeof(*p) *__force)lockless_dereference(p); \
rcu_lockdep_assert(c, suspicious rcu_dereference_check() usage); \
rcu_dereference_sparse(p, space); \
-   smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
-   ((typeof(*p) __force __kernel *)(_p1)); \
+   ((typeof(*p) __force __kernel *)(p1)); \
 })
 #define __rcu_dereference_protected(p, c, space) \
 ({ \
@@ -603,10 +603,10 @@ static inline void rcu_preempt_sleep_check(void)
 })
 #define __rcu_dereference_index_check(p, c) \
 ({ \
-   typeof(p) _p1 = ACCESS_ONCE(p); \
+   /* Dependency order vs. p above. */ \
+   typeof(p) _p1 = lockless_dereference(p); \
rcu_lockdep_assert(c, \
   suspicious rcu_dereference_index_check() usage); \
-   smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
(_p1); \
 })
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 03/16] drivers: dma: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 drivers/dma/ioat/dma_v2.c | 3 +--
 drivers/dma/ioat/dma_v3.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/ioat/dma_v2.c b/drivers/dma/ioat/dma_v2.c
index 695483e..0f94d72 100644
--- a/drivers/dma/ioat/dma_v2.c
+++ b/drivers/dma/ioat/dma_v2.c
@@ -142,10 +142,9 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
 
active = ioat2_ring_active(ioat);
for (i = 0; i  active  !seen_current; i++) {
-   smp_read_barrier_depends();
prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
desc = ioat2_get_ring_ent(ioat, idx + i);
-   tx = desc-txd;
+   tx = lockless_dereference(desc)-txd;
dump_desc_dbg(ioat, desc);
if (tx-cookie) {
dma_descriptor_unmap(tx);
diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
index 895f869..cbd0537 100644
--- a/drivers/dma/ioat/dma_v3.c
+++ b/drivers/dma/ioat/dma_v3.c
@@ -389,7 +389,6 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
for (i = 0; i  active  !seen_current; i++) {
struct dma_async_tx_descriptor *tx;
 
-   smp_read_barrier_depends();
prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
desc = ioat2_get_ring_ent(ioat, idx + i);
dump_desc_dbg(ioat, desc);
@@ -398,7 +397,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, 
dma_addr_t phys_complete)
if (device-cap  IOAT_CAP_DWBES)
desc_get_errstat(ioat, desc);
 
-   tx = desc-txd;
+   tx = lockless_dereference(desc)-txd;
if (tx-cookie) {
dma_cookie_complete(tx);
dma_descriptor_unmap(tx);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/16] doc: memory-barriers.txt: Document use of lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 Documentation/memory-barriers.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/memory-barriers.txt 
b/Documentation/memory-barriers.txt
index 3d5f49b..841ac36 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -203,7 +203,7 @@ There are some minimal guarantees that may be expected of a 
CPU:
  and always in that order.  On most systems, smp_read_barrier_depends()
  does nothing, but it is required for DEC Alpha.  The ACCESS_ONCE()
  is required to prevent compiler mischief.  Please note that you
- should normally use something like rcu_dereference() instead of
+ should normally use something like lockless_dereference() instead of
  open-coding smp_read_barrier_depends().
 
  (*) Overlapping loads and stores within a particular CPU will appear to be
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 05/16] overlayfs: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 fs/overlayfs/super.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 08b704c..b0f050e 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -84,12 +84,10 @@ enum ovl_path_type ovl_path_type(struct dentry *dentry)
 
 static struct dentry *ovl_upperdentry_dereference(struct ovl_entry *oe)
 {
-   struct dentry *upperdentry = ACCESS_ONCE(oe-__upperdentry);
/*
 * Make sure to order reads to upperdentry wrt ovl_dentry_update()
 */
-   smp_read_barrier_depends();
-   return upperdentry;
+   return lockless_dereference(oe-__upperdentry);
 }
 
 void ovl_path_upper(struct dentry *dentry, struct path *path)
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 01/16] crypto: caam - Remove unnecessary smp_read_barrier_depends()

2014-11-13 Thread Pranith Kumar
Recently lockless_dereference() was added which can be used in place of
hard-coding smp_read_barrier_depends(). The following PATCH makes the change.

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 drivers/crypto/caam/jr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index bae20d8..9b3ef1bc 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -181,8 +181,6 @@ static void caam_jr_dequeue(unsigned long devarg)
for (i = 0; CIRC_CNT(head, tail + i, JOBR_DEPTH) = 1; i++) {
sw_idx = (tail + i)  (JOBR_DEPTH - 1);
 
-   smp_read_barrier_depends();
-
if (jrp-outring[hw_idx].desc ==
jrp-entinfo[sw_idx].desc_addr_dma)
break; /* found */
@@ -218,7 +216,6 @@ static void caam_jr_dequeue(unsigned long devarg)
if (sw_idx == tail) {
do {
tail = (tail + 1)  (JOBR_DEPTH - 1);
-   smp_read_barrier_depends();
} while (CIRC_CNT(head, tail, JOBR_DEPTH) = 1 
 jrp-entinfo[tail].desc_addr_dma == 0);
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 16/16] rxrpc: Replace smp_read_barrier_depends() with lockless_dereference()

2014-11-13 Thread Pranith Kumar
On 11/13/2014 03:47 PM, David Howells wrote:
 Pranith Kumar bobby.pr...@gmail.com wrote:
 
 Recently lockless_dereference() was added which can be used in place of
 hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
 
 Actually, the use of smp_read_barrier_depends() is wrong in circular
 buffering.  See Documentation/circular-buffers.txt
 

OK. Should I send in a patch removing these barriers then?

--
Pranith

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH] printk: Use ACCESS_ONCE() instead of a volatile type

2014-11-13 Thread Pranith Kumar
Remove volatile type qualifier and use ACCESS_ONCE() in its place for each
access. Using volatile is not recommended as documented in
Documentation/volatile-considered-harmful.txt.

Here logbuf_cpu is a local variable and it is not clear how it is being accessed
concurrently. We should remove volatile accesses entirely here, but for now make
a safer change of using ACCESS_ONCE().

Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
---
 kernel/printk/printk.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index e748971..4790191 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1624,7 +1624,7 @@ asmlinkage int vprintk_emit(int facility, int level,
int printed_len = 0;
bool in_sched = false;
/* cpu currently holding logbuf_lock in this function */
-   static volatile unsigned int logbuf_cpu = UINT_MAX;
+   static unsigned int logbuf_cpu = UINT_MAX;
 
if (level == LOGLEVEL_SCHED) {
level = LOGLEVEL_DEFAULT;
@@ -1641,7 +1641,7 @@ asmlinkage int vprintk_emit(int facility, int level,
/*
 * Ouch, printk recursed into itself!
 */
-   if (unlikely(logbuf_cpu == this_cpu)) {
+   if (unlikely(ACCESS_ONCE(logbuf_cpu) == this_cpu)) {
/*
 * If a crash is occurring during printk() on this CPU,
 * then try to get the crash message out but make sure
@@ -1659,7 +1659,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 
lockdep_off();
raw_spin_lock(logbuf_lock);
-   logbuf_cpu = this_cpu;
+   ACCESS_ONCE(logbuf_cpu) = this_cpu;
 
if (unlikely(recursion_bug)) {
static const char recursion_msg[] =
@@ -1754,7 +1754,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 dict, dictlen, text, text_len);
}
 
-   logbuf_cpu = UINT_MAX;
+   ACCESS_ONCE(logbuf_cpu) = UINT_MAX;
raw_spin_unlock(logbuf_lock);
lockdep_on();
local_irq_restore(flags);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH] printk: Use ACCESS_ONCE() instead of a volatile type

2014-11-13 Thread Pranith Kumar
On Thu, Nov 13, 2014 at 10:47 PM, Steven Rostedt rost...@goodmis.org wrote:
 On Thu, 13 Nov 2014 22:21:21 -0500
 Pranith Kumar bobby.pr...@gmail.com wrote:

 Remove volatile type qualifier and use ACCESS_ONCE() in its place for each
 access. Using volatile is not recommended as documented in
 Documentation/volatile-considered-harmful.txt.

 Here logbuf_cpu is a local variable and it is not clear how it is being 
 accessed
 concurrently. We should remove volatile accesses entirely here, but for now 
 make
 a safer change of using ACCESS_ONCE().

 I'm a little confused by the above paragraph about it's not clear how
 it is being accessed concurrently. Do you mean the code is unclear, or
 your understanding of it is unclear?

It is definitely got to do with my understanding. recursion explains
how it can be concurrently accessed. Thanks!


 Regardless of your answer, this patch is correct. logbuf_cpu is used to
 determine if printk has recursed on itself before it takes the
 logbuf_lock and deadlocks. Your ACCESS_ONCE keeps the compiler from
 optimizing out the logbuf_cpu as it will see that this function is the
 only one that can touch it and may try to do weird things to it.

 Reviewed-by: Steven Rostedt rost...@goodmis.org

 -- Steve



 Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
 ---
  kernel/printk/printk.c | 8 
  1 file changed, 4 insertions(+), 4 deletions(-)

 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
 index e748971..4790191 100644
 --- a/kernel/printk/printk.c
 +++ b/kernel/printk/printk.c
 @@ -1624,7 +1624,7 @@ asmlinkage int vprintk_emit(int facility, int level,
   int printed_len = 0;
   bool in_sched = false;
   /* cpu currently holding logbuf_lock in this function */
 - static volatile unsigned int logbuf_cpu = UINT_MAX;
 + static unsigned int logbuf_cpu = UINT_MAX;

   if (level == LOGLEVEL_SCHED) {
   level = LOGLEVEL_DEFAULT;
 @@ -1641,7 +1641,7 @@ asmlinkage int vprintk_emit(int facility, int level,
   /*
* Ouch, printk recursed into itself!
*/
 - if (unlikely(logbuf_cpu == this_cpu)) {
 + if (unlikely(ACCESS_ONCE(logbuf_cpu) == this_cpu)) {
   /*
* If a crash is occurring during printk() on this CPU,
* then try to get the crash message out but make sure
 @@ -1659,7 +1659,7 @@ asmlinkage int vprintk_emit(int facility, int level,

   lockdep_off();
   raw_spin_lock(logbuf_lock);
 - logbuf_cpu = this_cpu;
 + ACCESS_ONCE(logbuf_cpu) = this_cpu;

   if (unlikely(recursion_bug)) {
   static const char recursion_msg[] =
 @@ -1754,7 +1754,7 @@ asmlinkage int vprintk_emit(int facility, int level,
dict, dictlen, text, 
 text_len);
   }

 - logbuf_cpu = UINT_MAX;
 + ACCESS_ONCE(logbuf_cpu) = UINT_MAX;
   raw_spin_unlock(logbuf_lock);
   lockdep_on();
   local_irq_restore(flags);




-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 0/6] Torture-test changes for 3.19

2014-10-29 Thread Pranith Kumar
On Tue, Oct 28, 2014 at 6:29 PM, Paul E. McKenney
 wrote:
> Hello!
>
> This series provides torture-testing updates:
>
> 1.  Run the Linux-kernel binary out of the results directory,
> easing re-runs.
>
> 2.  Add early-boot callback-posting self-tests for RCU, courtesy
> of Pranith Kumar.
>
> 3.  Enable early-boot callback-posting self-tests in rcutorture,
> courtesy of Pranith Kumar.
>
> 4.  Remove old-version rcutorture configuration files, courtesy
> of Pranith Kumar.
>
> 5.  Remove the --kversion parameter to kvm.sh, courtesy of Pranith
> Kumar.
>
> 6.  Fix rcu_torture_cbflood() memory leak.


For 1 and 6:

Reviewed-by: Pranith Kumar 

>
> Thanx, Paul
>
> 
>
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/CFLIST 
>|   14 -
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N1-S-T-NH-SD-SMP-HP
>|   18 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N2-2-t-nh-sd-SMP-hp
>|   20 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N3-3-T-nh-SD-SMP-hp
>|   22 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N4-A-t-NH-sd-SMP-HP
>|   18 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N5-U-T-NH-sd-SMP-hp
>|   22 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/NT1-nh 
>|   23 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/NT3-NH 
>|   20 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P1-S-T-NH-SD-SMP-HP
>|   19 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P2-2-t-nh-sd-SMP-hp
>|   20 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P3-3-T-nh-SD-SMP-hp
>|   20 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P4-A-t-NH-sd-SMP-HP
>|   22 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P5-U-T-NH-sd-SMP-hp
>|   27 ---
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/PT1-nh 
>|   23 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/PT2-NH 
>|   22 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/ver_functions.sh   
>|   33 ---
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/CFLIST
>|   17 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N1-S-T-NH-SD-SMP-HP   
>|   19 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N2-2-t-nh-sd-SMP-hp   
>|   20 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N3-3-T-nh-SD-SMP-hp   
>|   22 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N4-A-t-NH-sd-SMP-HP   
>|   18 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N5-U-T-NH-sd-SMP-hp   
>|   22 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N6---t-nh-SD-smp-hp   
>|   19 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N7-4-T-NH-SD-SMP-HP   
>|   26 ---
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N8-2-T-NH-SD-SMP-HP   
>|   22 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/NT1-nh
>|   23 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/NT3-NH
>|   20 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P1-S-T-NH-SD-SMP-HP   
>|   20 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P2-2-t-nh-sd-SMP-hp   
>|   20 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P3-3-T-nh-SD-SMP-hp   
>|   20 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P4-A-t-NH-sd-SMP-HP   
>|   22 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P5-U-T-NH-sd-SMP-hp   
>|   27 ---
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P6---t-nh-SD-smp-hp   
>|   18 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP   
>|   30 ---
>  
> a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP-all
>   |   30 ---
>  
> a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP-none
>  |   30 ---
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-hp   
>|   30 ---
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/PT1-nh
>|   23 --
>  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/PT2-NH
>|   22 --
>  a/tools/testing/selftests/rcutorture/confi

Re: [PATCH tip/core/rcu 0/5] Documentation updates for 3.19

2014-10-29 Thread Pranith Kumar
On Tue, Oct 28, 2014 at 5:59 PM, Paul E. McKenney
 wrote:
> Hello!
>
> This series contains a few documentation updates:
>
> 1.  Records limitations of bitfields and small variables.
> Also rules out pre-EV56 Alpha, which lack 8- and 16-bit
> memory-reference instructions.  Later Alpha CPUs are OK.
> (The official Alpha maintainers have thus far been silent
> on this patch.)
>
> 2.  Document the new RCU self-test boot parameters, courtesy of
> Pranith Kumar.
>
> 3.  Records that short-circuit boolean evaluation does not necessarily
> defend against control-dependency breakage by compiler optimizations.
>
> 4.  Add mention of atomic_long_t to atomic_ops.txt.
>
> 5.  Fix an example in memory-barriers.txt, courtesy of Pranith Kumar.


Reviewed-by: Pranith Kumar 

>
> Thanx, Paul
>
> 
>
>  b/Documentation/atomic_ops.txt|   12 +++--
>  b/Documentation/kernel-parameters.txt |9 
>  b/Documentation/memory-barriers.txt   |   71 
> --
>  3 files changed, 77 insertions(+), 15 deletions(-)
>



-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 10/10] cpu: Avoid puts_pending overflow

2014-10-29 Thread Pranith Kumar
On Tue, Oct 28, 2014 at 5:53 PM, Paul E. McKenney
 wrote:
> From: "Paul E. McKenney" 
>
> A long string of get_online_cpus() with each followed by a
> put_online_cpu() that fails to acquire cpu_hotplug.lock can result in
> overflow of the cpu_hotplug.puts_pending counter.  Although this is
> perhaps improbably, a system with absolutely no CPU-hotplug operations
> will have an arbitrarily long time in which this overflow could occur.
> This commit therefore adds overflow checks to get_online_cpus() and
> try_get_online_cpus().
>
> Signed-off-by: Paul E. McKenney 

This patch seems to be missing in the cover letter.

Reviewed-by: Pranith Kumar 

> ---
>  kernel/cpu.c | 19 +--
>  1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/cpu.c b/kernel/cpu.c
> index 90a3d017b90c..5d220234b3ca 100644
> --- a/kernel/cpu.c
> +++ b/kernel/cpu.c
> @@ -86,6 +86,16 @@ static struct {
>  #define cpuhp_lock_acquire()  lock_map_acquire(_hotplug.dep_map)
>  #define cpuhp_lock_release()  lock_map_release(_hotplug.dep_map)
>
> +static void apply_puts_pending(int max)
> +{
> +   int delta;
> +
> +   if (atomic_read(_hotplug.puts_pending) >= max) {
> +   delta = atomic_xchg(_hotplug.puts_pending, 0);
> +   cpu_hotplug.refcount -= delta;
> +   }
> +}
> +
>  void get_online_cpus(void)
>  {
> might_sleep();
> @@ -93,6 +103,7 @@ void get_online_cpus(void)
> return;
> cpuhp_lock_acquire_read();
> mutex_lock(_hotplug.lock);
> +   apply_puts_pending(65536);
> cpu_hotplug.refcount++;
> mutex_unlock(_hotplug.lock);
>  }
> @@ -105,6 +116,7 @@ bool try_get_online_cpus(void)
> if (!mutex_trylock(_hotplug.lock))
> return false;
> cpuhp_lock_acquire_tryread();
> +   apply_puts_pending(65536);
> cpu_hotplug.refcount++;
> mutex_unlock(_hotplug.lock);
> return true;
> @@ -161,12 +173,7 @@ void cpu_hotplug_begin(void)
> cpuhp_lock_acquire();
> for (;;) {
> mutex_lock(_hotplug.lock);
> -   if (atomic_read(_hotplug.puts_pending)) {
> -   int delta;
> -
> -   delta = atomic_xchg(_hotplug.puts_pending, 0);
> -   cpu_hotplug.refcount -= delta;
> -   }
> +   apply_puts_pending(1);
> if (likely(!cpu_hotplug.refcount))
> break;
> __set_current_state(TASK_UNINTERRUPTIBLE);
> --
> 1.8.1.5
>



-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 0/9] Per-CPU-variable updates

2014-10-29 Thread Pranith Kumar
On Tue, Oct 28, 2014 at 5:51 PM, Paul E. McKenney
 wrote:
> Hello!
>
> This series updates RCU's handling of per-CPU variables, mostly
> moving from "cpu" function arguments to various "this_"-style accessors
> for per-CPU variables:
>
> 1.  Drop the rdtp argument from RCU's dyntick-idle and sysidle
> functions, substituting this_cpu_ptr(), courtesy of Christoph
> Lameter.
>
> 2.  Use DEFINE_PER_CPU_SHARED_ALIGNED for rcu_data structures in
> order to avoid false sharing with other per-CPU variables.
>
> 3-9.Remove "cpu" arguments from a number of RCU functions that are
> only ever invoked on that CPU, and use appropriate "this_"-style
> accesssors for the per-CPU variables.
>

Reviewd-by: Pranith Kumar 


> Thanx, Paul
>
> 
>
>  b/include/linux/rcupdate.h |2 +-
>  b/include/linux/rcutiny.h  |2 +-
>  b/include/linux/rcutree.h  |4 ++--
>  b/kernel/cpu.c |   19 +--
>  b/kernel/rcu/tiny.c|2 +-
>  b/kernel/rcu/tree.c|   25 +
>  b/kernel/rcu/tree.h|4 ++--
>  b/kernel/rcu/tree_plugin.h |   11 +++
>  b/kernel/sched/core.c  |2 +-
>  b/kernel/softirq.c |2 +-
>  b/kernel/time/tick-sched.c |2 +-
>  b/kernel/time/timer.c  |3 +--
>  include/linux/rcupdate.h   |2 +-
>  include/linux/rcutree.h|2 +-
>  kernel/rcu/tree.c  |   30 +++---
>  kernel/rcu/tree.h  |8 
>  kernel/rcu/tree_plugin.h   |   42 +-
>  17 files changed, 86 insertions(+), 76 deletions(-)
>



-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 0/9] Per-CPU-variable updates

2014-10-29 Thread Pranith Kumar
On Tue, Oct 28, 2014 at 5:51 PM, Paul E. McKenney
paul...@linux.vnet.ibm.com wrote:
 Hello!

 This series updates RCU's handling of per-CPU variables, mostly
 moving from cpu function arguments to various this_-style accessors
 for per-CPU variables:

 1.  Drop the rdtp argument from RCU's dyntick-idle and sysidle
 functions, substituting this_cpu_ptr(), courtesy of Christoph
 Lameter.

 2.  Use DEFINE_PER_CPU_SHARED_ALIGNED for rcu_data structures in
 order to avoid false sharing with other per-CPU variables.

 3-9.Remove cpu arguments from a number of RCU functions that are
 only ever invoked on that CPU, and use appropriate this_-style
 accesssors for the per-CPU variables.


Reviewd-by: Pranith Kumar bobby.pr...@gmail.com


 Thanx, Paul

 

  b/include/linux/rcupdate.h |2 +-
  b/include/linux/rcutiny.h  |2 +-
  b/include/linux/rcutree.h  |4 ++--
  b/kernel/cpu.c |   19 +--
  b/kernel/rcu/tiny.c|2 +-
  b/kernel/rcu/tree.c|   25 +
  b/kernel/rcu/tree.h|4 ++--
  b/kernel/rcu/tree_plugin.h |   11 +++
  b/kernel/sched/core.c  |2 +-
  b/kernel/softirq.c |2 +-
  b/kernel/time/tick-sched.c |2 +-
  b/kernel/time/timer.c  |3 +--
  include/linux/rcupdate.h   |2 +-
  include/linux/rcutree.h|2 +-
  kernel/rcu/tree.c  |   30 +++---
  kernel/rcu/tree.h  |8 
  kernel/rcu/tree_plugin.h   |   42 +-
  17 files changed, 86 insertions(+), 76 deletions(-)




-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 10/10] cpu: Avoid puts_pending overflow

2014-10-29 Thread Pranith Kumar
On Tue, Oct 28, 2014 at 5:53 PM, Paul E. McKenney
paul...@linux.vnet.ibm.com wrote:
 From: Paul E. McKenney paul...@linux.vnet.ibm.com

 A long string of get_online_cpus() with each followed by a
 put_online_cpu() that fails to acquire cpu_hotplug.lock can result in
 overflow of the cpu_hotplug.puts_pending counter.  Although this is
 perhaps improbably, a system with absolutely no CPU-hotplug operations
 will have an arbitrarily long time in which this overflow could occur.
 This commit therefore adds overflow checks to get_online_cpus() and
 try_get_online_cpus().

 Signed-off-by: Paul E. McKenney paul...@linux.vnet.ibm.com

This patch seems to be missing in the cover letter.

Reviewed-by: Pranith Kumar bobby.pr...@gmail.com

 ---
  kernel/cpu.c | 19 +--
  1 file changed, 13 insertions(+), 6 deletions(-)

 diff --git a/kernel/cpu.c b/kernel/cpu.c
 index 90a3d017b90c..5d220234b3ca 100644
 --- a/kernel/cpu.c
 +++ b/kernel/cpu.c
 @@ -86,6 +86,16 @@ static struct {
  #define cpuhp_lock_acquire()  lock_map_acquire(cpu_hotplug.dep_map)
  #define cpuhp_lock_release()  lock_map_release(cpu_hotplug.dep_map)

 +static void apply_puts_pending(int max)
 +{
 +   int delta;
 +
 +   if (atomic_read(cpu_hotplug.puts_pending) = max) {
 +   delta = atomic_xchg(cpu_hotplug.puts_pending, 0);
 +   cpu_hotplug.refcount -= delta;
 +   }
 +}
 +
  void get_online_cpus(void)
  {
 might_sleep();
 @@ -93,6 +103,7 @@ void get_online_cpus(void)
 return;
 cpuhp_lock_acquire_read();
 mutex_lock(cpu_hotplug.lock);
 +   apply_puts_pending(65536);
 cpu_hotplug.refcount++;
 mutex_unlock(cpu_hotplug.lock);
  }
 @@ -105,6 +116,7 @@ bool try_get_online_cpus(void)
 if (!mutex_trylock(cpu_hotplug.lock))
 return false;
 cpuhp_lock_acquire_tryread();
 +   apply_puts_pending(65536);
 cpu_hotplug.refcount++;
 mutex_unlock(cpu_hotplug.lock);
 return true;
 @@ -161,12 +173,7 @@ void cpu_hotplug_begin(void)
 cpuhp_lock_acquire();
 for (;;) {
 mutex_lock(cpu_hotplug.lock);
 -   if (atomic_read(cpu_hotplug.puts_pending)) {
 -   int delta;
 -
 -   delta = atomic_xchg(cpu_hotplug.puts_pending, 0);
 -   cpu_hotplug.refcount -= delta;
 -   }
 +   apply_puts_pending(1);
 if (likely(!cpu_hotplug.refcount))
 break;
 __set_current_state(TASK_UNINTERRUPTIBLE);
 --
 1.8.1.5




-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 0/5] Documentation updates for 3.19

2014-10-29 Thread Pranith Kumar
On Tue, Oct 28, 2014 at 5:59 PM, Paul E. McKenney
paul...@linux.vnet.ibm.com wrote:
 Hello!

 This series contains a few documentation updates:

 1.  Records limitations of bitfields and small variables.
 Also rules out pre-EV56 Alpha, which lack 8- and 16-bit
 memory-reference instructions.  Later Alpha CPUs are OK.
 (The official Alpha maintainers have thus far been silent
 on this patch.)

 2.  Document the new RCU self-test boot parameters, courtesy of
 Pranith Kumar.

 3.  Records that short-circuit boolean evaluation does not necessarily
 defend against control-dependency breakage by compiler optimizations.

 4.  Add mention of atomic_long_t to atomic_ops.txt.

 5.  Fix an example in memory-barriers.txt, courtesy of Pranith Kumar.


Reviewed-by: Pranith Kumar bobby.pr...@gmail.com


 Thanx, Paul

 

  b/Documentation/atomic_ops.txt|   12 +++--
  b/Documentation/kernel-parameters.txt |9 
  b/Documentation/memory-barriers.txt   |   71 
 --
  3 files changed, 77 insertions(+), 15 deletions(-)




-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 0/6] Torture-test changes for 3.19

2014-10-29 Thread Pranith Kumar
On Tue, Oct 28, 2014 at 6:29 PM, Paul E. McKenney
paul...@linux.vnet.ibm.com wrote:
 Hello!

 This series provides torture-testing updates:

 1.  Run the Linux-kernel binary out of the results directory,
 easing re-runs.

 2.  Add early-boot callback-posting self-tests for RCU, courtesy
 of Pranith Kumar.

 3.  Enable early-boot callback-posting self-tests in rcutorture,
 courtesy of Pranith Kumar.

 4.  Remove old-version rcutorture configuration files, courtesy
 of Pranith Kumar.

 5.  Remove the --kversion parameter to kvm.sh, courtesy of Pranith
 Kumar.

 6.  Fix rcu_torture_cbflood() memory leak.


For 1 and 6:

Reviewed-by: Pranith Kumar bobby.pr...@gmail.com


 Thanx, Paul

 

  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/CFLIST 
|   14 -
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N1-S-T-NH-SD-SMP-HP
|   18 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N2-2-t-nh-sd-SMP-hp
|   20 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N3-3-T-nh-SD-SMP-hp
|   22 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N4-A-t-NH-sd-SMP-HP
|   18 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N5-U-T-NH-sd-SMP-hp
|   22 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/NT1-nh 
|   23 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/NT3-NH 
|   20 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P1-S-T-NH-SD-SMP-HP
|   19 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P2-2-t-nh-sd-SMP-hp
|   20 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P3-3-T-nh-SD-SMP-hp
|   20 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P4-A-t-NH-sd-SMP-HP
|   22 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P5-U-T-NH-sd-SMP-hp
|   27 ---
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/PT1-nh 
|   23 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/PT2-NH 
|   22 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v0.0/ver_functions.sh   
|   33 ---
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/CFLIST
|   17 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N1-S-T-NH-SD-SMP-HP   
|   19 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N2-2-t-nh-sd-SMP-hp   
|   20 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N3-3-T-nh-SD-SMP-hp   
|   22 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N4-A-t-NH-sd-SMP-HP   
|   18 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N5-U-T-NH-sd-SMP-hp   
|   22 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N6---t-nh-SD-smp-hp   
|   19 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N7-4-T-NH-SD-SMP-HP   
|   26 ---
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N8-2-T-NH-SD-SMP-HP   
|   22 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/NT1-nh
|   23 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/NT3-NH
|   20 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P1-S-T-NH-SD-SMP-HP   
|   20 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P2-2-t-nh-sd-SMP-hp   
|   20 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P3-3-T-nh-SD-SMP-hp   
|   20 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P4-A-t-NH-sd-SMP-HP   
|   22 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P5-U-T-NH-sd-SMP-hp   
|   27 ---
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P6---t-nh-SD-smp-hp   
|   18 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP   
|   30 ---
  
 a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP-all
   |   30 ---
  
 a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP-none
  |   30 ---
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-hp   
|   30 ---
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/PT1-nh
|   23 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.12/PT2-NH
|   22 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.3/CFLIST 
|   14 -
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N1-S-T-NH-SD-SMP-HP
|   19 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N2-2-t-nh-sd-SMP-hp
|   20 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N3-3-T-nh-SD-SMP-hp
|   22 --
  a/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N4

Re: [PATCH tip/core/rcu 0/2] Signal-related changes for 3.19

2014-10-28 Thread Pranith Kumar
On Tue, Oct 28, 2014 at 6:13 PM, Paul E. McKenney
 wrote:
> Hello!
>
> This series updates RCU handling in signals:
>
> 1.  Prevents a possible very long RCU read-side critical section
> in kill_pid_info().
>
> 2.  Explain why the "obviously buggy" freeing of sighand by
> __cleanup_sighand() without an RCU grace period really isn't
> buggy, courtesy of Oleg Nesterov.


Reviewed-by: Pranith Kumar 

>
> Thanx, Paul
>
> 
>
>  b/kernel/fork.c   |5 -
>  b/kernel/signal.c |   42 +-
>  2 files changed, 29 insertions(+), 18 deletions(-)
>



-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH tip/core/rcu 0/2] Signal-related changes for 3.19

2014-10-28 Thread Pranith Kumar
On Tue, Oct 28, 2014 at 6:13 PM, Paul E. McKenney
paul...@linux.vnet.ibm.com wrote:
 Hello!

 This series updates RCU handling in signals:

 1.  Prevents a possible very long RCU read-side critical section
 in kill_pid_info().

 2.  Explain why the obviously buggy freeing of sighand by
 __cleanup_sighand() without an RCU grace period really isn't
 buggy, courtesy of Oleg Nesterov.


Reviewed-by: Pranith Kumar bobby.pr...@gmail.com


 Thanx, Paul

 

  b/kernel/fork.c   |5 -
  b/kernel/signal.c |   42 +-
  2 files changed, 29 insertions(+), 18 deletions(-)




-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] cmpxchg: Discard unnecessary cast to volatile

2014-10-21 Thread Pranith Kumar
On Tue, Oct 21, 2014 at 11:48 AM, H. Peter Anvin  wrote:
> On 10/21/2014 03:14 AM, Peter Zijlstra wrote:
>> On Mon, Oct 20, 2014 at 04:22:27PM -0400, Pranith Kumar wrote:
>>>> Generating a volatile pointer is really not necessary here. This is the 
>>>> only
>>>> location where a volatile pointer is being generated for use in asm.
>>>>
>>>> This commit removes the unnecessary volatile pointer being created.
>>>>
>>>> Signed-off-by: Pranith Kumar 
>>
>> Seems sane enough to me.
>>
>
> However, it seems like unnecessary churn.  Does the volatile hurt in any
> way?

Removing 4 lines of unnecessary code seems to be worthwhile to me.
Also, we reduce the unnecessary use of 'volatile' data types which
IMHO makes this a good little clean up.

I am not sure if the use of volatile actually causes any loss of
chances of optimization. I've tried to come up with cases where this
happens and was unsuccessful.

-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] cmpxchg: Discard unnecessary cast to volatile

2014-10-21 Thread Pranith Kumar
On Tue, Oct 21, 2014 at 11:48 AM, H. Peter Anvin h...@zytor.com wrote:
 On 10/21/2014 03:14 AM, Peter Zijlstra wrote:
 On Mon, Oct 20, 2014 at 04:22:27PM -0400, Pranith Kumar wrote:
 Generating a volatile pointer is really not necessary here. This is the 
 only
 location where a volatile pointer is being generated for use in asm.

 This commit removes the unnecessary volatile pointer being created.

 Signed-off-by: Pranith Kumar bobby.pr...@gmail.com

 Seems sane enough to me.


 However, it seems like unnecessary churn.  Does the volatile hurt in any
 way?

Removing 4 lines of unnecessary code seems to be worthwhile to me.
Also, we reduce the unnecessary use of 'volatile' data types which
IMHO makes this a good little clean up.

I am not sure if the use of volatile actually causes any loss of
chances of optimization. I've tried to come up with cases where this
happens and was unsuccessful.

-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] cmpxchg: Discard unnecessary cast to volatile

2014-10-20 Thread Pranith Kumar
ping.

On Wed, Oct 1, 2014 at 1:57 PM, Pranith Kumar  wrote:
> Generating a volatile pointer is really not necessary here. This is the only
> location where a volatile pointer is being generated for use in asm.
>
> This commit removes the unnecessary volatile pointer being created.
>
> Signed-off-by: Pranith Kumar 
> ---
>  arch/x86/include/asm/cmpxchg.h | 12 
>  1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
> index 99c105d7..f0baea8 100644
> --- a/arch/x86/include/asm/cmpxchg.h
> +++ b/arch/x86/include/asm/cmpxchg.h
> @@ -90,36 +90,32 @@ extern void __add_wrong_size(void)
> switch (size) { \
> case __X86_CASE_B:  \
> {   \
> -   volatile u8 *__ptr = (volatile u8 *)(ptr);  \
> asm volatile(lock "cmpxchgb %2,%1"  \
> -: "=a" (__ret), "+m" (*__ptr)  \
> +: "=a" (__ret), "+m" (*ptr)\
>  : "q" (__new), "0" (__old) \
>  : "memory");   \
> break;  \
> }   \
> case __X86_CASE_W:  \
> {   \
> -   volatile u16 *__ptr = (volatile u16 *)(ptr);\
> asm volatile(lock "cmpxchgw %2,%1"  \
> -: "=a" (__ret), "+m" (*__ptr)  \
> +: "=a" (__ret), "+m" (*ptr)\
>  : "r" (__new), "0" (__old) \
>  : "memory");   \
> break;  \
> }   \
> case __X86_CASE_L:  \
> {   \
> -   volatile u32 *__ptr = (volatile u32 *)(ptr);\
> asm volatile(lock "cmpxchgl %2,%1"  \
> -: "=a" (__ret), "+m" (*__ptr)  \
> +: "=a" (__ret), "+m" (*ptr)\
>  : "r" (__new), "0" (__old) \
>  : "memory");   \
> break;  \
> }   \
> case __X86_CASE_Q:  \
> {   \
> -   volatile u64 *__ptr = (volatile u64 *)(ptr);\
> asm volatile(lock "cmpxchgq %2,%1"  \
> -: "=a" (__ret), "+m" (*__ptr)  \
> +: "=a" (__ret), "+m" (*ptr)\
>  : "r" (__new), "0" (__old) \
>  : "memory");   \
> break;  \
> --
> 1.9.1
>



-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] cmpxchg: Discard unnecessary cast to volatile

2014-10-20 Thread Pranith Kumar
ping.

On Wed, Oct 1, 2014 at 1:57 PM, Pranith Kumar bobby.pr...@gmail.com wrote:
 Generating a volatile pointer is really not necessary here. This is the only
 location where a volatile pointer is being generated for use in asm.

 This commit removes the unnecessary volatile pointer being created.

 Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
 ---
  arch/x86/include/asm/cmpxchg.h | 12 
  1 file changed, 4 insertions(+), 8 deletions(-)

 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
 index 99c105d7..f0baea8 100644
 --- a/arch/x86/include/asm/cmpxchg.h
 +++ b/arch/x86/include/asm/cmpxchg.h
 @@ -90,36 +90,32 @@ extern void __add_wrong_size(void)
 switch (size) { \
 case __X86_CASE_B:  \
 {   \
 -   volatile u8 *__ptr = (volatile u8 *)(ptr);  \
 asm volatile(lock cmpxchgb %2,%1  \
 -: =a (__ret), +m (*__ptr)  \
 +: =a (__ret), +m (*ptr)\
  : q (__new), 0 (__old) \
  : memory);   \
 break;  \
 }   \
 case __X86_CASE_W:  \
 {   \
 -   volatile u16 *__ptr = (volatile u16 *)(ptr);\
 asm volatile(lock cmpxchgw %2,%1  \
 -: =a (__ret), +m (*__ptr)  \
 +: =a (__ret), +m (*ptr)\
  : r (__new), 0 (__old) \
  : memory);   \
 break;  \
 }   \
 case __X86_CASE_L:  \
 {   \
 -   volatile u32 *__ptr = (volatile u32 *)(ptr);\
 asm volatile(lock cmpxchgl %2,%1  \
 -: =a (__ret), +m (*__ptr)  \
 +: =a (__ret), +m (*ptr)\
  : r (__new), 0 (__old) \
  : memory);   \
 break;  \
 }   \
 case __X86_CASE_Q:  \
 {   \
 -   volatile u64 *__ptr = (volatile u64 *)(ptr);\
 asm volatile(lock cmpxchgq %2,%1  \
 -: =a (__ret), +m (*__ptr)  \
 +: =a (__ret), +m (*ptr)\
  : r (__new), 0 (__old) \
  : memory);   \
 break;  \
 --
 1.9.1




-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3.13, 3.14, 3.16, 3.17] rcu: Reduce rcu kthread wakeups

2014-10-13 Thread Pranith Kumar
On Mon, Oct 13, 2014 at 4:01 PM, Kamal Mostafa  wrote:
> On Mon, 2014-10-13 at 12:29 -0400, Pranith Kumar wrote:
>> Backport 2aa792e and parts of 48a7639 to 3.13 which is Ubuntu LTS kernel.
>>
>> This commit reduces the number of rcu kthread wakeups. Tested for over a 
>> week on
>> my desktop 14.04 system.
>>
>> Signed-off-by: Pranith Kumar 
>> CC: Paul E. McKenney 
>
>
> Hi Pranith and Paul-
>
> This looks good, but how about lets split it back into two commits (the
> second a clean cherry-pick) and submit it for 3.{14,16,17}-stable also:
>
> 3.13 and 3.14 could apply the attached 48a7639 mini-backport (just
> supplying rcu_gp_kthread_wake), and then cherry-pick 2aa792e.
>
> 3.16 and 3.17 carry 48a7639 already, so could just cherry-pick 2aa792e.
>

The patch looks good. The commit message can be trimmed to just the last para:

Add a new rcu_gp_kthread_wake() which wakes up the gp kthread when it
is necessary and safe to do so: No self-wakes, no wake-ups if the
->gp_flags field indicates there is no need (as in someone else did
the wake-up before we got around to it),  and no wake-ups before the
grace-period kthread has been created.

Thanks!
-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3.13, 3.14, 3.16, 3.17] rcu: Reduce rcu kthread wakeups

2014-10-13 Thread Pranith Kumar
On Mon, Oct 13, 2014 at 4:01 PM, Kamal Mostafa ka...@canonical.com wrote:
 On Mon, 2014-10-13 at 12:29 -0400, Pranith Kumar wrote:
 Backport 2aa792e and parts of 48a7639 to 3.13 which is Ubuntu LTS kernel.

 This commit reduces the number of rcu kthread wakeups. Tested for over a 
 week on
 my desktop 14.04 system.

 Signed-off-by: Pranith Kumar bobby.pr...@gmail.com
 CC: Paul E. McKenney paul...@linux.vnet.ibm.com


 Hi Pranith and Paul-

 This looks good, but how about lets split it back into two commits (the
 second a clean cherry-pick) and submit it for 3.{14,16,17}-stable also:

 3.13 and 3.14 could apply the attached 48a7639 mini-backport (just
 supplying rcu_gp_kthread_wake), and then cherry-pick 2aa792e.

 3.16 and 3.17 carry 48a7639 already, so could just cherry-pick 2aa792e.


The patch looks good. The commit message can be trimmed to just the last para:

Add a new rcu_gp_kthread_wake() which wakes up the gp kthread when it
is necessary and safe to do so: No self-wakes, no wake-ups if the
-gp_flags field indicates there is no need (as in someone else did
the wake-up before we got around to it),  and no wake-ups before the
grace-period kthread has been created.

Thanks!
-- 
Pranith
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] powerpc: Wire up sys_bpf() syscall

2014-10-09 Thread Pranith Kumar
This patch wires up the new syscall sys_bpf() on powerpc.

Signed-off-by: Pranith Kumar 
---
 arch/powerpc/include/asm/systbl.h  | 1 +
 arch/powerpc/include/asm/unistd.h  | 2 +-
 arch/powerpc/include/uapi/asm/unistd.h | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/systbl.h 
b/arch/powerpc/include/asm/systbl.h
index 7d8a600..ce9577d 100644
--- a/arch/powerpc/include/asm/systbl.h
+++ b/arch/powerpc/include/asm/systbl.h
@@ -365,3 +365,4 @@ SYSCALL_SPU(renameat2)
 SYSCALL_SPU(seccomp)
 SYSCALL_SPU(getrandom)
 SYSCALL_SPU(memfd_create)
+SYSCALL_SPU(bpf)
diff --git a/arch/powerpc/include/asm/unistd.h 
b/arch/powerpc/include/asm/unistd.h
index 4e9af3f..e0da021 100644
--- a/arch/powerpc/include/asm/unistd.h
+++ b/arch/powerpc/include/asm/unistd.h
@@ -12,7 +12,7 @@
 #include 
 
 
-#define __NR_syscalls  361
+#define __NR_syscalls  362
 
 #define __NR__exit __NR_exit
 #define NR_syscalls__NR_syscalls
diff --git a/arch/powerpc/include/uapi/asm/unistd.h 
b/arch/powerpc/include/uapi/asm/unistd.h
index 0688fc0..f55351f 100644
--- a/arch/powerpc/include/uapi/asm/unistd.h
+++ b/arch/powerpc/include/uapi/asm/unistd.h
@@ -383,5 +383,6 @@
 #define __NR_seccomp   358
 #define __NR_getrandom 359
 #define __NR_memfd_create  360
+#define __NR_bpf   361
 
 #endif /* _UAPI_ASM_POWERPC_UNISTD_H_ */
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] networking: fm10k: Fix build failure

2014-10-09 Thread Pranith Kumar
The latest linus git tip (3.18-rc1) fails with the following build failure. Fix
this by making PTP support explicit for fm10k driver.

rivers/built-in.o: In function `fm10k_ptp_register':
(.text+0x12e760): undefined reference to `ptp_clock_registER'
drivers/built-in.o: In function `fm10k_ptp_unregister':
(.text+0x12e7dc): undefined reference to `ptp_clock_unregister'
Makefile:930: recipe for target 'vmlinux' failed

Signed-off-by: Pranith Kumar 
---
 drivers/net/ethernet/intel/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/intel/Kconfig 
b/drivers/net/ethernet/intel/Kconfig
index 6a6d5ee..6919adb 100644
--- a/drivers/net/ethernet/intel/Kconfig
+++ b/drivers/net/ethernet/intel/Kconfig
@@ -304,6 +304,7 @@ config FM10K
tristate "Intel(R) FM1 Ethernet Switch Host Interface Support"
default n
depends on PCI_MSI
+   select PTP_1588_CLOCK
---help---
  This driver supports Intel(R) FM1 Ethernet Switch Host
  Interface.  For more information on how to identify your adapter,
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] networking: fm10k: Fix build failure

2014-10-09 Thread Pranith Kumar
The latest linus git tip (3.18-rc1) fails with the following build failure. Fix
this by making PTP support explicit for fm10k driver.

rivers/built-in.o: In function `fm10k_ptp_register':
(.text+0x12e760): undefined reference to `ptp_clock_registER'
drivers/built-in.o: In function `fm10k_ptp_unregister':
(.text+0x12e7dc): undefined reference to `ptp_clock_unregister'
Makefile:930: recipe for target 'vmlinux' failed

Signed-off-by: Pranith Kumar 
---
 drivers/net/ethernet/intel/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/Kconfig 
b/drivers/net/ethernet/intel/Kconfig
index 6a6d5ee..281d998 100644
--- a/drivers/net/ethernet/intel/Kconfig
+++ b/drivers/net/ethernet/intel/Kconfig
@@ -303,7 +303,7 @@ config I40EVF
 config FM10K
tristate "Intel(R) FM1 Ethernet Switch Host Interface Support"
default n
-   depends on PCI_MSI
+   depends on PCI_MSI && PTP_1588_CLOCK
---help---
  This driver supports Intel(R) FM1 Ethernet Switch Host
  Interface.  For more information on how to identify your adapter,
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


<    1   2   3   4   5   6   7   8   9   10   >