Re: [PATCH] x86/virt/tdx: Further fix tdh_vp_enter() calls instrumentable code warning
From: Edgecombe, Rick P
Date: Thu Jun 26 2025 - 11:15:51 EST
On Thu, 2025-06-26 at 01:24 +0000, Huang, Kai wrote:
> > >
> > > To fix the second problem, change tdx_tdvpr_pa() to use
> > > PFN_PHYS(page_to_pfn()) instead of page_to_phys() so that there will be
> > > no more function call inside tdx_tdvpr_pa()[*].
> >
> > To check my understanding, page_to_pfn() on CONFIG_SPARSEMEM_VMEMMAP or
> > CONFIG_FLATMEM has no function calls, but on CONFIG_SPARSEMEM, it does. We
> > are
> > counting on x86_64 to not use CONFIG_SPARSEMEM?
>
> Yes. Please see include/asm-generic/memory_model.h.
It's a little brittle, but the compiler should warn at least.
>
> >
> > >
> > > The TDVPR page is always an actual page out of page allocator, so the
> > > additional warning around pfn_valid() check in page_to_phys() doesn't
> > > help a lot anyway. It's not worth complicating the code for such
> > > warning when CONFIG_DEBUG_VIRTUAL=y.
> > >
> > > [*] Since commit cba5d9b3e99d ("x86/mm/64: Make SPARSEMEM_VMEMMAP the
> > > only memory model") page_to_pfn() has been a simple macro without
> > > any function call.
> > >
> > > Fixes: e9f17038d814 ("x86/tdx: mark tdh_vp_enter() as __flatten")
> > > Signed-off-by: Kai Huang <kai.huang@xxxxxxxxx>
> >
> > Otherwise, LGTM.
>
> Is this a RB? :-)
Yes, I think this problem has been annoying. This is a decent solution all
things considered.
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>