From patchwork Wed Dec 1 05:51:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12649151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC036C4332F for ; Wed, 1 Dec 2021 05:52:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346868AbhLAFzc (ORCPT ); Wed, 1 Dec 2021 00:55:32 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:28296 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346840AbhLAFzV (ORCPT ); Wed, 1 Dec 2021 00:55:21 -0500 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1B10XHcL027420 for ; Tue, 30 Nov 2021 21:52:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=9uKO2x7+25CmQzWGTMLpHb3ikl8Ya9gX8x1/o6yiVAU=; b=WN3LQ9fXbqR2/NTuzATyyWjHP6ngPeQ3l3ZxBPzeXFb45xZbEtAKrvjgjw2qRaSA3kVx XgYoLf/fnQWjeoztaWoIXlePVYAte6XL4bsmmzogRpyPQh/bgG4RVoBRFMFu+V4ozZ8F aWPhN49faYlJuscqA2EYXe/b/TgF/vkH1oU= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 3cnmcfxfy4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 30 Nov 2021 21:52:01 -0800 Received: from intmgw001.05.ash7.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Tue, 30 Nov 2021 21:52:00 -0800 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 71DBC7227189; Tue, 30 Nov 2021 21:51:46 -0800 (PST) From: Stefan Roesch To: , , CC: Subject: [PATCH v2 5/5] io_uring: add fgetxattr and getxattr support Date: Tue, 30 Nov 2021 21:51:44 -0800 Message-ID: <20211201055144.3141001-6-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211201055144.3141001-1-shr@fb.com> References: <20211201055144.3141001-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-FB-Source: Intern X-Proofpoint-ORIG-GUID: RxzwYmt0s-26ywA1WoLFd98_mZy9myC5 X-Proofpoint-GUID: RxzwYmt0s-26ywA1WoLFd98_mZy9myC5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-30_10,2021-11-28_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 clxscore=1015 bulkscore=0 mlxlogscore=765 lowpriorityscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 spamscore=0 phishscore=0 mlxscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112010033 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This adds support to io_uring for the fgetxattr and getxattr API. Signed-off-by: Stefan Roesch --- fs/io_uring.c | 153 ++++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 2 + 2 files changed, 155 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 9d977bf243fd..231a021d8eea 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1114,6 +1114,10 @@ static const struct io_op_def io_op_defs[] = { [IORING_OP_MKDIRAT] = {}, [IORING_OP_SYMLINKAT] = {}, [IORING_OP_LINKAT] = {}, + [IORING_OP_FGETXATTR] = { + .needs_file = 1 + }, + [IORING_OP_GETXATTR] = {}, [IORING_OP_FSETXATTR] = { .needs_file = 1 }, @@ -3831,6 +3835,136 @@ static int io_renameat(struct io_kiocb *req, unsigned int issue_flags) return 0; } +static int __io_getxattr_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + struct io_xattr *ix = &req->xattr; + const char __user *name; + int 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; + ix->value = 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); + + if (ix->ctx.flags) + return -EINVAL; + + ix->ctx.kname = kmalloc(XATTR_NAME_MAX + 1, GFP_KERNEL); + if (!ix->ctx.kname) + return -ENOMEM; + + ret = strncpy_from_user(ix->ctx.kname, name, XATTR_NAME_MAX + 1); + if (!ret || ret == XATTR_NAME_MAX + 1) + ret = -ERANGE; + if (ret < 0) { + kfree(ix->ctx.kname); + return ret; + } + + req->flags |= REQ_F_NEED_CLEANUP; + return 0; +} + +static int io_fgetxattr_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + if (!req->file) + return -EBADF; + + return __io_getxattr_prep(req, sqe); +} + +static int io_getxattr_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + struct io_xattr *ix = &req->xattr; + const char __user *path; + int ret; + + ret = __io_getxattr_prep(req, sqe); + if (ret) + return ret; + + path = u64_to_user_ptr(READ_ONCE(sqe->addr3)); + + ix->filename = getname_flags(path, LOOKUP_FOLLOW, NULL); + if (IS_ERR(ix->filename)) { + ret = PTR_ERR(ix->filename); + ix->filename = NULL; + } + + return ret; +} + +static int io_fgetxattr(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_xattr *ix = &req->xattr; + int ret; + + if (issue_flags & IO_URING_F_NONBLOCK) + return -EAGAIN; + + ret = do_getxattr(mnt_user_ns(req->file->f_path.mnt), + req->file->f_path.dentry, + ix->ctx.kname, + (void __user *)ix->ctx.value, + ix->ctx.size); + + req->flags &= ~REQ_F_NEED_CLEANUP; + kfree(ix->ctx.kname); + if (ret < 0) + req_set_fail(req); + + io_req_complete(req, ret); + return 0; +} + +static int io_getxattr(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); + if (!ret) { + ret = do_getxattr(mnt_user_ns(path.mnt), + path.dentry, + ix->ctx.kname, + (void __user *)ix->ctx.value, + ix->ctx.size); + + 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 (ret < 0) + req_set_fail(req); + + io_req_complete(req, ret); + return 0; +} + static int __io_setxattr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe, struct user_namespace *user_ns) @@ -6685,6 +6819,10 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return io_symlinkat_prep(req, sqe); case IORING_OP_LINKAT: return io_linkat_prep(req, sqe); + case IORING_OP_FGETXATTR: + return io_fgetxattr_prep(req, sqe); + case IORING_OP_GETXATTR: + return io_getxattr_prep(req, sqe); case IORING_OP_FSETXATTR: return io_fsetxattr_prep(req, sqe); case IORING_OP_SETXATTR: @@ -6832,6 +6970,15 @@ static void io_clean_op(struct io_kiocb *req) putname(req->hardlink.oldpath); putname(req->hardlink.newpath); break; + + case IORING_OP_GETXATTR: + if (req->xattr.filename) + putname(req->xattr.filename); + fallthrough; + case IORING_OP_FGETXATTR: + kfree(req->xattr.ctx.kname); + break; + case IORING_OP_SETXATTR: if (req->xattr.filename) putname(req->xattr.filename); @@ -6983,6 +7130,12 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) case IORING_OP_LINKAT: ret = io_linkat(req, issue_flags); break; + case IORING_OP_FGETXATTR: + ret = io_fgetxattr(req, issue_flags); + break; + case IORING_OP_GETXATTR: + ret = io_getxattr(req, issue_flags); + break; case IORING_OP_FSETXATTR: ret = io_fsetxattr(req, issue_flags); break; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index dbf473900da2..cd9160272308 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -145,7 +145,9 @@ enum { IORING_OP_MKDIRAT, IORING_OP_SYMLINKAT, IORING_OP_LINKAT, + IORING_OP_FGETXATTR, IORING_OP_FSETXATTR, + IORING_OP_GETXATTR, IORING_OP_SETXATTR, /* this goes last, obviously */