Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1301471lqh; Mon, 6 May 2024 03:43:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUiV++zanWUqqs3hhs9s2APSN8zOno9Ka8BrQfneUsY5fYLDqsKVHA5m4Xx6Kqi7QuO4tlDqLEf0cCEeHF7XbRV5zHFAItmtPwV1VDntQ== X-Google-Smtp-Source: AGHT+IF+i6WAKFjBvvyCoRdtuK80SRhUl+jBn0ODxL0O68hwOCXHGfSB1yT9YQOQVnLI3pVIk1xJ X-Received: by 2002:a05:6a00:1993:b0:6eb:3c2d:76e0 with SMTP id d19-20020a056a00199300b006eb3c2d76e0mr12565177pfl.11.1714992197814; Mon, 06 May 2024 03:43:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714992197; cv=pass; d=google.com; s=arc-20160816; b=uZ2Y9QwlLDZS95/4ekjsu+jEVbRxi2Lv1WfuPCqSY9U+Y4iCCrjqPke5NfxahkkQTv 78RQzfZqZdtrELhgfdzAobhZe1eo2v2se77dsK4ZLOctPFvX4u16dBu6ekHegBXUx3C5 +V7rC4UTm38kzK3fIN9QUZTWvS8eMCalARBPFHy+q0rETyF56Pu7oxJJZLpJaUVR6Igg S1Ardi+rhKLcmxjX19dQbMydQZTVDpBJ9nLrkChBmzMRD+ZU0OSKIF66DGX4pOF502xm XTFT4Fi88paOWivrety6hOm78k9BS8HQxP2Ty4sXklCk6AYvP5e07Rt4se43nyfCDgll V2kA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bFtObBWWpAaEThNan5FYnmr0TnSmuoc3FKrd0rPupJU=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=k1aaDuwxf3e0E2KsOswg4MC/n2boSQqqw4zEbknGLg+cpM+fSP4qiDXdnNJir+AmnT 9pcyOB3TRcnsMDeflxPK8FviCqhbXl/tc+yWqXf3KzxMRPi+irXiV5naZM9Q95Jb6gNi nsxkdLIPRpYYhPpMfkE72XzsXCKbZ+KmVgiW3EzZ7n5P25gMo3BdM4LwyL7q4WjIiXjg 1fbI3FSbxc3z8Wkn9gMCK2glTlfxej+Kcl1UDFhXxpaYcLqW8nalHJcVnzhuXA7c8xHY 7CBC5AxpoCB039WdgEPxZDx03SCzDYqRKcG9wjCvZ0ZtoyH+nH8+qrASEf4NJ8b3noME lZQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BiOxEnJ1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-169685-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169685-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id v190-20020a6389c7000000b0061c41a9b633si6987415pgd.649.2024.05.06.03.43.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 03:43:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169685-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BiOxEnJ1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-169685-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169685-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 174B7B22E59 for ; Mon, 6 May 2024 10:42:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46758143877; Mon, 6 May 2024 10:42:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BiOxEnJ1" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72999143863 for ; Mon, 6 May 2024 10:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714992134; cv=none; b=a6kTfbAixMwl9SuhJK/+eT8WqQ+mqhYoEpB4/T6bvdipWtchK9Ba1EYZNBkpfq+St3CbBMO3mnCfs4BLoLHIhoisYTN03lKDYRVrHpCC7bZnK8yivtw8TvgVvCGJOrIFTXBGcC5HPA3RxusAt3rfVtbM4xbzCpDsutdI5R/I4jY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714992134; c=relaxed/simple; bh=h2cJ8DiDTvOHVXuqiLQoZiz/U51rJ58bz1v/ndbDMNc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KQ8gBMq2G70Ob+Kt+VTToyfK4OTws2TJ8i9ROyINBw4xYtJwgj8PINJd+apshoUozq4SsXqERgnBz9/hXvbpjLEVdFGR8VFZrZKbCBgtY0F4Cd45vccwBLvnriHXV1jeb9DsrLduXD00HBC1MLjJi6ay37OPDv3tN8qBWe1zLfM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BiOxEnJ1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 138FDC4AF66; Mon, 6 May 2024 10:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714992134; bh=h2cJ8DiDTvOHVXuqiLQoZiz/U51rJ58bz1v/ndbDMNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BiOxEnJ1khv7+Zae5sAhEAsn2ZDIc9Ye9P28fYz4pEatNLYbUaHZRWSQwOeayJsuO 3ON/Fn6RgX2LR295sTaNE53iuE8Wxdki7jx3y/GvNzpJRvcIFDtRCG6HH+e1pcB4s3 tOech77POBhS4mtwrZ/hU617xqruqq8zLlFwYyiXbh1V6YsT//8UuFKucEjLqgEa71 C1JGpJs4ZXt9RHyGFZErXZAHNWpBjUcvIjNTGTNSqn/CMaKWGAYSJaYurkERH5L0vX WT5wBhGOi8nPKmRL2MQIHb7/F7Yv7nu7edzCPcwzCM+O7aZRoDRahlbFpK533EFzP0 2Hj+mvEq2JVzw== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 4/5] f2fs: compress: fix to cover {reserve,release}_compress_blocks() w/ cp_rwsem lock Date: Mon, 6 May 2024 18:41:39 +0800 Message-Id: <20240506104140.776986-4-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240506104140.776986-1-chao@kernel.org> References: <20240506104140.776986-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit It needs to cover {reserve,release}_compress_blocks() w/ cp_rwsem lock to avoid racing with checkpoint, otherwise, filesystem metadata including blkaddr in dnode, inode fields and .total_valid_block_count may be corrupted after SPO case. Fixes: ef8d563f184e ("f2fs: introduce F2FS_IOC_RELEASE_COMPRESS_BLOCKS") Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS") Signed-off-by: Chao Yu --- fs/f2fs/file.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index e77e958a9f92..3f0db351e976 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3570,9 +3570,12 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) struct dnode_of_data dn; pgoff_t end_offset, count; + f2fs_lock_op(sbi); + set_new_dnode(&dn, inode, NULL, NULL, 0); ret = f2fs_get_dnode_of_data(&dn, page_idx, LOOKUP_NODE); if (ret) { + f2fs_unlock_op(sbi); if (ret == -ENOENT) { page_idx = f2fs_get_next_page_offset(&dn, page_idx); @@ -3590,6 +3593,8 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) f2fs_put_dnode(&dn); + f2fs_unlock_op(sbi); + if (ret < 0) break; @@ -3742,9 +3747,12 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) struct dnode_of_data dn; pgoff_t end_offset, count; + f2fs_lock_op(sbi); + set_new_dnode(&dn, inode, NULL, NULL, 0); ret = f2fs_get_dnode_of_data(&dn, page_idx, LOOKUP_NODE); if (ret) { + f2fs_unlock_op(sbi); if (ret == -ENOENT) { page_idx = f2fs_get_next_page_offset(&dn, page_idx); @@ -3762,6 +3770,8 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) f2fs_put_dnode(&dn); + f2fs_unlock_op(sbi); + if (ret < 0) break; -- 2.40.1