linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Stefan Roesch <shr@fb.com>,
	io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	kernel-team@fb.com
Cc: viro@zeniv.linux.org.uk
Subject: Re: [PATCH v4 4/5] io_uring: add fsetxattr and setxattr support
Date: Tue, 21 Dec 2021 17:27:02 +0000	[thread overview]
Message-ID: <6ce7133b-802f-74cf-7610-a7b0bbbb45fd@gmail.com> (raw)
In-Reply-To: <20211215221702.3695098-5-shr@fb.com>

On 12/15/21 22:17, Stefan Roesch wrote:
> This adds support to io_uring for the fsetxattr and setxattr API.

Apart from potentially putname comment,

Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>

> 
> Signed-off-by: Stefan Roesch <shr@fb.com>
> ---
>   fs/io_uring.c                 | 171 ++++++++++++++++++++++++++++++++++
>   include/uapi/linux/io_uring.h |   6 +-
>   2 files changed, 176 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 5092dfe56da6..fc2239635342 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
[...]> +static int __io_setxattr_prep(struct io_kiocb *req,
> +			const struct io_uring_sqe *sqe,
> +			struct user_namespace *user_ns)
> +{
> +	struct io_xattr *ix = &req->xattr;
> +	const char __user *name;
> +	void *ret;
> +
> +	if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
> +		return -EINVAL;
> +	if (unlikely(sqe->ioprio))
> +		return -EINVAL;
> +	if (unlikely(req->flags & REQ_F_FIXED_FILE))
> +		return -EBADF;
> +
> +	ix->filename = NULL;
> +	name = u64_to_user_ptr(READ_ONCE(sqe->addr));
> +	ix->ctx.value = u64_to_user_ptr(READ_ONCE(sqe->addr2));
> +	ix->ctx.size = READ_ONCE(sqe->len);
> +	ix->ctx.flags = READ_ONCE(sqe->xattr_flags);
> +
> +	ix->ctx.kname = kmalloc(XATTR_NAME_MAX + 1, GFP_KERNEL);
> +	if (!ix->ctx.kname)
> +		return -ENOMEM;> +	ix->ctx.kname_sz = XATTR_NAME_MAX + 1;

Might make sense to let the userspace specify kname size, but
depends what is the average name length and how much of free
space we have in io_xattr

[...]
> +static int io_setxattr(struct io_kiocb *req, unsigned int issue_flags)
> +{
> +	struct io_xattr *ix = &req->xattr;
> +	unsigned int lookup_flags = LOOKUP_FOLLOW;
> +	struct path path;
> +	int ret;
> +
> +	if (issue_flags & IO_URING_F_NONBLOCK)
> +		return -EAGAIN;
> +
> +retry:
> +	ret = do_user_path_at_empty(AT_FDCWD, ix->filename, lookup_flags, &path);
> +	putname(ix->filename);

It putname() multiple times on retry, how does it work?


> +	if (!ret) {
> +		ret = __io_setxattr(req, issue_flags, &path);
> +		path_put(&path);
> +		if (retry_estale(ret, lookup_flags)) {
> +			lookup_flags |= LOOKUP_REVAL;
> +			goto retry;
> +		}
> +	}
> +
> +	req->flags &= ~REQ_F_NEED_CLEANUP;
> +	kfree(ix->ctx.kname);
> +
> +	if (ix->value)
> +		kvfree(ix->value);
> +	if (ret < 0)
> +		req_set_fail(req);
> +
> +	io_req_complete(req, ret);
> +	return 0;
> +}
> +
[...]
>   
>   	printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n",
> @@ -6715,6 +6870,15 @@ static void io_clean_op(struct io_kiocb *req)
>   			putname(req->hardlink.oldpath);
>   			putname(req->hardlink.newpath);
>   			break;
> +		case IORING_OP_SETXATTR:
> +			if (req->xattr.filename)
> +				putname(req->xattr.filename);
> +			fallthrough;
> +		case IORING_OP_FSETXATTR:
> +			kfree(req->xattr.ctx.kname);
> +			if (req->xattr.value)
> +				kvfree(req->xattr.value);

nit: it's slow path and kvfree() handles NULLs, so we don't
really need NULL checks here.

-- 
Pavel Begunkov

  reply	other threads:[~2021-12-21 17:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15 22:16 [PATCH v4 0/5] io_uring: add xattr support Stefan Roesch
2021-12-15 22:16 ` [PATCH v4 1/5] fs: split off do_user_path_at_empty from user_path_at_empty() Stefan Roesch
2021-12-15 22:16 ` [PATCH v4 2/5] fs: split off setxattr_setup function from setxattr Stefan Roesch
2021-12-15 22:17 ` [PATCH v4 3/5] fs: split off do_getxattr from getxattr Stefan Roesch
2021-12-15 22:17 ` [PATCH v4 4/5] io_uring: add fsetxattr and setxattr support Stefan Roesch
2021-12-21 17:27   ` Pavel Begunkov [this message]
2021-12-15 22:17 ` [PATCH v4 5/5] io_uring: add fgetxattr and getxattr support Stefan Roesch
2021-12-21 17:32   ` Pavel Begunkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6ce7133b-802f-74cf-7610-a7b0bbbb45fd@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=io-uring@vger.kernel.org \
    --cc=kernel-team@fb.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=shr@fb.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).