Skip to content

Commit 3232f1c

Browse files
hcahcaVasily Gorbik
authored andcommitted
s390/processor: Use bitop functions for cpu flag helper functions
Use bitop functions to implement cpu flag helper functions. This way it is guaranteed that bits cannot get lost if modified in different contexts on a cpu. E.g. if process context is interrupted in the middle of a read-modify-write sequence while modifying cpu flags, and within interrupt context cpu flags are also modified, bits can get lost. There is currently no code which is doing this, however upcoming code could potentially run into this problem. Acked-by: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent b9be1be commit 3232f1c

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

arch/s390/include/asm/processor.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/cpumask.h>
3232
#include <linux/linkage.h>
3333
#include <linux/irqflags.h>
34+
#include <linux/bitops.h>
3435
#include <asm/fpu-types.h>
3536
#include <asm/cpu.h>
3637
#include <asm/page.h>
@@ -62,33 +63,27 @@ static __always_inline struct pcpu *this_pcpu(void)
6263

6364
static __always_inline void set_cpu_flag(int flag)
6465
{
65-
this_pcpu()->flags |= (1UL << flag);
66+
set_bit(flag, &this_pcpu()->flags);
6667
}
6768

6869
static __always_inline void clear_cpu_flag(int flag)
6970
{
70-
this_pcpu()->flags &= ~(1UL << flag);
71+
clear_bit(flag, &this_pcpu()->flags);
7172
}
7273

7374
static __always_inline bool test_cpu_flag(int flag)
7475
{
75-
return this_pcpu()->flags & (1UL << flag);
76+
return test_bit(flag, &this_pcpu()->flags);
7677
}
7778

7879
static __always_inline bool test_and_set_cpu_flag(int flag)
7980
{
80-
if (test_cpu_flag(flag))
81-
return true;
82-
set_cpu_flag(flag);
83-
return false;
81+
return test_and_set_bit(flag, &this_pcpu()->flags);
8482
}
8583

8684
static __always_inline bool test_and_clear_cpu_flag(int flag)
8785
{
88-
if (!test_cpu_flag(flag))
89-
return false;
90-
clear_cpu_flag(flag);
91-
return true;
86+
return test_and_clear_bit(flag, &this_pcpu()->flags);
9287
}
9388

9489
/*
@@ -97,7 +92,7 @@ static __always_inline bool test_and_clear_cpu_flag(int flag)
9792
*/
9893
static __always_inline bool test_cpu_flag_of(int flag, int cpu)
9994
{
100-
return per_cpu(pcpu_devices, cpu).flags & (1UL << flag);
95+
return test_bit(flag, &per_cpu(pcpu_devices, cpu).flags);
10196
}
10297

10398
#define arch_needs_cpu() test_cpu_flag(CIF_NOHZ_DELAY)

0 commit comments

Comments
 (0)