* [PATCH 1/6] io_uring: don't change sqpoll creds if not needed
2021-06-24 14:09 [PATCH for-next 0/6] straightforward for-next cleanups Pavel Begunkov
@ 2021-06-24 14:09 ` Pavel Begunkov
2021-06-24 14:09 ` [PATCH 2/6] io_uring: refactor io_sq_thread() Pavel Begunkov
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2021-06-24 14:09 UTC (permalink / raw)
To: Jens Axboe, io-uring
SQPOLL doesn't need to change creds if it's not submitting requests.
Move creds overriding into __io_sq_thread() after checking if there are
SQEs pending.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 14a90e4e4149..cf72cc3fd8f4 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -6999,6 +6999,10 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)
if (!list_empty(&ctx->iopoll_list) || to_submit) {
unsigned nr_events = 0;
+ const struct cred *creds = NULL;
+
+ if (ctx->sq_creds != current_cred())
+ creds = override_creds(ctx->sq_creds);
mutex_lock(&ctx->uring_lock);
if (!list_empty(&ctx->iopoll_list))
@@ -7015,6 +7019,8 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)
if (to_submit && wq_has_sleeper(&ctx->sqo_sq_wait))
wake_up(&ctx->sqo_sq_wait);
+ if (creds)
+ revert_creds(creds);
}
return ret;
@@ -7066,7 +7072,6 @@ static int io_sq_thread(void *data)
mutex_lock(&sqd->lock);
while (1) {
- int ret;
bool cap_entries, sqt_spin, needs_sched;
if (io_sqd_events_pending(sqd) || signal_pending(current)) {
@@ -7079,13 +7084,8 @@ static int io_sq_thread(void *data)
sqt_spin = false;
cap_entries = !list_is_singular(&sqd->ctx_list);
list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
- const struct cred *creds = NULL;
+ int ret = __io_sq_thread(ctx, cap_entries);
- if (ctx->sq_creds != current_cred())
- creds = override_creds(ctx->sq_creds);
- ret = __io_sq_thread(ctx, cap_entries);
- if (creds)
- revert_creds(creds);
if (!sqt_spin && (ret > 0 || !list_empty(&ctx->iopoll_list)))
sqt_spin = true;
}
--
2.32.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/6] io_uring: refactor io_sq_thread()
2021-06-24 14:09 [PATCH for-next 0/6] straightforward for-next cleanups Pavel Begunkov
2021-06-24 14:09 ` [PATCH 1/6] io_uring: don't change sqpoll creds if not needed Pavel Begunkov
@ 2021-06-24 14:09 ` Pavel Begunkov
2021-06-24 14:09 ` [PATCH 3/6] io_uring: fix code style problems Pavel Begunkov
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2021-06-24 14:09 UTC (permalink / raw)
To: Jens Axboe, io-uring
Move needs_sched declaration into the block where it's used, so it's
harder to misuse/wrongfully reuse.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index cf72cc3fd8f4..5745b3809b0d 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7072,7 +7072,7 @@ static int io_sq_thread(void *data)
mutex_lock(&sqd->lock);
while (1) {
- bool cap_entries, sqt_spin, needs_sched;
+ bool cap_entries, sqt_spin = false;
if (io_sqd_events_pending(sqd) || signal_pending(current)) {
if (io_sqd_handle_event(sqd))
@@ -7081,7 +7081,6 @@ static int io_sq_thread(void *data)
continue;
}
- sqt_spin = false;
cap_entries = !list_is_singular(&sqd->ctx_list);
list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
int ret = __io_sq_thread(ctx, cap_entries);
@@ -7100,7 +7099,8 @@ static int io_sq_thread(void *data)
prepare_to_wait(&sqd->wait, &wait, TASK_INTERRUPTIBLE);
if (!io_sqd_events_pending(sqd) && !io_run_task_work()) {
- needs_sched = true;
+ bool needs_sched = true;
+
list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
io_ring_set_wakeup_flag(ctx);
--
2.32.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/6] io_uring: fix code style problems
2021-06-24 14:09 [PATCH for-next 0/6] straightforward for-next cleanups Pavel Begunkov
2021-06-24 14:09 ` [PATCH 1/6] io_uring: don't change sqpoll creds if not needed Pavel Begunkov
2021-06-24 14:09 ` [PATCH 2/6] io_uring: refactor io_sq_thread() Pavel Begunkov
@ 2021-06-24 14:09 ` Pavel Begunkov
2021-06-24 14:09 ` [PATCH 4/6] io_uring: update sqe layout build checks Pavel Begunkov
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2021-06-24 14:09 UTC (permalink / raw)
To: Jens Axboe, io-uring
Fix a bunch of problems mostly found by checkpatch.pl
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 5745b3809b0d..669d1b48e4cb 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -173,7 +173,7 @@ struct io_rings {
* Written by the application, shouldn't be modified by the
* kernel.
*/
- u32 cq_flags;
+ u32 cq_flags;
/*
* Number of completion events lost because the queue was full;
* this should be avoided by the application by making sure
@@ -883,7 +883,7 @@ struct io_kiocb {
struct hlist_node hash_node;
struct async_poll *apoll;
struct io_wq_work work;
- const struct cred *creds;
+ const struct cred *creds;
/* store used ubuf, so we can prevent reloading */
struct io_mapped_ubuf *imu;
@@ -1736,7 +1736,7 @@ static struct io_kiocb *io_alloc_req(struct io_ring_ctx *ctx)
{
struct io_submit_state *state = &ctx->submit_state;
- BUILD_BUG_ON(IO_REQ_ALLOC_BATCH > ARRAY_SIZE(state->reqs));
+ BUILD_BUG_ON(ARRAY_SIZE(state->reqs) < IO_REQ_ALLOC_BATCH);
if (!state->free_reqs) {
gfp_t gfp = GFP_KERNEL | __GFP_NOWARN;
@@ -2798,7 +2798,7 @@ static void kiocb_done(struct kiocb *kiocb, ssize_t ret,
else
io_rw_done(kiocb, ret);
- if (check_reissue && req->flags & REQ_F_REISSUE) {
+ if (check_reissue && (req->flags & REQ_F_REISSUE)) {
req->flags &= ~REQ_F_REISSUE;
if (io_resubmit_prep(req)) {
req_ref_get(req);
@@ -3761,7 +3761,7 @@ static int io_shutdown(struct io_kiocb *req, unsigned int issue_flags)
static int __io_splice_prep(struct io_kiocb *req,
const struct io_uring_sqe *sqe)
{
- struct io_splice* sp = &req->splice;
+ struct io_splice *sp = &req->splice;
unsigned int valid_flags = SPLICE_F_FD_IN_FIXED | SPLICE_F_ALL;
if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
@@ -3815,7 +3815,7 @@ static int io_tee(struct io_kiocb *req, unsigned int issue_flags)
static int io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
- struct io_splice* sp = &req->splice;
+ struct io_splice *sp = &req->splice;
sp->off_in = READ_ONCE(sqe->splice_off_in);
sp->off_out = READ_ONCE(sqe->off);
@@ -8763,6 +8763,7 @@ static int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg)
ctx->cq_ev_fd = eventfd_ctx_fdget(fd);
if (IS_ERR(ctx->cq_ev_fd)) {
int ret = PTR_ERR(ctx->cq_ev_fd);
+
ctx->cq_ev_fd = NULL;
return ret;
}
@@ -9543,9 +9544,8 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
io_cqring_overflow_flush(ctx, false);
ret = -EOWNERDEAD;
- if (unlikely(ctx->sq_data->thread == NULL)) {
+ if (unlikely(ctx->sq_data->thread == NULL))
goto out;
- }
if (flags & IORING_ENTER_SQ_WAKEUP)
wake_up(&ctx->sq_data->wait);
if (flags & IORING_ENTER_SQ_WAIT) {
--
2.32.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/6] io_uring: update sqe layout build checks
2021-06-24 14:09 [PATCH for-next 0/6] straightforward for-next cleanups Pavel Begunkov
` (2 preceding siblings ...)
2021-06-24 14:09 ` [PATCH 3/6] io_uring: fix code style problems Pavel Begunkov
@ 2021-06-24 14:09 ` Pavel Begunkov
2021-06-24 14:09 ` [PATCH 5/6] io_uring: simplify struct io_uring_sqe layout Pavel Begunkov
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2021-06-24 14:09 UTC (permalink / raw)
To: Jens Axboe, io-uring
Add missing BUILD_BUG_SQE_ELEM() for ->buf_group verifying that SQE
layout doesn't change.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 669d1b48e4cb..c382182573d5 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -10463,6 +10463,7 @@ static int __init io_uring_init(void)
BUILD_BUG_SQE_ELEM(28, __u32, splice_flags);
BUILD_BUG_SQE_ELEM(32, __u64, user_data);
BUILD_BUG_SQE_ELEM(40, __u16, buf_index);
+ BUILD_BUG_SQE_ELEM(40, __u16, buf_group);
BUILD_BUG_SQE_ELEM(42, __u16, personality);
BUILD_BUG_SQE_ELEM(44, __s32, splice_fd_in);
@@ -10475,6 +10476,7 @@ static int __init io_uring_init(void)
BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST);
BUILD_BUG_ON(__REQ_F_LAST_BIT >= 8 * sizeof(int));
+
req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC |
SLAB_ACCOUNT);
return 0;
--
2.32.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/6] io_uring: simplify struct io_uring_sqe layout
2021-06-24 14:09 [PATCH for-next 0/6] straightforward for-next cleanups Pavel Begunkov
` (3 preceding siblings ...)
2021-06-24 14:09 ` [PATCH 4/6] io_uring: update sqe layout build checks Pavel Begunkov
@ 2021-06-24 14:09 ` Pavel Begunkov
2021-06-24 14:10 ` [PATCH 6/6] io_uring: refactor io_openat2() Pavel Begunkov
2021-06-24 15:35 ` [PATCH for-next 0/6] straightforward for-next cleanups Jens Axboe
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2021-06-24 14:09 UTC (permalink / raw)
To: Jens Axboe, io-uring
Flatten struct io_uring_sqe, the last union is exactly 64B, so move them
out of union { struct { ... }}, and decrease __pad2 size.
Signed-off-by: Pavel Begunkov <[email protected]>
---
include/uapi/linux/io_uring.h | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index c735fc22e459..10eb38d2864f 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -47,21 +47,17 @@ struct io_uring_sqe {
__u32 hardlink_flags;
};
__u64 user_data; /* data to be passed back at completion time */
+ /* pack this to avoid bogus arm OABI complaints */
union {
- struct {
- /* pack this to avoid bogus arm OABI complaints */
- union {
- /* index into fixed buffers, if used */
- __u16 buf_index;
- /* for grouped buffer selection */
- __u16 buf_group;
- } __attribute__((packed));
- /* personality to use, if used */
- __u16 personality;
- __s32 splice_fd_in;
- };
- __u64 __pad2[3];
- };
+ /* index into fixed buffers, if used */
+ __u16 buf_index;
+ /* for grouped buffer selection */
+ __u16 buf_group;
+ } __attribute__((packed));
+ /* personality to use, if used */
+ __u16 personality;
+ __s32 splice_fd_in;
+ __u64 __pad2[2];
};
enum {
--
2.32.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/6] io_uring: refactor io_openat2()
2021-06-24 14:09 [PATCH for-next 0/6] straightforward for-next cleanups Pavel Begunkov
` (4 preceding siblings ...)
2021-06-24 14:09 ` [PATCH 5/6] io_uring: simplify struct io_uring_sqe layout Pavel Begunkov
@ 2021-06-24 14:10 ` Pavel Begunkov
2021-06-24 15:35 ` [PATCH for-next 0/6] straightforward for-next cleanups Jens Axboe
6 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2021-06-24 14:10 UTC (permalink / raw)
To: Jens Axboe, io-uring
Put do_filp_open() fail path of io_openat2() under a single if,
deduplicating put_unused_fd(), making it look better and helping
the hot path.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index c382182573d5..b0dea0b39ea1 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4021,27 +4021,26 @@ static int io_openat2(struct io_kiocb *req, unsigned int issue_flags)
goto err;
file = do_filp_open(req->open.dfd, req->open.filename, &op);
- /* only retry if RESOLVE_CACHED wasn't already set by application */
- if ((!resolve_nonblock && (issue_flags & IO_URING_F_NONBLOCK)) &&
- file == ERR_PTR(-EAGAIN)) {
+ if (IS_ERR(file)) {
/*
- * We could hang on to this 'fd', but seems like marginal
- * gain for something that is now known to be a slower path.
- * So just put it, and we'll get a new one when we retry.
+ * We could hang on to this 'fd' on retrying, but seems like
+ * marginal gain for something that is now known to be a slower
+ * path. So just put it, and we'll get a new one when we retry.
*/
put_unused_fd(ret);
- return -EAGAIN;
- }
- if (IS_ERR(file)) {
- put_unused_fd(ret);
ret = PTR_ERR(file);
- } else {
- if ((issue_flags & IO_URING_F_NONBLOCK) && !nonblock_set)
- file->f_flags &= ~O_NONBLOCK;
- fsnotify_open(file);
- fd_install(ret, file);
+ /* only retry if RESOLVE_CACHED wasn't already set by application */
+ if (ret == -EAGAIN &&
+ (!resolve_nonblock && (issue_flags & IO_URING_F_NONBLOCK)))
+ return -EAGAIN;
+ goto err;
}
+
+ if ((issue_flags & IO_URING_F_NONBLOCK) && !nonblock_set)
+ file->f_flags &= ~O_NONBLOCK;
+ fsnotify_open(file);
+ fd_install(ret, file);
err:
putname(req->open.filename);
req->flags &= ~REQ_F_NEED_CLEANUP;
--
2.32.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH for-next 0/6] straightforward for-next cleanups
2021-06-24 14:09 [PATCH for-next 0/6] straightforward for-next cleanups Pavel Begunkov
` (5 preceding siblings ...)
2021-06-24 14:10 ` [PATCH 6/6] io_uring: refactor io_openat2() Pavel Begunkov
@ 2021-06-24 15:35 ` Jens Axboe
6 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2021-06-24 15:35 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 6/24/21 8:09 AM, Pavel Begunkov wrote:
> On top of 5.14 + mkdir v6 and friends.
>
> A bunch of small not related b/w each other cleanups.
>
> Pavel Begunkov (6):
> io_uring: don't change sqpoll creds if not needed
> io_uring: refactor io_sq_thread()
> io_uring: fix code style problems
> io_uring: update sqe layout build checks
> io_uring: simplify struct io_uring_sqe layout
> io_uring: refactor io_openat2()
>
> fs/io_uring.c | 67 ++++++++++++++++++-----------------
> include/uapi/linux/io_uring.h | 24 ++++++-------
> 2 files changed, 44 insertions(+), 47 deletions(-)
LGTM, applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 8+ messages in thread