Commit Graph

12 Commits

Author SHA1 Message Date
Chris von Recklinghausen c0aa51a6e5 fs: Add FGP_WRITEBEGIN
Conflicts:
	fs/iomap/buffered-io.c - We already have
		66dabbb65d67 ("mm: return an ERR_PTR from __filemap_get_folio")
		so don't add declaration for folio
	include/linux/pagemap.h - We already have
		263e721e3ba1 ("mm: make mapping_get_entry available outside of filemap.c")
		so keep declaration of filemap_get_entry
	fs/nfs/file.c - We already have
		66dabbb65d67 (" mm: return an ERR_PTR from __filemap_get_folio")
		so keep IS_ERR/PTR_ERR

JIRA: https://issues.redhat.com/browse/RHEL-27741

commit e999a5c5a19cf3b679f3d93c49ad5f5c04e4806c
Author: Matthew Wilcox <willy@infradead.org>
Date:   Fri Mar 24 18:01:01 2023 +0000

    fs: Add FGP_WRITEBEGIN

    This particular combination of flags is used by most filesystems
    in their ->write_begin method, although it does find use in a
    few other places.  Before folios, it warranted its own function
    (grab_cache_page_write_begin()), but I think that just having specialised
    flags is enough.  It certainly helps the few places that have been
    converted from grab_cache_page_write_begin() to __filemap_get_folio().

    Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
    Link: https://lore.kernel.org/r/20230324180129.1220691-2-willy@infradead.org
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
2024-04-30 07:00:46 -04:00
Chris von Recklinghausen c0446613df mm: return an ERR_PTR from __filemap_get_folio
Conflicts:
	fs/nilfs2/page.c - We already have
		f6e0e1734424 ("nilfs2: Convert nilfs_copy_back_pages() to use filemap_get_folios()")
		so use folios instead of pages
	fs/smb/client/cifsfs.c - The backport of
		7b2404a886f8 ("cifs: Fix flushing, invalidation and file size with copy_file_range()")
		cited the lack of this patch as a conflict. Fix it.

JIRA: https://issues.redhat.com/browse/RHEL-27741

commit 66dabbb65d673aef40dd17bf62c042be8f6d4a4b
Author: Christoph Hellwig <hch@lst.de>
Date:   Tue Mar 7 15:34:10 2023 +0100

    mm: return an ERR_PTR from __filemap_get_folio

    Instead of returning NULL for all errors, distinguish between:

     - no entry found and not asked to allocated (-ENOENT)
     - failed to allocate memory (-ENOMEM)
     - would block (-EAGAIN)

    so that callers don't have to guess the error based on the passed in
    flags.

    Also pass through the error through the direct callers: filemap_get_folio,
    filemap_lock_folio filemap_grab_folio and filemap_get_incore_folio.

    [hch@lst.de: fix null-pointer deref]
      Link: https://lkml.kernel.org/r/20230310070023.GA13563@lst.de
      Link: https://lkml.kernel.org/r/20230310043137.GA1624890@u2004
    Link: https://lkml.kernel.org/r/20230307143410.28031-8-hch@lst.de
    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Acked-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> [nilfs2]
    Cc: Andreas Gruenbacher <agruenba@redhat.com>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
    Cc: Naoya Horiguchi <naoya.horiguchi@linux.dev>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
2024-04-30 07:00:24 -04:00
Dave Wysochanski 4917d282f9 netfs: Only call folio_start_fscache() one time for each folio
JIRA: https://issues.redhat.com/browse/RHEL-7959
Upstream Status: linux.git

If a network filesystem using netfs implements a clamp_length()
function, it can set subrequest lengths smaller than a page size.

When we loop through the folios in netfs_rreq_unlock_folios() to
set any folios to be written back, we need to make sure we only
call folio_start_fscache() once for each folio.

Otherwise, this simple testcase:

  mount -o fsc,rsize=1024,wsize=1024 127.0.0.1:/export /mnt/nfs
  dd if=/dev/zero of=/mnt/nfs/file.bin bs=4096 count=1
  1+0 records in
  1+0 records out
  4096 bytes (4.1 kB, 4.0 KiB) copied, 0.0126359 s, 324 kB/s
  echo 3 > /proc/sys/vm/drop_caches
  cat /mnt/nfs/file.bin > /dev/null

