Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5233780rwl; Sun, 8 Jan 2023 10:58:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXvOT76b2StyBOI3/sK5SziIsO8/KCyqlyVNWidwFdZZPmZLNRfw0fetUMOIXg8lC6u7FoBK X-Received: by 2002:a17:906:6d8:b0:844:79b1:ab36 with SMTP id v24-20020a17090606d800b0084479b1ab36mr55192171ejb.25.1673204300159; Sun, 08 Jan 2023 10:58:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673204300; cv=none; d=google.com; s=arc-20160816; b=pOkWtPdLWFLPW89n6n763dxkYNVIdr2PE6soNud3OIelCfFXTyb9p3PZo2dUgtBNcq 6ES+6J0ZZvdltDOADSIy5SgEPD/rpcJFyr6LUOdmEQOxCbxpSVvDo0vNcZZaMuyIpzFZ 1FF2YBBP2Wz9iRH9dyKPfmLfTYJ1ms6QHOrLfVIUHCuPIxO0FQtOCddu/B8Wh3rB+rAJ NggwbokKR1ww0jyX9empYhwF0ujKW0yxwK0KjomELo3UioYT4gwqxxn6VGl10y2+DMeS +ve7sJCNuyDIblKcIRbR6LjoWuyLUk8jAA2vpsh1TBGbUM+8938waBn33c1L5ZTDcW0+ rYmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=YO4i/smnEboBYkUevl7yLtC43ByzcQPCofd+LoJf9y0=; b=NU4/E4ogwH8GTphppcTzbeWI6FRRl2DviSO2H5PyuvqU63hGYcoChvr8oRREFCkJKm z5ya5RFsBn0yqa4zbzt9569rbYRb8y+oiyG/YJEneYFR1AoHBjP8/eD9V2vTnUZyZpx1 zone8upRZ3iRazYpGVzDK8to7W5EnSHzU2zTirBenTxl01MIrFUSJDNuFlGEGEUFNjOm lMxUHfv+9E5ASiclmCbzlFF37SVDr5g402OAunJsQ1G2kL0gV44gl8f+hqjOVrkpmQp1 95Re8L4Yr9lHdsAUU0eXk0R/tzs1EeNjnI3tu/LhC7xUUzHeLYuJRvu95ZdtU0Q1hmuQ BmEA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v18-20020a1709064e9200b007f0e3370f87si5688055eju.297.2023.01.08.10.58.08; Sun, 08 Jan 2023 10:58:20 -0800 (PST) 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 S233171AbjAHR7C (ORCPT + 51 others); Sun, 8 Jan 2023 12:59:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjAHR66 (ORCPT ); Sun, 8 Jan 2023 12:58:58 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 001C264D9; Sun, 8 Jan 2023 09:58:55 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 308Hwg9X020774; Sun, 8 Jan 2023 18:58:42 +0100 Date: Sun, 8 Jan 2023 18:58:42 +0100 From: Willy Tarreau To: Ammar Faizi Cc: Shuah Khan , "Paul E. McKenney" , Gilang Fachrezy , Alviro Iskandar Setiawan , GNU/Weeb Mailing List , Linux Kernel Mailing List , Linux Kselftest Mailing List Subject: Re: [PATCH v3 0/5] nolibc signal handling support Message-ID: <20230108175842.GB18859@1wt.eu> References: <20230108135904.851762-1-ammar.faizi@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230108135904.851762-1-ammar.faizi@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ammar, On Sun, Jan 08, 2023 at 08:58:59PM +0700, Ammar Faizi wrote: > From: Ammar Faizi > > Hi Willy, > > On top of the series titled "nolibc auxiliary vector retrieval support". > The prerequisite patches of this series are in that series. > > This is v2 of nolibc signal handling support. It adds signal handling > support to the nolibc subsystem: > > 1) Initial implementation of nolibc sigaction(2) function. > > `sigaction()` needs an architecture-dependent "signal trampoline" > function that invokes __rt_sigreturn syscall to resume the process > after a signal gets handled. > > The "signal trampoline" function is called `__restore_rt` in this > implementation. The naming `__restore_rt` is important for GDB. It > also has to be given a special optimization attribute > "omit-frame-pointer" to prevent the compiler from creating a stack > frame that makes the `%rsp` value no longer points to the `struct > rt_sigframe` that the kernel constructed. > > > 2) signal(2) function. > > signal() function is the simpler version of sigaction(). Unlike > sigaction(), which fully controls the struct sigaction, the caller > only cares about the sa_handler when calling the signal() function. > signal() internally calls sigaction(). > > > 3) More selftests. > > This series also adds selftests for: > - fork(2) > - sigaction(2) > - signal(2) > > > Side note for __restore_rt: > This has been tested on x86-64 arch and `__restore_rt` generates the > correct code. The `__restore_rt` codegen correctness on other > architectures need to be evaluated as well. If it can't generate the > correct code, it has to be written in inline Assembly. I'm currently testing it on various archs. For now: - x86_64 and arm64 pass the test - i386 and arm fail: 59 sigactiontest_sigaction_sig(2): Failed to set a signal handler = -1 EINVAL [FAIL] 60 signaltest_signal_sig(2): Failed to set a signal handler = -1 EINVAL [FAIL] - riscv and mips build are now broken: sysroot/riscv/include/sys.h:1110:18: error: 'struct sigaction' has no member named 'sa_restorer' 1110 | if (!act2.sa_restorer) { | ^ sysroot/riscv/include/sys.h:1111:34: error: 'SA_RESTORER' undeclared (first use in this function); did you mean 'SA_RESTART'? 1111 | act2.sa_flags |= SA_RESTORER; | ^~~~~~~~~~~ | SA_RESTART - s390 segfaults: 58 select_fault = -1 EFAULT [OK] 59 sigactionqemu: uncaught target signal 11 (Segmentation fault) - core dumped Segmentation fault It dies in __restore_rt at 1006ba4 while performing the syscall, I don't know why, maybe this arch requires an alt stack or whatever : 0000000001006ba0 <__restore_rt>: 1006ba0: a7 19 00 ad lghi %r1,173 1006ba4: 0a 00 svc 0 1006ba6: 07 07 nopr %r7 At the very least we need to make sure we don't degrade existing tests, which means making sure that it builds everywhere and that all those which build do work. It would be nice to figure what's failing on i386. Given that both it and arm fail on EINVAL while both x86_64 and arm64 work, I suspect that once you figure what breaks i386 it'll fix the problem on arm at the same time. I had a quick look but didn't spot anything suspicious. Once we've figured this, we could decide to tag archs supporting sig_action() and condition the functions definition and the tests to these. The advantage of trying with i386 is that your regular tools and the debugger you used for x86_64 will work. I'm proceeding like this with the toolchains from https://mirrors.edge.kernel.org/pub/tools/crosstool/ : $ make nolibc-test LDFLAGS=-g CFLAGS=-g ARCH=i386 CC=/path/to/gcc-11.3.0-nolibc/i386-linux/bin/i386-linux-gcc $ gdb ./nolibc-test > b sigaction > run > s ... Note that the code looks correct at first glance: 0804b4a0 <__restore_rt>: 804b4a0: b8 ad 00 00 00 mov $0xad,%eax 804b4a5: cd 80 int $0x80 I also think that the printf() in test_sigaction_sig() are not welcome as they corrupt the output. Maybe one thing you could do to preserve the info would be to prepend a space in front of the message and remove the LF. For example the simple patch below: diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index a1883467451a..42f794c646b7 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -535,7 +535,7 @@ static int test_sigaction_sig(int sig) */ ret = sigaction(sig, &new, &old); if (ret) { - printf("test_sigaction_sig(%d): Failed to set a signal handler\n", sig); + printf(" (failed to set handler for signal %d)", sig); return ret; } @@ -549,7 +549,7 @@ static int test_sigaction_sig(int sig) * test_signal_handler() must set @g_test_sig to @sig. */ if (g_test_sig != sig) { - printf("test_sigaction_sig(%d): Invalid g_test_sig value (%d != %d)\n", sig, g_test_sig, sig); + printf(" (invalid g_test_sig value (%d != %d))", sig, g_test_sig); return -1; } @@ -558,7 +558,7 @@ static int test_sigaction_sig(int sig) */ ret = sigaction(sig, &old, NULL); if (ret) { - printf("test_sigaction_sig(%d): Failed to restore the signal handler\n", sig); + printf(" (Failed to restore handler for signal %d)", sig); return ret; } @@ -574,7 +574,7 @@ static int test_signal_sig(int sig) */ old = signal(sig, test_signal_handler); if (old == SIG_ERR) { - printf("test_signal_sig(%d): Failed to set a signal handler\n", sig); + printf(" (failed to set handler for signal %d)", sig); return -1; } @@ -588,7 +588,7 @@ static int test_signal_sig(int sig) * test_signal_handler() must set @g_test_sig to @sig. */ if (g_test_sig != sig) { - printf("test_signal_sig(%d): Invalid g_test_sig value (%d != %d)\n", sig, g_test_sig, sig); + printf(" (invalid g_test_sig value (%d != %d))", sig, g_test_sig); return -1; } @@ -597,7 +597,7 @@ static int test_signal_sig(int sig) */ old = signal(sig, old); if (old == SIG_ERR) { - printf("test_signal_sig(%d): Failed to restore the signal handler\n", sig); + printf(" (Failed to restore handler for signal %d)", sig); return -1; } Gives me this: ... 56 select_null = 0 [OK] 57 select_stdout = 1 [OK] 58 select_fault = -1 EFAULT [OK] 59 sigaction (failed to set handler for signal 2) = -1 EINVAL [FAIL] 60 signal (failed to set handler for signal 2) = -1 EINVAL [FAIL] 61 stat_blah = -1 ENOENT [OK] 62 stat_fault = -1 EFAULT [OK] 63 symlink_root = -1 EEXIST [OK] ... Which is way more readable and still grep-friendly. Thanks! Willy