Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14616C4338F for ; Tue, 24 Aug 2021 15:38:09 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D422961151 for ; Tue, 24 Aug 2021 15:38:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D422961151 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:MIME-Version:Message-Id:Date:Subject:Cc :To: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=HGg63OkYE/2tPWuKH5d2gGwo7MuLAYPMuC+GrAcYKtw=; b=jOdgIhQa4m8/lz Xc29EKlCugFETJL/H1E+kiISdKKrYI9ScROmR+hhcv2ZkQUgh0H2delRupbwNAo8HpoiXNulIN63o FCVyYPyMwX1z58+mUN9qdJbNcbAAWva30hjMVSTE7MX1r0Z2tZNgut4T/1HRCtaEeIKjA2JlDmSxX +MoUngB8aR0fyjl1XO6th6YZoEw+bY3QXbiZhbM7XdOlWqO5qYzR+kl3sS/fQBN13P1JoZImqK3x7 dJ0j53kgQ4Hk81nyLqrdCL21JsQezxj1EncADrUoOboGnfGoes+LDChi10Ma4DKSVzJu307pSdeBf /cmIDzWxAPDCg12NrZLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIYSz-003keK-Jg; Tue, 24 Aug 2021 15:35:57 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIYSs-003kca-Ko for linux-arm-kernel@lists.infradead.org; Tue, 24 Aug 2021 15:35:55 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8E0A961357; Tue, 24 Aug 2021 15:35:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629819350; bh=JnEDVM2E1dJJENKARHp3UdyNVA6plYdg8282Vsa4N30=; h=From:To:Cc:Subject:Date:From; b=Hjse23hQp0PP4E18du+U8RL4r7DCiAg2bMMJyQbJmPcLcvickgPKXC+FfHkzt4Q3c ECjJmY4cx4z0LWWOWzbO7jjprCvyiOdw0ntxf5y+sEPNxwdmzkm+buqFPVJKskDQ9D 2ItA/vlT7w+M0eGIEFqaMVNXk7djQRHpt624R/e0iN/KmOhRAxsdzwtYuhn2a01TZm zDjpQY2EXUqNZ1ydZ/r1/AQY+Ny4tp2RnvvDskvmOyOV6uTOx/yixaxRU2qS2K9gQ4 G9MbKDtEKSGci5+n91jezo32qgqhqpGJO4c8sGVKP/86y7Z8ZEX7ylerlqFThvEJ9m HhivhrxuiDzFA== From: Mark Brown To: Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v2] arm64/sve: Better handle failure to allocate SVE register storage Date: Tue, 24 Aug 2021 16:34:17 +0100 Message-Id: <20210824153417.18371-1-broonie@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3087; h=from:subject; bh=JnEDVM2E1dJJENKARHp3UdyNVA6plYdg8282Vsa4N30=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBhJRBbEMPg3Z5U4KQTgHgB6qQdO09BvFC7XKBz7EQg r6Z2M2GJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYSUQWwAKCRAk1otyXVSH0MkiB/ 4v6Za4cbX5qbNEAAjgpB1ZkPYLwceZiCZ4z7S8Dozv4HrRIYtHX2ckNZsqrqHkbgLheqZQc4R18cul e25XGzgoZvTZQQkHpnSiGyQ7H0ozAPlcthb3p1yYC+g5n7Cd2cbucuZcv1Eq3457/Q6sL+J4aHi9/Q f4Zj2gr/1kFh7P1W8Z6yW9iF2/X6LUuPSuEvetQ+EoBzqS7Gags5VTWYEUjP2+/UxukehJuCUMGX0K al152Vv3BskkbCTsK1H1E2TVOAlSTXHGPMnP38hQbnwbK9/eG5NqKGPjgzX9mcJIbbA0bfLrzAPpYb vvGYSz5IjdkCOzMI7i7/9aaeBV7Eh5 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-20210824_083550_775377_6A24F4FF X-CRM114-Status: GOOD ( 18.96 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently we "handle" failure to allocate the SVE register storage by doing a BUG_ON() and hoping for the best. This is obviously not great and the memory allocation failure will already be loud enough without the BUG_ON(). As the comment says it is a corner case but let's try to do a bit better, remove the BUG_ON() and add code to handle the failure in the callers. For the ptrace and signal code we can return -ENOMEM gracefully however we have no real error reporting path available to us for the SVE access trap so instead generate a SIGKILL if the allocation fails there. This at least means that we won't try to soldier on and end up trying to access the nonexistant state and while it's obviously not ideal for userspace SIGKILL doesn't allow any handling so minimises the ABI impact, making it easier to improve the interface later if we come up with a better idea. Signed-off-by: Mark Brown --- v2: On signal handling and ptrace allocation failures clear TIF_SVE so we don't later attempt to use the sve_state. arch/arm64/kernel/fpsimd.c | 10 ++++------ arch/arm64/kernel/ptrace.c | 5 +++++ arch/arm64/kernel/signal.c | 5 +++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index eb8d972ad3d2..5a294f20e9de 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -520,12 +520,6 @@ void sve_alloc(struct task_struct *task) /* This is a small allocation (maximum ~8KB) and Should Not Fail. */ task->thread.sve_state = kzalloc(sve_state_size(task), GFP_KERNEL); - - /* - * If future SVE revisions can have larger vectors though, - * this may cease to be true: - */ - BUG_ON(!task->thread.sve_state); } @@ -945,6 +939,10 @@ void do_sve_acc(unsigned int esr, struct pt_regs *regs) } sve_alloc(current); + if (!current->thread.sve_state) { + force_sig(SIGKILL); + return; + } get_cpu_fpsimd_context(); diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index b381a1ee9ea7..e26196a33cf4 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -845,6 +845,11 @@ static int sve_set(struct task_struct *target, } sve_alloc(target); + if (!target->thread.sve_state) { + ret = -ENOMEM; + clear_tsk_thread_flag(target, TIF_SVE); + goto out; + } /* * Ensure target->thread.sve_state is up to date with target's diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index aa46168bff32..298be5865dc4 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -290,6 +290,11 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user) /* From now, fpsimd_thread_switch() won't touch thread.sve_state */ sve_alloc(current); + if (!current->thread.sve_state) { + clear_thread_flag(TIF_SVE); + return -ENOMEM; + } + err = __copy_from_user(current->thread.sve_state, (char __user const *)user->sve + SVE_SIG_REGS_OFFSET, -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel