Commit Graph

40 Commits

Author SHA1 Message Date
Jeff Moyer 6968537ec1 io_uring: remove io_req_put_rsrc_locked()
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit c29006a2456bc9c2aea09e4a8958b4d9a7dfcb5a
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Fri Apr 5 16:50:05 2024 +0100

    io_uring: remove io_req_put_rsrc_locked()
    
    io_req_put_rsrc_locked() is a weird shim function around
    io_req_put_rsrc(). All calls to io_req_put_rsrc() require holding
    ->uring_lock, so we can just use it directly.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/a195bc78ac3d2c6fbaea72976e982fe51e50ecdd.1712331455.git.asml.silence@gmail.com
    Reviewed-by: Ming Lei <ming.lei@redhat.com>
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 17:15:44 -05:00
Jeff Moyer f1ebf01f03 io_uring/alloc_cache: switch to array based caching
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit 414d0f45c316221acbf066658afdbae5b354a5cc
Author: Jens Axboe <axboe@kernel.dk>
Date:   Wed Mar 20 15:19:44 2024 -0600

    io_uring/alloc_cache: switch to array based caching
    
    Currently lists are being used to manage this, but best practice is
    usually to have these in an array instead as that it cheaper to manage.
    
    Outside of that detail, games are also played with KASAN as the list
    is inside the cached entry itself.
    
    Finally, all users of this need a struct io_cache_entry embedded in
    their struct, which is union'ized with something else in there that
    isn't used across the free -> realloc cycle.
    
    Get rid of all of that, and simply have it be an array. This will not
    change the memory used, as we're just trading an 8-byte member entry
    for the per-elem array size.
    
    This reduces the overhead of the recycled allocations, and it reduces
    the amount of code code needed to support recycling to about half of
    what it currently is.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 16:56:44 -05:00
Jeff Moyer 8277b2cb1a io_uring: Don't include af_unix.h.
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit 3fb1764c6b57808ddab7fe7c242fa04c2479ef0a
Author: Kuniyuki Iwashima <kuniyu@amazon.com>
Date:   Mon Feb 12 15:42:36 2024 -0800

    io_uring: Don't include af_unix.h.
    
    Changes to AF_UNIX trigger rebuild of io_uring, but io_uring does
    not use AF_UNIX anymore.
    
    Let's not include af_unix.h and instead include necessary headers.
    
    Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
    Link: https://lore.kernel.org/r/20240212234236.63714-1-kuniyu@amazon.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 15:43:44 -05:00
Jeff Moyer c015a3abab io_uring/rsrc: improve code generation for fixed file assignment
JIRA: https://issues.redhat.com/browse/RHEL-27755

commit 3f302388d45855c0b24802e7b414e3fb29f172e3
Author: Jens Axboe <axboe@kernel.dk>
Date:   Thu Jan 11 13:34:33 2024 -0700

    io_uring/rsrc: improve code generation for fixed file assignment
    
    For the normal read/write path, we have already locked the ring
    submission side when assigning the file. This causes branch
    mispredictions when we then check and try and lock again in
    io_req_set_rsrc_node(). As this is a very hot path, this matters.
    
    Add a basic helper that already assumes we already have it locked,
    and use that in io_file_get_fixed().
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-07-02 14:33:36 -04:00
Jeff Moyer bfa2f16824 io_uring/rsrc: Annotate struct io_mapped_ubuf with __counted_by
JIRA: https://issues.redhat.com/browse/RHEL-27755

