Re: [PATCHv2 22/29] x86/tdx: Make pages shared in ioremap()

Borislav Petkov
2022-02-07T16:33:14Z

On Mon, Jan 24, 2022 at 06:02:08PM +0300, Kirill A. Shutemov wrote:
> -/*
> - * Macros to add or remove encryption attribute
> - */
> -#define pgprot_encrypted(prot) __pgprot(__sme_set(pgprot_val(prot)))
> -#define pgprot_decrypted(prot) __pgprot(__sme_clr(pgprot_val(prot)))

Why can't you simply define

cc_set() and cc_clear()

helpers which either call the __sme variants or __tdx variants, the
latter you can define the same way, respectively, as the __sme ones.

And then you do:

#define pgprot_encrypted(prot) __pgprot(cc_set(pgprot_val(prot)))
#define pgprot_decrypted(prot) __pgprot(cc_clear(pgprot_val(prot)))

And just so that it works as early as possible, you can define a global
tdx_shared_mask or so which gets initialized the moment you have
td_info.gpa_width.

And then you don't need to export anything or other ifdefferies - you
just make sure you have that mask defined as early as needed.

Thx.

--
Regards/Gruss,
Boris.