From patchwork Mon Oct 14 20:56:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1176643 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105937-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="FnHSgwYU"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="X4+f/XVK"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46sWBd20Wmz9sP6 for ; Tue, 15 Oct 2019 07:59:05 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=crn8NfUh+6FiYn0MVTi1IaqgrvswPPa OD11b5fRfGU9aZBFAviMHZXsuoMbpaU0eI+Wk1wrlHCHf808ctoRlI6cNW8W41e6 6eMuezB36iL5yt6J9fyb+Yh9MwvGj6/HCUeHWi5vD0QID2LTE+7Lbg3c6/LaknKf FYG9ZYmpoTRk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=yuaDoSlaZ4g6u0rPGEIL9PtYHw8=; b=FnHSg wYUMSFK2rkvec/Eg5EKZatwAxDBVPCKlxtoR4DUvFwiolRqvtGuSGjgd8v4yS0dq 4U9X8p+psN4qztLJfarBWcYtDL3iADhnhIhJ3Y7VDe6jgkq/IHVkJvGcPkfVtWyQ RR8U68h9t8R69uLmWEXGbnMiLGwt0ONf0nuD5E= Received: (qmail 115169 invoked by alias); 14 Oct 2019 20:57:25 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 114986 invoked by uid 89); 14 Oct 2019 20:57:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qk1-f177.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=L48C2S2cuH3wIpZN+1UP2+S+B1Xql7b/cQD2SyE3JK0=; b=X4+f/XVKLcWTph1unW2Tk2Ggknaj6NXdsUjivcstuHsJ/bljbG/jNp/DIEJn1JehbA ki6i0OdVNKtmxzNTnq3ktlS8M0YMyr2Ar9vrU8VM2+1YEB/czePsbJHzQ/yhbxRB2k8+ sxBJhwbEuWbcbleB11kjAJkYpy1PrygyTzRQ2E8frKF/RFlJvZYClNTeUFmcA+LnxujH Hu9TNzQ241cGMio4QBlshK7mmV8GMEfNUAqSPrq/x88rhxNGQPZZR5ZyXNAcSbT+IHE4 DuFOp8OV6pYU3wAiALuEEj9zR2I0reocqhk7JM00e2P1EsRkpTFw1NLhLid/MrOQf1KC Qa7w== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v3 10/21] nptl: powerpc: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 14 Oct 2019 17:56:45 -0300 Message-Id: <20191014205656.29834-11-adhemerval.zanella@linaro.org> In-Reply-To: <20191014205656.29834-1-adhemerval.zanella@linaro.org> References: <20191014205656.29834-1-adhemerval.zanella@linaro.org> This patch adds the powerpc modifications required for the BZ#12683 fix by adding the arch-specific cancellation syscall bridge. 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 | 67 +++++++++++++++++++ 3 files changed, 89 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 c21ea87f5a..689a708740 100644 --- a/sysdeps/powerpc/powerpc32/sysdep.h +++ b/sysdeps/powerpc/powerpc32/sysdep.h @@ -101,6 +101,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 db273f3346..fb6ede3e87 100644 --- a/sysdeps/powerpc/powerpc64/sysdep.h +++ b/sysdeps/powerpc/powerpc64/sysdep.h @@ -276,6 +276,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(__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..66d601da2a --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S @@ -0,0 +1,67 @@ +/* Cancellable syscall wrapper. Linux/powerpc version. + Copyright (C) 2019 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 + +/* 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 + .type __syscall_cancel_arch_start,@function +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + lwz r0,0(r3) + andi. r0,r0,0x4 + 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 + .type __syscall_cancel_arch_end,@function +__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) +libc_hidden_def (__syscall_cancel_arch)