@@ -665,11 +665,11 @@ static void fuse_release_user_pages(struct fuse_args_pages *ap, ssize_t nres,
665
665
{
666
666
unsigned int i ;
667
667
668
- for (i = 0 ; i < ap -> num_pages ; i ++ ) {
668
+ for (i = 0 ; i < ap -> num_folios ; i ++ ) {
669
669
if (should_dirty )
670
- set_page_dirty_lock (ap -> pages [i ]);
670
+ folio_mark_dirty_lock (ap -> folios [i ]);
671
671
if (ap -> args .is_pinned )
672
- unpin_user_page (ap -> pages [i ]);
672
+ unpin_folio (ap -> folios [i ]);
673
673
}
674
674
675
675
if (nres > 0 && ap -> args .invalidate_vmap )
@@ -742,24 +742,6 @@ static void fuse_aio_complete(struct fuse_io_priv *io, int err, ssize_t pos)
742
742
kref_put (& io -> refcnt , fuse_io_release );
743
743
}
744
744
745
- static struct fuse_io_args * fuse_io_alloc (struct fuse_io_priv * io ,
746
- unsigned int npages )
747
- {
748
- struct fuse_io_args * ia ;
749
-
750
- ia = kzalloc (sizeof (* ia ), GFP_KERNEL );
751
- if (ia ) {
752
- ia -> io = io ;
753
- ia -> ap .pages = fuse_pages_alloc (npages , GFP_KERNEL ,
754
- & ia -> ap .descs );
755
- if (!ia -> ap .pages ) {
756
- kfree (ia );
757
- ia = NULL ;
758
- }
759
- }
760
- return ia ;
761
- }
762
-
763
745
static struct fuse_io_args * fuse_io_folios_alloc (struct fuse_io_priv * io ,
764
746
unsigned int nfolios )
765
747
{
@@ -779,12 +761,6 @@ static struct fuse_io_args *fuse_io_folios_alloc(struct fuse_io_priv *io,
779
761
return ia ;
780
762
}
781
763
782
- static void fuse_io_free (struct fuse_io_args * ia )
783
- {
784
- kfree (ia -> ap .pages );
785
- kfree (ia );
786
- }
787
-
788
764
static void fuse_io_folios_free (struct fuse_io_args * ia )
789
765
{
790
766
kfree (ia -> ap .folios );
@@ -821,7 +797,7 @@ static void fuse_aio_complete_req(struct fuse_mount *fm, struct fuse_args *args,
821
797
fuse_release_user_pages (& ia -> ap , err ?: nres , io -> should_dirty );
822
798
823
799
fuse_aio_complete (io , err , pos );
824
- fuse_io_free (ia );
800
+ fuse_io_folios_free (ia );
825
801
}
826
802
827
803
static ssize_t fuse_async_req_send (struct fuse_mount * fm ,
@@ -1531,6 +1507,7 @@ static int fuse_get_user_pages(struct fuse_args_pages *ap, struct iov_iter *ii,
1531
1507
bool use_pages_for_kvec_io )
1532
1508
{
1533
1509
bool flush_or_invalidate = false;
1510
+ unsigned int nr_pages = 0 ;
1534
1511
size_t nbytes = 0 ; /* # bytes already packed in req */
1535
1512
ssize_t ret = 0 ;
1536
1513
@@ -1560,31 +1537,44 @@ static int fuse_get_user_pages(struct fuse_args_pages *ap, struct iov_iter *ii,
1560
1537
}
1561
1538
}
1562
1539
1563
- while (nbytes < * nbytesp && ap -> num_pages < max_pages ) {
1564
- unsigned npages ;
1540
+ /*
1541
+ * Until there is support for iov_iter_extract_folios(), we have to
1542
+ * manually extract pages using iov_iter_extract_pages() and then
1543
+ * copy that to a folios array.
1544
+ */
1545
+ struct page * * pages = kzalloc (max_pages * sizeof (struct page * ),
1546
+ GFP_KERNEL );
1547
+ if (!pages )
1548
+ return - ENOMEM ;
1549
+
1550
+ while (nbytes < * nbytesp && nr_pages < max_pages ) {
1551
+ unsigned nfolios , i ;
1565
1552
size_t start ;
1566
- struct page * * pt_pages ;
1567
1553
1568
- pt_pages = & ap -> pages [ap -> num_pages ];
1569
- ret = iov_iter_extract_pages (ii , & pt_pages ,
1554
+ ret = iov_iter_extract_pages (ii , & pages ,
1570
1555
* nbytesp - nbytes ,
1571
- max_pages - ap -> num_pages ,
1556
+ max_pages - nr_pages ,
1572
1557
0 , & start );
1573
1558
if (ret < 0 )
1574
1559
break ;
1575
1560
1576
1561
nbytes += ret ;
1577
1562
1578
1563
ret += start ;
1579
- npages = DIV_ROUND_UP (ret , PAGE_SIZE );
1564
+ /* Currently, all folios in FUSE are one page */
1565
+ nfolios = DIV_ROUND_UP (ret , PAGE_SIZE );
1580
1566
1581
- ap -> descs [ap -> num_pages ].offset = start ;
1582
- fuse_page_descs_length_init (ap -> descs , ap -> num_pages , npages );
1567
+ ap -> folio_descs [ap -> num_folios ].offset = start ;
1568
+ fuse_folio_descs_length_init (ap -> folio_descs , ap -> num_folios , nfolios );
1569
+ for (i = 0 ; i < nfolios ; i ++ )
1570
+ ap -> folios [i + ap -> num_folios ] = page_folio (pages [i ]);
1583
1571
1584
- ap -> num_pages += npages ;
1585
- ap -> descs [ap -> num_pages - 1 ].length -=
1572
+ ap -> num_folios += nfolios ;
1573
+ ap -> folio_descs [ap -> num_folios - 1 ].length -=
1586
1574
(PAGE_SIZE - ret ) & (PAGE_SIZE - 1 );
1575
+ nr_pages += nfolios ;
1587
1576
}
1577
+ kfree (pages );
1588
1578
1589
1579
if (write && flush_or_invalidate )
1590
1580
flush_kernel_vmap_range (ap -> args .vmap_base , nbytes );
@@ -1624,14 +1614,14 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1624
1614
bool fopen_direct_io = ff -> open_flags & FOPEN_DIRECT_IO ;
1625
1615
1626
1616
max_pages = iov_iter_npages (iter , fc -> max_pages );
1627
- ia = fuse_io_alloc (io , max_pages );
1617
+ ia = fuse_io_folios_alloc (io , max_pages );
1628
1618
if (!ia )
1629
1619
return - ENOMEM ;
1630
1620
1631
1621
if (fopen_direct_io && fc -> direct_io_allow_mmap ) {
1632
1622
res = filemap_write_and_wait_range (mapping , pos , pos + count - 1 );
1633
1623
if (res ) {
1634
- fuse_io_free (ia );
1624
+ fuse_io_folios_free (ia );
1635
1625
return res ;
1636
1626
}
1637
1627
}
@@ -1646,7 +1636,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1646
1636
if (fopen_direct_io && write ) {
1647
1637
res = invalidate_inode_pages2_range (mapping , idx_from , idx_to );
1648
1638
if (res ) {
1649
- fuse_io_free (ia );
1639
+ fuse_io_folios_free (ia );
1650
1640
return res ;
1651
1641
}
1652
1642
}
@@ -1673,7 +1663,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1673
1663
1674
1664
if (!io -> async || nres < 0 ) {
1675
1665
fuse_release_user_pages (& ia -> ap , nres , io -> should_dirty );
1676
- fuse_io_free (ia );
1666
+ fuse_io_folios_free (ia );
1677
1667
}
1678
1668
ia = NULL ;
1679
1669
if (nres < 0 ) {
@@ -1692,13 +1682,13 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1692
1682
}
1693
1683
if (count ) {
1694
1684
max_pages = iov_iter_npages (iter , fc -> max_pages );
1695
- ia = fuse_io_alloc (io , max_pages );
1685
+ ia = fuse_io_folios_alloc (io , max_pages );
1696
1686
if (!ia )
1697
1687
break ;
1698
1688
}
1699
1689
}
1700
1690
if (ia )
1701
- fuse_io_free (ia );
1691
+ fuse_io_folios_free (ia );
1702
1692
if (res > 0 )
1703
1693
* ppos = pos ;
1704
1694
0 commit comments