Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2724034rwi; Fri, 28 Oct 2022 10:23:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM69ZPbqqa/EVFcYIfSV65iQQAC0xmvl3qqTApTQgvX4uRrwNVmy2ctDxel/+zd3aE2x8Mjx X-Received: by 2002:a17:907:7290:b0:78d:ec20:fe4d with SMTP id dt16-20020a170907729000b0078dec20fe4dmr390303ejc.528.1666977809203; Fri, 28 Oct 2022 10:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666977809; cv=none; d=google.com; s=arc-20160816; b=KOIAR+X46qmprSXpc9Zaw9V8AK9LM/G8MADxlpfrtaI/VQnGdW1RGPyT8SvM4FuUFo oUZXKV9F2Hsvoq5OMTKioPeqCoqQdb1og/cxuq2aMIrDpKMhXvTx6kYAIkSuQctkIi/N 3DIXvuYPJtsxe31QYpryX6jAIu773KJWDZMJdNhzp5dXmDpPBxI9uTe9bworD/x7XdNo 6g9LEJk7p/EIPYT8FG3yjSp3nzTX3MjA54yomZuMZI40/lhqDAXGEaiPc+IUfbQaKTDd yWxUnrugnlWdsCOASsXXuBCf81cNCc2t/fZ3L6dVXByoV3c9oXzPld2B154pep6QQSJa C5UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=BmUVG6ms7j9t1XfpPFgVhAO9DJJUmMgqjadwiLxmTcw=; b=UkZDkViBHmHStNWcb+mHWNXx4ZtApk3xh2sRxN6WK4/kPutP2Sf6S2xg5C0NSw7wJI bEUyez2X3EV+8vUFWWU1q9AlNkoxuTkj7I+I6KP2qTwnzrc6z6kUIExewdbo6AFMu/bU 4ZagEhUjxSuO788cx5qYT5f6taXtQth97xYM0BnD9irYFU3+JMobSZnEImTmtY8wuyrK qsKBWrqMU8nSKOb9Za8uCGmzwBA8wPTFVSsQiDPwMtZJwQ9BAXyICNgClENAnGAkfylX T/RBTAErbm5XEc1YIFeawAanzMH6CIYU6OFA/hstqpA/Ny4l/RUXP98F5PBB+Plt9ZFx a81w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=BygQuWcH; dkim=pass header.i=@paragon-software.com header.s=mail header.b=be8RnZNL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc34-20020a17090716a200b0078d8db64fffsi5779925ejc.20.2022.10.28.10.23.03; Fri, 28 Oct 2022 10:23:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=BygQuWcH; dkim=pass header.i=@paragon-software.com header.s=mail header.b=be8RnZNL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231266AbiJ1RGc (ORCPT + 99 others); Fri, 28 Oct 2022 13:06:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbiJ1RFZ (ORCPT ); Fri, 28 Oct 2022 13:05:25 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86B675F65; Fri, 28 Oct 2022 10:04:29 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 5525A218D; Fri, 28 Oct 2022 17:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976508; bh=BmUVG6ms7j9t1XfpPFgVhAO9DJJUmMgqjadwiLxmTcw=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=BygQuWcHrtPlllKZ5K86ExroWKnBzp7tyPVA1fSldWehIIebhqr1t4xpqbY6LA5t4 d+gQ+9ApkUIifzZ61+sWm4gaBdzDtg5325q/kkF1ynKcUHOxY4dKSX66/y7z9H0nvn Q6yspqKR4aM8atx8zL2McYxz3BvVOBKO9qkLyUz0= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 5336DDD; Fri, 28 Oct 2022 17:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976667; bh=BmUVG6ms7j9t1XfpPFgVhAO9DJJUmMgqjadwiLxmTcw=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=be8RnZNLcEwCgSEyGxTN3VMSaPn1aEaicmyBZxAVejZb5/hOiuE8FHUcaTd2PVPoW YsGUoMcoqbi+rgmjWN5yRf7QczlRiEsNKepU9WTtackXhpl39HE79RwMkgPVpyqCAu dW+OnKeiRAK6IuMlpxhGQWBuGHfYeMemfa8pwrYo= Received: from [172.30.8.65] (172.30.8.65) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 28 Oct 2022 20:04:26 +0300 Message-ID: <721e9a74-607c-fb85-8cbf-5bfed49b266e@paragon-software.com> Date: Fri, 28 Oct 2022 20:04:26 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 06/14] fs/ntfs3: Changing locking in ntfs_rename Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [172.30.8.65] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In some cases we can be in deadlock because we tried to lock the same dir. Signed-off-by: Konstantin Komarov --- fs/ntfs3/namei.c | 4 ++++ fs/ntfs3/ntfs_fs.h | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index 1af02d4f6b4d..13d6acc0747f 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -305,6 +305,8 @@ static int ntfs_rename(struct user_namespace *mnt_userns, struct inode *dir, ni_lock_dir(dir_ni); ni_lock(ni); + if (dir_ni != new_dir_ni) + ni_lock_dir2(new_dir_ni); is_bad = false; err = ni_rename(dir_ni, new_dir_ni, ni, de, new_de, &is_bad); @@ -328,6 +330,8 @@ static int ntfs_rename(struct user_namespace *mnt_userns, struct inode *dir, ntfs_sync_inode(inode); } + if (dir_ni != new_dir_ni) + ni_unlock(new_dir_ni); ni_unlock(ni); ni_unlock(dir_ni); out: diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index c45a411f82f6..5fad93a2c3fd 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -333,6 +333,7 @@ enum ntfs_inode_mutex_lock_class { NTFS_INODE_MUTEX_REPARSE, NTFS_INODE_MUTEX_NORMAL, NTFS_INODE_MUTEX_PARENT, + NTFS_INODE_MUTEX_PARENT2, }; /* @@ -1119,6 +1120,11 @@ static inline void ni_lock_dir(struct ntfs_inode *ni) mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_PARENT); } +static inline void ni_lock_dir2(struct ntfs_inode *ni) +{ + mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_PARENT2); +} + static inline void ni_unlock(struct ntfs_inode *ni) { mutex_unlock(&ni->ni_lock); -- 2.37.0