Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp982760rdb; Wed, 6 Dec 2023 05:45:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUBe5eq0q50wXp44TMCz3fm0p8jEtn4LyjXaa6tq3lH6Z/+Rtq4x51ZlqzNXb0NcOUvyd9 X-Received: by 2002:a05:6a20:9384:b0:18c:55b4:df2a with SMTP id x4-20020a056a20938400b0018c55b4df2amr766430pzh.2.1701870348203; Wed, 06 Dec 2023 05:45:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701870348; cv=none; d=google.com; s=arc-20160816; b=NK8E69qGUpP/iHo1voLGamGjPsTC5ZDzlX2t2/S883BZaNjSPs1Jtvn+0o6IVBjkMi /3uP1ViMYDk/mJJR/Pp9ijm45dkp4yyyx2edO+DVy9WthYCFQfwNQhm7mhMhvk3vDXui PQ3RRlHtMhukNWtRHav2cE+e8ULCXhN+uSBuu51XJO0A/jQXWk9vn5iavvzrDJ/xJuEu crT5aWNWCUYrzqCO0A9OL4crrgdMg4FI8Y2bFGW1aDRMcionN4ycT3xvOMrJXIQP0WIb FxKmorTmTvSXdlNdmbIXK/0CKHZ4yePZ4Zl+y3S/WBThnxjQO6NFkBChTDQpsHDSEq/L Q2/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=eyzTJBorqo0srDT9PjO1S/0u5d8jIirct/7xXW8mDxs=; fh=JxoS+VSXNjMonlV+QN3moK6/HIuZhW3zL/QUnBw8aAM=; b=e0CnWurgBA8F8VN2os3bX7iBETysgg8dBB8NucE0TcO1lxwWrFT62YM9s0QewDrDt7 LMPYBgenDhcxB2vyaqzpTb/OzP3yLmdVXPd5Y99o9zt9ZcdcjZSSFddvPrbGst8p1Cq4 yPqRMe9aKgqeRM3+OipQwJrgQg6Gww+PbeUiiOqPA5yDSKZ/AD5LizkrCGyb5ougvUa8 7mNksUHOcemc/NfHYDzR8y4u3KNmgB96wKcRmdVKpV1FM9YhSBTPAXb7khirgK4spjSF UfuZ7SJwdB5SUuo0TTO5ztHdMvFvCk0dZoDCecdX9HMicPRev6l8D7p3V+rMQVTpk2Sf 99yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=TkBq9SVl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id r12-20020a6560cc000000b005c67e7f7917si6155457pgv.409.2023.12.06.05.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 05:45:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=TkBq9SVl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8216A809EC8E; Wed, 6 Dec 2023 05:45:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378509AbjLFNo4 (ORCPT + 99 others); Wed, 6 Dec 2023 08:44:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378494AbjLFNoz (ORCPT ); Wed, 6 Dec 2023 08:44:55 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA54512B for ; Wed, 6 Dec 2023 05:45:00 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40c192f488cso1353225e9.1 for ; Wed, 06 Dec 2023 05:45:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1701870299; x=1702475099; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=eyzTJBorqo0srDT9PjO1S/0u5d8jIirct/7xXW8mDxs=; b=TkBq9SVlHgOyTYNulhEvBJfN2a0ilMQbVFJO4AfXftWZgACwvz64beNgOOf+tPP16+ CdQIiVPkTUUqaCOb9MX6TARKKH97ax3uG8A5NK5SE2PKOInfiRJfxsL8RNTZbBQ0Wu2g BFdi2cq5wz3rL6kBzFMdOnnEJiWWir+R++gk2wwZqZUSIZGPANDy7A+Y5MQz/E/NeMJF 3cKPMPPY9dRmoLDl/tO4RTNVcnkWGcWCj7UXxd6Q7GC94vf8tj1gcZp8utkJriu2vURm ec3rkjBITQUeJmdYScZUfKZsxxRQ1VoRABRyywPBln0/rqtPMuSc+3c6b/O4+dKPQ7LL U3QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701870299; x=1702475099; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eyzTJBorqo0srDT9PjO1S/0u5d8jIirct/7xXW8mDxs=; b=HtF9YnJvqnsFU+ceKYRxfeVmodjzIn6S+96T2Bfz6g1HLVwmo1fVRabbXLnaneC6Ty Ds84dVFgsp/ztSfC9m6vpThqWwSZTscZTRzlGWODalQAg/+JgCGG+w8XncG5JiY25iu/ yMJPguth6/nWAqyb6pExysCuMyXMOpqqBgZQOK7yv7L1BhLs+4WNu3nYkSmZAhFfJCuO 3TT5nKKBck/ECMmgpnMCWU0Hk6VbWbhPP/jAxtYWAaH2XZGVfiRLdWHA7bt8JRkUUsiI 8FaHPgu1zxuqWAiwkc5ZR1ZJb7ou/NYLFxSVdYcdVkyTQ2tGxjwFVigDp0nLweEjmrY7 3Irg== X-Gm-Message-State: AOJu0YzuSbzcjRvykScfy4zVdBxrFNsahek4KoDYH6meXTvYP862SKiC rlbVZb2Urp2/KpE7VCp7YvPo9Q== X-Received: by 2002:a05:600c:1387:b0:40c:b81:c640 with SMTP id u7-20020a05600c138700b0040c0b81c640mr1410826wmf.0.1701870299133; Wed, 06 Dec 2023 05:44:59 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:68da:101e:d3e4:630b]) by smtp.gmail.com with ESMTPSA id hg10-20020a05600c538a00b0040b398f0585sm22258222wmb.9.2023.12.06.05.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 05:44:58 -0800 (PST) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: Thomas Gleixner , Shuah Khan , Gabriel Krisman Bertazi , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Palmer Dabbelt , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Subject: [PATCH v2] selftests: sud_test: return correct emulated syscall value on RISC-V Date: Wed, 6 Dec 2023 14:44:37 +0100 Message-ID: <20231206134438.473166-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 05:45:28 -0800 (PST) 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 Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt --- Changes in V2: - Changes comment to be more explicit - Use A7 syscall arg rather than hardcoding MAGIC_SYSCALL_1 --- .../selftests/syscall_user_dispatch/sud_test.c | 14 ++++++++++++++ 1 file changed, 14 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..d975a6767329 100644 --- a/tools/testing/selftests/syscall_user_dispatch/sud_test.c +++ b/tools/testing/selftests/syscall_user_dispatch/sud_test.c @@ -158,6 +158,20 @@ 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. + */ +#if defined(__riscv) +/* REG_A7 is not defined in libc headers */ +# define REG_A7 (REG_A0 + 7) + + ((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A0] = + ((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A7]; +#endif } TEST(dispatch_and_return) -- 2.43.0