bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [RFC][PATCH] x86,ibt: Use UDB instead of 0xEA
       [not found] <20250814111732.GW4067720@noisy.programming.kicks-ass.net>
@ 2025-08-15  5:42 ` Alexei Starovoitov
  2025-08-15  7:57   ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2025-08-15  5:42 UTC (permalink / raw)
  To: Peter Zijlstra, Leon Hwang, bpf, Andrii Nakryiko
  Cc: X86 ML, H. Peter Anvin, Kees Cook, alyssa.milburn,
	scott.d.constable, Joao Moreira, Andrew Cooper, Sami Tolvanen,
	Nathan Chancellor, Masami Hiramatsu, ojeda, LKML

On Thu, Aug 14, 2025 at 2:17 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> Hi!
>
> A while ago FineIBT started using the instruction 0xEA to generate #UD.
> All existing parts will generate #UD in 64bit mode on that instruction.
>
> However; Intel/AMD have not blessed using this instruction, it is on
> their 'reserved' list for future use.
>
> Peter Anvin worked the committees and got use of 0xD6 blessed, and it
> will be called UDB (per the next SDM or so).
>
> Reworking the FineIBT code to use UDB wasn't entirely trivial, and I've
> had to switch the hash register to EAX in order to free up some bytes.
>
> Per the x86_64 ABI, EAX is used to pass the number of vector registers
> for varargs -- something that should not happen in the kernel. More so,
> we build with -mskip-rax-setup, which should leave EAX completely unused
> in the calling convention.

rax is used to pass tail_call count.
See diagram in commit log:
https://lore.kernel.org/all/20240714123902.32305-2-hffilwlqm@gmail.com/
Before that commit rax was used differently.
Bottom line rax was used for a long time to support bpf_tail_calls.
I'm traveling atm. So cc-ing folks for follow ups.

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

* Re: [RFC][PATCH] x86,ibt: Use UDB instead of 0xEA
  2025-08-15  5:42 ` [RFC][PATCH] x86,ibt: Use UDB instead of 0xEA Alexei Starovoitov
@ 2025-08-15  7:57   ` Peter Zijlstra
  2025-08-15  8:28     ` Leon Hwang
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2025-08-15  7:57 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Leon Hwang, bpf, Andrii Nakryiko, X86 ML, H. Peter Anvin,
	Kees Cook, alyssa.milburn, scott.d.constable, Joao Moreira,
	Andrew Cooper, Sami Tolvanen, Nathan Chancellor, Masami Hiramatsu,
	ojeda, LKML

On Fri, Aug 15, 2025 at 08:42:39AM +0300, Alexei Starovoitov wrote:
> On Thu, Aug 14, 2025 at 2:17 PM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > Hi!
> >
> > A while ago FineIBT started using the instruction 0xEA to generate #UD.
> > All existing parts will generate #UD in 64bit mode on that instruction.
> >
> > However; Intel/AMD have not blessed using this instruction, it is on
> > their 'reserved' list for future use.
> >
> > Peter Anvin worked the committees and got use of 0xD6 blessed, and it
> > will be called UDB (per the next SDM or so).
> >
> > Reworking the FineIBT code to use UDB wasn't entirely trivial, and I've
> > had to switch the hash register to EAX in order to free up some bytes.
> >
> > Per the x86_64 ABI, EAX is used to pass the number of vector registers
> > for varargs -- something that should not happen in the kernel. More so,
> > we build with -mskip-rax-setup, which should leave EAX completely unused
> > in the calling convention.
> 
> rax is used to pass tail_call count.
> See diagram in commit log:
> https://lore.kernel.org/all/20240714123902.32305-2-hffilwlqm@gmail.com/
> Before that commit rax was used differently.
> Bottom line rax was used for a long time to support bpf_tail_calls.
> I'm traveling atm. So cc-ing folks for follow ups.

IIRC the bpf2bpf tailcall doesn't use CFI at the moment. But let me
double check.

