platform/x86/amd: pmc: Add a workaround for an s0i3 issue on Cezanne
PATCH 1/1 platform/x86/amd: pmc: Add a workaround for an s0i3 issue on Cezanne
Cezanne platforms under the right circumstances have a synchronization problem where attempting to enter s2idle may fail if the x86 cores are put into HLT before hardware resume from the previous attempt has completed.
To avoid this issue add a 10-20ms delay before entering s2idle another time. This workaround will only be applied on interrupts that wake the hardware but don't break the s2idle loop.
--- drivers/platform/x86/amd/pmc.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/platform/x86/amd/pmc.c +6 -0
@@ -739,8 +739,14 @@ static void amd_pmc_s2idle_prepare(void)static void amd_pmc_s2idle_check (void ) {struct amd_pmc_dev *pdev = &pmc; +struct smu_metrics table;int rc; +/* CZN: Ensure that future s0i3 entry attempts at least 10ms passed */ +if (pdev->cpu_id ==AMD_CPU_ID_CZN && !get_metrics_table (pdev, &table) && + table.s0i3_last_entry_status) +usleep_range (10000 ,20000 ); +/* Dump the IdleMask before we add to the STB */ amd_pmc_idlemask_read (pdev, pdev->dev,NULL );
Signature · 1 line
2.34.1
Hi Mario,
Quoted 5 lines · Mario Limonciello
Cezanne platforms under the right circumstances have a synchronization problem where attempting to enter s2idle may fail if the x86 cores are put into HLT before hardware resume from the previous attempt has completed.
Quoted 7 lines
To avoid this issue add a 10-20ms delay before entering s2idle another time. This workaround will only be applied on interrupts that wake the hardware but don't break the s2idle loop.
Cc "Mahapatra, Rajib" <[email protected]>Cc "Raul Rangel" <[email protected]>Signed-off-by Mario Limonciello <[email protected]>
Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Please let me know if it important to get this as a fix into 6.1, I wasn't really planning on doing any more fixes pull-reqs for 6.1, but I can do one if necessary.
Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.
Regards,
Hans
Quoted 23 lines
--- drivers/platform/x86/amd/pmc.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/platform/x86/amd/pmc.c +6
-0@@ -739,8 +739,14 @@ static void amd_pmc_s2idle_prepare(void)static void amd_pmc_s2idle_check (void ) {struct amd_pmc_dev *pdev = &pmc; +struct smu_metrics table;int rc; +/* CZN: Ensure that future s0i3 entry attempts at least 10ms passed */ +if (pdev->cpu_id ==AMD_CPU_ID_CZN && !get_metrics_table (pdev, &table) && + table.s0i3_last_entry_status) +usleep_range (10000 ,20000 ); +/* Dump the IdleMask before we add to the STB */ amd_pmc_idlemask_read (pdev, pdev->dev,NULL );
[Public]
Quoted 39 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Thursday, November 17, 2022 08:06
To: Limonciello, Mario <[email protected]>; S-k, Shyam-sundar <[email protected]>
Cc: Mahapatra, Rajib <[email protected]>; Raul Rangel <[email protected]>; Mark Gross <[email protected]>; platform- [email protected]; [email protected]
Subject: Re: [PATCH] platform/x86/amd: pmc: Add a workaround for an s0i3 issue on CezanneHi Mario,
Quoted 5 lines · Mario Limonciello
Cezanne platforms under the right circumstances have a synchronization problem where attempting to enter s2idle may fail if the x86 cores are put into HLT before hardware resume from the previous attempt has completed.
Quoted 7 lines
To avoid this issue add a 10-20ms delay before entering s2idle another time. This workaround will only be applied on interrupts that wake the hardware but don't break the s2idle loop.
Cc "Mahapatra, Rajib" <[email protected]>Cc "Raul Rangel" <[email protected]>Signed-off-by Mario Limonciello <[email protected]>Thank you for your patch, I've applied this patch to my review-hans branch:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.k
ernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fpdx86%2Fplatform- drivers-x86.git%2Flog%2F%3Fh%3Dreview- hans&data=05%7C01%7Cmario.limonciello%40amd.com%7C674f8bf7a8 114f83a3b408dac8a4d941%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C 0%7C638042907591739047%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C% 7C%7C&sdata=XYwl%2FOvUFy%2Bgz9EY9oa35M%2BkLf%2Bud8PKXynQ FlrUdoE%3D&reserved=0
Quoted 4 lines
Please let me know if it important to get this as a fix into 6.1, I wasn't really planning on doing any more fixes pull-reqs for 6.1, but I can do one if necessary.
AFAIK it's a corner case. I think it can wait until 6.2, but I think it should probably be Cc to 6.1 stable (which has the ability to run code in the check()) phase.
Quoted 36 lines
Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.
Regards,
Hans
Review
Quoted 5 lines
--- drivers/platform/x86/amd/pmc.c | 6 ++++++ 1 file changed, 6 insertions(+)(quoted diff) +0
-0
b/drivers/platform/x86/amd/pmc.cdrivers/platform/x86/amd/pmc.c static void amd_pmc_s2idle_prepare(void) · line 745
Quoted 11 lines
index
ef4ae977b8e0..439d282aafd1100644drivers/platform/x86/amd/pmc.c +2
-0@@ -739,8 +739,14 @@ static void amd_pmc_s2idle_prepare(void)static void amd_pmc_s2idle_check (void ) {struct amd_pmc_dev *pdev = &pmc; +struct smu_metrics table;int rc; +/* CZN: Ensure that future s0i3 entry attempts at least 10ms passed */
drivers/platform/x86/amd/pmc.c static void amd_pmc_s2idle_prepare(void) · line 746
Quoted 1 line
drivers/platform/x86/amd/pmc.c +1
-0+ if (pdev->cpu_id == AMD_CPU_ID_CZN &&!get_metrics_table(pdev, &table) &&
Quoted 6 lines
drivers/platform/x86/amd/pmc.c +3
-0+ table.s0i3_last_entry_status) +usleep_range (10000 ,20000 ); +/* Dump the IdleMask before we add to the STB */ amd_pmc_idlemask_read (pdev, pdev->dev,NULL );
Hi,
Quoted 34 lines · Mario
[Public]
Quoted 30 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Thursday, November 17, 2022 08:06
To: Limonciello, Mario <[email protected]>; S-k, Shyam-sundar <[email protected]>
Cc: Mahapatra, Rajib <[email protected]>; Raul Rangel <[email protected]>; Mark Gross <[email protected]>; platform- [email protected]; [email protected]
Subject: Re: [PATCH] platform/x86/amd: pmc: Add a workaround for an s0i3 issue on CezanneHi Mario,
Quoted 5 lines · Mario Limonciello
Cezanne platforms under the right circumstances have a synchronization problem where attempting to enter s2idle may fail if the x86 cores are put into HLT before hardware resume from the previous attempt has completed.
Quoted 7 lines
To avoid this issue add a 10-20ms delay before entering s2idle another time. This workaround will only be applied on interrupts that wake the hardware but don't break the s2idle loop.
Cc "Mahapatra, Rajib" <[email protected]>Cc "Raul Rangel" <[email protected]>Signed-off-by Mario Limonciello <[email protected]>Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.k
ernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fpdx86%2Fplatform-
Quoted 8 lines
Quoted 8 lines
drivers-x86.git%2Flog%2F%3Fh%3Dreview- hans&data=05%7C01%7Cmario.limonciello%40amd.com%7C674f8bf7a8 114f83a3b408dac8a4d941%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C 0%7C638042907591739047%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C% 7C%7C&sdata=XYwl%2FOvUFy%2Bgz9EY9oa35M%2BkLf%2Bud8PKXynQ FlrUdoE%3D&reserved=0
Quoted 7 lines
Quoted 4 lines
Please let me know if it important to get this as a fix into 6.1, I wasn't really planning on doing any more fixes pull-reqs for 6.1, but I can do one if necessary.
AFAIK it's a corner case. I think it can wait until 6.2, but I think it should probably be Cc to 6.1 stable (which has the ability to run code in the
check()) phase.
Ok, I have added a:
to the commit msg.
Regards,
Hans
Quoted 27 lines
Quoted 26 lines
Review
Quoted 5 lines
--- drivers/platform/x86/amd/pmc.c | 6 ++++++ 1 file changed, 6 insertions(+)(quoted diff) +0
-0
b/drivers/platform/x86/amd/pmc.cdrivers/platform/x86/amd/pmc.c static void amd_pmc_s2idle_prepare(void) · line 745
Quoted 11 lines
index
ef4ae977b8e0..439d282aafd1100644drivers/platform/x86/amd/pmc.c +2
-0@@ -739,8 +739,14 @@ static void amd_pmc_s2idle_prepare(void)static void amd_pmc_s2idle_check (void ) {struct amd_pmc_dev *pdev = &pmc; +struct smu_metrics table;int rc; +/* CZN: Ensure that future s0i3 entry attempts at least 10ms passed */
drivers/platform/x86/amd/pmc.c static void amd_pmc_s2idle_prepare(void) · line 746
Quoted 1 line
drivers/platform/x86/amd/pmc.c +1
-0+ if (pdev->cpu_id == AMD_CPU_ID_CZN &&!get_metrics_table(pdev, &table) &&
Quoted 6 lines
drivers/platform/x86/amd/pmc.c +3
-0+ table.s0i3_last_entry_status) +usleep_range (10000 ,20000 ); +/* Dump the IdleMask before we add to the STB */ amd_pmc_idlemask_read (pdev, pdev->dev,NULL );
[Public]
Quoted 82 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Thursday, November 17, 2022 10:09
To: Limonciello, Mario <[email protected]>; S-k, Shyam-sundar <[email protected]>
Cc: Mahapatra, Rajib <[email protected]>; Raul Rangel <[email protected]>; Mark Gross <[email protected]>; platform- [email protected]; [email protected]
Subject: Re: [PATCH] platform/x86/amd: pmc: Add a workaround for an s0i3 issue on CezanneHi,
Quoted 11 lines · Mario
[Public]
Quoted 7 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Thursday, November 17, 2022 08:06
To: Limonciello, Mario <[email protected]>; S-k, Shyam-sundar <[email protected]>
Cc: Mahapatra, Rajib <[email protected]>; Raul Rangel <[email protected]>; Mark Gross <[email protected]>;platform-
Quoted 2 lines
Quoted 2 lines
[email protected]; [email protected]
Subject: Re: [PATCH] platform/x86/amd: pmc: Add a workaround for ans0i3
Quoted 14 lines
Quoted 14 lines
issue on Cezanne
Hi Mario,
Quoted 9 lines · Mario Limonciello
Cezanne platforms under the right circumstances have a synchronization problem where attempting to enter s2idle may fail if the x86 cores are put into HLT before hardware resume from the previous attempt has completed.
To avoid this issue add a 10-20ms delay before entering s2idle another time. This workaround will only be applied on interrupts that wake the hardware but don't break the s2idle loop.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Cc "Mahapatra, Rajib" <[email protected]>Cc "Raul Rangel" <[email protected]>Signed-off-by Mario Limonciello <[email protected]>Thank you for your patch, I've applied this patch to my review-hans branch:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.k
%2F&data=05%7C01%7Cmario.limonciello%40amd.com%7Cb3c04b4449 154cad4f8208dac8b61509%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C 0%7C638042981632459900%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C% 7C%7C&sdata=3ZzdcI0BsHknBInf8V4MfrmNCkkc2U9ygYf4IP25LJ4%3D& amp;reserved=0
ernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fpdx86%2Fplatform-Quoted 2 lines
Quoted 2 lines
drivers-x86.git%2Flog%2F%3Fh%3Dreview-
hans&data=05%7C01%7Cmario.limonciello%40amd.com%7C674f8bf7a8
Quoted 1 line
Quoted 1 line
114f83a3b408dac8a4d941%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C
Quoted 1 line
Quoted 1 line
0%7C638042907591739047%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj
Quoted 1 line
Quoted 1 line
AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%
Quoted 1 line
Quoted 1 line
7C%7C&sdata=XYwl%2FOvUFy%2Bgz9EY9oa35M%2BkLf%2Bud8PKXynQ
Quoted 8 lines
Quoted 6 lines
FlrUdoE%3D&reserved=0
Please let me know if it important to get this as a fix into 6.1, I wasn't really planning on doing any more fixes pull-reqs for 6.1, but I can do one if necessary.
AFAIK it's a corner case. I think it can wait until 6.2, but I think it should
probably
Quoted 1 line
be Cc to 6.1 stable (which has the ability to run code in the
check()) phase.Ok, I have added a:
Quoted 7 lines
Cc [email protected] # 6.1to the commit msg.
Regards,
Hans
Hi Hans,
I just wanted to update you on this workaround. Previously it was believed to only be a very specific set of circumstances that happened on chromebooks running coreboot and an EC running cros_ec being utilized with unfortunate timing.
However it turns out that it can be "relatively" easily reproduced on UEFI machines as well though by suspending the laptop and then issuing anything that causes an ACPI event that otherwise shouldn't break the s2idle loop (such as closing the lid or unplugging the power adapter).
What will happen is that the SOC enters the deepest state up until the time of that ACPI event and then never enters again. The most common case this will break I think is someone suspends the laptop in GNOME, closes the lid and then tosses it in their bag. If you examine /sys/kernel/debug/amd_pmc/* you'll see that the duration of time in deepest state matches the time between suspending in GNOME and closing the lid.
I wanted to provide you that context to decide if this should still try to catch this in a 6.1 final pull request or not. Had I known how widely this helped at that time I would have advocated accordingly.
Thanks!
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Review
Quoted 8 lines
--- drivers/platform/x86/amd/pmc.c | 6 ++++++ 1 file changed, 6 insertions(+)(quoted diff) +0
-0
b/drivers/platform/x86/amd/pmc.cdrivers/platform/x86/amd/pmc.c static void amd_pmc_s2idle_prepare(void) · line 745
Quoted 11 lines
index
ef4ae977b8e0..439d282aafd1100644drivers/platform/x86/amd/pmc.c +2
-0@@ -739,8 +739,14 @@ static void amd_pmc_s2idle_prepare(void)static void amd_pmc_s2idle_check (void ) {struct amd_pmc_dev *pdev = &pmc; +struct smu_metrics table;int rc; +/* CZN: Ensure that future s0i3 entry attempts at least 10ms passed */
drivers/platform/x86/amd/pmc.c static void amd_pmc_s2idle_prepare(void) · line 746
Quoted 1 line
drivers/platform/x86/amd/pmc.c +1
-0+ if (pdev->cpu_id == AMD_CPU_ID_CZN &&!get_metrics_table(pdev, &table) &&
Quoted 6 lines
drivers/platform/x86/amd/pmc.c +3
-0+ table.s0i3_last_entry_status) +usleep_range (10000 ,20000 ); +/* Dump the IdleMask before we add to the STB */ amd_pmc_idlemask_read (pdev, pdev->dev,NULL );
Hi Mario,
Quoted 55 lines · Mario
[Public]
Quoted 51 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Thursday, November 17, 2022 10:09
To: Limonciello, Mario <[email protected]>; S-k, Shyam-sundar <[email protected]>
Cc: Mahapatra, Rajib <[email protected]>; Raul Rangel <[email protected]>; Mark Gross <[email protected]>; platform- [email protected]; [email protected]
Subject: Re: [PATCH] platform/x86/amd: pmc: Add a workaround for an s0i3 issue on CezanneHi,
Quoted 11 lines · Mario
[Public]
Quoted 7 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Thursday, November 17, 2022 08:06
To: Limonciello, Mario <[email protected]>; S-k, Shyam-sundar <[email protected]>
Cc: Mahapatra, Rajib <[email protected]>; Raul Rangel <[email protected]>; Mark Gross <[email protected]>;platform-
Quoted 2 lines
Quoted 2 lines
[email protected]; [email protected]
Subject: Re: [PATCH] platform/x86/amd: pmc: Add a workaround for ans0i3
Quoted 14 lines
Quoted 14 lines
issue on Cezanne
Hi Mario,
Quoted 9 lines · Mario Limonciello
Cezanne platforms under the right circumstances have a synchronization problem where attempting to enter s2idle may fail if the x86 cores are put into HLT before hardware resume from the previous attempt has completed.
To avoid this issue add a 10-20ms delay before entering s2idle another time. This workaround will only be applied on interrupts that wake the hardware but don't break the s2idle loop.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Cc "Mahapatra, Rajib" <[email protected]>Cc "Raul Rangel" <[email protected]>Signed-off-by Mario Limonciello <[email protected]>Thank you for your patch, I've applied this patch to my review-hans branch:
%2F&data=05%7C01%7Cmario.limonciello%40amd.com%7Cb3c04b4449
Quoted 55 lines
Quoted 30 lines
154cad4f8208dac8b61509%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C 0%7C638042981632459900%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C% 7C%7C&sdata=3ZzdcI0BsHknBInf8V4MfrmNCkkc2U9ygYf4IP25LJ4%3D& amp;reserved=0
ernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fpdx86%2Fplatform-Quoted 2 lines
Quoted 2 lines
drivers-x86.git%2Flog%2F%3Fh%3Dreview-
hans&data=05%7C01%7Cmario.limonciello%40amd.com%7C674f8bf7a8
Quoted 1 line
Quoted 1 line
114f83a3b408dac8a4d941%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C
Quoted 1 line
Quoted 1 line
0%7C638042907591739047%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj
Quoted 1 line
Quoted 1 line
AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%
Quoted 1 line
Quoted 1 line
7C%7C&sdata=XYwl%2FOvUFy%2Bgz9EY9oa35M%2BkLf%2Bud8PKXynQ
Quoted 8 lines
Quoted 6 lines
FlrUdoE%3D&reserved=0
Please let me know if it important to get this as a fix into 6.1, I wasn't really planning on doing any more fixes pull-reqs for 6.1, but I can do one if necessary.
AFAIK it's a corner case. I think it can wait until 6.2, but I think it should
probably
Quoted 1 line
be Cc to 6.1 stable (which has the ability to run code in the
check()) phase.Ok, I have added a:
Quoted 7 lines
Cc [email protected] # 6.1to the commit msg.
Regards,
Hans
Hi Hans,
I just wanted to update you on this workaround. Previously it was believed to only be a very specific set of circumstances that happened on chromebooks running coreboot and an EC running
cros_ecbeing utilized with unfortunate timing.However it turns out that it can be "relatively" easily reproduced on UEFI machines as well though by suspending the laptop and then issuing anything that causes an ACPI event that otherwise shouldn't break the s2idle loop (such as closing the lid or unplugging the power adapter).
What will happen is that the SOC enters the deepest state up until the time of that ACPI event and then never enters again. The most common case this will break I think is someone suspends the laptop in GNOME, closes the lid and then tosses it in their bag. If you examine
/sys/kernel/debug/amd_pmc/*you'll see that the duration of time in deepest state matches the time between suspending in GNOME and closing the lid.
Quoted 3 lines
I wanted to provide you that context to decide if this should still try to catch this in a 6.1 final pull request or not. Had I known how widely this helped at that time I would have advocated accordingly.
Based on the above I have prepared a pull-req to Linus with just this single patch in it to get this added to 6.1 .
I'll Cc you on the pull-req submission to Linus.
Regards,
Hans
Quoted 28 lines
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Review
Quoted 5 lines
--- drivers/platform/x86/amd/pmc.c | 6 ++++++ 1 file changed, 6 insertions(+)(quoted diff) +0
-0
b/drivers/platform/x86/amd/pmc.cdrivers/platform/x86/amd/pmc.c static void amd_pmc_s2idle_prepare(void) · line 745
Quoted 11 lines
index
ef4ae977b8e0..439d282aafd1100644drivers/platform/x86/amd/pmc.c +2
-0@@ -739,8 +739,14 @@ static void amd_pmc_s2idle_prepare(void)static void amd_pmc_s2idle_check (void ) {struct amd_pmc_dev *pdev = &pmc; +struct smu_metrics table;int rc; +/* CZN: Ensure that future s0i3 entry attempts at least 10ms passed */
drivers/platform/x86/amd/pmc.c static void amd_pmc_s2idle_prepare(void) · line 746
Quoted 1 line
drivers/platform/x86/amd/pmc.c +1
-0+ if (pdev->cpu_id == AMD_CPU_ID_CZN &&!get_metrics_table(pdev, &table) &&
Quoted 6 lines
drivers/platform/x86/amd/pmc.c +3
-0+ table.s0i3_last_entry_status) +usleep_range (10000 ,20000 ); +/* Dump the IdleMask before we add to the STB */ amd_pmc_idlemask_read (pdev, pdev->dev,NULL );