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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 EEAE5C54FD0 for ; Mon, 27 Apr 2020 06:01:11 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BB1CC2080C; Mon, 27 Apr 2020 06:01:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="VNXoS7Jy"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="IxxJXW3Y"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="aFPM60PS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB1CC2080C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jSwpJ-00078l-Rm; Mon, 27 Apr 2020 06:01:10 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jSwpI-00078Y-Qz for linux-f2fs-devel@lists.sourceforge.net; Mon, 27 Apr 2020 06:01:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=NMpBrJ+MWAxIYH4EAuywwnTikdBRWVUi+Ksjf8AeqQo=; b=VNXoS7Jy/MLp1xEJ6LprDeY+9g stww16YZB+WnW6blERUYh/ALpv2vfYXECI6Sbq9gqM0z2kvo00v5KoHKbRwXjD1wCO4RsL+EzElrF 5jEWJK6wdG0IKmOqSYUMnerk2SwMT1PJgV9c5J4r/20KbQT+ARW+RAHINui3gVjKMMjs=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version: Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=NMpBrJ+MWAxIYH4EAuywwnTikdBRWVUi+Ksjf8AeqQo=; b=IxxJXW3YYw/PbKcrv87bTTfZfL /UpdtnDRY9kUXa3ApzJoA9PkBo5LWFY1doljCqBqpXedvqXK2y7Bat/uUDtWkLvNiUfrq/kmTRAC0 qS/FdYxlWeyO65yelblSuEk0ppHaRBQkPbfMrVFXnHVjLyedb0nPC8/nNmQe+pzxx2Kc=; Received: from mail27.static.mailgun.info ([104.130.122.27]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.2) id 1jSwp4-00CRFW-1T for linux-f2fs-devel@lists.sourceforge.net; Mon, 27 Apr 2020 06:01:08 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1587967255; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=NMpBrJ+MWAxIYH4EAuywwnTikdBRWVUi+Ksjf8AeqQo=; b=aFPM60PSqcTaYnt9ycEOFhCwTVpIsSCrIXW337O5OgouaZ9RzVpdXGBT5IdeE9exkQU5WATs KI+N/Gcj1i/fY4JLu99KUS+RQ3ohII2vxxLNcHwpoi25aWhqq5IOZtfYK1J0dIi577nEXf0X FxtQp0oUtozQQdMmw9LlP2I+wr0= X-Mailgun-Sending-Ip: 104.130.122.27 X-Mailgun-Sid: WyI2M2Y4ZiIsICJsaW51eC1mMmZzLWRldmVsQGxpc3RzLnNvdXJjZWZvcmdlLm5ldCIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5ea674fd.7fda293e4998-smtp-out-n03; Mon, 27 Apr 2020 06:00:29 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 418AEC433F2; Mon, 27 Apr 2020 06:00:29 +0000 (UTC) Received: from sayalil-linux.qualcomm.com (blr-c-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sayalil) by smtp.codeaurora.org (Postfix) with ESMTPSA id 09865C433D2; Mon, 27 Apr 2020 06:00:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 09865C433D2 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=sayalil@codeaurora.org From: Sayali Lokhande To: jaegeuk@kernel.org, yuchao0@huawei.com, linux-f2fs-devel@lists.sourceforge.net Date: Mon, 27 Apr 2020 11:30:04 +0530 Message-Id: <1587967204-24824-1-git-send-email-sayalil@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-Headers-End: 1jSwp4-00CRFW-1T Subject: [f2fs-dev] [PATCH V2] f2fs: Avoid double lock for cp_rwsem during checkpoint X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net There could be a scenario where f2fs_sync_node_pages gets called during checkpoint, which in turn tries to flush inline data and calls iput(). This results in deadlock as iput() tries to hold cp_rwsem, which is already held at the beginning by checkpoint->block_operations(). Call stack : Thread A Thread B f2fs_write_checkpoint() - block_operations(sbi) - f2fs_lock_all(sbi); - down_write(&sbi->cp_rwsem); - open() - igrab() - write() write inline data - unlink() - f2fs_sync_node_pages() - if (is_inline_node(page)) - flush_inline_data() - ilookup() page = f2fs_pagecache_get_page() if (!page) goto iput_out; iput_out: - iput() iput(inode); - f2fs_evict_inode() - f2fs_truncate_blocks() - f2fs_lock_op() - down_read(&sbi->cp_rwsem); Signed-off-by: Sayali Lokhande --- fs/f2fs/checkpoint.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 5ba649e..97b6378 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1219,21 +1219,19 @@ static int block_operations(struct f2fs_sb_info *sbi) goto retry_flush_quotas; } -retry_flush_nodes: down_write(&sbi->node_write); if (get_pages(sbi, F2FS_DIRTY_NODES)) { up_write(&sbi->node_write); + up_write(&sbi->node_change); + f2fs_unlock_all(sbi); atomic_inc(&sbi->wb_sync_req[NODE]); err = f2fs_sync_node_pages(sbi, &wbc, false, FS_CP_NODE_IO); atomic_dec(&sbi->wb_sync_req[NODE]); - if (err) { - up_write(&sbi->node_change); - f2fs_unlock_all(sbi); + if (err) goto out; - } cond_resched(); - goto retry_flush_nodes; + goto retry_flush_quotas; } /* -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel