Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
* [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling
@ 2024-04-03  3:10 Dmitry Baryshkov
  2024-04-03  3:10 ` [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock Dmitry Baryshkov
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Dmitry Baryshkov @ 2024-04-03  3:10 UTC (permalink / raw)
  To: Bjorn Andersson, Konrad Dybcio, Neil Armstrong
  Cc: linux-arm-msm, linux-kernel, Dmitry Baryshkov, Andrew Halaney

Fix two issues with the way the pmic_glink driver handles its clients.
First issue is mostly theoretical, while the second issue can easily be
reproduced if the drivers are built as modules.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
Changes in v2:
- Also take a lock at pmic_glink_rpmsg_callback() (Andrew Halaney)
- Link to v1: https://lore.kernel.org/r/20240402-pmic-glink-fix-clients-v1-0-885440b81c65@linaro.org

---
Dmitry Baryshkov (2):
      soc: qcom: pmic_glink: don't traverse clients list without a lock
      soc: qcom: pmic_glink: notify clients about the current state

 drivers/soc/qcom/pmic_glink.c | 9 +++++++++
 1 file changed, 9 insertions(+)
---
base-commit: a6bd6c9333397f5a0e2667d4d82fef8c970108f2
change-id: 20240402-pmic-glink-fix-clients-5df0bab3e871

Best regards,
-- 
Dmitry Baryshkov <dmitry.baryshkov@linaro.org>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock
  2024-04-03  3:10 [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling Dmitry Baryshkov
@ 2024-04-03  3:10 ` Dmitry Baryshkov
  2024-04-03 15:17   ` Andrew Halaney
  2024-04-05 16:56   ` Mukesh Ojha
  2024-04-03  3:10 ` [PATCH v2 2/2] soc: qcom: pmic_glink: notify clients about the current state Dmitry Baryshkov
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 8+ messages in thread
From: Dmitry Baryshkov @ 2024-04-03  3:10 UTC (permalink / raw)
  To: Bjorn Andersson, Konrad Dybcio, Neil Armstrong
  Cc: linux-arm-msm, linux-kernel, Dmitry Baryshkov

Take the client_lock before traversing the clients list at the
pmic_glink_state_notify_clients() function. This is required to keep the
list traversal safe from concurrent modification.

Fixes: 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/soc/qcom/pmic_glink.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c
index f913e9bd57ed..2b2cdf479654 100644
--- a/drivers/soc/qcom/pmic_glink.c
+++ b/drivers/soc/qcom/pmic_glink.c
@@ -115,10 +115,12 @@ static int pmic_glink_rpmsg_callback(struct rpmsg_device *rpdev, void *data,
 
 	hdr = data;
 
+	mutex_lock(&pg->client_lock);
 	list_for_each_entry(client, &pg->clients, node) {
 		if (client->id == le32_to_cpu(hdr->owner))
 			client->cb(data, len, client->priv);
 	}
+	mutex_unlock(&pg->client_lock);
 
 	return 0;
 }
@@ -168,8 +170,10 @@ static void pmic_glink_state_notify_clients(struct pmic_glink *pg)
 	}
 
 	if (new_state != pg->client_state) {
+		mutex_lock(&pg->client_lock);
 		list_for_each_entry(client, &pg->clients, node)
 			client->pdr_notify(client->priv, new_state);
+		mutex_unlock(&pg->client_lock);
 		pg->client_state = new_state;
 	}
 }

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/2] soc: qcom: pmic_glink: notify clients about the current state
  2024-04-03  3:10 [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling Dmitry Baryshkov
  2024-04-03  3:10 ` [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock Dmitry Baryshkov
@ 2024-04-03  3:10 ` Dmitry Baryshkov
  2024-04-05 16:52   ` Mukesh Ojha
  2024-04-05 15:43 ` [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling Xilin Wu
  2024-04-21 22:29 ` Bjorn Andersson
  3 siblings, 1 reply; 8+ messages in thread
From: Dmitry Baryshkov @ 2024-04-03  3:10 UTC (permalink / raw)
  To: Bjorn Andersson, Konrad Dybcio, Neil Armstrong
  Cc: linux-arm-msm, linux-kernel, Dmitry Baryshkov, Andrew Halaney

In case the client is registered after the pmic-glink recived a response
from the Protection Domain mapper, it is going to miss the notification
about the state. Notify clients about the current state upon
registration.

Fixes: 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/soc/qcom/pmic_glink.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c
index 2b2cdf479654..e85a12ec2aab 100644
--- a/drivers/soc/qcom/pmic_glink.c
+++ b/drivers/soc/qcom/pmic_glink.c
@@ -83,9 +83,14 @@ struct pmic_glink_client *devm_pmic_glink_register_client(struct device *dev,
 	client->pdr_notify = pdr;
 	client->priv = priv;
 
+	mutex_lock(&pg->state_lock);
 	mutex_lock(&pg->client_lock);
+
 	list_add(&client->node, &pg->clients);
+	client->pdr_notify(client->priv, pg->client_state);
+
 	mutex_unlock(&pg->client_lock);
+	mutex_unlock(&pg->state_lock);
 
 	devres_add(dev, client);
 

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock
  2024-04-03  3:10 ` [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock Dmitry Baryshkov
@ 2024-04-03 15:17   ` Andrew Halaney
  2024-04-05 16:56   ` Mukesh Ojha
  1 sibling, 0 replies; 8+ messages in thread
From: Andrew Halaney @ 2024-04-03 15:17 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Bjorn Andersson, Konrad Dybcio, Neil Armstrong, linux-arm-msm,
	linux-kernel

On Wed, Apr 03, 2024 at 06:10:57AM +0300, Dmitry Baryshkov wrote:
> Take the client_lock before traversing the clients list at the
> pmic_glink_state_notify_clients() function. This is required to keep the
> list traversal safe from concurrent modification.
> 
> Fixes: 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")

Reviewed-by: Andrew Halaney <ahalaney@redhat.com>

> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
>  drivers/soc/qcom/pmic_glink.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c
> index f913e9bd57ed..2b2cdf479654 100644
> --- a/drivers/soc/qcom/pmic_glink.c
> +++ b/drivers/soc/qcom/pmic_glink.c
> @@ -115,10 +115,12 @@ static int pmic_glink_rpmsg_callback(struct rpmsg_device *rpdev, void *data,
>  
>  	hdr = data;
>  
> +	mutex_lock(&pg->client_lock);
>  	list_for_each_entry(client, &pg->clients, node) {
>  		if (client->id == le32_to_cpu(hdr->owner))
>  			client->cb(data, len, client->priv);
>  	}
> +	mutex_unlock(&pg->client_lock);
>  
>  	return 0;
>  }
> @@ -168,8 +170,10 @@ static void pmic_glink_state_notify_clients(struct pmic_glink *pg)
>  	}
>  
>  	if (new_state != pg->client_state) {
> +		mutex_lock(&pg->client_lock);
>  		list_for_each_entry(client, &pg->clients, node)
>  			client->pdr_notify(client->priv, new_state);
> +		mutex_unlock(&pg->client_lock);
>  		pg->client_state = new_state;
>  	}
>  }
> 
> -- 
> 2.39.2
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling
  2024-04-03  3:10 [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling Dmitry Baryshkov
  2024-04-03  3:10 ` [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock Dmitry Baryshkov
  2024-04-03  3:10 ` [PATCH v2 2/2] soc: qcom: pmic_glink: notify clients about the current state Dmitry Baryshkov
@ 2024-04-05 15:43 ` Xilin Wu
  2024-04-21 22:29 ` Bjorn Andersson
  3 siblings, 0 replies; 8+ messages in thread
From: Xilin Wu @ 2024-04-05 15:43 UTC (permalink / raw)
  To: Dmitry Baryshkov, Bjorn Andersson, Konrad Dybcio, Neil Armstrong
  Cc: linux-arm-msm, linux-kernel, Andrew Halaney


On 2024/4/3 11:10, Dmitry Baryshkov wrote:
> Fix two issues with the way the pmic_glink driver handles its clients.
> First issue is mostly theoretical, while the second issue can easily be
> reproduced if the drivers are built as modules.
>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
> Changes in v2:
> - Also take a lock at pmic_glink_rpmsg_callback() (Andrew Halaney)
> - Link to v1: https://lore.kernel.org/r/20240402-pmic-glink-fix-clients-v1-0-885440b81c65@linaro.org
>
> ---
> Dmitry Baryshkov (2):
>        soc: qcom: pmic_glink: don't traverse clients list without a lock
>        soc: qcom: pmic_glink: notify clients about the current state
>
>   drivers/soc/qcom/pmic_glink.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> ---
> base-commit: a6bd6c9333397f5a0e2667d4d82fef8c970108f2
> change-id: 20240402-pmic-glink-fix-clients-5df0bab3e871
>
> Best regards,

Tested-by: Xilin Wu <wuxilin123@gmail.com> # on QCS8550 AYN Odin 2
Fixes: 
https://lore.kernel.org/all/20240311-qcom-pd-mapper-v4-0-24679cca5c24@linaro.org/


Thanks,
Xilin

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] soc: qcom: pmic_glink: notify clients about the current state
  2024-04-03  3:10 ` [PATCH v2 2/2] soc: qcom: pmic_glink: notify clients about the current state Dmitry Baryshkov
@ 2024-04-05 16:52   ` Mukesh Ojha
  0 siblings, 0 replies; 8+ messages in thread
From: Mukesh Ojha @ 2024-04-05 16:52 UTC (permalink / raw)
  To: Dmitry Baryshkov, Bjorn Andersson, Konrad Dybcio, Neil Armstrong
  Cc: linux-arm-msm, linux-kernel, Andrew Halaney



On 4/3/2024 8:40 AM, Dmitry Baryshkov wrote:
> In case the client is registered after the pmic-glink recived a response

                                                         received

> from the Protection Domain mapper, it is going to miss the notification
> about the state. Notify clients about the current state upon
> registration.
> 
> Fixes: 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
> Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
>   drivers/soc/qcom/pmic_glink.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c
> index 2b2cdf479654..e85a12ec2aab 100644
> --- a/drivers/soc/qcom/pmic_glink.c
> +++ b/drivers/soc/qcom/pmic_glink.c
> @@ -83,9 +83,14 @@ struct pmic_glink_client *devm_pmic_glink_register_client(struct device *dev,
>   	client->pdr_notify = pdr;
>   	client->priv = priv;
>   
> +	mutex_lock(&pg->state_lock);
>   	mutex_lock(&pg->client_lock);
> +
>   	list_add(&client->node, &pg->clients);
> +	client->pdr_notify(client->priv, pg->client_state);
> +
>   	mutex_unlock(&pg->client_lock);
> +	mutex_unlock(&pg->state_lock);

LGTM,

Reviewed-by: Mukesh Ojha <quic_mojha@quicinc.com>

-Mukesh
>   
>   	devres_add(dev, client);
>   
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock
  2024-04-03  3:10 ` [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock Dmitry Baryshkov
  2024-04-03 15:17   ` Andrew Halaney
@ 2024-04-05 16:56   ` Mukesh Ojha
  1 sibling, 0 replies; 8+ messages in thread
From: Mukesh Ojha @ 2024-04-05 16:56 UTC (permalink / raw)
  To: Dmitry Baryshkov, Bjorn Andersson, Konrad Dybcio, Neil Armstrong
  Cc: linux-arm-msm, linux-kernel



On 4/3/2024 8:40 AM, Dmitry Baryshkov wrote:
> Take the client_lock before traversing the clients list at the
> pmic_glink_state_notify_clients() function. This is required to keep the
> list traversal safe from concurrent modification.
> 
> Fixes: 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

Nice catch.

Reviewed-by: Mukesh Ojha <quic_mojha@quicinc.com>

-Mukesh

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling
  2024-04-03  3:10 [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling Dmitry Baryshkov
                   ` (2 preceding siblings ...)
  2024-04-05 15:43 ` [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling Xilin Wu
@ 2024-04-21 22:29 ` Bjorn Andersson
  3 siblings, 0 replies; 8+ messages in thread
From: Bjorn Andersson @ 2024-04-21 22:29 UTC (permalink / raw)
  To: Konrad Dybcio, Neil Armstrong, Dmitry Baryshkov
  Cc: linux-arm-msm, linux-kernel, Andrew Halaney


On Wed, 03 Apr 2024 06:10:56 +0300, Dmitry Baryshkov wrote:
> Fix two issues with the way the pmic_glink driver handles its clients.
> First issue is mostly theoretical, while the second issue can easily be
> reproduced if the drivers are built as modules.
> 
> 

Applied, thanks!

[1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock
      commit: 635ce0db89567ba62f64b79e8c6664ba3eff6516
[2/2] soc: qcom: pmic_glink: notify clients about the current state
      commit: d6cbce2cd354c9a37a558f290a8f1dfd20584f99

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-04-21 22:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-03  3:10 [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling Dmitry Baryshkov
2024-04-03  3:10 ` [PATCH v2 1/2] soc: qcom: pmic_glink: don't traverse clients list without a lock Dmitry Baryshkov
2024-04-03 15:17   ` Andrew Halaney
2024-04-05 16:56   ` Mukesh Ojha
2024-04-03  3:10 ` [PATCH v2 2/2] soc: qcom: pmic_glink: notify clients about the current state Dmitry Baryshkov
2024-04-05 16:52   ` Mukesh Ojha
2024-04-05 15:43 ` [PATCH v2 0/2] soc: qcom: pmic_glink: fix client handling Xilin Wu
2024-04-21 22:29 ` Bjorn Andersson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox