netfs: Fix netfs_read_gaps() to use separate sink folios
David Howells
maintainerPATCH 1/1 netfs: Fix netfs_read_gaps() to use separate sink folios
Fix netfs_read_gaps() to use separate folios rather than re-using a single sink folio to discard the unwanted data so that cifs checksum checking sees all the data that was fetched.
--- fs/netfs/buffered_read.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
fs/netfs/buffered_read.c +19 -15
@@ -482,15 +482,14 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)struct netfs_group *group =netfs_folio_group (folio);struct netfs_folio *finfo =netfs_folio_info (folio);struct netfs_inode *ctx =netfs_inode (mapping->host); -struct folio *sink =NULL ; -struct bio_vec *bvec; +struct bio_vec *bvec =NULL ;unsigned int from = finfo->dirty_offset;unsigned int to = from + finfo->dirty_len; -unsigned int off =0 , i =0 ; +unsigned int off =0 ;size_t flen =folio_size (folio);size_t nr_bvec = flen /PAGE_SIZE +2 ;size_t part; -int ret; +int ret, i =0 , sink_from =-1 , sink_to =-1 ;_enter ("%lx" , folio->index);
@@ -515,24 +514,23 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)if (!bvec) goto discard; - sink =folio_alloc (GFP_KERNEL ,0 ); -if (!sink) { -kfree (bvec); - goto discard; - } -trace_netfs_folio (folio, netfs_folio_trace_read_gaps); - rreq->direct_bv = bvec; - rreq->direct_bv_count = nr_bvec;if (from >0 ) {bvec_set_folio (&bvec[i++], folio, from,0 ); off = from; } + sink_from = i;while (off < to) { +struct folio *sink =folio_alloc (GFP_KERNEL ,0 ); + +if (!sink) + goto discard; part =min_t (size_t, to - off,PAGE_SIZE ); -bvec_set_folio (&bvec[i++], sink, part,0 ); +bvec_set_folio (&bvec[i], sink, part,0 ); off += part; + sink_to = i; + i++; }if (to < flen)bvec_set_folio (&bvec[i++], folio, flen - to, to);
@@ -553,8 +551,10 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)folio_mark_uptodate (folio); } -if (sink) -folio_put (sink); +if (sink_to >=0 ) +for (; sink_from <= sink_to; sink_from++) +folio_put (bvec_folio (&bvec[sink_from])); +kfree (bvec);folio_unlock (folio);netfs_put_request (rreq, netfs_rreq_trace_put_return);return ret <0 ? ret :0 ;
@@ -563,6 +563,10 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)netfs_put_failed_request (rreq); alloc_error:folio_unlock (folio); +if (sink_to >=0 ) +for (; sink_from <= sink_to; sink_from++) +folio_put (bvec_folio (&bvec[sink_from])); +kfree (bvec);return ret; }
Quoted 5 lines · David Howells
Fix
netfs_read_gaps()to use separate folios rather than re-using a single sink folio to discard the unwanted data so that cifs checksum checking sees all the data that was fetched.
Quoted 10 lines
Fixes 7f84a7b9892d ("netfs: Make netfs_read_folio() handle streaming-write pages")Reported-by Frank Sorenson <[email protected]>Signed-off-by David Howells <[email protected]>Tested-by Frank Sorenson <[email protected]>cc Paulo Alcantara <[email protected]>cc Namjae Jeon <[email protected]>
Quoted 4 lines · David Howells
Fix
netfs_read_gaps()to use separate folios rather than re-using a single sink folio to discard the unwanted data so that cifs checksum checking sees all the data that was fetched.
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] netfs: Fix netfs_read_gaps() to use separate sink folios
https://git.kernel.org/vfs/vfs/c/fc3ae66514ca