From patchwork Tue Sep 3 13:24:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11127865 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 732D713B1 for ; Tue, 3 Sep 2019 13:25:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BCFF2343A for ; Tue, 3 Sep 2019 13:25:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="WNRLaYpH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729343AbfICNZJ (ORCPT ); Tue, 3 Sep 2019 09:25:09 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:55742 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729138AbfICNZI (ORCPT ); Tue, 3 Sep 2019 09:25:08 -0400 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 x83DO83k046784; Tue, 3 Sep 2019 13:24:59 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 : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=TsBg3V/tl4aUXqQSiAeslWhIsTsbykMZwpQqZWYisWA=; b=WNRLaYpHRBuP3zb6p2taNRXBUo6YOe+dD1O0DJadXYjIfejdgWZ0Wmum/bICxKIzpORF gyvXV/2Cpph6LUPRnCjQiwZ5HXi/VQ1Ogd+Wx3wngW6kWYkfF2XKMq0MRDFncr6aC+x3 sOqNX1au3nIpv7937lSUkdEmj4k/u9NDHj9uF0+rejUdcyQvDNlYsGQe6qWmBo5oPTok aA+4fu3MgMZ4Hq1FzSVzvB8MjyCjU7yxVb/OPxx3DcTZmuhNfgD4FOKcjbiczJWuhEMC msk7r1ouS200bgpEw+5vAUV4QnfubslMtmfDRMZMg9914Ep5SobgqpTGk3x1Yvmm6zT/ 3g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2usrvsr1u4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2019 13:24:59 +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 x83DO4Fu165077; Tue, 3 Sep 2019 13:24:59 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2uryv6py47-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2019 13:24:58 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x83DOu87023850; Tue, 3 Sep 2019 13:24:56 GMT Received: from paddy.uk.oracle.com (/10.175.205.235) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Sep 2019 06:24:55 -0700 From: Joao Martins To: linux-pm@vger.kernel.org Cc: Joao Martins , "Rafael J. Wysocki" , Daniel Lezcano , linux-kernel@vger.kernel.org, Marcelo Tosatti , kvm@vger.kernel.org Subject: [PATCH v2 1/4] cpuidle: allow governor switch on cpuidle_register_driver() Date: Tue, 3 Sep 2019 14:24:41 +0100 Message-Id: <20190903132444.11808-2-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190903132444.11808-1-joao.m.martins@oracle.com> References: <20190903132444.11808-1-joao.m.martins@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9368 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-1906280000 definitions=main-1909030142 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9368 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-1906280000 definitions=main-1909030142 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The recently introduced haltpoll driver is largely only useful with haltpoll governor. To allow drivers to associate with a particular idle behaviour, add a @governor property to 'struct cpuidle_driver' and thus allow a cpuidle driver to switch to a *preferred* governor on idle driver registration. We save the previous governor, and when an idle driver is unregistered we switch back to that. The @governor can be overridden by cpuidle.governor= boot param or alternatively be ignored if the governor doesn't exist. Signed-off-by: Joao Martins --- drivers/cpuidle/cpuidle.h | 1 + drivers/cpuidle/driver.c | 26 ++++++++++++++++++++++++++ drivers/cpuidle/governor.c | 6 +++--- include/linux/cpuidle.h | 3 +++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/drivers/cpuidle/cpuidle.h b/drivers/cpuidle/cpuidle.h index d6613101af92..c046f49c1920 100644 --- a/drivers/cpuidle/cpuidle.h +++ b/drivers/cpuidle/cpuidle.h @@ -22,6 +22,7 @@ extern void cpuidle_install_idle_handler(void); extern void cpuidle_uninstall_idle_handler(void); /* governors */ +extern struct cpuidle_governor *cpuidle_find_governor(const char *str); extern int cpuidle_switch_governor(struct cpuidle_governor *gov); /* sysfs */ diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c index dc32f34e68d9..16a3f6c5ad69 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -87,6 +87,7 @@ static inline int __cpuidle_set_driver(struct cpuidle_driver *drv) #else static struct cpuidle_driver *cpuidle_curr_driver; +static struct cpuidle_governor *cpuidle_prev_governor; /** * __cpuidle_get_cpu_driver - return the global cpuidle driver pointer. @@ -254,12 +255,25 @@ static void __cpuidle_unregister_driver(struct cpuidle_driver *drv) */ int cpuidle_register_driver(struct cpuidle_driver *drv) { + struct cpuidle_governor *gov; int ret; spin_lock(&cpuidle_driver_lock); ret = __cpuidle_register_driver(drv); spin_unlock(&cpuidle_driver_lock); + if (!ret && !strlen(param_governor) && drv->governor && + (cpuidle_get_driver() == drv)) { + mutex_lock(&cpuidle_lock); + gov = cpuidle_find_governor(drv->governor); + if (gov) { + cpuidle_prev_governor = cpuidle_curr_governor; + if (cpuidle_switch_governor(gov) < 0) + cpuidle_prev_governor = NULL; + } + mutex_unlock(&cpuidle_lock); + } + return ret; } EXPORT_SYMBOL_GPL(cpuidle_register_driver); @@ -274,9 +288,21 @@ EXPORT_SYMBOL_GPL(cpuidle_register_driver); */ void cpuidle_unregister_driver(struct cpuidle_driver *drv) { + bool enabled = (cpuidle_get_driver() == drv); + spin_lock(&cpuidle_driver_lock); __cpuidle_unregister_driver(drv); spin_unlock(&cpuidle_driver_lock); + + if (!enabled) + return; + + mutex_lock(&cpuidle_lock); + if (cpuidle_prev_governor) { + if (!cpuidle_switch_governor(cpuidle_prev_governor)) + cpuidle_prev_governor = NULL; + } + mutex_unlock(&cpuidle_lock); } EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c index 2e3e14192bee..08707759469e 100644 --- a/drivers/cpuidle/governor.c +++ b/drivers/cpuidle/governor.c @@ -22,12 +22,12 @@ LIST_HEAD(cpuidle_governors); struct cpuidle_governor *cpuidle_curr_governor; /** - * __cpuidle_find_governor - finds a governor of the specified name + * cpuidle_find_governor - finds a governor of the specified name * @str: the name * * Must be called with cpuidle_lock acquired. */ -static struct cpuidle_governor * __cpuidle_find_governor(const char *str) +struct cpuidle_governor *cpuidle_find_governor(const char *str) { struct cpuidle_governor *gov; @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov) return -ENODEV; mutex_lock(&cpuidle_lock); - if (__cpuidle_find_governor(gov->name) == NULL) { + if (cpuidle_find_governor(gov->name) == NULL) { ret = 0; list_add_tail(&gov->governor_list, &cpuidle_governors); if (!cpuidle_curr_governor || diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 1a9f54eb3aa1..2dc4c6b19c25 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -121,6 +121,9 @@ struct cpuidle_driver { /* the driver handles the cpus in cpumask */ struct cpumask *cpumask; + + /* preferred governor to switch at register time */ + const char *governor; }; #ifdef CONFIG_CPU_IDLE From patchwork Tue Sep 3 13:24:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11127877 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 C93D013B1 for ; Tue, 3 Sep 2019 13:25:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA02523711 for ; Tue, 3 Sep 2019 13:25:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="N5B6PkiJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729305AbfICNZI (ORCPT ); Tue, 3 Sep 2019 09:25:08 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33548 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729015AbfICNZI (ORCPT ); Tue, 3 Sep 2019 09:25:08 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x83DOBrM042257; Tue, 3 Sep 2019 13:25:00 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 : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=+VllEEyT4iEiGSQ5dF27BA09Kf2mwJdY7Ifdj5cpMaE=; b=N5B6PkiJt+VTDiKACfjykl3rhZtFTGRAvnf99gPhmKspLwggZAjajpgpEnt2HPMBk14d el+C+0DQMKBDE/qq+U6GIGGwgpCYKo8o9CD3MOSjHVnr/Z+C+0r8W5Nt88WxQnmYmEN+ JWz1v2o4Uo0Cyk2Gyb3Pnm9Ii0xtYm+J8ESK/KJvRzbNQftZKa/zj4m44595Zp+DwUJv dpY53+fm/eHqN5Mr1O8dsMeqWUxQT/qUImccGr1rUcpjjcJtZkDWX3rTuMaSboKaFp1B Zh+4ldG87qW3sgmzBh76j9JyerOu4OmfuofcyL98Noys/CZonsukB9JfHD54YBcVmlkT eQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2usrw8r1f6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2019 13:24:59 +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 x83DO3DH164824; Tue, 3 Sep 2019 13:24:59 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2uryv6py59-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2019 13:24:59 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x83DOw7a016999; Tue, 3 Sep 2019 13:24:58 GMT Received: from paddy.uk.oracle.com (/10.175.205.235) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Sep 2019 06:24:58 -0700 From: Joao Martins To: linux-pm@vger.kernel.org Cc: Joao Martins , "Rafael J. Wysocki" , Daniel Lezcano , linux-kernel@vger.kernel.org, Marcelo Tosatti , kvm@vger.kernel.org Subject: [PATCH v2 2/4] cpuidle-haltpoll: set haltpoll as preferred governor Date: Tue, 3 Sep 2019 14:24:42 +0100 Message-Id: <20190903132444.11808-3-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190903132444.11808-1-joao.m.martins@oracle.com> References: <20190903132444.11808-1-joao.m.martins@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9368 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=359 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909030142 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9368 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=412 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909030142 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Right now, guest current governors have the following ratings: * ladder -> 10 * teo -> 19 * menu -> 20 * haltpoll -> 21 * ladder + nohz=off -> 25 haltpoll governor got introduced and it is now the default governor given its highest rating -- with ladder+nohz being the exception -- regardless of idle driver in the guest. An example of an undesirable case is x86 KVM guests with MWAIT which have intel_idle registered first, and consequently will have haltpoll be used as governor which would get limited to a poll state and state 1 and the other states wouldn't get used. To keep the previous defaults we decrease rating of governor to 9 (below current lowest rating) and thus rely on @governor switch on cpuidle_register_driver() to tie in haltpoll idle driver and governor together. Signed-off-by: Joao Martins --- drivers/cpuidle/cpuidle-haltpoll.c | 1 + drivers/cpuidle/governors/haltpoll.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-haltpoll.c index 56d8ab814466..519e90d125cf 100644 --- a/drivers/cpuidle/cpuidle-haltpoll.c +++ b/drivers/cpuidle/cpuidle-haltpoll.c @@ -34,6 +34,7 @@ static int default_enter_idle(struct cpuidle_device *dev, static struct cpuidle_driver haltpoll_driver = { .name = "haltpoll", + .governor = "haltpoll", .owner = THIS_MODULE, .states = { { /* entry 0 is for polling */ }, diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c index 797477bda486..7a703d2e0064 100644 --- a/drivers/cpuidle/governors/haltpoll.c +++ b/drivers/cpuidle/governors/haltpoll.c @@ -133,7 +133,7 @@ static int haltpoll_enable_device(struct cpuidle_driver *drv, static struct cpuidle_governor haltpoll_governor = { .name = "haltpoll", - .rating = 21, + .rating = 9, .enable = haltpoll_enable_device, .select = haltpoll_select, .reflect = haltpoll_reflect, From patchwork Tue Sep 3 13:24:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11127867 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 E6EA514E5 for ; Tue, 3 Sep 2019 13:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5D2C23431 for ; Tue, 3 Sep 2019 13:25:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="WeeYkWVp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729431AbfICNZT (ORCPT ); Tue, 3 Sep 2019 09:25:19 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:41590 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729392AbfICNZR (ORCPT ); Tue, 3 Sep 2019 09:25:17 -0400 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 x83DOBP5048240; Tue, 3 Sep 2019 13:25:03 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 : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=qv8voy15J0vDwU5XKrHvG6gwYjAjx6li7t3EIYvElEU=; b=WeeYkWVp3yhIf6PElEXi0hqWcsoYlkJvd5o+7ATzhAfpje+vFzM31IK9Yd0P8+trzCjO ju8YAFoRHqIqiH5V/xtN2xU7qK8YbvA5Zzgby68jxGXo0QO1QPjXCxOM/iNdIn/aHEA6 VCWoqtoWZ01XZw0tWbiZ8+KB1g1HdcQ5CMKyqLRh0bgEDW50SMXhhehWO+bETfCSZI+i 54pHzRsLAzwFZOA4oujPuwyZCmenute0Gccgm3v3LwwDzGXrtEZLNPS0uNOMNaTSstDg YGvpN3VQno66WrbyUFvXI3AgXc7QWpPX37x0Lxl+VLJwphM3qKRrdO+LWMiw0aDt2OOg Jg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2usrvcg353-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2019 13:25:03 +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 x83DOFM3129252; Tue, 3 Sep 2019 13:25:02 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2us5pguu4n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2019 13:25:02 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x83DP1rq017032; Tue, 3 Sep 2019 13:25:01 GMT Received: from paddy.uk.oracle.com (/10.175.205.235) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Sep 2019 06:25:01 -0700 From: Joao Martins To: linux-pm@vger.kernel.org Cc: Joao Martins , "Rafael J. Wysocki" , Daniel Lezcano , linux-kernel@vger.kernel.org, Marcelo Tosatti , kvm@vger.kernel.org Subject: [PATCH v2 3/4] cpuidle-haltpoll: return -ENODEV on modinit failure Date: Tue, 3 Sep 2019 14:24:43 +0100 Message-Id: <20190903132444.11808-4-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190903132444.11808-1-joao.m.martins@oracle.com> References: <20190903132444.11808-1-joao.m.martins@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9368 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=884 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909030142 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9368 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=942 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909030142 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When a user loads cpuidle-haltpoll on a non KVM guest the module will successfully load, even though idle driver registration didn't take place. We should instead return -ENODEV signaling the user that the driver can't be loaded, like other error paths in haltpoll_init(). An example of such error paths is when we return -EBUSY when attempting to register an idle driver when it had one already (e.g. intel_idle loads at boot and then we attempt to insert module cpuidle-haltpoll). Fixes: fa86ee90eb11 ("add cpuidle-haltpoll driver") Signed-off-by: Joao Martins --- v2: * Add missing Fixes tag --- drivers/cpuidle/cpuidle-haltpoll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-haltpoll.c index 519e90d125cf..7a0239ef717e 100644 --- a/drivers/cpuidle/cpuidle-haltpoll.c +++ b/drivers/cpuidle/cpuidle-haltpoll.c @@ -99,7 +99,7 @@ static int __init haltpoll_init(void) cpuidle_poll_state_init(drv); if (!kvm_para_available()) - return 0; + return -ENODEV; ret = cpuidle_register_driver(drv); if (ret < 0) From patchwork Tue Sep 3 13:24:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11127871 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 F3C5313B1 for ; Tue, 3 Sep 2019 13:25:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D494623431 for ; Tue, 3 Sep 2019 13:25:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="l9sDZyu5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729396AbfICNZQ (ORCPT ); Tue, 3 Sep 2019 09:25:16 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33634 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729020AbfICNZO (ORCPT ); Tue, 3 Sep 2019 09:25:14 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x83DO2M3042149; Tue, 3 Sep 2019 13:25:05 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=KM/hdDQyd8Z+6S0BJ3ZElEafo02FzH2F7BIJZJMmdtk=; b=l9sDZyu5HJrQ8N3sKPlLr9yrmFxj6JhIDDRNX5ipMZcVcBqNkM/7RZEsZW7iFNcNrDaN 0oopaJTECQwvZLMfTQZBeEX5DYMsxhgUEgRLIlxCEIyXRzrOQpFGs0E97cicPxw9tju6 uYpCaY7nzJwYDKEUwGXvAhHZCF0ZcWj1Eecsa87AMTWFucZDKGYz0YtsUnPRSTIt2ued Sh+H0R/5vqSZjsWwxmD0pY95MruWkC/LhS3JAj+oDkJqa7MXxslq5UU5zPYFJakIkcRP cdhfY1+vXIFWXL8qm3tpWiZpqTCNlstzxAMfIHqANTpfLu9nwQY+S6oGIDc1350cidAB 5g== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2usrw8r1fu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2019 13:25:05 +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 x83DOF3j129247; Tue, 3 Sep 2019 13:25:04 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2us5pguu5s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Sep 2019 13:25:04 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x83DP3IJ000558; Tue, 3 Sep 2019 13:25:03 GMT Received: from paddy.uk.oracle.com (/10.175.205.235) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Sep 2019 06:25:03 -0700 From: Joao Martins To: linux-pm@vger.kernel.org Cc: Joao Martins , "Rafael J. Wysocki" , Daniel Lezcano , linux-kernel@vger.kernel.org, Marcelo Tosatti , kvm@vger.kernel.org Subject: [PATCH v2 4/4] cpuidle-haltpoll: do not set an owner to allow modunload Date: Tue, 3 Sep 2019 14:24:44 +0100 Message-Id: <20190903132444.11808-5-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190903132444.11808-1-joao.m.martins@oracle.com> References: <20190903132444.11808-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9368 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=704 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909030142 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9368 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=766 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909030142 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org cpuidle-haltpoll can be built as a module to allow optional late load. Given we are setting @owner to THIS_MODULE, cpuidle will attempt to grab a module reference every time a cpuidle_device is registered -- so essentially all online cpus get a reference. This prevents for the module to be unloaded later, which makes the module_exit callback entirely unused. Thus remove the @owner and allow module to be unloaded. Fixes: fa86ee90eb11 ("add cpuidle-haltpoll driver") Signed-off-by: Joao Martins --- v2: * Add missing Fixes tag --- drivers/cpuidle/cpuidle-haltpoll.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-haltpoll.c index 7a0239ef717e..49a65c6fe91e 100644 --- a/drivers/cpuidle/cpuidle-haltpoll.c +++ b/drivers/cpuidle/cpuidle-haltpoll.c @@ -35,7 +35,6 @@ static int default_enter_idle(struct cpuidle_device *dev, static struct cpuidle_driver haltpoll_driver = { .name = "haltpoll", .governor = "haltpoll", - .owner = THIS_MODULE, .states = { { /* entry 0 is for polling */ }, {