mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: mahesh.rao@altera.com, Dinh Nguyen <dinguyen@kernel.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: Matthew Gerlach <matthew.gerlach@altera.com>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 1/4] firmware: stratix10-svc: Add mutex lock and unlock in stratix10 memory allocation/free
Date: Tue, 27 May 2025 10:49:26 +0200	[thread overview]
Message-ID: <c9c08142-752a-4ce5-a723-9f50486dddb6@kernel.org> (raw)
In-Reply-To: <20250526-sip_svc_upstream-v3-1-6a08a4502de3@altera.com>

On 26/05/2025 08:25, Mahesh Rao via B4 Relay wrote:
> From: Mahesh Rao <mahesh.rao@altera.com>
> 
> This commit adds a mutex lock to stratix10_svc_allocate_memory
> and stratix10_svc_free_memory functions to ensure
> thread safety when allocating and freeing memory.
> This prevents potential race conditions and ensures
> synchronization.
> 
> Signed-off-by: Mahesh Rao <mahesh.rao@altera.com>
> Reviewed-by: Matthew Gerlach <matthew.gerlach@altera.com>
> ---
>  drivers/firmware/stratix10-svc.c | 29 ++++++++++++++++++++++-------
>  1 file changed, 22 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c
> index e3f990d888d71829f0ab22b8a59aa7af0316bea0..3d42d4b18b7299d0a9e5110159e06253dfeddf88 100644
> --- a/drivers/firmware/stratix10-svc.c
> +++ b/drivers/firmware/stratix10-svc.c
> @@ -1,6 +1,7 @@
>  // SPDX-License-Identifier: GPL-2.0
>  /*
>   * Copyright (C) 2017-2018, Intel Corporation
> + * Copyright (C) 2025, Altera Corporation
>   */
>  
>  #include <linux/completion.h>
> @@ -171,6 +172,7 @@ struct stratix10_svc_chan {
>  
>  static LIST_HEAD(svc_ctrl);
>  static LIST_HEAD(svc_data_mem);
> +static DEFINE_MUTEX(svc_mem_lock);

You need to document what you are protecting here.

>  
>  /**
>   * svc_pa_to_va() - translate physical address to virtual address
> @@ -182,14 +184,17 @@ static LIST_HEAD(svc_data_mem);
>  static void *svc_pa_to_va(unsigned long addr)
>  {
>  	struct stratix10_svc_data_mem *pmem;
> +	void *ret = NULL;
>  
>  	pr_debug("claim back P-addr=0x%016x\n", (unsigned int)addr);
> +	mutex_lock(&svc_mem_lock);
>  	list_for_each_entry(pmem, &svc_data_mem, node)
> -		if (pmem->paddr == addr)
> -			return pmem->vaddr;
> -
> -	/* physical address is not found */
> -	return NULL;
> +		if (pmem->paddr == addr) {
> +			/* physical address is found */
> +			ret = pmem->vaddr;
> +		}
> +	mutex_unlock(&svc_mem_lock);
> +	return ret;
>  }
>  
>  /**
> @@ -990,13 +995,16 @@ int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg)
>  			p_data->flag = ct->flags;
>  		}
>  	} else {
> +		mutex_lock(&svc_mem_lock);
>  		list_for_each_entry(p_mem, &svc_data_mem, node)
>  			if (p_mem->vaddr == p_msg->payload) {
>  				p_data->paddr = p_mem->paddr;
>  				p_data->size = p_msg->payload_length;
>  				break;
>  			}
> +		mutex_unlock(&svc_mem_lock);
>  		if (p_msg->payload_output) {
> +			mutex_lock(&svc_mem_lock);

Especially that this looks odd.



Best regards,
Krzysztof

  reply	other threads:[~2025-05-27  8:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-26  6:25 [PATCH v3 0/4] stratix10: Add framework for asynchronous communication with SDM Mahesh Rao via B4 Relay
2025-05-26  6:25 ` [PATCH v3 1/4] firmware: stratix10-svc: Add mutex lock and unlock in stratix10 memory allocation/free Mahesh Rao via B4 Relay
2025-05-27  8:49   ` Krzysztof Kozlowski [this message]
2025-05-28 10:27     ` Mahesh Rao
2025-05-26  6:25 ` [PATCH v3 2/4] firmware: stratix10-svc: Implement ID pool management for asynchronous operations Mahesh Rao via B4 Relay
2025-05-26  6:25 ` [PATCH v3 3/4] firmware: stratix10-svc: Add initial support for asynchronous communication with Stratix10 service channel Mahesh Rao via B4 Relay
2025-05-27  8:44   ` Krzysztof Kozlowski
2025-05-28 10:29     ` Mahesh Rao
2025-05-28 11:50       ` Krzysztof Kozlowski
2025-06-04 11:19         ` Mahesh Rao
2025-05-26  6:25 ` [PATCH v3 4/4] firmware: stratix10-svc: Add support for HWMON temperature and voltage read command Mahesh Rao via B4 Relay
2025-06-03 19:44   ` Dinh Nguyen
2025-06-04 11:21     ` Mahesh Rao

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=c9c08142-752a-4ce5-a723-9f50486dddb6@kernel.org \
    --to=krzk@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dinguyen@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mahesh.rao@altera.com \
    --cc=matthew.gerlach@altera.com \
    --cc=robh@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®