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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE4F5C4167B for ; Thu, 9 Nov 2023 08:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233553AbjKIIXB (ORCPT ); Thu, 9 Nov 2023 03:23:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233051AbjKIIWw (ORCPT ); Thu, 9 Nov 2023 03:22:52 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F066C2D63 for ; Thu, 9 Nov 2023 00:22:49 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-32da4180ca2so96922f8f.1 for ; Thu, 09 Nov 2023 00:22:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1699518168; x=1700122968; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=6L9e4FIZCW/cWI4CMkVwxfgtOwMhyuLQGfalUNr9zJ8=; b=nG+dhpYAbbJZyRNC2Wak13uNZxEqdTUSqGMnOHmXtTmasKq14ClI/aS/e799jUTKTm mbdA5tipoyTQL8Ka3SuRkJu23pu860+Ud2EssCO9ZbhkHJ1hXjCmf2SRstu8L5eUu3Ua J03A8udw3KqVQb9DWNQKVb5vKax6Jls2pKHMvUkWt+4YJOaKftdHQTXcv4qqxiV8zraj YSVbuz6qq9Yi+PZMGhiVghy7JSItzWHCgvtO9GwEmWW3IJgIuYNktPnPAXO9xH55pNcF IGJywKV1mXPm5EuFiFXfPp2deRVuBxFrDof2eZsm2zsAMBtm5LCio+g+u2u2BCgg6iWn hcxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699518168; x=1700122968; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6L9e4FIZCW/cWI4CMkVwxfgtOwMhyuLQGfalUNr9zJ8=; b=IjTFWgwfI5fb9UXJu+JVAENaCUZ1zVhgmHRMfmfnixPPnM2L0PS9qlB6H5UIjmpGod LvlbVqTwPJyto3+3VjOkiVoPsChtNC+sDlhfx9IDlFM7ckzbbN78gickThd9FWMvW0Br rXK/jJdCukp5+Bctd0Jy289kiRaGqXj9UfvPS3+PzLDt6AqEsbmSsXAHtJTFREtjZU07 5Kmhlsh5g4PePaZZWRGcdRtCXj6BR4SuQYayfqxjWFH86w/Rsv8I86nHCZ10L4X9R6XV YBo9pcl9LQkob1fRe0q7Qfi6ONl4Vt//rdFjAAXGRJY+jd9b2CbRgvKQoEEEwu7nf62v qp0w== X-Gm-Message-State: AOJu0YxsI9peX3UrfryizDLTSElLGykt39v9+dwx7ZZ9vrDcoIMoEHZW 5assG2eIbg5kt1dHD0jIanttWw== X-Google-Smtp-Source: AGHT+IHK4jz0hvKjL1UU+txgQCeQzgbTv4KRpSfNHNu6mKMYO3jCYjwyh6vF0R5mbSffwlvJKf1efA== X-Received: by 2002:a5d:6dae:0:b0:32f:8372:dfe8 with SMTP id u14-20020a5d6dae000000b0032f8372dfe8mr3193845wrs.1.1699518168015; Thu, 09 Nov 2023 00:22:48 -0800 (PST) Received: from ?IPV6:2a01:e0a:999:a3a0:87b4:87b9:6476:5df7? ([2a01:e0a:999:a3a0:87b4:87b9:6476:5df7]) by smtp.gmail.com with ESMTPSA id a6-20020a056000100600b0031984b370f2sm6817227wrx.47.2023.11.09.00.22.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Nov 2023 00:22:47 -0800 (PST) Message-ID: Date: Thu, 9 Nov 2023 09:22:46 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] selftests: sud_test: return correct emulated syscall value on RISC-V To: Palmer Dabbelt Cc: shuah@kernel.org, krisman@collabora.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org References: Content-Language: en-US From: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/11/2023 04:26, Palmer Dabbelt wrote: > On Wed, 13 Sep 2023 07:07:11 PDT (-0700), cleger@rivosinc.com wrote: >> Currently, the sud_test expects the emulated syscall to return the >> emulated syscall number. This assumption only works on architectures >> were the syscall calling convention use the same register for syscall >> number/syscall return value. This is not the case for RISC-V and thus >> the return value must be also emulated using the provided ucontext. >> >> Signed-off-by: Clément Léger >> --- >>  tools/testing/selftests/syscall_user_dispatch/sud_test.c | 8 ++++++++ >>  1 file changed, 8 insertions(+) >> >> diff --git a/tools/testing/selftests/syscall_user_dispatch/sud_test.c >> b/tools/testing/selftests/syscall_user_dispatch/sud_test.c >> index b5d592d4099e..1b5553c19700 100644 >> --- a/tools/testing/selftests/syscall_user_dispatch/sud_test.c >> +++ b/tools/testing/selftests/syscall_user_dispatch/sud_test.c >> @@ -158,6 +158,14 @@ static void handle_sigsys(int sig, siginfo_t >> *info, void *ucontext) >> >>      /* In preparation for sigreturn. */ >>      SYSCALL_DISPATCH_OFF(glob_sel); >> + >> +    /* >> +     * Modify interrupted context returned value according to syscall >> +     * calling convention >> +     */ >> +#if defined(__riscv) >> +    ((ucontext_t*)ucontext)->uc_mcontext.__gregs[REG_A0] = >> MAGIC_SYSCALL_1; >> +#endif >>  } >> >>  TEST(dispatch_and_return) > > I'm not sure if I'm just tired, but it took me a while to figure out why > this was necessary.  I think this is a better explanation: I think it's because this mechanism does not behave like other syscalls at all and the classic calling convention does not really apply... > >    diff --git a/tools/testing/selftests/syscall_user_dispatch/sud_test.c > b/tools/testing/selftests/syscall_user_dispatch/sud_test.c >    index b5d592d4099e..a913fd90cfa3 100644 >    --- a/tools/testing/selftests/syscall_user_dispatch/sud_test.c >    +++ b/tools/testing/selftests/syscall_user_dispatch/sud_test.c >    @@ -158,6 +158,16 @@ static void handle_sigsys(int sig, siginfo_t > *info, void *ucontext) >            /* In preparation for sigreturn. */ >         SYSCALL_DISPATCH_OFF(glob_sel); >    +    /* >    +     * The tests for argument handling assume that `syscall(x) == > x`.  This >    +     * is a NOP on x86 because the syscall number is passed in %rax, > which >    +     * happens to also be the function ABI return register.  Other >    +     * architectures may need to swizzle the arguments around. >    +     */ Indeed, that is more clear. Should I send a v2 ? >    +#if defined(__riscv) >    +    (ucontext_t*)ucontext)->uc_mcontext.__gregs[REG_A0] = >    +        (ucontext_t*)ucontext)->uc_mcontext.__gregs[REG_A7]; >    +#endif >     } >        TEST(dispatch_and_return) > > but also > > Reviewed-by: Palmer Dabbelt > Acked-by: Palmer Dabbelt > > as I agree this is correct. > > also: wouldn't arm64 also need to move x8 into x0 here, for essentially > the same reason as we do? Yes, as well as for a bunch of other architectures. I suspect this has only been tested on x86. AFAIK, this feature is mainly for wine usage which then makes sense for x86 and games. Thanks, Clément