Messages in this thread | | | Subject | Re: [RFC v2 27/32] x86/tdx: Exclude Shared bit from __PHYSICAL_MASK | From | Dave Hansen <> | Date | Thu, 20 May 2021 13:56:13 -0700 |
| |
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);
Then, in a place like __set_memory_enc_dec(), you would query whether memory protection was in place or not: + if (protect) { + cpa.mask_set = pmc.p_set_bits; + cpa.mask_clr = pmc.p_clear_bits; + map_type = TDX_MAP_PRIVATE; + } else { + cpa.mask_set = pmc.p_clear_bits; + cpa.mask_clr = pmc.p_set_bits; + map_type = TDX_MAP_SHARED; + }
The is_tdx_guest() if()'s would just go away.
Basically, if there's a is_tdx_guest() check in common code, it's a place that might need an abstraction.
This, for instance:
> + if (!ret && is_tdx_guest()) { > + ret = tdg_map_gpa(__pa(addr), numpages, map_type); > + }
could probably just be:
if (!ret && is_protected_guest()) { ret = x86_vmm_protect(__pa(addr), numpages, protected); }
| |