Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp315522ybb; Tue, 24 Mar 2020 23:37:53 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsCs3913+xM8dczlabuHK0Q1p+NEjYSZF3zYT81ogQbaC2iEKyiwyVErKVAa49GFczMBobI X-Received: by 2002:a9d:65c4:: with SMTP id z4mr1384712oth.51.1585118273869; Tue, 24 Mar 2020 23:37:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585118273; cv=none; d=google.com; s=arc-20160816; b=ZezAB3HQJGjFqh1kIkEpTnwr7skhOH9xmimRWJUbEQi546xIgIbcydMHZ98ICQAks9 hNnhPDL/VZreDWFZMjI5YAXFRq5gpfrfAH4auFjIY574wlZ+xUzFctOgkINxVo6Y/7iy Xlfr//wFyWCDgynQDxDvhMlIYguYalO9xyivoZVh4gUd9WdwRXEU423H8avTpECy878G jxMeqxJw0FMvlBntxSjmm9mmDLT5LmAR2EuF8F6nqo0BTUw1n5ppRtSiLjV/PezW14mO nPh/KquB5X3xGU7DgD7ElZlfKhrcKNKwwSz4hTSGmbgm5JytgGjy29+F7EFKdQjtlNJ+ cMMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=BOEELJkN8wlsq6etaVcDWTPfWjI4S2GufoB/jFtu0sY=; b=EzuzzUGR24/staLxpCHqk0oQMHJ2ghwZ45UcwWl4SSno8qbttGhM/qS4nperjnnJyU caG7IButVgdQy5SeMv3XWKua4KQVOMAvDPgH0fFN9lLtgPtWfSN/utNMb1fPwpRA4/Fh rNCQUI7rgqRpfe3Vu/Ifxr1DXiYYoEWwT1ZH+iAm8D1fqtwgehfnuxyWZ7tyRDZsPrkR 8fKVthy444twsk1bWPu7t1PgG5xc1e23HIuqx6ECuu1hBOMErekfnJv4398+dwl/Hic7 qQA4/OwZWsMw72L2z1tDiol939SHP968Q2Cr4sompuGWPQ6sIjojAZo+bQB0/8uYnAmw kqtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i184si10410803oia.14.2020.03.24.23.37.26; Tue, 24 Mar 2020 23:37:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726065AbgCYGhT (ORCPT + 99 others); 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