Skip to content

Commit 3ff93c5

Browse files
committed
Merge tag 'fuse-fixes-6.13-rc7' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse
Pull fuse fixes from Miklos Szeredi <[email protected]>: - Fix fuse_get_user_pages() allocation failure handling. - Fix direct-io folio offset and length calculation. * tag 'fuse-fixes-6.13-rc7' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse: fuse: Set *nbytesp=0 in fuse_get_user_pages on allocation failure fuse: fix direct io folio offset and length calculation Link: https://lore.kernel.org/r/CAJfpegu7o_X%[email protected] Signed-off-by: Christian Brauner <[email protected]>
2 parents fbfd64d + 78f2560 commit 3ff93c5

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

fs/fuse/file.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,8 +1541,10 @@ static int fuse_get_user_pages(struct fuse_args_pages *ap, struct iov_iter *ii,
15411541
*/
15421542
struct page **pages = kzalloc(max_pages * sizeof(struct page *),
15431543
GFP_KERNEL);
1544-
if (!pages)
1545-
return -ENOMEM;
1544+
if (!pages) {
1545+
ret = -ENOMEM;
1546+
goto out;
1547+
}
15461548

15471549
while (nbytes < *nbytesp && nr_pages < max_pages) {
15481550
unsigned nfolios, i;
@@ -1557,18 +1559,22 @@ static int fuse_get_user_pages(struct fuse_args_pages *ap, struct iov_iter *ii,
15571559

15581560
nbytes += ret;
15591561

1560-
ret += start;
1561-
/* Currently, all folios in FUSE are one page */
1562-
nfolios = DIV_ROUND_UP(ret, PAGE_SIZE);
1562+
nfolios = DIV_ROUND_UP(ret + start, PAGE_SIZE);
1563+
1564+
for (i = 0; i < nfolios; i++) {
1565+
struct folio *folio = page_folio(pages[i]);
1566+
unsigned int offset = start +
1567+
(folio_page_idx(folio, pages[i]) << PAGE_SHIFT);
1568+
unsigned int len = min_t(unsigned int, ret, PAGE_SIZE - start);
15631569

1564-
ap->descs[ap->num_folios].offset = start;
1565-
fuse_folio_descs_length_init(ap->descs, ap->num_folios, nfolios);
1566-
for (i = 0; i < nfolios; i++)
1567-
ap->folios[i + ap->num_folios] = page_folio(pages[i]);
1570+
ap->descs[ap->num_folios].offset = offset;
1571+
ap->descs[ap->num_folios].length = len;
1572+
ap->folios[ap->num_folios] = folio;
1573+
start = 0;
1574+
ret -= len;
1575+
ap->num_folios++;
1576+
}
15681577

1569-
ap->num_folios += nfolios;
1570-
ap->descs[ap->num_folios - 1].length -=
1571-
(PAGE_SIZE - ret) & (PAGE_SIZE - 1);
15721578
nr_pages += nfolios;
15731579
}
15741580
kfree(pages);
@@ -1584,6 +1590,7 @@ static int fuse_get_user_pages(struct fuse_args_pages *ap, struct iov_iter *ii,
15841590
else
15851591
ap->args.out_pages = true;
15861592

1593+
out:
15871594
*nbytesp = nbytes;
15881595

15891596
return ret < 0 ? ret : 0;

0 commit comments

Comments
 (0)