From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 BB739367B65; Sat, 12 Sep 2026 19:58:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789243087; cv=none; b=Tsg12HgWPUmwU+0rzbzuUxe1JCI0Z7oTKLsF/I5NvHiLvZoBaKJcoO09xKIzRe576CV02YnMx2vcrSs2yXxfP7dRO9p3POFEpcdf9sEMV65hqg1HTnHWzaDXywDUkcCYQLz3kc2lzfU7pEaph1nUtc21S2h7SC9UfFERv2MBmK0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789243087; c=relaxed/simple; bh=RQ3PoxuvBxvmW6YFqUMTzGI5fGAg8acPEPgFyrLKZus=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PI6af96sfQST4T1PaKwssAPRCD+p7N7t/h5OUkl0XOC7S9V2smyKIGhCyWNuDtqnqrcU3VxnYG+52Q+ZP0k/YT9gcwYnx0mkrgaAYPtQL5dAb/NsSY21cwbA4bchvNnby6083jsfcgBvaQ7AbbEoj+zR3EqQM+ohkzHgXDsFu28= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=KUrnXJvt; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="KUrnXJvt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0842D1F000FF; Sat, 12 Sep 2026 19:58:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789243086; bh=rD2RKCtoZqTV8K4PR2V4JGcfgA4lHMqZXUpfGRbUfgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KUrnXJvtTk1y2CR1yt2W7celW7aYH5XVZakQatjLdyoLP+sxdl2987VoTHFHZ7+WO dv7oyAmdZLRch7DRUa0j6Jbt4knoTYYv2TsrzWdi7pq4yOZsvMR658cFkm8fPcSCbL 1KN9qLEL2y113F1HsHj7bRL568sOp0/e7Ohi4mGE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mathieu Poirier , Arnaud Pouliquen , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.10 605/798] remoteproc: Introduce function rproc_detach() Date: Sat, 12 Sep 2026 09:03:53 +0200 Message-ID: <20260912065530.993099890@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065516.948645775@linuxfoundation.org> References: <20260912065516.948645775@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mathieu Poirier [ Upstream commit d3962a397885518a85d2dc6b0c51e6594f71c30f ] Introduce function rproc_detach() to enable the remoteproc core to release the resources associated with a remote processor without stopping its operation. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen Link: https://lore.kernel.org/r/20210312162453.1234145-11-mathieu.poirier@linaro.org Signed-off-by: Bjorn Andersson Stable-dep-of: bb840ea69347 ("remoteproc: fix OOB read via signed offset in rsc_table_for_each_entry()") Signed-off-by: Sasha Levin --- drivers/remoteproc/remoteproc_core.c | 58 +++++++++++++++++++++++++++- include/linux/remoteproc.h | 1 + 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index e73f6eb3279d3..aff27e7ff5ca1 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1713,7 +1713,7 @@ static int rproc_stop(struct rproc *rproc, bool crashed) /* * __rproc_detach(): Does the opposite of __rproc_attach() */ -static int __maybe_unused __rproc_detach(struct rproc *rproc) +static int __rproc_detach(struct rproc *rproc) { struct device *dev = &rproc->dev; int ret; @@ -1969,6 +1969,62 @@ void rproc_shutdown(struct rproc *rproc) } EXPORT_SYMBOL(rproc_shutdown); +/** + * rproc_detach() - Detach the remote processor from the + * remoteproc core + * + * @rproc: the remote processor + * + * Detach a remote processor (previously attached to with rproc_attach()). + * + * In case @rproc is still being used by an additional user(s), then + * this function will just decrement the power refcount and exit, + * without disconnecting the device. + * + * Function rproc_detach() calls __rproc_detach() in order to let a remote + * processor know that services provided by the application processor are + * no longer available. From there it should be possible to remove the + * platform driver and even power cycle the application processor (if the HW + * supports it) without needing to switch off the remote processor. + */ +int rproc_detach(struct rproc *rproc) +{ + struct device *dev = &rproc->dev; + int ret; + + ret = mutex_lock_interruptible(&rproc->lock); + if (ret) { + dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); + return ret; + } + + /* if the remote proc is still needed, bail out */ + if (!atomic_dec_and_test(&rproc->power)) { + ret = 0; + goto out; + } + + ret = __rproc_detach(rproc); + if (ret) { + atomic_inc(&rproc->power); + goto out; + } + + /* clean up all acquired resources */ + rproc_resource_cleanup(rproc); + + /* release HW resources if needed */ + rproc_unprepare_device(rproc); + + rproc_disable_iommu(rproc); + + rproc->table_ptr = NULL; +out: + mutex_unlock(&rproc->lock); + return ret; +} +EXPORT_SYMBOL(rproc_detach); + /** * rproc_get_by_phandle() - find a remote processor by phandle * @phandle: phandle to the rproc diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 0e4dccbaa2cad..d75758743e8f0 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -667,6 +667,7 @@ rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len, int rproc_boot(struct rproc *rproc); void rproc_shutdown(struct rproc *rproc); +int rproc_detach(struct rproc *rproc); int rproc_set_firmware(struct rproc *rproc, const char *fw_name); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); int rproc_coredump_add_segment(struct rproc *rproc, dma_addr_t da, size_t size); -- 2.53.0