[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220221221424.r7ffo5je4lyt4tw5@black.fi.intel.com>
Date: Tue, 22 Feb 2022 01:14:24 +0300
From: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
To: Tom Lendacky <thomas.lendacky@....com>
Cc: "Kirill A. Shutemov" <kirill@...temov.name>, bp@...en8.de,
aarcange@...hat.com, ak@...ux.intel.com, dan.j.williams@...el.com,
dave.hansen@...el.com, david@...hat.com, hpa@...or.com,
jgross@...e.com, jmattson@...gle.com, joro@...tes.org,
jpoimboe@...hat.com, knsathya@...nel.org,
linux-kernel@...r.kernel.org, luto@...nel.org, mingo@...hat.com,
pbonzini@...hat.com, peterz@...radead.org,
sathyanarayanan.kuppuswamy@...ux.intel.com, sdeep@...are.com,
seanjc@...gle.com, tglx@...utronix.de, tony.luck@...el.com,
vkuznets@...hat.com, wanpengli@...cent.com, x86@...nel.org
Subject: Re: [PATCHv3.1 2.1/2] x86/coco: Add API to handle encryption mask
On Mon, Feb 21, 2022 at 12:31:40PM -0600, Tom Lendacky wrote:
> On 2/18/22 18:13, Kirill A. Shutemov wrote:
> > AMD SME/SEV uses a bit in the page table entries to indicate that the
> > page is encrypted and not accessible to the VMM.
> >
> > TDX uses a similar approach, but the polarity of the mask is opposite to
> > AMD: if the bit is set the page is accessible to VMM.
> >
> > Provide vendor-neutral API to deal with the mask:
> >
> > - cc_mkenc() and cc_mkdec() modify given address to make it
> > encrypted/decrypted. It can be applied to phys_addr_t, pgprotval_t
> > or page table entry value.
> >
> > - cc_get_mask() returns encryption or decrypthion mask. It is useful
> > for set_memory_encrypted() and set_memory_decrypted()
> > implementation.
> >
> > The implementation will be extended to cover TDX.
> >
> > pgprot_decrypted() is used by drivers (i915, virtio_gpu, vfio).
> > cc_mkdec() called by pgprot_decrypted(). Export cc_mkdec().
> >
> > HyperV doesn't use bits in page table entries, so the mask is 0 for both
> > encrypthion and decrypthion.
> >
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@...ux.intel.com>
>
> > @@ -84,7 +85,39 @@ bool cc_platform_has(enum cc_attr attr)
> > }
> > EXPORT_SYMBOL_GPL(cc_platform_has);
> > -__init void cc_init(enum cc_vendor vendor)
> > +u64 cc_get_mask(bool enc)
>
> I was a bit confused by this name, expecting to always get the mask, but it
> is dependent on the input parameter.
Well, it always get you a mask. But it can be empty :P
> How about cc_get_operation_mask() or ... ? I'm struggling to come up
> with a good name, but plain cc_get_mask() is very confusing.
Yeah. Naming is hard. cc_get_operation_mask() doesn't clarify anything
comparing to cc_get_mask(). To me it is as confusing.
>
> > +{
> > + switch (cc_vendor) {
> > + case CC_VENDOR_AMD:
> > + return enc ? cc_mask : 0;
> > + default:
> > + return 0;
> > + }
> > +}
> > +
>
> > diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c
> > index eb7fbd85b77e..fa758247ab57 100644
> > --- a/arch/x86/mm/mem_encrypt_identity.c
> > +++ b/arch/x86/mm/mem_encrypt_identity.c
> > @@ -603,5 +603,5 @@ void __init sme_enable(struct boot_params *bp)
> > out:
> > physical_mask &= ~sme_me_mask;
> > if (sme_me_mask)
> > - cc_init(CC_VENDOR_AMD);
> > + cc_init(CC_VENDOR_AMD, sme_me_mask);
>
> Since you're adding the if statement, you can probably wrap the adjustment
> to physical_mask within the if, also (I guess in the previous patch). Not
> required, though.
Can do.
--
Kirill A. Shutemov
Powered by blists - more mailing lists