will trigger an oops similar to the following:

  page dumped because: VM_BUG_ON_FOLIO(folio_test_private_2(folio))
  ------------[ cut here ]------------
  kernel BUG at include/linux/netfs.h:44!
  ...
  CPU: 5 PID: 134 Comm: kworker/u16:5 Kdump: loaded Not tainted 6.4.0-rc5
  ...
  RIP: 0010:netfs_rreq_unlock_folios+0x68e/0x730 [netfs]
  ...
  Call Trace:
    netfs_rreq_assess+0x497/0x660 [netfs]
    netfs_subreq_terminated+0x32b/0x610 [netfs]
    nfs_netfs_read_completion+0x14e/0x1a0 [nfs]
    nfs_read_completion+0x2f9/0x330 [nfs]
    rpc_free_task+0x72/0xa0 [sunrpc]
    rpc_async_release+0x46/0x70 [sunrpc]
    process_one_work+0x3bd/0x710
    worker_thread+0x89/0x610
    kthread+0x181/0x1c0
    ret_from_fork+0x29/0x50

Fixes: 3d3c950467 ("netfs: Provide readahead and readpage netfs helpers"
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2210612
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/r/20230608214137.856006-1-dwysocha@redhat.com/ # v1
Link: https://lore.kernel.org/r/20230915185704.1082982-1-dwysocha@redhat.com/ # v2
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit df1c357f25d808e30b216188330e708e09e1a412)
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2023-09-25 09:38:45 -04:00
Dave Wysochanski 314261acbd netfs: Further cleanups after struct netfs_inode wrapper introduced
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2129854

commit e81fb4198e27925b151aad1450e0fd607d6733f8
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Thu Jun 9 15:04:01 2022 -0700

    netfs: Further cleanups after struct netfs_inode wrapper introduced

    Change the signature of netfs helper functions to take a struct netfs_inode
    pointer rather than a struct inode pointer where appropriate, thereby
    relieving the need for the network filesystem to convert its internal inode
    format down to the VFS inode only for netfslib to bounce it back up.  For
    type safety, it's better not to do that (and it's less typing too).

    Give netfs_write_begin() an extra argument to pass in a pointer to the
    netfs_inode struct rather than deriving it internally from the file
    pointer.  Note that the ->write_begin() and ->write_end() ops are intended
    to be replaced in the future by netfslib code that manages this without the
    need to call in twice for each page.

    netfs_readpage() and similar are intended to be pointed at directly by the
    address_space_operations table, so must stick to the signature dictated by
    the function pointers there.

    Changes
    =======
    - Updated the kerneldoc comments and documentation [DH].

    Signed-off-by: David Howells <dhowells@redhat.com>
    cc: linux-cachefs@redhat.com
    Link: https://lore.kernel.org/r/CAHk-=wgkwKyNmNdKpQkqZ6DnmUL-x9hp0YBnUGjaPFEAdxDTbw@mail.gmail.com/

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2023-05-11 16:58:24 -04:00
Chris von Recklinghausen 03b7673657 fs: Convert netfs_readpage to netfs_read_folio
Bugzilla: https://bugzilla.redhat.com/2160210

commit 6c62371b7fd77628feb5b806bc29433caecedff8
Author: Matthew Wilcox (Oracle) <willy@infradead.org>
Date:   Fri Apr 29 08:49:28 2022 -0400

    fs: Convert netfs_readpage to netfs_read_folio

    This is straightforward because netfs already worked in terms of folios.

    Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
2023-03-24 11:18:58 -04:00
Chris von Recklinghausen 6c0c15a2d2 fs: Remove aop_flags parameter from netfs_write_begin()
Bugzilla: https://bugzilla.redhat.com/2160210

commit de2a931150177957d37e9c975025604f4a1fe853
Author: Matthew Wilcox (Oracle) <willy@infradead.org>
Date:   Tue Feb 22 10:47:09 2022 -0500

    fs: Remove aop_flags parameter from netfs_write_begin()

    There are no more aop flags left, so remove the parameter.

    Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
2023-03-24 11:18:57 -04:00
Chris von Recklinghausen c20a837503 fs: Remove AOP_FLAG_NOFS
Bugzilla: https://bugzilla.redhat.com/2160210

