[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1572060239-17401-5-git-send-email-zhenzhong.duan@oracle.com>
Date: Sat, 26 Oct 2019 11:23:58 +0800
From: Zhenzhong Duan <zhenzhong.duan@...cle.com>
To: linux-kernel@...r.kernel.org
Cc: kvm@...r.kernel.org, mtosatti@...hat.com,
joao.m.martins@...cle.com, rafael.j.wysocki@...el.com,
rkrcmar@...hat.com, pbonzini@...hat.com,
Zhenzhong Duan <zhenzhong.duan@...cle.com>
Subject: [PATCH 4/5] cpuidle-haltpoll: add a check to ensure grow start value is nonzero
dev->poll_limit_ns could be zeroed in certain cases (e.g. by
guest_halt_poll_shrink). If guest_halt_poll_grow_start is zero,
dev->poll_limit_ns will never be larger than zero.
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@...cle.com>
---
drivers/cpuidle/governors/haltpoll.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c
index 7a703d2..4b00d7a 100644
--- a/drivers/cpuidle/governors/haltpoll.c
+++ b/drivers/cpuidle/governors/haltpoll.c
@@ -77,7 +77,7 @@ static int haltpoll_select(struct cpuidle_driver *drv,
static void adjust_poll_limit(struct cpuidle_device *dev, unsigned int block_us)
{
- unsigned int val;
+ unsigned int val, grow_start;
u64 block_ns = block_us*NSEC_PER_USEC;
/* Grow cpu_halt_poll_us if
@@ -86,8 +86,17 @@ static void adjust_poll_limit(struct cpuidle_device *dev, unsigned int block_us)
if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns) {
val = dev->poll_limit_ns * guest_halt_poll_grow;
- if (val < guest_halt_poll_grow_start)
- val = guest_halt_poll_grow_start;
+ /*
+ * vcpu->halt_poll_ns needs a nonzero start point to grow if
+ * it's zero.
+ */
+ grow_start = guest_halt_poll_grow_start;
+ if (!grow_start)
+ grow_start = 1;
+
+ if (val < grow_start)
+ val = grow_start;
+
if (val > guest_halt_poll_ns)
val = guest_halt_poll_ns;
--
1.8.3.1
Powered by blists - more mailing lists