# \[PATCH 5.12 273/363\] kvm: exit halt polling on need\_resched() as well

- From: Greg Kroah-Hartman \<gregkh@linuxfoundation.org\>
- Date: 2021-05-17 14:35:17 
- List: stable
- Page: https://ratatoskr.run/stable/2021/05/1380036
- Thread: https://ratatoskr.run/stable/2021/05/1379699/t/4.md

```text
From: Benjamin Segall <bsegall@google.com>

commit 262de4102c7bb8e59f26a967a8ffe8cce85cc537 upstream.

single_task_running() is usually more general than need_resched()
but CFS_BANDWIDTH throttling will use resched_task() when there
is just one task to get the task to block. This was causing
long-need_resched warnings and was likely allowing VMs to
overrun their quota when halt polling.

Signed-off-by: Ben Segall <bsegall@google.com>
Signed-off-by: Venkatesh Srinivas <redacted>
Message-Id: [ref]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: <redacted>
Reviewed-by: Jim Mattson <redacted>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 virt/kvm/kvm_main.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2838,7 +2838,8 @@ void kvm_vcpu_block(struct kvm_vcpu *vcp
 				goto out;
 			}
 			poll_end = cur = ktime_get();
-		} while (single_task_running() && ktime_before(cur, stop));
+		} while (single_task_running() && !need_resched() &&
+			 ktime_before(cur, stop));
 	}
 
 	prepare_to_rcuwait(&vcpu->wait);


```
