Skip to content

Commit

Permalink
RISC-V: KVM: move preempt_disable() call in kvm_arch_vcpu_ioctl_run
Browse files Browse the repository at this point in the history
local_irq_disable provides stronger guarantees than preempt_disable so
calling the latter is redundant when interrupts are disabled. Instead,
explicitly disable preemption right before interrupts are enabled/disabled
to ensure that the time accounted in guest_timing_exit_irqoff
includes time taken by the guest or interrupts.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Anup Patel <anup@brainfault.org>
  • Loading branch information
Nikolay Borisov authored and Anup Patel committed Jul 29, 2022
1 parent cca986f commit fe283e5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions arch/riscv/kvm/vcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)

kvm_riscv_check_vcpu_requests(vcpu);

preempt_disable();

local_irq_disable();

/*
Expand Down Expand Up @@ -974,7 +972,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
kvm_request_pending(vcpu)) {
vcpu->mode = OUTSIDE_GUEST_MODE;
local_irq_enable();
preempt_enable();
kvm_vcpu_srcu_read_lock(vcpu);
continue;
}
Expand Down Expand Up @@ -1008,6 +1005,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
/* Syncup interrupts state with HW */
kvm_riscv_vcpu_sync_interrupts(vcpu);

preempt_disable();

/*
* We must ensure that any pending interrupts are taken before
* we exit guest timing so that timer ticks are accounted as
Expand Down

0 comments on commit fe283e5

Please sign in to comment.