From nobody Mon Feb 9 10:28:23 2026 Received: from sxb1plsmtpa01-06.prod.sxb1.secureserver.net (sxb1plsmtpa01-06.prod.sxb1.secureserver.net [188.121.53.63]) (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 855E91A291 for ; Sun, 18 Aug 2024 23:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.121.53.63 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025540; cv=none; b=BW9xHIThKbkvab0g0tyh+Q0B5q8vXFGUSHWmOPs9sfy+kycE9MeypkrZMtoM2pxQgJHdW/Rb6yzUUuA2z9cjH0G5eOr/+TIHKim5/m7mumCbfl3/99euVKO4lgOJU7nLFEV0N/1PUvrGWlinY2UD1H1pWrpk3ckUDxQZTWDuExM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025540; c=relaxed/simple; bh=VMbsSCwl8BRhNBMKYMjgjw4ce4B36fAYx4tZYgbpdIc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ibYxuq5tj+wOVmCGceG2Fv6E55zuW9MRU5h4VyE2CTM/BzeAC0S9kIaIE093D5L3SB8C4YPZ9Kl8PXc0COzAGEULARBiXUnBDD6jlUQf+RaVm1SbW9IEfPyRRE1J2ymv6FgzfiDfs6grqPIqgUlo8fPyXf2IZhqWfH4QEBwq4+U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk; spf=pass smtp.mailfrom=squashfs.org.uk; arc=none smtp.client-ip=188.121.53.63 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=squashfs.org.uk Received: from phoenix.fritz.box ([82.69.79.175]) by :SMTPAUTH: with ESMTPA id fpn7sTYC0QGHUfpnOsxSIr; Sun, 18 Aug 2024 16:58:51 -0700 X-CMAE-Analysis: v=2.4 cv=LJ6tQ4W9 c=1 sm=1 tr=0 ts=66c28abb a=84ok6UeoqCVsigPHarzEiQ==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=FXvPX3liAAAA:8 a=9tSg9AYEYi0W0Z4Y8GAA:9 a=UObqyxdv-6Yh2QiB9mM_:22 X-SECURESERVER-ACCT: phillip@squashfs.org.uk From: Phillip Lougher To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: willy@infradead.org, lizetao1@huawei.com, Phillip Lougher Subject: [PATCH 4/4] Squashfs: Rewrite and update squashfs_readahead_fragment() to not use page->index Date: Mon, 19 Aug 2024 00:58:47 +0100 Message-Id: <20240818235847.170468-5-phillip@squashfs.org.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240818235847.170468-1-phillip@squashfs.org.uk> References: <20240818235847.170468-1-phillip@squashfs.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CMAE-Envelope: MS4xfJrHU6NXhXbqHmipeh76Mhj9TxdPQEZUIwgjTedAZz55OJAQAGvHE6zLaMdETM4u2qYG8Ks0sRIclrYqajWNlwKi0jTtbp1KVEaqNN4ktOtuMMYAbQIS apd4NfiShAp/E+sNRpfNDUbfwU0pNKmiTFgZG+I2Bbgu7C7EuWUQIm2tFVAFANw5I9Mrxe2gl/UoCuSUMEZ98PuEeFUvRX99T8RukU5vCvqJpPrsKEePxIyt I0GNu8edEyFbtHsr8JallWSpp46NqPhbeHNPxW9ZClcW0kVGsNlkiGchTGVI9CIhM/OmOxzA1qbvnt8nLF0lzIXCdqLQo5RKTSdervWw6xEq/jorZRbQmRzU rCZ6m90kvn18KijJpoPE1mYS0L40jbtpmGheKf4/VUp83Ac2+Ak= Content-Type: text/plain; charset="utf-8" The previous implementation lacked error checking (e.g. the bytes returned by squashfs_fill_page() is not checked), and the use of page->index could not be removed without substantially rewriting the routine to use the page actor abstraction used elsewhere. Signed-off-by: Phillip Lougher --- fs/squashfs/file.c | 66 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index 50fe5a078b83..5a3745e52025 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -494,39 +494,73 @@ static int squashfs_read_folio(struct file *file, str= uct folio *folio) } =20 static int squashfs_readahead_fragment(struct page **page, - unsigned int pages, unsigned int expected) + unsigned int pages, unsigned int expected, loff_t start) { struct inode *inode =3D page[0]->mapping->host; struct squashfs_cache_entry *buffer =3D squashfs_get_fragment(inode->i_sb, squashfs_i(inode)->fragment_block, squashfs_i(inode)->fragment_size); struct squashfs_sb_info *msblk =3D inode->i_sb->s_fs_info; - unsigned int n, mask =3D (1 << (msblk->block_log - PAGE_SHIFT)) - 1; - int error =3D buffer->error; + int i, bytes, copied; + struct squashfs_page_actor *actor; + unsigned int offset; + void *addr; + struct page *last_page; =20 - if (error) + if (buffer->error) goto out; =20 - expected +=3D squashfs_i(inode)->fragment_offset; + actor =3D squashfs_page_actor_init_special(msblk, page, pages, + expected, start); + if (!actor) + goto out; =20 - for (n =3D 0; n < pages; n++) { - unsigned int base =3D (page[n]->index & mask) << PAGE_SHIFT; - unsigned int offset =3D base + squashfs_i(inode)->fragment_offset; + squashfs_actor_nobuff(actor); + addr =3D squashfs_first_page(actor); =20 - if (expected > offset) { - unsigned int avail =3D min_t(unsigned int, expected - - offset, PAGE_SIZE); + for (copied =3D offset =3D 0; offset < expected; offset +=3D PAGE_SIZE) { + int avail =3D min_t(int, expected - offset, PAGE_SIZE); =20 - squashfs_fill_page(page[n], buffer, offset, avail); + if (!IS_ERR(addr)) { + bytes =3D squashfs_copy_data(addr, buffer, offset + + squashfs_i(inode)->fragment_offset, avail); + + if (bytes !=3D avail) + goto failed; } =20 - unlock_page(page[n]); - put_page(page[n]); + copied +=3D avail; + addr =3D squashfs_next_page(actor); } =20 + last_page =3D squashfs_page_actor_free(actor); + + if (copied =3D=3D expected) { + /* Last page (if present) may have trailing bytes not filled */ + bytes =3D copied % PAGE_SIZE; + if (bytes && last_page) + memzero_page(last_page, bytes, PAGE_SIZE - bytes); + + for (i =3D 0; i < pages; i++) { + flush_dcache_page(page[i]); + SetPageUptodate(page[i]); + } + } + + for (i =3D 0; i < pages; i++) { + unlock_page(page[i]); + put_page(page[i]); + } + + squashfs_cache_put(buffer); + return 0; + +failed: + squashfs_page_actor_free(actor); + out: squashfs_cache_put(buffer); - return error; + return 1; } =20 static void squashfs_readahead(struct readahead_control *ractl) @@ -572,7 +606,7 @@ static void squashfs_readahead(struct readahead_control= *ractl) if (start >> msblk->block_log =3D=3D file_end && squashfs_i(inode)->fragment_block !=3D SQUASHFS_INVALID_BLK) { res =3D squashfs_readahead_fragment(pages, nr_pages, - expected); + expected, start); if (res) goto skip_pages; continue; --=20 2.39.2