Skip to content

Commit

Permalink
KVM: PPC: exit halt polling on need_resched()
Browse files Browse the repository at this point in the history
This is inspired by commit 262de41 (kvm: exit halt polling on
need_resched() as well). Due to PPC implements an arch specific halt
polling logic, we have to the need_resched() check there as well. This
patch adds a helper function that can be shared between book3s and generic
halt-polling loops.

Reviewed-by: David Matlack <[email protected]>
Reviewed-by: Venkatesh Srinivas <[email protected]>
Cc: Ben Segall <[email protected]>
Cc: Venkatesh Srinivas <[email protected]>
Cc: Jim Mattson <[email protected]>
Cc: David Matlack <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Suraj Jitindar Singh <[email protected]>
Signed-off-by: Wanpeng Li <[email protected]>
Message-Id: <[email protected]>
[Make the function inline. - Paolo]
Signed-off-by: Paolo Bonzini <[email protected]>
Wanpeng Li authored and bonzini committed May 27, 2021
1 parent 28a4aa1 commit 6bd5b74
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion arch/powerpc/kvm/book3s_hv.c
Original file line number Diff line number Diff line change
@@ -3936,7 +3936,7 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
break;
}
cur = ktime_get();
} while (single_task_running() && ktime_before(cur, stop));
} while (kvm_vcpu_can_poll(cur, stop));

spin_lock(&vc->lock);
vc->vcore_state = VCORE_INACTIVE;
6 changes: 6 additions & 0 deletions include/linux/kvm_host.h
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
#include <linux/spinlock.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/sched/stat.h>
#include <linux/bug.h>
#include <linux/minmax.h>
#include <linux/mm.h>
@@ -265,6 +266,11 @@ static inline bool kvm_vcpu_mapped(struct kvm_host_map *map)
return !!map->hva;
}

static inline bool kvm_vcpu_can_poll(ktime_t cur, ktime_t stop)
{
return single_task_running() && !need_resched() && ktime_before(cur, stop);
}

/*
* Sometimes a large or cross-page mmio needs to be broken up into separate
* exits for userspace servicing.
3 changes: 1 addition & 2 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
@@ -2973,8 +2973,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
goto out;
}
poll_end = cur = ktime_get();
} while (single_task_running() && !need_resched() &&
ktime_before(cur, stop));
} while (kvm_vcpu_can_poll(cur, stop));
}

prepare_to_rcuwait(&vcpu->wait);

0 comments on commit 6bd5b74

Please sign in to comment.