Re: [PATCH 0/5] KVM: VMX: Drop MTRR virtualization, honor guest PAT

From: Paul E. McKenney
Date: Wed Jun 05 2024 - 20:03:19 EST


On Wed, Jun 05, 2024 at 04:20:34PM -0700, Sean Christopherson wrote:
> On Fri, 08 Mar 2024 17:09:24 -0800, Sean Christopherson wrote:
> > First, rip out KVM's support for virtualizing guest MTRRs on VMX. The
> > code is costly to main, a drag on guest boot performance, imperfect, and
> > not required for functional correctness with modern guest kernels. Many
> > details in patch 1's changelog.
> >
> > With MTRR virtualization gone, always honor guest PAT on Intel CPUs that
> > support self-snoop, as such CPUs are guaranteed to maintain coherency
> > even if the guest is aliasing memtypes, e.g. if the host is using WB but
> > the guest is using WC. Honoring guest PAT is desirable for use cases
> > where the guest must use WC when accessing memory that is DMA'd from a
> > non-coherent device that does NOT bounce through VFIO, e.g. for mediated
> > virtual GPUs.
> >
> > [...]
>
> Applied to kvm-x86 mtrrs, to get as much testing as possible before a potential
> merge in 6.11.
>
> Paul, if you can take a gander at patch 3, it would be much appreciated.
>
> Thanks!
>
> [1/5] KVM: x86: Remove VMX support for virtualizing guest MTRR memtypes
> https://github.com/kvm-x86/linux/commit/0a7b73559b39
> [2/5] KVM: VMX: Drop support for forcing UC memory when guest CR0.CD=1
> https://github.com/kvm-x86/linux/commit/e1548088ff54
> [3/5] srcu: Add an API for a memory barrier after SRCU read lock
> https://github.com/kvm-x86/linux/commit/fcfe671e0879

Looks straightforward enough. We could combine this with the existing
smp_mb__after_srcu_read_unlock(), but if we did that, someone would no
doubt come up with some clever optimization that provided a full barrier
in srcu_read_lock() but not in srcu_read_unlock() or vice versa. So:

Reviewed-by: Paul E. McKenney <paulmck@xxxxxxxxxx>

> [4/5] KVM: x86: Ensure a full memory barrier is emitted in the VM-Exit path
> https://github.com/kvm-x86/linux/commit/eb8d8fc29286
> [5/5] KVM: VMX: Always honor guest PAT on CPUs that support self-snoop
> https://github.com/kvm-x86/linux/commit/95200f24b862
>
> --
> https://github.com/kvm-x86/linux/tree/next