19 Aug, 2020

1 commit

  • commit cb0aae0e31c632c407a2cab4307be85a001d4d98 upstream.

    v9fs_mount
    v9fs_session_init
    v9fs_cache_session_get_cookie
    v9fs_random_cachetag -->alloc cachetag
    v9ses->fscache = fscache_acquire_cookie -->maybe NULL
    sb = sget -->fail, goto clunk
    clunk_fid:
    v9fs_session_close
    if (v9ses->fscache) -->NULL
    kfree(v9ses->cachetag)

    Thus memleak happens.

    Link: http://lkml.kernel.org/r/20200615012153.89538-1-zhengbin13@huawei.com
    Fixes: 60e78d2c993e ("9p: Add fscache support to 9p")
    Cc: # v2.6.32+
    Signed-off-by: Zheng Bin
    Signed-off-by: Dominique Martinet
    Signed-off-by: Greg Kroah-Hartman

    Zheng Bin
     

28 Sep, 2019

1 commit

  • Pull 9p updates from Dominique Martinet:
    "Some of the usual small fixes and cleanup.

    Small fixes all around:
    - avoid overlayfs copy-up for PRIVATE mmaps
    - KUMSAN uninitialized warning for transport error
    - one syzbot memory leak fix in 9p cache
    - internal API cleanup for v9fs_fill_super"

    * tag '9p-for-5.4' of git://github.com/martinetd/linux:
    9p/vfs_super.c: Remove unused parameter data in v9fs_fill_super
    9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie
    9p: Transport error uninitialized
    9p: avoid attaching writeback_fid on mmap with type PRIVATE

    Linus Torvalds
     

03 Sep, 2019

3 commits

  • v9fs_fill_super has a param 'void *data' which is unused in the
    function.

    This patch removes the 'void *data' param in v9fs_fill_super and changes
    the parameters in all function calls of v9fs_fill_super.

    Link: http://lkml.kernel.org/r/20190523165619.GA4209@bharath12345-Inspiron-5559
    Signed-off-by: Bharath Vedartham
    Signed-off-by: Dominique Martinet

    Bharath Vedartham
     
  • v9fs_cache_session_get_cookie assigns a random cachetag to v9ses->cachetag,
    if the cachetag is not assigned previously.

    v9fs_random_cachetag allocates memory to v9ses->cachetag with kmalloc and uses
    scnprintf to fill it up with a cachetag.

    But if scnprintf fails, v9ses->cachetag is not freed in the current
    code causing a memory leak.

    Fix this by freeing v9ses->cachetag it v9fs_random_cachetag fails.

    This was reported by syzbot, the link to the report is below:
    https://syzkaller.appspot.com/bug?id=f012bdf297a7a4c860c38a88b44fbee43fd9bbf3

    Link: http://lkml.kernel.org/r/20190522194519.GA5313@bharath12345-Inspiron-5559
    Reported-by: syzbot+3a030a73b6c1e9833815@syzkaller.appspotmail.com
    Signed-off-by: Bharath Vedartham
    Signed-off-by: Dominique Martinet

    Bharath Vedartham
     
  • Currently on mmap cache policy, we always attach writeback_fid
    whether mmap type is SHARED or PRIVATE. However, in the use case
    of kata-container which combines 9p(Guest OS) with overlayfs(Host OS),
    this behavior will trigger overlayfs' copy-up when excute command
    inside container.

    Link: http://lkml.kernel.org/r/20190820100325.10313-1-cgxu519@zoho.com.cn
    Signed-off-by: Chengguang Xu
    Signed-off-by: Dominique Martinet

    Chengguang Xu
     

30 Aug, 2019

1 commit

  • struct p9_wstat and struct p9_stat_dotl indicate that the
    wire transport uses u32 and u64 fields for timestamps.
    Fill in the appropriate limits to avoid inconsistencies in
    the vfs cached inode times when timestamps are outside the
    permitted range.

    Note that the upper bound for V9FS_PROTO_2000L is retained as S64_MAX.
    This is because that is the upper bound supported by vfs.

    Signed-off-by: Deepa Dinamani
    Acked-by: Jeff Layton
    Cc: ericvh@gmail.com
    Cc: lucho@ionkov.net
    Cc: asmadeus@codewreck.org
    Cc: v9fs-developer@lists.sourceforge.net

    Deepa Dinamani
     

