Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp515460pxb; Wed, 29 Sep 2021 04:18:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCbOu0NfSLygcqmK1Cxxq/mJrrugltdk9+CZH2A4S42ApDwHk+BPDCcnYzxs5HD2lfxKSL X-Received: by 2002:a17:902:854c:b0:13a:519c:67ea with SMTP id d12-20020a170902854c00b0013a519c67eamr9785327plo.82.1632914301310; Wed, 29 Sep 2021 04:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632914301; cv=none; d=google.com; s=arc-20160816; b=WcevhFvhDpKKH5zf6gGvERKWXPdty8lE1O5zveGabNEORGeKlHQtVf29MctHcHU8A5 eXVgUEdPtz67MyF+SUIYbps9D+Lg+yBGKR127Y/UQN0xsvdCp8fMmV/vrB8Fv7g6sxp6 89dtJlmrU3A8JvE3A5rRiWDU5hQHqam7aSrLofRx2NEp2DobGXqHwNHfiWc6AL8QRk7X bMlv3mORe4rN/e0sVCHhTicMbTKvtn16EiFryVCL//OlVftathyUBJn/uxnWppmopnr0 pSKjIMkxM5u1e5wmbCshg3qZkv9Ivyx8pq4dsOnu2mn11OrljJ96396T7i0rvonEltbr CGgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4genJQjDWCPq01mfsl/SodOolA0l+brvgr2HMEBkVck=; b=e/hch85GpUye2cCe0TDr/ycaosbdNzrqew3gNUDEC8oBOqRtyKHMAZNtgK4HuUs1P9 7c2ANee71MM/O1g7ecx7+xRIU0RTo7n+KSQVB4Y5XJRG2CQQZ5BvfAzZgqHQo3pWkbKo k834B4F1oOmckRsdWtGkndenJuNXNBmNcLVZJ/wiVrKGUTsTVNa0f1kV8CTLLyfqwd5+ YtXx4MglnQUP9bbVBb34vBnb5X9Waw4omZOA9M2YZye83qmdmWn5KmjwvdVwPk/UXClI 78smvuolcPDkQZXOG58Vu7DTS5scB4xUap3z/hNSY9u3deskgxtota9oP5CuHPW8Le7Y LDzw== 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 x13si2493581pfj.107.2021.09.29.04.18.08; Wed, 29 Sep 2021 04:18:21 -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 S245593AbhI2K4L (ORCPT + 99 others); Wed, 29 Sep 2021 06:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245590AbhI2K4L (ORCPT ); Wed, 29 Sep 2021 06:56:11 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C196FC06161C; Wed, 29 Sep 2021 03:54:30 -0700 (PDT) Received: from localhost.localdomain (unknown [IPv6:2401:4900:1c20:3124:6d32:b2f4:daed:4666]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: shreeya) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id DD8A41F43F97; Wed, 29 Sep 2021 11:54:24 +0100 (BST) From: Shreeya Patel To: tytso@mit.edu, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, krisman@collabora.com Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Shreeya Patel Subject: [PATCH 1/2] fs: dcache: Handle case-exact lookup in d_alloc_parallel Date: Wed, 29 Sep 2021 16:23:38 +0530 Message-Id: <0b8fd2677b797663bfcb97f6aa108193fedf9767.1632909358.git.shreeya.patel@collabora.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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; +} + 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 { + 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)) { -- 2.30.2