commit 236d93c4bf2d6da83241cc8e4625e89d9604cb43
Author: Matthew Wilcox (Oracle) <willy@infradead.org>
Date:   Tue Feb 22 10:40:11 2022 -0500

    fs: Remove AOP_FLAG_NOFS

    With all users of this flag gone, we can stop testing whether it's set.

    Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
2023-03-24 11:18:57 -04:00
Xiubo Li 28a6306a90 netfs: Fix dodgy maths
Bugzilla: https://bugzilla.redhat.com/2138981

commit 5e51c627c5acbcf82bb552e17533a79d2a6a2600
Author: David Howells <dhowells@redhat.com>
Date:   Fri Nov 4 15:36:49 2022 +0000

    netfs: Fix dodgy maths

    Fix the dodgy maths in netfs_rreq_unlock_folios().  start_page could be
    inside the folio, in which case the calculation of pgpos will be come up
    with a negative number (though for the moment rreq->start is rounded down
    earlier and folios would have to get merged whilst locked)

    Alter how this works to just frame the tracking in terms of absolute file
    positions, rather than offsets from the start of the I/O request.  This
    simplifies the maths and makes it easier to follow.

    Fix the issue by using folio_pos() and folio_size() to calculate the end
    position of the page.

    Fixes: 3d3c950467 ("netfs: Provide readahead and readpage netfs helpers")
    Reported-by: Matthew Wilcox <willy@infradead.org>
    Signed-off-by: David Howells <dhowells@redhat.com>
    Reviewed-by: Jeff Layton <jlayton@kernel.org>
    Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com>
    cc: linux-cachefs@redhat.com
    cc: linux-fsdevel@vger.kernel.org
    Link: https://lore.kernel.org/r/Y2SJw7w1IsIik3nb@casper.infradead.org/
    Link: https://lore.kernel.org/r/166757988611.950645.7626959069846893164.stgit@warthog.procyon.org.uk/ # v2

Signed-off-by: Xiubo Li <xiubli@redhat.com>
2022-12-19 22:21:48 +08:00
Xiubo Li 5575369564 netfs: Fix missing xas_retry() calls in xarray iteration
Bugzilla: https://bugzilla.redhat.com/2138981

commit 7e043a80b5dae5c2d2cf84031501de7827fd6c00
Author: David Howells <dhowells@redhat.com>
Date:   Thu Nov 3 16:08:14 2022 +0000

    netfs: Fix missing xas_retry() calls in xarray iteration

    netfslib has a number of places in which it performs iteration of an xarray
    whilst being under the RCU read lock.  It *should* call xas_retry() as the
    first thing inside of the loop and do "continue" if it returns true in case
    the xarray walker passed out a special value indicating that the walk needs
    to be redone from the root[*].

    Fix this by adding the missing retry checks.

    [*] I wonder if this should be done inside xas_find(), xas_next_node() and
        suchlike, but I'm told that's not an simple change to effect.

    This can cause an oops like that below.  Note the faulting address - this
    is an internal value (|0x2) returned from xarray.

    BUG: kernel NULL pointer dereference, address: 0000000000000402
    ...
    RIP: 0010:netfs_rreq_unlock+0xef/0x380 [netfs]
    ...
    Call Trace:
     netfs_rreq_assess+0xa6/0x240 [netfs]
     netfs_readpage+0x173/0x3b0 [netfs]
     ? init_wait_var_entry+0x50/0x50
     filemap_read_page+0x33/0xf0
     filemap_get_pages+0x2f2/0x3f0
     filemap_read+0xaa/0x320
     ? do_filp_open+0xb2/0x150
     ? rmqueue+0x3be/0xe10
     ceph_read_iter+0x1fe/0x680 [ceph]
     ? new_sync_read+0x115/0x1a0
     new_sync_read+0x115/0x1a0
     vfs_read+0xf3/0x180
     ksys_read+0x5f/0xe0
     do_syscall_64+0x38/0x90
     entry_SYSCALL_64_after_hwframe+0x44/0xae

    Changes:
    ========
    ver #2)
     - Changed an unsigned int to a size_t to reduce the likelihood of an
       overflow as per Willy's suggestion.
     - Added an additional patch to fix the maths.

    Fixes: 3d3c950467 ("netfs: Provide readahead and readpage netfs helpers")
    Reported-by: George Law <glaw@redhat.com>
    Signed-off-by: David Howells <dhowells@redhat.com>
    Reviewed-by: Jeff Layton <jlayton@kernel.org>
    Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com>
    cc: Matthew Wilcox <willy@infradead.org>
    cc: linux-cachefs@redhat.com
    cc: linux-fsdevel@vger.kernel.org
    Link: https://lore.kernel.org/r/166749229733.107206.17482609105741691452.stgit@warthog.procyon.org.uk/ # v1
    Link: https://lore.kernel.org/r/166757987929.950645.12595273010425381286.stgit@warthog.procyon.org.uk/ # v2