13 Jul, 2019

1 commit

  • Fix the callback 9p passes to read_cache_page to actually have the
    proper type expected. Casting around function pointers can easily
    hide typing bugs, and defeats control flow protection.

    Link: http://lkml.kernel.org/r/20190520055731.24538-5-hch@lst.de
    Signed-off-by: Christoph Hellwig
    Reviewed-by: Kees Cook
    Cc: Sami Tolvanen
    Cc: Nick Desaulniers
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Hellwig
     

31 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation this program is
    distributed in the hope that it will be useful but without any
    warranty without even the implied warranty of merchantability or
    fitness for a particular purpose see the gnu general public license
    for more details you should have received a copy of the gnu general
    public license along with this program if not write to free software
    foundation 51 franklin street fifth floor boston ma 02111 1301 usa

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 27 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Richard Fontana
    Reviewed-by: Alexios Zavras
    Reviewed-by: Steve Winslow
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190528170026.981318839@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

21 May, 2019

1 commit


02 May, 2019

1 commit


18 Mar, 2019

1 commit

  • Pull 9p updates from Dominique Martinet:
    "Here is a 9p update for 5.1; there honestly hasn't been much.

    Two fixes (leak on invalid mount argument and possible deadlock on
    i_size update on 32bit smp) and a fall-through warning cleanup"

    * tag '9p-for-5.1' of git://github.com/martinetd/linux:
    9p/net: fix memory leak in p9_client_create
    9p: use inode->i_lock to protect i_size_write() under 32-bit
    9p: mark expected switch fall-through

    Linus Torvalds
     

13 Mar, 2019

1 commit

  • All users of VM_MAX_READAHEAD actually convert it to kbytes and then to
    pages. Define the macro explicitly as (SZ_128K / PAGE_SIZE). This
    simplifies the expression in every filesystem. Also rename the macro to
    VM_READAHEAD_PAGES to properly convey its meaning. Finally remove unused
    VM_MIN_READAHEAD

    [akpm@linux-foundation.org: fix fs/io_uring.c, per Stephen]
    Link: http://lkml.kernel.org/r/20181221144053.24318-1-nborisov@suse.com
    Signed-off-by: Nikolay Borisov
    Reviewed-by: Matthew Wilcox
    Reviewed-by: David Hildenbrand
    Cc: Jens Axboe
    Cc: Eric Van Hensbergen
    Cc: Latchesar Ionkov
    Cc: Dominique Martinet
    Cc: David Howells
    Cc: Chris Mason
    Cc: Josef Bacik
    Cc: David Sterba
    Cc: Miklos Szeredi
    Cc: Stephen Rothwell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Nikolay Borisov
     

03 Mar, 2019

