Re: [PATCH v2 2/9] KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall

From: Paolo Bonzini
Date: Sun Dec 06 2020 - 05:27:07 EST


On 02/12/20 22:22, Ashish Kalra wrote:
Hello Dave,

On Wed, Dec 02, 2020 at 04:54:20PM +0000, Dr. David Alan Gilbert wrote:
* Ashish Kalra (Ashish.Kalra@xxxxxxx) wrote:
From: Brijesh Singh <brijesh.singh@xxxxxxx>

This hypercall is used by the SEV guest to notify a change in the page
encryption status to the hypervisor. The hypercall should be invoked
only when the encryption attribute is changed from encrypted -> decrypted
and vice versa. By default all guest pages are considered encrypted.

Is it defined whether these are supposed to be called before or after
the the page type has been changed; is it change the type and then
notify or the other way around?

It doesn't matter. However, you have do it before writing to the page, and the content of the page is unspecified between the hypercall and the write to the page.

So you cannot for example encrypt a page in place (using the same PFN but different settings of the C bit), you need to do:

hypercall(); /* mark enc_data as encrypted */
/*
* The contents of enc_data is now undefined as it can change
* across migration.
*/
memset(enc_data, unenc_data, PAGE_SIZE);

Paolo