From patchwork Thu Jun 22 13:39:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13289164 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 DCA46EB64D8 for ; Thu, 22 Jun 2023 13:40:29 +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:In-Reply-To:References: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: List-Owner; bh=h1j7dutURxQJpoWsEaij8HZzrYgG46+YFnHYm7TyGFY=; b=CeMjnw0UfZ74P9 lS5avGSjFIrKh1MTKI+dwBZqhs55rDIMpV9eQL96KBCifH4fNbCYYlPK0wBKZKHMzjvbn8wZ6utVM I6TACeTucNRzc2KUklAGK4sTPhDdzbP1duaCwD/IylEizNX35HdPTRpeLHcC6hvLPpjY1T/1vsR9p 9MPUMg+iY88w/9yHI+s4pNbpiuysEWjpI002b7k8qHwqoQTfkccIUi4Z94q2udWPVtNK8Jsy6EVUM Vndnqco4NItLSF054G9L8tBtKLknBvR4AvoIRKV++Us83favamGdNSTCdBcwsogeQgFoara8HzbQL 8bEqlDH6m7G7LRqx8qqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qCKXe-000oZC-2R; Thu, 22 Jun 2023 13:40:06 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qCKXb-000oXv-38 for linux-arm-kernel@lists.infradead.org; Thu, 22 Jun 2023 13:40:05 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4E70761831; Thu, 22 Jun 2023 13:40:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0A17C433CC; Thu, 22 Jun 2023 13:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687441202; bh=w8fxWAGiQaBMUkDFhDb0uejIT4OUWJBakDRMQaptQUc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iICu2phPR5ILZG7JI+68q0+Ns20bNqyrhvhMml5d1wdZUjJIv++BCVrkuNLIDBWdt Kd20yWMwj+Dga0597jCavM6zRC4YX2QQBwy7sJsOBxGH4Sn6RLqwHv/b1evHSWIwQr Vvzl7D0C9M/k+2WEDmAG4EtSyLHUnnFIr1IQegTJXtK9mZ82SNPw5THJH9/FMAgQXH WGXWTaqIbQ8tG4UF5qObRfLwG4RRRxci7Pdvxiii/6Is5GNiD2mEomUesEHkn7QEnI I9L4amYoZMYfzQRlZECyjtWYCRe/wp1ZgqrWgAuqrTU/9BbRgBPt6zi9ZzPJT+owK1 oVn511dFpR3nQ== From: Mark Brown Date: Thu, 22 Jun 2023 14:39:45 +0100 Subject: [PATCH v2 1/2] arm64/signal: Restore TPIDR2 register rather than memory state MIME-Version: 1.0 Message-Id: <20230621-arm64-fix-tpidr2-signal-restore-v2-1-c8e8fcc10302@kernel.org> References: <20230621-arm64-fix-tpidr2-signal-restore-v2-0-c8e8fcc10302@kernel.org> In-Reply-To: <20230621-arm64-fix-tpidr2-signal-restore-v2-0-c8e8fcc10302@kernel.org> To: Catalin Marinas , Will Deacon , Shuah Khan , Szabolcs Nagy Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown , stable@vger.kernel.org X-Mailer: b4 0.13-dev-c6835 X-Developer-Signature: v=1; a=openpgp-sha256; l=1250; i=broonie@kernel.org; h=from:subject:message-id; bh=w8fxWAGiQaBMUkDFhDb0uejIT4OUWJBakDRMQaptQUc=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBklE8nsYvELF3WpfKfmByc+fGAeLNPcr9NAY5/8CsN LVvdDDuJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZJRPJwAKCRAk1otyXVSH0KBhB/ 473Gq3ZQ6893sd0piLda7UZJYhhBVNu0fwedBuDBuNgvNMdK0H3wXVUYvCW9jNcR15aSIZS/pq7kU3 8URMlQX/Z3hg3mls6Rq4kAmBU26Z/ZaX1P9Q1mcVp+MWL/W6xzcN27KBFS+5nIWPX6tgpLMmVAMnep Sypvldcx/pJRVAfX5wnHWPfQ35s2NEPO+mfTDSsOh5lvsOq3KJ0KISzk3k1R6X7MCbXB6ZxVoKl7sg EzoiSrSssf+NLXLIom2bKAeEnYVN+aO+T9bF0MKAPteCBs9Am8fNNY4VBsqaD40r3LNfdl3yO2byUn Ugs8AZ/DZYuXXkxiMZmhsbq+06e+oe 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-20230622_064004_049303_596A91D4 X-CRM114-Status: GOOD ( 16.12 ) 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 Currently when restoring the TPIDR2 signal context we set the new value from the signal frame in the thread data structure but not the register, following the pattern for the rest of the data we are restoring. This does not work in the case of TPIDR2, the register always has the value for the current task. This means that either we return to userspace and ignore the new value or we context switch and save the register value on top of the newly restored value. Load the value from the signal context into the register instead. Fixes: 39e54499280f ("arm64/signal: Include TPIDR2 in the signal context") Signed-off-by: Mark Brown Cc: stable@vger.kernel.org --- arch/arm64/kernel/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 2cfc810d0a5b..10b407672c42 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -398,7 +398,7 @@ static int restore_tpidr2_context(struct user_ctxs *user) __get_user_error(tpidr2_el0, &user->tpidr2->tpidr2, err); if (!err) - current->thread.tpidr2_el0 = tpidr2_el0; + write_sysreg_s(tpidr2_el0, SYS_TPIDR2_EL0); return err; } From patchwork Thu Jun 22 13:39:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13289165 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 3CBEEEB64DB for ; Thu, 22 Jun 2023 13:40:40 +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:In-Reply-To:References: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: List-Owner; bh=hLIcJ3QjW4MEZVLCazk1MEazR2YCKxwuKz9NBMsi1fE=; b=jYBsp1wr946iuy CiPWjBEKx1Rrw8cAwZpLu7PIZUIsmsIhcDciYJR/bS2/g84nZvHWGKYawv6d7F7S3QTSxWaUPG9N6 sDe7O1OjsWOmd1D67d9QkK4FZ3hgyKsj0Ujpg8udrKaD86yPCwMidcPj/ox9gLrczP+XY4q9b9K2e icOeEp5zyRwadJ5Icp8uksRLdYIoXDDKch3IJ2T+zPJZ/dT4NqGV2Uvxw7IZl5cQARGyEC/ayXF31 26QGhgt8kojGrtX9/7MCfq4y9WHz/9XUiDiZaNd4aBiH3Ocu7UtcWoKEZ3iOu95U7qgArZezwxQUO CjnET11wtq4JmesvuRPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qCKXl-000obv-2a; Thu, 22 Jun 2023 13:40:13 +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 1qCKXd-000oYX-2U for linux-arm-kernel@lists.infradead.org; Thu, 22 Jun 2023 13:40:07 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 35ADB6182F; Thu, 22 Jun 2023 13:40:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E12FC433C0; Thu, 22 Jun 2023 13:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687441204; bh=I4NWuVbplK94yptwpSk7z+1nz1dxISccSIH9QFqpMIc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Jlg6cuqOpeQ72dq2z3kl6mrX5yOFq7owxNRCUa2c/INC4MKicRqW//hAPFQlZE/yl K4C0Y5aN0wU6UB8SAzcujpJ1WQdLQjjwxcoy51+tYHHQJ1dJEJQKKkUjfnP9jx9m/B s6D61/rnyezlgaX3nPLCXB6bCtY1nqYn7YRu0nwOzbmPnG3Ww/Ix+WU3M5VmUDU/8x QfZv3o+CtwyDuHJ4zi47v2WKIeD+xQc0vsjq2IqXJ2u48RYIylw6OP0OYlgo4dudco UPOAoAqWNYqTZ6Qg2CDyyccNVFuIKthWTVSOEV00vAytSSGVV4WzjpAc6XxR8ocTD9 LLsXGbysZS1Bw== From: Mark Brown Date: Thu, 22 Jun 2023 14:39:46 +0100 Subject: [PATCH v2 2/2] kselftest/arm64: Add a test case for TPIDR2 restore MIME-Version: 1.0 Message-Id: <20230621-arm64-fix-tpidr2-signal-restore-v2-2-c8e8fcc10302@kernel.org> References: <20230621-arm64-fix-tpidr2-signal-restore-v2-0-c8e8fcc10302@kernel.org> In-Reply-To: <20230621-arm64-fix-tpidr2-signal-restore-v2-0-c8e8fcc10302@kernel.org> To: Catalin Marinas , Will Deacon , Shuah Khan , Szabolcs Nagy Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-c6835 X-Developer-Signature: v=1; a=openpgp-sha256; l=3094; i=broonie@kernel.org; h=from:subject:message-id; bh=I4NWuVbplK94yptwpSk7z+1nz1dxISccSIH9QFqpMIc=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBklE8oAzJLhyfqqFXIZ6KSC5CDDs//cJNa/u71raaB GcEjEVCJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZJRPKAAKCRAk1otyXVSH0PZkB/ 9DJ0hlTEAW0a9O7uSlCy0E+iH7b41edp7KAkTbTWJ2lxc5XlBOrAD2gVWVMDsjDC6kWNOq1ClqKawt GZd4ZbPEKBmsxvf2BUSQLqVYDhcznqvFnI7JDmIAPEgN+EqC/60Vc9QcxZKIzWqZZ+/wWk9kAmhhqO +VW+jEy6PN6mJ4rUV+tqd9PU/WmfBsKWMtDA8grIH350qt7FW1fA/wo94bSXwDl2U4+oXB85j3T/ZS S25BFB/M5+jsjemNMnbKuUlkNWzad8uXWnTwVkXt3P0Ts5QgKAEWEv6UH92LyCCogaVpQ9h1mZYGVJ PfNTnmniWi7TlrTYt/gUIrF9VyYZ9R 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-20230622_064005_893555_0B73A6BE X-CRM114-Status: GOOD ( 18.06 ) 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 Due to the fact that TPIDR2 is intended to be managed by libc we don't currently test modifying it via the signal context since that might disrupt libc's usage of it and cause instability. We can however test the opposite case with less risk, modifying TPIDR2 in a signal handler and making sure that the original value is restored after returning from the signal handler. Add a test which does this. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/.gitignore | 2 +- .../arm64/signal/testcases/tpidr2_restore.c | 86 ++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/signal/.gitignore b/tools/testing/selftests/arm64/signal/.gitignore index 8ab4c86837fd..839e3a252629 100644 --- a/tools/testing/selftests/arm64/signal/.gitignore +++ b/tools/testing/selftests/arm64/signal/.gitignore @@ -4,7 +4,7 @@ fake_sigreturn_* sme_* ssve_* sve_* -tpidr2_siginfo +tpidr2_* za_* zt_* !*.[ch] diff --git a/tools/testing/selftests/arm64/signal/testcases/tpidr2_restore.c b/tools/testing/selftests/arm64/signal/testcases/tpidr2_restore.c new file mode 100644 index 000000000000..f9a86c00c28c --- /dev/null +++ b/tools/testing/selftests/arm64/signal/testcases/tpidr2_restore.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023 ARM Limited + * + * Verify that the TPIDR2 register context in signal frames is restored. + */ + +#include +#include +#include +#include +#include +#include + +#include "test_signals_utils.h" +#include "testcases.h" + +#define SYS_TPIDR2 "S3_3_C13_C0_5" + +static uint64_t get_tpidr2(void) +{ + uint64_t val; + + asm volatile ( + "mrs %0, " SYS_TPIDR2 "\n" + : "=r"(val) + : + : "cc"); + + return val; +} + +static void set_tpidr2(uint64_t val) +{ + asm volatile ( + "msr " SYS_TPIDR2 ", %0\n" + : + : "r"(val) + : "cc"); +} + + +static uint64_t initial_tpidr2; + +static bool save_tpidr2(struct tdescr *td) +{ + initial_tpidr2 = get_tpidr2(); + fprintf(stderr, "Initial TPIDR2: %lx\n", initial_tpidr2); + + return true; +} + +static int modify_tpidr2(struct tdescr *td, siginfo_t *si, ucontext_t *uc) +{ + uint64_t my_tpidr2 = get_tpidr2(); + + my_tpidr2++; + fprintf(stderr, "Setting TPIDR2 to %lx\n", my_tpidr2); + set_tpidr2(my_tpidr2); + + return 0; +} + +static void check_tpidr2(struct tdescr *td) +{ + uint64_t tpidr2 = get_tpidr2(); + + td->pass = tpidr2 == initial_tpidr2; + + if (td->pass) + fprintf(stderr, "TPIDR2 restored\n"); + else + fprintf(stderr, "TPIDR2 was %lx but is now %lx\n", + initial_tpidr2, tpidr2); +} + +struct tdescr tde = { + .name = "TPIDR2 restore", + .descr = "Validate that TPIDR2 is restored from the sigframe", + .feats_required = FEAT_SME, + .timeout = 3, + .sig_trig = SIGUSR1, + .init = save_tpidr2, + .run = modify_tpidr2, + .check_result = check_tpidr2, +};