From: Peter Zijlstra <peterz@infradead.org>
To: Nikolay Borisov <nik.borisov@suse.com>
Cc: "Huang, Kai" <kai.huang@intel.com>,
"x86@kernel.org" <x86@kernel.org>,
"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>
Subject: Re: [PATCH] x86/tdx: Make seamcall/tdcall CET-compliant
Date: Wed, 22 Oct 2025 12:30:31 +0200 [thread overview]
Message-ID: <20251022103031.GX3419281@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <d8bdeaa7-3bda-43ea-8b98-ef4f23d0e7b8@suse.com>
On Wed, Oct 22, 2025 at 01:21:25PM +0300, Nikolay Borisov wrote:
>
>
> On 10/22/25 13:14, Huang, Kai wrote:
> > On Wed, 2025-10-22 at 12:36 +0300, Nikolay Borisov wrote:
> > > _seamcall/_ret/_saved_ret can be the target of indirect calls via
> > > sc_retry_prerr/__seamcall_dirty_cache so on machines with CET enabled
> > > such call chains result in a splat and a BUG():
> > >
> >
> > [...]
> >
> > >
> > > Fix it by adding an ENBDR in TDX_MODULE_CALL macro to cover all
> > > cases.
> > >
> > > Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
> > > ---
> > >
> > > The kernel this was observed is a SLE, however it contains the current upstream
> > > TDX patches. And looking at the usptream code the problem persists there as well.
> >
> > Does your kernel contain commit 0b3bc018e86af ("x86/virt/tdx: Avoid
> > indirect calls to TDX assembly functions")?
> >
> > Some history about this commit:
> >
> > I firstly found __seamcall*() could be indirect calls in some randconfig
> > when building the kernel, and tried to resolve it by (effectively) adding
> > ENDBR:
> >
> > https://lore.kernel.org/lkml/20250604003848.13154-1-kai.huang@intel.com/
> >
> > Peter suggested that we could use __always_inline to keep compiler from
> > generating indirect calls (which resulted in the above commit):
> >
> > https://lore.kernel.org/lkml/20250605145914.GW39944@noisy.programming.kicks-ass.net/
> >
> > I never met __tdcall*() could be indirect calls, though.
>
> Well, adding __always_inline to sc_retry means it will be inlined, but
> inside the body of the function you do have:
>
> __seamcall_dirty_cache (which is also always inlined) but in it you have:
> return func(fn, args);
>
> So you still have this indirect call, no ?
If you do always-inline, the function argument can be constant
propagated, and thus func will be a known function and not result in an
indirect call.
That is:
void foo(void);
__always_inline void bar(void (*func)(void))
{
func();
}
void ponies(void)
{
bar(&foo);
}
The compiler is clever enough to see that is a direct call of foo.
next prev parent reply other threads:[~2025-10-22 10:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-22 9:36 [PATCH] x86/tdx: Make seamcall/tdcall CET-compliant Nikolay Borisov
2025-10-22 10:14 ` Huang, Kai
2025-10-22 10:21 ` Nikolay Borisov
2025-10-22 10:30 ` Peter Zijlstra [this message]
2025-10-22 10:48 ` Nikolay Borisov
2025-10-22 10:51 ` Peter Zijlstra
2025-10-22 11:10 ` Nikolay Borisov
2025-10-22 11:19 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251022103031.GX3419281@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=dave.hansen@linux.intel.com \
--cc=kai.huang@intel.com \
--cc=linux-coco@lists.linux.dev \
--cc=nik.borisov@suse.com \
--cc=rick.p.edgecombe@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox