From patchwork Mon Apr 10 19:58:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 67573 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92DE03857717 for ; Mon, 10 Apr 2023 19:59:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92DE03857717 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681156779; bh=TDUqa1KFRgWXwQiFuIC/388RyAU957ehsxXfSDRO3dw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=AT6NH2ivyKgkgj282r2R3+d5ajr+XfH8/L5ivAyLAztYcwHcKuAQ7jpSh/KfLIxVx ycBqJZyejGgTWCd6GeMt+U809fNvmpWK7vjK1eJf+k6DmoBsKtvAbJqgWxJJ6Z4ptX ujya59cy2EyXJGsSOpnFinyOyvdWJLP/HiLh72cY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 5DEE63858C62 for ; Mon, 10 Apr 2023 19:59:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DEE63858C62 Received: by mail-ot1-x32f.google.com with SMTP id f10-20020a9d2c0a000000b006a13f728172so701946otb.3 for ; Mon, 10 Apr 2023 12:59:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681156755; x=1683748755; 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=TDUqa1KFRgWXwQiFuIC/388RyAU957ehsxXfSDRO3dw=; b=D1jP/h1y7Lgz6nvSJvIBalbugAriD7q7mya6cqpLw0snfoQxTOBMxe82J4JqIShAMv YWL0LikTbCXzfcKVWTpdlIsmOaMnYG9OyMehhevC9KOe3OOr5ftA8/C1OusEcDz6C7Wk AABW8q8pmbxUTEi2ZHVukokxWTpOkiTp7HdEMqoKt9k0EAdP6xR4LQVbeZoO71q6+EG/ 1LcQI/rrutKGseWEcne7puRKbAMPaJ8dLjQ3qCcQgbd9HxbVuhAPmTHynWuYGCAAli/M 2IDeg4eUK5LnJifxMnG5y3D3JtEog19RHk0lny6qS3BhdQnIdntZsZxsZAQmEyoOGYY6 nV3Q== X-Gm-Message-State: AAQBX9cvnaPmRLR3EsSL4lTAi7owThp5p2BI3l0ePP0v6K91Prb/GmvN gKstAGSyKGHpSL54meqkLQR4NXCQaCgskP7WQw6fJQ== X-Google-Smtp-Source: AKy350ajyNauUbNQP+Of0yvks1ca2r77fRIYF3WovPYTKFXHDmvTfc8qrYHcg6cUx3jXyVu9fLnHxA== X-Received: by 2002:a9d:6c57:0:b0:69f:a6f8:37ec with SMTP id g23-20020a9d6c57000000b0069fa6f837ecmr248628otq.29.1681156755394; Mon, 10 Apr 2023 12:59:15 -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.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 12:59:14 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 02/22] x86_64: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 16:58:47 -0300 Message-Id: <20230410195907.4123869-3-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 X-Spam-Status: No, score=-12.1 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked on x86_64-linux-gnu. --- .../unix/sysv/linux/x86_64/syscall_cancel.S | 57 +++++++++++++++++++ sysdeps/x86_64/nptl/tcb-offsets.sym | 3 - 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S b/sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S new file mode 100644 index 0000000000..cda9d20a83 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S @@ -0,0 +1,57 @@ +/* Cancellable syscall wrapper. Linux/x86_64 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 [rax] __syscall_cancel_arch (volatile int *cancelhandling [%rdi], + __syscall_arg_t nr [%rsi], + __syscall_arg_t arg1 [%rdx], + __syscall_arg_t arg2 [%rcx], + __syscall_arg_t arg3 [%r8], + __syscall_arg_t arg4 [%r9], + __syscall_arg_t arg5 [SP+8], + __syscall_arg_t arg6 [SP+16]) */ + +ENTRY (__syscall_cancel_arch) + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + mov (%rdi),%eax + testb $TCB_CANCELED_BITMASK, (%rdi) + jne __syscall_do_cancel + + /* Issue a 6 argument syscall, the nr [%rax] being the syscall + number. */ + mov %rdi,%r11 + mov %rsi,%rax + mov %rdx,%rdi + mov %rcx,%rsi + mov %r8,%rdx + mov %r9,%r10 + mov 8(%rsp),%r8 + mov 16(%rsp),%r9 + mov %r11,8(%rsp) + syscall + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + ret +END (__syscall_cancel_arch) diff --git a/sysdeps/x86_64/nptl/tcb-offsets.sym b/sysdeps/x86_64/nptl/tcb-offsets.sym index 2bbd563a6c..988a4b8593 100644 --- a/sysdeps/x86_64/nptl/tcb-offsets.sym +++ b/sysdeps/x86_64/nptl/tcb-offsets.sym @@ -13,6 +13,3 @@ MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads) POINTER_GUARD offsetof (tcbhead_t, pointer_guard) FEATURE_1_OFFSET offsetof (tcbhead_t, feature_1) SSP_BASE_OFFSET offsetof (tcbhead_t, ssp_base) - --- Not strictly offsets, but these values are also used in the TCB. -TCB_CANCELED_BITMASK CANCELED_BITMASK