lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6d997522660f3ddf673d981cf2511674a94e99ae.camel@intel.com>
Date: Wed, 25 Jun 2025 23:56:26 +0000
From: "Edgecombe, Rick P" <rick.p.edgecombe@...el.com>
To: "Hansen, Dave" <dave.hansen@...el.com>, "Huang, Kai"
	<kai.huang@...el.com>, "bp@...en8.de" <bp@...en8.de>, "peterz@...radead.org"
	<peterz@...radead.org>, "hpa@...or.com" <hpa@...or.com>, "mingo@...hat.com"
	<mingo@...hat.com>, "tglx@...utronix.de" <tglx@...utronix.de>,
	"kirill.shutemov@...ux.intel.com" <kirill.shutemov@...ux.intel.com>
CC: "pbonzini@...hat.com" <pbonzini@...hat.com>, "seanjc@...gle.com"
	<seanjc@...gle.com>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, "x86@...nel.org" <x86@...nel.org>
Subject: Re: [PATCH] x86/virt/tdx: Further fix tdh_vp_enter() calls
 instrumentable code warning

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@...el.com>

Otherwise, LGTM.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