[PATCH v2 3/7] x86/bugs: Exit early if return thunk is already set

Pawan Gupta posted 7 patches 6 months, 3 weeks ago
There is a newer version of this series
[PATCH v2 3/7] x86/bugs: Exit early if return thunk is already set
Posted by Pawan Gupta 6 months, 3 weeks ago
ITS and retbleed can both set CDT return thunk. If the exact same return
thunk is already set, avoid the warning and exit early.

Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
---
 arch/x86/kernel/cpu/bugs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 20d7d14b08298d4f610f2ebc7f13a490ee3d957a..a088302b320cf68344e28be7710b5a3582bba9ea 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -113,6 +113,9 @@ void (*x86_return_thunk)(void) __ro_after_init = __x86_return_thunk;
 
 static void __init set_return_thunk(void *thunk)
 {
+	if (thunk == x86_return_thunk)
+		return;
+
 	if (x86_return_thunk != __x86_return_thunk)
 		pr_warn("x86/bugs: return thunk changed\n");
 

-- 
2.34.1
Re: [PATCH v2 3/7] x86/bugs: Exit early if return thunk is already set
Posted by Nikolay Borisov 6 months, 3 weeks ago

On 5/22/25 05:44, Pawan Gupta wrote:
> ITS and retbleed can both set CDT return thunk. If the exact same return
> thunk is already set, avoid the warning and exit early.

According to the code there is only a single call which sets the CDT 
thunkand its in retbleed_apply_mitigation() if RETBLEED_MITIGATION_STUFF 
is being used.

ITS OTOH only sets 'its_return_thunk'.

While the patch itself is not wrong, the description doesn't reflect the 
current code?

> 
> Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Re: [PATCH v2 3/7] x86/bugs: Exit early if return thunk is already set
Posted by Nikolay Borisov 6 months, 3 weeks ago

On 5/22/25 13:22, Nikolay Borisov wrote:
> 
> 
> On 5/22/25 05:44, Pawan Gupta wrote:
>> ITS and retbleed can both set CDT return thunk. If the exact same return
>> thunk is already set, avoid the warning and exit early.
> 
> According to the code there is only a single call which sets the CDT 
> thunkand its in retbleed_apply_mitigation() if RETBLEED_MITIGATION_STUFF 
> is being used.
> 
> ITS OTOH only sets 'its_return_thunk'.
> 
> While the patch itself is not wrong, the description doesn't reflect the 
> current code?

So this is in preparation to allowing ITS to select the CDT, but this 
must be mentioned explicitly or simply squash this change into 'x86/its: 
Remove =stuff dependency on retbleed'

> 
>>
>> Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
> 
> 
>
Re: [PATCH v2 3/7] x86/bugs: Exit early if return thunk is already set
Posted by Pawan Gupta 6 months, 3 weeks ago
On Thu, May 22, 2025 at 01:26:16PM +0300, Nikolay Borisov wrote:
> 
> 
> On 5/22/25 13:22, Nikolay Borisov wrote:
> > 
> > 
> > On 5/22/25 05:44, Pawan Gupta wrote:
> > > ITS and retbleed can both set CDT return thunk. If the exact same return
> > > thunk is already set, avoid the warning and exit early.
> > 
> > According to the code there is only a single call which sets the CDT
> > thunkand its in retbleed_apply_mitigation() if RETBLEED_MITIGATION_STUFF
> > is being used.
> > 
> > ITS OTOH only sets 'its_return_thunk'.
> > 
> > While the patch itself is not wrong, the description doesn't reflect the
> > current code?
> 
> So this is in preparation to allowing ITS to select the CDT, but this must
> be mentioned explicitly or simply squash this change into 'x86/its: Remove
> =stuff dependency on retbleed'

Right, will update the commit message.