Skip to contentSkip to conversation

KVM: Don't actually set a request when evicting vCPUs for GFN cache invd

PATCH Sean Christopherson 2 participants 2 messages Feb 14, 2022 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Sean Christopherson

author maintainer
#1 lore raw
Quoted 14 lines · David

(Apologies if this is HTML but I'm half-way to Austria and the laptop is buried somewhere in the car, and access to work email with sane email apps is difficult.)

On 12 Feb 2022 03:05, Sean Christopherson <[email protected]> wrote:

Don't actually set a request bit in vcpu->requests when making a request purely to force a vCPU to exit the guest. Logging the request but not actually consuming it causes the vCPU to get stuck in an infinite loop during KVM_RUN because KVM sees a pending request and bails from VM-Enter to service the request.

Quoted 2 lines

Right, but there is no extant code which does this. The guest_uses_pa flag is unused.

Grr. A WARN or something would have been nice to have. Oh well.

Quoted 5 lines

The series came with a proof-of-concept that attempted using it for fixing nesting UAFs but it was just that — a proof of concept to demonstrate that the new design of GPC was sufficient to address that problem.

IIRC, said proof of concept did also actually consume the req in question,

It did. I saw that, but obviously didn't connect the dots to guest_uses_pa.

arch/x86/kvm/x86.c +2 -0
@@ -9826,6 +9826,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 
                if (kvm_check_request(KVM_REQ_UPDATE_CPU_DIRTY_LOGGING, vcpu))
                        static_call(kvm_x86_update_cpu_dirty_logging)(vcpu);
+               if (kvm_check_request(KVM_REQ_GPC_INVALIDATE, vcpu))
+                       ; /* Nothing to do. It just wanted to wake us */
 
Quoted 3 lines

and one of the existing test cases did exercise it with an additional mmap torture added? Of course until we have kernel code that *does* this, it's hard to exercise it from userspace :)

Indeed. I'll send a new version with a different changelog, that way we're not leaving a trap for developers and each architecture doesn't need to manually handle the request.

Thanks!

#2 lore raw
Quoted 14 lines · Sean Christopherson
Quoted 13 lines · David

(Apologies if this is HTML but I'm half-way to Austria and the laptop is buried somewhere in the car, and access to work email with sane email apps is difficult.)

On 12 Feb 2022 03:05, Sean Christopherson <[email protected]> wrote:

Don't actually set a request bit in vcpu->requests when making a request purely to force a vCPU to exit the guest. Logging the request but not actually consuming it causes the vCPU to get stuck in an infinite loop during KVM_RUN because KVM sees a pending request and bails from VM-Enter to service the request.

Quoted 4 lines
Quoted 2 lines

Right, but there is no extant code which does this. The guest_uses_pa flag is unused.

Grr. A WARN or something would have been nice to have. Oh well.

I don't think it was clear yet what the 'wrong' behaviour would we that we should warn about, since we really hadn't finished defining the 'correct' usage :)

Quoted 11 lines
Quoted 5 lines

The series came with a proof-of-concept that attempted using it for fixing nesting UAFs but it was just that — a proof of concept to demonstrate that the new design of GPC was sufficient to address that problem.

IIRC, said proof of concept did also actually consume the req in question,

It did. I saw that, but obviously didn't connect the dots to guest_uses_pa.

arch/x86/kvm/x86.c static int vcpu_enter_guest(struct kvm_vcpu *vcpu) · line 9831

Quoted 6 lines
arch/x86/kvm/x86.c +2 -0
@@ -9826,6 +9826,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 
                if (kvm_check_request(KVM_REQ_UPDATE_CPU_DIRTY_LOGGING, vcpu))
                        static_call(kvm_x86_update_cpu_dirty_logging)(vcpu);
+               if (kvm_check_request(KVM_REQ_GPC_INVALIDATE, vcpu))
+                       ; /* Nothing to do. It just wanted to wake us */
 

Right. That's a later iteration. I originally *did* actually use it to trigger an action, IIRC, but Paolo suggested we do it differently.

I also pondered having each GPC able to raise a specific request, and set the KVM_REQ_xxx bit in the GPC itself. That just made the loop in invalidate_start() a bit more complex though because of the way that it wakes the vCPUs after it's done its iteration and collected them in a cpumask. So it seemed like premature deoptimisation; we can add that in future if we really do need it, and looks like we're going in the opposite direction.

Quoted 7 lines
Quoted 3 lines

and one of the existing test cases did exercise it with an additional mmap torture added? Of course until we have kernel code that *does* this, it's hard to exercise it from userspace :)

Indeed. I'll send a new version with a different changelog, that way we're not leaving a trap for developers and each architecture doesn't need to manually handle the request.

Ack, thanks.