Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1509185pxb; Fri, 1 Oct 2021 12:10:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyO/xeKeajiUXtKVYirPM0RtZCV6HbJvgKgVUGVT8Uc+k4Urhmzz/h+xnbJI2PZ1vmRIFb X-Received: by 2002:a65:6187:: with SMTP id c7mr11039813pgv.317.1633115444282; Fri, 01 Oct 2021 12:10:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633115444; cv=none; d=google.com; s=arc-20160816; b=D4sABiNczLJx/Ig/8OI9wigya4RvsgQoFlbW8s16wkPMNr2kiohalZOLEuhGMMV7bB 13xw8bzGx3XU8c5CdwBc53msQSuCWiY2k5UYMtkvZxIBnkFs8y+Es7eLW9UCimnTfOBh FddemjgwC71Do5NO4rjV4NoziDpkNRIWUsMfAQMkDNTSxJ34WnXuqQUq8YFT7LIDA7Te kkUh7aacLtOylznE+KbH5ffpgQgRFkv5U1w+R7JXAy6ZmO2g+MmdDkGsrUdTaeek+/E8 b06kDp707V69wyM4mffhEvPUdwII/5SsZZ5u7np+bTu6FWng63d/OqPVOFbGRZLUCOHX PhlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:organization:subject:cc:to:from; bh=A5uWEBNLOJ/wEyHUMFCuWQR3NG+CfWnDGld0h8H2ZRg=; b=INqifIkiig3lM2LDCDH8/aiE4nmsiHDQ1AGh+NWK/AlSg+WNIDM57sv716Cj8Qp/kl fROd7kL9+Bi5leqPV98aUA1jLtzpBGZ7ujeXViw1pbuXAbHZIuIQGT/u1uP7UWVliv4q UyajdLU9FlybwfoL+JzsN/MSsqJ28H/40Geb9X26Nr/+Mk82DxohuG3E2oloBTmTFqC8 CQeKuON+mbAjVrzvaV6wsNMOZDYoQiuzqD5Mp3+VbERm+9mkQyZNMLFMD8U1Xzqwi7zT TRkVX8H/OdKpF9oEmg1N5qemdp4A4Wws4b4MpHLPr93Ul8EHj551VzuErfjh2LIATZAT 9NRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d18si7958442pgo.441.2021.10.01.12.10.21; Fri, 01 Oct 2021 12:10:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355857AbhJAShY (ORCPT + 99 others); Fri, 1 Oct 2021 14:37:24 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:48722 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355832AbhJAShW (ORCPT ); Fri, 1 Oct 2021 14:37:22 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 63FE01F459BE From: Gabriel Krisman Bertazi To: Shreeya Patel Cc: tytso@mit.edu, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com Subject: Re: [PATCH 1/2] fs: dcache: Handle case-exact lookup in d_alloc_parallel Organization: Collabora References: <0b8fd2677b797663bfcb97f6aa108193fedf9767.1632909358.git.shreeya.patel@collabora.com> Date: Fri, 01 Oct 2021 14:35:32 -0400 In-Reply-To: <0b8fd2677b797663bfcb97f6aa108193fedf9767.1632909358.git.shreeya.patel@collabora.com> (Shreeya Patel's message of "Wed, 29 Sep 2021 16:23:38 +0530") Message-ID: <87a6js61aj.fsf@collabora.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Shreeya Patel writes: > There is a soft hang caused by a deadlock in d_alloc_parallel which > waits up on lookups to finish for the dentries in the parent directory's > hash_table. > In case when d_add_ci is called from the fs layer's lookup functions, > the dentry being looked up is already in the hash table (created before > the fs lookup function gets called). We should not be processing the > same dentry that is being looked up, hence, in case of case-insensitive > filesystems we are making it a case-exact match to prevent this from > happening. > > Signed-off-by: Shreeya Patel > --- > fs/dcache.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/fs/dcache.c b/fs/dcache.c > index cf871a81f4fd..2a28ab64a165 100644 > --- a/fs/dcache.c > +++ b/fs/dcache.c > @@ -2565,6 +2565,15 @@ static void d_wait_lookup(struct dentry *dentry) > } > } > > +static inline bool d_same_exact_name(const struct dentry *dentry, > + const struct dentry *parent, > + const struct qstr *name) > +{ > + if (dentry->d_name.len != name->len) > + return false; > + return dentry_cmp(dentry, name->name, name->len) == 0; > +} I don't like the idea of having a flavor of a dentry comparison function that doesn't invoke d_compare. In particular because d_compare might be used for all sorts of things, and this fix is really specific to the case-insensitive case. Would it be possible to fold this change into generic_ci_d_compare? If we could flag the dentry as part of a parallel lookup under the relevant condition, generic_ci_d_compare could simply return immediately in such case. > + > struct dentry *d_alloc_parallel(struct dentry *parent, > const struct qstr *name, > wait_queue_head_t *wq) > @@ -2575,6 +2584,7 @@ struct dentry *d_alloc_parallel(struct dentry *parent, > struct dentry *new = d_alloc(parent, name); > struct dentry *dentry; > unsigned seq, r_seq, d_seq; > + int ci_dir = IS_CASEFOLDED(parent->d_inode); > > if (unlikely(!new)) > return ERR_PTR(-ENOMEM); > @@ -2626,8 +2636,14 @@ struct dentry *d_alloc_parallel(struct dentry *parent, > continue; > if (dentry->d_parent != parent) > continue; > - if (!d_same_name(dentry, parent, name)) > - continue; > + if (ci_dir) { > + if (!d_same_exact_name(dentry, parent, name)) > + continue; > + } else { As is, this is problematic because d_alloc_parallel is also part of the lookup path (see lookup_open, lookup_slow). In those cases, you want to do the CI comparison, to prevent racing two tasks creating a dentry differing only by case. > + if (!d_same_name(dentry, parent, name)) > + continue; > + } > + > hlist_bl_unlock(b); > /* now we can try to grab a reference */ > if (!lockref_get_not_dead(&dentry->d_lockref)) { -- Gabriel Krisman Bertazi