Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp3037985lqz; Wed, 3 Apr 2024 16:52:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXj8mL6l7tc91J7zueQxztoSG9NHQ3NGCPekQf3wXF37Z3QP+6emmWgU6oolzWjSBoDyg4VRNf+3v6vpMWWPRcDmlLg2x+Ym5VuKGk4fQ== X-Google-Smtp-Source: AGHT+IGyF+nLmoz2mxIfVYOGS3ueRUA6idlOteiuKXxsnkA0M1vj2KSnNnclGvZYbMk/SDnegupb X-Received: by 2002:a9d:3e04:0:b0:6e6:e36b:8de2 with SMTP id a4-20020a9d3e04000000b006e6e36b8de2mr850790otd.11.1712188320334; Wed, 03 Apr 2024 16:52:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712188320; cv=pass; d=google.com; s=arc-20160816; b=B3qyT1xQKZi7VTyDOj1p1UTuR2Il9fhL+Yn58clIhhEIKpMGRNO9yv9PmHdXfH3IzA TtrO91Y5qG8mQdPVWc/GtVKZHCk2z5qJq2xzYubHHGvOQyhus9zkWX9Z1578iXlUOF8M DxZX3/O3Yum5mUoE0k8p/DgOrbKTHkrPjAZVm9YQUh4evhD1d1cKBvsPgtSuGgirbrlj /IRTqtmG95TJJgzisAEzpF++9dbiLx13kU2KaytUsZpwdTNYScsjQmaWivImVcF6IxXm C42v2SPp0MWXPiRsCgbUF4EuLeHxeFBg8tp9Rt8zPF4MMptEiDP/sXONvQNmnAxdrGQf 3TAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=BjQ9DxTSZlVH9DP6dgs1HodUGsGtzbmnUpujjVOtQj8=; fh=To1TBdbHG4kSD4nZMNgewN3cH2ilXHG4sG/qBhuqqX4=; b=GGzcJrLOPVTZLNRgKfw26aymBIyQG3Zhn5DVIcG/XLH0nN/26PyTeXLq0hpNQ5yfob WpZQg7ZS08ufYkO9tqusJqR2Jm6k8DYSdfMWwl9Hb2bul/pQeCY20W+f3ynJzEKXEHm1 evPDqs5yDd4huiRFpDhmqJBjE+TEzzfVgjrrYDn05gTCMC5YLH9t4GuuvB4KNRKTXg1W OVIIIGwtYP5l4jty2aljxGV6+toKx/7PFbaL40wIX0/ji7GA6u/HYo5VObxwvuS5WkTz y/zBOjoiqxRUgqiHtz3kTurpBErAHC2ZJRTlwpJyyo4tDHOnv07rY+8i6ir0jix0Y/uH hIiw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=rryWRANd; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-130752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130752-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i32-20020a635860000000b005d8bbd208desi13908524pgm.163.2024.04.03.16.52.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 16:52:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=rryWRANd; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-130752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130752-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7CD2C28ACFF for ; Wed, 3 Apr 2024 23:51:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93BC6156C6C; Wed, 3 Apr 2024 23:50:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="rryWRANd" Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8F5D156C44 for ; Wed, 3 Apr 2024 23:50:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712188247; cv=none; b=PinbZnyPg65eJz1+AKuQZxqk9ZJuFxKLVvjoPXGM2x+bB9TuapeFXi64Ut1nluAjPkCKcMg81eL8J000dD3vUcmmNY+W+HZItNsuSCvczHDdioixer3z6+rxjZsBaOsOl259lxJq1akctB4Ia11mp/2R3hc82n38A5QZp8LAZvQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712188247; c=relaxed/simple; bh=sjml5nKV165rpXbyrONuqdwpWxVpnj1/2NP5/i0pID8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=WeOa8lSQGHHlKEhnO8Nhe+EuvDkgK6Yo4Or14GXXfh0fYZhCPBfrN5fIjgjXuV6w8i4VDtOQ4w807G/aboQzUtCFr75kqRq+S5wQxPVq/TqSzNDJa2xqmKHsGzolsmNuQcyGoi6nuEdympE0EZXvvx2Px2PigIP0Yy1qoE5sjzI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=rryWRANd; arc=none smtp.client-ip=209.85.210.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-6e67b5d6dd8so224430a34.2 for ; Wed, 03 Apr 2024 16:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712188245; x=1712793045; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=BjQ9DxTSZlVH9DP6dgs1HodUGsGtzbmnUpujjVOtQj8=; b=rryWRANdqVHZ5Zrg/9KSaCBISkL3lcRobYcHGHGyuNky/l6Qv0Iyt6GyXGUVIkDdFg gRvmx3mW3v3oCHmbTEAVjLxiKIRAHlMAJGPJ7QiKvfAKB+S27yWQvH7FXc9ZUfFJgVyj QVgGoDG1hmhzhiTcZqSP3KZxZEK+X36qdyJCstkbJ8ojNoMLDWHlXg/OXCuuxH3Qpcm7 QzqhQa7CXu7ressZAAMfC8kFQzxerszk+Otnx4Aof57bghHYPLatG7bp+1xI9iuIyd7t Wuh8v5kc46yWRjtBt4/TyZebGGBF/OnosC983DLRKSNQ/yR4hv/laBgQrRo0PDAEBhTJ PQ8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712188245; x=1712793045; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BjQ9DxTSZlVH9DP6dgs1HodUGsGtzbmnUpujjVOtQj8=; b=ZHMikc96cJWFl4GHBcPOFmt3AdeNeX+6ESOx7zj/4t9uBSdrK/0+4qh5Q9+gJMbXyj 5codEpwyndhAE3u9pnsbVvviWrCabd928i8lw7TwZO5nuM2IRt2691UnJfx/WVEOXhty gN+ktRlbpGtM5n00x0dhpa5UZuVi0256i8B2wBmurX0FbA6sl/U3EfMKjxl8WEDcmVCk tz41+RtD1gb3uSmizqXOaOmdVUbNwIyPEvjJhUNZtOx3cTHGhSYBrdMaBfOG4JbaKfWB LJQ3uynpfytp5cgyR28E6zG14KNBe/509fn3TeSTZ1vmgSBX1KsJAEPMIG690MB+yvaJ EPQQ== X-Gm-Message-State: AOJu0YzRbEKiwIv7PQhuj4UIfKFBnuax6SN8gOgmvpCawOzgDqcRai/R IFc4TEz6EFAZEncl1yM101MA+GThao1hWlfatwCKjRcJMcRiQeoMXWMT0AOtBCM= X-Received: by 2002:a05:6870:f113:b0:22e:8954:79e0 with SMTP id k19-20020a056870f11300b0022e895479e0mr910730oac.27.1712188244889; Wed, 03 Apr 2024 16:50:44 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id fk23-20020a056a003a9700b006eac2c1187esm12396470pfb.69.2024.04.03.16.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 16:50:44 -0700 (PDT) From: Charlie Jenkins Date: Wed, 03 Apr 2024 16:50:29 -0700 Subject: [PATCH] riscv: selftests: Add signal handling vector tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240403-vector_sigreturn_tests-v1-1-2e68b7a3b8d7@rivosinc.com> X-B4-Tracking: v=1; b=H4sIAETrDWYC/x3MQQqAIBBA0avErBO0DKSrRITYaLOxmLEIorsnL d/i/wcEmVBgbB5gvEhozxWmbSBsPidUtFZDpzurre7VhaHsvAglxnJyXgpKEeWMcVH7MNjoocY HY6T7H0/z+358AMhUaAAAAA== To: Shuah Khan , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andy Chiu , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , Vineet Gupta Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Charlie Jenkins X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712188243; l=4622; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=sjml5nKV165rpXbyrONuqdwpWxVpnj1/2NP5/i0pID8=; b=4iFK/GfVcZesnDl+zdr6iD0IGvm4qzOpnkoVTbipLNsG58jc957MZltjGAdMn1mOnR5S7NYNa vRE76Q28UMqADC3o7OVdl/8bmddTFGw77o8lQqW12vEowRDKKO0WIxs X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Add two tests to check vector save/restore when a signal is received during a vector routine. One test ensures that a value is not clobbered during signal handling. The other verifies that vector registers modified in the signal handler are properly reflected when the signal handling is complete. Signed-off-by: Charlie Jenkins --- These tests came about to highlight the bug fixed in https://lore.kernel.org/lkml/20240403072638.567446-1-bjorn@kernel.org/ and will only pass with that fix applied. --- tools/testing/selftests/riscv/Makefile | 2 +- tools/testing/selftests/riscv/sigreturn/.gitignore | 1 + tools/testing/selftests/riscv/sigreturn/Makefile | 12 ++++ .../testing/selftests/riscv/sigreturn/sigreturn.c | 82 ++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/riscv/Makefile b/tools/testing/selftests/riscv/Makefile index 4a9ff515a3a0..7ce03d832b64 100644 --- a/tools/testing/selftests/riscv/Makefile +++ b/tools/testing/selftests/riscv/Makefile @@ -5,7 +5,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),riscv)) -RISCV_SUBTARGETS ?= hwprobe vector mm +RISCV_SUBTARGETS ?= hwprobe vector mm sigreturn else RISCV_SUBTARGETS := endif diff --git a/tools/testing/selftests/riscv/sigreturn/.gitignore b/tools/testing/selftests/riscv/sigreturn/.gitignore new file mode 100644 index 000000000000..35002b8ae780 --- /dev/null +++ b/tools/testing/selftests/riscv/sigreturn/.gitignore @@ -0,0 +1 @@ +sigreturn diff --git a/tools/testing/selftests/riscv/sigreturn/Makefile b/tools/testing/selftests/riscv/sigreturn/Makefile new file mode 100644 index 000000000000..eb8bac9279a8 --- /dev/null +++ b/tools/testing/selftests/riscv/sigreturn/Makefile @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021 ARM Limited +# Originally tools/testing/arm64/abi/Makefile + +CFLAGS += -I$(top_srcdir)/tools/include + +TEST_GEN_PROGS := sigreturn + +include ../../lib.mk + +$(OUTPUT)/sigreturn: sigreturn.c + $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^ diff --git a/tools/testing/selftests/riscv/sigreturn/sigreturn.c b/tools/testing/selftests/riscv/sigreturn/sigreturn.c new file mode 100644 index 000000000000..62397d5934f1 --- /dev/null +++ b/tools/testing/selftests/riscv/sigreturn/sigreturn.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include +#include "../../kselftest_harness.h" + +#define RISCV_V_MAGIC 0x53465457 +#define DEFAULT_VALUE 2 +#define SIGNAL_HANDLER_OVERRIDE 3 + +static void simple_handle(int sig_no, siginfo_t *info, void *vcontext) +{ + ucontext_t *context = vcontext; + + context->uc_mcontext.__gregs[REG_PC] = context->uc_mcontext.__gregs[REG_PC] + 4; +} + +static void vector_override(int sig_no, siginfo_t *info, void *vcontext) +{ + ucontext_t *context = vcontext; + + // vector state + struct __riscv_extra_ext_header *ext; + struct __riscv_v_ext_state *v_ext_state; + + /* Find the vector context. */ + ext = (void *)(&context->uc_mcontext.__fpregs); + if (ext->hdr.magic != RISCV_V_MAGIC) { + fprintf(stderr, "bad vector magic: %x\n", ext->hdr.magic); + abort(); + } + + v_ext_state = (void *)((char *)(ext) + sizeof(*ext)); + + *(int *)v_ext_state->datap = SIGNAL_HANDLER_OVERRIDE; + + context->uc_mcontext.__gregs[REG_PC] = context->uc_mcontext.__gregs[REG_PC] + 4; +} + +static int vector_sigreturn(int data, void (*handler)(int, siginfo_t *, void *)) +{ + int after_sigreturn; + struct sigaction sig_action = { + .sa_sigaction = handler, + .sa_flags = SA_SIGINFO + }; + + sigaction(SIGSEGV, &sig_action, 0); + + asm(".option push \n\ + .option arch, +v \n\ + vsetivli x0, 1, e32, ta, ma \n\ + vmv.s.x v0, %1 \n\ + # Generate SIGSEGV \n\ + lw a0, 0(x0) \n\ + vmv.x.s %0, v0 \n\ + .option pop" : "=r" (after_sigreturn) : "r" (data)); + + return after_sigreturn; +} + +TEST(vector_restore) +{ + int result; + + result = vector_sigreturn(DEFAULT_VALUE, &simple_handle); + + EXPECT_EQ(DEFAULT_VALUE, result); +} + +TEST(vector_restore_signal_handler_override) +{ + int result; + + result = vector_sigreturn(DEFAULT_VALUE, &vector_override); + + EXPECT_EQ(SIGNAL_HANDLER_OVERRIDE, result); +} + +TEST_HARNESS_MAIN --- base-commit: 4cece764965020c22cff7665b18a012006359095 change-id: 20240403-vector_sigreturn_tests-8118f0ac54fa -- - Charlie