[v5,22/22] loongarch: Fix Race conditions in pthread cancellation [BZ#12683]
Checks
Commit Message
By adding the required syscall_cancel.S.
Checked against a build and make check run-built-tests=no for
loongarch64-linux-gnu-lp64d.
---
.../sysv/linux/loongarch/syscall_cancel.S | 54 +++++++++++++++++++
1 file changed, 54 insertions(+)
create mode 100644 sysdeps/unix/sysv/linux/loongarch/syscall_cancel.S
Comments
On Mon, 2023-04-10 at 17:46 -0300, Adhemerval Zanella via Libc-alpha
wrote:
/* snip */
> +1:
> + addi.d $r3,$r3,-16
> + cfi_def_cfa_offset (16)
> + st.d $r1,$r3,8
> + cfi_offset (1, -8)
> + bl __syscall_do_cancel
Can we simply use "b __syscall_do_cancel" for 1: like AArch64?
> +
> +END (__syscall_cancel_arch)
在 2023/4/11 下午2:19, Xi Ruoyao 写道:
> On Mon, 2023-04-10 at 17:46 -0300, Adhemerval Zanella via Libc-alpha
> wrote:
>
> /* snip */
>
>> +1:
>> + addi.d $r3,$r3,-16
>> + cfi_def_cfa_offset (16)
>> + st.d $r1,$r3,8
>> + cfi_offset (1, -8)
>> + bl __syscall_do_cancel
> Can we simply use "b __syscall_do_cancel" for 1: like AArch64?
In LoongArch, the "b" instruction is equivalent to the "b" instruction
in AArch64, and similarly,
the "bl" instruction in LoongArch is equivalent to the "bl" instruction
in AArch64.
>> +
>> +END (__syscall_cancel_arch)
在 2023/4/11 下午8:00, caiyinyu 写道:
>
> 在 2023/4/11 下午2:19, Xi Ruoyao 写道:
>> On Mon, 2023-04-10 at 17:46 -0300, Adhemerval Zanella via Libc-alpha
>> wrote:
>>
>> /* snip */
>>
>>> +1:
>>> + addi.d $r3,$r3,-16
>>> + cfi_def_cfa_offset (16)
>>> + st.d $r1,$r3,8
>>> + cfi_offset (1, -8)
>>> + bl __syscall_do_cancel
>> Can we simply use "b __syscall_do_cancel" for 1: like AArch64?
>
> In LoongArch, the "b" instruction is equivalent to the "b" instruction
> in AArch64, and similarly,
>
> the "bl" instruction in LoongArch is equivalent to the "bl"
> instruction in AArch64.
This is our instruction manual.
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#arithmetic-operation-instructions
>
>>> +
>>> +END (__syscall_cancel_arch)
On Tue, 2023-04-11 at 20:00 +0800, caiyinyu wrote:
>
> 在 2023/4/11 下午2:19, Xi Ruoyao 写道:
> > On Mon, 2023-04-10 at 17:46 -0300, Adhemerval Zanella via Libc-alpha
> > wrote:
> >
> > /* snip */
> >
> > > +1:
> > > + addi.d $r3,$r3,-16
> > > + cfi_def_cfa_offset (16)
> > > + st.d $r1,$r3,8
> > > + cfi_offset (1, -8)
> > > + bl __syscall_do_cancel
> > Can we simply use "b __syscall_do_cancel" for 1: like AArch64?
>
> In LoongArch, the "b" instruction is equivalent to the "b" instruction
> in AArch64, and similarly,
>
> the "bl" instruction in LoongArch is equivalent to the "bl"
> instruction
> in AArch64.
>
> > > +
> > > +END (__syscall_cancel_arch)
I've rewritten the syscall_cancel.S file as follow to exploit the tail
call and improve readability. It passed nptl/tst-cancel31:
#include <sysdep.h>
#include <descr-const.h>
ENTRY (__syscall_cancel_arch)
.global __syscall_cancel_arch_start
__syscall_cancel_arch_start:
/* if (*cancelhandling & CANCELED_BITMASK)
__syscall_do_cancel() */
ld.w t0, a0, 0
andi t0, t0, TCB_CANCELED_BITMASK
bnez t0, 1f
/* Issue a 6 argument syscall. */
move t1, a1
move a0, a2
move a1, a3
move a2, a4
move a3, a5
move a4, a6
move a5, a7
move a7, t1
syscall 0
.global __syscall_cancel_arch_end
__syscall_cancel_arch_end:
jr ra
1:
b __syscall_do_cancel
END (__syscall_cancel_arch)
>
On 11/04/23 09:55, Xi Ruoyao wrote:
> On Tue, 2023-04-11 at 20:00 +0800, caiyinyu wrote:
>>
>> 在 2023/4/11 下午2:19, Xi Ruoyao 写道:
>>> On Mon, 2023-04-10 at 17:46 -0300, Adhemerval Zanella via Libc-alpha
>>> wrote:
>>>
>>> /* snip */
>>>
>>>> +1:
>>>> + addi.d $r3,$r3,-16
>>>> + cfi_def_cfa_offset (16)
>>>> + st.d $r1,$r3,8
>>>> + cfi_offset (1, -8)
>>>> + bl __syscall_do_cancel
>>> Can we simply use "b __syscall_do_cancel" for 1: like AArch64?
>>
>> In LoongArch, the "b" instruction is equivalent to the "b" instruction
>> in AArch64, and similarly,
>>
>> the "bl" instruction in LoongArch is equivalent to the "bl"
>> instruction
>> in AArch64.
>>
>>>> +
>>>> +END (__syscall_cancel_arch)
>
> I've rewritten the syscall_cancel.S file as follow to exploit the tail
> call and improve readability. It passed nptl/tst-cancel31:
>
> #include <sysdep.h>
> #include <descr-const.h>
>
> ENTRY (__syscall_cancel_arch)
>
> .global __syscall_cancel_arch_start
> __syscall_cancel_arch_start:
>
> /* if (*cancelhandling & CANCELED_BITMASK)
> __syscall_do_cancel() */
> ld.w t0, a0, 0
> andi t0, t0, TCB_CANCELED_BITMASK
> bnez t0, 1f
>
> /* Issue a 6 argument syscall. */
> move t1, a1
> move a0, a2
> move a1, a3
> move a2, a4
> move a3, a5
> move a4, a6
> move a5, a7
> move a7, t1
> syscall 0
>
> .global __syscall_cancel_arch_end
> __syscall_cancel_arch_end:
> jr ra
> 1:
> b __syscall_do_cancel
>
> END (__syscall_cancel_arch)
>
Thanks, I have merged it locally. I will update my sourceware branch
with this change.
new file mode 100644
@@ -0,0 +1,54 @@
+/* Cancellable syscall wrapper. Linux/loongarch version.
+ Copyright (C) 2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <descr-const.h>
+
+ENTRY (__syscall_cancel_arch)
+
+ .global __syscall_cancel_arch_start
+__syscall_cancel_arch_start:
+
+ /* if (*cancelhandling & CANCELED_BITMASK)
+ __syscall_do_cancel() */
+ ldptr.w $r12,$r4,0
+ andi $r12,$r12,TCB_CANCELED_BITMASK
+ bnez $r12,1f
+
+ /* Issue a 6 argument syscall. */
+ or $r13,$r5,$r0
+ or $r4,$r6,$r0
+ or $r5,$r7,$r0
+ or $r6,$r8,$r0
+ or $r7,$r9,$r0
+ or $r8,$r10,$r0
+ or $r9,$r11,$r0
+ or $r11,$r13,$r0
+ syscall 0
+
+ .global __syscall_cancel_arch_end
+__syscall_cancel_arch_end:
+ jr $r1
+1:
+ addi.d $r3,$r3,-16
+ cfi_def_cfa_offset (16)
+ st.d $r1,$r3,8
+ cfi_offset (1, -8)
+ bl __syscall_do_cancel
+
+END (__syscall_cancel_arch)