From: Yihao Wu <wuyihao@linux.alibaba.com>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: Trond Myklebust <trondmy@hammerspace.com>,
Bruce Fields <bfields@fieldses.org>,
"neilb@suse.com" <neilb@suse.com>,
Linux NFS Mailing List <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH] nfsd: fix race between cache_clean and cache_purge
Date: Wed, 25 Mar 2020 23:14:33 +0800 [thread overview]
Message-ID: <eaa72567-a77d-5274-1569-fb3daf2c4162@linux.alibaba.com> (raw)
In-Reply-To: <6AA6A103-6A9C-40CF-A625-B7A29B0D6BA0@oracle.com>
On 2020/3/25 10:24 PM, Chuck Lever wrote:
>
>
>> On Mar 25, 2020, at 2:37 AM, Yihao Wu <wuyihao@linux.alibaba.com> wrote:
>>
>> On 2020/3/25 1:46 AM, Chuck Lever wrote:
>>>>>> ---
>>>>>> net/sunrpc/cache.c | 3 +++
>>>>>> 1 file changed, 3 insertions(+)
>>>>>>
>>>>>> diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
>>>>>> index bd843a81afa0..3e523eefc47f 100644
>>>>>> --- a/net/sunrpc/cache.c
>>>>>> +++ b/net/sunrpc/cache.c
>>>>>> @@ -524,9 +524,11 @@ void cache_purge(struct cache_detail *detail)
>>>>>> struct hlist_node *tmp = NULL;
>>>>>> int i = 0;
>>>>>>
>>>>>> + spin_lock(&cache_list_lock);
>>>>>> spin_lock(&detail->hash_lock);
>>>>>> if (!detail->entries) {
>>>>>> spin_unlock(&detail->hash_lock);
>>>>>> + spin_unlock(&cache_list_lock);
>>>>>> return;
>>>>>> }
>>>>>>
>>>>>> @@ -541,6 +543,7 @@ void cache_purge(struct cache_detail *detail)
>>>>>> }
>>>>>> }
>>>>>> spin_unlock(&detail->hash_lock);
>>>>>> + spin_unlock(&cache_list_lock);
>>>>>> }
>>>>>> EXPORT_SYMBOL_GPL(cache_purge);
>>>>
>>>> Hmm... Shouldn't this patch be dropping cache_list_lock() when we call
>>>> sunrpc_end_cache_remove_entry()? The latter does call both
>>>> cache_revisit_request() and cache_put(), and while they do not
>>>> explicitly call anything that holds cache_list_lock, some of those cd-
>>>>> cache_put callbacks do look as if there is potential for deadlock.
>>> I see svc_export_put calling dput, eventually, which might_sleep().
>>
>> Wow that's a little strange. If svc_export_put->dput might_sleep, why can we
>> spin_lock(&detail->hash_lock); in cache_purge in the first place?
>>
>> And I agree with Trond those cd->cache_put callbacks are dangerous. I will look
>> into them today.
>>
>> But if we dropping cache_list_lock when we call sunrpc_end_cache_remove_entry,
>> cache_put is not protected, and this patch won't work anymore, right?
>
> IMHO Neil's proposed solution seems pretty safe, and follows a well-understood
> pattern.
>
> It would be nice (but not 100% necessary) if the race you found was spelled out
> in the patch description.
>
> Thanks!
>
>
> --
> Chuck Lever
>
>
Yeah. I believe Neil's solution must be better.
But I'm still studying it, so I didn't reply to him yet.
OK. I'll try make it more clearly in the next version patch.
Thanks,
Yihao Wu
next prev parent reply other threads:[~2020-03-25 15:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-24 9:49 [PATCH] nfsd: fix race between cache_clean and cache_purge Yihao Wu
2020-03-24 13:38 ` Chuck Lever
2020-03-24 14:33 ` Bruce Fields
2020-03-24 14:35 ` Chuck Lever
2020-03-24 15:24 ` Trond Myklebust
2020-03-24 17:46 ` Chuck Lever
2020-03-25 6:37 ` Yihao Wu
2020-03-25 14:24 ` Chuck Lever
2020-03-25 15:14 ` Yihao Wu [this message]
2020-03-24 14:18 ` Chuck Lever
2020-03-24 14:28 ` Yihao Wu
2020-03-24 23:07 ` NeilBrown
2020-04-04 13:53 ` Yihao Wu
2020-03-25 1:01 ` Sasha Levin
2020-03-25 14:13 ` Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eaa72567-a77d-5274-1569-fb3daf2c4162@linux.alibaba.com \
--to=wuyihao@linux.alibaba.com \
--cc=bfields@fieldses.org \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.com \
--cc=trondmy@hammerspace.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox