lkml.org 
[lkml]   [2021]   [Dec]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 19/26] x86/tdx: Make pages shared in ioremap()
From
Date
On 12/23/21 9:15 AM, Kirill A. Shutemov wrote:
>>> +pgprot_t pgprot_cc_encrypted(pgprot_t prot)
>>> +{
>>> + if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
>>> + return __pgprot(__sme_set(pgprot_val(prot)));
>>> + else if (cc_platform_has(CC_ATTR_GUEST_TDX))
>>> + return __pgprot(pgprot_val(prot) & ~tdx_shared_mask());
>>> +
>> Hmmm... I believe this breaks SEV guests. __sme_set() uses sme_me_mask which
>> is used for both SME and SEV. With the current checks, an SEV guest will end
>> up never setting an encrypted address through this path. Ditto below on the
>> decrypted path.
> Hm, okay. What if I rewrite code like this:
>
> pgprot_t pgprot_cc_encrypted(pgprot_t prot)
> {
> if (cc_platform_has(CC_ATTR_GUEST_TDX))
> return __pgprot(pgprot_val(prot) & ~tdx_shared_mask());
> else
> return __pgprot(__sme_set(pgprot_val(prot)));
> }
>
> I believe it should cover all cases, right?

I _think_ that should be fine for now. But, it does expose that
__sme_set() is weird because it get used on non-SME systems while
tdx_shared_mask() is only used on TDX systems.

Ideally, we'd eventually get to something close to what you had originally:

pgprot_t pgprot_cc_encrypted(pgprot_t prot)
{
if (cc_platform_has(CC_ATTR_GUEST_TDX))
return __pgprot(pgprot_val(prot) & ~tdx_shared_mask());
if (cc_platform_has(CC_ATTR_SME_SOMETHING??))
return __pgprot(pgprot_val(prot) | sme_me_mask));

return prot;
}

CC_ATTR_SME_SOMETHING would get set when sme_me_mask is initialized to
something non-zero. That will keep folks from falling into the same
trap that you did in the long term.

The SEV code wasn't crazy for doing what it did when it was the only
game in town. But, now that TDX is joining the party, we need to make
sure that SEV isn't special.

\
 
 \ /
  Last update: 2021-12-23 20:45    [W:0.167 / U:2.384 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site