Skip to content

Commit 5c189c5

Browse files
committed
powerpc/time: Fix mftb()/get_tb() for use with the compat VDSO
When we're building the compat VDSO we are building 32-bit code but in the context of a 64-bit kernel configuration. To make this work we need to be careful in some places when using ifdefs to differentiate between CONFIG_PPC64 and __powerpc64__. CONFIG_PPC64 indicates the kernel we're building is 64-bit, but it doesn't tell us that we're currently building 64-bit code - we could be building 32-bit code for the compat VDSO. On the other hand __powerpc64__ tells us that we are currently building 64-bit code (and therefore we must also be building a 64-bit kernel). In the case of get_tb() we want to use the 32-bit code sequence regardless of whether the kernel we're building for is 64-bit or 32-bit, what matters is the word size of the current object. So we need to check __powerpc64__ to decide if we use mftb() or the mftbu()/mftb() sequence. For mftb() the logic for CPU_FTR_CELL_TB_BUG only makes sense if we're building 64-bit code, so guard that with a __powerpc64__ check. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d26b381 commit 5c189c5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

arch/powerpc/include/asm/vdso/timebase.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
#include <asm/reg.h>
1010

11-
#if defined(CONFIG_PPC_CELL) || defined(CONFIG_E500)
11+
/*
12+
* We use __powerpc64__ here because we want the compat VDSO to use the 32-bit
13+
* version below in the else case of the ifdef.
14+
*/
15+
#if defined(__powerpc64__) && (defined(CONFIG_PPC_CELL) || defined(CONFIG_E500))
1216
#define mftb() ({unsigned long rval; \
1317
asm volatile( \
1418
"90: mfspr %0, %2;\n" \
@@ -49,7 +53,11 @@ static inline u64 get_tb(void)
4953
{
5054
unsigned int tbhi, tblo, tbhi2;
5155

52-
if (IS_ENABLED(CONFIG_PPC64))
56+
/*
57+
* We use __powerpc64__ here not CONFIG_PPC64 because we want the compat
58+
* VDSO to use the 32-bit compatible version in the while loop below.
59+
*/
60+
if (__is_defined(__powerpc64__))
5361
return mftb();
5462

5563
do {

0 commit comments

Comments
 (0)