Re: [PATCH v8 020/103] KVM: TDX: create/destroy VM structure

From: Isaku Yamahata
Date: Fri Aug 26 2022 - 02:44:27 EST


On Tue, Aug 23, 2022 at 05:53:00PM -0700,
Erdem Aktas <erdemaktas@xxxxxxxxxx> wrote:

> On Sun, Aug 7, 2022 at 3:03 PM <isaku.yamahata@xxxxxxxxx> wrote:

> > +static void tdx_clear_page(unsigned long page)
> > +{
> > + const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
> > + unsigned long i;
> > +
> > + /*
> > + * Zeroing the page is only necessary for systems with MKTME-i:
> > + * when re-assign one page from old keyid to a new keyid, MOVDIR64B is
> > + * required to clear/write the page with new keyid to prevent integrity
> > + * error when read on the page with new keyid.
> > + */
>
> Are we saying that we do not need to use MOVDIR64B to clear pages with Li?

Yes. TDX module spec, Table 15.3: Checks on Memory Reads in Li mode says that
read with shared HKID doesn't result in #MC. Read of poisoned cache line is
another story, though.


> > + if (!static_cpu_has(X86_FEATURE_MOVDIR64B))
> > + return;
> > +
> > + for (i = 0; i < 4096; i += 64)
> > + /* MOVDIR64B [rdx], es:rdi */
> > + asm (".byte 0x66, 0x0f, 0x38, 0xf8, 0x3a"
> > + : : "d" (zero_page), "D" (page + i) : "memory");
> > +}
>
> According to the Software Developer Manual, mfence is required for a
> strong ordering on stores. Should we not use mfence here?

Right. I'll add __mb(). thanks for catching it.

--
Isaku Yamahata <isaku.yamahata@xxxxxxxxx>