Re: [PATCH v5 00/13] KVM: mm: fd-based approach for supporting KVM guest private memory

From: Sean Christopherson
Date: Mon Apr 04 2022 - 18:08:22 EST


On Mon, Apr 04, 2022, Quentin Perret wrote:
> On Friday 01 Apr 2022 at 12:56:50 (-0700), Andy Lutomirski wrote:
> FWIW, there are a couple of reasons why I'd like to have in-place
> conversions:
>
> - one goal of pKVM is to migrate some things away from the Arm
> Trustzone environment (e.g. DRM and the likes) and into protected VMs
> instead. This will give Linux a fighting chance to defend itself
> against these things -- they currently have access to _all_ memory.
> And transitioning pages between Linux and Trustzone (donations and
> shares) is fast and non-destructive, so we really do not want pKVM to
> regress by requiring the hypervisor to memcpy things;

Is there actually a _need_ for the conversion to be non-destructive? E.g. I assume
the "trusted" side of things will need to be reworked to run as a pKVM guest, at
which point reworking its logic to understand that conversions are destructive and
slow-ish doesn't seem too onerous.

> - it can be very useful for protected VMs to do shared=>private
> conversions. Think of a VM receiving some data from the host in a
> shared buffer, and then it wants to operate on that buffer without
> risking to leak confidential informations in a transient state. In
> that case the most logical thing to do is to convert the buffer back
> to private, do whatever needs to be done on that buffer (decrypting a
> frame, ...), and then share it back with the host to consume it;

If performance is a motivation, why would the guest want to do two conversions
instead of just doing internal memcpy() to/from a private page? I would be quite
surprised if multiple exits and TLB shootdowns is actually faster, especially at
any kind of scale where zapping stage-2 PTEs will cause lock contention and IPIs.

> - similar to the previous point, a protected VM might want to
> temporarily turn a buffer private to avoid ToCToU issues;

Again, bounce buffer the page in the guest.

> - once we're able to do device assignment to protected VMs, this might
> allow DMA-ing to a private buffer, and make it shared later w/o
> bouncing.

Exposing a private buffer to a device doesn't requring in-place conversion. The
proper way to handle this would be to teach e.g. VFIO to retrieve the PFN from
the backing store. I don't understand the use case for sharing a DMA'd page at a
later time; with whom would the guest share the page? E.g. if a NIC has access to
guest private data then there should never be a need to convert/bounce the page.