FAILED: patch "[PATCH] misc: fastrpc: Remove buffer from list prior to unmap" failed to apply to 6.1-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 6102ceb4eab845743ee57acd3863fbd06e93c927
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026081715-barbecue-galleria-588e@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 6102ceb4eab845743ee57acd3863fbd06e93c927 Mon Sep 17 00:00:00 2001
From: Ekansh Gupta <[email protected]>
Date: Fri, 24 Jul 2026 23:33:38 +0100
Subject: [PATCH] misc: fastrpc: Remove buffer from list prior to unmap
operation
fastrpc_req_munmap_impl() is called to unmap any buffer. The buffer is getting removed from the list after it is unmapped from DSP. This can create potential race conditions if multiple threads invoke unmap concurrently, where one thread may remove the entry from the list while another thread's unmap operation is still ongoing.
Fix this by removing the buffer entry from the list before calling the unmap operation. If the unmap fails, the entry is re-added to the list so that userspace can retry the unmap, or alternatively, the buffer will be cleaned up during device release when the DSP process is torn down and all DSP-side mappings are freed along with remaining buffers in the list.
drivers/misc/fastrpc.c +10 -4
@@ -1889,9 +1889,6 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf * &args[0]);if (!err) {dev_dbg (dev,"unmmap\tpt 0x%09lx OK\n" , buf->raddr); -spin_lock (&fl->lock); -list_del (&buf->node); -spin_unlock (&fl->lock);fastrpc_buf_free (buf); }else {dev_err (dev,"unmmap\tpt 0x%09lx ERROR\n" , buf->raddr);
@@ -1905,6 +1902,7 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)struct fastrpc_buf *buf =NULL , *iter, *b;struct fastrpc_req_munmap req;struct device *dev = fl->sctx->dev; +int err;if (copy_from_user (&req, argp,sizeof (req)))return -EFAULT ;
@@ -1912,6 +1910,7 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)spin_lock (&fl->lock);list_for_each_entry_safe (iter, b, &fl->mmaps, node) {if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) { +list_del (&iter->node); buf = iter;break ; }
@@ -1924,7 +1923,14 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)return -EINVAL ; } -return fastrpc_req_munmap_impl (fl, buf); + err =fastrpc_req_munmap_impl (fl, buf); +if (err) { +spin_lock (&fl->lock); +list_add_tail (&buf->node, &fl->mmaps); +spin_unlock (&fl->lock); + } + +return err; }static int fastrpc_req_mmap (struct fastrpc_user *fl,char __user *argp)
Sasha Levin
maintainerPATCH 1/2 misc: fastrpc: Rework fastrpc_req_munmap
From: Abel Vesa <[email protected]>
[ Upstream commit 72fa6f7820c4cf96c5f7aabc4e54bdf52d1e2ac2 ]
Move the lookup of the munmap request to the fastrpc_req_munmap and pass on only the buf to the lower level fastrpc_req_munmap_impl. That way we can use the lower level fastrpc_req_munmap_impl on error path in fastrpc_req_mmap to free the buf without searching for the munmap request it belongs to.
Stable-dep-of: 6102ceb4eab8 ("misc: fastrpc: Remove buffer from list prior to unmap operation")
--- drivers/misc/fastrpc.c | 47 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 24 deletions(-)
drivers/misc/fastrpc.c +23 -24
@@ -1657,30 +1657,14 @@ static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp)return 0 ; } -static int fastrpc_req_munmap_impl (struct fastrpc_user *fl, -struct fastrpc_req_munmap *req) +static int fastrpc_req_munmap_impl (struct fastrpc_user *fl,struct fastrpc_buf *buf) {struct fastrpc_invoke_args args[1 ] = { [0 ] = {0 } }; -struct fastrpc_buf *buf =NULL , *iter, *b;struct fastrpc_munmap_req_msg req_msg;struct device *dev = fl->sctx->dev;int err;u32 sc; -spin_lock (&fl->lock); -list_for_each_entry_safe (iter, b, &fl->mmaps, node) { -if ((iter->raddr == req->vaddrout) && (iter->size == req->size)) { - buf = iter; -break ; - } - } -spin_unlock (&fl->lock); - -if (!buf) { -dev_err (dev,"mmap not in list\n" ); -return -EINVAL ; - } - req_msg.pgid = fl->tgid; req_msg.size = buf->size; req_msg.vaddr = buf->raddr;
@@ -1706,12 +1690,29 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,static int fastrpc_req_munmap (struct fastrpc_user *fl,char __user *argp) { +struct fastrpc_buf *buf =NULL , *iter, *b;struct fastrpc_req_munmap req; +struct device *dev = fl->sctx->dev;if (copy_from_user (&req, argp,sizeof (req)))return -EFAULT ; -return fastrpc_req_munmap_impl (fl, &req); +spin_lock (&fl->lock); +list_for_each_entry_safe (iter, b, &fl->mmaps, node) { +if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) { + buf = iter; +break ; + } + } +spin_unlock (&fl->lock); + +if (!buf) { +dev_err (dev,"mmap\t\tpt 0x%09llx [len 0x%08llx] not in list\n" , + req.vaddrout, req.size); +return -EINVAL ; + } + +return fastrpc_req_munmap_impl (fl, buf); }static int fastrpc_req_mmap (struct fastrpc_user *fl,char __user *argp)
@@ -1720,7 +1721,6 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)struct fastrpc_buf *buf =NULL ;struct fastrpc_mmap_req_msg req_msg;struct fastrpc_mmap_rsp_msg rsp_msg; -struct fastrpc_req_munmap req_unmap;struct fastrpc_phy_page pages;struct fastrpc_req_mmap req;struct device *dev = fl->sctx->dev;
@@ -1782,11 +1782,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)spin_unlock (&fl->lock);if (copy_to_user ((void __user *)argp, &req,sizeof (req))) { -/* unmap the memory and release the buffer */ - req_unmap.vaddrout = buf->raddr; - req_unmap.size = buf->size; -fastrpc_req_munmap_impl (fl, &req_unmap); -return -EFAULT ; + err = -EFAULT ; + goto err_assign; } dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n",
@@ -1794,6 +1791,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)return 0 ; +err_assign: +fastrpc_req_munmap_impl (fl, buf); err_invoke:fastrpc_buf_free (buf);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 misc: fastrpc: Remove buffer from list prior to unmap operation
From: Ekansh Gupta <[email protected]>
[ Upstream commit 6102ceb4eab845743ee57acd3863fbd06e93c927 ]
fastrpc_req_munmap_impl() is called to unmap any buffer. The buffer is getting removed from the list after it is unmapped from DSP. This can create potential race conditions if multiple threads invoke unmap concurrently, where one thread may remove the entry from the list while another thread's unmap operation is still ongoing.
Fix this by removing the buffer entry from the list before calling the unmap operation. If the unmap fails, the entry is re-added to the list so that userspace can retry the unmap, or alternatively, the buffer will be cleaned up during device release when the DSP process is torn down and all DSP-side mappings are freed along with remaining buffers in the list.
--- drivers/misc/fastrpc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/misc/fastrpc.c +10 -4
@@ -1677,9 +1677,6 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf * &args[0]);if (!err) {dev_dbg (dev,"unmmap\tpt 0x%09lx OK\n" , buf->raddr); -spin_lock (&fl->lock); -list_del (&buf->node); -spin_unlock (&fl->lock);fastrpc_buf_free (buf); }else {dev_err (dev,"unmmap\tpt 0x%09lx ERROR\n" , buf->raddr);
@@ -1693,6 +1690,7 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)struct fastrpc_buf *buf =NULL , *iter, *b;struct fastrpc_req_munmap req;struct device *dev = fl->sctx->dev; +int err;if (copy_from_user (&req, argp,sizeof (req)))return -EFAULT ;
@@ -1700,6 +1698,7 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)spin_lock (&fl->lock);list_for_each_entry_safe (iter, b, &fl->mmaps, node) {if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) { +list_del (&iter->node); buf = iter;break ; }
@@ -1712,7 +1711,14 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)return -EINVAL ; } -return fastrpc_req_munmap_impl (fl, buf); + err =fastrpc_req_munmap_impl (fl, buf); +if (err) { +spin_lock (&fl->lock); +list_add_tail (&buf->node, &fl->mmaps); +spin_unlock (&fl->lock); + } + +return err; }static int fastrpc_req_mmap (struct fastrpc_user *fl,char __user *argp)
Signature · 1 line
2.53.0