Re: [PATCHv3 02/32] x86/coco: Add API to handle encryption mask

From: Kirill A. Shutemov
Date: Mon Feb 21 2022 - 17:28:52 EST


On Mon, Feb 21, 2022 at 11:28:16AM -0800, Dave Hansen wrote:
> I'm just a bit confused why *this* was chosen as the cc_whatever() hook.
> Just like the mask function, it has one spot where it gets used:
>
> +#define pgprot_encrypted(prot) __pgprot(cc_mkenc(pgprot_val(prot)))
> +#define pgprot_decrypted(prot) __pgprot(cc_mkdec(pgprot_val(prot)))
>
> So, why bother having another level of abstraction?
>
> Why don't we just have:
>
> pgprot_t cc_mkenc(pgprot prot)
> pgprot_t cc_mkenc(pgprot prot)
>
> and *no* pgprot_{en,de}crypted()?

Okay. Let me try this.

> >>> +out:
> >>> physical_mask &= ~sme_me_mask;
> >>> + if (sme_me_mask)
> >>> + cc_init(CC_VENDOR_AMD, sme_me_mask);
> >>> }
> >>
> >> I don't think you need to mop it up here, but where does this leave
> >> sme_me_mask?
> >
> > I think sme_me_mask still can be useful to indicate that the code is only
> > relevant for AMD context.
>
> Shouldn't we be able to tell that because something is in an
> AMD-specific file, function or #ifdef?

Sure. But for some code it is not immidiately obvious that it is
AMD-specific. Like from file name alone, mem_encrypt_identity.c doesn't
look like it is only AMD thing.

Anyway, I think getting rid of sme_me_mask is out of scope for the
patchset.

> Is there ever a time where sme_me_mask is populated by cc_mask is not?

Yes. Decompression code. (I know it doesn't affect bottom line much).

> This seems like it is just making a copy of sme_me_mask.
>
> sme_me_mask does look quite AMD-specialized, like its assembly
> manipulation. Even if it's just a copy of cc_mask, it would be nice to
> call that out so the relationship is crystal clear.

--
Kirill A. Shutemov