Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp3066691lqz; Wed, 3 Apr 2024 18:11:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUrhxDV6rgjquaQwS4uKn9eEg9YZQj1mto5eLY01UdW4u7to91co3uiHnpLahewpS3VNMubasY6sjhdf9j2PKoQkBUdoK23A0e93+vwDQ== X-Google-Smtp-Source: AGHT+IErxoW2TBRf4mpps9dR3mqnjTVbtE2O9gmJXXwbO6HIk/itwOmzw8e2ydlmTMSrnk3TPtcL X-Received: by 2002:a05:6358:6f8f:b0:17f:565c:8dad with SMTP id s15-20020a0563586f8f00b0017f565c8dadmr838633rwn.24.1712193061026; Wed, 03 Apr 2024 18:11:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712193060; cv=pass; d=google.com; s=arc-20160816; b=kmEmwngn11XEcSr3qHTUDgvrZ0lkDSbP7F/C3CMih64+0hFv5Cr1fOI8OQO3ReY9Lo AOSyIfkmGegh4p16UOykP8KL7rlXwdtBuH0pjRa/7tIedOO3y1oKCGkIKzCiFAt91Ifz WSKL9ByeuSp3WHcZQcB4nIf2hK4X1cgpvpyMt4y1V4oLhOkQyE5FeIvAzQWQI4XOopzz CA7gjqSLEr1zVPxenCQejhX15MvOOhQRVLmpNUdOs07Xu3upNz3XSwSgpDH/l2/NUvzI pEqY62l3pKNy0BYCyq2Y74NbAoDuq4gLh2mxsUMc79fAS+yadInuUx+/yw/AHFtYxrkk 90Rw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=NPAkNpwkOcE2aj5H76UIs4DtdZThjvuKeLHUXLWOipM=; fh=BpGRX/DkM/4wZmuqgcc8jPVuhOKyrctNbkobLfDqvug=; b=Ml44Cgx2hUD3zp3ApcgO2r3E1AJW0aWcrJSdx/Sa/ynIQ88i6CY7VXtwuVtIXpzpMX zuLVWkUxn0r0b2H0ErjEa92R1cxFzp4OvjUriFWD694RAUBOe45a2Y1wgiAx6j0Z8S2r j49GfB3e+fBAidi2I8O9+CH1tpenNzn39imc7igwxJqULCOysgqUG1ypz1zL1Wu4eB0r ce6g8KMB6ZgBjhkHdT16AQmSXVAhoR+1VhibjAEeG6Lis2mamW1NSJpbbjfo3PY3A1lu yXOqQUm7sQqd1Q9mDfzeeMpINxARsRrg017tr+5SC9VpZv1gzQMuzyQwpfVOeo7NDIs/ Q/Sg==; 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=Dpo8It0M; 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-130793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130793-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k11-20020a6568cb000000b005dc496a3597si7760326pgt.417.2024.04.03.18.11.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 18:11:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Dpo8It0M; 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-130793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130793-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B45A7B2ACE7 for ; Thu, 4 Apr 2024 00:44:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AD9C4C97; Thu, 4 Apr 2024 00:43:57 +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="Dpo8It0M" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 C80E037E for ; Thu, 4 Apr 2024 00:43:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712191436; cv=none; b=b6ZfaTpvwJVHHGfP1lGSWIngpyhJN2c+yXQmPbDrMnt+rZpS3a2XEa+rpQLWEEtjx91u7przn0QWCFLD0TZe0GRk9TWBREI/Z8N96QfJfqEAn/Bv5HZWt0ef0/6tTejj4MsHfqJa6mgHTZBQnnKFkAVbzl5WS3zxhNaYN7gOmUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712191436; c=relaxed/simple; bh=l7SjNlBscIXDHCJfPdHXfaKN62Yzih8xgtSq0+UhS8I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DWNdN9Ca494cE8Htx+BXrJZy53lqYQRDk10e5alq8IJoSOINDe+MADrbQCtfOACwR37nVOzeTql++f6z9moNApxiO/bweIwQcWynbdoInA12TW2bQikr445bZS3Qtea4206Sff0qiIY1UtgcKBLAqwtftp5ClpCow8w4SzAJdoA= 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=Dpo8It0M; arc=none smtp.client-ip=209.85.215.182 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-pg1-f182.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso372649a12.3 for ; Wed, 03 Apr 2024 17:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712191433; x=1712796233; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=NPAkNpwkOcE2aj5H76UIs4DtdZThjvuKeLHUXLWOipM=; b=Dpo8It0MpO/4EKZq/dLqnl8VTu/k+kFqte8YzPZCW+5NoceEpdaptDFvkM8/6Qp43d 9aypLH9C07xpgQMJtdus0fCSBOWsyIIhHZqIiZqqJ1XIpWOq6/mBSAombSzU7SMjrp+w 3ZG1rgfLsPJ2zA+DL1jUDkCwmaadAYXXFL4ifkZVdFcvFrK289icC7M4z0pvZvhSBW9w PlakplbIsNIe0nOeBfn6Jkz5QZ99sYccO/6nFtSjHC1R4dyNSVAj9ul9ayPNggDfY0z2 EvhPU+WQSIjICum+rhVFKsJNw0PtJmGWsYEnoFHImkJUXgoiwCZ5bnf1Wvd9/PNqd/X2 azkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712191433; x=1712796233; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NPAkNpwkOcE2aj5H76UIs4DtdZThjvuKeLHUXLWOipM=; b=nsnFuX/SB//5+K/sgMUpkY0HWZpvN6OWea8ZX6zRK2edEtFJ+BbR09C3KCDmEyQegB NV88jVP1A8fbacubkuvvBWlx1z6gNi+qy6Gb/deySZjlYpXi2Oi4YSSaVyVIQ15jGq1g tlYGKUCMOXWmTM59Wga2J2Q2Kwpr+IHe2k/au2pFPCQVotfNXo8IsSfdfzzkgQccnHbY 3LNXN75OSeYGiyzImJfMNPcueexrBnWQ7oHq7jgr3RRr9sM2S9xyyUwXsyRFFOuCRHZw RSBHAFkDK3paXL5+hpL+sFXNJnJp6yhqumLAg3B+MPO2LTdsFgCwdTCp2MPGR5MQ4okT oneQ== X-Forwarded-Encrypted: i=1; AJvYcCWJ592Ec7O7jE/JBsWAlRSkVM7tl7fIZxbBXAJrxxKfUbX+o6Fwvw8cUcQgzI5ykzIROfymlE5m2YvNVh0xm/s1T1lw4HYAwbbHL4ev X-Gm-Message-State: AOJu0YzZyKIzjcpFVwze/hmDA9K8uXLgTfejzUsuOF7G2XFzDEWq7v/t 4KnvrggFUJgOh/a47z78NDMWkNJAUCDuSbG9IfcZD6H/mxh0Q6NRy26sNA/+7xI6kV02GIFYJz6 u X-Received: by 2002:a17:90a:8d01:b0:2a2:b5db:79cf with SMTP id c1-20020a17090a8d0100b002a2b5db79cfmr1155132pjo.21.1712191433057; Wed, 03 Apr 2024 17:43:53 -0700 (PDT) Received: from ghost ([2601:647:5700:6860:b005:9197:83df:91f1]) by smtp.gmail.com with ESMTPSA id t15-20020a17090a0d0f00b002a24886fa5asm358052pja.36.2024.04.03.17.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 17:43:52 -0700 (PDT) Date: Wed, 3 Apr 2024 17:43:50 -0700 From: Charlie Jenkins To: Vineet Gupta Cc: Shuah Khan , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andy Chiu , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH] riscv: selftests: Add signal handling vector tests Message-ID: References: <20240403-vector_sigreturn_tests-v1-1-2e68b7a3b8d7@rivosinc.com> <56863fe7-4d82-4f37-a518-2acf368c3ea6@rivosinc.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <56863fe7-4d82-4f37-a518-2acf368c3ea6@rivosinc.com> On Wed, Apr 03, 2024 at 05:27:23PM -0700, Vineet Gupta wrote: > On 4/3/24 16:50, Charlie Jenkins wrote: > > 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. > > Hmm, isn't this testing two contradictory things ? > > We do want V regs to be not clobbered across a handled signal, o/w V > enabled code would just not work at all. > That implies that anything done by signal handler should just be > discarded - no ? > > Am I missing something. > > -Vineet This is referring to the user-implemented signal handler. The test in question is testing the ability of the user-implemented signal handler to be able to modify the vector registers. In the test: static void vector_override(int sig_no, siginfo_t *info, void *vcontext) { ... *(int *)v_ext_state->datap = SIGNAL_HANDLER_OVERRIDE; ... } This line is changing the saved state of the user program's vector registers. When the signal handling concludes and the original user program resumes execution, the content of the user-context registers that were modified by the signal handler should be restored into the hardware registers. Hence the test case checks that the v0 register contains the value SIGNAL_HANDLER_OVERRIDE. EXPECT_EQ(SIGNAL_HANDLER_OVERRIDE, result); - Charlie > > > > > 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 >