So emit_cfi() is called at the very start of emit_prologue() and
__arch_prepare_bpf_trampoline() in the BPF_TRAMP_F_INDIRECT case.

Now, emit_prologue() starts with the CFI bits, but the tailcall lands at
X86_TAIL_CALL_OFFSET, at which spot we only have EMIT_ENDBR(), nothing
else. So RAX should be unaffected at that point.

So, AFAICT, we're good on that point. It is just the C level indirect
function call ABI that is affected, BPF internal conventions are
unaffected.


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

* Re: [RFC][PATCH] x86,ibt: Use UDB instead of 0xEA
  2025-08-15  7:57   ` Peter Zijlstra
@ 2025-08-15  8:28     ` Leon Hwang
  0 siblings, 0 replies; 3+ messages in thread
From: Leon Hwang @ 2025-08-15  8:28 UTC (permalink / raw)
  To: Peter Zijlstra, Alexei Starovoitov
  Cc: bpf, Andrii Nakryiko, X86 ML, H. Peter Anvin, Kees Cook,
	alyssa.milburn, scott.d.constable, Joao Moreira, Andrew Cooper,
	Sami Tolvanen, Nathan Chancellor, Masami Hiramatsu, ojeda, LKML



On 15/8/25 15:57, Peter Zijlstra wrote:
> On Fri, Aug 15, 2025 at 08:42:39AM +0300, Alexei Starovoitov wrote:
>> On Thu, Aug 14, 2025 at 2:17 PM Peter Zijlstra <peterz@infradead.org> wrote:
>>>
>>> Hi!
>>>
>>> A while ago FineIBT started using the instruction 0xEA to generate #UD.
>>> All existing parts will generate #UD in 64bit mode on that instruction.
>>>
>>> However; Intel/AMD have not blessed using this instruction, it is on
>>> their 'reserved' list for future use.
>>>
>>> Peter Anvin worked the committees and got use of 0xD6 blessed, and it
>>> will be called UDB (per the next SDM or so).
>>>
>>> Reworking the FineIBT code to use UDB wasn't entirely trivial, and I've
>>> had to switch the hash register to EAX in order to free up some bytes.
>>>
>>> Per the x86_64 ABI, EAX is used to pass the number of vector registers
>>> for varargs -- something that should not happen in the kernel. More so,
>>> we build with -mskip-rax-setup, which should leave EAX completely unused
>>> in the calling convention.
>>
>> rax is used to pass tail_call count.
>> See diagram in commit log:
>> https://lore.kernel.org/all/20240714123902.32305-2-hffilwlqm@gmail.com/
>> Before that commit rax was used differently.
>> Bottom line rax was used for a long time to support bpf_tail_calls.
>> I'm traveling atm. So cc-ing folks for follow ups.
> 
> IIRC the bpf2bpf tailcall doesn't use CFI at the moment. But let me
> double check.
> 
> So emit_cfi() is called at the very start of emit_prologue() and
> __arch_prepare_bpf_trampoline() in the BPF_TRAMP_F_INDIRECT case.
> 
> Now, emit_prologue() starts with the CFI bits, but the tailcall lands at
> X86_TAIL_CALL_OFFSET, at which spot we only have EMIT_ENDBR(), nothing
> else. So RAX should be unaffected at that point.
> 
> So, AFAICT, we're good on that point. It is just the C level indirect
> function call ABI that is affected, BPF internal conventions are
> unaffected.
> 

RAX is used for propagating tail_call_cnt_ptr from caller to callee for
bpf2bpf+tailcall on x86_64.

Before the aforementioned commit, RAX is used for propagating
tail_call_cnt from caller to callee for the case.

Thanks,
Leon


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

end of thread, other threads:[~2025-08-15  8:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250814111732.GW4067720@noisy.programming.kicks-ass.net>
2025-08-15  5:42 ` [RFC][PATCH] x86,ibt: Use UDB instead of 0xEA Alexei Starovoitov
2025-08-15  7:57   ` Peter Zijlstra
2025-08-15  8:28     ` Leon Hwang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).