[PATCH v4 12/21] nptl: sparc: Fix Race conditions in pthread cancellation [BZ#12683]

Adhemerval Zanella adhemerval.zanella@linaro.org
Wed Apr 15 14:48:48 GMT 2020



On 14/04/2020 13:54, Stepan Golosunov wrote:
> 12.04.2020 в 19:33:21 +0400 Stepan Golosunov написал:
>> 03.04.2020 в 17:31:52 -0300 Adhemerval Zanella написал:
>>> This patch adds the sparc modifications required for the BZ#12683 fix.
>>>
>>> Different than other architectures, SPARC passes the sigcontext_t
>>> struct pointer as third argument in the signal handler set with
>>> SA_SIGINFO (some info at [1]) for 64 bits and the pt_regs in 32 bits.
>>> >From Linux code:
>>>
>>> * arch/sparc/kernel/signal_64.c
>>>
>>> 428         /* 3. signal handler back-trampoline and parameters */
>>> 429         regs->u_regs[UREG_FP] = ((unsigned long) sf) - STACK_BIAS;
>>> 430         regs->u_regs[UREG_I0] = ksig->sig;
>>> 431         regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
>>> 432
>>> 433         /* The sigcontext is passed in this way because of how it
>>> 434          * is defined in GLIBC's /usr/include/bits/sigcontext.h
>>> 435          * for sparc64.  It includes the 128 bytes of siginfo_t.
>>> 436          */
>>> 437         regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
>>>
>>> * arch/sparc/kernel/signal_32.c:
>>>
>>> 392         regs->u_regs[UREG_FP] = (unsigned long) sf;
>>> 393         regs->u_regs[UREG_I0] = ksig->sig;
>>> 394         regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
>>> 395         regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
>>> 396
>>> 397         regs->pc = (unsigned long) ksig->ka.sa.sa_handler;
>>> 398         regs->npc = (regs->pc + 4);
>>>
>>> So it requires an arch-specific ucontext_add_cancel.
>>>
>>> Also on sparc interrupted pause syscall returns with a PC indicating a
>>> side-effect and this deviates from other architectures.  The sparc64
>>> pause fall back to ppool syscall.
>>
>> s/ppool/ppoll/
>>
>>>
>>> Checked on sparc64-linux-gnu and sparcv9-linux-gnu.
>>>
>>> [1] https://www.spinics.net/lists/sparclinux/msg05037.html
>>> ---
>>>  sysdeps/sparc/nptl/tcb-offsets.sym            |  3 +
>>>  .../sysv/linux/sparc/cancellation-sigmask.h   | 39 ++++++++++
>>>  .../sysv/linux/sparc/sparc32/syscall_cancel.S | 71 ++++++++++++++++++
>>>  sysdeps/unix/sysv/linux/sparc/sparc64/pause.c | 25 +++++++
>>>  .../sysv/linux/sparc/sparc64/syscall_cancel.S | 74 +++++++++++++++++++
>>>  5 files changed, 212 insertions(+)
>>>  create mode 100644 sysdeps/unix/sysv/linux/sparc/cancellation-sigmask.h
>>>  create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
>>>  create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/pause.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
>>
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c
>>> @@ -0,0 +1,25 @@
>>> +/* Linux pause syscall implementation.  Linux/sparc64.
>>> +   Copyright (C) 2020 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 <sys/syscall.h>
>>> +
>>> +/* On sparc interrupted pause syscall returns with a PC indicating a
>>> +   side-effect and this deviates from other architectures.  Fall back to
>>> +   ppool implementation.  */
>>
>> ditto
>>
>>> +#undef __NR_pause
>>> +#include <sysdeps/unix/sysv/linux/pause.c>
> 
> But sysdeps/unix/sysv/linux/sparc/kernel-features.h already contains
> 
> #ifdef __arch64__
> /* sparc64 defines __NR_pause,  however it is not supported (ENOSYS).
>    Undefine so pause.c can use a correct alternative.  */
> # undef __NR_pause
> #endif
> 

Indeed, I already has pushed this fix on generic implementation. I have
removed the new pause implementation and fixed the commit message
accordingly.


More information about the Libc-alpha mailing list