From patchwork Fri Sep 6 05:16:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13793267 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 704C73CF73 for ; Fri, 6 Sep 2024 05:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725599821; cv=none; b=Psk/Cm6FFQWYHPtesW4yYixiWoQA57nJ/D6kKJTB2icA1eeKP7hIiHPXtyFPlZv5ItrjfmNkuKS1zU9dZ4bjXk/o0yjb04dJwjVpZFkUpSm5kxkVtjK3ToQyz6fQjdiEXYJDclSa+RODkgMGwXUCJfrO9IM4CKfN2KMVcGlpUCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725599821; c=relaxed/simple; bh=aDevwAj8/r4LgHUE6vF9RATFhCch92FLaFsnbQFkAuQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cu90Pl38GbfaaD5nIo9H2DXSCjO93/U2xy9mlnhPzJ3uOpiZyuNoOdJ/NFVFH2ZsldaaU4vi7Jis+ceYre1Bg0nVqnAB9qzDSBldg0i84GP/3aYL4cfeUIqbqSTAkfIUhSQx8rEy0Sq3bPx0ff4uNvegev1umD5CvnUCx8zBijQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=lNpvv8gr; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=lNpvv8gr; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="lNpvv8gr"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="lNpvv8gr" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 713CE1F88E for ; Fri, 6 Sep 2024 05:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1725599817; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qEYvZM++balYg6+cO33NmqtqSZGKOkbCv0wFAVv93OI=; b=lNpvv8grChrqZjYcZ2Wo4vwtxyU29PFPEj1BLC5i/hm2xH0PXb5E37g8PJWyCiWEzSO+ZI nfWcY7SKY+Mm0faXF3JvAzX4Z5aLueBfJ6lRE8S0TK2aCZGFPloHcCWiudD8gHtgjW9QHc IBW+rwLXGNyhnj47TJnn55QuefhpLWU= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=lNpvv8gr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1725599817; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qEYvZM++balYg6+cO33NmqtqSZGKOkbCv0wFAVv93OI=; b=lNpvv8grChrqZjYcZ2Wo4vwtxyU29PFPEj1BLC5i/hm2xH0PXb5E37g8PJWyCiWEzSO+ZI nfWcY7SKY+Mm0faXF3JvAzX4Z5aLueBfJ6lRE8S0TK2aCZGFPloHcCWiudD8gHtgjW9QHc IBW+rwLXGNyhnj47TJnn55QuefhpLWU= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id AB2951395F for ; Fri, 6 Sep 2024 05:16:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id UMEFG0iQ2ma6DQAAD6G6ig (envelope-from ) for ; Fri, 06 Sep 2024 05:16:56 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/3] btrfs: zlib: make the compression path to handle sector size < page size Date: Fri, 6 Sep 2024 14:46:20 +0930 Message-ID: <6b91a9dd123c0337f57df91255d930797e3339d8.1725599171.git.wqu@suse.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 713CE1F88E X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.com:dkim,suse.com:mid]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_NONE(0.00)[]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; MIME_TRACE(0.00)[0:+]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO Inside zlib_compress_folios(), each time we switch the input page cache, the @start is increased by PAGE_SIZE. But for the incoming compression support for sector size < page size (previously we support compression only when the range is fully page aligned), this is not going to handle the following case: 0 32K 64K 96K | |///////////||///////////| @start has the initial value 32K, indicating the start filepos of the to-be-compressed range. And when grabbing the first page as input, we always call "start += PAGE_SIZE;". But since @start is starting at 32K, it will be increased by 64K, resulting it to be 96K for the next range, causing incorrect input range and corruption for the future subpage compression. Fix it by only increase @start by the input size. Signed-off-by: Qu Wenruo --- fs/btrfs/zlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 100abc00b794..ddf0d5a448a7 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -194,7 +194,7 @@ int zlib_compress_folios(struct list_head *ws, struct address_space *mapping, pg_off = offset_in_page(start); cur_len = btrfs_calc_input_length(orig_end, start); data_in = kmap_local_folio(in_folio, pg_off); - start += PAGE_SIZE; + start += cur_len; workspace->strm.next_in = data_in; workspace->strm.avail_in = cur_len; } From patchwork Fri Sep 6 05:16:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13793268 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B75444C86 for ; Fri, 6 Sep 2024 05:17:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725599822; cv=none; b=FItK//7LpFcgMqdoZnN/a2KB2ntTP4jnqAk/9B+y6P+6ASrnhc6Vu2a3CtbG8SDaDYkC/ap+NosUM2V29Zm3cg5x9K9qeBPw0Eu7EKJiHniPMlgN5EO0QmYZQwXyXpxwQgicL1oXXAi/0K3wYYoTSZWzm5GYf3QKRIRtRbp7UIg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725599822; c=relaxed/simple; bh=kPZlMEqsIS61aJZWywPWNLrQ/fN4hc2iFU+w189HCew=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E8kQD7XIm+xXhd/doAzcT1sRnM9wXxmjpjG69adIoZGiog81OZ7A7TRyMds9W34yu/MaAwaTAQG3kpKvWFaaaNHEqvx5fyxy5Fp8XQtJaXzTOF8uhnaJ84LIjEtls2GjfNFS9dd1cPf0VhVXTZuab2VKI5/o6H/7ggSvTWYpOzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=DixfVBSi; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=DixfVBSi; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="DixfVBSi"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="DixfVBSi" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AD0B91F88F for ; Fri, 6 Sep 2024 05:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1725599818; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ApyqJFl2LFyj5mzEZ9mYajo9bMouq5odBHVDvF7iJfU=; b=DixfVBSiQrFBdUUvHRyBthMyLPlhXgTaTQv9s0pAFo7lUlKEAVCuSrxbUxeNdAeInm/fGc qMWWDIXdpR6AW7bHbcPwLNC0VURn2b6mhY2Wo2JinUyxzuyPASJRzotuOmRh0CEinHwJ9o fn6AbwdtIHudmht+h9L8aT1qcXOd2HI= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1725599818; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ApyqJFl2LFyj5mzEZ9mYajo9bMouq5odBHVDvF7iJfU=; b=DixfVBSiQrFBdUUvHRyBthMyLPlhXgTaTQv9s0pAFo7lUlKEAVCuSrxbUxeNdAeInm/fGc qMWWDIXdpR6AW7bHbcPwLNC0VURn2b6mhY2Wo2JinUyxzuyPASJRzotuOmRh0CEinHwJ9o fn6AbwdtIHudmht+h9L8aT1qcXOd2HI= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E673D1395F for ; Fri, 6 Sep 2024 05:16:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ENp4KUmQ2ma6DQAAD6G6ig (envelope-from ) for ; Fri, 06 Sep 2024 05:16:57 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/3] btrfs: zstd: make the compression path to handle sector size < page size Date: Fri, 6 Sep 2024 14:46:21 +0930 Message-ID: <764a9c6a8e9e5d88253a65595dba8b2709f8d5f2.1725599171.git.wqu@suse.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.com:mid]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO Inside zstd_compress_folios(), after exhausted one input page, we need to switch to the next page as input. However when counting the total input bytes (@tot_in), we always increase it by PAGE_SIZE. For the following case, it can cause incorrect value: 0 32K 64K 96K | |///////////||///////////| After compressing range [32K, 64K), we switch to the next page, and increasing @tot_in by 64K, while we only read 32K. This will cause the @total_in to return a value larger than the input length. Fix it by only increase @tot_in by the input size. Signed-off-by: Qu Wenruo --- fs/btrfs/zstd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 866607fd3e58..15f8a83165a3 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -495,7 +495,7 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping, /* Check if we need more input */ if (workspace->in_buf.pos == workspace->in_buf.size) { - tot_in += PAGE_SIZE; + tot_in += workspace->in_buf.size; kunmap_local(workspace->in_buf.src); workspace->in_buf.src = NULL; folio_put(in_folio); From patchwork Fri Sep 6 05:16:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13793269 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5075823DE for ; Fri, 6 Sep 2024 05:17:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725599823; cv=none; b=s0py/xoHLr772fObaqBCIdM496w159OxLJm2hEWWetDKORJzTfx2+IPZU5lmuBmWa9tmfloPz6vqDMfTo4hE2JCr2F/OT/Yvj33SLzqDS6y+NU2DwSoP3PdHHyZfrdPv6ZFPO8YG1eXK0UoP7P53GtjC0wMni9gQc8pHaW3jc8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725599823; c=relaxed/simple; bh=8wUYTs1p4bP6qdDA9pZEmT6Y0i1CH28NuOUS3x7kroI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UCXvwED39+DWIDt7+/KI/ymrg7Qr0lsD/3kTVzZozwSb65gY1TpCUbi3FZdrBdN2cEIy7BDTtyY2o5WYR35Sk65ZAhhnslpxYVDWKXzj/AWiW0CU5wh0XkL5+EJIzgGu+SbjtuzLSzB3A26WKWEaDzpO6GxQhUuDEiSA3JotEqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=l3zy3fDi; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=l3zy3fDi; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="l3zy3fDi"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="l3zy3fDi" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E86632198C for ; Fri, 6 Sep 2024 05:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1725599819; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2iOvP2zWsGCteZr9apUrtW3ZJKt2W7Ac/qCGZW+VQks=; b=l3zy3fDisqK3wGZr5y6kh9nFUkUsNEEER8Lqkne7ovt/1n1Mms4Wdd+Hv8aAa8b1ZD/tVD YTBYtMMAqseJqED1pLh55+4RGWcHFGtfigdao30L2JstO/SH3X/lsYShgC++Y9PPNovF3U MgUGYnvy8xbNTzje7UglSIaehyUKaCw= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1725599819; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2iOvP2zWsGCteZr9apUrtW3ZJKt2W7Ac/qCGZW+VQks=; b=l3zy3fDisqK3wGZr5y6kh9nFUkUsNEEER8Lqkne7ovt/1n1Mms4Wdd+Hv8aAa8b1ZD/tVD YTBYtMMAqseJqED1pLh55+4RGWcHFGtfigdao30L2JstO/SH3X/lsYShgC++Y9PPNovF3U MgUGYnvy8xbNTzje7UglSIaehyUKaCw= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2D14C1395F for ; Fri, 6 Sep 2024 05:16:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id qP/jN0qQ2ma6DQAAD6G6ig (envelope-from ) for ; Fri, 06 Sep 2024 05:16:58 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/3] btrfs: compression: add an ASSERT() to ensure the read-in length is sane Date: Fri, 6 Sep 2024 14:46:22 +0930 Message-ID: <56cd7dba707d1a4c65e7c9b86e65359a0d11cfa9.1725599171.git.wqu@suse.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: There are already two bugs (one in zlib, one in zstd) that involved compression path is not handling sector size < page size cases well. So it makes more sense to make sure that btrfs_compress_folios() returns Since we already have two bugs (one in zlib, one in zstd) in the compression path resulting the @total_in be to larger than the to-be-compressed range length, there is enough reason to add an ASSERT() to make sure the total read-in length doesn't exceed the input length. Signed-off-by: Qu Wenruo --- fs/btrfs/compression.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 90aef2627ca2..6e9c4a5e0d51 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -1030,6 +1030,7 @@ int btrfs_compress_folios(unsigned int type_level, struct address_space *mapping { int type = btrfs_compress_type(type_level); int level = btrfs_compress_level(type_level); + const unsigned long orig_len = *total_out; struct list_head *workspace; int ret; @@ -1037,6 +1038,8 @@ int btrfs_compress_folios(unsigned int type_level, struct address_space *mapping workspace = get_workspace(type, level); ret = compression_compress_pages(type, workspace, mapping, start, folios, out_folios, total_in, total_out); + /* The total read-in bytes should be no larger than the input. */ + ASSERT(*total_in <= orig_len); put_workspace(type, workspace); return ret; }