Message ID | 9359ab11b52ef7c1799337f475e1e27c0cb00e3b.1684949268.git.falcon@tinylab.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp112207vqr; Wed, 24 May 2023 11:51:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5JfhGi7lJ+ki9IWkC0nuNVafClqp90ov/rPP67BC56yBbyDGFMxwIIapzdB/E2+tGo/BJi X-Received: by 2002:a17:90b:180f:b0:255:5d65:3a86 with SMTP id lw15-20020a17090b180f00b002555d653a86mr11935403pjb.8.1684954285979; Wed, 24 May 2023 11:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684954285; cv=none; d=google.com; s=arc-20160816; b=k3n6vg6KKFlFm5MI2d3a7zry1IxMm2/hLJeQ8QRenfa5Xg0NKhDOjmbCgnUtbkyj7S f+bi8Ma6+Nj+65Q2G1UvGiwmHv4gklmkewlJQ/2Oe78Vf9EkumehkeXitlqqwEZ5bwrQ Is1OCl+0D6T9xcrzXbqjbz7uflMXKh1YGSyvO2P7XcYLCh+xtsyPzg5gqPoB2tepRN3Q SPbI/GTuERdy6q5iyB2eK22HFLPNk7xqD4l97efrDhV5aOmE3HlMBzkwGnTX8T8LK3xH ODYnQ1EXHazTxsQpaiA5xunEZEESBpQ6owezHztWUk/U9nO+tsdKZECiHk34mLKfvLYB ui4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=23Ps52NYVgZIKovG02fA9IvbOt8y9/Ls6WSLlaOYgsI=; b=S0cJtW1jbCwnhkIzWTOySnUYsHECSeU5Whg8qpBUql65vqexhoB2UjF+pafmIX8R1q 2/0yIp+6GzCTE6u1/SwNxntSg1c1NpNmEwVJoeqgpgorsuRdNAoWDl4/od6PaAeS1sXX TeD3cMC0vMqg3R8H8OWmMVsFCq1RtV51aSmGDNzFQ8cNrtp2yYsFxqdQ84P26z5cWlTg Y8Z0Rv8A2k2j+FHq2iB5vNonR6SycyleMuinsNnwk+OiNMBtwcIPNr4XpouO3zPUZHnB 95atGneOh3eV4cip2Zo8HfuOgEl2m93UeLeyIk4q9mi4KNB3xfO0ZggXgRUc6Rotjh5p Yg8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020a17090ac28500b00250807e3c5dsi157418pjt.137.2023.05.24.11.51.11; Wed, 24 May 2023 11:51:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236458AbjEXSBT (ORCPT <rfc822;jian.xie.xdx@gmail.com> + 99 others); Wed, 24 May 2023 14:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjEXSBR (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 24 May 2023 14:01:17 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.221.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6610898; Wed, 24 May 2023 11:01:14 -0700 (PDT) X-QQ-mid: bizesmtp75t1684951269t67ndppu Received: from linux-lab-host.localdomain ( [116.30.125.36]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 25 May 2023 02:01:08 +0800 (CST) X-QQ-SSF: 01200000000000D0V000B00A0000000 X-QQ-FEAT: hoArX50alxHX1mYOrihcB1iZGA+cMKRF18+VTtXY99N55mVqxxcNdy0jsu7Jz AcFGpT9by4v33/v8k6d71SGSNut3w5M1Y55V4QKFnuqDFz4e83jelIWCnwnh7ZZM/sT3E7F z6uTpi+OMP1Z7jyvBEXLGAs4F6CizZ4L8XY7TfsyP2p/AFUjdFPl7T1OArgl97XQgJkh/6Y UFvN8POwUkaWKQhBkorPnFG0okEi1/pIjfr9VCs/vFUjAG/lqDuM5K9BE9462Br2voypj0+ KqU2y/d9dGgUBYc8VJyjXbBM9c6PjzUS1OidPVawQduEJIza/o8yXXFRHqHoIzmrt3APMEb gsgqua+2O/NyW4ZeCqKXTDW6FjzPqNY0tBIaYOff9EXpYK8gO+mip2Uh9tHJw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4020491424755662603 From: Zhangjin Wu <falcon@tinylab.org> To: w@1wt.eu Cc: falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, palmer@dabbelt.com, paul.walmsley@sifive.com, thomas@t-8ch.de Subject: [PATCH 11/13] tools/nolibc: sys_select: riscv: use __NR_pselect6_time64 for rv32 Date: Thu, 25 May 2023 01:59:55 +0800 Message-Id: <9359ab11b52ef7c1799337f475e1e27c0cb00e3b.1684949268.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <cover.1684949267.git.falcon@tinylab.org> References: <cover.1684949267.git.falcon@tinylab.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766802625174460941?= X-GMAIL-MSGID: =?utf-8?q?1766802625174460941?= |
Series |
tools/nolibc: riscv: Add full rv32 support
|
|
Commit Message
Zhangjin Wu
May 24, 2023, 5:59 p.m. UTC
rv32 uses the generic include/uapi/asm-generic/unistd.h and it has no
__NR_pselect6 after kernel commit d4c08b9776b3 ("riscv: Use latest
system call ABI"), use __NR_pselect6_time64 instead.
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
tools/include/nolibc/sys.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Comments
On 2023-05-25 01:59:55+0800, Zhangjin Wu wrote: > rv32 uses the generic include/uapi/asm-generic/unistd.h and it has no > __NR_pselect6 after kernel commit d4c08b9776b3 ("riscv: Use latest > system call ABI"), use __NR_pselect6_time64 instead. > > Signed-off-by: Zhangjin Wu <falcon@tinylab.org> > --- > tools/include/nolibc/sys.h | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h > index c0335a84f880..00c7197dcd50 100644 > --- a/tools/include/nolibc/sys.h > +++ b/tools/include/nolibc/sys.h > @@ -1041,8 +1041,13 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva > struct timeval *t; > } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout }; > return my_syscall1(__NR_select, &arg); > -#elif defined(__ARCH_WANT_SYS_PSELECT6) && defined(__NR_pselect6) > +#elif defined(__ARCH_WANT_SYS_PSELECT6) && (defined(__NR_pselect6) || defined(__NR_pselect6_time64)) > +#ifdef __NR_pselect6 > struct timespec t; > +#else > + struct timespec64 t; > +#define __NR_pselect6 __NR_pselect6_time64 Wouldn't this #define leak to the users of nolibc and lead to calls to pselect6_time64 with the ABI of the __NR_pselect6 if userspace is doing its own raw syscalls? > +#endif > > if (timeout) { > t.tv_sec = timeout->tv_sec; > -- > 2.25.1 >
Hi, Thomas > On 2023-05-25 01:59:55+0800, Zhangjin Wu wrote: > > rv32 uses the generic include/uapi/asm-generic/unistd.h and it has no > > __NR_pselect6 after kernel commit d4c08b9776b3 ("riscv: Use latest > > system call ABI"), use __NR_pselect6_time64 instead. > > > > Signed-off-by: Zhangjin Wu <falcon@tinylab.org> > > --- > > tools/include/nolibc/sys.h | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h > > index c0335a84f880..00c7197dcd50 100644 > > --- a/tools/include/nolibc/sys.h > > +++ b/tools/include/nolibc/sys.h > > @@ -1041,8 +1041,13 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva > > struct timeval *t; > > } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout }; > > return my_syscall1(__NR_select, &arg); > > -#elif defined(__ARCH_WANT_SYS_PSELECT6) && defined(__NR_pselect6) > > +#elif defined(__ARCH_WANT_SYS_PSELECT6) && (defined(__NR_pselect6) || defined(__NR_pselect6_time64)) > > +#ifdef __NR_pselect6 > > struct timespec t; > > +#else > > + struct timespec64 t; > > +#define __NR_pselect6 __NR_pselect6_time64 > > Wouldn't this #define leak to the users of nolibc and lead to calls to > pselect6_time64 with the ABI of the __NR_pselect6 if userspace is doing > its own raw syscalls? > Yeah, it would break the user-side raw __NR_pselect6 syscall for nolibc is a header-only libc, so, it is not safe to use such method like glibc. Something like this will let the syscall call to pselect6_time64 instead of the user-required __NR_pselect6 and pass the wrong type of argument. #include "nolibc.h" // If no __NR_pselect6 defined, __NR_pselect6 = __NR_pselect6_time64 #ifdef __NR_pselect6 struct timespec t; // come here for __NR_pselect6_time64, but t is not timespec64, broken syscall(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); #else struct timespec64 t; syscall(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); #endif I have used something like __NR_pselect6_time3264 locally, before sending the patchset, I found a cleaner method already used in sys.h: #ifndef __NR__newselect #define __NR__newselect __NR_select #endif But I forgot the arguments mixing issue, __NR__newselect and __NR_select share the same type of arguments, but __NR_pselect6 and __NR_pselect6_time64 not, so, I will use back the old method but still need to find a better string, just like __NR__newselect, __NR__pselect6 may be used in kernel space in the future, and __NR_pselect6_time3264 is too long, what about this? #ifdef __NR_pselect6 struct timespec t; #define __NR_pselect6__ __NR_pselect6 #else struct timespec64 t; #define __NR_pselect6__ __NR_pselect6_time64 #endif Or even ___NR_pselect6? The same issue is in this patch: [PATCH 13/13] tools/nolibc: sys_gettimeofday: riscv: use __NR_clock_gettime64 will solve it with the same method. Thanks, Zhangjin > > > +#endif > > > > if (timeout) { > > t.tv_sec = timeout->tv_sec; > > -- > > 2.25.1 > >
On 2023-05-25 15:10:21+0800, Zhangjin Wu wrote: > Hi, Thomas > > > On 2023-05-25 01:59:55+0800, Zhangjin Wu wrote: > > > rv32 uses the generic include/uapi/asm-generic/unistd.h and it has no > > > __NR_pselect6 after kernel commit d4c08b9776b3 ("riscv: Use latest > > > system call ABI"), use __NR_pselect6_time64 instead. > > > > > > Signed-off-by: Zhangjin Wu <falcon@tinylab.org> > > > --- > > > tools/include/nolibc/sys.h | 7 ++++++- > > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > > > diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h > > > index c0335a84f880..00c7197dcd50 100644 > > > --- a/tools/include/nolibc/sys.h > > > +++ b/tools/include/nolibc/sys.h > > > @@ -1041,8 +1041,13 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva > > > struct timeval *t; > > > } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout }; > > > return my_syscall1(__NR_select, &arg); > > > -#elif defined(__ARCH_WANT_SYS_PSELECT6) && defined(__NR_pselect6) > > > +#elif defined(__ARCH_WANT_SYS_PSELECT6) && (defined(__NR_pselect6) || defined(__NR_pselect6_time64)) > > > +#ifdef __NR_pselect6 > > > struct timespec t; > > > +#else > > > + struct timespec64 t; > > > +#define __NR_pselect6 __NR_pselect6_time64 > > > > Wouldn't this #define leak to the users of nolibc and lead to calls to > > pselect6_time64 with the ABI of the __NR_pselect6 if userspace is doing > > its own raw syscalls? > > > > Yeah, it would break the user-side raw __NR_pselect6 syscall for nolibc is a > header-only libc, so, it is not safe to use such method like glibc. > > Something like this will let the syscall call to pselect6_time64 instead of the > user-required __NR_pselect6 and pass the wrong type of argument. > > #include "nolibc.h" // If no __NR_pselect6 defined, __NR_pselect6 = __NR_pselect6_time64 > > #ifdef __NR_pselect6 > struct timespec t; // come here for __NR_pselect6_time64, but t is not timespec64, broken > syscall(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); > #else > struct timespec64 t; > syscall(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); > #endif > > I have used something like __NR_pselect6_time3264 locally, before > sending the patchset, I found a cleaner method already used in sys.h: > > #ifndef __NR__newselect > #define __NR__newselect __NR_select > #endif > > But I forgot the arguments mixing issue, __NR__newselect and __NR_select > share the same type of arguments, but __NR_pselect6 and > __NR_pselect6_time64 not, so, I will use back the old method but still > need to find a better string, just like __NR__newselect, __NR__pselect6 > may be used in kernel space in the future, and __NR_pselect6_time3264 is > too long, what about this? > > #ifdef __NR_pselect6 > struct timespec t; > #define __NR_pselect6__ __NR_pselect6 > #else > struct timespec64 t; > #define __NR_pselect6__ __NR_pselect6_time64 > #endif > > Or even ___NR_pselect6? What about: #ifdef __NR_pselect6 struct timespec t; const long nr_pselect = __NR_pselect6; #else struct timespec64 t; const long nr_pselect = __NR_pselect6_time64; #endif > > The same issue is in this patch: > > [PATCH 13/13] tools/nolibc: sys_gettimeofday: riscv: use __NR_clock_gettime64 > > will solve it with the same method. Thanks!
> On 2023-05-25 15:10:21+0800, Zhangjin Wu wrote: > > Hi, Thomas > > > > > On 2023-05-25 01:59:55+0800, Zhangjin Wu wrote: > > > > rv32 uses the generic include/uapi/asm-generic/unistd.h and it has no > > > > __NR_pselect6 after kernel commit d4c08b9776b3 ("riscv: Use latest > > > > system call ABI"), use __NR_pselect6_time64 instead. > > > > > > > > Signed-off-by: Zhangjin Wu <falcon@tinylab.org> > > > > --- > > > > tools/include/nolibc/sys.h | 7 ++++++- > > > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h > > > > index c0335a84f880..00c7197dcd50 100644 > > > > --- a/tools/include/nolibc/sys.h > > > > +++ b/tools/include/nolibc/sys.h > > > > @@ -1041,8 +1041,13 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva > > > > struct timeval *t; > > > > } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout }; > > > > return my_syscall1(__NR_select, &arg); > > > > -#elif defined(__ARCH_WANT_SYS_PSELECT6) && defined(__NR_pselect6) > > > > +#elif defined(__ARCH_WANT_SYS_PSELECT6) && (defined(__NR_pselect6) || defined(__NR_pselect6_time64)) > > > > +#ifdef __NR_pselect6 > > > > struct timespec t; > > > > +#else > > > > + struct timespec64 t; > > > > +#define __NR_pselect6 __NR_pselect6_time64 > > > > > > Wouldn't this #define leak to the users of nolibc and lead to calls to > > > pselect6_time64 with the ABI of the __NR_pselect6 if userspace is doing > > > its own raw syscalls? > > > > > > > Yeah, it would break the user-side raw __NR_pselect6 syscall for nolibc is a > > header-only libc, so, it is not safe to use such method like glibc. > > > > Something like this will let the syscall call to pselect6_time64 instead of the > > user-required __NR_pselect6 and pass the wrong type of argument. > > > > #include "nolibc.h" // If no __NR_pselect6 defined, __NR_pselect6 = __NR_pselect6_time64 > > > > #ifdef __NR_pselect6 > > struct timespec t; // come here for __NR_pselect6_time64, but t is not timespec64, broken > > syscall(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); > > #else > > struct timespec64 t; > > syscall(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); > > #endif > > > > I have used something like __NR_pselect6_time3264 locally, before > > sending the patchset, I found a cleaner method already used in sys.h: > > > > #ifndef __NR__newselect > > #define __NR__newselect __NR_select > > #endif > > > > But I forgot the arguments mixing issue, __NR__newselect and __NR_select > > share the same type of arguments, but __NR_pselect6 and > > __NR_pselect6_time64 not, so, I will use back the old method but still > > need to find a better string, just like __NR__newselect, __NR__pselect6 > > may be used in kernel space in the future, and __NR_pselect6_time3264 is > > too long, what about this? > > > > #ifdef __NR_pselect6 > > struct timespec t; > > #define __NR_pselect6__ __NR_pselect6 > > #else > > struct timespec64 t; > > #define __NR_pselect6__ __NR_pselect6_time64 > > #endif > > > > Or even ___NR_pselect6? > > What about: > > #ifdef __NR_pselect6 > struct timespec t; > const long nr_pselect = __NR_pselect6; > #else > struct timespec64 t; > const long nr_pselect = __NR_pselect6_time64; > #endif > It looks better and cleaner, will apply this method, thanks! > > > > The same issue is in this patch: > > > > [PATCH 13/13] tools/nolibc: sys_gettimeofday: riscv: use __NR_clock_gettime64 > > > > will solve it with the same method. > And also this one: [PATCH 09/13] tools/nolibc: sys_poll: riscv: use __NR_ppoll_time64 Have tested all of them, will send a v2 later. Best regards, Zhangjin > Thanks!
On Wed, May 24, 2023, at 19:59, Zhangjin Wu wrote: > diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h > index c0335a84f880..00c7197dcd50 100644 > --- a/tools/include/nolibc/sys.h > +++ b/tools/include/nolibc/sys.h > @@ -1041,8 +1041,13 @@ int sys_select(int nfds, fd_set *rfds, fd_set > *wfds, fd_set *efds, struct timeva > struct timeval *t; > } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout }; > return my_syscall1(__NR_select, &arg); > -#elif defined(__ARCH_WANT_SYS_PSELECT6) && defined(__NR_pselect6) > +#elif defined(__ARCH_WANT_SYS_PSELECT6) && (defined(__NR_pselect6) || > defined(__NR_pselect6_time64)) > +#ifdef __NR_pselect6 > struct timespec t; > +#else > + struct timespec64 t; > +#define __NR_pselect6 __NR_pselect6_time64 > +#endif Overriding the __NR_pselect6 constant seems wrong here, this can easily lead to more bugs, as pselect6 and pselect6_time64 are not compatible because of the different arguments, so anything using the constant after including sys.h will be broken. I would just use __kernel_timespec64 unconditionally and then use __NR_pselect6_time64 on all 32-bit architectures here, but use __NR_pselect6 on 32-bit architectures. I think we can also kill off the oldselect and newselect cases, using pselect6/pselect6_time64 unconditionally here, and no longer care about building against pre-5.1 kernel headers, at least for the copy of nolibc that ships with the kernel. Arnd
Hi, Arnd > On Wed, May 24, 2023, at 19:59, Zhangjin Wu wrote: > > diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h > > index c0335a84f880..00c7197dcd50 100644 > > --- a/tools/include/nolibc/sys.h > > +++ b/tools/include/nolibc/sys.h > > @@ -1041,8 +1041,13 @@ int sys_select(int nfds, fd_set *rfds, fd_set > > *wfds, fd_set *efds, struct timeva > > struct timeval *t; > > } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout }; > > return my_syscall1(__NR_select, &arg); > > -#elif defined(__ARCH_WANT_SYS_PSELECT6) && defined(__NR_pselect6) > > +#elif defined(__ARCH_WANT_SYS_PSELECT6) && (defined(__NR_pselect6) || > > defined(__NR_pselect6_time64)) > > +#ifdef __NR_pselect6 > > struct timespec t; > > +#else > > + struct timespec64 t; > > +#define __NR_pselect6 __NR_pselect6_time64 > > +#endif > > Overriding the __NR_pselect6 constant seems wrong here, this can > easily lead to more bugs, as pselect6 and pselect6_time64 are > not compatible because of the different arguments, so anything > using the constant after including sys.h will be broken. > Yes, thanks, Thomas also pointed out this issue in another reply of this message thread, it has been fixed locally with his suggestion, it looks like this: #ifdef __NR_pselect6 struct timespec t; const long nr_pselect = __NR_pselect6; #else struct timespec64 t; const long nr_pselect = __NR_pselect6_time64; #endif if (timeout) { t.tv_sec = timeout->tv_sec; t.tv_nsec = timeout->tv_usec * 1000; } return my_syscall6(nr_pselect, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); I have applied this method for ppoll_time64 and clock_gettime64 too, this method can save several duplicated lines for us, I have prepared v2 patches locally for them. > I would just use __kernel_timespec64 unconditionally and then > use __NR_pselect6_time64 on all 32-bit architectures here, > but use __NR_pselect6 on 32-bit architectures. > The 2nd 32-bit you mean is 64-bit? This is related to the timespec64/time64_t definitions as you commented in another reply. I will learn how to use the one from <linux/time_types.h>, it may require to clean up the existing files in tools/include/nolibc/ at first. > I think we can also kill off the oldselect and newselect > cases, using pselect6/pselect6_time64 unconditionally here, > and no longer care about building against pre-5.1 kernel > headers, at least for the copy of nolibc that ships with the > kernel. As Willy commented in another reply, users may want to copy the recent one and use them with an old kernel, even if want to drop them, a standalone patch may be preferable. Thanks very much, Zhangjin > > Arnd
On Fri, May 26, 2023, at 13:00, Zhangjin Wu wrote: >> On Wed, May 24, 2023, at 19:59, Zhangjin Wu wrote: >> > diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h > > I have applied this method for ppoll_time64 and clock_gettime64 too, > this method can save several duplicated lines for us, I have prepared v2 > patches locally for them. Ok, that addresses my concern about the possible bugs. >> I would just use __kernel_timespec64 unconditionally and then >> use __NR_pselect6_time64 on all 32-bit architectures here, >> but use __NR_pselect6 on 32-bit architectures. >> > > The 2nd 32-bit you mean is 64-bit? Yes, sorry for the typo. > This is related to the timespec64/time64_t definitions as you commented > in another reply. I will learn how to use the one from > <linux/time_types.h>, it may require to clean up the existing files in > tools/include/nolibc/ at first. Ok, thanks. >> I think we can also kill off the oldselect and newselect >> cases, using pselect6/pselect6_time64 unconditionally here, >> and no longer care about building against pre-5.1 kernel >> headers, at least for the copy of nolibc that ships with the >> kernel. > > As Willy commented in another reply, users may want to copy the recent > one and use them with an old kernel, even if want to drop them, a > standalone patch may be preferable. Fair enough. I checked the old versions and see that 5.1 in May 2019 was the first one to include the time64 system call definitions, though 5.6 from March 2020 was the first version that I consider fully working with time64. I don't know how common it is to copy nolibc into other projects, but requiring a three year old kernel might be a little too aggressive here. They could copy from 6.1-stable to keep the fallback (and miss rv32) if we do this, but a better cutoff may be Dec 2025 when linux-5.4 has its "projected EOL" date and one last LTS with the fallback (linux-6.16 or so) gets released. Arnd
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index c0335a84f880..00c7197dcd50 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -1041,8 +1041,13 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva struct timeval *t; } arg = { .n = nfds, .r = rfds, .w = wfds, .e = efds, .t = timeout }; return my_syscall1(__NR_select, &arg); -#elif defined(__ARCH_WANT_SYS_PSELECT6) && defined(__NR_pselect6) +#elif defined(__ARCH_WANT_SYS_PSELECT6) && (defined(__NR_pselect6) || defined(__NR_pselect6_time64)) +#ifdef __NR_pselect6 struct timespec t; +#else + struct timespec64 t; +#define __NR_pselect6 __NR_pselect6_time64 +#endif if (timeout) { t.tv_sec = timeout->tv_sec;