Re: [RFC v2 27/32] x86/tdx: Exclude Shared bit from __PHYSICAL_MASK

From: Kirill A. Shutemov
Date: Mon May 31 2021 - 17:45:58 EST


On Thu, May 20, 2021 at 01:56:13PM -0700, Dave Hansen wrote:
> On 5/20/21 1:16 PM, Sean Christopherson wrote:
> > On Thu, May 20, 2021, Kuppuswamy, Sathyanarayanan wrote:
> >> So what is your proposal? "tdx_guest_" / "tdx_host_" ?
> > 1. Abstract things where appropriate, e.g. I'm guessing there is a clever way
> > to deal with the shared vs. private inversion and avoid tdg_shared_mask
> > altogether.
>
> One example here would be to keep a structure like:
>
> struct protected_mem_config
> {
> unsigned long p_set_bits;
> unsigned long p_clear_bits;
> }
>
> Where 'p_set_bits' are the bits that need to be set to establish memory
> protection and 'p_clear_bits' are the bits that need to be cleared.
> physical_mask would clear both of them:
>
> physical_mask &= ~(pmc.p_set_bits & pmc.p_set_bits);

For me it looks like an abstraction for sake of abstraction. More levels
of indirection without clear benefit. It doesn't add any more readability:
would you know what 'p_set_bits' stands for in two month? I'm not sure.

I would rather leave explicit check for protection flavour. It provides
better context for a reader.

--
Kirill A. Shutemov