From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6C08C54FD0 for ; Wed, 25 Mar 2020 06:37:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9C61320775 for ; Wed, 25 Mar 2020 06:37:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726065AbgCYGhT (ORCPT ); Wed, 25 Mar 2020 02:37:19 -0400 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:49815 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725781AbgCYGhS (ORCPT ); Wed, 25 Mar 2020 02:37:18 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04427;MF=wuyihao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Tta890y_1585118232; Received: from Macintosh.local(mailfrom:wuyihao@linux.alibaba.com fp:SMTPD_---0Tta890y_1585118232) by smtp.aliyun-inc.com(127.0.0.1); Wed, 25 Mar 2020 14:37:13 +0800 Subject: Re: [PATCH] nfsd: fix race between cache_clean and cache_purge To: Chuck Lever , Trond Myklebust Cc: Bruce Fields , "neilb@suse.com" , Linux NFS Mailing List References: <5eed50660eb13326b0fbf537fb58481ea53c1acb.1585043174.git.wuyihao@linux.alibaba.com> <8B2BC124-6911-46C9-9B01-A237AC149F0A@oracle.com> <13c45bdcb67d689bfcb4f4b720b631e56c662f2b.camel@hammerspace.com> From: Yihao Wu Message-ID: <5372f88d-efb7-25a3-789f-53bfa7bb6f26@linux.alibaba.com> Date: Wed, 25 Mar 2020 14:37:12 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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? Thanks, Yihao Wu