From patchwork Fri Apr 3 20:31:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 38742 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by sourceware.org (Postfix) with ESMTPS id 34E8D388B828 for ; Fri, 3 Apr 2020 20:32:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 34E8D388B828 Received: by mail-qt1-x82a.google.com with SMTP id i3so7638305qtv.8 for ; Fri, 03 Apr 2020 13:32:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=op3TeVdQV0Pm09yUX2QOHpbwi6dWGEAIThUk8gIKnSw=; b=qpMmJo6ZN+nwPJZJCNNBE/UKI0Ng58/p00CW8JiGdsNWEIFjHOGXF9o78MKOq6nVCJ TEreo/CP1JtRvoNs9uK8eKf8T5ASf773YeLCvyzm06HWo2c3J55QtOG8sqAAdsRkDksz kH5SjKsBqkhXTQ2ZrBTSI0cZ07DLefFDY1Ri0GQEl6jN3t9XSNPEAVjslUF7hM5bDTUf rhc7gQm1ZDqDYwQEqyktmtqV8n43oXNPKsluIgjJaE1RvKjyv8ewA5yNoN1J/+xPTAbp VpuHAOOoXfJXHobh78PIbkiZ5Ye9TYBPDXBUOkGz8+WueYuP+HFhSzhX1ZNVTV5mgNsL CPHA== X-Gm-Message-State: AGi0PuZjn1IZFX+WZZ6lYAR7MmTbJr66z8SLLdc6PoA0rcyMl5rp86xw eT9zC/9hztzqYBbAZXJJSmxyjGaxFOI= X-Google-Smtp-Source: APiQypLZrBA9qAIBC0KLe409mmgUuh4sKvhggeXZ7fuWK+x4lo9kcVIznJhq7zqTakZ3VcJGX9KHYw== X-Received: by 2002:ac8:2939:: with SMTP id y54mr10102411qty.160.1585945952404; Fri, 03 Apr 2020 13:32:32 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id d141sm7063535qke.68.2020.04.03.13.32.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 13:32:32 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v4 17/21] nptl: riscv: Fix Race conditions in pthread cancellation [BZ#12683] Date: Fri, 3 Apr 2020 17:31:57 -0300 Message-Id: <20200403203201.7494-18-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200403203201.7494-1-adhemerval.zanella@linaro.org> References: <20200403203201.7494-1-adhemerval.zanella@linaro.org> X-Spam-Status: No, score=-26.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Apr 2020 20:32:34 -0000 This patch adds the riscv modifications required for the BZ#12683 fix by adding the arch-specific cancellation syscall bridge. Reviewed-by: Andrew Waterman --- sysdeps/riscv/nptl/tcb-offsets.sym | 3 + sysdeps/riscv/nptl/tls.h | 2 + .../unix/sysv/linux/riscv/syscall_cancel.S | 67 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/riscv/syscall_cancel.S diff --git a/sysdeps/riscv/nptl/tcb-offsets.sym b/sysdeps/riscv/nptl/tcb-offsets.sym index ab4981f2e2..bcee223d1e 100644 --- a/sysdeps/riscv/nptl/tcb-offsets.sym +++ b/sysdeps/riscv/nptl/tcb-offsets.sym @@ -4,3 +4,6 @@ #define thread_offsetof(mem) (long)(offsetof (struct pthread, mem) - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads) + +-- Not strictly offsets, used on syscall_cancel.S +TCB_CANCELED_BITMASK CANCELED_BITMASK diff --git a/sysdeps/riscv/nptl/tls.h b/sysdeps/riscv/nptl/tls.h index a9167bc143..21e9124564 100644 --- a/sysdeps/riscv/nptl/tls.h +++ b/sysdeps/riscv/nptl/tls.h @@ -142,6 +142,8 @@ typedef struct # define THREAD_GSCOPE_WAIT() \ GL(dl_wait_lookup_done) () +#else /* __ASSEMBLER__ */ +# include #endif /* __ASSEMBLER__ */ #endif /* tls.h */ diff --git a/sysdeps/unix/sysv/linux/riscv/syscall_cancel.S b/sysdeps/unix/sysv/linux/riscv/syscall_cancel.S new file mode 100644 index 0000000000..520e25aa3a --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/syscall_cancel.S @@ -0,0 +1,67 @@ +/* Cancellable syscall wrapper. Linux/riscv version. + 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 + . */ + +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6) */ + +#ifdef SHARED + .option pic +#else + .option nopic +#endif + +ENTRY (__syscall_cancel_arch) + mv t1, a7 + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + lw a7, 0(a0) + /* if (*ch & CANCELED_BITMASK) */ + andi a7, a7, TCB_CANCELED_BITMASK + bnez a7, 1f + + mv a7,a1 + mv a0,a2 + mv a1,a3 + mv a2,a4 + mv a3,a5 + mv a4,a6 + mv a5,t1 + scall + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + ret + +1: + addi sp, sp, -16 + cfi_def_cfa_offset (16) + sd ra, 8(sp) + cfi_offset (ra, -8) + call __syscall_do_cancel + +END (__syscall_cancel_arch) +libc_hidden_def (__syscall_cancel_arch)