linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: nfs: Fix a sleep-in-atomic bug in nfs_access_add_cache
@ 2017-06-05  8:05 Jia-Ju Bai
  2017-06-05 11:48 ` Trond Myklebust
  0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2017-06-05  8:05 UTC (permalink / raw)
  To: trond.myklebust, anna.schumaker; +Cc: linux-nfs, linux-kernel, Jia-Ju Bai

The driver may sleep under a rcu read lock, and function call path is:
nfs_permission (acquire the lock by rcu_read_lock)
  nfs_do_access
    nfs_access_add_cache
      kmalloc(GFP_KERNEL) --> may sleep

To fix it, "GFP_KERNEL" is replaced with "GFP_ATOMIC".

Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
---
 fs/nfs/dir.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 32ccd77..7a074db 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -2333,7 +2333,7 @@ static void nfs_access_add_rbtree(struct inode *inode, struct nfs_access_entry *
 
 void nfs_access_add_cache(struct inode *inode, struct nfs_access_entry *set)
 {
-	struct nfs_access_entry *cache = kmalloc(sizeof(*cache), GFP_KERNEL);
+	struct nfs_access_entry *cache = kmalloc(sizeof(*cache), GFP_ATOMIC);
 	if (cache == NULL)
 		return;
 	RB_CLEAR_NODE(&cache->rb_node);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs: nfs: Fix a sleep-in-atomic bug in nfs_access_add_cache
  2017-06-05  8:05 [PATCH] fs: nfs: Fix a sleep-in-atomic bug in nfs_access_add_cache Jia-Ju Bai
@ 2017-06-05 11:48 ` Trond Myklebust
  2017-06-05 12:36   ` Jia-Ju Bai
  0 siblings, 1 reply; 3+ messages in thread
From: Trond Myklebust @ 2017-06-05 11:48 UTC (permalink / raw)
  To: baijiaju1990, anna.schumaker; +Cc: linux-kernel, linux-nfs

On Mon, 2017-06-05 at 16:05 +0800, Jia-Ju Bai wrote:
> The driver may sleep under a rcu read lock, and function call path
> is:
> nfs_permission (acquire the lock by rcu_read_lock)
>   nfs_do_access
>     nfs_access_add_cache
>       kmalloc(GFP_KERNEL) --> may sleep
> 
> To fix it, "GFP_KERNEL" is replaced with "GFP_ATOMIC".
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
> ---
>  fs/nfs/dir.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
> index 32ccd77..7a074db 100644
> --- a/fs/nfs/dir.c
> +++ b/fs/nfs/dir.c
> @@ -2333,7 +2333,7 @@ static void nfs_access_add_rbtree(struct inode
> *inode, struct nfs_access_entry *
>  
>  void nfs_access_add_cache(struct inode *inode, struct
> nfs_access_entry *set)
>  {
> -	struct nfs_access_entry *cache = kmalloc(sizeof(*cache),
> GFP_KERNEL);
> +	struct nfs_access_entry *cache = kmalloc(sizeof(*cache),
> GFP_ATOMIC);
>  	if (cache == NULL)
>  		return;
>  	RB_CLEAR_NODE(&cache->rb_node);

The RCU locked codepath will not ever hit nfs_access_add_rbtree(). It
returns with an error code of -ECHILD after the test of "may_block".

Cheers
  Trond
-- 
Trond Myklebust
Linux NFS client maintainer, PrimaryData
trond.myklebust@primarydata.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs: nfs: Fix a sleep-in-atomic bug in nfs_access_add_cache
  2017-06-05 11:48 ` Trond Myklebust
@ 2017-06-05 12:36   ` Jia-Ju Bai
  0 siblings, 0 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2017-06-05 12:36 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: anna.schumaker, linux-kernel, linux-nfs

On 06/05/2017 07:48 PM, Trond Myklebust wrote:
> On Mon, 2017-06-05 at 16:05 +0800, Jia-Ju Bai wrote:
>> The driver may sleep under a rcu read lock, and function call path
>> is:
>> nfs_permission (acquire the lock by rcu_read_lock)
>>    nfs_do_access
>>      nfs_access_add_cache
>>        kmalloc(GFP_KERNEL) -->  may sleep
>>
>> To fix it, "GFP_KERNEL" is replaced with "GFP_ATOMIC".
>>
>> Signed-off-by: Jia-Ju Bai<baijiaju1990@163.com>
>> ---
>>   fs/nfs/dir.c |    2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
>> index 32ccd77..7a074db 100644
>> --- a/fs/nfs/dir.c
>> +++ b/fs/nfs/dir.c
>> @@ -2333,7 +2333,7 @@ static void nfs_access_add_rbtree(struct inode
>> *inode, struct nfs_access_entry *
>>   
>>   void nfs_access_add_cache(struct inode *inode, struct
>> nfs_access_entry *set)
>>   {
>> -	struct nfs_access_entry *cache = kmalloc(sizeof(*cache),
>> GFP_KERNEL);
>> +	struct nfs_access_entry *cache = kmalloc(sizeof(*cache),
>> GFP_ATOMIC);
>>   	if (cache == NULL)
>>   		return;
>>   	RB_CLEAR_NODE(&cache->rb_node);
> The RCU locked codepath will not ever hit nfs_access_add_rbtree(). It
> returns with an error code of -ECHILD after the test of "may_block".
>
> Cheers
>    Trond
Yes, I think you are right.

Thanks,
Jia-Ju Bai

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-05 12:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-05  8:05 [PATCH] fs: nfs: Fix a sleep-in-atomic bug in nfs_access_add_cache Jia-Ju Bai
2017-06-05 11:48 ` Trond Myklebust
2017-06-05 12:36   ` Jia-Ju Bai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).