From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id F28E93857712 for ; Mon, 10 Apr 2023 19:59:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F28E93857712 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ot1-x334.google.com with SMTP id q5-20020a056830232500b006a11eb19f8eso2147425otg.5 for ; Mon, 10 Apr 2023 12:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681156764; x=1683748764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=4De80TwHo20PxnsZL/o7uF3ZonEhm0AW3+M3iyQSSCk=; b=GVhKrjkkjITVmY38JhIM0bMRDuHnjL2t8eT0LHw0PDA5BGfcGbeoUG90Ec5oZH33SS u39HIV2iACi+osV4j3gEUcHadgWnb8l2N+OswYIlizfrwZENg3Mp8qFl6MgbnVou/j13 /VVjm9CxWJ1kLlDiOkAjOdjqwlWwmyh8LFU02UqnTQ1zL6rqom4XNItD2Mkhhnea5HBG FulzlRYufpHkSTC/gEbrBvmEDC34gSmrbKjY2LEn26c6JPCaEPp/sQuCoRtDxrn1FiMl LalA++15vn1J9Ib2VKQoXUAbi9wIGLko+aoaxeFiHCsIoUQ6dPUj810m2Ouvc75Gi9t8 Qpxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681156764; x=1683748764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4De80TwHo20PxnsZL/o7uF3ZonEhm0AW3+M3iyQSSCk=; b=QSiJXX1TtQo37hfhoRtdpS4Go+mQ77zo6mII4qVRGPgVvmiTSQyZWX/zPCyxDPffTu LndFKEG81m8+9rhQ5ujieXNizscbCN1duDvDvWUjzfHBNtxBu7mOyyC9FY35zdyDiJVz EIoWrfLK0cs/L+iytlwQGcTiqFsnT2An90Pv9icOVK5bWM5cox91TiLLUbzqTZJK5sUl oSsIifKF8AJ2xEU9bXeGRJF2ES7yT+DW53tP9cMhH3Rbju27zI8EQSvCnWLi3vBcBJA7 yyPElhfDVvBz8oHkl9vmRWrh+Enw/3ajY3EQXF09UjorOQkw4LXm6r7k375dM0/8sRWg 4BPA== X-Gm-Message-State: AAQBX9eISgF13HaoMJTqwDQFFh/BJq3nvV1gzN8PTd8TRFFo2f6c0wLK 5fsloGLdwj+j+dejnr1EuDjDnbbjOeVj8YQiJumQog== X-Google-Smtp-Source: AKy350a0GdUYv7V9uWwq2T3XEKBFHETaO7MJmKXtEi7cKZZ2qj18oIb0E3mqYpwd91RxAw1HkxHzMA== X-Received: by 2002:a9d:4e8d:0:b0:697:a381:a8f8 with SMTP id v13-20020a9d4e8d000000b00697a381a8f8mr317757otk.3.1681156764527; Mon, 10 Apr 2023 12:59:24 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id r7-20020a9d7507000000b006a30260ccfdsm4673293otk.11.2023.04.10.12.59.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 12:59:23 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v5 07/22] powerpc: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 16:58:52 -0300 Message-Id: <20230410195907.4123869-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: By adding the required syscall_cancel.S. Checked on powerpc64le-linux-gnu, powerpc64-linux-gnu and powerpc-linux-gnu. --- sysdeps/powerpc/powerpc32/sysdep.h | 3 + sysdeps/powerpc/powerpc64/sysdep.h | 19 ++++++ .../unix/sysv/linux/powerpc/syscall_cancel.S | 65 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S diff --git a/sysdeps/powerpc/powerpc32/sysdep.h b/sysdeps/powerpc/powerpc32/sysdep.h index 095a726765..df67e3516a 100644 --- a/sysdeps/powerpc/powerpc32/sysdep.h +++ b/sysdeps/powerpc/powerpc32/sysdep.h @@ -104,6 +104,9 @@ GOT_LABEL: ; \ # define JUMPTARGET(name) name #endif +#define TAIL_CALL_NO_RETURN(__func) \ + b __func@local + #if defined SHARED && defined PIC && !defined NO_HIDDEN # undef HIDDEN_JUMPTARGET # define HIDDEN_JUMPTARGET(name) __GI_##name##@local diff --git a/sysdeps/powerpc/powerpc64/sysdep.h b/sysdeps/powerpc/powerpc64/sysdep.h index ce92d8b3d2..1815131dc2 100644 --- a/sysdeps/powerpc/powerpc64/sysdep.h +++ b/sysdeps/powerpc/powerpc64/sysdep.h @@ -352,6 +352,25 @@ LT_LABELSUFFIX(name,_name_end): ; \ ENTRY (name); \ DO_CALL (SYS_ify (syscall_name)) +#ifdef SHARED +# define TAIL_CALL_NO_RETURN(__func) \ + b JUMPTARGET(__func) +#else +# define TAIL_CALL_NO_RETURN(__func) \ + .ifdef .Local ## __func; \ + b .Local ## __func; \ + .else; \ +.Local ## __func: \ + mflr 0; \ + std 0,FRAME_LR_SAVE(1); \ + stdu 1,-FRAME_MIN_SIZE(1); \ + cfi_adjust_cfa_offset(FRAME_MIN_SIZE); \ + cfi_offset(lr,FRAME_LR_SAVE); \ + bl JUMPTARGET(__func); \ + nop; \ + .endif +#endif + #ifdef SHARED #define TAIL_CALL_SYSCALL_ERROR \ b JUMPTARGET (NOTOC (__syscall_error)) diff --git a/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S new file mode 100644 index 0000000000..7aa2b77caa --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S @@ -0,0 +1,65 @@ +/* Cancellable syscall wrapper. Linux/powerpc 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 + . */ + +#include +#include + +/* long int [r3] __syscall_cancel_arch (int *cancelhandling [r3], + long int nr [r4], + long int arg1 [r5], + long int arg2 [r6], + long int arg3 [r7], + long int arg4 [r8], + long int arg5 [r9], + long int arg6 [r10]) */ + +ENTRY (__syscall_cancel_arch) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + lwz r0,0(r3) + andi. r0,r0,TCB_CANCELED_BITMASK + bne- 1f + + /* Issue a 6 argument syscall, the nr [r4] being the syscall + number. */ + mr r0,r4 + mr r3,r5 + mr r4,r6 + mr r5,r7 + mr r6,r8 + mr r7,r9 + mr r8,r10 + sc + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + bnslr+ + neg r3,r3 + blr + + /* Although the __syscall_do_cancel do not return, we need to stack + being set correctly for unwind. */ +1: + TAIL_CALL_NO_RETURN (__syscall_do_cancel) + +END (__syscall_cancel_arch) -- 2.34.1