X86 platform drivers
 help / color / mirror / Atom feed
* [PATCH] platform/x86/amd/pmf: Register notify handler only if SPS is enabled
@ 2023-06-22  6:03 Shyam Sundar S K
  2023-06-22  8:27 ` Hans de Goede
  0 siblings, 1 reply; 2+ messages in thread
From: Shyam Sundar S K @ 2023-06-22  6:03 UTC (permalink / raw)
  To: hdegoede, markgross
  Cc: platform-driver-x86, Patil.Reddy, mario.limonciello,
	Shyam Sundar S K, Allen Zhong

Power source notify handler is getting registered even when none of the
PMF feature in enabled leading to a crash.

...
[   22.592162] Call Trace:
[   22.592164]  <TASK>
[   22.592164]  ? rcu_note_context_switch+0x5e0/0x660
[   22.592166]  ? __warn+0x81/0x130
[   22.592171]  ? rcu_note_context_switch+0x5e0/0x660
[   22.592172]  ? report_bug+0x171/0x1a0
[   22.592175]  ? prb_read_valid+0x1b/0x30
[   22.592177]  ? handle_bug+0x3c/0x80
[   22.592178]  ? exc_invalid_op+0x17/0x70
[   22.592179]  ? asm_exc_invalid_op+0x1a/0x20
[   22.592182]  ? rcu_note_context_switch+0x5e0/0x660
[   22.592183]  ? acpi_ut_delete_object_desc+0x86/0xb0
[   22.592186]  ? acpi_ut_update_ref_count.part.0+0x22d/0x930
[   22.592187]  __schedule+0xc0/0x1410
[   22.592189]  ? ktime_get+0x3c/0xa0
[   22.592191]  ? lapic_next_event+0x1d/0x30
[   22.592193]  ? hrtimer_start_range_ns+0x25b/0x350
[   22.592196]  schedule+0x5e/0xd0
[   22.592197]  schedule_hrtimeout_range_clock+0xbe/0x140
[   22.592199]  ? __pfx_hrtimer_wakeup+0x10/0x10
[   22.592200]  usleep_range_state+0x64/0x90
[   22.592203]  amd_pmf_send_cmd+0x106/0x2a0 [amd_pmf bddfe0fe3712aaa99acce3d5487405c5213c6616]
[   22.592207]  amd_pmf_update_slider+0x56/0x1b0 [amd_pmf bddfe0fe3712aaa99acce3d5487405c5213c6616]
[   22.592210]  amd_pmf_set_sps_power_limits+0x72/0x80 [amd_pmf bddfe0fe3712aaa99acce3d5487405c5213c6616]
[   22.592213]  amd_pmf_pwr_src_notify_call+0x49/0x90 [amd_pmf bddfe0fe3712aaa99acce3d5487405c5213c6616]
[   22.592216]  notifier_call_chain+0x5a/0xd0
[   22.592218]  atomic_notifier_call_chain+0x32/0x50
...

Fix this by moving the registration of source change notify handler only
when SPS(Static Slider) is advertised as supported.

Reported-by: Allen Zhong <allen@atr.me>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217571
Fixes: 4c71ae414474 ("platform/x86/amd/pmf: Add support SPS PMF feature")
Tested-by: Patil Rajesh Reddy <Patil.Reddy@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
---
 drivers/platform/x86/amd/pmf/core.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
index d5bb775dadcf..a5b8f9bbc0d9 100644
--- a/drivers/platform/x86/amd/pmf/core.c
+++ b/drivers/platform/x86/amd/pmf/core.c
@@ -280,6 +280,8 @@ static void amd_pmf_init_features(struct amd_pmf_dev *dev)
 	/* Enable Static Slider */
 	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR)) {
 		amd_pmf_init_sps(dev);
+		dev->pwr_src_notifier.notifier_call = amd_pmf_pwr_src_notify_call;
+		power_supply_reg_notifier(&dev->pwr_src_notifier);
 		dev_dbg(dev->dev, "SPS enabled and Platform Profiles registered\n");
 	}
 
@@ -298,8 +300,10 @@ static void amd_pmf_init_features(struct amd_pmf_dev *dev)
 
 static void amd_pmf_deinit_features(struct amd_pmf_dev *dev)
 {
-	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR))
+	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR)) {
+		power_supply_unreg_notifier(&dev->pwr_src_notifier);
 		amd_pmf_deinit_sps(dev);
+	}
 
 	if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) {
 		amd_pmf_deinit_auto_mode(dev);
@@ -382,9 +386,6 @@ static int amd_pmf_probe(struct platform_device *pdev)
 	apmf_install_handler(dev);
 	amd_pmf_dbgfs_register(dev);
 
-	dev->pwr_src_notifier.notifier_call = amd_pmf_pwr_src_notify_call;
-	power_supply_reg_notifier(&dev->pwr_src_notifier);
-
 	dev_info(dev->dev, "registered PMF device successfully\n");
 
 	return 0;
@@ -394,7 +395,6 @@ static void amd_pmf_remove(struct platform_device *pdev)
 {
 	struct amd_pmf_dev *dev = platform_get_drvdata(pdev);
 
-	power_supply_unreg_notifier(&dev->pwr_src_notifier);
 	amd_pmf_deinit_features(dev);
 	apmf_acpi_deinit(dev);
 	amd_pmf_dbgfs_unregister(dev);
-- 
2.25.1


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

* Re: [PATCH] platform/x86/amd/pmf: Register notify handler only if SPS is enabled
  2023-06-22  6:03 [PATCH] platform/x86/amd/pmf: Register notify handler only if SPS is enabled Shyam Sundar S K
@ 2023-06-22  8:27 ` Hans de Goede
  0 siblings, 0 replies; 2+ messages in thread
