Message ID | 68dace9e2532316ff454894697ecfd99e419a523.1685777982.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 k13csp1541979vqr; Sat, 3 Jun 2023 01:53:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5G8xnD4s5tskIzCAX7C32bFvrRn+HdSLwyw3ppe0ZtB4VhrTInSizIdMCiZQZMWnps5Ovf X-Received: by 2002:a92:da89:0:b0:334:c74c:4403 with SMTP id u9-20020a92da89000000b00334c74c4403mr10886897iln.11.1685782422440; Sat, 03 Jun 2023 01:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685782422; cv=none; d=google.com; s=arc-20160816; b=ytbH+vRk7oL1qxoAiNdv4OwXqBFonXYNPu7nlG+ApMIxZlmtF4Zr7uAi/RjBfQbokp LCcIoph6ZjlC3B3nJwG+874ZiM8RF7Yad61InYnIUNx+DNQuEMp8hqqSH+7UpDr6c2EJ QbV9tqeJc3KiLZ+yH+JlXpXiPB6WVCjBlW2BWPSAWfouLSa+Icmgdf1k4Fy+Byaqbxzm t6ioHEEmpu2X1h5gxElgb7YyeiVXxFrRpyYdJ8kCRsm/mQwaec30/HkoF8KV7byRgSPI +vP0OCdogxdFUO8+4cVMXdNq6ModfK4qkG4+if7q4G5A3y7YlOYbCFdifnccKphXV1Qc Zp4Q== 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=o62uFiqxoxK60o4Djc7O0dznsLet8kiTa1Wg5VG3vZI=; b=RPWCEHshhCrMyZ0xRfKTm5SnDnqN3G7QLjZkGSBHGwYrw+THlFAzCsXajqgLgTLFYA tN+hsPgeQ58kjccGjRFGtGv5WOjd9SFW2GKsTq7VMGHW2ZaCHE8ofdoYGXsxsrbzgQpk ezhcwZ6w+BLIpD+8osFjFfzNAtUPlukpPF6+bjF76GWiGSwt+8imWbPmvHXrhUZFjLcO RHGHTXkxEdFMkw9fEOuVWItFWS9v2eHwZVHhqitqE9iFR4btZ6FbSCgKWK6b52WLdI1z 7znd1+UP4qfRm2e9r6s368CCym4uuHYjG0tyEHejNx0crS9ik16h1p0/dhlQvXmgNiTv gIMg== 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 g24-20020a632018000000b0053f4a814953si2250052pgg.870.2023.06.03.01.53.27; Sat, 03 Jun 2023 01:53:42 -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 S234548AbjFCIQ3 (ORCPT <rfc822;limurcpp@gmail.com> + 99 others); Sat, 3 Jun 2023 04:16:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjFCIQ2 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 3 Jun 2023 04:16:28 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29E9F1B3; Sat, 3 Jun 2023 01:16:26 -0700 (PDT) X-QQ-mid: bizesmtp77t1685780177tiq7j5j8 Received: from linux-lab-host.localdomain ( [119.123.130.226]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 03 Jun 2023 16:16:15 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: hoArX50alxFFZWWL2Wyj1D3SOa6jZE2VhGESBJVTnGUig23E/NM6osFUoAejc ZMnT/lOPYyAss5rGMd5FNaLZyAovm6YOd7t29lhWCVjscHA33su6FF+MkKHvlCsNyzW3iet QTTEeqpyfmlHlPe16kFQ8T//b0we/bCoXaw76jfP8nhXhjqXglXlhb3mLhsjItcfXzOcVsn ow6D/k9IEf0Q7tF/wtaReG1iUW2jRUByaH8tMIGBtv/FkX2Uc9m49rBTvnu33BAK+aeG/eg wXrlbRPV63CeKIcUmlwSnu2AEvTkhVFGK0euwG0yyMpM1m0Px8nY0Z8nIOFF+ohSORa7fjN dNu7jD6jHWXx5n2wUcEz9LxNYZixsgris0WcF8ROqihn3JWeCY2apZ5A0RrzSKN4dZp/MJx BVUWy7RiVqo= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8375714549719897536 From: Zhangjin Wu <falcon@tinylab.org> To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net> Subject: [PATCH v3 11/12] selftests/nolibc: add new gettimeofday test cases Date: Sat, 3 Jun 2023 16:16:07 +0800 Message-Id: <68dace9e2532316ff454894697ecfd99e419a523.1685777982.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <cover.1685777982.git.falcon@tinylab.org> References: <cover.1685777982.git.falcon@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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?1767670989415872316?= X-GMAIL-MSGID: =?utf-8?q?1767670989415872316?= |
Series |
nolibc: add generic part1 of prepare for rv32
|
|
Commit Message
Zhangjin Wu
June 3, 2023, 8:16 a.m. UTC
These 2 test cases are added to cover the normal using scenes of
gettimeofday().
They have been used to trigger and fix up such issue with nolibc:
nolibc-test.c:(.text.gettimeofday+0x54): undefined reference to `__aeabi_ldivmod'
This issue happens while there is no "unsigned int" conversion in the
coming new clock_gettime / clock_gettime64 syscall path of
gettimeofday():
tv->tv_usec = ts.tv_nsec / 1000;
Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/linux-riscv/280867a8-7601-4a96-9b85-87668e1f1282@t-8ch.de/
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
tools/testing/selftests/nolibc/nolibc-test.c | 4 ++++
1 file changed, 4 insertions(+)
Comments
On 2023-06-03 16:16:07+0800, Zhangjin Wu wrote: > These 2 test cases are added to cover the normal using scenes of > gettimeofday(). > > They have been used to trigger and fix up such issue with nolibc: > > nolibc-test.c:(.text.gettimeofday+0x54): undefined reference to `__aeabi_ldivmod' > > This issue happens while there is no "unsigned int" conversion in the > coming new clock_gettime / clock_gettime64 syscall path of > gettimeofday(): > > tv->tv_usec = ts.tv_nsec / 1000; As mentioned before this looks to me like an issue in the build setup. Could you provide reproduction steps? Nevertheless I guess the tests themselves are fine to have. > Suggested-by: Thomas Weißschuh <linux@weissschuh.net> > Link: https://lore.kernel.org/linux-riscv/280867a8-7601-4a96-9b85-87668e1f1282@t-8ch.de/ > Signed-off-by: Zhangjin Wu <falcon@tinylab.org> > --- > tools/testing/selftests/nolibc/nolibc-test.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c > index bf63fc66e486..e68c5692ec54 100644 > --- a/tools/testing/selftests/nolibc/nolibc-test.c > +++ b/tools/testing/selftests/nolibc/nolibc-test.c > @@ -533,6 +533,8 @@ static int test_stat_timestamps(void) > */ > int run_syscall(int min, int max) > { > + struct timeval tv; > + struct timezone tz; > struct stat stat_buf; > int euid0; > int proc; > @@ -588,6 +590,8 @@ int run_syscall(int min, int max) > CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1); break; > CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null"), -1, ENOTDIR); break; > CASE_TEST(gettimeofday_null); EXPECT_SYSZR(1, gettimeofday(NULL, NULL)); break; > + CASE_TEST(gettimeofday_tv); EXPECT_SYSZR(1, gettimeofday(&tv, NULL)); break; > + CASE_TEST(gettimeofday_tv_tz);EXPECT_SYSZR(1, gettimeofday(&tv, &tz)); break; > CASE_TEST(getpagesize); EXPECT_SYSZR(1, test_getpagesize()); break; > CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); break; > CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); break; > -- > 2.25.1 >
On Sun, Jun 4, 2023, at 10:29, 吴章金 wrote: > > Sorry for missing part of your feedbacks, I will check if -nostdlib > stops the linking of libgcc_s or my own separated test script forgot > linking the libgcc_s manually. According to the gcc documentation, -nostdlib drops libgcc.a, but adding -lgcc is the recommended way to bring it back. > And as suggestion from Thomas' reply, > >>> Perhaps we really need to add the missing __divdi3 and __aeabi_ldivmod and the >>> ones for the other architectures, or get one from lib/math/div64.c. > >>No, these ones come from the compiler via libgcc_s, we must not try to > reimplement them. And we should do our best to avoid depending on them > to avoid the error you got above. > > So, the explicit conversion is used instead in the patch. I think a cast to a 32-bit type is ideal when converting the clock_gettime() result into microseconds, since the kernel guarantees that the timespec value is normalized, with all zeroes in the upper 34 bits. Going through __aeabi_ldivmod would make the conversion much slower. For user supplied non-normalized timeval values, it's not obvious whether we need the full 64-bit division Arnd
On Sun, Jun 04, 2023 at 11:24:39AM +0200, Arnd Bergmann wrote: > On Sun, Jun 4, 2023, at 10:29, ??? wrote: > > > > Sorry for missing part of your feedbacks, I will check if -nostdlib > > stops the linking of libgcc_s or my own separated test script forgot > > linking the libgcc_s manually. > > According to the gcc documentation, -nostdlib drops libgcc.a, but > adding -lgcc is the recommended way to bring it back. > > > And as suggestion from Thomas' reply, > > > >>> Perhaps we really need to add the missing __divdi3 and __aeabi_ldivmod and the > >>> ones for the other architectures, or get one from lib/math/div64.c. > > > >>No, these ones come from the compiler via libgcc_s, we must not try to > > reimplement them. And we should do our best to avoid depending on them > > to avoid the error you got above. > > > > So, the explicit conversion is used instead in the patch. > > I think a cast to a 32-bit type is ideal when converting the > clock_gettime() result into microseconds, since the kernel guarantees > that the timespec value is normalized, with all zeroes in the > upper 34 bits. Going through __aeabi_ldivmod would make the > conversion much slower. > > For user supplied non-normalized timeval values, it's not obvious > whether we need the full 64-bit division We don't have to care about these here for the microsecond part, because for decades these were exclusively 32-bit. Also the only one consuming this field would have been settimeofday() and it's already documented as returning EINVAL if tv_usec is not within the expected 0..999999 range. And when in doubt we should keep in mind that nolibc's purpose is not to become a yet-another full-blown libc alternative but just a small piece of software allowing to produce portable and compact binaries for testing or booting. Being a bit stricter than other libcs for the sake of code compactness is better here. Originally for example it was necessary to always pass the 3 arguments to open(). Over time we managed to make simple code compile with both glibc and nolibc, but when it comes at the cost of adding size and burden for the developers, such as forcing them to add libgcc, I prefer that we slightly limit the domain of application instead. Thanks! Willy
On Sun, Jun 4, 2023, at 13:27, Willy Tarreau wrote: > On Sun, Jun 04, 2023 at 11:24:39AM +0200, Arnd Bergmann wrote: >> >> For user supplied non-normalized timeval values, it's not obvious >> whether we need the full 64-bit division > > We don't have to care about these here for the microsecond part, > because for decades these were exclusively 32-bit. Also the only > one consuming this field would have been settimeofday() and it's > already documented as returning EINVAL if tv_usec is not within > the expected 0..999999 range. Right > Over time we managed > to make simple code compile with both glibc and nolibc, but when it > comes at the cost of adding size and burden for the developers, such > as forcing them to add libgcc, I prefer that we slightly limit the > domain of application instead. Good point. This also reminds me that the compilers I build for https://mirrors.edge.kernel.org/pub/tools/crosstool/ don't always have every version of libgcc that may be needed, for instance the mips compilers only provide a big-endian libgcc and the arm compilers only provide a little-endian one, even though the compilers can build code both ways with the right flags. Arnd
On Sun, Jun 04, 2023 at 01:38:39PM +0200, Arnd Bergmann wrote: > > Over time we managed > > to make simple code compile with both glibc and nolibc, but when it > > comes at the cost of adding size and burden for the developers, such > > as forcing them to add libgcc, I prefer that we slightly limit the > > domain of application instead. > > Good point. This also reminds me that the compilers I build for > https://mirrors.edge.kernel.org/pub/tools/crosstool/ don't always > have every version of libgcc that may be needed, for instance > the mips compilers only provide a big-endian libgcc and the > arm compilers only provide a little-endian one, even though > the compilers can build code both ways with the right flags. That reminds me something indeed, I know that MIPS is a great platform for testing portability due to libgcc and/or atomics not always being complete depending how it's built. At work when I double-check that haproxy still builds and starts on my EdgeRouter-X, then it will build everywhere ;-) Willy
> On Sun, Jun 04, 2023 at 11:24:39AM +0200, Arnd Bergmann wrote: > > On Sun, Jun 4, 2023, at 10:29, ??? wrote: > > > > > > Sorry for missing part of your feedbacks, I will check if -nostdlib > > > stops the linking of libgcc_s or my own separated test script forgot > > > linking the libgcc_s manually. > > > > According to the gcc documentation, -nostdlib drops libgcc.a, but > > adding -lgcc is the recommended way to bring it back. > > > > > And as suggestion from Thomas' reply, > > > > > >>> Perhaps we really need to add the missing __divdi3 and __aeabi_ldivmod and the > > >>> ones for the other architectures, or get one from lib/math/div64.c. > > > > > >>No, these ones come from the compiler via libgcc_s, we must not try to > > > reimplement them. And we should do our best to avoid depending on them > > > to avoid the error you got above. > > > > > > So, the explicit conversion is used instead in the patch. > > > > I think a cast to a 32-bit type is ideal when converting the > > clock_gettime() result into microseconds, since the kernel guarantees > > that the timespec value is normalized, with all zeroes in the > > upper 34 bits. Going through __aeabi_ldivmod would make the > > conversion much slower. > > Perfectly, this message is really required to be added to the coming clock_gettime/time64 patches, I did worry about the (unsigned int) conversion may lose the upper bits, thanks Arnd. > > For user supplied non-normalized timeval values, it's not obvious > > whether we need the full 64-bit division > > We don't have to care about these here for the microsecond part, > because for decades these were exclusively 32-bit. Also the only > one consuming this field would have been settimeofday() and it's > already documented as returning EINVAL if tv_usec is not within > the expected 0..999999 range. > And this one, thanks Willy. > And when in doubt we should keep in mind that nolibc's purpose is not > to become a yet-another full-blown libc alternative but just a small > piece of software allowing to produce portable and compact binaries > for testing or booting. Being a bit stricter than other libcs for the > sake of code compactness is better here. Originally for example it was > necessary to always pass the 3 arguments to open(). Over time we managed > to make simple code compile with both glibc and nolibc, but when it > comes at the cost of adding size and burden for the developers, such > as forcing them to add libgcc, I prefer that we slightly limit the > domain of application instead. This explains why it is 'no' libc ;-) Best regards, Zhangjin > > Thanks! > Willy
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index bf63fc66e486..e68c5692ec54 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -533,6 +533,8 @@ static int test_stat_timestamps(void) */ int run_syscall(int min, int max) { + struct timeval tv; + struct timezone tz; struct stat stat_buf; int euid0; int proc; @@ -588,6 +590,8 @@ int run_syscall(int min, int max) CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1); break; CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null"), -1, ENOTDIR); break; CASE_TEST(gettimeofday_null); EXPECT_SYSZR(1, gettimeofday(NULL, NULL)); break; + CASE_TEST(gettimeofday_tv); EXPECT_SYSZR(1, gettimeofday(&tv, NULL)); break; + CASE_TEST(gettimeofday_tv_tz);EXPECT_SYSZR(1, gettimeofday(&tv, &tz)); break; CASE_TEST(getpagesize); EXPECT_SYSZR(1, test_getpagesize()); break; CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); break; CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); break;