On Mon, Mar 25, 2024 at 05:58:47PM +0800, Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx> wrote: > > +static void tdx_clear_page(unsigned long page_pa) > > +{ > > + const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0))); > > + void *page = __va(page_pa); > > + unsigned long 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. > > + * > > + * clflush doesn't flush cache with HKID set. The cache line could be > > + * poisoned (even without MKTME-i), clear the poison bit. > > + */ > > + for (i = 0; i < PAGE_SIZE; i += 64) > > + movdir64b(page + i, zero_page); > > + /* > > + * MOVDIR64B store uses WC buffer. Prevent following memory reads > > + * from seeing potentially poisoned cache. > > + */ > > + __mb(); > > Is __wmb() sufficient for this case? I don't think so because sfence is for other store. Here we care other load. > > + > > +static int tdx_do_tdh_mng_key_config(void *param) > > +{ > > + hpa_t *tdr_p = param; > > + u64 err; > > + > > + do { > > + err = tdh_mng_key_config(*tdr_p); > > + > > + /* > > + * If it failed to generate a random key, retry it because this > > + * is typically caused by an entropy error of the CPU's random > > Here you say "typically", is there other cause and is it safe to loop on > retry? No as long as I know. the TDX module returns KEY_GENERATION_FAILED only when rdrnd (or equivalent) failed. But I don't know the future. Let's delete "tyepically" because it seems confusing. -- Isaku Yamahata <isaku.yamahata@xxxxxxxxx>