1 commit

  • Use inode->i_lock to protect i_size_write(), else i_size_read() in
    generic_fillattr() may loop infinitely in read_seqcount_begin() when
    multiple processes invoke v9fs_vfs_getattr() or v9fs_vfs_getattr_dotl()
    simultaneously under 32-bit SMP environment, and a soft lockup will be
    triggered as show below:

    watchdog: BUG: soft lockup - CPU#5 stuck for 22s! [stat:2217]
    Modules linked in:
    CPU: 5 PID: 2217 Comm: stat Not tainted 5.0.0-rc1-00005-g7f702faf5a9e #4
    Hardware name: Generic DT based system
    PC is at generic_fillattr+0x104/0x108
    LR is at 0xec497f00
    pc : [] lr : [] psr: 200c0013
    sp : ec497e20 ip : ed608030 fp : ec497e3c
    r10: 00000000 r9 : ec497f00 r8 : ed608030
    r7 : ec497ebc r6 : ec497f00 r5 : ee5c1550 r4 : ee005780
    r3 : 0000052d r2 : 00000000 r1 : ec497f00 r0 : ed608030
    Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
    Control: 10c5387d Table: ac48006a DAC: 00000051
    CPU: 5 PID: 2217 Comm: stat Not tainted 5.0.0-rc1-00005-g7f702faf5a9e #4
    Hardware name: Generic DT based system
    Backtrace:
    [] (dump_backtrace) from [] (show_stack+0x20/0x24)
    [] (show_stack) from [] (dump_stack+0xb0/0xdc)
    [] (dump_stack) from [] (show_regs+0x1c/0x20)
    [] (show_regs) from [] (watchdog_timer_fn+0x280/0x2f8)
    [] (watchdog_timer_fn) from [] (__hrtimer_run_queues+0x18c/0x380)
    [] (__hrtimer_run_queues) from [] (hrtimer_run_queues+0xb8/0xf0)
    [] (hrtimer_run_queues) from [] (run_local_timers+0x28/0x64)
    [] (run_local_timers) from [] (update_process_times+0x3c/0x6c)
    [] (update_process_times) from [] (tick_nohz_handler+0xe0/0x1bc)
    [] (tick_nohz_handler) from [] (arch_timer_handler_virt+0x38/0x48)
    [] (arch_timer_handler_virt) from [] (handle_percpu_devid_irq+0x8c/0x240)
    [] (handle_percpu_devid_irq) from [] (generic_handle_irq+0x34/0x44)
    [] (generic_handle_irq) from [] (__handle_domain_irq+0x6c/0xc4)
    [] (__handle_domain_irq) from [] (gic_handle_irq+0x4c/0x88)
    [] (gic_handle_irq) from [] (__irq_svc+0x70/0x98)
    [] (generic_fillattr) from [] (v9fs_vfs_getattr_dotl+0x74/0xa4)
    [] (v9fs_vfs_getattr_dotl) from [] (vfs_getattr_nosec+0x68/0x7c)
    [] (vfs_getattr_nosec) from [] (vfs_getattr+0x44/0x48)
    [] (vfs_getattr) from [] (vfs_statx+0x9c/0xec)
    [] (vfs_statx) from [] (sys_lstat64+0x48/0x78)
    [] (sys_lstat64) from [] (ret_fast_syscall+0x0/0x28)

    [dominique.martinet@cea.fr: updated comment to not refer to a function
    in another subsystem]
    Link: http://lkml.kernel.org/r/20190124063514.8571-2-houtao1@huawei.com
    Cc: stable@vger.kernel.org
    Fixes: 7549ae3e81cc ("9p: Use the i_size_[read, write]() macros instead of using inode->i_size directly.")
    Reported-by: Xing Gaopeng
    Signed-off-by: Hou Tao
    Signed-off-by: Dominique Martinet

    Hou Tao
     

02 Nov, 2018

1 commit

  • Pull AFS updates from Al Viro:
    "AFS series, with some iov_iter bits included"

    * 'work.afs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (26 commits)
    missing bits of "iov_iter: Separate type from direction and use accessor functions"
    afs: Probe multiple fileservers simultaneously
    afs: Fix callback handling
    afs: Eliminate the address pointer from the address list cursor
    afs: Allow dumping of server cursor on operation failure
    afs: Implement YFS support in the fs client
    afs: Expand data structure fields to support YFS
    afs: Get the target vnode in afs_rmdir() and get a callback on it
    afs: Calc callback expiry in op reply delivery
    afs: Fix FS.FetchStatus delivery from updating wrong vnode
    afs: Implement the YFS cache manager service
    afs: Remove callback details from afs_callback_break struct
    afs: Commit the status on a new file/dir/symlink
    afs: Increase to 64-bit volume ID and 96-bit vnode ID for YFS
    afs: Don't invoke the server to read data beyond EOF
    afs: Add a couple of tracepoints to log I/O errors
    afs: Handle EIO from delivery function
    afs: Fix TTL on VL server and address lists
    afs: Implement VL server rotation
    afs: Improve FS server rotation error handling
    ...

    Linus Torvalds
     

24 Oct, 2018

1 commit

  • In the iov_iter struct, separate the iterator type from the iterator
    direction and use accessor functions to access them in most places.

    Convert a bunch of places to use switch-statements to access them rather
    then chains of bitwise-AND statements. This makes it easier to add further
    iterator types. Also, this can be more efficient as to implement a switch
    of small contiguous integers, the compiler can use ~50% fewer compare
    instructions than it has to use bitwise-and instructions.

    Further, cease passing the iterator type into the iterator setup function.
    The iterator function can set that itself. Only the direction is required.

    Signed-off-by: David Howells

    David Howells
     

08 Sep, 2018

