From patchwork Tue Feb 21 19:26:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 65428 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 072D6385B516 for ; Tue, 21 Feb 2023 19:27:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 072D6385B516 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677007629; bh=oyTApXCm6xFqP4hWRXKK51WYu+/fkkYfFFGTSmKsVq4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=u3FNuZf2I7Hs+dXO79J8IRhNqoz+Zdceejix36z1bylx0vnE8anVOEu0M2HQEYTmf xlBC7reILMepXMJfiv9WISteYRMuJYszXBwyzSeU0JV/PFNXCqZ7vf7EISE4ifIr15 DKR1fWyHe4mTBgj2qXUfF6l8Gh+mI/SuWBTOGQ2E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 62B863858C2B for ; Tue, 21 Feb 2023 19:26:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 62B863858C2B Received: by mail-oi1-x233.google.com with SMTP id bg11so5417561oib.5 for ; Tue, 21 Feb 2023 11:26:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677007605; 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=oyTApXCm6xFqP4hWRXKK51WYu+/fkkYfFFGTSmKsVq4=; b=1l7ZLlULGsmX1TF0/QZI65DIuLLlAPXMGhq6jkHgEYSQsckVrrF+qnXtf7/Yts/G2y 8fTbz6UWuIpMp3CaKArL1Y8zox6tSLHLfppbA8SQbbXild6qW086UVFOwJTSn1NuhGpO plpR3xFRkZkjLVUc4CzaHcsMiB7rc1xYmNz98kgOSV4PO+yyr+HzTix+o/XtV2/aScq7 YjfiZUoZqCDSlRZEvwb4vtRbayva1xDITdBzTNiNfwc83HLjQDbYzc2bHUa68oQEbw3H dexoVA/fG7jfiZ0kguPjW/jXK5ql3dW2nqqPGjr2WraylNcZbPbsHXPnRrWIyHsZw9wo xYSg== X-Gm-Message-State: AO0yUKXtuioqlMmLpTA7Do+3fpjKrWGwDtHIW6Pl7Zdvu7OUIP2SSRVf R8EH8Kuz81KH7Ivc7Hz7sziOe869UZrCwIeg/94= X-Google-Smtp-Source: AK7set/mgwRZkwF5rBNdKd2Uv83djEWq9eK7jQn/gSXZDNaCXg01wW7EnG4Ey1UQbSjstjhC/g21gg== X-Received: by 2002:a05:6808:618e:b0:378:5a94:8b22 with SMTP id dn14-20020a056808618e00b003785a948b22mr1970744oib.47.1677007605148; Tue, 21 Feb 2023 11:26:45 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:3a5:3769:ff3e:331a:7f95]) by smtp.gmail.com with ESMTPSA id x5-20020acae005000000b0037868f9e657sm461336oig.37.2023.02.21.11.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 11:26:44 -0800 (PST) To: libc-alpha@sourceware.org, DJ Delorie Subject: [PATCH v2] i386: Use pthread_barrier for synchronization on tst-bz21269 Date: Tue, 21 Feb 2023 16:26:40 -0300 Message-Id: <20230221192640.3650934-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. --- 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..bc2a380a11 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 @@ -40,6 +37,9 @@ #include #include #include +#include + +#define NITER 5 static int xset_thread_area (struct user_desc *u_info) @@ -55,13 +55,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) { @@ -69,7 +62,7 @@ xsethandler (int sig, void (*handler)(int, siginfo_t *, void *), int flags) sa.sa_sigaction = handler; sa.sa_flags = SA_SIGINFO | flags; TEST_VERIFY_EXIT (sigemptyset (&sa.sa_mask) == 0); - TEST_VERIFY_EXIT (sigaction (sig, &sa, 0) == 0); + xsigaction (sig, &sa, 0); } static jmp_buf jmpbuf; @@ -123,33 +116,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,18 +164,19 @@ 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 = { .entry_number = 0, @@ -207,28 +192,19 @@ do_test (void) xmodify_ldt (0x11, &desc, sizeof (desc)); - /* Arm the thread. */ - ftx = 1; - futex ((int*) &ftx, FUTEX_WAKE, 0, NULL, NULL, 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; }