[PATCH][2.5] APM does unsafe conditional set_cpus_allowed

From: Zwane Mwaikambo (zwane@linuxpower.ca)
Date: Mon May 19 2003 - 08:17:09 EST


kapmd does a conditional check in order to decide whether to set the
task's cpu affinity mask. This can change during runtime, therefore we
unconditionally set it. There is an early exit in set_cpus_allowed if the
current processor is in the allowed mask anyway.

        Zwane

Index: linux-2.5-devel/arch/i386/kernel/apm.c
===================================================================
RCS file: /home/cvs/linux-2.5/arch/i386/kernel/apm.c,v
retrieving revision 1.52
diff -u -p -B -r1.52 apm.c
--- linux-2.5-devel/arch/i386/kernel/apm.c 15 May 2003 03:43:20 -0000 1.52
+++ linux-2.5-devel/arch/i386/kernel/apm.c 19 May 2003 12:14:05 -0000
@@ -512,9 +512,8 @@ static unsigned long apm_save_cpus(void)
 {
         unsigned long x = current->cpus_allowed;
         /* Some bioses don't like being called from CPU != 0 */
- set_cpus_allowed(current, 1 << 0);
- if (unlikely(smp_processor_id() != 0))
- BUG();
+ set_cpus_allowed(current, 1UL << 0);
+ BUG_ON(smp_processor_id() != 0);
         return x;
 }
 
@@ -914,11 +913,8 @@ static void apm_power_off(void)
          */
 #ifdef CONFIG_SMP
         /* Some bioses don't like being called from CPU != 0 */
- if (smp_processor_id() != 0) {
- set_cpus_allowed(current, 1 << 0);
- if (unlikely(smp_processor_id() != 0))
- BUG();
- }
+ set_cpus_allowed(current, 1UL << 0);
+ BUG_ON(smp_processor_id() != 0);
 #endif
         if (apm_info.realmode_power_off)
         {
@@ -1708,11 +1704,8 @@ static int apm(void *unused)
          * Some bioses don't like being called from CPU != 0.
          * Method suggested by Ingo Molnar.
          */
- if (smp_processor_id() != 0) {
- set_cpus_allowed(current, 1 << 0);
- if (unlikely(smp_processor_id() != 0))
- BUG();
- }
+ set_cpus_allowed(current, 1UL << 0);
+ BUG_ON(smp_processor_id() != 0);
 #endif
 
         if (apm_info.connection_version == 0) {

-- 
function.linuxpower.ca
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri May 23 2003 - 22:00:34 EST