5 commits

  • the 9p client code overwrites our glock.client_id pointing to a static
    buffer by an allocated string holding the network provided value which
    we do not care about; free and reset the value as appropriate.

    This is almost identical to the leak in v9fs_file_getlock() fixed by
    Al Viro in commit ce85dd58ad5a6 ("9p: we are leaking glock.client_id
    in v9fs_file_getlock()"), which was returned as an error by a coverity
    false positive -- while we are here attempt to make the code slightly
    more robust to future change of the net/9p/client code and hopefully
    more clear to coverity that there is no problem.

    Link: http://lkml.kernel.org/r/1536339057-21974-5-git-send-email-asmadeus@codewreck.org
    Signed-off-by: Dominique Martinet

    Dominique Martinet
     
  • iattr is passed to v9fs_vfs_setattr_dotl which does send various
    values from iattr over the wire, even if it tells the server to
    only look at iattr.ia_valid fields this could leak some stack data.

    Link: http://lkml.kernel.org/r/1536339057-21974-2-git-send-email-asmadeus@codewreck.org
    Addresses-Coverity-ID: 1195601 ("Uninitalized scalar variable")
    Signed-off-by: Dominique Martinet

    Dominique Martinet
     
  • The default P9_LOCK_TIMEOUT can be too long for some users exporting
    a local file system to a guest VM (30s), make this configurable at
    mount time.

    Link: http://lkml.kernel.org/r/1536295827-3181-1-git-send-email-asmadeus@codewreck.org
    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195727
    Signed-off-by: Dinu-Razvan Chis-Serban
    Signed-off-by: Dominique Martinet

    Dinu-Razvan Chis-Serban
     
  • v9fs_dir_readdir() could deadloop if a struct was sent with a size set
    to -2

    Link: http://lkml.kernel.org/r/1536134432-11997-1-git-send-email-asmadeus@codewreck.org
    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=88021
    Signed-off-by: Gertjan Halkes
    Signed-off-by: Dominique Martinet

    Gertjan Halkes
     
  • Replace "fallthough" with a proper "fall through" annotation.

    This fix is part of the ongoing efforts to enabling -Wimplicit-fallthrough

    Link: http://lkml.kernel.org/r/20180903193806.GA11258@embeddedor.com
    Addresses-Coverity-ID: 402012 ("Missing break in switch")
    Signed-off-by: Gustavo A. R. Silva
    Signed-off-by: Dominique Martinet

    Gustavo A. R. Silva
     

29 Aug, 2018

1 commit

  • p9stat_read will call p9stat_free on error, we should only free the
    struct content on success.

    There also is no need to "p9stat_init" st as the read function will
    zero the whole struct for us anyway, so clean up the code a bit while
    we are here.

    Link: http://lkml.kernel.org/r/1535410108-20650-1-git-send-email-asmadeus@codewreck.org
    Signed-off-by: Dominique Martinet
    Reported-by: syzbot+d4252148d198410b864f@syzkaller.appspotmail.com

    Dominique Martinet
     

18 Aug, 2018

1 commit

  • Pull 9p updates from Dominique Martinet:
    "This contains mostly fixes (6 to be backported to stable) and a few
    changes, here is the breakdown:

    - rework how fids are attributed by replacing some custom tracking in
    a list by an idr

    - for packet-based transports (virtio/rdma) validate that the packet
    length matches what the header says

    - a few race condition fixes found by syzkaller

    - missing argument check when NULL device is passed in sys_mount

    - a few virtio fixes

    - some spelling and style fixes"

    * tag '9p-for-4.19-2' of git://github.com/martinetd/linux: (21 commits)
    net/9p/trans_virtio.c: add null terminal for mount tag
    9p/virtio: fix off-by-one error in sg list bounds check
    9p: fix whitespace issues
    9p: fix multiple NULL-pointer-dereferences
    fs/9p/xattr.c: catch the error of p9_client_clunk when setting xattr failed
    9p: validate PDU length
    net/9p/trans_fd.c: fix race by holding the lock
    net/9p/trans_fd.c: fix race-condition by flushing workqueue before the kfree()
    net/9p/virtio: Fix hard lockup in req_done
    net/9p/trans_virtio.c: fix some spell mistakes in comments
    9p/net: Fix zero-copy path in the 9p virtio transport
    9p: Embed wait_queue_head into p9_req_t
    9p: Replace the fidlist with an IDR
    9p: Change p9_fid_create calling convention
    9p: Fix comment on smp_wmb
    net/9p/client.c: version pointer uninitialized
    fs/9p/v9fs.c: fix spelling mistake "Uknown" -> "Unknown"
    net/9p: fix error path of p9_virtio_probe
    9p/net/protocol.c: return -ENOMEM when kmalloc() failed
    net/9p/client.c: add missing '\n' at the end of p9_debug()
    ...

    Linus Torvalds
     

13 Aug, 2018

3 commits

  • In my testing, v9fs_fid_xattr_set will return successfully even if the
    backend ext4 filesystem has no space to store xattr key-value. That will
    cause inconsistent behavior between front end and back end. The reason is
    that lsetxattr will be triggered by p9_client_clunk, and unfortunately we
    did not catch the error. This patch will catch the error to notify upper
    caller.

    p9_client_clunk (in 9p)
    p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid);
    v9fs_clunk (in qemu)
    put_fid
    free_fid
    v9fs_xattr_fid_clunk
    v9fs_co_lsetxattr
    s->ops->lsetxattr
    ext4_xattr_user_set (in host ext4 filesystem)

    Link: http://lkml.kernel.org/r/5B57EACC.2060900@huawei.com
    Signed-off-by: Jun Piao
    Cc: Eric Van Hensbergen
    Cc: Ron Minnich
    Cc: Latchesar Ionkov
    Cc: Andrew Morton
    Cc: stable@vger.kernel.org
    Signed-off-by: Dominique Martinet

    piaojun
     
  • fix spelling mistake in pr_info message text

    Link: http://lkml.kernel.org/r/20180526150650.10562-1-colin.king@canonical.com
    Signed-off-by: Colin Ian King
    Cc: Eric Van Hensbergen
    Cc: Ron Minnich
    Cc: Latchesar Ionkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Dominique Martinet

    Colin Ian King
     
  • Use new return type vm_fault_t for page_mkwrite handler.

    See 1c8f422059ae ("mm: change return type to vm_fault_t") for reference.

    Link: http://lkml.kernel.org/r/20180702154928.GA3964@jordon-HP-15-Notebook-PC
    Signed-off-by: Souptick Joarder
    Reviewed-by: Matthew Wilcox
    Acked-by: Jun Piao
    Cc: Eric Van Hensbergen
    Cc: Ron Minnich
    Cc: Latchesar Ionkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Dominique Martinet

    Souptick Joarder
     

