Skip to contentSkip to conversation

KVM: PPC: Book3S HV: exit halt polling on need_resched() as well

PATCH In review Wanpeng Li 2 participants 3 messages May 13, 2021 – May 17, 2021

Subsystems (3)
lore
Share & tools
lore

Wanpeng Li

author
#0 lore raw

PATCH v2 1/4 KVM: PPC: Book3S HV: exit halt polling on need_resched() as well

From: Wanpeng Li <[email protected]>

Inspired by commit 262de4102c7bb8 (kvm: exit halt polling on need_resched() as well), CFS_BANDWIDTH throttling will use resched_task() when there is just one task to get the task to block. It was likely allowing VMs to overrun their quota when halt polling. Due to PPC implements an arch specific halt polling logic, we should add the need_resched() checking there as well.

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]>

---
v1 -> v2:
* update patch description

 arch/powerpc/kvm/book3s_hv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +2 -1
index 28a80d2..6199397 100644
@@ -3936,7 +3936,8 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
 				break;
 			}
 			cur = ktime_get();
-		} while (single_task_running() && ktime_before(cur, stop));
+		} while (single_task_running() && !need_resched() &&
+			 ktime_before(cur, stop));
 
 		spin_lock(&vc->lock);
 		vc->vcore_state = VCORE_INACTIVE;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 28 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

Inspired by commit 262de4102c7bb8 (kvm: exit halt polling on need_resched() as well), CFS_BANDWIDTH throttling will use resched_task() when there is just one task to get the task to block. It was likely allowing VMs to overrun their quota when halt polling. Due to PPC implements an arch specific halt polling logic, we should add the need_resched() checking there as well.

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]>

---
v1 -> v2:
* update patch description

 arch/powerpc/kvm/book3s_hv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +0 -0
index 28a80d2..6199397 100644

arch/powerpc/kvm/book3s_hv.c static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) · line 3940

Quoted 6 lines
arch/powerpc/kvm/book3s_hv.c +2 -1
@@ -3936,7 +3936,8 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
                                break;
                        }
                        cur = ktime_get();
-               } while (single_task_running() && ktime_before(cur, stop));
+               } while (single_task_running() && !need_resched() &&
+                        ktime_before(cur, stop));

Consider moving this condition to a helper function that can be shared between book3s and the generic halt-polling loop.

Quoted 6 lines
arch/powerpc/kvm/book3s_hv.c +0 -1
                spin_lock(&vc->lock);
                vc->vcore_state = VCORE_INACTIVE;
--

2.7.4

author
#2 lore raw
Quoted 25 lines · David Matlack
Quoted 23 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

Inspired by commit 262de4102c7bb8 (kvm: exit halt polling on need_resched() as well), CFS_BANDWIDTH throttling will use resched_task() when there is just one task to get the task to block. It was likely allowing VMs to overrun their quota when halt polling. Due to PPC implements an arch specific halt polling logic, we should add the need_resched() checking there as well.

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]>

---
v1 -> v2:
* update patch description

 arch/powerpc/kvm/book3s_hv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines

arch/powerpc/kvm/book3s_hv.c static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) · line 3940

Quoted 11 lines
arch/powerpc/kvm/book3s_hv.c +2 -1
index 28a80d2..6199397 100644
@@ -3936,7 +3936,8 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
                                break;
                        }
                        cur = ktime_get();
-               } while (single_task_running() && ktime_before(cur, stop));
+               } while (single_task_running() && !need_resched() &&
+                        ktime_before(cur, stop));

Consider moving this condition to a helper function that can be shared between book3s and the generic halt-polling loop.

Will do in the next version, thanks for review. :)

Wanpeng