From patchwork Wed Nov 6 11:54:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenzhong Duan X-Patchwork-Id: 11230107 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 696A415AB for ; Wed, 6 Nov 2019 11:56:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 447342075C for ; Wed, 6 Nov 2019 11:56:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="moDcX+2w" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730155AbfKFL4H (ORCPT ); Wed, 6 Nov 2019 06:56:07 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:40192 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725856AbfKFL4G (ORCPT ); Wed, 6 Nov 2019 06:56:06 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xA6Bs8Ph049980; Wed, 6 Nov 2019 11:55:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=EPKzfVRRWTGlG40d7rhnldMOWGwhBLJaJGkHe+80yiw=; b=moDcX+2wcqRmyIvB8FKPWFflJ+KDihvj4whWqFyfE71UiGmuXEcGhGKPKz9FEVAUbH5x B8NYPal0fGdPgvfDBKNL4KoNIBWB8AEtJMFNz42PELtAui17slpTuYsQf8+n4KNDxUkJ Zom61tgP25VcZthq73P1v19qA5b1galtl0XPq1zc73QravPV9ZTtnkTE5Ghd+V0JLCv4 vWf/9DK4tmPXPo35oLEfxdYPttPAW5yszxDrkHAIeY2uddzROD/Qb/+KFIDMP5XTisKo Itv9SGVp5JZ6a+oOi9sOiR+nNKxmSFlY5KfLLj7Llty49P8C2qEvmyy0zX7I2pVDd4Y/ Wg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2w11rq5m5s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Nov 2019 11:55:43 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xA6BsLeu051863; Wed, 6 Nov 2019 11:55:43 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2w31639sgh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Nov 2019 11:55:42 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id xA6BtffF022120; Wed, 6 Nov 2019 11:55:41 GMT Received: from z2.cn.oracle.com (/10.182.71.218) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Nov 2019 03:55:41 -0800 From: Zhenzhong Duan To: linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, rafael.j.wysocki@intel.com, joao.m.martins@oracle.com, mtosatti@redhat.com, kvm@vger.kernel.org, linux-pm@vger.kernel.org, Zhenzhong Duan Subject: [PATCH RESEND v2 1/4] cpuidle-haltpoll: ensure grow start value is nonzero Date: Wed, 6 Nov 2019 19:54:59 +0800 Message-Id: <1573041302-4904-2-git-send-email-zhenzhong.duan@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573041302-4904-1-git-send-email-zhenzhong.duan@oracle.com> References: <1573041302-4904-1-git-send-email-zhenzhong.duan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9432 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=808 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1911060119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9432 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=886 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1911060119 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org dev->poll_limit_ns could be zeroed in certain cases (e.g. by guest_halt_poll_ns = 0). If guest_halt_poll_grow_start is zero, dev->poll_limit_ns will never be bigger than zero. Use param callback to avoid writing zero to guest_halt_poll_grow_start. Signed-off-by: Zhenzhong Duan --- drivers/cpuidle/governors/haltpoll.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c index 7a703d2..660859d 100644 --- a/drivers/cpuidle/governors/haltpoll.c +++ b/drivers/cpuidle/governors/haltpoll.c @@ -20,6 +20,26 @@ #include #include +static int grow_start_set(const char *val, const struct kernel_param *kp) +{ + int ret; + unsigned int n; + + if (!val) + return -EINVAL; + + ret = kstrtouint(val, 0, &n); + if (ret || !n) + return -EINVAL; + + return param_set_uint(val, kp); +} + +static const struct kernel_param_ops grow_start_ops = { + .set = grow_start_set, + .get = param_get_uint, +}; + static unsigned int guest_halt_poll_ns __read_mostly = 200000; module_param(guest_halt_poll_ns, uint, 0644); @@ -33,7 +53,7 @@ /* value in us to start growing per-cpu halt_poll_ns */ static unsigned int guest_halt_poll_grow_start __read_mostly = 50000; -module_param(guest_halt_poll_grow_start, uint, 0644); +module_param_cb(guest_halt_poll_grow_start, &grow_start_ops, &guest_halt_poll_grow_start, 0644); /* allow shrinking guest halt poll */ static bool guest_halt_poll_allow_shrink __read_mostly = true; From patchwork Wed Nov 6 11:55:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenzhong Duan X-Patchwork-Id: 11230109 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 350B115AB for ; Wed, 6 Nov 2019 11:56:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 10E6F2075C for ; Wed, 6 Nov 2019 11:56:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="PLRZgckq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731402AbfKFL4w (ORCPT ); Wed, 6 Nov 2019 06:56:52 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:40812 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730103AbfKFL4w (ORCPT ); Wed, 6 Nov 2019 06:56:52 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xA6BsTNU050495; Wed, 6 Nov 2019 11:56:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=1qFf9aDf9zG7q8bwQc3g1PGXiQtKf91A0j9zzYWPIcQ=; b=PLRZgckqQFpZRbWAqCJMxIXLLeshs5d9pAS7ANQhjiOd04YPxgSf24Up7KnZU5a/FcDr SMaTi8/2iY38+pPrrIWZHzQJonbPtKx8bKaXxRSEHqcfGuyaW2GS85BPPLrHN36H08lX Nrl+o0RwE4beNEIplAdz0jV9cUCPHtaVV1yKTRbQKyBcgiWJkhNNxI4YN281wbwVqPze M/HttnqfQ2zXARVWM5QCCtPUeTLZxxdHC5PSdkMdTMeK8Jgx15wS3qZQytV0mwpjsoGl cRQoskpHNwac7KuE62BFQxjTxETcrCu4yXe/x4KQhvt9R/vpTlSRId6+K8gzIr+cQwPj oA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2w11rq5m9d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Nov 2019 11:56:30 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xA6BuFd8015241; Wed, 6 Nov 2019 11:56:29 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2w333x73sv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Nov 2019 11:56:28 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id xA6BtimS027549; Wed, 6 Nov 2019 11:55:44 GMT Received: from z2.cn.oracle.com (/10.182.71.218) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Nov 2019 03:55:44 -0800 From: Zhenzhong Duan To: linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, rafael.j.wysocki@intel.com, joao.m.martins@oracle.com, mtosatti@redhat.com, kvm@vger.kernel.org, linux-pm@vger.kernel.org, Zhenzhong Duan Subject: [PATCH RESEND v2 2/4] KVM: ensure grow start value is nonzero Date: Wed, 6 Nov 2019 19:55:00 +0800 Message-Id: <1573041302-4904-3-git-send-email-zhenzhong.duan@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573041302-4904-1-git-send-email-zhenzhong.duan@oracle.com> References: <1573041302-4904-1-git-send-email-zhenzhong.duan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9432 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=683 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1911060119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9432 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=761 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1911060119 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org vcpu->halt_poll_ns could be zeroed in certain cases (e.g. by halt_poll_ns = 0). If halt_poll_grow_start is zero, vcpu->halt_poll_ns will never be bigger than zero. Use param callback to avoid writing zero to halt_poll_grow_start. Signed-off-by: Zhenzhong Duan --- virt/kvm/kvm_main.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index d6f0696..359516b 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -69,6 +69,26 @@ MODULE_AUTHOR("Qumranet"); MODULE_LICENSE("GPL"); +static int grow_start_set(const char *val, const struct kernel_param *kp) +{ + int ret; + unsigned int n; + + if (!val) + return -EINVAL; + + ret = kstrtouint(val, 0, &n); + if (ret || !n) + return -EINVAL; + + return param_set_uint(val, kp); +} + +static const struct kernel_param_ops grow_start_ops = { + .set = grow_start_set, + .get = param_get_uint, +}; + /* Architectures should define their poll value according to the halt latency */ unsigned int halt_poll_ns = KVM_HALT_POLL_NS_DEFAULT; module_param(halt_poll_ns, uint, 0644); @@ -81,7 +101,7 @@ /* The start value to grow halt_poll_ns from */ unsigned int halt_poll_ns_grow_start = 10000; /* 10us */ -module_param(halt_poll_ns_grow_start, uint, 0644); +module_param_cb(halt_poll_ns_grow_start, &grow_start_ops, &halt_poll_ns_grow_start, 0644); EXPORT_SYMBOL_GPL(halt_poll_ns_grow_start); /* Default resets per-vcpu halt_poll_ns . */ From patchwork Wed Nov 6 11:55:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenzhong Duan X-Patchwork-Id: 11230117 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 854A615AB for ; Wed, 6 Nov 2019 11:57:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6039A217D7 for ; Wed, 6 Nov 2019 11:57:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="AAj4HeqD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727906AbfKFL5f (ORCPT ); Wed, 6 Nov 2019 06:57:35 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:38446 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727391AbfKFL5f (ORCPT ); Wed, 6 Nov 2019 06:57:35 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xA6BsBC5061334; Wed, 6 Nov 2019 11:57:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=QVEFup4AnIoDyOHVkZA0dQXS1IbWCtRajrTPgCoUWZk=; b=AAj4HeqDaK7eGF1Wk0zlu/g+kDbsR3UIJS7mmk/XbMbdwDv5gyrsMIxWXrouYnhJpnbQ HU0r1jFUkkeVz4suntwMLrHtEl3REKYeOXgl7AODNwEVpzxUhjMPiWeEZ3YuPdnHBbhm WJyPH5J2nKQLVP9NxVwnwnx6pWu6Xy3WM63LYynuNug2GpBhLzN2JumEsiC5KIsPiw3m o5cLNRTMwstUiLku4qcRJKhKvBWhxGkWSWus7jwdWsFHUVoojd7F+eoj8efCHwXdGzKM Z85FY3G3osH6VohTZW2sf2RME5T/VZR6giYX1XO39t56KeCKWW6HKvlmJONZHsiwnfcY ew== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2w117u5pfg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Nov 2019 11:57:17 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xA6Bv7WY057904; Wed, 6 Nov 2019 11:57:17 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2w31639squ-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Nov 2019 11:57:13 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id xA6BtkeA002264; Wed, 6 Nov 2019 11:55:46 GMT Received: from z2.cn.oracle.com (/10.182.71.218) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Nov 2019 03:55:46 -0800 From: Zhenzhong Duan To: linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, rafael.j.wysocki@intel.com, joao.m.martins@oracle.com, mtosatti@redhat.com, kvm@vger.kernel.org, linux-pm@vger.kernel.org, Zhenzhong Duan Subject: [PATCH RESEND v2 3/4] cpuidle-haltpoll: ensure cpu_halt_poll_us in right scope Date: Wed, 6 Nov 2019 19:55:01 +0800 Message-Id: <1573041302-4904-4-git-send-email-zhenzhong.duan@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573041302-4904-1-git-send-email-zhenzhong.duan@oracle.com> References: <1573041302-4904-1-git-send-email-zhenzhong.duan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9432 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1911060119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9432 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1911060119 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org As user can adjust guest_halt_poll_grow_start and guest_halt_poll_ns which leads to cpu_halt_poll_us beyond the two boundaries. This patch ensures cpu_halt_poll_us in that scope. If guest_halt_poll_shrink is 0, shrink the cpu_halt_poll_us to guest_halt_poll_grow_start instead of 0. To disable poll we can set guest_halt_poll_ns to 0. If user wrongly set guest_halt_poll_grow_start > guest_halt_poll_ns > 0, guest_halt_poll_ns take precedency and poll time is a fixed value of guest_halt_poll_ns. Signed-off-by: Zhenzhong Duan --- drivers/cpuidle/governors/haltpoll.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c index 660859d..4a39df4 100644 --- a/drivers/cpuidle/governors/haltpoll.c +++ b/drivers/cpuidle/governors/haltpoll.c @@ -97,32 +97,30 @@ 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 = dev->poll_limit_ns; u64 block_ns = block_us*NSEC_PER_USEC; /* Grow cpu_halt_poll_us if - * cpu_halt_poll_us < block_ns < guest_halt_poll_us + * cpu_halt_poll_us < block_ns <= guest_halt_poll_us */ - if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns) { + if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns && + guest_halt_poll_grow) val = dev->poll_limit_ns * guest_halt_poll_grow; - - if (val < guest_halt_poll_grow_start) - val = guest_halt_poll_grow_start; - if (val > guest_halt_poll_ns) - val = guest_halt_poll_ns; - - dev->poll_limit_ns = val; - } else if (block_ns > guest_halt_poll_ns && - guest_halt_poll_allow_shrink) { + else if (block_ns > guest_halt_poll_ns && + guest_halt_poll_allow_shrink) { unsigned int shrink = guest_halt_poll_shrink; - val = dev->poll_limit_ns; if (shrink == 0) - val = 0; + val = guest_halt_poll_grow_start; else val /= shrink; - dev->poll_limit_ns = val; } + if (val < guest_halt_poll_grow_start) + val = guest_halt_poll_grow_start; + if (val > guest_halt_poll_ns) + val = guest_halt_poll_ns; + + dev->poll_limit_ns = val; } /** From patchwork Wed Nov 6 11:55:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenzhong Duan X-Patchwork-Id: 11230097 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BDDC015AB for ; Wed, 6 Nov 2019 11:56:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 992872075C for ; Wed, 6 Nov 2019 11:56:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="eKPgNEYL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727906AbfKFL4E (ORCPT ); Wed, 6 Nov 2019 06:56:04 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:40140 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725856AbfKFL4D (ORCPT ); Wed, 6 Nov 2019 06:56:03 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xA6BsJOu050056; Wed, 6 Nov 2019 11:55:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=ITh4bqD9xE5YeUegJCsH0m9UXI6eEn2CS5ZImoYu/nk=; b=eKPgNEYLBCRGh1Pax3oS6cIJQHd5BE6cCoIie94e2RzspGhfduHmCKVrIGdWJ1CnVZ7O 2vnFPgOVNuJXhZ1hwynUHMZbzzdbuNrTTBuZHwK1xMzJB7DyOAsoyVRi79Vl6heh6AD4 PVDPj25M9Vb23d80Ah9JIJYVc+xu5BEsvh9VPSwwkkZg2VRm85XY/L+dg5fVmoi9Idx9 loyZVrJcHsP+7LjxMMcfsPv+ZYmJDctwQGUf4XPeO63deomVN/kIVSwjFjjK3J7/XXKj 3QIW2+oIfSjZuscvP3Wi38JJz6NS5XHp2A/8ZLzs8wo1MdYUzN+iAbnIkjPswuYprsEH 4w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2w11rq5m73-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Nov 2019 11:55:51 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xA6Btgxv061288; Wed, 6 Nov 2019 11:55:51 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2w3vr25smd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Nov 2019 11:55:51 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id xA6BtnVQ027585; Wed, 6 Nov 2019 11:55:49 GMT Received: from z2.cn.oracle.com (/10.182.71.218) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Nov 2019 03:55:48 -0800 From: Zhenzhong Duan To: linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, rafael.j.wysocki@intel.com, joao.m.martins@oracle.com, mtosatti@redhat.com, kvm@vger.kernel.org, linux-pm@vger.kernel.org, Zhenzhong Duan Subject: [PATCH RESEND v2 4/4] KVM: ensure vCPU halt_poll_us in right scope Date: Wed, 6 Nov 2019 19:55:02 +0800 Message-Id: <1573041302-4904-5-git-send-email-zhenzhong.duan@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573041302-4904-1-git-send-email-zhenzhong.duan@oracle.com> References: <1573041302-4904-1-git-send-email-zhenzhong.duan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9432 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=990 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1911060119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9432 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1911060119 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org As user can adjust halt_poll_ns_grow_start and halt_poll_ns which leads to vcpu->halt_poll_ns beyond the two boundaries. This patch ensures vcpu->halt_poll_ns in that scope after growing or shrinking. If halt_poll_ns_shrink is 0, shrink vcpu->halt_poll_ns to halt_poll_ns_grow_start instead of 0. To disable poll we can set halt_poll_ns to 0. In case user wrongly set halt_poll_ns_grow_start > halt_poll_ns > 0, halt_poll_ns take precedency and poll time is a fixed value of halt_poll_ns. This patch also simplifies branch check based on the guest haltpoll code. Signed-off-by: Zhenzhong Duan --- virt/kvm/kvm_main.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 359516b..b4fca66 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2308,9 +2308,15 @@ static void shrink_halt_poll_ns(struct kvm_vcpu *vcpu) old = val = vcpu->halt_poll_ns; shrink = READ_ONCE(halt_poll_ns_shrink); if (shrink == 0) - val = 0; - else + val = halt_poll_ns_grow_start; + else { val /= shrink; + if (val < halt_poll_ns_grow_start) + val = halt_poll_ns_grow_start; + } + + if (val > halt_poll_ns) + val = halt_poll_ns; vcpu->halt_poll_ns = val; trace_kvm_halt_poll_ns_shrink(vcpu->vcpu_id, val, old); @@ -2385,21 +2391,12 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) block_ns = ktime_to_ns(cur) - ktime_to_ns(start); if (!kvm_arch_no_poll(vcpu)) { - if (!vcpu_valid_wakeup(vcpu)) { + /* we had a long block, shrink polling */ + if (!vcpu_valid_wakeup(vcpu) || block_ns > halt_poll_ns) shrink_halt_poll_ns(vcpu); - } else if (halt_poll_ns) { - if (block_ns <= vcpu->halt_poll_ns) - ; - /* we had a long block, shrink polling */ - else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns) - shrink_halt_poll_ns(vcpu); - /* we had a short halt and our poll time is too small */ - else if (vcpu->halt_poll_ns < halt_poll_ns && - block_ns < halt_poll_ns) - grow_halt_poll_ns(vcpu); - } else { - vcpu->halt_poll_ns = 0; - } + /* we had a short block and our poll time is too small */ + else if (block_ns > vcpu->halt_poll_ns) + grow_halt_poll_ns(vcpu); } trace_kvm_vcpu_wakeup(block_ns, waited, vcpu_valid_wakeup(vcpu));