From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A4D1C433F5 for ; Sat, 2 Oct 2021 01:29:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 455C061AFA for ; Sat, 2 Oct 2021 01:29:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231904AbhJBBbI (ORCPT ); Fri, 1 Oct 2021 21:31:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230255AbhJBBbI (ORCPT ); Fri, 1 Oct 2021 21:31:08 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC81DC061775 for ; Fri, 1 Oct 2021 18:29:22 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id x4so7377407pln.5 for ; Fri, 01 Oct 2021 18:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amikom.ac.id; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n59o9XNcHfUxT95mwLLDOSF+fK2tB71OB69oeAiTLM8=; b=UTGvTKvjdQyuAZhaHMXluuXm3uy/bwdZyq4Ua6FUsFrOnhns5muPYITRzupzfuog99 Yypf3iw74fjfAaMqiZtpzIiOJ0EQlcQextL9punRVZObtn+hWn77mugSQjjCAoFmqTGX e0V66GsjX+0nzkq0uVUcW0bukPYSbXmHBNitfYvczhyNGOqVnG40MmiUsCQuAOzVEvSd uskkG94QjL6ghk4lNrWr9XDnF9w7AkjAtSPakl/UisNWOcENrvoPFAaA50uIpKvDMY1S 04OUYiwVFlOqqL9053iZJDVhlwfwFXF+KbnZJfTj+t0b294kVvLoMvJmVPJWgCNdldCi 6IEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n59o9XNcHfUxT95mwLLDOSF+fK2tB71OB69oeAiTLM8=; b=T8cwOMcOJms3YXMLSfeELOqvI69TQogBwdRsvtpc/2xPumLnWaHvWQMLx/d/PIiyLR NSDmp93deN/scBKZee3G5eNN+Ca9X2IC6RDR5YNoko86WGQcgHBJoeGzyU/gwB42eQ8n ctyA5ub9RMjhCPyq0vO1nRrzfXb7Q+EQetKPBEG9XxISEgSnTobcPcYN1itsXQCODtYt LDt2iWBdf9TD4AN/s3wnV/4jZtqzW0PainW3qM+v3mwc3zLHb9amnvh/cmAVxO10md+1 u87HzgKw8fqKxEDdVQnH7DBWtt1Or0H0MKCuNRdhppgfastp43Dv7oy2pCrVWNWoLgqJ 8sBA== X-Gm-Message-State: AOAM532S5xwN/6Mg28+OV3LZstT0h3mGkRc0qrwQn9JZQf3rQ9zuLCv+ k1zj1GTTkdQbmfj/Ga/1+TM1Kg== X-Google-Smtp-Source: ABdhPJw5+Q0VNUCp6XqQ2ZRHcrmJxcSWBnzCF1HgJS2gquj1ivg06kVpM7q7hP30ZuypFpGn935yHA== X-Received: by 2002:a17:90a:14c4:: with SMTP id k62mr16573380pja.154.1633138162041; Fri, 01 Oct 2021 18:29:22 -0700 (PDT) Received: from integral.. ([182.2.69.211]) by smtp.gmail.com with ESMTPSA id b13sm867654pjl.15.2021.10.01.18.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 18:29:21 -0700 (PDT) From: Ammar Faizi To: Jens Axboe , Pavel Begunkov Cc: Ammar Faizi , io-uring Mailing List , Bedirhan KURT , Louvian Lyndal , Ammar Faizi Subject: [PATCH v2 RFC liburing 1/4] src/syscall: Implement the kernel style return value Date: Sat, 2 Oct 2021 08:28:14 +0700 Message-Id: <20211002012817.107517-2-ammar.faizi@students.amikom.ac.id> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211002012817.107517-1-ammar.faizi@students.amikom.ac.id> References: <20211002012817.107517-1-ammar.faizi@students.amikom.ac.id> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Make it possible to remove the dependency of `errno` variable (which comes from libc). Currently, we expose these functions to userland: 1) `__sys_io_uring_register` 2) `__sys_io_uring_setup` 3) `__sys_io_uring_enter2` 4) `__sys_io_uring_enter` The tests in `test/io_uring_{enter,register,setup}.c` are the examples of it. Since the userland needs to check the `errno` value to use them properly, this means those functions always depend on libc. So we cannot change their behavior. This ensures the changes only affect liburing internal and no visible functionality changes for the users. Then we introduce new functions with the same name (with extra underscore as prefix, 4 underscores): 1) `____sys_io_uring_register` 2) `____sys_io_uring_setup` 3) `____sys_io_uring_enter2` 4) `____sys_io_uring_enter` These functions do not use `errno` variable *on the caller*, they use the kernel style return value (return a negative value of error code when errors). These functions are defined as `inline static` in `src/syscall.h`. They are just a wrapper to make sure liburing internal sources do not touch `errno` variable from C files directly. Link: https://github.com/axboe/liburing/issues/443#issuecomment-927873932 Cc: Bedirhan KURT Suggested-by: Louvian Lyndal Signed-off-by: Ammar Faizi Signed-off-by: Ammar Faizi --- src/syscall.c | 36 ---------------------- src/syscall.h | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 36 deletions(-) diff --git a/src/syscall.c b/src/syscall.c index 69027e5..221f0f1 100644 --- a/src/syscall.c +++ b/src/syscall.c @@ -5,47 +5,11 @@ * Will go away once libc support is there */ #include -#include #include #include "liburing/compat.h" #include "liburing/io_uring.h" #include "syscall.h" -#ifdef __alpha__ -/* - * alpha and mips are exception, other architectures have - * common numbers for new system calls. - */ -# ifndef __NR_io_uring_setup -# define __NR_io_uring_setup 535 -# endif -# ifndef __NR_io_uring_enter -# define __NR_io_uring_enter 536 -# endif -# ifndef __NR_io_uring_register -# define __NR_io_uring_register 537 -# endif -#elif defined __mips__ -# ifndef __NR_io_uring_setup -# define __NR_io_uring_setup (__NR_Linux + 425) -# endif -# ifndef __NR_io_uring_enter -# define __NR_io_uring_enter (__NR_Linux + 426) -# endif -# ifndef __NR_io_uring_register -# define __NR_io_uring_register (__NR_Linux + 427) -# endif -#else /* !__alpha__ and !__mips__ */ -# ifndef __NR_io_uring_setup -# define __NR_io_uring_setup 425 -# endif -# ifndef __NR_io_uring_enter -# define __NR_io_uring_enter 426 -# endif -# ifndef __NR_io_uring_register -# define __NR_io_uring_register 427 -# endif -#endif int __sys_io_uring_register(int fd, unsigned opcode, const void *arg, unsigned nr_args) diff --git a/src/syscall.h b/src/syscall.h index 2368f83..5f7343f 100644 --- a/src/syscall.h +++ b/src/syscall.h @@ -2,7 +2,47 @@ #ifndef LIBURING_SYSCALL_H #define LIBURING_SYSCALL_H +#include #include +#include +#include + +#ifdef __alpha__ +/* + * alpha and mips are exception, other architectures have + * common numbers for new system calls. + */ +# ifndef __NR_io_uring_setup +# define __NR_io_uring_setup 535 +# endif +# ifndef __NR_io_uring_enter +# define __NR_io_uring_enter 536 +# endif +# ifndef __NR_io_uring_register +# define __NR_io_uring_register 537 +# endif +#elif defined __mips__ +# ifndef __NR_io_uring_setup +# define __NR_io_uring_setup (__NR_Linux + 425) +# endif +# ifndef __NR_io_uring_enter +# define __NR_io_uring_enter (__NR_Linux + 426) +# endif +# ifndef __NR_io_uring_register +# define __NR_io_uring_register (__NR_Linux + 427) +# endif +#else /* !__alpha__ and !__mips__ */ +# ifndef __NR_io_uring_setup +# define __NR_io_uring_setup 425 +# endif +# ifndef __NR_io_uring_enter +# define __NR_io_uring_enter 426 +# endif +# ifndef __NR_io_uring_register +# define __NR_io_uring_register 427 +# endif +#endif + struct io_uring_params; @@ -17,4 +57,46 @@ int __sys_io_uring_enter2(int fd, unsigned to_submit, unsigned min_complete, int __sys_io_uring_register(int fd, unsigned int opcode, const void *arg, unsigned int nr_args); + + +/* + * Syscall with kernel style return value. + */ +static inline int ____sys_io_uring_register(int fd, unsigned opcode, + const void *arg, unsigned nr_args) +{ + int ret; + + ret = syscall(__NR_io_uring_register, fd, opcode, arg, nr_args); + return (ret < 0) ? -errno : ret; +} + +static inline int ____sys_io_uring_setup(unsigned entries, + struct io_uring_params *p) +{ + int ret; + + ret = syscall(__NR_io_uring_setup, entries, p); + return (ret < 0) ? -errno : ret; +} + +static inline int ____sys_io_uring_enter2(int fd, unsigned to_submit, + unsigned min_complete, unsigned flags, + sigset_t *sig, int sz) +{ + int ret; + + ret = syscall(__NR_io_uring_enter, fd, to_submit, min_complete, + flags, sig, sz); + return (ret < 0) ? -errno : ret; +} + +static inline int ____sys_io_uring_enter(int fd, unsigned to_submit, + unsigned min_complete, unsigned flags, + sigset_t *sig) +{ + return ____sys_io_uring_enter2(fd, to_submit, min_complete, flags, sig, + _NSIG / 8); +} + #endif -- 2.30.2