From patchwork Fri Feb 24 16:15:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 65602 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 683ED38555A4 for ; Fri, 24 Feb 2023 16:15:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 683ED38555A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677255358; bh=IDxerWKvxj3yTydMeqNRSRPyFBlxbWYxdhhst5Hnpew=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wSxlceAdjy0RuGDcGhy7jl3sqwzye1fV/vVaJlukqL3mvZHSSTdATWJtg+dsqU5Rc t8KF5eEf+E0itkwH1hhw4cUa6QbfNT00Y6pPWB0qoVCK9aPgASGiHOb0bJEW1hzvgK +TwnZ5+rAa99jCp+h/GHEyDWfmEavZlZPAgWqdPc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by sourceware.org (Postfix) with ESMTPS id 9CD76385B501 for ; Fri, 24 Feb 2023 16:15:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9CD76385B501 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-172b0ba97b0so6017fac.4 for ; Fri, 24 Feb 2023 08:15:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677255334; 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=IDxerWKvxj3yTydMeqNRSRPyFBlxbWYxdhhst5Hnpew=; b=r5kkWWDTdiQZmggbDCoYsjb915U7VIBvl1aGvgvuzPfv74pqYfqHR8a8GG6scvp0EP fynB+a0/Bsm0UnX/ULchNcPDL5vEH5prZyHOKs3JFOXqjbLhcLKFbuf6yxRP2bSNZmWi 04DzQDlhJy66cNmz+3woChVcnxVUp/YEDsDINhPQbZLvVmjIg1OeDkOPLcreAU3qyNBB cjsQT7SRNPywb4INAOpY2FtfU3oENvDivTBQavpg4yanthzbIJ1BKNpRrgCiQ3N/4nLC hWsTzZ7a3xEBiutTVZ0txdkha47dpRUQhRVHaS4GFd9dFd5BlkiFSeWlWAFgPb7V/Sj9 8+2A== X-Gm-Message-State: AO0yUKVyDpz27b3f5jXdRSiJ6TvHK6/qCShKuc41CahgGlra31suQ2kT r5hFJxOCEu8zWFVDPfgrnDfV/4ZPhyDWxXX3EWo= X-Google-Smtp-Source: AK7set+Cwm82mqWtOv+xgQnDgKaToUm8MRAbxv3gRGNUt+LLtGA8c1Ym9CEJdUzGNFZY85S/0hawHg== X-Received: by 2002:a05:6870:64ab:b0:16d:ed9f:75ee with SMTP id cz43-20020a05687064ab00b0016ded9f75eemr13954584oab.53.1677255333689; Fri, 24 Feb 2023 08:15:33 -0800 (PST) Received: from ubuntu-vm.. ([2804:18:18f9:9546:cde:c1c:28a:7b75]) by smtp.gmail.com with ESMTPSA id l22-20020a056870e91600b00172a7cfa45dsm530344oan.12.2023.02.24.08.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 08:15:32 -0800 (PST) To: libc-alpha@sourceware.org, DJ Delorie Subject: [PATCH v3] i386: Use pthread_barrier for synchronization on tst-bz21269 Date: Fri, 24 Feb 2023 16:15:28 +0000 Message-Id: <20230224161528.997-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 | 69 ++++++++-------------- 1 file changed, 23 insertions(+), 46 deletions(-) diff --git a/sysdeps/unix/sysv/linux/i386/tst-bz21269.c b/sysdeps/unix/sysv/linux/i386/tst-bz21269.c index 1850240c34..351a9187e7 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,20 +164,18 @@ 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) - ; - - struct user_desc desc = { + const struct user_desc desc = { .entry_number = 0, .base_addr = 0, .limit = 0xffff, @@ -207,28 +189,23 @@ do_test (void) xmodify_ldt (0x11, &desc, sizeof (desc)); - /* Arm the thread. */ - ftx = 1; - futex ((int*) &ftx, FUTEX_WAKE, 0, NULL, NULL, 0); - - asm volatile ("mov %0, %%ss" : : "r" (0x7)); + /* Make sure the thread is ready after the last test. */ + xpthread_barrier_wait (&barrier); - /* Fire up thread modify_ldt call. */ - atomic_store (&ftx, 2); + /* Wait thread clear LDT entry 0. */ + xpthread_barrier_wait (&barrier); - while (atomic_load (&ftx) != 0) - ; + asm volatile ("mov %0, %%ss" : : "r" (0x7)); /* 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; }