Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp25640rdb; Mon, 15 Jan 2024 10:42:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQE6bxfXS+KlAPTDy8XfyWugstaG3NhHLMymTpkR/OlPHCKT+idPdUdtF6fcgXGKbza5be X-Received: by 2002:ad4:5dca:0:b0:681:6b48:a86a with SMTP id m10-20020ad45dca000000b006816b48a86amr18697qvh.25.1705344169806; Mon, 15 Jan 2024 10:42:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705344169; cv=none; d=google.com; s=arc-20160816; b=Gl0tbAlMFmF+nUL2g0oJ+r034IEBh8oxS5PTPii78892qex9roLu1CLD2LxVD7N1eN x9s7GfxHPZez+QKR/KTp4dojXl2pE7qa90MGKOZp8PxBr02GzBR/A93maoi1/AyZiheS e5A6UE7nEK/jZ7ysi1tgcKMKUyN3YSd0eoSYyJPiA+RQ8BktC5n3xQKEnNPhZBkMCm+6 o0gOHfeDZUrZOkDCsX7mZp2IUo5kLeVLZ43IpOIMQElcyMTnoCt5hUWgL4+ZSGc/IL6J KrCjr+85qg8Fc+Whc65WGtv4zEvbfWTMGA7tKOkBOG29o+SC6hepiMcdutLVcLKReeol lCcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=idXgq5dWE/3NsMysvkBookYY/NbGwvCQhZLB7ZW57Ok=; fh=RAOu09mszhXETLx15DjXQltpO3+GVKM6aI+ur1hpljM=; b=I4fu9K6cBWvC6pj5Rvn5AByIfv4Ct5C1iIEJ+yK2NOOtIJNuoV2y7X6Sofa8rxZIFJ febFlZ9STU2cS8ZbdxGPNJKbhatZ3VMkJ3KhoAGhjAZCg+V+6FPxiHSfhH0LK7b0Dpe6 12UEd4ZNXkc0IH3znab+SB58ekZLh7OF2XKXRlb+YptK0FSinVYqRoHSOBCMx26uVrZW uoEDNBKaU3nTPNjyhgal5O2t1HTTcYyw4mswzkKjYLn8vW9aSH8FwzsbQGxOiol5L9yR k1vh3sk2DOBWsdvTu3PVf61yxczYiQeYw1DxgP/d8fcXFHV+lCwbdUnpiyzsgXXrSxdu CgJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g0v+juD4; spf=pass (google.com: domain of linux-kernel+bounces-26407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o15-20020a0c8c4f000000b0067f99bbc781si8816253qvb.109.2024.01.15.10.42.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 10:42:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g0v+juD4; spf=pass (google.com: domain of linux-kernel+bounces-26407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8961F1C21FA1 for ; Mon, 15 Jan 2024 18:42:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B53BF18AE8; Mon, 15 Jan 2024 18:42:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g0v+juD4" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E76CE18646 for ; Mon, 15 Jan 2024 18:42:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EBD9C433C7; Mon, 15 Jan 2024 18:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705344162; bh=0e9tVn+FNGLr7RXH+YBjqOTRWHfqCyuIDty9nT2Bl60=; h=From:Date:Subject:To:Cc:From; b=g0v+juD4ISQdgkUQajGj2XCROOqOnR/D2whSJF2Vd6PDbiSW/TlS0LDy7T1CaY1Q9 HGNqBw43eG3DWBUJjGdseR5E6X4BOuJlGREvNztVLl5zpl2QSi59SXyziI6gsIKaIa 4Los9dHGdX7ocyxr+LA092EtuQg9aEnWQdMvao+DaYJXP8vRkWhTjCfJiUvG0d2BVj CtH6f15gLETgV5mc/cIUGPcixTuU4rfNTtgWKGhBWDJqkYb/39ymSRCcYFgVHVmi0t nmNjiWQZxx6jTWuykpWe4/Aww6xjlVb/8ACx3kmSjiaIGBoepT8kJXxV0WCgOv9c4f X0U/im7fQuucw== From: Mark Brown Date: Mon, 15 Jan 2024 18:42:38 +0000 Subject: [PATCH] arm64/ptrace: Don't flush ZA/ZT storage when writing ZA via ptrace Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240115-arm64-fix-ptrace-za-zt-v1-1-48617517028a@kernel.org> X-B4-Tracking: v=1; b=H4sIAJ18pWUC/x2MMQqAMAwAvyKZDbSldvAr4hA01QxqSUVE6d8tj gd390JmFc7QNy8oX5Ll2CvYtoFppX1hlLkyOOO8saZD0i14jHJjOpUmxofwObGLwVOwcQ7WQY2 TcnX+8TCW8gHB9a9SaAAAAA== To: Oleg Nesterov , Catalin Marinas , Will Deacon Cc: Dave Martin , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-5c066 X-Developer-Signature: v=1; a=openpgp-sha256; l=1637; i=broonie@kernel.org; h=from:subject:message-id; bh=0e9tVn+FNGLr7RXH+YBjqOTRWHfqCyuIDty9nT2Bl60=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlpXygOHcQfoBfSOoQVEOrxzFQdYkeOWc3cp8j/aXr 0O/ZlimJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZaV8oAAKCRAk1otyXVSH0FP+B/ 9Il7QHh2iaP+xU3Vz6qvGOneH3frjzkoSsXoVw71qDmN5VAOsQQ2VgeKBLR/XA9u4tTL7E0ikOvK/r 5K38Nc0Lyk/8f5g5cgd9ogBWnSCqoPKqELdwGbZDU1UpYELQe7UbmXvpLnqfw3af/9uEnXwZpjW7Rv kzGwjzrOwwD4Kup9OVzm1VWIWHbg4XgqQxWVA5LqGaiswQyt2jphqojlnhYIubHCiyUntNYhC4wtAU vAIzvdpbiJbKVlOS4pu5Db0TCZgDAl/IocDarXm2e30mPVK8oUMnTJrbam3CE9vkzIFLeTo6b50ElP uJXnX3cD932BWbQY6SH7YJE97MffOB X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB When writing ZA we currently unconditionally flush the buffer used to store it as part of ensuring that it is allocated. Since this buffer is shared with ZT0 this means that a write to ZA when PSTATE.ZA is already set will corrupt the value of ZT0 on a SME2 system. Fix this by only flushing the backing storage if PSTATE.ZA was not previously set. This will mean that short or failed writes may leave stale data in the buffer, this seems as correct as our current behaviour and unlikely to be something that userspace will rely on. Fixes: f90b529bcbe5 ("arm64/sme: Implement ZT0 ptrace support") Signed-off-by: Mark Brown --- arch/arm64/kernel/ptrace.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 20d7ef82de90..b3f64144b5cd 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -1107,12 +1107,13 @@ static int za_set(struct task_struct *target, } } - /* Allocate/reinit ZA storage */ - sme_alloc(target, true); - if (!target->thread.sme_state) { - ret = -ENOMEM; - goto out; - } + /* + * Only flush the storage if PSTATE.ZA was not already set, + * otherwise preserve any existing data. + */ + sme_alloc(target, !thread_za_enabled(&target->thread)); + if (!target->thread.sme_state) + return -ENOMEM; /* If there is no data then disable ZA */ if (!count) { --- base-commit: 0dd3ee31125508cd67f7e7172247f05b7fd1753a change-id: 20240105-arm64-fix-ptrace-za-zt-5f64a61fd612 Best regards, -- Mark Brown