cpuidle: Check cpuidle driver before add refcount
PATCH 1/1 cpuidle: Check cpuidle driver before add refcount
If the current CPU has no cpuidle driver, drv will be NULL. Check if we get drv successfully before add refount to prevent Kernel panic.
--- drivers/cpuidle/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cpuidle/driver.c +2 -1
@@ -331,7 +331,8 @@ struct cpuidle_driver *cpuidle_driver_ref(void)spin_lock (&cpuidle_driver_lock); drv =cpuidle_get_driver (); - drv->refcnt++; +if (drv) + drv->refcnt++;spin_unlock (&cpuidle_driver_lock);return drv;
Signature · 1 line
1.8.1.5
Quoted 3 lines · Daniel Fu
If the current CPU has no cpuidle driver, drv will be NULL. Check if we get drv successfully before add refount to prevent Kernel panic.
What is the actual scenario that may lead to this panic?
Rafael
Quoted 20 lines
Signed-off-by Daniel Fu <[email protected]>--- drivers/cpuidle/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/cpuidle/driver.c +2
-1@@ -331,7 +331,8 @@ struct cpuidle_driver *cpuidle_driver_ref(void)spin_lock (&cpuidle_driver_lock); drv =cpuidle_get_driver (); - drv->refcnt++; +if (drv) + drv->refcnt++;spin_unlock (&cpuidle_driver_lock);return drv;
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
X-NVConfidentiality: public
In SMP, When doing the cpuidle driver registration. There maybe only 1 cpu have register cpuidle(CPU0),
but In the process of registration cpuidle driver, the scheduler maybe schedule the process to the other CPU (eg. CPU0 have heay load, migrate to CPU1) cpuidle_get_driver() --> get_cpu() , will get CPU1, if CPU1 didn't register cpuidle driver, Will get NULL.
I know we should prevent the registration migrate to the other CPU, but we should check drv before add refcount to prevent kernel panic at least, Right?
Best Regards,
Daniel
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: 2013年8月30日 20:01
To: Daniel Fu
Cc: [email protected]; [email protected]; [email protected]; Johnny Qiu
Subject: Re: [PATCH] cpuidle: Check cpuidle driver before add refcount
Quoted 3 lines · Daniel Fu
If the current CPU has no cpuidle driver, drv will be NULL. Check if we get drv successfully before add refount to prevent Kernel panic.
What is the actual scenario that may lead to this panic?
Rafael
Quoted 11 lines
Signed-off-by Daniel Fu <[email protected]>--- drivers/cpuidle/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/cpuidle/driver.c index renamed from drivers/cpuidle/driver.c +0
-03ac499d..6e11701 100644
drivers/cpuidle/driver.c struct cpuidle_driver *cpuidle_driver_ref(void) · line 338
Quoted 9 lines
drivers/cpuidle/driver.c +2
-1@@ -331,7 +331,8 @@ struct cpuidle_driver *cpuidle_driver_ref(void)spin_lock (&cpuidle_driver_lock); drv =cpuidle_get_driver (); - drv->refcnt++; +if (drv) + drv->refcnt++;spin_unlock (&cpuidle_driver_lock);return drv;
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
Quoted 7 lines · Daniel Fu
X-NVConfidentiality: public
In SMP, When doing the cpuidle driver registration. There maybe only 1 cpu have register cpuidle(CPU0),
but In the process of registration cpuidle driver, the scheduler maybe schedule the process to the other CPU (eg. CPU0 have heay load, migrate to CPU1)cpuidle_get_driver()-->get_cpu(), will get CPU1, if CPU1 didn't register cpuidle driver, Will get NULL.I know we should prevent the registration migrate to the other CPU, but we should check drv before add refcount to prevent kernel panic at least, Right?
Well, cpuidle_driver_ref() has only one caller, which is not the registration.
However, the caller apparently assumes that that function may return NULL and cpuidle_driver_unref() check drv against NULL too, so cpuidle_driver_ref() should do that either.
Did you see that problem in testing or just through code inspection?
Rafael
Quoted 41 lines
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: 2013年8月30日 20:01
To: Daniel Fu
Cc: [email protected]; [email protected]; [email protected]; Johnny Qiu
Subject: Re: [PATCH] cpuidle: Check cpuidle driver before add refcountQuoted 3 lines · Daniel Fu
If the current CPU has no cpuidle driver, drv will be NULL. Check if we get drv successfully before add refount to prevent Kernel panic.
What is the actual scenario that may lead to this panic?
Rafael
Quoted 11 lines
Signed-off-by Daniel Fu <[email protected]>--- drivers/cpuidle/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/cpuidle/driver.c index renamed from drivers/cpuidle/driver.c +0
-03ac499d..6e11701 100644
drivers/cpuidle/driver.c struct cpuidle_driver *cpuidle_driver_ref(void) · line 338
Quoted 9 lines
drivers/cpuidle/driver.c +2
-1@@ -331,7 +331,8 @@ struct cpuidle_driver *cpuidle_driver_ref(void)spin_lock (&cpuidle_driver_lock); drv =cpuidle_get_driver (); - drv->refcnt++; +if (drv) + drv->refcnt++;spin_unlock (&cpuidle_driver_lock);return drv;--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Yes, I saw it.
Thanks. found one case when Find PM domain and connect cpuidle to it , in when Kernel booting ,opening early prink testing pm_genpd_name_attach_cpuidle()->cpuidle_driver_ref().
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: 2013年8月30日 21:26
To: Daniel Fu
Cc: [email protected]; [email protected]; [email protected]; Johnny Qiu
Subject: Re: [PATCH] cpuidle: Check cpuidle driver before add refcount
Quoted 9 lines · Daniel Fu
X-NVConfidentiality: public
In SMP, When doing the cpuidle driver registration. There maybe only 1
cpu have register cpuidle(CPU0), but In the process of registration
cpuidle driver, the scheduler maybe schedule the process to the other
CPU (eg. CPU0 have heay load, migrate to CPU1)cpuidle_get_driver()-->get_cpu(), will get CPU1, if CPU1 didn't register cpuidle driver, Will get NULL.I know we should prevent the registration migrate to the other CPU, but we should check drv before add refcount to prevent kernel panic at least, Right?
Well, cpuidle_driver_ref() has only one caller, which is not the registration.
However, the caller apparently assumes that that function may return NULL and cpuidle_driver_unref() check drv against NULL too, so cpuidle_driver_ref() should do that either.
Did you see that problem in testing or just through code inspection?
Rafael
Quoted 36 lines
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: 2013年8月30日 20:01
To: Daniel Fu
Cc: [email protected]; [email protected]; [email protected]; Johnny Qiu
Subject: Re: [PATCH] cpuidle: Check cpuidle driver before add refcountQuoted 3 lines · Daniel Fu
If the current CPU has no cpuidle driver, drv will be NULL. Check if we get drv successfully before add refount to prevent
Kernel panic.What is the actual scenario that may lead to this panic?
Rafael
Quoted 18 lines
Signed-off-by Daniel Fu <[email protected]>--- drivers/cpuidle/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/cpuidle/driver.c +0
-0index
3ac499d..6e11701 100644drivers/cpuidle/driver.c +2
-1@@ -331,7 +331,8 @@ struct cpuidle_driver *cpuidle_driver_ref(void)spin_lock (&cpuidle_driver_lock); drv =cpuidle_get_driver (); - drv->refcnt++; +if (drv) + drv->refcnt++;
Quoted 7 lines
drivers/cpuidle/driver.c struct cpuidle_driver *cpuidle_driver_ref(void) · line 338
Quoted 3 lines
drivers/cpuidle/driver.c +0
-0spin_unlock (&cpuidle_driver_lock);return drv;--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
Quoted 3 lines · Daniel Fu
Yes, I saw it.
Thanks. found one case when Find PM domain and connect cpuidle to it , in when Kernel booting ,opening early prink testing pm_genpd_name_attach_cpuidle()->cpuidle_driver_ref().
I see. OK, I'll queue it up for the second part of the 3.12 merge window.
Thanks,
Rafael
Quoted 75 lines
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: 2013年8月30日 21:26
To: Daniel Fu
Cc: [email protected]; [email protected]; [email protected]; Johnny Qiu
Subject: Re: [PATCH] cpuidle: Check cpuidle driver before add refcountQuoted 9 lines · Daniel Fu
X-NVConfidentiality: public
In SMP, When doing the cpuidle driver registration. There maybe only 1
cpu have register cpuidle(CPU0), but In the process of registration
cpuidle driver, the scheduler maybe schedule the process to the other
CPU (eg. CPU0 have heay load, migrate to CPU1)cpuidle_get_driver()-->get_cpu(), will get CPU1, if CPU1 didn't register cpuidle driver, Will get NULL.I know we should prevent the registration migrate to the other CPU, but we should check drv before add refcount to prevent kernel panic at least, Right?
Well,
cpuidle_driver_ref()has only one caller, which is not the registration.However, the caller apparently assumes that that function may return NULL and
cpuidle_driver_unref()check drv against NULL too, socpuidle_driver_ref()should do that either.Did you see that problem in testing or just through code inspection?
Rafael
Quoted 36 lines
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: 2013年8月30日 20:01
To: Daniel Fu
Cc: [email protected]; [email protected]; [email protected]; Johnny Qiu
Subject: Re: [PATCH] cpuidle: Check cpuidle driver before add refcountQuoted 3 lines · Daniel Fu
If the current CPU has no cpuidle driver, drv will be NULL. Check if we get drv successfully before add refount to prevent
Kernel panic.What is the actual scenario that may lead to this panic?
Rafael
Quoted 18 lines
Signed-off-by Daniel Fu <[email protected]>--- drivers/cpuidle/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/cpuidle/driver.c +0
-0index
3ac499d..6e11701 100644drivers/cpuidle/driver.c +2
-1@@ -331,7 +331,8 @@ struct cpuidle_driver *cpuidle_driver_ref(void)spin_lock (&cpuidle_driver_lock); drv =cpuidle_get_driver (); - drv->refcnt++; +if (drv) + drv->refcnt++;Quoted 7 lines
drivers/cpuidle/driver.c struct cpuidle_driver *cpuidle_driver_ref(void) · line 338
Quoted 3 lines
drivers/cpuidle/driver.c +0
-0spin_unlock (&cpuidle_driver_lock);return drv;--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.