[PATCH] powerpc: Make set_endian() return EINVAL when not supporting little endian

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE1829d

4 messages, 2 authors, 2021-08-26 · open the first message on its own page

[PATCH] powerpc: Make set_endian() return EINVAL when not supporting little endian

From: Christophe Leroy <hidden>
Date: 2021-08-25 13:43:55

There is no point in modifying MSR_LE bit on CPUs not supporting
little endian.

Just like done for get_endian(), make set_endian() return
EINVAL in that case.

Signed-off-by: Christophe Leroy <redacted>
---
 arch/powerpc/kernel/process.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 185beb290580..b2b9919795a2 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1995,6 +1995,10 @@ int set_endian(struct task_struct *tsk, unsigned int val)
 {
 	struct pt_regs *regs = tsk->thread.regs;
 
+	if (!cpu_has_feature(CPU_FTR_PPC_LE) &&
+	    !cpu_has_feature(CPU_FTR_REAL_LE))
+		return -EINVAL;
+
 	if ((val == PR_ENDIAN_LITTLE && !cpu_has_feature(CPU_FTR_REAL_LE)) ||
 	    (val == PR_ENDIAN_PPC_LITTLE && !cpu_has_feature(CPU_FTR_PPC_LE)))
 		return -EINVAL;
-- 
2.25.0

Re: [PATCH] powerpc: Make set_endian() return EINVAL when not supporting little endian

From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2021-08-26 03:42:47

Christophe Leroy [off-list ref] writes:
There is no point in modifying MSR_LE bit on CPUs not supporting
little endian.
Isn't that an ABI break?

set_endian(PR_ENDIAN_BIG) should work on a big endian CPU, even if it
does nothing useful.

cheers
quoted hunk
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 185beb290580..b2b9919795a2 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1995,6 +1995,10 @@ int set_endian(struct task_struct *tsk, unsigned int val)
 {
 	struct pt_regs *regs = tsk->thread.regs;
 
+	if (!cpu_has_feature(CPU_FTR_PPC_LE) &&
+	    !cpu_has_feature(CPU_FTR_REAL_LE))
+		return -EINVAL;
+
 	if ((val == PR_ENDIAN_LITTLE && !cpu_has_feature(CPU_FTR_REAL_LE)) ||
 	    (val == PR_ENDIAN_PPC_LITTLE && !cpu_has_feature(CPU_FTR_PPC_LE)))
 		return -EINVAL;
-- 
2.25.0

Re: [PATCH] powerpc: Make set_endian() return EINVAL when not supporting little endian

From: Christophe Leroy <hidden>
Date: 2021-08-26 04:55:55


Le 26/08/2021 à 05:41, Michael Ellerman a écrit :
Christophe Leroy [off-list ref] writes:
quoted
There is no point in modifying MSR_LE bit on CPUs not supporting
little endian.
Isn't that an ABI break?
Or an ABI fix ? I don't know.

My first thought was that all other 32 bits architectures were returning -EINVAL, but looking at the 
man page of prctl, it is explicit that this is powerpc only.
set_endian(PR_ENDIAN_BIG) should work on a big endian CPU, even if it
does nothing useful.
Fair enough. But shouldn't in that case get_endian() return PR_ENDIAN_BIG instead of returning EINVAL ?

We can do one or the other, but I think it should at least be consistant between them, shouldn't it ?

Christophe

Re: [PATCH] powerpc: Make set_endian() return EINVAL when not supporting little endian

From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2021-08-26 14:23:57

Christophe Leroy [off-list ref] writes:
Le 26/08/2021 à 05:41, Michael Ellerman a écrit :
quoted
Christophe Leroy [off-list ref] writes:
quoted
There is no point in modifying MSR_LE bit on CPUs not supporting
little endian.
Isn't that an ABI break?
Or an ABI fix ? I don't know.
It could break existing applications, even if the new semantics make
more sense. So that's a break IMHO :)
My first thought was that all other 32 bits architectures were returning -EINVAL, but looking at the 
man page of prctl, it is explicit that this is powerpc only.
It could be generic, but yeah seems we're the only arch that implements
it.
quoted
set_endian(PR_ENDIAN_BIG) should work on a big endian CPU, even if it
does nothing useful.
Fair enough. But shouldn't in that case get_endian() return PR_ENDIAN_BIG instead of returning EINVAL ?
We can do one or the other, but I think it should at least be consistant between them, shouldn't it ?
It should be consistent, but it isn't, and if we change it now we
potentially break existing userspace, which is bad.

I don't think it's widely used, and the risk of breakage would be
minimal, but it's not zero.

So I'm not sure it's worth changing it just for the sake of consistency.

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help