On 2/23/20 7:58 AM, Jens Axboe wrote: > On 2/23/20 7:49 AM, Jens Axboe wrote: >>> Anyway, creds handling is too scattered across the code, and this do a >>> lot of useless refcounting and bouncing. It's better to find it a >>> better place in the near future. >> >> I think a good cleanup on top of this would be to move the personality >> lookup to io_req_defer_prep(), and kill it from io_submit_sqe(). Now >> __io_issue_sqe() does the right thing, and it'll just fall out nicely >> with that as far as I can tell. >> >> Care to send a patch for that? > > Since we also need it for non-deferral, how about just leaving the > lookup in there and removing the assignment? That means we only do that > juggling in one spot, which makes more sense. I think this should just > be folded into the previous patch. Tested, we need a ref grab on the creds when assigning since we're dropped at the other end. diff --git a/fs/io_uring.c b/fs/io_uring.c index cead1a0602b4..d83f113f22fd 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4923,7 +4923,6 @@ static inline void io_queue_link_head(struct io_kiocb *req) static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, struct io_submit_state *state, struct io_kiocb **link) { - const struct cred *old_creds = NULL; struct io_ring_ctx *ctx = req->ctx; unsigned int sqe_flags; int ret, id; @@ -4938,14 +4937,12 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, id = READ_ONCE(sqe->personality); if (id) { - const struct cred *personality_creds; - - personality_creds = idr_find(&ctx->personality_idr, id); - if (unlikely(!personality_creds)) { + req->work.creds = idr_find(&ctx->personality_idr, id); + if (unlikely(!req->work.creds)) { ret = -EINVAL; goto err_req; } - old_creds = override_creds(personality_creds); + get_cred(req->work.creds); } /* same numerical values with corresponding REQ_F_*, safe to copy */ @@ -4957,8 +4954,6 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, err_req: io_cqring_add_event(req, ret); io_double_put_req(req); - if (old_creds) - revert_creds(old_creds); return false; } @@ -5019,8 +5014,6 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, } } - if (old_creds) - revert_creds(old_creds); return true; } -- Jens Axboe