[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220216153703.42wnvgxcvshgpkj2@black.fi.intel.com>
Date: Wed, 16 Feb 2022 18:37:03 +0300
From: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
To: Borislav Petkov <bp@...en8.de>
Cc: Dave Hansen <dave.hansen@...el.com>,
Tom Lendacky <thomas.lendacky@....com>, tglx@...utronix.de,
mingo@...hat.com, luto@...nel.org, peterz@...radead.org,
sathyanarayanan.kuppuswamy@...ux.intel.com, aarcange@...hat.com,
ak@...ux.intel.com, dan.j.williams@...el.com, david@...hat.com,
hpa@...or.com, jgross@...e.com, jmattson@...gle.com,
joro@...tes.org, jpoimboe@...hat.com, knsathya@...nel.org,
pbonzini@...hat.com, sdeep@...are.com, seanjc@...gle.com,
tony.luck@...el.com, vkuznets@...hat.com, wanpengli@...cent.com,
x86@...nel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCHv2 22/29] x86/tdx: Make pages shared in ioremap()
On Wed, Feb 16, 2022 at 10:58:34AM +0100, Borislav Petkov wrote:
> On Tue, Feb 15, 2022 at 08:33:21PM +0300, Kirill A. Shutemov wrote:
> > Like cc_mkencrypted()/cc_mkdecrypted()? I donno. Looks strange.
>
> cc_mkenc/cc_mkdec probably.
Okay, what about this:
static u64 cc_mask;
pgprotval_t cc_mkenc(pgprotval_t protval)
{
if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST))
return protval & ~cc_mask;
else
return protval | cc_mask;
}
pgprotval_t cc_mkdec(pgprotval_t protval)
{
if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST))
return protval | cc_mask;
else
return protval & ~cc_mask;
}
EXPORT_SYMBOL_GPL(cc_mkdec);
__init void cc_init(void)
{
if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST))
cc_mask = tdx_shared_mask();
else
cc_mask = sme_me_mask;
}
I did not introduce explicit vendor variable but opted for
X86_FEATURE_TDX_GUEST to check vendor. There's no X86_FEATURE counter part
on AMD side presumably because it get used too early to be functional.
TDX needs cc_platform_has() later and X86_FEATURE infrastructure is
already functional there (and we can benefit from static branch).
cc_init() got called from sme_enable() for AMD and from tdx_early_init()
for TDX.
I also reworked cc_platform_has() to use combination of
X86_FEATURE_TDX_GUEST and cc_mask to route to right helper:
bool cc_platform_has(enum cc_attr attr)
{
if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST))
return intel_cc_platform_has(attr);
else if (cc_mask)
return amd_cc_platform_has(attr);
else if (hv_is_isolation_supported())
return hyperv_cc_platform_has(attr);
else
return false;
}
Any opinions?
--
Kirill A. Shutemov
Powered by blists - more mailing lists