Re: [PATCHv2 23/29] x86/tdx: Add helper to convert memory between shared and private

From: Kirill A. Shutemov
Date: Wed Feb 09 2022 - 18:21:44 EST


On Tue, Feb 08, 2022 at 01:12:45PM +0100, Borislav Petkov wrote:
> On Mon, Jan 24, 2022 at 06:02:09PM +0300, Kirill A. Shutemov wrote:
> > + if (ret)
> > + ret = -EIO;
> > +
> > + if (ret || !enc)
>
> Is the second case here after the "||" the conversion-to-shared where it
> only needs to notify with MapGPA and return?

Right. Memory accepting is required on the way to private.

I will rewrite and comment this code to make it more readable.

> > + return ret;
> > +
> > + /*
> > + * For shared->private conversion, accept the page using
> > + * TDX_ACCEPT_PAGE TDX module call.
> > + */
> > + while (start < end) {
> > + /* Try 2M page accept first if possible */
> > + if (!(start & ~PMD_MASK) && end - start >= PMD_SIZE &&
> > + !tdx_accept_page(start, PG_LEVEL_2M)) {
>
> What happens here if the module doesn't accept the page? No error
> reporting, no error handling, no warning, nada?

If it fails we fallback to 4k accept below.

We only report error if 4k accept fails.

--
Kirill A. Shutemov