From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "Hansen, Dave" <dave.hansen@intel.com>,
"Huang, Kai" <kai.huang@intel.com>, "bp@alien8.de" <bp@alien8.de>,
"peterz@infradead.org" <peterz@infradead.org>,
"hpa@zytor.com" <hpa@zytor.com>,
"mingo@redhat.com" <mingo@redhat.com>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"kirill.shutemov@linux.intel.com"
<kirill.shutemov@linux.intel.com>
Cc: "pbonzini@redhat.com" <pbonzini@redhat.com>,
"seanjc@google.com" <seanjc@google.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"x86@kernel.org" <x86@kernel.org>
Subject: Re: [PATCH] x86/virt/tdx: Further fix tdh_vp_enter() calls instrumentable code warning
Date: Wed, 25 Jun 2025 23:56:26 +0000 [thread overview]
Message-ID: <6d997522660f3ddf673d981cf2511674a94e99ae.camel@intel.com> (raw)
In-Reply-To: <20250624101351.8019-1-kai.huang@intel.com>
On Tue, 2025-06-24 at 22:13 +1200, Kai Huang wrote:
> tdh_vp_enter() needs to be marked noinstr, which means it can't call any
> non-inlined noinstr functions. Commit e9f17038d814 ("x86/tdx: mark
> tdh_vp_enter() as __flatten") tried to address a build warning caused by
> tdx_tdvpr_pa() not getting inlined. Unfortunately that commit didn't
> fix the warning completely due to the inconsistent behavior of the
> __flatten annotation.
>
> There are two problems that can come up depending on the compiler and
> config. One is that tdx_tdvpr_pa() doesn't get inlined, the other is
> that page_to_phys() doesn't get inlined.
>
> The __flatten annotation makes the compiler inline all function calls
> that the annotated function makes, and the aforementioned commit assumed
> this is always honored, recursively. But it turns out it's not always
> true:
>
> - Gcc may ignore __flatten when CONFIG_CC_OPTIMIZE_FOR_SIZE=y.
> - Clang doesn't support recursive inlining for __flatten, which can
> trigger another similar warning when page_to_phys() calls pfn_valid()
> when CONFIG_DEBUG_VIRTUAL=y.
>
> Therefore using __flatten is not the right fix.
>
> To fix the first problem, remove the __flatten for tdh_vp_enter() and
> instead annotate tdx_tdvpr_pa() with __always_inline to make sure it is
> always inlined.
>
> 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?
>
> 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@intel.com>
Otherwise, LGTM.
next prev parent reply other threads:[~2025-06-25 23:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-24 10:13 Kai Huang
2025-06-25 23:56 ` Edgecombe, Rick P [this message]
2025-06-26 1:24 ` Huang, Kai
2025-06-26 15:07 ` Edgecombe, Rick P
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=6d997522660f3ddf673d981cf2511674a94e99ae.camel@intel.com \
--to=rick.p.edgecombe@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=hpa@zytor.com \
--cc=kai.huang@intel.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®