12 Jul, 2018

3 commits


13 Jun, 2018

1 commit

  • The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
    patch replaces cases of:

    kmalloc(a * b, gfp)

    with:
    kmalloc_array(a * b, gfp)

    as well as handling cases of:

    kmalloc(a * b * c, gfp)

    with:

    kmalloc(array3_size(a, b, c), gfp)

    as it's slightly less ugly than:

    kmalloc_array(array_size(a, b), c, gfp)

    This does, however, attempt to ignore constant size factors like:

    kmalloc(4 * 1024, gfp)

    though any constants defined via macros get caught up in the conversion.

    Any factors with a sizeof() of "unsigned char", "char", and "u8" were
    dropped, since they're redundant.

    The tools/ directory was manually excluded, since it has its own
    implementation of kmalloc().

    The Coccinelle script used for this was:

    // Fix redundant parens around sizeof().
    @@
    type TYPE;
    expression THING, E;
    @@

    (
    kmalloc(
    - (sizeof(TYPE)) * E
    + sizeof(TYPE) * E
    , ...)
    |
    kmalloc(
    - (sizeof(THING)) * E
    + sizeof(THING) * E
    , ...)
    )

    // Drop single-byte sizes and redundant parens.
    @@
    expression COUNT;
    typedef u8;
    typedef __u8;
    @@

    (
    kmalloc(
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(unsigned char) * COUNT
    + COUNT
    , ...)
    )

    // 2-factor product with sizeof(type/expression) and identifier or constant.
    @@
    type TYPE;
    expression THING;
    identifier COUNT_ID;
    constant COUNT_CONST;
    @@

    (
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

    // 2-factor product, only identifiers.
    @@
    identifier SIZE, COUNT;
    @@

    - kmalloc
    + kmalloc_array
    (
    - SIZE * COUNT
    + COUNT, SIZE
    , ...)

    // 3-factor product with 1 sizeof(type) or sizeof(expression), with
    // redundant parens removed.
    @@
    expression THING;
    identifier STRIDE, COUNT;
    type TYPE;
    @@

    (
    kmalloc(
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    )

    // 3-factor product with 2 sizeof(variable), with redundant parens removed.
    @@
    expression THING1, THING2;
    identifier COUNT;
    type TYPE1, TYPE2;
    @@

    (
    kmalloc(
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kmalloc(
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    )

    // 3-factor product, only identifiers, with redundant parens removed.
    @@
    identifier STRIDE, SIZE, COUNT;
    @@

    (
    kmalloc(
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    )

    // Any remaining multi-factor products, first at least 3-factor products,
    // when they're not all constants...
    @@
    expression E1, E2, E3;
    constant C1, C2, C3;
    @@

    (
    kmalloc(C1 * C2 * C3, ...)
    |
    kmalloc(
    - (E1) * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - (E1) * (E2) * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - (E1) * (E2) * (E3)
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - E1 * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    )

    // And then all remaining 2 factors products when they're not all constants,
    // keeping sizeof() as the second factor argument.
    @@
    expression THING, E1, E2;
    type TYPE;
    constant C1, C2, C3;
    @@

    (
    kmalloc(sizeof(THING) * C2, ...)
    |
    kmalloc(sizeof(TYPE) * C2, ...)
    |
    kmalloc(C1 * C2 * C3, ...)
    |
    kmalloc(C1 * C2, ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (E2)
    + E2, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * E2
    + E2, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (E2)
    + E2, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * E2
    + E2, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - (E1) * E2
    + E1, E2
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - (E1) * (E2)
    + E1, E2
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - E1 * E2
    + E1, E2
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     

08 Jun, 2018

1 commit

  • Currently when detecting invalid options in option parsing, some
    options(e.g. msize) just set errno and allow to continuously validate
    other options so that it can detect invalid options as much as possible
    and give proper error messages together.

    This patch applies same rule to option 'cache' and 'access' when
    detecting -EINVAL.

    Link: http://lkml.kernel.org/r/1525340676-34072-2-git-send-email-cgxu519@gmx.com
    Signed-off-by: Chengguang Xu
    Reviewed-by: Andrew Morton
    Cc: Eric Van Hensbergen
    Cc: Ron Minnich
    Cc: Latchesar Ionkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Chengguang Xu
     

23 May, 2018

1 commit


08 Apr, 2018

1 commit

  • Pull fscache updates from David Howells:
    "Three patches that fix some of AFS's usage of fscache:

    (1) Need to invalidate the cache if a foreign data change is detected
    on the server.

    (2) Move the vnode ID uniquifier (equivalent to i_generation) from
    the auxiliary data to the index key to prevent a race between
    file delete and a subsequent file create seeing the same index
    key.

    (3) Need to retire cookies that correspond to files that we think got
    deleted on the server.

    Four patches to fix some things in fscache and cachefiles:

    (4) Fix a couple of checker warnings.

    (5) Correctly indicate to the end-of-operation callback whether an
    operation completed or was cancelled.

    (6) Add a check for multiple cookie relinquishment.

    (7) Fix a path through the asynchronous write that doesn't wake up a
    waiter for a page if the cache decides not to write that page,
    but discards it instead.

    A couple of patches to add tracepoints to fscache and cachefiles:

    (8) Add tracepoints for cookie operators, object state machine
    execution, cachefiles object management and cachefiles VFS
    operations.

    (9) Add tracepoints for fscache operation management and page
    wrangling.

    And then three development patches:

    (10) Attach the index key and auxiliary data to the cookie, pass this
    information through various fscache-netfs API functions and get
    rid of the callbacks to the netfs to get it.

    This means that the cache can get at this information, even if
    the netfs goes away. It also means that the cache can be lazy in
    updating the coherency data.

    (11) Pass the object data size through various fscache-netfs API
    rather than calling back to the netfs for it, and store the value
    in the object.

    This makes it easier to correctly resize the object, as the size
    is updated on writes to the cache, rather than calling back out
    to the netfs.

    (12) Maintain a catalogue of allocated cookies. This makes it possible
    to catch cookie collision up front rather than down in the bowels
    of the cache being run from a service thread from the object
    state machine.

    This will also make it possible in the future to reconnect to a
    cookie that's not gone dead yet because it's waiting for
    finalisation of the storage and also make it possible to bring
    cookies online if the cache is added after the cookie has been
    obtained"

    * tag 'fscache-next-20180406' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs:
    fscache: Maintain a catalogue of allocated cookies
    fscache: Pass object size in rather than calling back for it
    fscache: Attach the index key and aux data to the cookie
    fscache: Add more tracepoints
    fscache: Add tracepoints
    fscache: Fix hanging wait on page discarded by writeback
    fscache: Detect multiple relinquishment of a cookie
    fscache: Pass the correct cancelled indications to fscache_op_complete()
    fscache, cachefiles: Fix checker warnings
    afs: Be more aggressive in retiring cached vnodes
    afs: Use the vnode ID uniquifier in the cache key not the aux data
    afs: Invalidate cache on server data change

    Linus Torvalds
     

06 Apr, 2018

4 commits

  • Pass the object size in to fscache_acquire_cookie() and
    fscache_write_page() rather than the netfs providing a callback by which it
    can be received. This makes it easier to update the size of the object
    when a new page is written that extends the object.

    The current object size is also passed by fscache to the check_aux
    function, obviating the need to store it in the aux data.

    Signed-off-by: David Howells
    Acked-by: Anna Schumaker
    Tested-by: Steve Dickson

    David Howells
     
  • When the user uses some syscall, for example mmap(v9fs_file_mmap), it
    will not update atime even if user's was set mnt_flags without
    MNT_NOATIME, because v9fs defaults to settine SB_NOATIME in
    v9fs_set_super.

    For supporting access time updating when the user mounts with relatime,
    we should not set SB_NOATIME by default.

    Link: http://lkml.kernel.org/r/5AB9A377.6080906@huawei.com
    Signed-off-by: Yiwen Jiang
    Reviewed-by: Greg Kurz
    Cc: Eric Van Hensbergen
    Cc: Ron Minnich
    Cc: Latchesar Ionkov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yiwen Jiang
     
  • Check memory allocation result for cachetag in mount option parsing and
    fix potential memory leak in the error case.

    Link: http://lkml.kernel.org/r/1521614889-73446-1-git-send-email-cgxu519@gmx.com
    Signed-off-by: Chengguang Xu
    Reviewed-by: Andrew Morton
    Cc: Eric Van Hensbergen
    Cc: Ron Minnich
    Cc: Latchesar Ionkov
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Chengguang Xu
     
  • If the exported filesystem dir on 9p server doesn't maintain accurate
    i_nlink count, e.g. always reports i_nlink as 1, then 9p should not
    maintain nlink count either, otherwise drop_link would report warning
    with i_nlink being zero.

    For example:

    - overlayfs sets nlink to 1 for merged dir

    - ext4 (with dir_nlink feature enabled) sets nlink to 1 if a dir has
    more than EXT4_LINK_MAX (65000) links.

    In this case, everytime a stat(2) call (getattr) on such exported dirs
    on 9p client side, the i_nlink gets reset to 1, then operations like
    rmdir(2), unlink(2) and rename(2) would cause the dir nlink to go to
    zero (then negative), which results in warnings in drop_nlink() and/or
    inc_nlink() calls.

    This can be reproduced easily as the following steps:

    - export a merged overlayfs dir via qemu virtfs to guest

    - mount the exported virtfs in guest

    - create two sub-directories in the root dir of the mounted 9pfs

    - stat the root dir of 9pfs, this resets nlink to 1

    - remove all subdirs, the second unlink/rmdir would trigger warning

    ------------[ cut here ]------------
    WARNING: CPU: 3 PID: 1284 at fs/inode.c:282 drop_nlink+0x3e/0x50
    ...
    Call Trace:
    dump_stack+0x63/0x81
    __warn+0xcb/0xf0
    warn_slowpath_null+0x1d/0x20
    drop_nlink+0x3e/0x50
    v9fs_remove+0xaa/0x130 [9p]
    v9fs_vfs_rmdir+0x13/0x20 [9p]
    vfs_rmdir+0xb7/0x130
    do_rmdir+0x1b8/0x230
    SyS_unlinkat+0x22/0x30
    do_syscall_64+0x67/0x180
    ---[ end trace 43758d8ba91e603b ]---

    Fix it by leaving i_nlink to be 1 and don't drop nlink if a directory
    has nlink
    Reviewed-by: Yiwen Jiang
    Tested-by: Roman Kapl
    Cc: Caspar Zhang
    Cc: Eric Van Hensbergen
    Cc: Ron Minnich
    Cc: Latchesar Ionkov
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eryu Guan
     

04 Apr, 2018

1 commit

  • Attach copies of the index key and auxiliary data to the fscache cookie so
    that:

    (1) The callbacks to the netfs for this stuff can be eliminated. This
    can simplify things in the cache as the information is still
    available, even after the cache has relinquished the cookie.

    (2) Simplifies the locking requirements of accessing the information as we
    don't have to worry about the netfs object going away on us.

    (3) The cache can do lazy updating of the coherency information on disk.
    As long as the cache is flushed before reboot/poweroff, there's no
    need to update the coherency info on disk every time it changes.

    (4) Cookies can be hashed or put in a tree as the index key is easily
    available. This allows:

    (a) Checks for duplicate cookies can be made at the top fscache layer
    rather than down in the bowels of the cache backend.

    (b) Caching can be added to a netfs object that has a cookie if the
    cache is brought online after the netfs object is allocated.

    A certain amount of space is made in the cookie for inline copies of the
    data, but if it won't fit there, extra memory will be allocated for it.

    The downside of this is that live cache operation requires more memory.

    Signed-off-by: David Howells
    Acked-by: Anna Schumaker
    Tested-by: Steve Dickson

    David Howells
     

02 Jan, 2018

1 commit

  • This link is replicated in most filesystems' config stanzas. Referring
    to an archived version of that site is pointless as it mostly deals with
    patches; user documentation is available elsewhere.

    Signed-off-by: Adam Borowski
    CC: Alexander Viro
    Reviewed-by: Darrick J. Wong
    Acked-by: Jan Kara
    Acked-by: Dave Kleikamp
    Acked-by: David Sterba
    Acked-by: "Yan, Zheng"
    Acked-by: Chao Yu
    Acked-by: Jaegeuk Kim
    Acked-by: Steve French
    Signed-off-by: Jonathan Corbet

    Adam Borowski
     

28 Nov, 2017

1 commit

  • This is a pure automated search-and-replace of the internal kernel
    superblock flags.

    The s_flags are now called SB_*, with the names and the values for the
    moment mirroring the MS_* flags that they're equivalent to.

    Note how the MS_xyz flags are the ones passed to the mount system call,
    while the SB_xyz flags are what we then use in sb->s_flags.

    The script to do this was:

    # places to look in; re security/*: it generally should *not* be
    # touched (that stuff parses mount(2) arguments directly), but
    # there are two places where we really deal with superblock flags.
    FILES="drivers/mtd drivers/staging/lustre fs ipc mm \
    include/linux/fs.h include/uapi/linux/bfs_fs.h \
    security/apparmor/apparmorfs.c security/apparmor/include/lib.h"
    # the list of MS_... constants
    SYMS="RDONLY NOSUID NODEV NOEXEC SYNCHRONOUS REMOUNT MANDLOCK \
    DIRSYNC NOATIME NODIRATIME BIND MOVE REC VERBOSE SILENT \
    POSIXACL UNBINDABLE PRIVATE SLAVE SHARED RELATIME KERNMOUNT \
    I_VERSION STRICTATIME LAZYTIME SUBMOUNT NOREMOTELOCK NOSEC BORN \
    ACTIVE NOUSER"

    SED_PROG=
    for i in $SYMS; do SED_PROG="$SED_PROG -e s/MS_$i/SB_$i/g"; done

    # we want files that contain at least one of MS_...,
    # with fs/namespace.c and fs/pnode.c excluded.
    L=$(for i in $SYMS; do git grep -w -l MS_$i $FILES; done| sort|uniq|grep -v '^fs/namespace.c'|grep -v '^fs/pnode.c')

    for f in $L; do sed -i $f $SED_PROG; done

    Requested-by: Al Viro
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

23 Nov, 2017

1 commit