2022-07-15 23:18:11

by Jim Mattson

[permalink] [raw]
Subject: Re: [PATCH 1/4] KVM: x86: Reject loading KVM if host.PAT[0] != WB

On Fri, Jul 15, 2022 at 4:02 PM Sean Christopherson <[email protected]> wrote:
>
> Reject KVM if entry '0' in the host's IA32_PAT MSR is not programmed to
> writeback (WB) memtype. KVM subtly relies on IA32_PAT entry '0' to be
> programmed to WB by leaving the PAT bits in shadow paging and NPT SPTEs
> as '0'. If something other than WB is in PAT[0], at _best_ guests will
> suffer very poor performance, and at worst KVM will crash the system by
> breaking cache-coherency expecations (e.g. using WC for guest memory).
>
> Signed-off-by: Sean Christopherson <[email protected]>
> ---
What if someone changes the host's PAT to violate this rule *after*
kvm is loaded?


2022-07-15 23:22:40

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 1/4] KVM: x86: Reject loading KVM if host.PAT[0] != WB

On Fri, Jul 15, 2022, Jim Mattson wrote:
> On Fri, Jul 15, 2022 at 4:02 PM Sean Christopherson <[email protected]> wrote:
> >
> > Reject KVM if entry '0' in the host's IA32_PAT MSR is not programmed to
> > writeback (WB) memtype. KVM subtly relies on IA32_PAT entry '0' to be
> > programmed to WB by leaving the PAT bits in shadow paging and NPT SPTEs
> > as '0'. If something other than WB is in PAT[0], at _best_ guests will
> > suffer very poor performance, and at worst KVM will crash the system by
> > breaking cache-coherency expecations (e.g. using WC for guest memory).
> >
> > Signed-off-by: Sean Christopherson <[email protected]>
> > ---
> What if someone changes the host's PAT to violate this rule *after*
> kvm is loaded?

Then KVM (and probably many other things in the kernel) is hosed. The same argument
(that KVM isn't paranoid enough) can likely be made for a number of MSRs and critical
registers.

2022-07-18 10:25:06

by Maxim Levitsky

[permalink] [raw]
Subject: Re: [PATCH 1/4] KVM: x86: Reject loading KVM if host.PAT[0] != WB

On Fri, 2022-07-15 at 23:18 +0000, Sean Christopherson wrote:
> On Fri, Jul 15, 2022, Jim Mattson wrote:
> > On Fri, Jul 15, 2022 at 4:02 PM Sean Christopherson <[email protected]> wrote:
> > >
> > > Reject KVM if entry '0' in the host's IA32_PAT MSR is not programmed to
> > > writeback (WB) memtype.  KVM subtly relies on IA32_PAT entry '0' to be
> > > programmed to WB by leaving the PAT bits in shadow paging and NPT SPTEs
> > > as '0'.  If something other than WB is in PAT[0], at _best_ guests will
> > > suffer very poor performance, and at worst KVM will crash the system by
> > > breaking cache-coherency expecations (e.g. using WC for guest memory).
> > >
> > > Signed-off-by: Sean Christopherson <[email protected]>
> > > ---
> > What if someone changes the host's PAT to violate this rule *after*
> > kvm is loaded?
>
> Then KVM (and probably many other things in the kernel) is hosed.  The same argument
> (that KVM isn't paranoid enough) can likely be made for a number of MSRs and critical
> registers.
>

I was thinking about the same thing and I also 100% agree with the above.

Reviewed-by: Maxim Levitsky <[email protected]>

Best regards,
Maxim Levitsky