From patchwork Mon Apr 17 19:29:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13214480 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DAF0AC77B72 for ; Mon, 17 Apr 2023 19:30:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id:MIME-Version:Subject: Date:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=hJXhHklqY2wSKBcSBYbw7B5goxXE5k9GIiAkPCFH8Po=; b=E7/vy+gZ47iv+/ GjUq1KJV8Sfg5Cbj3GEeZOsRJNa5wPMGg2oUQH/yQeMnMyU7cxHejV7LZiS4p9BckLvotzpSCaV5B SJwx8VG7myLnWOftOhl3WDUkSZWzOqd6GWY2uCbd0vRZr/prOEDfNx5H7TzheBuPmC9/AyNwtcWra limyDgkA/CeYA2FDfD26boX5uypAKDGB5ewtN3rhVe/XT5Lg2Bs195/Do4+tQ2HsGjh1XlJ9WnUfO mdKhvjKiTytBou7vOb/cVvF1mtjHN+2YFWGZkH35J4KG1EVm/x9xiBd/PPAA0cI/gjaZTt4kByugU I/6T8+U3UPQfgbpU3kWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1poUXt-00HQjZ-1d; Mon, 17 Apr 2023 19:29:49 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1poUXq-00HQiu-2W for linux-arm-kernel@lists.infradead.org; Mon, 17 Apr 2023 19:29:48 +0000 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 5A58A62999; Mon, 17 Apr 2023 19:29:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43914C433EF; Mon, 17 Apr 2023 19:29:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681759785; bh=3xwZsN/3MlqqwkkFE5f4fTjJksFnJsuRxCEAeDUAhYM=; h=From:Date:Subject:To:Cc:From; b=fN0NnXzXwyXuLNwyYppiUMamCPyukTdJCmYcjPoctKBCsZxus0mhBHxJElJbJVRmY uo1PlBTr2mSX5F1aGmuaNy5IZFYNtSxTJd4Z/LiEdYBENADl1mTQuB/A/+TMnpYMDr dyfAVbj2ASAB6O250OSJZ71HWqiXg2VbR0YuTTN3AYhY2gl2micwXplNzMEsFd9+Wo id2azw0EXSzOhyCuUX+dSGcCtdyUEyWSOHTa/UbrczJgVlyc9Ysh8mlzUyB+CE2MVm tyN3MiUqmtlTI4zldx95Sc1tfQVLOpx14i64KYVl8YzvjtypUJkcR4ElVEm4TdEfgm v3IVdS/vU1lcw== From: Mark Brown Date: Mon, 17 Apr 2023 20:29:33 +0100 Subject: [PATCH] kselftest/arm64: Add a smoke test for ptracing hardware break/watch points MIME-Version: 1.0 Message-Id: <20230414-arm64-test-hw-breakpoint-v1-1-14162c8e5b31@kernel.org> X-B4-Tracking: v=1; b=H4sIAByePWQC/x2NwQqDMBBEf0X23IUYgy39ldJDTDfNIk1kN2hB/ PfGHt8Mb2YHJWFSuHc7CK2sXHKD/tJBSD6/CfnVGKyxg3G9Qy+f0WElrZg2nIT8vBTOFW9DJGP jaK4xQNMnr9R6n0M6B7Yi8xkvQpG//8fH8zh+wmbkfIEAAAA= To: Catalin Marinas , Will Deacon , Shuah Khan Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-00303 X-Developer-Signature: v=1; a=openpgp-sha256; l=2603; i=broonie@kernel.org; h=from:subject:message-id; bh=3xwZsN/3MlqqwkkFE5f4fTjJksFnJsuRxCEAeDUAhYM=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkPZ4nxut0+zmSbsQh5bqITSVW9fLv3TMuBFadBqGv pVCj0eaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZD2eJwAKCRAk1otyXVSH0PjfB/ 9YiQE1Lh1iWFaQgMlaMBF5PLMkEMHnGrtLYA12JFq9L6ooZjbx/MiCL59+oP/vmuWq/+DOJvwWBzV5 ndmc0+u8D+2CGWuY4WKwrMM4eyXfwBo3gWW676IV9t1Py8E6zLkoHcJ9dLdPwugRYnDVRsAvT8S81N 7h86yIiykMH/xgN8QkznptXcvC68pyh5PJT7gqIPygOvknEJPtaoFkSFCuHfygNn+rFGpUnjIBcUCz 1maVloReU9PKGUFqzSRfcYCrXAkJ2M0KUZlZF/FQRpMRPiZt5jP3Dogox1iF/T+UmEQZvvDCBOT+9Y yv9guM9QxN+IQ9ucpIGbENnjPt1HK8 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230417_122946_897394_644E89FC X-CRM114-Status: GOOD ( 19.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There was a report that the hardware breakpoints and watch points weren't reporting the debug architecture version as expected, they were reporting a version of 0 which is not defined in the architecture. This happens when running in a KVM guest if the host has a debug architecture version not supported by KVM, it in turn confuses GDB which rejects any debug architecture version it does not know about. Add a test that covers that situation and while we're at it reports the debug architecture version and number of slots available to aid with figuring out problems that may arise. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/abi/ptrace.c | 32 +++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) --- base-commit: e8d018dd0257f744ca50a729e3d042cf2ec9da65 change-id: 20230414-arm64-test-hw-breakpoint-83fe02f607fc Best regards, diff --git a/tools/testing/selftests/arm64/abi/ptrace.c b/tools/testing/selftests/arm64/abi/ptrace.c index be952511af22..abe4d58d731d 100644 --- a/tools/testing/selftests/arm64/abi/ptrace.c +++ b/tools/testing/selftests/arm64/abi/ptrace.c @@ -20,7 +20,7 @@ #include "../../kselftest.h" -#define EXPECTED_TESTS 7 +#define EXPECTED_TESTS 11 #define MAX_TPIDRS 2 @@ -132,6 +132,34 @@ static void test_tpidr(pid_t child) } } +static void test_hw_debug(pid_t child, int type, const char *type_name) +{ + struct user_hwdebug_state state; + struct iovec iov; + int slots, arch, ret; + + iov.iov_len = sizeof(state); + iov.iov_base = &state; + + /* Should be able to read the values */ + ret = ptrace(PTRACE_GETREGSET, child, type, &iov); + ksft_test_result(ret == 0, "read_%s\n", type_name); + + if (ret == 0) { + /* Low 8 bits is the number of slots, next 4 bits the arch */ + slots = state.dbg_info & 0xff; + arch = (state.dbg_info >> 8) & 0xf; + + ksft_print_msg("%s version %d with %d slots\n", type_name, + arch, slots); + + /* Zero is not currently architecturally valid */ + ksft_test_result(arch, "%s_arch_set\n", type_name); + } else { + ksft_test_result_skip("%s_arch_set\n"); + } +} + static int do_child(void) { if (ptrace(PTRACE_TRACEME, -1, NULL, NULL)) @@ -207,6 +235,8 @@ static int do_parent(pid_t child) ksft_print_msg("Parent is %d, child is %d\n", getpid(), child); test_tpidr(child); + test_hw_debug(child, NT_ARM_HW_WATCH, "NT_ARM_HW_WATCH"); + test_hw_debug(child, NT_ARM_HW_BREAK, "NT_ARM_HW_BREAK"); ret = EXIT_SUCCESS;