commit 04d9244c9420db33149608a566399176d57690f8
Author: Kees Cook <keescook@chromium.org>
Date:   Thu Aug 17 14:21:47 2023 -0700

    io_uring/rsrc: Annotate struct io_mapped_ubuf with __counted_by
    
    Prepare for the coming implementation by GCC and Clang of the __counted_by
    attribute. Flexible array members annotated with __counted_by can have
    their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
    (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
    functions).
    
    As found with Coccinelle[1], add __counted_by for struct io_mapped_ubuf.
    
    [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
    
    Cc: Jens Axboe <axboe@kernel.dk>
    Cc: Pavel Begunkov <asml.silence@gmail.com>
    Cc: io-uring@vger.kernel.org
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Reviewed-by: "Gustavo A. R. Silva" <gustavoars@kernel.org>
    Link: https://lore.kernel.org/r/20230817212146.never.853-kees@kernel.org
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-07-02 09:39:34 -04:00
Jeff Moyer bc8154d90e io_uring: drop any code related to SCM_RIGHTS
JIRA: https://issues.redhat.com/browse/RHEL-36366
CVE: CVE-2023-52656
Conflicts: We backported commit 4f0b9194bc11 ("fs: Rename
  anon_inode_getfile_secure() and anon_inode_getfd_secure()"), which
  obviously causes a conflict in io_uring_get_file().

commit 6e5e6d274956305f1fc0340522b38f5f5be74bdb
Author: Jens Axboe <axboe@kernel.dk>
Date:   Tue Dec 19 12:36:34 2023 -0700

    io_uring: drop any code related to SCM_RIGHTS
    
    This is dead code after we dropped support for passing io_uring fds
    over SCM_RIGHTS, get rid of it.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-05-15 13:58:17 -04:00
Felix Maurer 6c44713ac7 io_uring/af_unix: disable sending io_uring over sockets
JIRA: https://issues.redhat.com/browse/RHEL-18161
JIRA: https://issues.redhat.com/browse/RHEL-18162
CVE: CVE-2023-6531

commit 69db702c83874fbaa2a51af761e35a8e5a593b95
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Dec 6 13:55:19 2023 +0000

    io_uring/af_unix: disable sending io_uring over sockets

    File reference cycles have caused lots of problems for io_uring
    in the past, and it still doesn't work exactly right and races with
    unix_stream_read_generic(). The safest fix would be to completely
    disallow sending io_uring files via sockets via SCM_RIGHT, so there
    are no possible cycles invloving registered files and thus rendering
    SCM accounting on the io_uring side unnecessary.

    Cc: stable@vger.kernel.org
    Fixes: 0091bfc81741b ("io_uring/af_unix: defer registered files gc to io_uring release")
    Reported-and-suggested-by: Jann Horn <jannh@google.com>
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Acked-by: Jakub Kicinski <kuba@kernel.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Felix Maurer <fmaurer@redhat.com>
2024-01-09 11:03:18 +01:00
Jeff Moyer 04990000c9 io_uring/rsrc: Remove unused declaration io_rsrc_put_tw()
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit d4b30eed51d79361c290dc25a1386f5611f4982a
Author: Yue Haibing <yuehaibing@huawei.com>
Date:   Tue Aug 8 23:10:58 2023 +0800

    io_uring/rsrc: Remove unused declaration io_rsrc_put_tw()
    
    Commit 36b9818a5a84 ("io_uring/rsrc: don't offload node free")
    removed the implementation but leave declaration.
    
    Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
    Link: https://lore.kernel.org/r/20230808151058.4572-1-yuehaibing@huawei.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:32:16 -04:00
Jeff Moyer 32af48a0f7 io_uring/rsrc: disassociate nodes and rsrc_data
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 2236b3905b4d4e9cd4d149ab35767858c02bb79b
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 18 14:06:41 2023 +0100

    io_uring/rsrc: disassociate nodes and rsrc_data
    
    Make rsrc nodes independent from rsrd_data, for that we keep ctx and
    rsrc type in nodes.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/4f259abe9cd4eea6a3b4ed83508635218acd3c3f.1681822823.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:34 -04:00
Jeff Moyer a02d5bc14b io_uring/rsrc: devirtualise rsrc put callbacks
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit fc7f3a8d3a78503c4f3e108155fb9a233dc307a4
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 18 14:06:40 2023 +0100

    io_uring/rsrc: devirtualise rsrc put callbacks
    
    We only have two rsrc types, buffers and files, replace virtual
    callbacks for putting resources down with a switch..case.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/02ca727bf8e5f7f820c2f404e95ae88c8f472930.1681822823.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:34 -04:00
Jeff Moyer aacba14952 io_uring/rsrc: inline io_rsrc_put_work()
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 4130b49991d6b8ca0ea44cb256e710c4e48d7f01
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 18 14:06:38 2023 +0100

    io_uring/rsrc: inline io_rsrc_put_work()
    
    io_rsrc_put_work() is simple enough to be open coded into its only
    caller.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/1b36dd46766ced39a9b160767babfa2fce07b8f8.1681822823.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:34 -04:00
Jeff Moyer 252fa76607 io_uring/rsrc: add empty flag in rsrc_node
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 26147da37f3e52041d9deba189d39f27ce78a84f
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 18 14:06:37 2023 +0100

    io_uring/rsrc: add empty flag in rsrc_node
    
    Unless a node was flushed by io_rsrc_ref_quiesce(), it'll carry a
    resource. Replace ->inline_items with an empty flag, which is
    initialised to false and only raised in io_rsrc_ref_quiesce().
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/75d384c9d2252e12af73b9cf8a44e1699106aeb1.1681822823.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:34 -04:00
Jeff Moyer b99aa89db1 io_uring/rsrc: merge nodes and io_rsrc_put
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit c376644fb915fbdea8c4a04f859d032a8be352fd
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 18 14:06:36 2023 +0100

    io_uring/rsrc: merge nodes and io_rsrc_put
    
    struct io_rsrc_node carries a number of resources represented by struct
    io_rsrc_put. That was handy before for sync overhead ammortisation, but
    all complexity is gone and nodes are simple and lightweight. Let's
    allocate a separate node for each resource.
    
    Nodes and io_rsrc_put and not much different in size, and former are
    cached, so node allocation should work better. That also removes some
    overhead for nested iteration in io_rsrc_node_ref_zero() /
    __io_rsrc_put_work().
    
    Another reason for the patch is that it greatly reduces complexity
    by moving io_rsrc_node_switch[_start]() inside io_queue_rsrc_removal(),
    so users don't have to care about it.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/c7d3a45b30cc14cd93700a710dd112edc703db98.1681822823.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:34 -04:00
Jeff Moyer c5de9ff392 io_uring/rsrc: infer node from ctx on io_queue_rsrc_removal
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 63fea89027ff4fd4f350b471ad5b9220d373eec5
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 18 14:06:35 2023 +0100

    io_uring/rsrc: infer node from ctx on io_queue_rsrc_removal
    
    For io_queue_rsrc_removal() we should always use the current active rsrc
    node, don't pass it directly but let the function grab it from the
    context.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/d15939b4afea730978b4925685c2577538b823bb.1681822823.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:33 -04:00
Jeff Moyer 15020ff598 io_uring/rsrc: remove unused io_rsrc_node::llist
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 2e6f45ac0e640bbd49296adfa0982c84f85fa342
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 18 14:06:34 2023 +0100

    io_uring/rsrc: remove unused io_rsrc_node::llist
    
    ->llist was needed for rsrc node destruction offload, which is removed
    now. Get rid of the unused field.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/8e7d764c3f947489fde88d0927c3060d2e1bb599.1681822823.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:33 -04:00
Jeff Moyer 7f28d9822b io_uring/rsrc: inline switch_start fast path
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 2f2af35f8e5a1ed552ed02e47277d50092a2b9f6
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Thu Apr 13 15:28:11 2023 +0100

    io_uring/rsrc: inline switch_start fast path
    
    Inline the part of io_rsrc_node_switch_start() that checks whether the
    cache is empty or not, as most of the times it will have some number of
    entries in there.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/9619c1717a0e01f22c5fce2f1ba2735f804da0f2.1681395792.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:33 -04:00
Jeff Moyer 5904c89c9a io_uring/rsrc: remove rsrc_data refs
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 0b222eeb6514ba6c3457b667fa4f3645032e1fc9
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Thu Apr 13 15:28:10 2023 +0100

    io_uring/rsrc: remove rsrc_data refs
    
    Instead of waiting for rsrc_data->refs to be downed to zero, check
    whether there are rsrc nodes queued for completion, that's easier then
    maintaining references.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/8e33fd143d83e11af3e386aea28eb6d6c6a1be10.1681395792.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:33 -04:00
Jeff Moyer e282fef7b1 io_uring/rsrc: use wq for quiescing
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 4ea15b56f0810f0d8795d475db1bb74b3a7c1b2f
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Thu Apr 13 15:28:08 2023 +0100

    io_uring/rsrc: use wq for quiescing
    
    Replace completions with waitqueues for rsrc data quiesce, the main
    wakeup condition is when data refs hit zero. Note that data refs are
    only changes under ->uring_lock, so we prepare before mutex_unlock()
    reacquire it after taking the lock back. This change will be needed
    in the next patch.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/1d0dbc74b3b4fd67c8f01819e680c5e0da252956.1681395792.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:33 -04:00
Jeff Moyer 7b8d16c640 io_uring/rsrc: remove io_rsrc_node::done
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit c732ea242d565c8281c4b017929fc62a246d81b9
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Thu Apr 13 15:28:06 2023 +0100

    io_uring/rsrc: remove io_rsrc_node::done
    
    Kill io_rsrc_node::node and check refs instead, it's set when the nodes
    refcount hits zero, and it won't change afterwards.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/bbde361f4010f7e8bf196f1ecca27a763b79926f.1681395792.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:32 -04:00
Jeff Moyer ce9bdf5c09 io_uring/rsrc: refactor io_rsrc_node_switch
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 2933ae6eaa05e8db6ad33a3ca12af18d2a25358c
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 11 12:06:07 2023 +0100

    io_uring/rsrc: refactor io_rsrc_node_switch
    
    We use io_rsrc_node_switch() coupled with io_rsrc_node_switch_start()
    for a bunch of cases including initialising ctx->rsrc_node, i.e. by
    passing NULL instead of rsrc_data. Leave it to only deal with actual
    node changing.
    
    For that, first remove it from io_uring_create() and add a function
    allocating the first node. Then also remove all calls to
    io_rsrc_node_switch() from files/buffers register as we already have a
    node installed and it does essentially nothing.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/d146fe306ff98b1a5a60c997c252534f03d423d7.1681210788.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:32 -04:00
Jeff Moyer 989784208d io_uring/rsrc: add custom limit for node caching
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 69bbc6ade9d9d4e3c556cb83e77b6f3cd9ad3d18
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 4 13:39:57 2023 +0100

    io_uring/rsrc: add custom limit for node caching
    
    The number of entries in the rsrc node cache is limited to 512, which
    still seems unnecessarily large. Add per cache thresholds and set to
    to 32 for the rsrc node cache.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/d0cd538b944dac0bf878e276fc0199f21e6bccea.1680576071.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:30 -04:00
Jeff Moyer 3cb59f3336 io_uring/rsrc: optimise io_rsrc_data refcounting
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 757ef4682b6aa29fdf752ad47f0d63eb48b261cf
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 4 13:39:56 2023 +0100

    io_uring/rsrc: optimise io_rsrc_data refcounting
    
    Every struct io_rsrc_node takes a struct io_rsrc_data reference, which
    means all rsrc updates do 2 extra atomics. Replace atomics refcounting
    with a int as it's all done under ->uring_lock.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/e73c3d6820cf679532696d790b5b8fae23537213.1680576071.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:30 -04:00
Jeff Moyer 067bb80c4a io_uring/rsrc: add lockdep sanity checks
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 1f2c8f610aa6c6a3dc3523f93eaf28c25051df6f
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 4 13:39:55 2023 +0100

    io_uring/rsrc: add lockdep sanity checks
    
    We should hold ->uring_lock while putting nodes with io_put_rsrc_node(),
    add a lockdep check for that.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/b50d5f156ac41450029796738c1dfd22a521df7a.1680576071.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:30 -04:00
Jeff Moyer d00f0ad4e6 io_uring/rsrc: cache struct io_rsrc_node
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 9eae8655f9cd2eeed99fb7a0d2bb22816c17e497
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 4 13:39:54 2023 +0100

    io_uring/rsrc: cache struct io_rsrc_node
    
    Add allocation cache for struct io_rsrc_node, it's always allocated and
    put under ->uring_lock, so it doesn't need any extra synchronisation
    around caches.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/252a9d9ef9654e6467af30fdc02f57c0118fb76e.1680576071.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:30 -04:00
Jeff Moyer 5e922f26a3 io_uring/rsrc: optimise io_rsrc_put allocation
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit ff7c75ecaa9e6b251f76c24e289d4bfe413ffe31
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 4 13:39:52 2023 +0100

    io_uring/rsrc: optimise io_rsrc_put allocation
    
    Every io_rsrc_node keeps a list of items to put, and all entries are
    kmalloc()'ed. However, it's quite often to queue up only one entry per
    node, so let's add an inline entry there to avoid extra allocations.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/c482c1c652c45c85ac52e67c974bc758a50fed5f.1680576071.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:30 -04:00
Jeff Moyer ac730dc64c io_uring/rsrc: rename rsrc_list
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit c824986c113f15e2ef2c00da9a226c09ecaac74c
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 4 13:39:51 2023 +0100

    io_uring/rsrc: rename rsrc_list
    
    We have too many "rsrc" around which makes the name of struct
    io_rsrc_node::rsrc_list confusing. The field is responsible for keeping
    a list of files or buffers, so call it item_list and add comments
    around.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/3e34d4dfc1fdbb6b520f904ee6187c2ccf680efe.1680576071.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:30 -04:00
Jeff Moyer 1031294661 io_uring/rsrc: protect node refs with uring_lock
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit ef8ae64ffa9578c12e44de42604004c2cc3e9c27
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 4 13:39:49 2023 +0100

    io_uring/rsrc: protect node refs with uring_lock
    
    Currently, for nodes we have an atomic counter and some cached
    (non-atomic) refs protected by uring_lock. Let's put all ref
    manipulations under uring_lock and get rid of the atomic part.
    It's free as in all cases we care about we already hold the lock.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/25b142feed7d831008257d90c8b17c0115d4fc15.1680576071.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:30 -04:00
Jeff Moyer 15a8ea4c05 io_uring: don't put nodes under spinlocks
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 2ad4c6d08018e4eec130c29992028dc356ab2181
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 4 13:39:47 2023 +0100

    io_uring: don't put nodes under spinlocks
    
    io_req_put_rsrc() doesn't need any locking, so move it out of
    a spinlock section in __io_req_complete_post() and adjust helpers.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/d5b87a5f31270dade6805f7acafc4cc34b84b241.1680576071.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:29 -04:00
Jeff Moyer 4622b46d9b io_uring/rsrc: keep cached refs per node
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 8e15c0e71b8ae64fb7163532860f8d608165281f
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 4 13:39:46 2023 +0100

    io_uring/rsrc: keep cached refs per node
    
    We cache refs of the current node (i.e. ctx->rsrc_node) in
    ctx->rsrc_cached_refs. We'll be moving away from atomics, so move the
    cached refs in struct io_rsrc_node for now. It's a prep patch and
    shouldn't change anything in practise.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/9edc3669c1d71b06c2dca78b2b2b8bb9292738b9.1680576071.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:29 -04:00
Jeff Moyer 847c95f93a io_uring/rsrc: use non-pcpu refcounts for nodes
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit b8fb5b4fdd67f9d18109c5d21d44a8bd4ddb608b
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Apr 4 13:39:45 2023 +0100

    io_uring/rsrc: use non-pcpu refcounts for nodes
    
    One problem with the current rsrc infra is that often updates will
    generates lots of rsrc nodes, each carry pcpu refs. That takes quite a
    lot of memory, especially if there is a stall, and takes lots of CPU
    cycles. Only pcpu allocations takes >50 of CPU with a naive benchmark
    updating files in a loop.
    
    Replace pcpu refs with normal refcounting. There is already a hot path
    avoiding atomics / refs, but following patches will further improve it.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/e9ed8a9457b331a26555ff9443afc64cdaab7247.1680576071.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:29 -04:00
Jeff Moyer c824d16470 io_uring/rsrc: fix rogue rsrc node grabbing
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 4ff0b50de8cabba055efe50bbcb7506c41a69835
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Mar 29 15:03:43 2023 +0100

    io_uring/rsrc: fix rogue rsrc node grabbing
    
    We should not be looking at ctx->rsrc_node and anyhow modifying the node
    without holding uring_lock, grabbing references in such a way is not
    safe either.
    
    Cc: stable@vger.kernel.org
    Fixes: 5106dd6e74ab6 ("io_uring: propagate issue_flags state down to file assignment")
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/1202ede2d7bb90136e3482b2b84aad9ed483e5d6.1680098433.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:26:31 -04:00
Jeff Moyer 64e12a4127 io_uring: use tw for putting rsrc
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit d34b1b0b6779d4f5ee877b53cad90eef0f1cbe34
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Dec 7 03:53:32 2022 +0000

    io_uring: use tw for putting rsrc
    
    Use task_work for completing rsrc removals, it'll be needed later for
    spinlock optimisations.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/cbba5d53a11ee6fc2194dacea262c1d733c8b529.1670384893.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:25:20 -04:00
Jeff Moyer 8be49fc979 io_uring: remove FFS_SCM
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 38eddb2c75fb99b9cd78445094ca0e1bda08d102
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Sun Oct 16 21:30:48 2022 +0100

    io_uring: remove FFS_SCM
    
    THe lifetime of SCM'ed files is bound to ring_sock, which is destroyed
    strictly after we're done with registered file tables. This means there
    is no need for the FFS_SCM hack, which was not available on 32-bit builds
    anyway.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/984226a1045adf42dc35d8bd7fb5a8bbfa472ce1.1665891182.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:24:10 -04:00
Jeff Moyer 37fde95f60 Revert "io_uring: rename IORING_OP_FILES_UPDATE"
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit d9808ceb3129b811becebdee3ec96d189c83e56c
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Thu Sep 1 11:54:02 2022 +0100

    Revert "io_uring: rename IORING_OP_FILES_UPDATE"
    
    This reverts commit 4379d5f15b3fd4224c37841029178aa8082a242e.
    
    We removed notification flushing, also cleanup uapi preparation changes
    to not pollute it.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/89edc3905350f91e1b6e26d9dbf42ee44fd451a2.1662027856.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:22:57 -04:00
Jeff Moyer 56754e8145 io_uring/net: make page accounting more consistent
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 6a9ce66f4d0872861e0bbc67eee6ce5dca5dd886
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Mon Jul 25 10:52:05 2022 +0100

    io_uring/net: make page accounting more consistent
    
    Make network page accounting more consistent with how buffer
    registration is working, i.e. account all memory to ctx->user.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/4aacfe64bbb81b27f9ecf5d5c219c69a07e5aa56.1658742118.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 08:32:02 -04:00
Jeff Moyer c447d13dbe io_uring: rename IORING_OP_FILES_UPDATE
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 4379d5f15b3fd4224c37841029178aa8082a242e
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Jul 12 21:52:48 2022 +0100

    io_uring: rename IORING_OP_FILES_UPDATE
    
    IORING_OP_FILES_UPDATE will be a more generic opcode serving different
    resource types, rename it into IORING_OP_RSRC_UPDATE and add subtype
    handling.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/0a907133907d9af3415a8a7aa1802c6aa97c03c6.1657643355.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 08:26:02 -04:00
Jeff Moyer e80fb737ed io_uring: add rsrc referencing for notifiers
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 68ef5578efc8893489400b1ec30af66dab4f75ff
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Jul 12 21:52:41 2022 +0100

    io_uring: add rsrc referencing for notifiers
    
    In preparation to zerocopy sends with fixed buffers make notifiers to
    reference the rsrc node to protect the used fixed buffers. We can't just
    grab it for a send request as notifiers can likely outlive requests that
    used it.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/3cd7a01d26837945b6982fa9cf15a63230f2ed4f.1657643355.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 08:19:02 -04:00
Jeff Moyer 47f5ef3f25 io_uring: move io_import_fixed()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit c059f785840807ed5e1f2810420c1555969b6246
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Mon Jun 20 01:25:59 2022 +0100

    io_uring: move io_import_fixed()
    
    Move io_import_fixed() into rsrc.c where it belongs.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/4d5becb21f332b4fef6a7cedd6a50e65e2371630.1655684496.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 06:34:02 -04:00
Jeff Moyer e61677c1ff io_uring: move a few private types to local headers
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit ad163a7e2562230c77102c60f668bac440e60cce
Author: Jens Axboe <axboe@kernel.dk>
Date:   Sat Jun 18 19:44:33 2022 -0600

    io_uring: move a few private types to local headers
    
    Commit 3a3d47fa9cfd ("io_uring: make io_uring_types.h public") moved
    a bunch of io_uring types to a kernel wide header, so we could make
    tracing a bit saner rather than pass in a ton of arguments.
    
    However, there are a few types in there that are not really needed to
    be system wide. Move the cancel data and mapped buffers back to the
    appropriate io_uring local headers.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 06:22:02 -04:00
Jeff Moyer 35319b7b26 io_uring: move rsrc related data, core, and commands
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 73572984481907d92673255b494c0ff4f77c8ed4
Author: Jens Axboe <axboe@kernel.dk>
Date:   Mon Jun 13 07:12:45 2022 -0600

    io_uring: move rsrc related data, core, and commands
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 05:39:02 -04:00