Thread (10 messages) 10 messages, 3 authors, 2025-06-02

Re: [PATCH 1/2] powerpc: properly negate error in syscall_set_return_value() in sc case

From: Dmitry V. Levin <hidden>
Date: 2025-01-28 16:10:06
Also in: lkml

On Tue, Jan 28, 2025 at 05:00:31PM +0100, Christophe Leroy wrote:
Le 28/01/2025 à 16:52, Dmitry V. Levin a écrit :
quoted
On Tue, Jan 28, 2025 at 03:59:29PM +0100, Christophe Leroy wrote:
quoted
Le 27/01/2025 à 19:13, Dmitry V. Levin a écrit :
quoted
According to the Power Architecture Linux system call ABI documented in
[1], when the syscall is made with the sc instruction, both a value and an
error condition are returned, where r3 register contains the return value,
and cr0.SO bit specifies the error condition.  When cr0.SO is clear, the
syscall succeeded and r3 is the return value.  When cr0.SO is set, the
syscall failed and r3 is the error value.  This syscall return semantics
was implemented from the very beginning of Power Architecture on Linux,
and syscall tracers and debuggers like strace that read or modify syscall
return information also rely on this ABI.
I see a quite similar ABI on microblaze, mips, nios2 and sparc. Do they
behave all the same ?
Yes, also on alpha.  I don't think microblaze should be in this list,
though.
Microblaze has

static inline void syscall_set_return_value(struct task_struct *task,
					    struct pt_regs *regs,
					    int error, long val)
{
	if (error)
		regs->r3 = -error;
	else
		regs->r3 = val;
}

So it has a positive error setting allthough it has no flag to tell it 
is an error. Wondering how it works at the end.
It's a bug, but given that microblaze doesn't enable
CONFIG_HAVE_ARCH_TRACEHOOK, most likely this function is unused there.
Alpha I'm not sure, I see nothing obvious in include/asm/ptrace.h or 
include/asm/syscall.h
Alpha doesn't enable CONFIG_HAVE_ARCH_TRACEHOOK, it just lacks the
necessary interfaces, but it uses a3 register for this purpose, see
arch/alpha/kernel/entry.S for details.


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