From patchwork Mon Aug 29 15:49:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958069 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 BC43BECAAD2 for ; Mon, 29 Aug 2022 15:50:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229566AbiH2Puk (ORCPT ); Mon, 29 Aug 2022 11:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbiH2Puk (ORCPT ); Mon, 29 Aug 2022 11:50:40 -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 5C48486041 for ; Mon, 29 Aug 2022 08:50:39 -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 EB567611D4 for ; Mon, 29 Aug 2022 15:50:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE09AC433D6; Mon, 29 Aug 2022 15:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661788238; bh=0SDRjlUj0I9V3lB4e8go1XrPWs95giQhpLEhoSJP9+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OjlJ8MnH1sjHn9+hKIrJsaQTZLtC7UrWhTopUN8I1wIpoL9soCTWNf5bXtD/dcBxH GhvhE1MwVCQBvj/AHYY9ojR7rWU3UVmeMMDD80lzezRV18Q00edElRweazcQF/0R0V l4Bp38ErK7ctWa9Lj23qZEPmXiMMVSmnKy8TvtLu8cf2cOQ+82MSu6h2zN1Yk1UB9f 42XBA9mvMdrg9ih4I8HGM1Ush52xxo6p51Qi4E2JO7edoDJvMy7KMEOgADzwUUCG/K OByS3Dv93QNPfRmH7vmgZhgl13KeAqrVdZQO9+0VDIB1AIkniLgNl9mazsCEeH3CLF AITlrpBfYqs/A== 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 v4 1/4] kselftest/arm64: Add test coverage for NT_ARM_TLS Date: Mon, 29 Aug 2022 16:49:18 +0100 Message-Id: <20220829154921.837871-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829154921.837871-1-broonie@kernel.org> References: <20220829154921.837871-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5050; i=broonie@kernel.org; h=from:subject; bh=0SDRjlUj0I9V3lB4e8go1XrPWs95giQhpLEhoSJP9+c=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDN/9nrKLY3N+9Hy5wGkFDa19ikgbLAommVjyLu9q LHimnBaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzf/QAKCRAk1otyXVSH0OR6B/ 9jld6RDjhY+ZGBNuf0smNcaydgAddBd+KCcegVSGGQPl0+9NCQUvBI3B/w7zqdo0q2WtWtkpODqgs4 AdkWk7I5Ysg0D2y3PX0KpME4bZ8Kp65Sx17mxZElhs9rsZlMT7t+GE1hXyE2AIFXaRVUdLoAZKjy1A TtDBfkSDPKyrNenWXvI7vsynjUM7iQwUcfaZEiNbwEjT/eazwfgnL6s0QJL4vMM4gegJvmJxhtm7wl R5nyXb+/2Df/nZvlFpbHlJBtgG7/jyLKU6KVDWT4p/XvephyHUyZtQDEqcv92K4OpQaINxPuNec6EG w2r0cNrJuV6dSqLGI1Qrv9j0jpmPOq 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..a74157dcc4fc --- /dev/null +++ b/tools/testing/selftests/arm64/abi/ptrace.c @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2022 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 Aug 29 15:49:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958070 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 7B80DECAAD5 for ; Mon, 29 Aug 2022 15:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229815AbiH2Puz (ORCPT ); Mon, 29 Aug 2022 11:50:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbiH2Puy (ORCPT ); Mon, 29 Aug 2022 11:50:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52CAA89922 for ; Mon, 29 Aug 2022 08:50: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 ams.source.kernel.org (Postfix) with ESMTPS id 061E0B81109 for ; Mon, 29 Aug 2022 15:50:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B22FC433C1; Mon, 29 Aug 2022 15:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661788250; bh=4SS1HhiCCSG9y1tYIhTUgiCAE3c544P3f86asq/gm0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WLN6EaqzhIik23Ovn7oYm5ym7YxKZjz+YRtjMvW1FKK3JBvHnRpjxV7IRyqv2ssev w4xMff3CKgLr1QymEFRRReW4zzKGNCYMI2U5GBsN3RvUll2hM8rV4Tl5Y4kaK16NRN 4tZM2DkW+qRl+QeLFlLx/v1Ro6pr4eYPWW4Eidyg8r2ndCR736GJzysoVdJUmWQAZ2 nP83y1yrtQZJqh0gi/mzEOsBnQs/juiNpl2emFhHlsRsXDcoBDVaribolkSQhTJFrQ kCuoyYWI+Nge/QcnL0a4iQS2puuBgday4l5FXvsGFDbDekjY0eagbHip+q+go1MkIz LxOS25ehUwFMg== 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 v4 2/4] arm64/ptrace: Document extension of NT_ARM_TLS to cover TPIDR2_EL0 Date: Mon, 29 Aug 2022 16:49:19 +0100 Message-Id: <20220829154921.837871-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829154921.837871-1-broonie@kernel.org> References: <20220829154921.837871-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1023; i=broonie@kernel.org; h=from:subject; bh=4SS1HhiCCSG9y1tYIhTUgiCAE3c544P3f86asq/gm0U=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDN/+G54LoL/yWs5q4ClkhlcssbMavyJEG2YIqqRj 7oMMUOKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzf/gAKCRAk1otyXVSH0PdaB/ 9wHEw8feBFk/t5VuOhnmODXTg+U9Xl+CXUtR2wbnNLcjXRyk2mDXsiqjsGDf1DUTv4x35H6XPCodYg cC5wSppufKLnTWBSWedRAoBaN1NP/X5Gn5Dw1hpFkgkWkDG83GO1n2NjpQNP84U7FzJXjreen3g1aO 98KpO62ipyzRBT0MzheD1ET3tb2Ern53eH6u1u2iJrXs7LfxiXuu799yKzdrUukoNdUE171mKeemIQ XiA+DZcBy3jYQEWrNySKkh4pfuJbgtxe2YWXUUQ3n5uW9lRld4cAD+K112Sw61IIdOyA4Zi9arPmUH 8ZcOepee1rgL3eBKLLOr2CuMnauQqM 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 Aug 29 15:49:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958071 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 2FA05ECAAD2 for ; Mon, 29 Aug 2022 15:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbiH2PvF (ORCPT ); Mon, 29 Aug 2022 11:51:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbiH2PvE (ORCPT ); Mon, 29 Aug 2022 11:51:04 -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 656AC8B2FE for ; Mon, 29 Aug 2022 08:51: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 dfw.source.kernel.org (Postfix) with ESMTPS id 65D2961045 for ; Mon, 29 Aug 2022 15:51:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49C17C4347C; Mon, 29 Aug 2022 15:50:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661788260; bh=gJAqGnSzNPHzgfUKu3akdS0hlaIcDTOFmkXW09ngPF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P4hqrmATWU8kBMFSfgKqiIu4fAz8tRElmKgABYZJSivtdeqVIuctiLPPY80bC11Qt GfpEoPFx4IxXCx3FCJcpJfHRjl0DBc4HmR6pZNqsVEW2iQffUOEoK3KRkY19+cO8BB hS3XZ5s/AoMfjN9A1KnvlLtCtKnVYB6HDVph03lXsLWUfz0LKuUg9rzNWA34NRXyUN bYoeEHtgdLlf5QwzgxU4QWQa2P+3wbluugc1VnX3VEMCttWvP+qaVAvsW76D0pET39 XheCZTgx9iQUU/A9DMqnLAiRw+Yq4qABQlzk0ZW9SrwwU9JGT+CKyzqCl+tE4olxe9 x6RgYlIUcIjdw== 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 v4 3/4] arm64/ptrace: Support access to TPIDR2_EL0 Date: Mon, 29 Aug 2022 16:49:20 +0100 Message-Id: <20220829154921.837871-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829154921.837871-1-broonie@kernel.org> References: <20220829154921.837871-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2582; i=broonie@kernel.org; h=from:subject; bh=gJAqGnSzNPHzgfUKu3akdS0hlaIcDTOFmkXW09ngPF0=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDN//jpOq9XhtCpO1DkpQmkKgvQqtHf6mMYVbUR1u hW3edBSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzf/wAKCRAk1otyXVSH0LN1B/ 472QY7+WHrjp4Ey82HmTM/nXPjzE3f7R/T1c8e7xaQYForswQjTQ7zK1HMQXKcpo9awwCVXKYvsKyO 3lGuRJD6UD5uw3mqKu+wNrPLKf3Z2RI5L+o1b00twy6+FsbmoBX5VGF3vsbWUAt/6xkNl1GFl9ilZ/ OVHgEUmt8rj0yfkZq5sUzxjUZQxKSCromDzKmsPa1QmiVlXLuIgHrJlDMr7pwussxo4Aeb8dK7gfy/ 0YoHGPRALb+FTXZJujtbd8rSANIXLJq+Z5Fs8wfDTn8Ta5x+jT1bmPvqrA4TOYS28nJq9SOSznSuW6 sm1R0nQYZUpC2qUe7DzdsYVHmuuY65 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 eb7c08dfb834..0e9764f73d61 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 Aug 29 15:49:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958072 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 17041ECAAD2 for ; Mon, 29 Aug 2022 15:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229625AbiH2Pvd (ORCPT ); Mon, 29 Aug 2022 11:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbiH2Pvc (ORCPT ); Mon, 29 Aug 2022 11:51:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32F3C8A6FA for ; Mon, 29 Aug 2022 08:51:31 -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 B3C38611C6 for ; Mon, 29 Aug 2022 15:51:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB809C433D6; Mon, 29 Aug 2022 15:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661788290; bh=5JvLo0UnJeyCZ1yxO1+Xnv5AbjhocOYtyL3ng59uNM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CIxfyRixFzSP4Ukr2U48e+cIQMszx0z6HA1ZpkORTNAhgf8Fjc3zkKTotstfMa7jC TYA6EWw8TYJ1kP7V523k0jDyvsE9937aaeof898PEl4naH+sCMkfIOWAeJ98e9atTY HhWdWBr9AklL3in/awMUYDdrHbYyi9jsmkn7J9BXT9gYEjb+hcQKBtD1NR89lsc7bh p+F1Onu/3yeoRqiYLMLjB1mnLkj4pj0p5CYp+khNbE7kFzj869A74k8LXcDLt79PjM KYpCs3jKrzKnpRgHyyRe77GmtqBRZUvEnigUc9xvvGjuQvEu0UP6mRnRd65GW8PhNE fgBKorBImPFdg== 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 v4 4/4] kselftest/arm64: Add coverage of TPIDR2_EL0 ptrace interface Date: Mon, 29 Aug 2022 16:49:21 +0100 Message-Id: <20220829154921.837871-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829154921.837871-1-broonie@kernel.org> References: <20220829154921.837871-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3913; i=broonie@kernel.org; h=from:subject; bh=5JvLo0UnJeyCZ1yxO1+Xnv5AbjhocOYtyL3ng59uNM8=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOAAB28b/VVGFj2CZ8OO+K9TBKMw+RoDC2fFs8kM irPZVW6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzgAAAKCRAk1otyXVSH0Mz0B/ 4r5JX6xz2NggAebmjtdpJ8fIalwxptGK5c+xWCVUu0KF2EUmvcGkWM659dLrIWPHvT+ttV3ysPnTp0 q6XLqd739g5orSIBJtZ9hnjDYVp6EpUtqCS9F4D0qb9/O5z+6O3h49uOMK17NWFOGT74swCL/8UWL4 zRpdLQME07BqU7TUTzh8Rocezgh80NGZgzUy9zmfz/V4u5bf/qmZ/UjgLUHQQ59K2r3p0FpmMe7WqC spF3A98qQvfQx41iRAbBMsIQlJgjP0g9u7eXmg+xvpXcItFnAPYJV0ILIkvI8LYQeejYKWCYHHVezY zI8GtET/pq5aDToqe3kCJr7/pnzWHY 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 a74157dcc4fc..be952511af22 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)