From patchwork Tue Feb 28 14:30:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 65776 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 C82153858281 for ; Tue, 28 Feb 2023 14:30:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C82153858281 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677594639; bh=7IDJPa3pQyGEJOefyUw05RxV7MZtmLdfvoUMMTOBNQI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=K11LPYNGNoR1WdI3RnGbWOaFavyIeTPpK0kgxGNvbnc2zD0hFPGbHwznEqYcPs7JS Ydj/seh4YG0ig8z/XX16dfvqncZlmaIP08vQ1SjXmshNf+Dzj8jHQjK99yu3VM11MO tPb3B49AuUCXT7MZqvTMB/Ods1xJCSZxHaMbC43Q= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id CB29C385842C for ; Tue, 28 Feb 2023 14:30:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB29C385842C Received: by mail-oi1-x22f.google.com with SMTP id c11so8171271oiw.2 for ; Tue, 28 Feb 2023 06:30:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677594615; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7IDJPa3pQyGEJOefyUw05RxV7MZtmLdfvoUMMTOBNQI=; b=vUCF6rpbbxBrWYpQUeybKwS9RBrOEi6GqIsIw3VAkQI7oOHdY91qFtmOcMcpt/FgsH EbZud930a9AQraCix4y9AqK/JheHm/NCGy8DumciHVVZH4y0HnojqkITupuDJDjjUOLw yFMIZmvWlvz/10QPmLjRJK7cgxtk+xrut43CV5OtiSzANzT/c44LY0EN81Zy7lZim4ZU 7WDTGadF7N0JS+BhXeLn0+0crPm92JH3hHekIeb9KIO68L6/LxUuITfo9MPti1Kltghj dS1BrgQIG7H0kDF6HuSctR0HqG4PWtbSmEnp/J6xcL2mVjQs2vfnLHK9BUgPKUJR+7xI yiqg== X-Gm-Message-State: AO0yUKX5aWb92oTIVf4bjZiesVkzm7LY2cIWGt/jgDcYOLfZFrOlwd4U iajwe9JU1BaAe7bO6njI7j4dYwSOGwRCLLxePoc= X-Google-Smtp-Source: AK7set/TIiGH8y2sGdBgnBI0A69owoEzQTa1gR+0USX6LTMkFd0OWt4uoE81mUwN3dnbzqW27ThuNQ== X-Received: by 2002:a05:6808:bca:b0:37a:2bf0:502e with SMTP id o10-20020a0568080bca00b0037a2bf0502emr6377096oik.28.1677594615316; Tue, 28 Feb 2023 06:30:15 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:d849:7299:419:6fb3:7a8]) by smtp.gmail.com with ESMTPSA id u13-20020a4ad0cd000000b0052037988717sm3813661oor.4.2023.02.28.06.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 06:30:14 -0800 (PST) To: libc-alpha@sourceware.org, DJ Delorie Subject: [PATCH v4] i386: Use pthread_barrier for synchronization on tst-bz21269 Date: Tue, 28 Feb 2023 11:30:11 -0300 Message-Id: <20230228143011.784920-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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" To improve the false negative in patchwork buildbot. Checked on i686-linux-gnu and I also checked by reverting the original bz21269 fix to pass a bogus sa_restore value (and thus triggering the test failure). --- sysdeps/unix/sysv/linux/i386/tst-bz21269.c | 62 +++++++--------------- 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/sysdeps/unix/sysv/linux/i386/tst-bz21269.c b/sysdeps/unix/sysv/linux/i386/tst-bz21269.c index 1850240c34..deaf9e5ef8 100644 --- a/sysdeps/unix/sysv/linux/i386/tst-bz21269.c +++ b/sysdeps/unix/sysv/linux/i386/tst-bz21269.c @@ -20,16 +20,13 @@ more specifically in do_multicpu_tests function. The main changes are: - - C11 atomics instead of plain access. + - Use pthread_barrier instead of atomic and futexes. - Remove x86_64 support which simplifies the syscall handling and fallbacks. - Replicate only the test required to trigger the issue for the BZ#21269. */ -#include - #include -#include #include #include @@ -41,6 +38,8 @@ #include #include +#define NITER 5 + static int xset_thread_area (struct user_desc *u_info) { @@ -55,13 +54,6 @@ xmodify_ldt (int func, const void *ptr, unsigned long bytecount) TEST_VERIFY_EXIT (syscall (SYS_modify_ldt, 1, ptr, bytecount) == 0); } -static int -futex (int *uaddr, int futex_op, int val, void *timeout, int *uaddr2, - int val3) -{ - return syscall (SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3); -} - static void xsethandler (int sig, void (*handler)(int, siginfo_t *, void *), int flags) { @@ -123,33 +115,24 @@ setup_low_user_desc (void) low_user_desc_clear->seg_not_present = 1; } -/* Possible values of futex: - 0: thread is idle. - 1: thread armed. - 2: thread should clear LDT entry 0. - 3: thread should exit. */ -static atomic_uint ftx; +static pthread_barrier_t barrier; static void * threadproc (void *ctx) { - while (1) + for (int i = 0; i < NITER; i++) { - futex ((int *) &ftx, FUTEX_WAIT, 1, NULL, NULL, 0); - while (atomic_load (&ftx) != 2) - { - if (atomic_load (&ftx) >= 3) - return NULL; - } + xpthread_barrier_wait (&barrier); /* clear LDT entry 0. */ const struct user_desc desc = { 0 }; xmodify_ldt (1, &desc, sizeof (desc)); - /* If ftx == 2, set it to zero, If ftx == 100, quit. */ - if (atomic_fetch_add (&ftx, -2) != 2) - return NULL; + /* Wait for 'ss' set in main thread. */ + xpthread_barrier_wait (&barrier); } + + return NULL; } @@ -180,20 +163,21 @@ do_test (void) /* Some kernels send SIGBUS instead. */ xsethandler (SIGBUS, sigsegv_handler, 0); + xpthread_barrier_init (&barrier, NULL, 2); + thread = xpthread_create (0, threadproc, 0); asm volatile ("mov %%ss, %0" : "=rm" (orig_ss)); - for (int i = 0; i < 5; i++) + for (int i = 0; i < NITER; i++) { if (sigsetjmp (jmpbuf, 1) != 0) continue; /* Make sure the thread is ready after the last test. */ - while (atomic_load (&ftx) != 0) - ; + xpthread_barrier_wait (&barrier); - struct user_desc desc = { + const struct user_desc desc = { .entry_number = 0, .base_addr = 0, .limit = 0xffff, @@ -207,28 +191,20 @@ do_test (void) xmodify_ldt (0x11, &desc, sizeof (desc)); - /* Arm the thread. */ - ftx = 1; - futex ((int*) &ftx, FUTEX_WAKE, 0, NULL, NULL, 0); + /* Wait thread clear LDT entry 0. */ + xpthread_barrier_wait (&barrier); asm volatile ("mov %0, %%ss" : : "r" (0x7)); - /* Fire up thread modify_ldt call. */ - atomic_store (&ftx, 2); - - while (atomic_load (&ftx) != 0) - ; - /* On success, modify_ldt will segfault us synchronously and we will escape via siglongjmp. */ support_record_failure (); } - atomic_store (&ftx, 100); - futex ((int*) &ftx, FUTEX_WAKE, 0, NULL, NULL, 0); - xpthread_join (thread); + xpthread_barrier_destroy (&barrier); + return 0; }