From nobody Sun Feb 8 05:37:24 2026 Received: from sxb1plsmtpa01-06.prod.sxb1.secureserver.net (sxb1plsmtpa01-06.prod.sxb1.secureserver.net [92.204.81.209]) (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 AD3D3624 for ; Mon, 19 Aug 2024 00:01:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=92.204.81.209 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025673; cv=none; b=dVVTcvOrMPmmYcxHxgtpC4ozKj47j6E0ThsVGU3mrQxi4Rg+lJPl66oOAGdL+6UhQj7e057auhWdhcH4u55+NnDNgGcmNSZMSVJL+sJ+9Zlmdd707bbu7He/s9GomFCrZ4d4fxN5LdeWa4H1Pu/AQHIhxgir9V2gTa5vl2rGYbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025673; c=relaxed/simple; bh=G73OEgJWv98tJ1N7a3jIpsciRVOfJTKmyNgrnC4lwWY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kcZiuKxFQcnTvzisfmczsYO1oHrZqDQ1yZmT1YCA3yGqlv9ywA9y8s/KTVonua/TQs8TTeDSGlhXNcin9gkG0FqKRgbqXHwNvodokdb3qjA/bG4jayDIjHb1dzb1h6twZ9A78M8CenKQVcjcFz23b6NrOKUtv39w06n2qUYQSAY= 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=92.204.81.209 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 fpn7sTYC0QGHUfpnKsxSIV; Sun, 18 Aug 2024 16:58:47 -0700 X-CMAE-Analysis: v=2.4 cv=LJ6tQ4W9 c=1 sm=1 tr=0 ts=66c28ab7 a=84ok6UeoqCVsigPHarzEiQ==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=FXvPX3liAAAA:8 a=anrbtZqQEueed_iD4xoA: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 1/4] Squashfs: Update page_actor to not use page->index Date: Mon, 19 Aug 2024 00:58:44 +0100 Message-Id: <20240818235847.170468-2-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: MS4xfFSx/F/6C0Y7TeC/JaJpJkGg+I37+UT52v5GqI7/FTbq0zwkBaiVIG/Mo4HU28wok1h3/vD2rspnh6hAyd8rkSz9PAU1tpLlGA5MzG7WuOQCh4/yv/hD E3ljf9rAmfPBwjjm5HRgF5B1E7BhTJfnz4msf8TTjr6mrHs9ZvlzfbsldzFVMi9CRGFHkZgXgeNrD6PNHupxtD096C5h+OiYekKKDPueQIFlu96rHWzJD2Zy b8u6/26klW5FGcBzTyP553KjBXMYDTC6w2El51ntvM+BzC+Yj0MILn9I70bcrL6jOUtgpuaWgxs0e+UQ8LZMucPC+cL1cNpX1rJ2+q1DiPg0SWH4eIoW1mm5 oNz0pfbZhrCx0SaEDeUPMlbN67C8aHouB4mT3rKtJZ6Jv0eO9rQ= Content-Type: text/plain; charset="utf-8" This commit removes an unnecessary use of page->index, and moves the other use over to folio->index. Signed-off-by: Phillip Lougher --- fs/squashfs/file.c | 2 +- fs/squashfs/file_direct.c | 3 ++- fs/squashfs/page_actor.c | 11 ++++++++--- fs/squashfs/page_actor.h | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index a8c1e7f9a609..2b6b63f4ccd1 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -589,7 +589,7 @@ static void squashfs_readahead(struct readahead_control= *ractl) goto skip_pages; =20 actor =3D squashfs_page_actor_init_special(msblk, pages, nr_pages, - expected); + expected, start); if (!actor) goto skip_pages; =20 diff --git a/fs/squashfs/file_direct.c b/fs/squashfs/file_direct.c index 2a689ce71de9..0586e6ba94bf 100644 --- a/fs/squashfs/file_direct.c +++ b/fs/squashfs/file_direct.c @@ -67,7 +67,8 @@ int squashfs_readpage_block(struct page *target_page, u64= block, int bsize, * Create a "page actor" which will kmap and kunmap the * page cache pages appropriately within the decompressor */ - actor =3D squashfs_page_actor_init_special(msblk, page, pages, expected); + actor =3D squashfs_page_actor_init_special(msblk, page, pages, expected, + start_index << PAGE_SHIFT); if (actor =3D=3D NULL) goto out; =20 diff --git a/fs/squashfs/page_actor.c b/fs/squashfs/page_actor.c index 81af6c4ca115..2b3e807d4dea 100644 --- a/fs/squashfs/page_actor.c +++ b/fs/squashfs/page_actor.c @@ -60,6 +60,11 @@ struct squashfs_page_actor *squashfs_page_actor_init(voi= d **buffer, } =20 /* Implementation of page_actor for decompressing directly into page cache= . */ +static loff_t page_next_index(struct squashfs_page_actor *actor) +{ + return page_folio(actor->page[actor->next_page])->index; +} + static void *handle_next_page(struct squashfs_page_actor *actor) { int max_pages =3D (actor->length + PAGE_SIZE - 1) >> PAGE_SHIFT; @@ -68,7 +73,7 @@ static void *handle_next_page(struct squashfs_page_actor = *actor) return NULL; =20 if ((actor->next_page =3D=3D actor->pages) || - (actor->next_index !=3D actor->page[actor->next_page]->index)) { + (actor->next_index !=3D page_next_index(actor))) { actor->next_index++; actor->returned_pages++; actor->last_page =3D NULL; @@ -103,7 +108,7 @@ static void direct_finish_page(struct squashfs_page_act= or *actor) } =20 struct squashfs_page_actor *squashfs_page_actor_init_special(struct squash= fs_sb_info *msblk, - struct page **page, int pages, int length) + struct page **page, int pages, int length, loff_t start_index) { struct squashfs_page_actor *actor =3D kmalloc(sizeof(*actor), GFP_KERNEL); =20 @@ -125,7 +130,7 @@ struct squashfs_page_actor *squashfs_page_actor_init_sp= ecial(struct squashfs_sb_ actor->pages =3D pages; actor->next_page =3D 0; actor->returned_pages =3D 0; - actor->next_index =3D page[0]->index & ~((1 << (msblk->block_log - PAGE_S= HIFT)) - 1); + actor->next_index =3D start_index >> PAGE_SHIFT; actor->pageaddr =3D NULL; actor->last_page =3D NULL; actor->alloc_buffer =3D msblk->decompressor->alloc_buffer; diff --git a/fs/squashfs/page_actor.h b/fs/squashfs/page_actor.h index 97d4983559b1..c6d837f0e9ca 100644 --- a/fs/squashfs/page_actor.h +++ b/fs/squashfs/page_actor.h @@ -29,7 +29,8 @@ extern struct squashfs_page_actor *squashfs_page_actor_in= it(void **buffer, int pages, int length); extern struct squashfs_page_actor *squashfs_page_actor_init_special( struct squashfs_sb_info *msblk, - struct page **page, int pages, int length); + struct page **page, int pages, int length, + loff_t start_index); static inline struct page *squashfs_page_actor_free(struct squashfs_page_a= ctor *actor) { struct page *last_page =3D actor->last_page; --=20 2.39.2 From nobody Sun Feb 8 05:37:24 2026 Received: from sxb1plsmtpa01-06.prod.sxb1.secureserver.net (sxb1plsmtpa01-06.prod.sxb1.secureserver.net [188.121.53.58]) (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 CA8A7EEB3 for ; Mon, 19 Aug 2024 00:06:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.121.53.58 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025984; cv=none; b=dvTEc2JokvtCWuJGqKYO22rfzDW/tguB1G2+rcSnrHspwD8eadLCyznnvLko+d7uV09ehWnEEIdRqtIo6PRWdNiDAjBxbjXfyK9M/LuFRodqpkqL6h6RDS9Zw3jPKZ8kBtKYe+cTzWmlndhYIiuPowlkjosQ3bbTQjvTyQbzmbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025984; c=relaxed/simple; bh=AZ57LPeQ04mzM+QuuWSVbk/W3te3QhYFAyBfKK3jk9I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gLycmSTjgh6dWZOi8El4aqdA2uztgaMWyFxShQxYKXWUP//lNgDmJbMq1Z/5g9xemmtMI1BQutwQ27btjnpA9Xtb8Ew4/FkxwDga0SM+j/nsAkvSuy82Ykh7U/Eh6PoVk9j+RwNEjHesi1fe+Wo+RBdsEpDo+s6P82jyoy3cQso= 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.58 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 fpn7sTYC0QGHUfpnLsxSIc; Sun, 18 Aug 2024 16:58:48 -0700 X-CMAE-Analysis: v=2.4 cv=LJ6tQ4W9 c=1 sm=1 tr=0 ts=66c28ab8 a=84ok6UeoqCVsigPHarzEiQ==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=FXvPX3liAAAA:8 a=zvuxCLvZWVJikxbZp60A: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 2/4] Squashfs: Update squashfs_readahead() to not use page->index Date: Mon, 19 Aug 2024 00:58:45 +0100 Message-Id: <20240818235847.170468-3-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: MS4xfFb2ovMBOh8BLMyp5LuvcpONdolk5ZxlPm3dw/0yXCFT9HYtOK8GhpUQKtPX8DJpbXCfsaSFc5Tcuf9G1s3nIil/jU5CC0PlhIhECCK5zW3bJfoaNM4Y M3Rq61j4sHsz4lnW1U0bmkKsGVBNorkUDnoG9yKnp8Ayj9gIWUCfjNnO5VgU2EhkVfURNTCSqlnsvtu/137uSsy/mCOXbzwBaWA7SH4YeIOlxtMXM5URuVbx Em8Q+akYJwoWeU0tWjAYvY3kxaDzEWmlVpXeA3n5RO9DIbM48tZ1r/6go+5oaeZHgCwZINJphtdaxghkyV6FUR/L9wPDrhF5GpqsW7flIfoEcJi/X19TtcG/ n5nIDXSX2Cq6hzKREbsLDOBtiUV2AFZfxFZjfoItUU90FoWCeUY= Content-Type: text/plain; charset="utf-8" This commit removes references to page->index in the pages returned from __readahead_batch(), and instead uses the 'start' variable. This does reveal a bug in the previous code in that 'start' was not updated every time around the loop. This is fixed in this commit. Signed-off-by: Phillip Lougher --- fs/squashfs/file.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index 2b6b63f4ccd1..50fe5a078b83 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -551,7 +551,6 @@ static void squashfs_readahead(struct readahead_control= *ractl) return; =20 for (;;) { - pgoff_t index; int res, bsize; u64 block =3D 0; unsigned int expected; @@ -570,13 +569,8 @@ static void squashfs_readahead(struct readahead_contro= l *ractl) if (readahead_pos(ractl) >=3D i_size_read(inode)) goto skip_pages; =20 - index =3D pages[0]->index >> shift; - - if ((pages[nr_pages - 1]->index >> shift) !=3D index) - goto skip_pages; - - if (index =3D=3D file_end && squashfs_i(inode)->fragment_block !=3D - SQUASHFS_INVALID_BLK) { + 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); if (res) @@ -584,7 +578,7 @@ static void squashfs_readahead(struct readahead_control= *ractl) continue; } =20 - bsize =3D read_blocklist(inode, index, &block); + bsize =3D read_blocklist(inode, start >> msblk->block_log, &block); if (bsize =3D=3D 0) goto skip_pages; =20 @@ -602,7 +596,7 @@ static void squashfs_readahead(struct readahead_control= *ractl) =20 /* Last page (if present) may have trailing bytes not filled */ bytes =3D res % PAGE_SIZE; - if (index =3D=3D file_end && bytes && last_page) + if (start >> msblk->block_log =3D=3D file_end && bytes && last_page) memzero_page(last_page, bytes, PAGE_SIZE - bytes); =20 @@ -616,6 +610,8 @@ static void squashfs_readahead(struct readahead_control= *ractl) unlock_page(pages[i]); put_page(pages[i]); } + + start +=3D readahead_batch_length(ractl); } =20 kfree(pages); --=20 2.39.2 From nobody Sun Feb 8 05:37:24 2026 Received: from sxb1plsmtpa01-06.prod.sxb1.secureserver.net (sxb1plsmtpa01-06.prod.sxb1.secureserver.net [188.121.53.60]) (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 7E4041D555 for ; Mon, 19 Aug 2024 00:06:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.121.53.60 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025991; cv=none; b=Apx2ReAhXz1+5sd4btNiTJ2Lf38WZJzHBrzeotjJZEkN7fjfgLXyTp/aaP21laDDm16YrMtcQfYTB5KvZg4BI2RKeanMFkCeYF3cs3A3xP/mAsSszhABe3UeqhYSaCETxk+PqZWdcgCa1sNJq+Nb494CEuv76hrLD55v9qsSKlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025991; c=relaxed/simple; bh=CLxWQbrGLeGhf8m0jbFA8flJFaDPvmVHoBNH0fNSN8I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dGlb2mBcmkv/qQ/rDtjKPdiaYlherWqRI8XjtQc4Lc5fF0tFPT/ZsOkCkB3DyjN+LWCk3Kpe4vcZs/Lyqdnh2O6+cegUI6o0CMXvYyP+CWid3K1BMI5mYb/+IP5ePwczzEH7NQzNmYNm46sKJgOkYsSj5z6YUnnFDWpdfEg02DY= 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.60 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 fpn7sTYC0QGHUfpnNsxSIj; Sun, 18 Aug 2024 16:58:49 -0700 X-CMAE-Analysis: v=2.4 cv=LJ6tQ4W9 c=1 sm=1 tr=0 ts=66c28ab9 a=84ok6UeoqCVsigPHarzEiQ==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=FXvPX3liAAAA:8 a=pK5tc-4CcGVY2xxucFwA: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 3/4] Squashfs: Update squashfs_readpage_block() to not use page->index Date: Mon, 19 Aug 2024 00:58:46 +0100 Message-Id: <20240818235847.170468-4-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: MS4xfC4EVImtNchewiNRgGU1EmOg2S2bEAhPfYB7xYHZx62zj16rW1wXEiGhBHJb2pZyWqgHuUiMHBnuoaKse3n4P2iplaSfLA0GibD8z3UEo6VMJ13xHzzz ZX6qikiQjekYxDy8K9wjlydyXOTI2NFtR4pBSHVOH4IkX17/CpV4gCGK0OpFxCdqKwexPg40XbH4IYz482sZ1vFm1LqUq7zxgiRQ4ClJFMu8O7bqWFnb5zLm 8tQihrRuTqnIlsu+JHWGh8003TV7ajTlm9iop1Uwi6rQBAbSNdOLhKrAyitgrrB2rsNXrIZ9hK0uxORY4hHZQNsuogHHSvRARbAmX2RkLRXc8bNuJm76nWbw pUGtse+x32VYdUY34ruG5RBzUKAK8WwNmkMBoCxGrkn74mHR8kQ= Content-Type: text/plain; charset="utf-8" This commit replaces references to page->index to folio->index or their equivalent. Signed-off-by: Phillip Lougher --- fs/squashfs/file_direct.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/squashfs/file_direct.c b/fs/squashfs/file_direct.c index 0586e6ba94bf..646d4d421f99 100644 --- a/fs/squashfs/file_direct.c +++ b/fs/squashfs/file_direct.c @@ -23,15 +23,15 @@ int squashfs_readpage_block(struct page *target_page, u= 64 block, int bsize, int expected) =20 { + struct folio *folio =3D page_folio(target_page); struct inode *inode =3D target_page->mapping->host; struct squashfs_sb_info *msblk =3D inode->i_sb->s_fs_info; - loff_t file_end =3D (i_size_read(inode) - 1) >> PAGE_SHIFT; int mask =3D (1 << (msblk->block_log - PAGE_SHIFT)) - 1; - loff_t start_index =3D target_page->index & ~mask; + loff_t start_index =3D folio->index & ~mask; loff_t end_index =3D start_index | mask; int i, n, pages, bytes, res =3D -ENOMEM; - struct page **page; + struct page **page, *last_page; struct squashfs_page_actor *actor; void *pageaddr; =20 @@ -46,7 +46,7 @@ int squashfs_readpage_block(struct page *target_page, u64= block, int bsize, =20 /* Try to grab all the pages covered by the Squashfs block */ for (i =3D 0, n =3D start_index; n <=3D end_index; n++) { - page[i] =3D (n =3D=3D target_page->index) ? target_page : + page[i] =3D (n =3D=3D folio->index) ? target_page : grab_cache_page_nowait(target_page->mapping, n); =20 if (page[i] =3D=3D NULL) @@ -75,7 +75,7 @@ int squashfs_readpage_block(struct page *target_page, u64= block, int bsize, /* Decompress directly into the page cache buffers */ res =3D squashfs_read_data(inode->i_sb, block, bsize, NULL, actor); =20 - squashfs_page_actor_free(actor); + last_page =3D squashfs_page_actor_free(actor); =20 if (res < 0) goto mark_errored; @@ -87,8 +87,8 @@ int squashfs_readpage_block(struct page *target_page, u64= block, int bsize, =20 /* Last page (if present) may have trailing bytes not filled */ bytes =3D res % PAGE_SIZE; - if (page[pages - 1]->index =3D=3D end_index && bytes) { - pageaddr =3D kmap_local_page(page[pages - 1]); + if (end_index =3D=3D file_end && last_page && bytes) { + pageaddr =3D kmap_local_page(last_page); memset(pageaddr + bytes, 0, PAGE_SIZE - bytes); kunmap_local(pageaddr); } --=20 2.39.2 From nobody Sun Feb 8 05:37:24 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