From patchwork Fri Aug 12 08:34:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Metzmacher X-Patchwork-Id: 12942031 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 71AE8C25B0F for ; Fri, 12 Aug 2022 08:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229464AbiHLIey (ORCPT ); Fri, 12 Aug 2022 04:34:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbiHLIex (ORCPT ); Fri, 12 Aug 2022 04:34:53 -0400 Received: from hr2.samba.org (hr2.samba.org [IPv6:2a01:4f8:192:486::2:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F025A721B for ; Fri, 12 Aug 2022 01:34:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-Id:Date:Cc:To:From; bh=9n8eFO8XMUfghIJ1UEWQVRQaYTqey4Wvlh7X/fJjFXA=; b=QFXcio1AjQE7xKfMa8TaUpV1H1 mkpNRJtzM8YcUIsBQNky3f3gSs6U5ZvQYc7jjudDsKoIA4VVZHQPCAEpnUMYeodvQju4OoWq3oPO4 c/NCy+cogt1K2CMQ6pxXAJQgLghdEQuol41Z16q/BydvxA1+TJUfz7qGESaJ5blJwaqKtFfptht+O nT7+ZMHH8zplbfgt2iMHJbzz/TfdC9/+y8vtVZWl1iAylitaf9RjXe4Sm+Yk3t96o4/YmggpFYzfW wMP56AdM5fkfzN9fhYf4bOnJhiJQbQxAU8W4ksTg1exOgz3mujiLvioa/6rpMHPESWziTju9RpHR3 55e1v4fuLxOqNTuPNPZB2vzMytyt7F5S98Ds0475IG/Qp16Ka2jDAR2jXI5bdAnyj/UqWJriR7D8i EUkpW/nmI2x8N/jOksVq8d3HqWcB0gclZBhAH2L5uZLmNziWZ1RZw/GkIRDt0PQDGCK37RePsyf6G E0wiZICara3cLoCvNOQSZ5Ot; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1oMQ82-009Jb7-3g; Fri, 12 Aug 2022 08:34:50 +0000 From: Stefan Metzmacher To: io-uring@vger.kernel.org, axboe@kernel.dk Cc: Stefan Metzmacher Subject: [RFC PATCH 1/8] io_uring: move the current struct io_uring_sqe members to legacy sub struct Date: Fri, 12 Aug 2022 10:34:25 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Adding more and more opcodes makes the layout of struct io_uring_sqe really complex and very hard to keep an overview what fields are required to be the same for all opcodes and which can be adjusted per opcode. Adding unnamed union and struct, doesn't change anything to current callers. Check with 'git show -w' it's mainly just an indentation change. The next patches will fill the union with specific structure for each .prep() function. Signed-off-by: Stefan Metzmacher --- include/uapi/linux/io_uring.h | 129 ++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 62 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 1463cfecb56b..83f16bce3dc7 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -16,72 +16,77 @@ * IO submission data structure (Submission Queue Entry) */ struct io_uring_sqe { - __u8 opcode; /* type of operation for this sqe */ - __u8 flags; /* IOSQE_ flags */ - __u16 ioprio; /* ioprio for the request */ - __s32 fd; /* file descriptor to do IO on */ union { - __u64 off; /* offset into file */ - __u64 addr2; + /* This is the legacy structure */ struct { - __u32 cmd_op; - __u32 __pad1; + __u8 opcode; /* type of operation for this sqe */ + __u8 flags; /* IOSQE_ flags */ + __u16 ioprio; /* ioprio for the request */ + __s32 fd; /* file descriptor to do IO on */ + union { + __u64 off; /* offset into file */ + __u64 addr2; + struct { + __u32 cmd_op; + __u32 __pad1; + }; + }; + union { + __u64 addr; /* pointer to buffer or iovecs */ + __u64 splice_off_in; + }; + __u32 len; /* buffer size or number of iovecs */ + union { + __kernel_rwf_t rw_flags; + __u32 fsync_flags; + __u16 poll_events; /* compatibility */ + __u32 poll32_events; /* word-reversed for BE */ + __u32 sync_range_flags; + __u32 msg_flags; + __u32 timeout_flags; + __u32 accept_flags; + __u32 cancel_flags; + __u32 open_flags; + __u32 statx_flags; + __u32 fadvise_advice; + __u32 splice_flags; + __u32 rename_flags; + __u32 unlink_flags; + __u32 hardlink_flags; + __u32 xattr_flags; + __u32 msg_ring_flags; + }; + __u64 user_data; /* data to be passed back at completion time */ + /* 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; + union { + __s32 splice_fd_in; + __u32 file_index; + struct { + __u16 notification_idx; + __u16 addr_len; + }; + }; + union { + struct { + __u64 addr3; + __u64 __pad2[1]; + }; + /* + * If the ring is initialized with IORING_SETUP_SQE128, then + * this field is used for 80 bytes of arbitrary command data + */ + __u8 cmd[0]; + }; }; }; - union { - __u64 addr; /* pointer to buffer or iovecs */ - __u64 splice_off_in; - }; - __u32 len; /* buffer size or number of iovecs */ - union { - __kernel_rwf_t rw_flags; - __u32 fsync_flags; - __u16 poll_events; /* compatibility */ - __u32 poll32_events; /* word-reversed for BE */ - __u32 sync_range_flags; - __u32 msg_flags; - __u32 timeout_flags; - __u32 accept_flags; - __u32 cancel_flags; - __u32 open_flags; - __u32 statx_flags; - __u32 fadvise_advice; - __u32 splice_flags; - __u32 rename_flags; - __u32 unlink_flags; - __u32 hardlink_flags; - __u32 xattr_flags; - __u32 msg_ring_flags; - }; - __u64 user_data; /* data to be passed back at completion time */ - /* 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; - union { - __s32 splice_fd_in; - __u32 file_index; - struct { - __u16 notification_idx; - __u16 addr_len; - }; - }; - union { - struct { - __u64 addr3; - __u64 __pad2[1]; - }; - /* - * If the ring is initialized with IORING_SETUP_SQE128, then - * this field is used for 80 bytes of arbitrary command data - */ - __u8 cmd[0]; - }; }; /* From patchwork Fri Aug 12 08:34:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Metzmacher X-Patchwork-Id: 12942032 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 D54E0C00140 for ; Fri, 12 Aug 2022 08:35:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230049AbiHLIfA (ORCPT ); Fri, 12 Aug 2022 04:35:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231283AbiHLIe7 (ORCPT ); Fri, 12 Aug 2022 04:34:59 -0400 Received: from hr2.samba.org (hr2.samba.org [IPv6:2a01:4f8:192:486::2:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F5E8A721B for ; Fri, 12 Aug 2022 01:34:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-Id:Date:Cc:To:From; bh=NcZnmmzwhcR1lsU32RrYbOAQ2U9wKjl1y4pt/PTN1Cg=; b=o7ZApuStLZwZ6NMbF8QeTj7k8h jzZpWjhT61yRO7TR6hheoN/l43pC/vM2nHHDoDfPMMRqPZaGObblx1MqhPjcwtLXB6YYBAQ30/bzG ql9xJy5XNK3DBxPEjAzYN5nwAp0Y6oyxeBaO2OvDBH9+iIZXPTp29Oyq63zVY8BdAMaJxrdR09Y82 rZvt3SZFX6ZF9MEEpqU5oQr5M3GOA8DIxrCvZc0t7+u+T9WizZv9QZiBSsaVpeJab2Sg6eORGSHR/ sT/QlLDnk8S++D3j1/LDbsXUQ+oBanohOhrEbAfkliDM4Uf3TkwxUJ7mjCM6rXuaEI4q45tCiDkNE KNmJ371ExXpE9sWZdtYTgZFw1l6jAEiUuohiUGF3qFyPMQHi91cNPdMDDDyqzeVWG/T4s6n4NvB68 zwlpq0Tp4qNxJr3uB6EtyefFpZu3bWiQSEkAqSO8GTej/DvKA5Cxw+pUpUPl0kOgfpqYlX+6G9NJG DZa8xpIH4P4QJLeXnPpyFMNb; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1oMQ88-009JbG-EJ; Fri, 12 Aug 2022 08:34:56 +0000 From: Stefan Metzmacher To: io-uring@vger.kernel.org, axboe@kernel.dk Cc: Stefan Metzmacher Subject: [RFC PATCH 2/8] io_uring: add a generic structure for struct io_uring_sqe Date: Fri, 12 Aug 2022 10:34:26 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This makes it visible, which fields are used by every opcode. Until everything is converted individual files can define IO_URING_SQE_HIDE_LEGACY in order to hide all legacy fields under a named union arm. Signed-off-by: Stefan Metzmacher --- include/uapi/linux/io_uring.h | 30 +++++++++++++++++++++++ io_uring/io_uring.c | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 83f16bce3dc7..4dcad4929bc7 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -15,6 +15,12 @@ /* * IO submission data structure (Submission Queue Entry) */ +#ifdef IO_URING_SQE_HIDE_LEGACY +#define __io_uring_sqe_legacy legacy +#else +#define __io_uring_sqe_legacy +#endif + struct io_uring_sqe { union { /* This is the legacy structure */ @@ -85,6 +91,30 @@ struct io_uring_sqe { */ __u8 cmd[0]; }; + } __io_uring_sqe_legacy; + + struct { /* This is the structure showing the generic fields */ + struct io_uring_sqe_hdr { + __u8 opcode; /* type of operation for this sqe */ + __u8 flags; /* IOSQE_ flags */ + __u16 ioprio; /* ioprio for the request */ + __s32 fd; /* file descriptor to do IO on */ + } __attribute__((packed)) hdr; + + __u64 u64_ofs08; + __u64 u64_ofs16; + __u32 u32_ofs24; + __u32 u32_ofs28; + + struct io_uring_sqe_common { + __u64 user_data; /* data to be passed back at completion time */ + __u16 buf_info; /* buf_index or buf_group */ + __u16 personality; /* the personality to run this request under */ + } __attribute__((packed)) common; + + __u32 u32_ofs44; + __u64 u64_ofs48; + __u64 u64_ofs56; }; }; }; diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index ebfdb2212ec2..427dde7dfbd1 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3890,11 +3890,57 @@ static int __init io_uring_init(void) BUILD_BUG_ON(sizeof_field(stype, ename) != esize); \ } while (0) +#define __BUILD_BUG_VERIFY_ALIAS(stype, eoffset, esize, ename, aname) do { \ + __BUILD_BUG_VERIFY_OFFSET_SIZE(stype, eoffset, esize, ename); \ + BUILD_BUG_ON(sizeof_field(stype, ename) != sizeof_field(stype, aname)); \ + BUILD_BUG_ON(offsetof(stype, ename) != offsetof(stype, aname)); \ +} while (0) + +#define BUILD_BUG_SQE_HDR_ELEM(eoffset, etype, ename) \ + __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe_hdr, eoffset, sizeof(etype), ename) +#define BUILD_BUG_SQE_COMMON_ELEM(eoffset, etype, ename) \ + __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe_common, eoffset, sizeof(etype), ename) + #define BUILD_BUG_SQE_ELEM(eoffset, etype, ename) \ __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, sizeof(etype), ename) #define BUILD_BUG_SQE_ELEM_SIZE(eoffset, esize, ename) \ __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, esize, ename) +#define BUILD_BUG_SQE_ALIAS(eoffset, etype, ename, aname) \ + __BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, aname) + +#define BUILD_BUG_SQE_LEGACY_ALIAS(eoffset, etype, ename, lname) \ + __BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, lname) + + BUILD_BUG_ON(sizeof(struct io_uring_sqe_hdr) != 8); + BUILD_BUG_SQE_HDR_ELEM(0, __u8, opcode); + BUILD_BUG_SQE_HDR_ELEM(1, __u8, flags); + BUILD_BUG_SQE_HDR_ELEM(2, __u16, ioprio); + BUILD_BUG_SQE_HDR_ELEM(4, __s32, fd); + + BUILD_BUG_ON(sizeof(struct io_uring_sqe_common) != 12); + BUILD_BUG_SQE_COMMON_ELEM(0, __u64, user_data); + BUILD_BUG_SQE_COMMON_ELEM(8, __u16, buf_info); + BUILD_BUG_SQE_COMMON_ELEM(10, __u16, personality); + BUILD_BUG_ON(sizeof(struct io_uring_sqe) != 64); + /* generic layout */ + BUILD_BUG_SQE_ELEM(0, struct io_uring_sqe_hdr, hdr); + BUILD_BUG_SQE_LEGACY_ALIAS(0, __u8, hdr.opcode, opcode); + BUILD_BUG_SQE_LEGACY_ALIAS(1, __u8, hdr.flags, flags); + BUILD_BUG_SQE_LEGACY_ALIAS(2, __u16, hdr.ioprio, ioprio); + BUILD_BUG_SQE_LEGACY_ALIAS(4, __s32, hdr.fd, fd); + BUILD_BUG_SQE_ELEM(8, __u64, u64_ofs08); + BUILD_BUG_SQE_ELEM(16, __u64, u64_ofs16); + BUILD_BUG_SQE_ELEM(24, __u32, u32_ofs24); + BUILD_BUG_SQE_ELEM(28, __u32, u32_ofs28); + BUILD_BUG_SQE_ELEM(32, struct io_uring_sqe_common, common); + BUILD_BUG_SQE_LEGACY_ALIAS(32, __u64, common.user_data, user_data); + BUILD_BUG_SQE_LEGACY_ALIAS(40, __u16, common.buf_info, buf_index); + BUILD_BUG_SQE_LEGACY_ALIAS(42, __u16, common.personality, personality); + BUILD_BUG_SQE_ELEM(44, __u32, u32_ofs44); + BUILD_BUG_SQE_ELEM(48, __u64, u64_ofs48); + BUILD_BUG_SQE_ELEM(56, __u64, u64_ofs56); + /* Legacy layout */ BUILD_BUG_SQE_ELEM(0, __u8, opcode); BUILD_BUG_SQE_ELEM(1, __u8, flags); BUILD_BUG_SQE_ELEM(2, __u16, ioprio); From patchwork Fri Aug 12 08:34:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Metzmacher X-Patchwork-Id: 12942033 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 A4E3BC00140 for ; Fri, 12 Aug 2022 08:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231283AbiHLIfH (ORCPT ); Fri, 12 Aug 2022 04:35:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236197AbiHLIfG (ORCPT ); Fri, 12 Aug 2022 04:35:06 -0400 Received: from hr2.samba.org (hr2.samba.org [IPv6:2a01:4f8:192:486::2:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37AEDA5C56 for ; Fri, 12 Aug 2022 01:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-Id:Date:Cc:To:From; bh=Wiv8VdAbG7iP9BnJPv4+YCUL3Mbo2bTkF0cP44h2fsM=; b=kxffGrZ4eSWFLumidhkiDph/uy N4MMZy0IrBMpI8wNcMwCoWiLf3pxwAQjDGCAe0cw7mdewX8VhvGF3pBBJC5iE9iYkQbGGFRckHNgQ eIxu9GB8HP5oFIxRO7rGZD/sMK3/+4pliqxaL8WVW+JN6IHllBLvsmxmexwLaw+Fz87QAb1hqweq3 WN9+y76ySz9Bq/n6/inzfYHw1Te+rB7gk1RvN8JuCzmGxf5LhZS41m0EGRiBnpisIHiC4AqdVnvHe RtR00J+mZyF2uaMTQg51tjwwX2CrIrSR6d7w12NcCgR/t99fcCZBtFG6VcSz+JdemyIS2yy9WIbfq WalxQmbNwKKZXSyanNvEiE07GjrWVxn91KoqIs0Lyml5lKMo3EJdRRmLSnASUpJvpyugfSh6f7RKA GvO/xop2j8D9HViQPa83N5D8puFOKCta64SsLCE6h7azh5v4ivPf6SaiQKwaA6qmMMpHtsH1dLWmX m0ylqywMvAf/oes9BtMIXKRh; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1oMQ8E-009JbT-Lr; Fri, 12 Aug 2022 08:35:02 +0000 From: Stefan Metzmacher To: io-uring@vger.kernel.org, axboe@kernel.dk Cc: Stefan Metzmacher Subject: [RFC PATCH 3/8] io_uring: check legacy layout of struct io_uring_sqe with BUILD_BUG_SQE_LEGACY* Date: Fri, 12 Aug 2022 10:34:27 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This makes the next changes easier. Signed-off-by: Stefan Metzmacher --- io_uring/io_uring.c | 88 +++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 427dde7dfbd1..60426265ee9f 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3908,6 +3908,10 @@ static int __init io_uring_init(void) #define BUILD_BUG_SQE_ALIAS(eoffset, etype, ename, aname) \ __BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, aname) +#define BUILD_BUG_SQE_LEGACY(eoffset, etype, lname) \ + __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, sizeof(etype), lname) +#define BUILD_BUG_SQE_LEGACY_SIZE(eoffset, esize, lname) \ + __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, esize, lname) #define BUILD_BUG_SQE_LEGACY_ALIAS(eoffset, etype, ename, lname) \ __BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, lname) @@ -3941,48 +3945,48 @@ static int __init io_uring_init(void) BUILD_BUG_SQE_ELEM(48, __u64, u64_ofs48); BUILD_BUG_SQE_ELEM(56, __u64, u64_ofs56); /* Legacy layout */ - BUILD_BUG_SQE_ELEM(0, __u8, opcode); - BUILD_BUG_SQE_ELEM(1, __u8, flags); - BUILD_BUG_SQE_ELEM(2, __u16, ioprio); - BUILD_BUG_SQE_ELEM(4, __s32, fd); - BUILD_BUG_SQE_ELEM(8, __u64, off); - BUILD_BUG_SQE_ELEM(8, __u64, addr2); - BUILD_BUG_SQE_ELEM(8, __u32, cmd_op); - BUILD_BUG_SQE_ELEM(12, __u32, __pad1); - BUILD_BUG_SQE_ELEM(16, __u64, addr); - BUILD_BUG_SQE_ELEM(16, __u64, splice_off_in); - BUILD_BUG_SQE_ELEM(24, __u32, len); - BUILD_BUG_SQE_ELEM(28, __kernel_rwf_t, rw_flags); - BUILD_BUG_SQE_ELEM(28, /* compat */ int, rw_flags); - BUILD_BUG_SQE_ELEM(28, /* compat */ __u32, rw_flags); - BUILD_BUG_SQE_ELEM(28, __u32, fsync_flags); - BUILD_BUG_SQE_ELEM(28, /* compat */ __u16, poll_events); - BUILD_BUG_SQE_ELEM(28, __u32, poll32_events); - BUILD_BUG_SQE_ELEM(28, __u32, sync_range_flags); - BUILD_BUG_SQE_ELEM(28, __u32, msg_flags); - BUILD_BUG_SQE_ELEM(28, __u32, timeout_flags); - BUILD_BUG_SQE_ELEM(28, __u32, accept_flags); - BUILD_BUG_SQE_ELEM(28, __u32, cancel_flags); - BUILD_BUG_SQE_ELEM(28, __u32, open_flags); - BUILD_BUG_SQE_ELEM(28, __u32, statx_flags); - BUILD_BUG_SQE_ELEM(28, __u32, fadvise_advice); - BUILD_BUG_SQE_ELEM(28, __u32, splice_flags); - BUILD_BUG_SQE_ELEM(28, __u32, rename_flags); - BUILD_BUG_SQE_ELEM(28, __u32, unlink_flags); - BUILD_BUG_SQE_ELEM(28, __u32, hardlink_flags); - BUILD_BUG_SQE_ELEM(28, __u32, xattr_flags); - BUILD_BUG_SQE_ELEM(28, __u32, msg_ring_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); - BUILD_BUG_SQE_ELEM(44, __u32, file_index); - BUILD_BUG_SQE_ELEM(44, __u16, notification_idx); - BUILD_BUG_SQE_ELEM(46, __u16, addr_len); - BUILD_BUG_SQE_ELEM(48, __u64, addr3); - BUILD_BUG_SQE_ELEM_SIZE(48, 0, cmd); - BUILD_BUG_SQE_ELEM(56, __u64, __pad2); + BUILD_BUG_SQE_LEGACY(0, __u8, opcode); + BUILD_BUG_SQE_LEGACY(1, __u8, flags); + BUILD_BUG_SQE_LEGACY(2, __u16, ioprio); + BUILD_BUG_SQE_LEGACY(4, __s32, fd); + BUILD_BUG_SQE_LEGACY(8, __u64, off); + BUILD_BUG_SQE_LEGACY(8, __u64, addr2); + BUILD_BUG_SQE_LEGACY(8, __u32, cmd_op); + BUILD_BUG_SQE_LEGACY(12, __u32, __pad1); + BUILD_BUG_SQE_LEGACY(16, __u64, addr); + BUILD_BUG_SQE_LEGACY(16, __u64, splice_off_in); + BUILD_BUG_SQE_LEGACY(24, __u32, len); + BUILD_BUG_SQE_LEGACY(28, __kernel_rwf_t, rw_flags); + BUILD_BUG_SQE_LEGACY(28, /* compat */ int, rw_flags); + BUILD_BUG_SQE_LEGACY(28, /* compat */ __u32, rw_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, fsync_flags); + BUILD_BUG_SQE_LEGACY(28, /* compat */ __u16, poll_events); + BUILD_BUG_SQE_LEGACY(28, __u32, poll32_events); + BUILD_BUG_SQE_LEGACY(28, __u32, sync_range_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, msg_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, timeout_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, accept_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, cancel_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, open_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, statx_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, fadvise_advice); + BUILD_BUG_SQE_LEGACY(28, __u32, splice_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, rename_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, unlink_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, hardlink_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, xattr_flags); + BUILD_BUG_SQE_LEGACY(28, __u32, msg_ring_flags); + BUILD_BUG_SQE_LEGACY(32, __u64, user_data); + BUILD_BUG_SQE_LEGACY(40, __u16, buf_index); + BUILD_BUG_SQE_LEGACY(40, __u16, buf_group); + BUILD_BUG_SQE_LEGACY(42, __u16, personality); + BUILD_BUG_SQE_LEGACY(44, __s32, splice_fd_in); + BUILD_BUG_SQE_LEGACY(44, __u32, file_index); + BUILD_BUG_SQE_LEGACY(44, __u16, notification_idx); + BUILD_BUG_SQE_LEGACY(46, __u16, addr_len); + BUILD_BUG_SQE_LEGACY(48, __u64, addr3); + BUILD_BUG_SQE_LEGACY_SIZE(48, 0, cmd); + BUILD_BUG_SQE_LEGACY(56, __u64, __pad2); BUILD_BUG_ON(sizeof(struct io_uring_files_update) != sizeof(struct io_uring_rsrc_update)); From patchwork Fri Aug 12 08:34:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Metzmacher X-Patchwork-Id: 12942034 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 7DD61C00140 for ; Fri, 12 Aug 2022 08:35:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235029AbiHLIfO (ORCPT ); Fri, 12 Aug 2022 04:35:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236197AbiHLIfN (ORCPT ); Fri, 12 Aug 2022 04:35:13 -0400 Received: from hr2.samba.org (hr2.samba.org [IPv6:2a01:4f8:192:486::2:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59B9625D for ; Fri, 12 Aug 2022 01:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-Id:Date:Cc:To:From; bh=o0kR3zMUJZLoDs14oQ3YI4u4jgNsc7SoiXcSckYuZIs=; b=QnykvwJs8lDXLy71TgY8VeEsP5 9mwQNBZOPQSATXPUEwVYUpn3cZZwyshBvggLPXdBIT2CmuKDFd3Cv4sLOW3p578nQYjU/PeDYD8IU v5i5xRktZowjqu4CHCf/dxbN3HCpshH+So7HtwQCHSuOF325pJOCIyVkevXTI5lPcRCgR3Ld7gFjl BPKZWhy9Ia5KTD9eieOyUdwmIE6bjw3V1/kJdw5WHHqHFzuuwxS8cIg5jA6QnWMR/CUN7B8FtUD4D a7ky0g+sIzY0jMIGszECWFS6ANr7nKl12CcG4cCFf366u6gR3+x/xQE/dSriyaY1Pp7QL7NyliW+3 b/Zg8id6Sly+CCGXS+fhF3k6ncHl88ESjPeOoRismvqLMj32uWZ0Km1rMHO55xWyUBD83caco723x f/ZGeWyg2JSJRutYY+IUUDiS2MfgVxOXk6Y/QB0RIRwEtjiWR0RFfYlEhJHduxL2Z9B3xxGgTRI5k IkOUbaH8QN5CdDV8UJPpCbgx; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1oMQ8L-009Jbd-2k; Fri, 12 Aug 2022 08:35:09 +0000 From: Stefan Metzmacher To: io-uring@vger.kernel.org, axboe@kernel.dk Cc: Stefan Metzmacher Subject: [RFC PATCH 4/8] io_uring: only make use generic struct io_uring_sqe elements for tracing Date: Fri, 12 Aug 2022 10:34:28 +0200 Message-Id: <0910d8ca0ab2894101e088bee685df87eaf351cb.1660291547.git.metze@samba.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org In the long run we might change the output, but for now just prepare that defining IO_URING_SQE_HIDE_LEGACY would be possible. Signed-off-by: Stefan Metzmacher --- include/trace/events/io_uring.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/include/trace/events/io_uring.h b/include/trace/events/io_uring.h index c5b21ff0ac85..12ffbe4e69cc 100644 --- a/include/trace/events/io_uring.h +++ b/include/trace/events/io_uring.h @@ -520,28 +520,28 @@ TRACE_EVENT(io_uring_req_failed, __field( u64, addr3 ) __field( int, error ) - __string( op_str, io_uring_get_opcode(sqe->opcode) ) + __string( op_str, io_uring_get_opcode(sqe->hdr.opcode) ) ), TP_fast_assign( __entry->ctx = req->ctx; __entry->req = req; - __entry->user_data = sqe->user_data; - __entry->opcode = sqe->opcode; - __entry->flags = sqe->flags; - __entry->ioprio = sqe->ioprio; - __entry->off = sqe->off; - __entry->addr = sqe->addr; - __entry->len = sqe->len; - __entry->op_flags = sqe->poll32_events; - __entry->buf_index = sqe->buf_index; - __entry->personality = sqe->personality; - __entry->file_index = sqe->file_index; - __entry->pad1 = sqe->__pad2[0]; - __entry->addr3 = sqe->addr3; + __entry->user_data = sqe->common.user_data; + __entry->opcode = sqe->hdr.opcode; + __entry->flags = sqe->hdr.flags; + __entry->ioprio = sqe->hdr.ioprio; + __entry->off = sqe->u64_ofs08; + __entry->addr = sqe->u64_ofs16; + __entry->len = sqe->u32_ofs24; + __entry->op_flags = sqe->u32_ofs28; + __entry->buf_index = sqe->common.buf_info; + __entry->personality = sqe->common.personality; + __entry->file_index = sqe->u32_ofs44; + __entry->pad1 = sqe->u64_ofs56; + __entry->addr3 = sqe->u64_ofs48; __entry->error = error; - __assign_str(op_str, io_uring_get_opcode(sqe->opcode)); + __assign_str(op_str, io_uring_get_opcode(sqe->hdr.opcode)); ), TP_printk("ring %p, req %p, user_data 0x%llx, " From patchwork Fri Aug 12 08:34:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Metzmacher X-Patchwork-Id: 12942035 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 DE2A3C00140 for ; Fri, 12 Aug 2022 08:35:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236116AbiHLIfX (ORCPT ); Fri, 12 Aug 2022 04:35:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236197AbiHLIfV (ORCPT ); Fri, 12 Aug 2022 04:35:21 -0400 Received: from hr2.samba.org (hr2.samba.org [IPv6:2a01:4f8:192:486::2:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0AC711813 for ; Fri, 12 Aug 2022 01:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-Id:Date:Cc:To:From; bh=TsgtwajptdxMGTmu5bVJE1WEzLCihCl0Umpf54+PXIg=; b=TzEq9S4d3xGLQKIyJ28b4qUyx4 qbR1xGIpmpBhnXZAkaF/FoaOj8aK939JOaFJhgP8TlTQp+NFLEvCDipla4mqeHPDYCPcj8svuP2RY ItlkJ9gi1YdRoPOZerFrnq/mNBSLFMa86m+Po+u8P8iqWRsA8wcKKEfOGCdhtblOs29iAy4JGbNk7 S5xjlUfO8nAcWYnb48jhpPSi7TXElU4KZBaNcHzvgKY93MC7/kPfdZ60tDlfiDpNWJP9RFj340/mT mZo45ev6QMi4sl7BmjUmbNB9TtZjcrIhy9wJDgDw+Szd7nygo+93ZY/zY4hdv+I9QSDWWL5mrii82 Cnr1+AUhVMjM6PWs8tk2LR+90uxnWYZHNfrp1z1o8r3RC+roTx7V/u0eGwNT76Oithkz4mKWHSD+5 nndLkISi1PpPSqTnjlJI1avR/TlqbJhdyuvRXhaZnGTORoT1mwtL6xGJbZRyKXgOHoOnkkwwt4AtN /n5zk5xHXuYvx5wRpGwUt4Xt; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1oMQ8R-009Jbl-Je; Fri, 12 Aug 2022 08:35:16 +0000 From: Stefan Metzmacher To: io-uring@vger.kernel.org, axboe@kernel.dk Cc: Stefan Metzmacher Subject: [RFC PATCH 5/8] io_uring: only access generic struct io_uring_sqe elements in io_uring.c Date: Fri, 12 Aug 2022 10:34:29 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Signed-off-by: Stefan Metzmacher --- io_uring/io_uring.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 60426265ee9f..f82173bde393 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -39,6 +39,7 @@ * Copyright (C) 2018-2019 Jens Axboe * Copyright (c) 2018-2019 Christoph Hellwig */ +#define IO_URING_SQE_HIDE_LEGACY 1 #include #include #include @@ -1837,10 +1838,10 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, u8 opcode; /* req is partially pre-initialised, see io_preinit_req() */ - req->opcode = opcode = READ_ONCE(sqe->opcode); + req->opcode = opcode = READ_ONCE(sqe->hdr.opcode); /* same numerical values with corresponding REQ_F_*, safe to copy */ - req->flags = sqe_flags = READ_ONCE(sqe->flags); - req->cqe.user_data = READ_ONCE(sqe->user_data); + req->flags = sqe_flags = READ_ONCE(sqe->hdr.flags); + req->cqe.user_data = READ_ONCE(sqe->common.user_data); req->file = NULL; req->rsrc_node = NULL; req->task = current; @@ -1857,7 +1858,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, if (sqe_flags & IOSQE_BUFFER_SELECT) { if (!def->buffer_select) return -EOPNOTSUPP; - req->buf_index = READ_ONCE(sqe->buf_group); + req->buf_index = READ_ONCE(sqe->common.buf_info); } if (sqe_flags & IOSQE_CQE_SKIP_SUCCESS) ctx->drain_disabled = true; @@ -1881,7 +1882,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, } } - if (!def->ioprio && sqe->ioprio) + if (!def->ioprio && sqe->hdr.ioprio) return -EINVAL; if (!def->iopoll && (ctx->flags & IORING_SETUP_IOPOLL)) return -EINVAL; @@ -1889,7 +1890,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, if (def->needs_file) { struct io_submit_state *state = &ctx->submit_state; - req->cqe.fd = READ_ONCE(sqe->fd); + req->cqe.fd = READ_ONCE(sqe->hdr.fd); /* * Plug now if we have more than 2 IO left after this, and the @@ -1902,7 +1903,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, } } - personality = READ_ONCE(sqe->personality); + personality = READ_ONCE(sqe->common.personality); if (personality) { int ret; @@ -3909,11 +3910,11 @@ static int __init io_uring_init(void) __BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, aname) #define BUILD_BUG_SQE_LEGACY(eoffset, etype, lname) \ - __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, sizeof(etype), lname) + __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, sizeof(etype), legacy.lname) #define BUILD_BUG_SQE_LEGACY_SIZE(eoffset, esize, lname) \ - __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, esize, lname) + __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, esize, legacy.lname) #define BUILD_BUG_SQE_LEGACY_ALIAS(eoffset, etype, ename, lname) \ - __BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, lname) + __BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, legacy.lname) BUILD_BUG_ON(sizeof(struct io_uring_sqe_hdr) != 8); BUILD_BUG_SQE_HDR_ELEM(0, __u8, opcode); From patchwork Fri Aug 12 08:34:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Metzmacher X-Patchwork-Id: 12942036 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 CE703C00140 for ; Fri, 12 Aug 2022 08:35:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236015AbiHLIf1 (ORCPT ); Fri, 12 Aug 2022 04:35:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236197AbiHLIf0 (ORCPT ); Fri, 12 Aug 2022 04:35:26 -0400 Received: from hr2.samba.org (hr2.samba.org [IPv6:2a01:4f8:192:486::2:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86CEE12D39 for ; Fri, 12 Aug 2022 01:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-Id:Date:Cc:To:From; bh=ff7Nc2RhtxW7fQcgYHeopNtDiVRD4BMoeDN12LLnR/Y=; b=uc0RKq3m7TSQE1kXo5cQRjDfgQ KTSTpBJdPKdG+O5snCnxwqQt6/Zj6155xTYi7l+KL1cdOugDn70d1EiHBBTg7lQlQd/fU3E8b0Cb6 K8F7ytkzRcpL/9zg7jJbTJwxTgxviCkOAusWeE7vQy0LvxDWCGUjou2wk7tOt/fYapGacx/4Xapx/ JzoZ/NP8N+1pUfPBrnfpk/cOpJhf2Lf8IpUNj0Zo4q5rNnGoEghnt8/RxjN+/1SBIts/4N/0sp1U7 3rpVoAqwolYcP9qHOdHTGJweZCnjZI3IvdZgNauTg1QdpH6SX0eZds1I/M7g1ezT6jx4X2YCkIO+1 PURaGmNnXZRPVQD1OiFfaHPCM07Q3bRtOHK8DKQkfmjUjE54uEgmcnOCceXK9R0a3Leg4PP0jSX9x jWnVgFuZEpX3nquI7geej/v9LVh015V4G9YIEKKRE44Dk2Q3Y9X94OletIF+CCAVkhvKQfI3MdyaM 5c7QxCs1t7mDK6KTQZEocxfU; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1oMQ8Z-009Jbt-7v; Fri, 12 Aug 2022 08:35:23 +0000 From: Stefan Metzmacher To: io-uring@vger.kernel.org, axboe@kernel.dk Cc: Stefan Metzmacher Subject: [RFC PATCH 6/8] io_uring: add BUILD_BUG_SQE_HDR_COMMON() macro Date: Fri, 12 Aug 2022 10:34:30 +0200 Message-Id: <3d34b306c65ccf095646ba01b08cdf473a54957b.1660291547.git.metze@samba.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This will be used in the next commits in order to check common fields of opcode specific struct io_uring_sqe union arms. Signed-off-by: Stefan Metzmacher --- io_uring/io_uring.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index f82173bde393..8e1a8800b252 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3916,6 +3916,20 @@ static int __init io_uring_init(void) #define BUILD_BUG_SQE_LEGACY_ALIAS(eoffset, etype, ename, lname) \ __BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, legacy.lname) +#define BUILD_BUG_SQE_HDR_COMMON(subtype, subname) do { \ + BUILD_BUG_ON(sizeof(subtype) != 64); \ + BUILD_BUG_SQE_ELEM(0, subtype, subname); \ + BUILD_BUG_SQE_ELEM(0, struct io_uring_sqe_hdr, subname.hdr); \ + BUILD_BUG_SQE_ALIAS(0, __u8, subname.hdr.opcode, hdr.opcode); \ + BUILD_BUG_SQE_ALIAS(1, __u8, subname.hdr.flags, hdr.flags); \ + BUILD_BUG_SQE_ALIAS(2, __u16, subname.hdr.ioprio, hdr.ioprio); \ + BUILD_BUG_SQE_ALIAS(4, __s32, subname.hdr.fd, hdr.fd); \ + BUILD_BUG_SQE_ELEM(32, struct io_uring_sqe_common, subname.common); \ + BUILD_BUG_SQE_ALIAS(32, __u64, subname.common.user_data, common.user_data); \ + BUILD_BUG_SQE_ALIAS(40, __u16, subname.common.buf_info, common.buf_info); \ + BUILD_BUG_SQE_ALIAS(42, __u16, subname.common.personality, common.personality); \ +} while (0) + BUILD_BUG_ON(sizeof(struct io_uring_sqe_hdr) != 8); BUILD_BUG_SQE_HDR_ELEM(0, __u8, opcode); BUILD_BUG_SQE_HDR_ELEM(1, __u8, flags); From patchwork Fri Aug 12 08:34:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Metzmacher X-Patchwork-Id: 12942037 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 5C5CDC00140 for ; Fri, 12 Aug 2022 08:35:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236290AbiHLIfj (ORCPT ); Fri, 12 Aug 2022 04:35:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236197AbiHLIfd (ORCPT ); Fri, 12 Aug 2022 04:35:33 -0400 Received: from hr2.samba.org (hr2.samba.org [IPv6:2a01:4f8:192:486::2:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F2E214088 for ; Fri, 12 Aug 2022 01:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-Id:Date:Cc:To:From; bh=9vLR9I/s/Gt9S7/C2keS2sfOrL5iuoZP7IGqkr6U+V4=; b=J4oDItYSNCuRyPCkOlimzoX3sn 0TdJWOCPD5DmtH9IMKwkE4Rhemx2LEQUkEFJnfO7pDwHvPBrpuPd+HSsCqgpXixjuRIb9h8n48yM6 G3eu/luBKeFTqPC5Krnr3k4UQpgNZSxO9OrmBzV/Oc9k4/yUQCaO/A6jjNXpsKS/QFEnqsJE3eerD yLBrzAYNXDI5EAeLm61LmyRCg4aC5h7k7+jlbpaVAQtYCNrJF5Js+Uv1djDAeRUTDsJQxp0289g8x E6RNulzzMa919Xlu07JrNmk94rWZ/vSJcyshnqPACJ+wRzC6X4t3L+W7t4ZW/SyqvnGHM8NnEnv07 zrYM5kuvtNcDS8nEY8HWOrS/TpFySIy2ZH/RPS/ETR0Ht0er514B4qB284uDLKNR/h1dGQItdQcRs lkw4Q+eGpAHmCGyNrRaB9D5NZ9ulGiBv42+8XPPviltVcub0f6cJeCv41sif9D2KbVQxv0hkbRpbY VSRHb2hRnkDH3kBwcpi5yuoK; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1oMQ8g-009Jc1-1h; Fri, 12 Aug 2022 08:35:30 +0000 From: Stefan Metzmacher To: io-uring@vger.kernel.org, axboe@kernel.dk Cc: Stefan Metzmacher Subject: [RFC PATCH 7/8] io_uring: introduce struct io_uring_sqe_rw for all io_prep_rw() using opcodes Date: Fri, 12 Aug 2022 10:34:31 +0200 Message-Id: <03b3026be552fe5ddb36c281d75881c3b887c89b.1660291547.git.metze@samba.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This is the start to use opcode specific struct io_uring_sqe layouts. It hopefully make it much easier to maintain the struct io_uring_sqe. Signed-off-by: Stefan Metzmacher --- include/uapi/linux/io_uring.h | 16 ++++++++++++++++ io_uring/io_uring.c | 9 +++++++++ io_uring/rw.c | 26 +++++++++++++++++++------- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 4dcad4929bc7..690b13229227 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -116,6 +116,22 @@ struct io_uring_sqe { __u64 u64_ofs48; __u64 u64_ofs56; }; + + /* IORING_OP_{READV,WRITEV,READ_FIXED,WRITE_FIXED,READ,WRITE} */ + struct io_uring_sqe_rw { + struct io_uring_sqe_hdr hdr; + + __u64 offset; + __u64 buffer_addr; + __u32 length; + __u32 flags; + + struct io_uring_sqe_common common; + + __u32 u32_ofs44; + __u64 u64_ofs48; + __u64 u64_ofs56; + } rw; }; }; diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 8e1a8800b252..e3336621e667 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -4003,6 +4003,15 @@ static int __init io_uring_init(void) BUILD_BUG_SQE_LEGACY_SIZE(48, 0, cmd); BUILD_BUG_SQE_LEGACY(56, __u64, __pad2); + BUILD_BUG_SQE_HDR_COMMON(struct io_uring_sqe_rw, rw); + BUILD_BUG_SQE_LEGACY_ALIAS(8, __u64, rw.offset, off); + BUILD_BUG_SQE_LEGACY_ALIAS(16, __u64, rw.buffer_addr, addr); + BUILD_BUG_SQE_LEGACY_ALIAS(24, __u32, rw.length, len); + BUILD_BUG_SQE_LEGACY_ALIAS(28, __u32, rw.flags, rw_flags); + BUILD_BUG_SQE_ALIAS(44, __u32, rw.u32_ofs44, u32_ofs44); + BUILD_BUG_SQE_ALIAS(48, __u64, rw.u64_ofs48, u64_ofs48); + BUILD_BUG_SQE_ALIAS(56, __u64, rw.u64_ofs56, u64_ofs56); + BUILD_BUG_ON(sizeof(struct io_uring_files_update) != sizeof(struct io_uring_rsrc_update)); BUILD_BUG_ON(sizeof(struct io_uring_rsrc_update) > diff --git a/io_uring/rw.c b/io_uring/rw.c index 3d732b19b760..5612b03af997 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#define IO_URING_SQE_HIDE_LEGACY 1 #include #include #include @@ -33,15 +34,16 @@ static inline bool io_file_supports_nowait(struct io_kiocb *req) return req->flags & REQ_F_SUPPORT_NOWAIT; } -int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe) +int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *_sqe) { + const struct io_uring_sqe_rw *sqe = &_sqe->rw; struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); unsigned ioprio; int ret; - rw->kiocb.ki_pos = READ_ONCE(sqe->off); + rw->kiocb.ki_pos = READ_ONCE(sqe->offset); /* used for fixed read/write too - just read unconditionally */ - req->buf_index = READ_ONCE(sqe->buf_index); + req->buf_index = READ_ONCE(sqe->common.buf_info); if (req->opcode == IORING_OP_READ_FIXED || req->opcode == IORING_OP_WRITE_FIXED) { @@ -55,7 +57,7 @@ int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe) io_req_set_rsrc_node(req, ctx, 0); } - ioprio = READ_ONCE(sqe->ioprio); + ioprio = READ_ONCE(sqe->hdr.ioprio); if (ioprio) { ret = ioprio_check_cap(ioprio); if (ret) @@ -66,9 +68,19 @@ int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe) rw->kiocb.ki_ioprio = get_current_ioprio(); } - rw->addr = READ_ONCE(sqe->addr); - rw->len = READ_ONCE(sqe->len); - rw->flags = READ_ONCE(sqe->rw_flags); + rw->addr = READ_ONCE(sqe->buffer_addr); + rw->len = READ_ONCE(sqe->length); + rw->flags = READ_ONCE(sqe->flags); + + /* + * Note for compat reasons we don't check the following + * to be zero: + * + * sqe->u32_ofs44 + * sqe->u64_ofs48 + * sqe->u64_ofs56 + */ + return 0; } From patchwork Fri Aug 12 08:34:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Metzmacher X-Patchwork-Id: 12942038 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 3F49EC3F6B0 for ; Fri, 12 Aug 2022 08:35:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236346AbiHLIfl (ORCPT ); Fri, 12 Aug 2022 04:35:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236197AbiHLIfk (ORCPT ); Fri, 12 Aug 2022 04:35:40 -0400 Received: from hr2.samba.org (hr2.samba.org [IPv6:2a01:4f8:192:486::2:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F356E1BE9D for ; Fri, 12 Aug 2022 01:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-Id:Date:Cc:To:From; bh=sC6oBsYEFjtJzAxkKyLzp3l6tw1ZIHBKxL/2QAcAcGg=; b=IvgiPfj+aQIPwMW/a7gGciDFLe UqFGfth7QhTtH0bBNDs9yDC5OR0b16S0qfmjMdP5t/vYwmwTadfhDIkdt++ZVO0fVbzXACcPxceAz xyu4pvhSCiQNQ0StE+bU8thV8LaNC8gSNt671cRVN9XBOJLH0lQYB9s2lWizkVHXnqujtbiKml3wR F2XyxD66wkCE4Z1LqW7E+9nARe5dAoF4b4qVQzlZmOu05bg9Bq6xa4kOMg/Q5Ofko/Jr5gCBY0lYi vWulews/0bo2Rq0xb8JmKYPKWwnsOnZCqg1miuEZke3XlUo61dcBd5NyKUf50Au9l3FmGwn9NiT66 +pId+lqdPzcawbRaJmI+IVQINRZd/MnP6H0f2MrbPlOt+mvmU98hOtlvijvTiksOXB9N95+DiN5dE 1nmiTv+9+djYdAUNfdvy3aD5b5pueZg3scPS9KxEFDtpFc8tsKIDi3po7lc6zcVcYDZnCYN/2ByIB 87UDATaRNKqPFe82GgOLRmIB; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1oMQ8m-009Jc9-MW; Fri, 12 Aug 2022 08:35:36 +0000 From: Stefan Metzmacher To: io-uring@vger.kernel.org, axboe@kernel.dk Cc: Stefan Metzmacher Subject: [RFC PATCH 8/8] io_uring: introduce struct io_uring_sqe_{fsync,sfr,fallocate} Date: Fri, 12 Aug 2022 10:34:32 +0200 Message-Id: <07ade3e4e9182f0857e6206e6613063639f95dce.1660291547.git.metze@samba.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This allows us to use IO_URING_SQE_HIDE_LEGACY in io_uring/sync.c Signed-off-by: Stefan Metzmacher --- include/uapi/linux/io_uring.h | 48 +++++++++++++++++++++++++++++ io_uring/io_uring.c | 33 ++++++++++++++++++++ io_uring/sync.c | 58 ++++++++++++++++++++++++++--------- 3 files changed, 124 insertions(+), 15 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 690b13229227..6428d97e14fc 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -132,6 +132,54 @@ struct io_uring_sqe { __u64 u64_ofs48; __u64 u64_ofs56; } rw; + + /* IORING_OP_FSYNC */ + struct io_uring_sqe_fsync { + struct io_uring_sqe_hdr hdr; + + __u64 offset; + __u64 u64_ofs16; + __u32 length; + __u32 flags; + + struct io_uring_sqe_common common; + + __u32 u32_ofs44; + __u64 u64_ofs48; + __u64 u64_ofs56; + } fsync; + + /* IORING_OP_SYNC_FILE_RANGE */ + struct io_uring_sqe_sfr { + struct io_uring_sqe_hdr hdr; + + __u64 offset; + __u64 u64_ofs16; + __u32 length; + __u32 flags; + + struct io_uring_sqe_common common; + + __u32 u32_ofs44; + __u64 u64_ofs48; + __u64 u64_ofs56; + } sfr; + + /* IORING_OP_FALLOCATE */ + struct io_uring_sqe_fallocate { + struct io_uring_sqe_hdr hdr; + + __u64 offset; + __u64 length; + __u32 mode; + __u32 u32_ofs28; + + struct io_uring_sqe_common common; + + __u32 u32_ofs44; + __u64 u64_ofs48; + __u64 u64_ofs56; + } fallocate; }; }; diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index e3336621e667..893252701363 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -4012,6 +4012,39 @@ static int __init io_uring_init(void) BUILD_BUG_SQE_ALIAS(48, __u64, rw.u64_ofs48, u64_ofs48); BUILD_BUG_SQE_ALIAS(56, __u64, rw.u64_ofs56, u64_ofs56); + BUILD_BUG_SQE_HDR_COMMON(struct io_uring_sqe_fsync, fsync); + BUILD_BUG_SQE_LEGACY_ALIAS(8, __u64, fsync.offset, off); + BUILD_BUG_SQE_LEGACY_ALIAS(16, __u64, fsync.u64_ofs16, addr); + BUILD_BUG_SQE_ALIAS(16, __u64, fsync.u64_ofs16, u64_ofs16); + BUILD_BUG_SQE_LEGACY_ALIAS(24, __u32, fsync.length, len); + BUILD_BUG_SQE_LEGACY_ALIAS(28, __u32, fsync.flags, fsync_flags); + BUILD_BUG_SQE_LEGACY_ALIAS(44, __u32, fsync.u32_ofs44, splice_fd_in); + BUILD_BUG_SQE_ALIAS(44, __u32, rw.u32_ofs44, u32_ofs44); + BUILD_BUG_SQE_ALIAS(48, __u64, rw.u64_ofs48, u64_ofs48); + BUILD_BUG_SQE_ALIAS(56, __u64, rw.u64_ofs56, u64_ofs56); + + BUILD_BUG_SQE_HDR_COMMON(struct io_uring_sqe_sfr, sfr); + BUILD_BUG_SQE_LEGACY_ALIAS(8, __u64, sfr.offset, off); + BUILD_BUG_SQE_LEGACY_ALIAS(16, __u64, sfr.u64_ofs16, addr); + BUILD_BUG_SQE_ALIAS(16, __u64, sfr.u64_ofs16, u64_ofs16); + BUILD_BUG_SQE_LEGACY_ALIAS(24, __u32, sfr.length, len); + BUILD_BUG_SQE_LEGACY_ALIAS(28, __u32, sfr.flags, fsync_flags); + BUILD_BUG_SQE_LEGACY_ALIAS(44, __u32, sfr.u32_ofs44, splice_fd_in); + BUILD_BUG_SQE_ALIAS(44, __u32, sfr.u32_ofs44, u32_ofs44); + BUILD_BUG_SQE_ALIAS(48, __u64, sfr.u64_ofs48, u64_ofs48); + BUILD_BUG_SQE_ALIAS(56, __u64, sfr.u64_ofs56, u64_ofs56); + + BUILD_BUG_SQE_HDR_COMMON(struct io_uring_sqe_fallocate, fallocate); + BUILD_BUG_SQE_LEGACY_ALIAS(8, __u64, fallocate.offset, off); + BUILD_BUG_SQE_LEGACY_ALIAS(16, __u64, fallocate.length, addr); + BUILD_BUG_SQE_LEGACY_ALIAS(24, __u32, fallocate.mode, len); + BUILD_BUG_SQE_LEGACY_ALIAS(28, __u32, fallocate.u32_ofs28, rw_flags); + BUILD_BUG_SQE_ALIAS(28, __u32, fallocate.u32_ofs28, u32_ofs28); + BUILD_BUG_SQE_LEGACY_ALIAS(44, __u32, fallocate.u32_ofs44, splice_fd_in); + BUILD_BUG_SQE_ALIAS(44, __u32, fallocate.u32_ofs44, u32_ofs44); + BUILD_BUG_SQE_ALIAS(48, __u64, fallocate.u64_ofs48, u64_ofs48); + BUILD_BUG_SQE_ALIAS(56, __u64, fallocate.u64_ofs56, u64_ofs56); + BUILD_BUG_ON(sizeof(struct io_uring_files_update) != sizeof(struct io_uring_rsrc_update)); BUILD_BUG_ON(sizeof(struct io_uring_rsrc_update) > diff --git a/io_uring/sync.c b/io_uring/sync.c index 64e87ea2b8fb..ba8e3a91a1ab 100644 --- a/io_uring/sync.c +++ b/io_uring/sync.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#define IO_URING_SQE_HIDE_LEGACY 1 #include #include #include @@ -22,16 +23,25 @@ struct io_sync { int mode; }; -int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *_sqe) { + const struct io_uring_sqe_sfr *sqe = &_sqe->sfr; struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync); - if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in)) + /* + * Note for compat reasons we don't check the following + * to be zero: + * + * sqe->u64_ofs48 + * sqe->u64_ofs56 + */ + if (unlikely(sqe->u64_ofs16 || sqe->common.buf_info || sqe->u32_ofs44)) return -EINVAL; - sync->off = READ_ONCE(sqe->off); - sync->len = READ_ONCE(sqe->len); - sync->flags = READ_ONCE(sqe->sync_range_flags); + sync->off = READ_ONCE(sqe->offset); + sync->len = READ_ONCE(sqe->length); + sync->flags = READ_ONCE(sqe->flags); + return 0; } @@ -49,19 +59,28 @@ int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags) return IOU_OK; } -int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *_sqe) { + const struct io_uring_sqe_fsync *sqe = &_sqe->fsync; struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync); - if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in)) + /* + * Note for compat reasons we don't check the following + * to be zero: + * + * sqe->u64_ofs48 + * sqe->u64_ofs56 + */ + if (unlikely(sqe->u64_ofs16 || sqe->common.buf_info || sqe->u32_ofs44)) return -EINVAL; - sync->flags = READ_ONCE(sqe->fsync_flags); + sync->flags = READ_ONCE(sqe->flags); if (unlikely(sync->flags & ~IORING_FSYNC_DATASYNC)) return -EINVAL; - sync->off = READ_ONCE(sqe->off); - sync->len = READ_ONCE(sqe->len); + sync->off = READ_ONCE(sqe->offset); + sync->len = READ_ONCE(sqe->length); + return 0; } @@ -81,16 +100,25 @@ int io_fsync(struct io_kiocb *req, unsigned int issue_flags) return IOU_OK; } -int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *_sqe) { + const struct io_uring_sqe_fallocate *sqe = &_sqe->fallocate; struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync); - if (sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in) + /* + * Note for compat reasons we don't check the following + * to be zero: + * + * sqe->u64_ofs48 + * sqe->u64_ofs56 + */ + if (sqe->common.buf_info || sqe->u32_ofs28 || sqe->u32_ofs44) return -EINVAL; - sync->off = READ_ONCE(sqe->off); - sync->len = READ_ONCE(sqe->addr); - sync->mode = READ_ONCE(sqe->len); + sync->off = READ_ONCE(sqe->offset); + sync->len = READ_ONCE(sqe->length); + sync->mode = READ_ONCE(sqe->mode); + return 0; }