Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2398610lqp; Sun, 24 Mar 2024 17:48:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUkNFCv/7gZVL4+2PwjJaIsDIXKRv0sdWzQzBZSRFJwhStn5/dOJggFt8JpkRWNppSH31/dDIYq0UK01U7eeb+giqKRZ8ApcZtszBNSzQ== X-Google-Smtp-Source: AGHT+IF/II/t/JtJ3/S+2poJwlH/P+g+RF10QqZvQabFvkJz4CfO665yhRvBtyJfnkdMaQBrdJrN X-Received: by 2002:a17:90a:6441:b0:2a0:66b8:607d with SMTP id y1-20020a17090a644100b002a066b8607dmr1819996pjm.38.1711327685201; Sun, 24 Mar 2024 17:48:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711327685; cv=pass; d=google.com; s=arc-20160816; b=L9tzys88PhyhaDtVC0l0AxdWzxgS58aSYMi2UsCuiWQSjfnhRygee572UkJwbhV7n2 3DcfSrq97UEv9oPpuCl+Sb8Kax2z0Ry8+pjngFE2d45cCjimcY+sQ/1LNj5oTI/uzgPh XazfltmX8yY7uev1hcofgcLxDPrcWECD4jEryuVZFeU7BSskLMd6wPcltwgC5P6o6Fze TgT8XCAMDftM9ULKZQgwsFw/Wkc4yVONMgpp7pS97ZBKib0C/7vvVIqpkla8uKiV6BFJ eMdA3IbgOjmAp5OGd6FCZuxzpxgL2XTwQl9Y8wfCLGEaJ60+yhpTSObaj0NWgqE7Y3Y9 iElw== 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=VCVN1QMw0hEdn/k8zC+eaZ6zSS1kSsyooIt6PeXF4B0=; fh=j/x7sSRnXo0LaHT7QL10tuC6FCXce9x5R+7s6GpGj34=; b=NE2zprVausgqrhc22cgh7YpX5j0ce7Qya1r4qnLJHVZRafuIGHsj2OHWT+pfsR8xfc 5WrnncGxgtvvP/Qxzyo1jl1Dy45+tUL06bEWm4DlLMEl2FQG5J6nz34FpDsJjdL/lazb 4FkzyoaPdf/4uBdYimF3zLs12MlgEIuU52FGp9kHy1wJjtkwCrFjF75K80uQ4As1WyEu nVziVy0nWNg6adW/d4+FZH6Sc/sZpuE+eB/AwT9fE8lqYW6B/h5MqlRPBKF/PUkTuDMQ H0us9WKZnLuQ78zzT41qMC1pD4djwBa8vVum9OdvJTCSWecl+fydgsX5s+Um3aMMyzzM ap/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SZ1PzXb9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113451-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113451-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u17-20020a17090a891100b0029c0f24aa9dsi9938210pjn.69.2024.03.24.17.48.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:48:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113451-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SZ1PzXb9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113451-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113451-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 31CAC286419 for ; Mon, 25 Mar 2024 00:40:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B8FF1AF18A; Sun, 24 Mar 2024 22:44:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SZ1PzXb9" 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 ED1101AE8D6; Sun, 24 Mar 2024 22:44:12 +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=1711320253; cv=none; b=EGzgBFQauPuKR8mn5sqcMe/hOGOcPWcWMqnagK9+cdidFwVhCHgH6eiMhAwY7dAvlk6UHlpZ3DaNmMsNVxI9gfFASYgPzPJCyZlMF79CMg1QhjwxRABB6ETOa3CugQeoFLdsq6pnV3P0+e8nhdRGnhHuhgZCh5lGaP3i1EPnjJg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320253; c=relaxed/simple; bh=977aFKEZI/79Z6vD1txCZeAm2HBBiJ349Wa6DSmk5d4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CX7DKCDTOJXbwd+k25CdAm7dXi56kg6c0fOD8PFDhAA3ylsE4Cde5ILD1KjsY1pFWwMd905NXJj4lypMXq1+97+DEX3Raq+q6KBLnnwdY/GyQ43X8sq1H5vYLSkuFHt+/39rTTutxue35x1h7uYizDc/UxHCcehwGnwzzNOTWFQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SZ1PzXb9; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2282AC43394; Sun, 24 Mar 2024 22:44:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320252; bh=977aFKEZI/79Z6vD1txCZeAm2HBBiJ349Wa6DSmk5d4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SZ1PzXb9s9FLbt2aMA6ncX/W0wvpXx+k3s5P5565PUsa9GNiCsyDudl0XrCfF2pFA hREKgZtZ7Z8gqnsTclFj3u7fkos9DUBJxysY0UvCivZchTKCRujQz3b3EBVCzvgx5/ LZZg0D24VsVmpZXjr2Ir8r/DiQf7q3THIfv8SdbIngTAKcwV9uyegO66LQ1S03+DQG qprBdmA5QYkyjl6VnnW9Rq6wFcumIEdR1iQBT0LaqRg2Vv4TdJBpCCZEasVYZrudFk miEKik89L2f1MldXhGwbT3cLj7pZGkqIfi58gSsXwsT6qzXjNbdMhWDB9oLt8C4u9s ctbBkxuWmI7ww== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Chao Yu , Daeho Jeong , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.8 560/715] f2fs: compress: fix to cover normal cluster write with cp_rwsem Date: Sun, 24 Mar 2024 18:32:19 -0400 Message-ID: <20240324223455.1342824-561-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Chao Yu [ Upstream commit fd244524c2cf07b5f4c3fe8abd6a99225c76544b ] When we overwrite compressed cluster w/ normal cluster, we should not unlock cp_rwsem during f2fs_write_raw_pages(), otherwise data will be corrupted if partial blocks were persisted before CP & SPOR, due to cluster metadata wasn't updated atomically. Fixes: 4c8ff7095bef ("f2fs: support data compression") Reviewed-by: Daeho Jeong Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/compress.c | 27 ++++++++++++++++++--------- fs/f2fs/data.c | 3 ++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 3a8d8a213b406..ff26b49c0d71f 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1443,12 +1443,14 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) } static int f2fs_write_raw_pages(struct compress_ctx *cc, - int *submitted, + int *submitted_p, struct writeback_control *wbc, enum iostat_type io_type) { struct address_space *mapping = cc->inode->i_mapping; - int _submitted, compr_blocks, ret, i; + struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); + int submitted, compr_blocks, i; + int ret = 0; compr_blocks = f2fs_compressed_blocks(cc); @@ -1463,6 +1465,10 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, if (compr_blocks < 0) return compr_blocks; + /* overwrite compressed cluster w/ normal cluster */ + if (compr_blocks > 0) + f2fs_lock_op(sbi); + for (i = 0; i < cc->cluster_size; i++) { if (!cc->rpages[i]) continue; @@ -1487,7 +1493,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, if (!clear_page_dirty_for_io(cc->rpages[i])) goto continue_unlock; - ret = f2fs_write_single_data_page(cc->rpages[i], &_submitted, + ret = f2fs_write_single_data_page(cc->rpages[i], &submitted, NULL, NULL, wbc, io_type, compr_blocks, false); if (ret) { @@ -1495,26 +1501,29 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, unlock_page(cc->rpages[i]); ret = 0; } else if (ret == -EAGAIN) { + ret = 0; /* * for quota file, just redirty left pages to * avoid deadlock caused by cluster update race * from foreground operation. */ if (IS_NOQUOTA(cc->inode)) - return 0; - ret = 0; + goto out; f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT); goto retry_write; } - return ret; + goto out; } - *submitted += _submitted; + *submitted_p += submitted; } - f2fs_balance_fs(F2FS_M_SB(mapping), true); +out: + if (compr_blocks > 0) + f2fs_unlock_op(sbi); - return 0; + f2fs_balance_fs(sbi, true); + return ret; } int f2fs_write_multi_pages(struct compress_ctx *cc, diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index d00e92b6c9025..7a93a99fbd04b 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2839,7 +2839,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, .encrypted_page = NULL, .submitted = 0, .compr_blocks = compr_blocks, - .need_lock = LOCK_RETRY, + .need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY, .post_read = f2fs_post_read_required(inode) ? 1 : 0, .io_type = io_type, .io_wbc = wbc, @@ -2920,6 +2920,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, if (err == -EAGAIN) { err = f2fs_do_write_data_page(&fio); if (err == -EAGAIN) { + f2fs_bug_on(sbi, compr_blocks); fio.need_lock = LOCK_REQ; err = f2fs_do_write_data_page(&fio); } -- 2.43.0