mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
To: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Cc: srinivas.kandagatla@oss.qualcomm.com,
	linux-arm-msm@vger.kernel.org, gregkh@linuxfoundation.org,
	quic_bkumar@quicinc.com, linux-kernel@vger.kernel.org,
	quic_chennak@quicinc.com, dri-devel@lists.freedesktop.org,
	arnd@arndb.de, stable@kernel.org
Subject: Re: [PATCH v1 4/5] misc: fastrpc: Remove buffer from list prior to unmap operation
Date: Mon, 19 May 2025 16:26:27 +0530	[thread overview]
Message-ID: <1246b4e6-dd1f-4293-b580-5d642f661956@oss.qualcomm.com> (raw)
In-Reply-To: <uw6dcnbgg5vbfkcnei54rwkslpbseolr46cqhsosiadscd5srh@ixk67qdcwfug>



On 5/19/2025 3:50 PM, Dmitry Baryshkov wrote:
> On Tue, May 13, 2025 at 09:58:24AM +0530, Ekansh Gupta wrote:
>> 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 any other thread removes the entry
>> from list while unmap operation is ongoing. Remove the entry before
>> calling unmap operation.
>>
>> Fixes: 2419e55e532de ("misc: fastrpc: add mmap/unmap support")
>> Cc: stable@kernel.org
>> Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
>> ---
>>  drivers/misc/fastrpc.c | 29 ++++++++++++++++++++++-------
>>  1 file changed, 22 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
>> index b629e24f00bc..d54368bf8c5c 100644
>> --- a/drivers/misc/fastrpc.c
>> +++ b/drivers/misc/fastrpc.c
>> @@ -1868,9 +1868,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);
>> @@ -1884,13 +1881,15 @@ 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;
>>  
>>  	spin_lock(&fl->lock);
>>  	list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
>> -		if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) {
>> +		if (iter->raddr == req.vaddrout && iter->size == req.size) {
> Cosmetics, please drop.
Ack.
>
>> +			list_del(&iter->node);
>>  			buf = iter;
>>  			break;
>>  		}
>> @@ -1903,7 +1902,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)
>> @@ -1997,14 +2003,23 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
>>  
>>  	if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
>>  		err = -EFAULT;
>> -		goto err_assign;
>> +		goto err_copy;
>>  	}
>>  
>>  	dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n",
>>  		buf->raddr, buf->size);
>>  
>>  	return 0;
>> -
> Please keep the empty line here, it improves readability.
Ack.
>
>> +err_copy:
>> +	if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) {
>> +		spin_lock_irqsave(&fl->cctx->lock, flags);
>> +		list_del(&buf->node);
>> +		spin_unlock_irqrestore(&fl->cctx->lock, flags);
>> +	} else {
>> +		spin_lock(&fl->lock);
>> +		list_del(&buf->node);
>> +		spin_unlock(&fl->lock);
>> +	}
> Can we store the spinlock pointer in the struct fastrpc_buf instead?
this spinlock is used for multiple lists(bufs, maps and ctx).
>
>>  err_assign:
>>  	fastrpc_req_munmap_impl(fl, buf);
>>  
>> -- 
>> 2.34.1
>>


  reply	other threads:[~2025-05-19 10:56 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-13  4:28 [PATCH v1 0/5] misc: fastrpc: Add missing bug fixes Ekansh Gupta
2025-05-13  4:28 ` [PATCH v1 1/5] misc: fastrpc: Add NULL check to fastrpc_buf_free to prevent crash Ekansh Gupta
2025-05-19  9:25   ` Srinivas Kandagatla
2025-05-19 10:09     ` Dmitry Baryshkov
2025-05-19 10:40       ` Srinivas Kandagatla
2025-05-19 10:50         ` Ekansh Gupta
2025-05-13  4:28 ` [PATCH v1 2/5] misc: fastrpc: Move all remote heap allocations to a new list Ekansh Gupta
2025-05-19 10:16   ` Dmitry Baryshkov
2025-05-19 11:06     ` Ekansh Gupta
2025-05-19 13:29       ` Dmitry Baryshkov
2025-05-22  4:54         ` Ekansh Gupta
2025-05-22 12:09           ` Dmitry Baryshkov
2025-06-12  5:13             ` Ekansh Gupta
2025-06-12 11:16               ` Dmitry Baryshkov
2025-05-19 11:35   ` Srinivas Kandagatla
2025-05-22  5:09     ` Ekansh Gupta
2025-05-13  4:28 ` [PATCH v1 3/5] misc: fastrpc: Fix initial memory allocation for Audio PD memory pool Ekansh Gupta
2025-05-19 10:17   ` Dmitry Baryshkov
2025-05-19 10:53     ` Ekansh Gupta
2025-05-19 13:31       ` Dmitry Baryshkov
2025-05-22  4:58         ` Ekansh Gupta
2025-05-22 12:11           ` Dmitry Baryshkov
2025-05-19 11:41   ` Srinivas Kandagatla
2025-05-22  5:11     ` Ekansh Gupta
2025-05-13  4:28 ` [PATCH v1 4/5] misc: fastrpc: Remove buffer from list prior to unmap operation Ekansh Gupta
2025-05-19 10:20   ` Dmitry Baryshkov
2025-05-19 10:56     ` Ekansh Gupta [this message]
2025-05-19 13:32       ` Dmitry Baryshkov
2025-05-13  4:28 ` [PATCH v1 5/5] misc: fastrpc: Add missing unmapping user-requested remote heap Ekansh Gupta
2025-05-19 10:52   ` Dmitry Baryshkov
2025-05-19 10:58     ` Ekansh Gupta
2025-05-19 13:34       ` Dmitry Baryshkov
2025-05-22  5:01         ` Ekansh Gupta
2025-05-22 12:13           ` Dmitry Baryshkov
2025-06-12  5:20             ` Ekansh Gupta
2025-06-12  8:05               ` Dmitry Baryshkov
2025-06-12  9:32                 ` Ekansh Gupta
2025-06-12 10:24                   ` Dmitry Baryshkov
2025-07-09  5:43                     ` Ekansh Gupta
2025-07-19  9:44                       ` Dmitry Baryshkov
2025-07-23  9:24                         ` Ekansh Gupta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1246b4e6-dd1f-4293-b580-5d642f661956@oss.qualcomm.com \
    --to=ekansh.gupta@oss.qualcomm.com \
    --cc=arnd@arndb.de \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_bkumar@quicinc.com \
    --cc=quic_chennak@quicinc.com \
    --cc=srinivas.kandagatla@oss.qualcomm.com \
    --cc=stable@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®