From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Db8NMAfX02T3aDwAWB0awg (envelope-from ) for ; Wed, 09 Aug 2023 14:12:23 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ZrxDxQiB; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B6FA81E0BB; Wed, 9 Aug 2023 14:12:23 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A83801E028 for ; Wed, 9 Aug 2023 14:12:21 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 173C03857706 for ; Wed, 9 Aug 2023 18:12:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 173C03857706 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1691604741; bh=W/LAE/sJHM2okWK5mOOjJxvyPgMdqkUS/ir0FQoPamc=; h=References:In-Reply-To:Date:Subject:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ZrxDxQiBV4TIH2gLTLJ9lT97Lh8ciY+dMh79khib1jXUZb2WM6ZOYqHzMqpsNhrj0 kLAYqkebrLokN7k5imGuY+HQZF7wJLY9nx3NfVZXJeLRml93/UB6yU3njgHwz39zsN 3CkndYOHRdiUm9cp7XevYws3Jc070/bOHwMid1JM= Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 6A5FF385770D for ; Wed, 9 Aug 2023 18:11:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A5FF385770D Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4fe85fd3d27so59283e87.0 for ; Wed, 09 Aug 2023 11:11:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691604715; x=1692209515; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ib3Qgt3pwANiBg9x+v82uZBaXvWyC+JTzAQ+Bm4DWpk=; b=Y0C+UnQq4PsTz43lU1gRtcB8xqMj5i6dU04yBc2pI9N7N9I/qGMrpOnltscQpDoX8I V1RpBRq11l4pxEVfHkxgLS7+98ZGyc6Wwj5Cl70tYao9v/OaiTRo+ifQxIdOzYK1qT4o O14wWSiAfQPVEyoi1vFnyMcYYt19xLFxRfk0MbwuSPbtFM/QVXEOiMbEAsTgWc88PZlw ZkUfQr4OpJ0q5CjImNvkK/NJbr/P1kNisRuKT3ESJg46IJn13vl4+fJYD8j9Lyp6368t NxU/OhTheE+IM0cf+zIvuLSdwm7JHbEqZuNjug9S0pGWYz0AKHizbkHUrOB0A2T2ort4 hoDg== X-Gm-Message-State: AOJu0YzcWZC1tviaZTmDPi5QyZHTEuJeTo5TgdsVj29nRzUCdstALz4p KyAxIm6Yi2O/Lvj6Lmxa+gEIKPvd7RC6xTA4w5jHQfWegrcPCImv X-Google-Smtp-Source: AGHT+IEWpq7AVti6x9bcQXg2DfG3GDiS7bgdtlbY8Vef+OJz7pCpm5pbAtEyZOUzyWVUHG5lwyaZ15WGgHIjrzc2qew= X-Received: by 2002:a05:6512:3f1:b0:4fb:9772:6639 with SMTP id n17-20020a05651203f100b004fb97726639mr2216817lfq.6.1691604715496; Wed, 09 Aug 2023 11:11:55 -0700 (PDT) MIME-Version: 1.0 References: <20230803230110.904724-1-greg.savin@sifive.com> In-Reply-To: Date: Wed, 9 Aug 2023 11:11:44 -0700 Message-ID: Subject: Re: [PATCH] RISC-V: support for vector register accesses via ptrace() in RISC-V Linux native To: "Maciej W. Rozycki" Cc: gdb-patches@sourceware.org, Andrew Burgess X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Greg Savin via Gdb-patches Reply-To: Greg Savin Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi Maciej, The SIGILL guard is being used as a wrapper around determination of the VLENB CSR, which is not part of the ptrace() payload for vector registers, at least as it exists at head-of-tree Linux kernel. GDB or gdbserver needs to know VLENB in order to construct the architectural feature metadata that reports an accurate width for the vector registers. If not for the VLENB determination specifically, and the lack of this information via ptrace(), then there would be no motivation for executing a vector instruction directly. It's a workaround, basically. I guess I could inquire in Linux kernel land regarding whether the NT_RISCV_VECTOR ptrace() payload could be enhanced to provide VLENB. Regards, Greg On Wed, Aug 9, 2023 at 2:21=E2=80=AFAM Maciej W. Rozycki wrote: > On Thu, 3 Aug 2023, Greg Savin via Gdb-patches wrote: > > > +static unsigned long > > +safe_read_vlenb () > > +{ > > + /* Surrounding the attempt here to read VLENB CSR to have a signal > handler set up > > + to trap illegal instruction condition (SIGILL), and if a trap > happens during this call, > > + get control back within this function and return 0 in that case. > > + */ > > + unsigned long vlenb =3D 0; > > + struct sigaction our_action =3D { 0 }; > > + struct sigaction original_action; > > + int sysresult; > > + > > + > > + our_action.sa_handler =3D sigill_guard; > > + > > + sysresult =3D sigaction (SIGILL, &our_action, &original_action); > > + if (sysresult !=3D 0) > > + { > > + perror > > + ("Error installing temporary SIGILL handler in safe_read_vlenb()"= ); > > + } > > + > > + if (SIGSETJMP (sigill_guard_jmp_buf, 1) =3D=3D 0) > > + { > > + asm ("csrr %0, vlenb":"=3Dr" (vlenb)); > > + } > > + else > > + { > > + /* Must've generated an illegal instruction condition; we'll > figure this means > > + no vector unit is present */ > > + vlenb =3D 0; > > + } > > I find it weird that you trap SIGILL and try to execute a vector > instruction in the debugger to determine whether `ptrace' can be used to > access the vector state in the debuggee. Why? > > The usual way is to try to use `ptrace' itself to determine whether the > OS has support for it in the first place and then can access the vector > state. You can then return the contents of the register retrieved if > successful. > > Maciej >