From: Hans de Goede @ 2023-06-22  8:27 UTC (permalink / raw)
  To: Shyam Sundar S K, markgross
  Cc: platform-driver-x86, Patil.Reddy, mario.limonciello, Allen Zhong

Hi,

On 6/22/23 08:03, Shyam Sundar S K wrote:
> Power source notify handler is getting registered even when none of the
> PMF feature in enabled leading to a crash.
> 
> ...
> [   22.592162] Call Trace:
> [   22.592164]  <TASK>
> [   22.592164]  ? rcu_note_context_switch+0x5e0/0x660
> [   22.592166]  ? __warn+0x81/0x130
> [   22.592171]  ? rcu_note_context_switch+0x5e0/0x660
> [   22.592172]  ? report_bug+0x171/0x1a0
> [   22.592175]  ? prb_read_valid+0x1b/0x30
> [   22.592177]  ? handle_bug+0x3c/0x80
> [   22.592178]  ? exc_invalid_op+0x17/0x70
> [   22.592179]  ? asm_exc_invalid_op+0x1a/0x20
> [   22.592182]  ? rcu_note_context_switch+0x5e0/0x660
> [   22.592183]  ? acpi_ut_delete_object_desc+0x86/0xb0
> [   22.592186]  ? acpi_ut_update_ref_count.part.0+0x22d/0x930
> [   22.592187]  __schedule+0xc0/0x1410
> [   22.592189]  ? ktime_get+0x3c/0xa0
> [   22.592191]  ? lapic_next_event+0x1d/0x30
> [   22.592193]  ? hrtimer_start_range_ns+0x25b/0x350
> [   22.592196]  schedule+0x5e/0xd0
> [   22.592197]  schedule_hrtimeout_range_clock+0xbe/0x140
> [   22.592199]  ? __pfx_hrtimer_wakeup+0x10/0x10
> [   22.592200]  usleep_range_state+0x64/0x90
> [   22.592203]  amd_pmf_send_cmd+0x106/0x2a0 [amd_pmf bddfe0fe3712aaa99acce3d5487405c5213c6616]
> [   22.592207]  amd_pmf_update_slider+0x56/0x1b0 [amd_pmf bddfe0fe3712aaa99acce3d5487405c5213c6616]
> [   22.592210]  amd_pmf_set_sps_power_limits+0x72/0x80 [amd_pmf bddfe0fe3712aaa99acce3d5487405c5213c6616]
> [   22.592213]  amd_pmf_pwr_src_notify_call+0x49/0x90 [amd_pmf bddfe0fe3712aaa99acce3d5487405c5213c6616]
> [   22.592216]  notifier_call_chain+0x5a/0xd0
> [   22.592218]  atomic_notifier_call_chain+0x32/0x50
> ...
> 
> Fix this by moving the registration of source change notify handler only
> when SPS(Static Slider) is advertised as supported.
> 
> Reported-by: Allen Zhong <allen@atr.me>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217571
> Fixes: 4c71ae414474 ("platform/x86/amd/pmf: Add support SPS PMF feature")
> Tested-by: Patil Rajesh Reddy <Patil.Reddy@amd.com>
> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
> Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>

Thank you for your patch, I've applied this patch to my fixes
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=fixes

And I have just send a fixes pull-req with this to Linus
for the current kernel development cycle.

Regards,

Hans


> ---
>  drivers/platform/x86/amd/pmf/core.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
> index d5bb775dadcf..a5b8f9bbc0d9 100644
> --- a/drivers/platform/x86/amd/pmf/core.c
> +++ b/drivers/platform/x86/amd/pmf/core.c
> @@ -280,6 +280,8 @@ static void amd_pmf_init_features(struct amd_pmf_dev *dev)
>  	/* Enable Static Slider */
>  	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR)) {
>  		amd_pmf_init_sps(dev);
> +		dev->pwr_src_notifier.notifier_call = amd_pmf_pwr_src_notify_call;
> +		power_supply_reg_notifier(&dev->pwr_src_notifier);
>  		dev_dbg(dev->dev, "SPS enabled and Platform Profiles registered\n");
>  	}
>  
> @@ -298,8 +300,10 @@ static void amd_pmf_init_features(struct amd_pmf_dev *dev)
>  
>  static void amd_pmf_deinit_features(struct amd_pmf_dev *dev)
>  {
> -	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR))
> +	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR)) {
> +		power_supply_unreg_notifier(&dev->pwr_src_notifier);
>  		amd_pmf_deinit_sps(dev);
> +	}
>  
>  	if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) {
>  		amd_pmf_deinit_auto_mode(dev);
> @@ -382,9 +386,6 @@ static int amd_pmf_probe(struct platform_device *pdev)
>  	apmf_install_handler(dev);
>  	amd_pmf_dbgfs_register(dev);
>  
> -	dev->pwr_src_notifier.notifier_call = amd_pmf_pwr_src_notify_call;
> -	power_supply_reg_notifier(&dev->pwr_src_notifier);
> -
>  	dev_info(dev->dev, "registered PMF device successfully\n");
>  
>  	return 0;
> @@ -394,7 +395,6 @@ static void amd_pmf_remove(struct platform_device *pdev)
>  {
>  	struct amd_pmf_dev *dev = platform_get_drvdata(pdev);
>  
> -	power_supply_unreg_notifier(&dev->pwr_src_notifier);
>  	amd_pmf_deinit_features(dev);
>  	apmf_acpi_deinit(dev);
>  	amd_pmf_dbgfs_unregister(dev);


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

end of thread, other threads:[~2023-06-22  8:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-22  6:03 [PATCH] platform/x86/amd/pmf: Register notify handler only if SPS is enabled Shyam Sundar S K
2023-06-22  8:27 ` Hans de Goede

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