From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_SOFTFAIL,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A397C433EF for ; Wed, 23 Mar 2022 15:44:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245203AbiCWPqN (ORCPT ); Wed, 23 Mar 2022 11:46:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243898AbiCWPqL (ORCPT ); Wed, 23 Mar 2022 11:46:11 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C93FA3FD98 for ; Wed, 23 Mar 2022 08:44:40 -0700 (PDT) Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 22N6WTbo000755 for ; Wed, 23 Mar 2022 08:44:40 -0700 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=TcUnRKFRA1Sw+mMdMANvau1BFMXz1aPW9I9VjZ0MCII=; b=UoBd6n2i42a/aNBdeJ/UbVDn3z/5kddaJnGQmIuF2OdQJMxYiQSwz6Z1XQ7JySoWv/5L 49t/1OZohbeFqnbZ9JV2ZIEcgVeXcinoIWCMpqJ1WlaZld3GdqVQ1dBwGkp0C1lVCIjM 6XaOlEqNiiARSUtwI0zS+t/tjR0nqIUzICM= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3ey6ddmtxh-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 23 Mar 2022 08:44:40 -0700 Received: from twshared37304.07.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 23 Mar 2022 08:44:38 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 916B4CA024CB; Wed, 23 Mar 2022 08:44:22 -0700 (PDT) From: Stefan Roesch To: , , CC: , , Subject: [PATCH v13 4/4] io_uring: add fgetxattr and getxattr support Date: Wed, 23 Mar 2022 08:44:20 -0700 Message-ID: <20220323154420.3301504-5-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220323154420.3301504-1-shr@fb.com> References: <20220323154420.3301504-1-shr@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: 2x8MtrhIktGoPhVGRqb6TvZjQQY1GK55 X-Proofpoint-ORIG-GUID: 2x8MtrhIktGoPhVGRqb6TvZjQQY1GK55 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-23_07,2022-03-23_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This adds support to io_uring for the fgetxattr and getxattr API. Signed-off-by: Stefan Roesch --- fs/io_uring.c | 129 ++++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 2 + 2 files changed, 131 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index d71073be91c2..6ae0eef96f3e 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1166,6 +1166,10 @@ static const struct io_op_def io_op_defs[] =3D { .needs_file =3D 1 }, [IORING_OP_SETXATTR] =3D {}, + [IORING_OP_FGETXATTR] =3D { + .needs_file =3D 1 + }, + [IORING_OP_GETXATTR] =3D {}, }; =20 /* requests with any of those set should undergo io_disarm_next() */ @@ -4128,6 +4132,119 @@ static void io_xattr_finish(struct io_kiocb *req,= int ret) io_req_complete(req, ret); } =20 +static int __io_getxattr_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + struct io_xattr *ix =3D &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 =3D NULL; + ix->ctx.kvalue =3D NULL; + name =3D u64_to_user_ptr(READ_ONCE(sqe->addr)); + ix->ctx.cvalue =3D u64_to_user_ptr(READ_ONCE(sqe->addr2)); + ix->ctx.size =3D READ_ONCE(sqe->len); + ix->ctx.flags =3D READ_ONCE(sqe->xattr_flags); + + if (ix->ctx.flags) + return -EINVAL; + + ix->ctx.kname =3D kmalloc(sizeof(*ix->ctx.kname), GFP_KERNEL); + if (!ix->ctx.kname) + return -ENOMEM; + + ret =3D strncpy_from_user(ix->ctx.kname->name, name, + sizeof(ix->ctx.kname->name)); + if (!ret || ret =3D=3D sizeof(ix->ctx.kname->name)) + ret =3D -ERANGE; + if (ret < 0) { + kfree(ix->ctx.kname); + return ret; + } + + req->flags |=3D REQ_F_NEED_CLEANUP; + return 0; +} + +static int io_fgetxattr_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + 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 =3D &req->xattr; + const char __user *path; + int ret; + + ret =3D __io_getxattr_prep(req, sqe); + if (ret) + return ret; + + path =3D u64_to_user_ptr(READ_ONCE(sqe->addr3)); + + ix->filename =3D getname_flags(path, LOOKUP_FOLLOW, NULL); + if (IS_ERR(ix->filename)) { + ret =3D PTR_ERR(ix->filename); + ix->filename =3D NULL; + } + + return ret; +} + +static int io_fgetxattr(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_xattr *ix =3D &req->xattr; + int ret; + + if (issue_flags & IO_URING_F_NONBLOCK) + return -EAGAIN; + + ret =3D do_getxattr(mnt_user_ns(req->file->f_path.mnt), + req->file->f_path.dentry, + &ix->ctx); + + io_xattr_finish(req, ret); + return 0; +} + +static int io_getxattr(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_xattr *ix =3D &req->xattr; + unsigned int lookup_flags =3D LOOKUP_FOLLOW; + struct path path; + int ret; + + if (issue_flags & IO_URING_F_NONBLOCK) + return -EAGAIN; + +retry: + ret =3D filename_lookup(AT_FDCWD, ix->filename, lookup_flags, &path, NU= LL); + if (!ret) { + ret =3D do_getxattr(mnt_user_ns(path.mnt), + path.dentry, + &ix->ctx); + + path_put(&path); + if (retry_estale(ret, lookup_flags)) { + lookup_flags |=3D LOOKUP_REVAL; + goto retry; + } + } + + io_xattr_finish(req, ret); + return 0; +} + static int __io_setxattr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { @@ -7139,6 +7256,10 @@ static int io_req_prep(struct io_kiocb *req, const= struct io_uring_sqe *sqe) return io_fsetxattr_prep(req, sqe); case IORING_OP_SETXATTR: return io_setxattr_prep(req, sqe); + case IORING_OP_FGETXATTR: + return io_fgetxattr_prep(req, sqe); + case IORING_OP_GETXATTR: + return io_getxattr_prep(req, sqe); } =20 printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n", @@ -7286,6 +7407,8 @@ static void io_clean_op(struct io_kiocb *req) break; case IORING_OP_SETXATTR: case IORING_OP_FSETXATTR: + case IORING_OP_GETXATTR: + case IORING_OP_FGETXATTR: __io_xattr_finish(req); break; } @@ -7439,6 +7562,12 @@ static int io_issue_sqe(struct io_kiocb *req, unsi= gned int issue_flags) case IORING_OP_SETXATTR: ret =3D io_setxattr(req, issue_flags); break; + case IORING_OP_FGETXATTR: + ret =3D io_fgetxattr(req, issue_flags); + break; + case IORING_OP_GETXATTR: + ret =3D io_getxattr(req, issue_flags); + break; default: ret =3D -EINVAL; break; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.= h index 68d003d49f14..77a8cec5a6bb 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -149,6 +149,8 @@ enum { IORING_OP_MSG_RING, IORING_OP_FSETXATTR, IORING_OP_SETXATTR, + IORING_OP_FGETXATTR, + IORING_OP_GETXATTR, =20 /* this goes last, obviously */ IORING_OP_LAST, --=20 2.30.2