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=-2.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by gnuweeb.org (Postfix) with ESMTPS id 7154D7F7F3 for ; Mon, 6 Jun 2022 11:52:14 +0000 (UTC) Authentication-Results: gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=KFAf+A4e; dkim-atps=neutral Received: by mail-wm1-f42.google.com with SMTP id a10so5002023wmj.5 for ; Mon, 06 Jun 2022 04:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=CWvsDpmb9aoWZSw0w9qyVTNu5dEh0Xri0WzmJyC9vWU=; b=KFAf+A4etENIbmWb2tYrQlVGH2XGoS7LimdbOI6spSSL/e50zrVvOzlwV1sEvPQS2c rex7l0sV8N3u+VbgDm/sOD8GLMnV19IW45M73WA+EHS0+k6M7Gz7JpROoEsQwQDJHQm1 QHGJbY1jHKLlrgxo+3vxoMfnmTeMyRtNOAdL1e2idBlqYGXl3jwXB1gUWExDeNZUVff2 xRuRg/Ew9qeJxcplV1Ctqy9dRYtCmqXEIgrvvTndUiIAqJWWUG9Y58VmBltwxlzUm9Tw 1ZlHXXM8NZkZQwX/PFms0I/m6b4Ka2aN2hZRsAfUKDu4+4zFPGHxaYLHHloyCq0+B/4B 1xwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=CWvsDpmb9aoWZSw0w9qyVTNu5dEh0Xri0WzmJyC9vWU=; b=BIhBgiqfZFqa3Dd4Jq0XIEYJARRGKdwMKW0EF8wzI6jXsreaLWpVqePSdq1CeI3F8G Sa7ODvDK8ptFz/fRAOVeQNJm1BuITKAj9XDPtNHU5w4LAG5AKDYnEigYnZu8cmorFRoL iGy/ymgIa0dU+jYQYvujG5ZiCPoh7sdHZgZfKAoubOzgnrJFhz7nRmxJROQw9XGxjlEr 7tYFc8hirUtXXg2tCPI+BtBsTo+tv+MCA+a2lWq31Hp6lYevCJ6R3FTX4J0uCanQAKgi pF7EsHU9q6t8RQ9m603JTXEHdEmG6vC+UstNcL0SXnMclxj3tlhMqOf45vsNIt2fOtgM iLWg== X-Gm-Message-State: AOAM53148nLZajXAo9xgZS8r73yyZ1MlpamFyp6JVuVmqIw30Amjwrhr atP0hRqB5uLk82E90HUINHU= X-Google-Smtp-Source: ABdhPJzRXeCdyhSHqkt9CPGLU032z9s6ZQpMlTsLNmrjTsWjUTv652s080pNhoDqyPrWTWMvXA+YWA== X-Received: by 2002:a05:600c:1d05:b0:397:6fd1:6959 with SMTP id l5-20020a05600c1d0500b003976fd16959mr22816535wms.202.1654516332722; Mon, 06 Jun 2022 04:52:12 -0700 (PDT) Received: from [192.168.43.77] (82-132-232-174.dab.02.net. [82.132.232.174]) by smtp.gmail.com with ESMTPSA id l19-20020a1ced13000000b0039c1396b495sm17170571wmh.9.2022.06.06.04.52.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Jun 2022 04:52:12 -0700 (PDT) Message-ID: Date: Mon, 6 Jun 2022 12:51:46 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [RFC PATCH v1 5/5] Add io_uring data structure build assertion Content-Language: en-US To: Ammar Faizi , Jens Axboe Cc: Fernanda Ma'rouf , Hao Xu , Alviro Iskandar Setiawan , io-uring Mailing List , GNU/Weeb Mailing List References: <20220606061209.335709-1-ammarfaizi2@gnuweeb.org> <20220606061209.335709-6-ammarfaizi2@gnuweeb.org> From: Pavel Begunkov In-Reply-To: <20220606061209.335709-6-ammarfaizi2@gnuweeb.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: On 6/6/22 07:12, Ammar Faizi wrote: > Ensure io_uring data structure consistent between the kernel and user > space. These assertions are taken from io_uring.c in the kernel. I don't see why would we do that. io_uring.h is only intended to be copied from the kernel's uapi without some weird changes in structs, I really really hope nobody will be trying to modify it separately. But the real downside is that we'll need to maintain a full duplicate of it and keep updating both for no good reason. What do I miss? > > Signed-off-by: Ammar Faizi > --- > src/Makefile | 3 ++- > src/build_assert.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 59 insertions(+), 1 deletion(-) > create mode 100644 src/build_assert.h > > diff --git a/src/Makefile b/src/Makefile > index 12cf49f..aed3c40 100644 > --- a/src/Makefile > +++ b/src/Makefile > @@ -7,7 +7,8 @@ libdevdir ?= $(prefix)/lib > > CPPFLAGS ?= > override CPPFLAGS += -D_GNU_SOURCE \ > - -Iinclude/ -include ../config-host.h > + -Iinclude/ -include ../config-host.h \ > + -include build_assert.h > CFLAGS ?= -g -O2 -Wall -Wextra -fno-stack-protector > override CFLAGS += -Wno-unused-parameter -Wno-sign-compare -DLIBURING_INTERNAL > SO_CFLAGS=-fPIC $(CFLAGS) > diff --git a/src/build_assert.h b/src/build_assert.h > new file mode 100644 > index 0000000..5b2a9c6 > --- /dev/null > +++ b/src/build_assert.h > @@ -0,0 +1,57 @@ > +/* SPDX-License-Identifier: MIT */ > + > +#ifndef LIBURING_BUILD_ASSERT_H > +#define LIBURING_BUILD_ASSERT_H > + > +#include "liburing/io_uring.h" > +#include "lib.h" > + > +static inline __attribute__((__unused__)) void io_uring_build_assert(void) > +{ > +#define __BUILD_BUG_VERIFY_ELEMENT(stype, eoffset, etype, ename) do { \ > + BUILD_BUG_ON(offsetof(stype, ename) != eoffset); \ > + BUILD_BUG_ON(sizeof(etype) != sizeof_field(stype, ename)); \ > +} while (0) > + > +#define BUILD_BUG_SQE_ELEM(eoffset, etype, ename) \ > + __BUILD_BUG_VERIFY_ELEMENT(struct io_uring_sqe, eoffset, etype, ename) > + BUILD_BUG_ON(sizeof(struct io_uring_sqe) != 64); > + 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(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(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(48, __u64, addr3); > + > + BUILD_BUG_ON(sizeof(struct io_uring_files_update) != > + sizeof(struct io_uring_rsrc_update)); > + BUILD_BUG_ON(sizeof(struct io_uring_rsrc_update) > > + sizeof(struct io_uring_rsrc_update2)); > +} > + > +#endif -- Pavel Begunkov