Re: [PATCH 2/4] KVM: x86: Introduce paravirt feature CR0/CR4 pinning

From: Sean Christopherson
Date: Tue Jul 07 2020 - 17:12:50 EST


On Thu, Jun 18, 2020 at 07:51:10AM -0700, Dave Hansen wrote:
> On 6/18/20 7:43 AM, Andersen, John wrote:
> > On Thu, Jun 18, 2020 at 07:18:09AM -0700, Dave Hansen wrote:
> >> On 6/17/20 12:07 PM, John Andersen wrote:
> >>> +#define KVM_CR0_PIN_ALLOWED (X86_CR0_WP)
> >>> +#define KVM_CR4_PIN_ALLOWED (X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_UMIP)
> >>
> >> Why *is* there an allowed set? Why don't we just allow everything?
> >>
> >> Shouldn't we also pin any unknown bits? The CR4.FSGSBASE bit is an
> >> example of something that showed up CPUs without Linux knowing about it.
> >> If set, it causes problems. This set couldn't have helped FSGSBASE
> >> because it is not in the allowed set.
> >>
> >> Let's say Intel loses its marbles and adds a CR4 bit that lets userspace
> >> write to kernel memory. Linux won't set it, but an attacker would go
> >> after it, first thing.

That's an orthogonal to pinning. KVM never lets the guest set CR4 bits that
are unknown to KVM. Supporting CR4.NO_MARBLES would require an explicit KVM
change to allow it to be set by the guest, and would also require a userspace
VMM to expose NO_MARBLES to the guest.

That being said, this series should supporting pinning as much as possible,
i.e. if the bit can be exposed to the guest and doesn't require special
handling in KVM, allow it to be pinned. E.g. TS is a special case because
pinning would require additional emulator support and IMO isn't interesting
enough to justify the extra complexity. At a glance, I don't see anything
that would prevent pinning FSGSBASE.