Messages in this thread | | | Subject | Re: [PATCH 19/26] x86/tdx: Make pages shared in ioremap() | From | Tom Lendacky <> | Date | Mon, 27 Dec 2021 09:07:10 -0600 |
| |
On 12/24/21 5:03 AM, Kirill A. Shutemov wrote: > On Thu, Dec 23, 2021 at 10:09:26PM +0100, Borislav Petkov wrote: >> On Thu, Dec 23, 2021 at 11:56:04PM +0300, Kirill A. Shutemov wrote: >>> Except CC_ATTR_MEM_ENCRYPT is true for TDX too, so it will also depend on >>> check order. It is fragile. >> >> So the query you wanna do is: >> >> if (memory encryption in use) >> use mask; >> >> and the mask you use depends on whether it is SEV or TDX. Right? >> >> If so, you can either do a cc_get_mask() function which gives you either >> the SEV or TDX mask or simply do: >> >> if (CC_ATTR_MEM_ENCRYPT) { >> if (CC_ATTR_GUEST_TDX) >> mask = tdx_shared_mask(); >> else if (sme_me_mask) >> mask = sme_me_mask; >> } >> >> Yeah, sme_me_mask has become synonymous with the kernel running as a AMD >> confidential guest. I need to think about how to make this cleaner... > > Okay. Meanwhile I leave it this way: > > pgprot_t pgprot_cc_encrypted(pgprot_t prot) > { > if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { > if (cc_platform_has(CC_ATTR_GUEST_TDX)) > return __pgprot(pgprot_val(prot) & ~tdx_shared_mask()); > else if (sme_me_mask) > return __pgprot(__sme_set(pgprot_val(prot))); > else > WARN_ON_ONCE(1); > } > > return prot; > } > EXPORT_SYMBOL_GPL(pgprot_cc_encrypted);
Why can't this follow the cc_platform_has() logic and maybe even live in the cc_platform.c file (though there might be issues with that, I haven't really looked)?
if (sme_me_mask) return __pgprot(__sme_set(pgprot_val(prot))); else if (is_tdx_guest()) return return __pgprot(pgprot_val(prot) & ~tdx_shared_mask());
return prot;
and maybe even it call it cc_pgrot_encrypted()?
Just a thought.
Thanks, Tom
> > pgprot_t pgprot_cc_decrypted(pgprot_t prot) > { > if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { > if (cc_platform_has(CC_ATTR_GUEST_TDX)) > return __pgprot(pgprot_val(prot) | tdx_shared_mask()); > else if (sme_me_mask) > return __pgprot(__sme_clr(pgprot_val(prot))); > else > WARN_ON_ONCE(1); > } > > return prot; > } > EXPORT_SYMBOL_GPL(pgprot_cc_decrypted); >
| |