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

From: Dave Hansen
Date: Mon Feb 07 2022 - 11:59:43 EST


On 2/7/22 08:27, Borislav Petkov wrote:
> 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.

I think your basic point here is valid: Let's have a single function to
take a pgprot and turn it into an "encrypted" or "decrypted" pgprot.

But, we can't do it with functions like cc_set() and cc_clear() because
the polarity is different:

> +pgprot_t pgprot_encrypted(pgprot_t prot)
> +{
> + if (sme_me_mask)
> + return __pgprot(__sme_set(pgprot_val(prot)));
> + else if (is_tdx_guest())
> + return __pgprot(pgprot_val(prot) & ~tdx_shared_mask());
> +
> + return prot;
> +}

For "encrypted", SME sets bits and TDX clears bits.

For "decrypted", SME clears bits and TDX sets bits.

We can surely *do* this with cc_something() helpers. It's just not as
easy as making cc_set/cc_clear().