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_PASS,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 4A127C4338F for ; Tue, 17 Aug 2021 17:16:20 +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 0BAAE6054E for ; Tue, 17 Aug 2021 17:16:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0BAAE6054E 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=Epjql0oUB35J4wXhsBeE3Kusulrnm/K9HanRjMtyvGM=; b=wJj4ZjDyfFyQ3U yGwtuFH6cb92AFSZ0+rdo022Fb39cxmhNzp6s0Fl2gk7nMdvieZ7tgowUncqud8XD30w9ElR/j6+0 xU8k1wzrhnmP9qwSmG3UAoi5eyqJGu16iG6/7CrN6VOi8CXEuVdjZtVfbhN+0pV/2Uy+zrCj9aYIN 6T064mVUdWABkpVLfIE3zC3EW5TQv8BnkN7+ws0B9dNO+AKPwEBNXxXCZv0/WKBeEY6YqycrwWjIv WvuTPAhyAZkkbNQlSs+bxO/DT5seY5zrM/MxqJXgHxOFEa0a64JGhZbvAXbC2w4fac6ZbrxFIwsGp WYQRst+PgsP7YjA4Wtbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mG2fM-0037Y9-5V; Tue, 17 Aug 2021 17:14:20 +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 1mG2fH-0037XS-Iz for linux-arm-kernel@lists.infradead.org; Tue, 17 Aug 2021 17:14:16 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id BBD4F60FDA; Tue, 17 Aug 2021 17:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629220455; bh=W/w+LD41qPaQDdE8qBBT4pn7jm1A6seSBTRYSuRFcxw=; h=From:To:Cc:Subject:Date:From; b=AirRA08xSEYOhe+AiCVPa9afq4rWJJatVWo3hItgUah8RnAr/6paLKm0Arc9tNNse gnaJPbkGgTFQOX1zitkc6i+67X+J9sPa9Q5MjvJ3VfneaYrZ64gE9Z5qt7W42pV/Fb IHosFy9v1V8LUHVAj77zYdcGXsm1nqsKbLn36YNpTGxmHDwlNB3gjBnkLVB1I3SNHl GLzCGgXE2OQGD9xn6b3e/0e6teSgGxlDQAwuPc84AEzhbQ04HglaWBAHy0+9N3IafB HDjaVNMs1f9O7/htfR0LsrRhQTU6NgFRkZ9w78ZP+Qhcc5dlqZqKUNMhvJggkKQCAN 6GcAYqKCxuDuA== From: Mark Brown To: Will Deacon , Catalin Marinas Cc: linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH] arm64/sve: Better handle failure to allocate SVE register storage Date: Tue, 17 Aug 2021 18:13:30 +0100 Message-Id: <20210817171330.25847-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=2874; h=from:subject; bh=W/w+LD41qPaQDdE8qBBT4pn7jm1A6seSBTRYSuRFcxw=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBhG+wU4aaX4jZzKEKWVu07AP1UgMmz38SWvQPJmNVG 8SSNQaKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYRvsFAAKCRAk1otyXVSH0Nm8B/ 0SBOhtKjRjT/XFPpkT8PFYUp3ltD/93LtRBJzTpGnRu3vLA9dCZkFmwrCYTt3Hplx86fxr24nn1n2p MlxQ+/vj+6JPCQepMfMR7ZLhXHktLHna3opnxt+EiiDbzSNpZbSunT9IAA62+pev2vv/7ZXg/my6eH EfPKDtz+I2e0fxjyyyaEtOAvp4FUUzotPe8rXdo1qXGnGqG9KtyVzuTltBhzstEA350IQv9eILd4ek PnlGgv/kChsyq+ZiA1842SlHPbCWDFjAJV3xeonKiEj91wEEREyDgZjM8McJ/CTnqXUYddKF/yqxIj vdJOHIhfCEBGYrV99+KRDwxpxdRmJ/ 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-20210817_101415_700317_9E7EADC9 X-CRM114-Status: GOOD ( 19.21 ) 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 --- arch/arm64/kernel/fpsimd.c | 10 ++++------ arch/arm64/kernel/ptrace.c | 4 ++++ arch/arm64/kernel/signal.c | 3 +++ 3 files changed, 11 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..8bb3376b53fe 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -845,6 +845,10 @@ static int sve_set(struct task_struct *target, } sve_alloc(target); + if (!target->thread.sve_state) { + ret = -ENOMEM; + 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..34ea71ea6126 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -290,6 +290,9 @@ 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) + 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