Signed-off-by: Xiubo Li <xiubli@redhat.com>
2022-12-19 22:21:32 +08:00
Jeffrey Layton 9e2861f576 netfs: do not unlock and put the folio twice
Bugzilla: https://bugzilla.redhat.com/1229736

commit fac47b43c760ea90e64b895dba60df0327be7775
Author: Xiubo Li <xiubli@redhat.com>
Date:   Mon Jul 11 12:11:21 2022 +0800

    netfs: do not unlock and put the folio twice

    check_write_begin() will unlock and put the folio when return
    non-zero.  So we should avoid unlocking and putting it twice in
    netfs layer.

    Change the way ->check_write_begin() works in the following two ways:

     (1) Pass it a pointer to the folio pointer, allowing it to unlock and put
         the folio prior to doing the stuff it wants to do, provided it clears
         the folio pointer.

     (2) Change the return values such that 0 with folio pointer set means
         continue, 0 with folio pointer cleared means re-get and all error
         codes indicating an error (no special treatment for -EAGAIN).

    [ bagasdotme: use Sphinx code text syntax for *foliop pointer ]

    Cc: stable@vger.kernel.org
    Link: https://tracker.ceph.com/issues/56423
    Link: https://lore.kernel.org/r/cf169f43-8ee7-8697-25da-0204d1b4343e@redhat.com
    Co-developed-by: David Howells <dhowells@redhat.com>
    Signed-off-by: Xiubo Li <xiubli@redhat.com>
    Signed-off-by: David Howells <dhowells@redhat.com>
    Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
    Signed-off-by: Ilya Dryomov <idryomov@gmail.com>

Signed-off-by: Jeffrey Layton <jlayton@redhat.com>
2022-08-29 11:10:23 -04:00
Jeffrey Layton 33382c22fa netfs: Fix gcc-12 warning by embedding vfs inode in netfs_i_context
Bugzilla: http://bugzilla.redhat.com/1229736

commit 874c8ca1e60b2c564a48f7e7acc40d328d5c8733
Author: David Howells <dhowells@redhat.com>
Date:   Thu Jun 9 21:46:04 2022 +0100

    netfs: Fix gcc-12 warning by embedding vfs inode in netfs_i_context

    While randstruct was satisfied with using an open-coded "void *" offset
    cast for the netfs_i_context <-> inode casting, __builtin_object_size() as
    used by FORTIFY_SOURCE was not as easily fooled.  This was causing the
    following complaint[1] from gcc v12:

      In file included from include/linux/string.h:253,
                       from include/linux/ceph/ceph_debug.h:7,
                       from fs/ceph/inode.c:2:
      In function 'fortify_memset_chk',
          inlined from 'netfs_i_context_init' at include/linux/netfs.h:326:2,
          inlined from 'ceph_alloc_inode' at fs/ceph/inode.c:463:2:
      include/linux/fortify-string.h:242:25: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
        242 |                         __write_overflow_field(p_size_field, size);
            |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Fix this by embedding a struct inode into struct netfs_i_context (which
    should perhaps be renamed to struct netfs_inode).  The struct inode
    vfs_inode fields are then removed from the 9p, afs, ceph and cifs inode
    structs and vfs_inode is then simply changed to "netfs.inode" in those
    filesystems.

    Further, rename netfs_i_context to netfs_inode, get rid of the
    netfs_inode() function that converted a netfs_i_context pointer to an
    inode pointer (that can now be done with &ctx->inode) and rename the
    netfs_i_context() function to netfs_inode() (which is now a wrapper
    around container_of()).

    Most of the changes were done with:

      perl -p -i -e 's/vfs_inode/netfs.inode/'g \
            `git grep -l 'vfs_inode' -- fs/{9p,afs,ceph,cifs}/*.[ch]`

    Kees suggested doing it with a pair structure[2] and a special
    declarator to insert that into the network filesystem's inode
    wrapper[3], but I think it's cleaner to embed it - and then it doesn't
    matter if struct randomisation reorders things.

    Dave Chinner suggested using a filesystem-specific VFS_I() function in
    each filesystem to convert that filesystem's own inode wrapper struct
    into the VFS inode struct[4].

    Version #2:
     - Fix a couple of missed name changes due to a disabled cifs option.
     - Rename nfs_i_context to nfs_inode
     - Use "netfs" instead of "nic" as the member name in per-fs inode wrapper
       structs.

    [ This also undoes commit 507160f46c55 ("netfs: gcc-12: temporarily
      disable '-Wattribute-warning' for now") that is no longer needed ]

    Fixes: bc899ee1c898 ("netfs: Add a netfs inode context")
    Reported-by: Jeff Layton <jlayton@kernel.org>
    Signed-off-by: David Howells <dhowells@redhat.com>
    Reviewed-by: Jeff Layton <jlayton@kernel.org>
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Reviewed-by: Xiubo Li <xiubli@redhat.com>
    cc: Jonathan Corbet <corbet@lwn.net>
    cc: Eric Van Hensbergen <ericvh@gmail.com>
    cc: Latchesar Ionkov <lucho@ionkov.net>
    cc: Dominique Martinet <asmadeus@codewreck.org>
    cc: Christian Schoenebeck <linux_oss@crudebyte.com>
    cc: Marc Dionne <marc.dionne@auristor.com>
    cc: Ilya Dryomov <idryomov@gmail.com>
    cc: Steve French <smfrench@gmail.com>
    cc: William Kucharski <william.kucharski@oracle.com>
    cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
    cc: Dave Chinner <david@fromorbit.com>
    cc: linux-doc@vger.kernel.org
    cc: v9fs-developer@lists.sourceforge.net
    cc: linux-afs@lists.infradead.org
    cc: ceph-devel@vger.kernel.org
    cc: linux-cifs@vger.kernel.org
    cc: samba-technical@lists.samba.org
    cc: linux-fsdevel@vger.kernel.org
    cc: linux-hardening@vger.kernel.org
    Link: https://lore.kernel.org/r/d2ad3a3d7bdd794c6efb562d2f2b655fb67756b9.camel@kernel.org/ [1]
    Link: https://lore.kernel.org/r/20220517210230.864239-1-keescook@chromium.org/ [2]
    Link: https://lore.kernel.org/r/20220518202212.2322058-1-keescook@chromium.org/ [3]
    Link: https://lore.kernel.org/r/20220524101205.GI2306852@dread.disaster.area/ [4]
    Link: https://lore.kernel.org/r/165296786831.3591209.12111293034669289733.stgit@warthog.procyon.org.uk/ # v1
    Link: https://lore.kernel.org/r/165305805651.4094995.7763502506786714216.stgit@warthog.procyon.org.uk # v2
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Jeffrey Layton <jlayton@redhat.com>
2022-08-22 12:32:29 -04:00
Jeffrey Layton fbe9d5891f netfs: Split fs/netfs/read_helper.c
Bugzilla: http://bugzilla.redhat.com/1229736

commit 16211268fcb36672a84359362c2fc2c4695b0fc4
Author: David Howells <dhowells@redhat.com>
Date:   Tue Mar 1 14:35:58 2022 +0000

    netfs: Split fs/netfs/read_helper.c

    Split fs/netfs/read_helper.c into two pieces, one to deal with buffered
    writes and one to deal with the I/O mechanism.

    Changes
    =======
    ver #2)
     - Add kdoc reference to new file.

    Signed-off-by: David Howells <dhowells@redhat.com>
    Reviewed-by: Jeff Layton <jlayton@kernel.org>
    cc: linux-cachefs@redhat.com

    Link: https://lore.kernel.org/r/164623005586.3564931.6149556072728481767.stgit@warthog.procyon.org.uk/ # v1
    Link: https://lore.kernel.org/r/164678217075.1200972.5101072043126828757.stgit@warthog.procyon.org.uk/ # v2
    Link: https://lore.kernel.org/r/164692919953.2099075.7156989585513833046.stgit@warthog.procyon.org.uk/ # v3

Signed-off-by: Jeffrey Layton <jlayton@redhat.com>
2022-08-22 12:32:26 -04:00