From patchwork Mon Jul 4 18:13:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12905772 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 07E9CC433EF for ; Mon, 4 Jul 2022 18:14:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233550AbiGDSO4 (ORCPT ); Mon, 4 Jul 2022 14:14:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233326AbiGDSO4 (ORCPT ); Mon, 4 Jul 2022 14:14:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0435B863 for ; Mon, 4 Jul 2022 11:14:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 44A42615F1 for ; Mon, 4 Jul 2022 18:14:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7314C341CD; Mon, 4 Jul 2022 18:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656958492; bh=fawzE1wErSSnwcEEm6P4Uue8NDFRkja7UF5XYZYKoUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VVe18dIk6DzVWY9/Z8rjRCpwdIug1Lptf5c1tfe+eYjy8CLLWWFO7LxUasznqxNNK B34ssW5FtLeUDM4Nrn6QoCYcIDRFi0PuydnEXQ5uS/fbNIBDZdIPqF+SE4ygqUj5JI C2A+8T8XSHwxQiSB2N3uwv7XIdGkBHQBOcUU/xn8N4atQdeOWkC0Le4iEsazXJ2WbL A/D/srRxHrRCR7Ec/t1ikf3iRKzdNBu8RagTGghzxS/zxUPTM0G5iNE481uj+XgtUs Q+b5E/2h660CASQ9C1nKf4QHaoNOgXm25Kl3flE3/Kyiif18KlRCse018xHN6P4Wha OhbfzOKUm1Mbg== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan , Shuah Khan Cc: Alan Hayward , Luis Machado , linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown Subject: [PATCH v1 1/4] kselftest/arm64: Add test coverage for NT_ARM_TLS Date: Mon, 4 Jul 2022 19:13:29 +0100 Message-Id: <20220704181332.3318214-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220704181332.3318214-1-broonie@kernel.org> References: <20220704181332.3318214-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5050; h=from:subject; bh=fawzE1wErSSnwcEEm6P4Uue8NDFRkja7UF5XYZYKoUs=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiwy3JQ3HAK6cHlsMtQRp2yrMQ4gEbIEfaHkMkToEg bJFYu4WJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYsMtyQAKCRAk1otyXVSH0GubB/ 9TyqpMSp2526WJUE+I097VRmh/s3GP6NLaptUNtoVEQ7oXMZZZkjiRdXoVJTmErx//dhb2Ki/wr1ac jWx0mfdnyl+2BOa2TTGFjKxGBGiAu5kl/xVXcpcRZHgJI6GXLYRZ4kAkS5z3VwV+DOsXuS0FIpiMU7 Q050ChP95XzWtejvSPwDvpKzlcO7PiZcZA19EVgnEiFliuJaxrS6xnb7Gif5C1uRLovTIFtSf1QPhB VVWLrJkMV7CygNETBFna/sI99qjtNiKQxDjd4vPw0/e6XCXiGLavO4kl8s0susMItW1PsPCqY5hClF L+Ov3dQH5ud7nSyE0KCoV9FoFIm8v2 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org In preparation for extending support for NT_ARM_TLS to cover additional TPIDRs add some tests for the existing interface. Do this in a generic ptrace test program to provide a place to collect additional tests in the future. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/abi/.gitignore | 1 + tools/testing/selftests/arm64/abi/Makefile | 2 +- tools/testing/selftests/arm64/abi/ptrace.c | 165 +++++++++++++++++++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/arm64/abi/ptrace.c diff --git a/tools/testing/selftests/arm64/abi/.gitignore b/tools/testing/selftests/arm64/abi/.gitignore index b9e54417250d..12607c4580c6 100644 --- a/tools/testing/selftests/arm64/abi/.gitignore +++ b/tools/testing/selftests/arm64/abi/.gitignore @@ -1,2 +1,3 @@ +ptrace syscall-abi tpidr2 diff --git a/tools/testing/selftests/arm64/abi/Makefile b/tools/testing/selftests/arm64/abi/Makefile index c8d7f2495eb2..445ac2dac4ee 100644 --- a/tools/testing/selftests/arm64/abi/Makefile +++ b/tools/testing/selftests/arm64/abi/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # Copyright (C) 2021 ARM Limited -TEST_GEN_PROGS := syscall-abi tpidr2 +TEST_GEN_PROGS := ptrace syscall-abi tpidr2 include ../../lib.mk diff --git a/tools/testing/selftests/arm64/abi/ptrace.c b/tools/testing/selftests/arm64/abi/ptrace.c new file mode 100644 index 000000000000..4cc4d415b2e7 --- /dev/null +++ b/tools/testing/selftests/arm64/abi/ptrace.c @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2021 ARM Limited. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../kselftest.h" + +#define EXPECTED_TESTS 3 + +#define MAX_TPIDRS 1 + +static bool have_sme(void) +{ + return getauxval(AT_HWCAP2) & HWCAP2_SME; +} + +static void test_tpidr(pid_t child) +{ + uint64_t read_val[MAX_TPIDRS]; + uint64_t write_val[MAX_TPIDRS]; + struct iovec read_iov, write_iov; + int ret; + + read_iov.iov_base = read_val; + write_iov.iov_base = write_val; + + /* Should be able to read a single TPIDR... */ + read_iov.iov_len = sizeof(uint64_t); + ret = ptrace(PTRACE_GETREGSET, child, NT_ARM_TLS, &read_iov); + ksft_test_result(ret == 0, "read_tpidr_one\n"); + + /* ...write a new value.. */ + write_iov.iov_len = sizeof(uint64_t); + write_val[0] = read_val[0]++; + ret = ptrace(PTRACE_SETREGSET, child, NT_ARM_TLS, &write_iov); + ksft_test_result(ret == 0, "write_tpidr_one\n"); + + /* ...then read it back */ + ret = ptrace(PTRACE_GETREGSET, child, NT_ARM_TLS, &read_iov); + ksft_test_result(ret == 0 && write_val[0] == read_val[0], + "verify_tpidr_one\n"); +} + +static int do_child(void) +{ + if (ptrace(PTRACE_TRACEME, -1, NULL, NULL)) + ksft_exit_fail_msg("PTRACE_TRACEME", strerror(errno)); + + if (raise(SIGSTOP)) + ksft_exit_fail_msg("raise(SIGSTOP)", strerror(errno)); + + return EXIT_SUCCESS; +} + +static int do_parent(pid_t child) +{ + int ret = EXIT_FAILURE; + pid_t pid; + int status; + siginfo_t si; + + /* Attach to the child */ + while (1) { + int sig; + + pid = wait(&status); + if (pid == -1) { + perror("wait"); + goto error; + } + + /* + * This should never happen but it's hard to flag in + * the framework. + */ + if (pid != child) + continue; + + if (WIFEXITED(status) || WIFSIGNALED(status)) + ksft_exit_fail_msg("Child died unexpectedly\n"); + + if (!WIFSTOPPED(status)) + goto error; + + sig = WSTOPSIG(status); + + if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &si)) { + if (errno == ESRCH) + goto disappeared; + + if (errno == EINVAL) { + sig = 0; /* bust group-stop */ + goto cont; + } + + ksft_test_result_fail("PTRACE_GETSIGINFO: %s\n", + strerror(errno)); + goto error; + } + + if (sig == SIGSTOP && si.si_code == SI_TKILL && + si.si_pid == pid) + break; + + cont: + if (ptrace(PTRACE_CONT, pid, NULL, sig)) { + if (errno == ESRCH) + goto disappeared; + + ksft_test_result_fail("PTRACE_CONT: %s\n", + strerror(errno)); + goto error; + } + } + + ksft_print_msg("Parent is %d, child is %d\n", getpid(), child); + + test_tpidr(child); + + ret = EXIT_SUCCESS; + +error: + kill(child, SIGKILL); + +disappeared: + return ret; +} + +int main(void) +{ + int ret = EXIT_SUCCESS; + pid_t child; + + srandom(getpid()); + + ksft_print_header(); + + ksft_set_plan(EXPECTED_TESTS); + + child = fork(); + if (!child) + return do_child(); + + if (do_parent(child)) + ret = EXIT_FAILURE; + + ksft_print_cnts(); + + return ret; +} From patchwork Mon Jul 4 18:13:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12905773 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 07355C433EF for ; Mon, 4 Jul 2022 18:14:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233539AbiGDSO6 (ORCPT ); Mon, 4 Jul 2022 14:14:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233326AbiGDSO6 (ORCPT ); Mon, 4 Jul 2022 14:14:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9376FB863 for ; Mon, 4 Jul 2022 11:14:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 48F90B811E0 for ; Mon, 4 Jul 2022 18:14:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 202DDC341CF; Mon, 4 Jul 2022 18:14:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656958495; bh=4SS1HhiCCSG9y1tYIhTUgiCAE3c544P3f86asq/gm0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CW9jp+YMe6eY7y4NoxXDNeuZ4GNIRLulJ1I93h8VUfKI3cOD1e2P3ov+vCkGvkt96 3X5KEJXwCb05GHAG1JKS8MU0qA9bb1L0A+iKfNDkK3Eyyy7dWihLRSTfmc7MbKQrGj +HojrmvmTfC546E6ZIXP88gsH6j3jl0X3cKdD/y9+rLr83mNiP0KEPLR8OGo973F7b bGtE3iEkCYc0UPs/r9KuceOzVqguTzGE70DhDwSc61wGRb5PxtoiWA4I+/dPorVTpZ rJ2abVuZwBR2eCX5U7xKrHAhhTPSwIiLBGT0P6ebE+jd2nHWRSM2iy/rRjLvX74CI+ cKpdn0eAr1svw== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan , Shuah Khan Cc: Alan Hayward , Luis Machado , linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown Subject: [PATCH v1 2/4] arm64/ptrace: Document extension of NT_ARM_TLS to cover TPIDR2_EL0 Date: Mon, 4 Jul 2022 19:13:30 +0100 Message-Id: <20220704181332.3318214-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220704181332.3318214-1-broonie@kernel.org> References: <20220704181332.3318214-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1023; h=from:subject; bh=4SS1HhiCCSG9y1tYIhTUgiCAE3c544P3f86asq/gm0U=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiwy3KjoHA7nfaC+35Gif2a+0nlfbRiTju6t1wdb9X jyFWDcOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYsMtygAKCRAk1otyXVSH0B8+CA CDbpf/pnNRu1N1AfwGh+sKz1lY2Wb4IWG2kDZcUVVQpvowa/GPGXO87G3EJckwvJcyF0SwGrwyTbxW 1z0sdJRY80MogwewBjWVPs+o+03yDDEL5Q4mJ2hSuWqxBLL9NXQaD+2G0ecJ1N+r71Em5PwVnBAs0c wqb1E5/SvE1OqM3TSVOtCyNof+XhFq3W8unnGYZ0G+rUdkAVm4DB1LYbTrAO8+N/WnVKQ83dqzL6qu 3XIA/V31r8/w6RcKjZXaHEoR45sguAGmKmeyvlNj/+PUCKbl5oqszC5BWEmuE9ERi939o23k483R2k IsXN4WNWlbu2x0nR6Fmts00Nk4WCcn X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org In order to allow debuggers to discover lazily saved SME state we need to provide access to TPIDR2_EL0, we will extend the existing NT_ARM_TLS used for TPIDR to also include TPIDR2_EL0 as the second register in the regset. Signed-off-by: Mark Brown --- Documentation/arm64/sme.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/arm64/sme.rst b/Documentation/arm64/sme.rst index 937147f58cc5..16d2db4c2e2e 100644 --- a/Documentation/arm64/sme.rst +++ b/Documentation/arm64/sme.rst @@ -331,6 +331,9 @@ The regset data starts with struct user_za_header, containing: been read if a PTRACE_GETREGSET of NT_ARM_ZA were executed for each thread when the coredump was generated. +* The NT_ARM_TLS note will be extended to two registers, the second register + will contain TPIDR2_EL0 on systems that support SME and will be read as + zero with writes ignored otherwise. 9. System runtime configuration -------------------------------- From patchwork Mon Jul 4 18:13:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12905774 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 760AAC43334 for ; Mon, 4 Jul 2022 18:15:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233628AbiGDSPB (ORCPT ); Mon, 4 Jul 2022 14:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233326AbiGDSPA (ORCPT ); Mon, 4 Jul 2022 14:15:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0010637C for ; Mon, 4 Jul 2022 11:14:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AE67EB811FC for ; Mon, 4 Jul 2022 18:14:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D69AC341CB; Mon, 4 Jul 2022 18:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656958497; bh=2FRY03mI0lys9sGvaqOL1d+m6IEPqOMSpUOGBSMSQvQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bq6Cyt751EBE6fDRLDS9+LW0OiaO7MEDxggL6h28jZUq7pOKMDiaLT76XUYMhbo8M pBQAAwuXjonrmBGvWvznEjgu4aC7dRZGI+ppotUasPUF9FaU+gsqDwNBXIbjEE5Ybr mxGleaHFeAmiGACnv6265Wc3r7lppylfRls5F4/P73n/zhfhpCg7jWYGBKOXZC/tyW sTAfoOJpbD1gF2etRoM/i+M5mAhXLZDGny2ejc+dEelPs+5U087IsD8hc30Snu4e6+ U7h0jtU21QnXPH9EUdp3SPE2VxjxNdLCnYuU2b8JhlJcjhPSAfYdiUJhoy9TN3rdNz DMWML9vTFUo0A== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan , Shuah Khan Cc: Alan Hayward , Luis Machado , linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown Subject: [PATCH v1 3/4] arm64/ptrace: Support access to TPIDR2_EL0 Date: Mon, 4 Jul 2022 19:13:31 +0100 Message-Id: <20220704181332.3318214-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220704181332.3318214-1-broonie@kernel.org> References: <20220704181332.3318214-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2582; h=from:subject; bh=2FRY03mI0lys9sGvaqOL1d+m6IEPqOMSpUOGBSMSQvQ=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiwy3K7HF509PjAusm21vbxp1Var0V8oRiJCuMprVH mcWqdQ+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYsMtygAKCRAk1otyXVSH0BbjB/ 0eWCDoTfarmX7ufAfxHEIyGJ/6LJQxFKDB4sud8sMYQGw4rvk9In6tlP+kbNoYqiKVU82Otgu4BE0A 8zZNvZibU+HAfRXtsiGPcmXN4RB7EhOi6d1gx1yCp5Lh0pkqhXg4IDWzeMG3FjUbHDOlxMWJvrpX9i x7xxjl4XRtCt000cLrLTlsO1WFbvByy7jaFcO2982oOz3U4gBXNAoKs1M5+IhpCYgAPstnezXPbbXX 0ZycbYQKVXn6Alm8S2POFlIgspTOgEPxL/FMqZBEUBzz+TljagP+xJUU5HiT5mcycNsL6bMLgmovx3 he3c+wWpUSbBxE6uQQUm7lBc2qCqp3 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org SME introduces an additional EL0 register, TPIDR2_EL0, intended for use by userspace as part of the SME. Provide ptrace access to it through the existing NT_ARM_TLS regset used for TPIDR_EL0 by expanding it to two registers with TPIDR2_EL0 being the second one. Existing programs that query the size of the register set will be able to observe the increased size of the register set. Programs that assume the register set is single register will see no change. On systems that do not support SME TPIDR2_EL0 will read as 0 and writes will be ignored, support for SME should be queried via hwcaps as normal. Signed-off-by: Mark Brown --- arch/arm64/kernel/ptrace.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 21da83187a60..82feabba3911 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -666,10 +666,18 @@ static int fpr_set(struct task_struct *target, const struct user_regset *regset, static int tls_get(struct task_struct *target, const struct user_regset *regset, struct membuf to) { + int ret; + if (target == current) tls_preserve_current_state(); - return membuf_store(&to, target->thread.uw.tp_value); + ret = membuf_store(&to, target->thread.uw.tp_value); + if (system_supports_tpidr2()) + ret = membuf_store(&to, target->thread.tpidr2_el0); + else + ret = membuf_zero(&to, sizeof(u64)); + + return ret; } static int tls_set(struct task_struct *target, const struct user_regset *regset, @@ -677,13 +685,20 @@ static int tls_set(struct task_struct *target, const struct user_regset *regset, const void *kbuf, const void __user *ubuf) { int ret; - unsigned long tls = target->thread.uw.tp_value; + unsigned long tls[2]; - ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &tls, 0, -1); + tls[0] = target->thread.uw.tp_value; + if (system_supports_sme()) + tls[1] = target->thread.tpidr2_el0; + + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, tls, 0, count); if (ret) return ret; - target->thread.uw.tp_value = tls; + target->thread.uw.tp_value = tls[0]; + if (system_supports_sme()) + target->thread.tpidr2_el0 = tls[1]; + return ret; } @@ -1392,7 +1407,7 @@ static const struct user_regset aarch64_regsets[] = { }, [REGSET_TLS] = { .core_note_type = NT_ARM_TLS, - .n = 1, + .n = 2, .size = sizeof(void *), .align = sizeof(void *), .regset_get = tls_get, From patchwork Mon Jul 4 18:13:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12905775 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 3CAC0C433EF for ; Mon, 4 Jul 2022 18:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231465AbiGDSPF (ORCPT ); Mon, 4 Jul 2022 14:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230349AbiGDSPD (ORCPT ); Mon, 4 Jul 2022 14:15:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 634532C7 for ; Mon, 4 Jul 2022 11:15:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1AC17B811FB for ; Mon, 4 Jul 2022 18:15:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBC0DC341CA; Mon, 4 Jul 2022 18:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656958499; bh=WtxGbnwMA4FM2hRQxjmT3ZWIT+hyPUy99ZX+fZW5Elk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jxf5jI1wRXbpbCyM8TEQq+XvBhNLa5RkIKmnIGMSV3Brx7x/WhTKRglqvVkdDz1q9 5+ojeCABRGy191Ev54qLl77M+7+3tr3l7kkIBBQkOK4FBimScF1yEd2jLWYWYv/US/ mZGZ51t6txvyBLlYVChpiegINFLFw5gDtpnMeVDc+JoUztmm7ycWjZmlD4v3aeX0z4 tr4vvr2Rxs1oRiL52TiYVXy/Siyb3lTaZHWroN/6G8fJcGvywxj1GskviBe37lTpoV bTRA0YFepz/UILPq6fuqY+9Hd8YCeq4h8gR+iP4oaNkPNQbyjRSHmNxw0k85PwR2kW x+BhcW4frVaVA== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan , Shuah Khan Cc: Alan Hayward , Luis Machado , linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown Subject: [PATCH v1 4/4] kselftest/arm64: Add coverage of TPIDR2_EL0 ptrace interface Date: Mon, 4 Jul 2022 19:13:32 +0100 Message-Id: <20220704181332.3318214-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220704181332.3318214-1-broonie@kernel.org> References: <20220704181332.3318214-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3913; h=from:subject; bh=WtxGbnwMA4FM2hRQxjmT3ZWIT+hyPUy99ZX+fZW5Elk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiwy3LC9No1U7o9VGMR+xYV3ZpIJy2sIZV+M6q1Lhk jIY94c2JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYsMtywAKCRAk1otyXVSH0DZLB/ 9ypfuQVeVfsMXdMMnMRo6Z/CPfRVnWevAqVtesUBJW9+gaOWhEGmC+xqIQ3ESHqvos4KFXtMNijVgl oLYiDiOeZABK5yNTnTr7Rtc6CDGh12DD2IYJiet9SkKHPT9giMO5iGC5/A4kvPTueoORXvOPBLRZRy FFrjeWRkB09fh4TyifrSSaS8G056U4aOa4+5v0RXhI76H1BxCQ+fgNB6W2m89Fcu/XI6zdKpCSWJWw FuZzpsFFne8mraTGWVBsGAipXqcuNVjKGIHRWtMCN80wt3AVzd10qfaj5RNF2ZVrgYbucOQrntLk0K jrnss5iA5r81BLrg8OA2I2irfbzdGI X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Extend the ptrace test support for NT_ARM_TLS to cover TPIDR2_EL0 - on systems that support SME the NT_ARM_TLS regset can be up to 2 elements long with the second element containing TPIDR2_EL0. On systems supporting SME we verify that this value can be read and written while on systems that do not support SME we verify correct truncation of reads and writes. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/abi/ptrace.c | 82 +++++++++++++++++++++- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/arm64/abi/ptrace.c b/tools/testing/selftests/arm64/abi/ptrace.c index 4cc4d415b2e7..0a3d28a3972b 100644 --- a/tools/testing/selftests/arm64/abi/ptrace.c +++ b/tools/testing/selftests/arm64/abi/ptrace.c @@ -20,9 +20,9 @@ #include "../../kselftest.h" -#define EXPECTED_TESTS 3 +#define EXPECTED_TESTS 7 -#define MAX_TPIDRS 1 +#define MAX_TPIDRS 2 static bool have_sme(void) { @@ -34,7 +34,8 @@ static void test_tpidr(pid_t child) uint64_t read_val[MAX_TPIDRS]; uint64_t write_val[MAX_TPIDRS]; struct iovec read_iov, write_iov; - int ret; + bool test_tpidr2 = false; + int ret, i; read_iov.iov_base = read_val; write_iov.iov_base = write_val; @@ -54,6 +55,81 @@ static void test_tpidr(pid_t child) ret = ptrace(PTRACE_GETREGSET, child, NT_ARM_TLS, &read_iov); ksft_test_result(ret == 0 && write_val[0] == read_val[0], "verify_tpidr_one\n"); + + /* If we have TPIDR2 we should be able to read it */ + read_iov.iov_len = sizeof(read_val); + ret = ptrace(PTRACE_GETREGSET, child, NT_ARM_TLS, &read_iov); + if (ret == 0) { + /* If we have SME there should be two TPIDRs */ + if (read_iov.iov_len >= sizeof(read_val)) + test_tpidr2 = true; + + if (have_sme() && test_tpidr2) { + ksft_test_result(test_tpidr2, "count_tpidrs\n"); + } else { + ksft_test_result(read_iov.iov_len % sizeof(uint64_t) == 0, + "count_tpidrs\n"); + } + } else { + ksft_test_result_fail("count_tpidrs\n"); + } + + if (test_tpidr2) { + /* Try to write new values to all known TPIDRs... */ + write_iov.iov_len = sizeof(write_val); + for (i = 0; i < MAX_TPIDRS; i++) + write_val[i] = read_val[i] + 1; + ret = ptrace(PTRACE_SETREGSET, child, NT_ARM_TLS, &write_iov); + + ksft_test_result(ret == 0 && + write_iov.iov_len == sizeof(write_val), + "tpidr2_write\n"); + + /* ...then read them back */ + read_iov.iov_len = sizeof(read_val); + ret = ptrace(PTRACE_GETREGSET, child, NT_ARM_TLS, &read_iov); + + if (have_sme()) { + /* Should read back the written value */ + ksft_test_result(ret == 0 && + read_iov.iov_len >= sizeof(read_val) && + memcmp(read_val, write_val, + sizeof(read_val)) == 0, + "tpidr2_read\n"); + } else { + /* TPIDR2 should read as zero */ + ksft_test_result(ret == 0 && + read_iov.iov_len >= sizeof(read_val) && + read_val[0] == write_val[0] && + read_val[1] == 0, + "tpidr2_read\n"); + } + + /* Writing only TPIDR... */ + write_iov.iov_len = sizeof(uint64_t); + memcpy(write_val, read_val, sizeof(read_val)); + write_val[0] += 1; + ret = ptrace(PTRACE_SETREGSET, child, NT_ARM_TLS, &write_iov); + + if (ret == 0) { + /* ...should leave TPIDR2 untouched */ + read_iov.iov_len = sizeof(read_val); + ret = ptrace(PTRACE_GETREGSET, child, NT_ARM_TLS, + &read_iov); + + ksft_test_result(ret == 0 && + read_iov.iov_len >= sizeof(read_val) && + memcmp(read_val, write_val, + sizeof(read_val)) == 0, + "write_tpidr_only\n"); + } else { + ksft_test_result_fail("write_tpidr_only\n"); + } + } else { + ksft_test_result_skip("tpidr2_write\n"); + ksft_test_result_skip("tpidr2_read\n"); + ksft_test_result_skip("write_tpidr_only\n"); + } } static int do_child(void)