From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=0.3 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 0AF4A200B9 for ; Mon, 7 May 2018 17:13:45 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=HJTEIPVi7xohjAac 0UA3YT9qcYJW2I3GkRsCP3bUCGqqHM0a2j/NvXqZo6A0JjoIe7JqtvpV/h4T1lL2 aVizH/JVMnaUOPMrQAHXPaxnaJKgzpn9t967mIM2u5amSA++/dNQ2pBKdHogVDTd Hy7cQFMPmDG5FNIdxQy2eUwv+So= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=FxIFAVDmRsx7E/Rtw29moe iIdaQ=; b=d2IxBP/M+415mDv6yLQXg7Zdo449Qjn2dCnuPLxZrwklFPWWaFIvaG K9M1vqL0KkHZ7i2Mko44IkQc60SdodBAUPLobrNmQRal1n484cMgBA+DUy4Ybu3E fbieFVjZ2xibbtEWVrl76A70tofr/TramcvfeWZ4Fq0LYZbrdsjNA= Received: (qmail 35657 invoked by alias); 7 May 2018 17:13:42 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 35643 invoked by uid 89); 7 May 2018 17:13:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-HELO: mail-qt0-f171.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=kEQTN4ZMbvwref1xWW4qyWZPjmgOAF0Crck1njpmY+w=; b=lfn+ziT0dz8MiQX583qDL6F62uCaZwEokhPDDfqLFkq5qEbngXv+pMBFjpSxaV5A2Q +lYIbNdjhzftbMvll9rMN6qAGLxVB2NdudlG4tVyiRXqRNxJsaaOC/EP7LVRQUaKw+Z1 u46aCVOzUu/b15PmUAHpuD8LyyCYGNWh0a6LHs2rD7nUbyHuus188aKSVQmsaJk02dNW qKkONVF3ARMHTyMN9dmNt0xi+5+ZCSObuxoPk2LutBQFgTx7xd5OK7YiaUBGDaicIuBh XjUXa4t1EmG4AQYGv6lBmjgzHmt4aXvY1onSMl8Hnf/3m8e309/ISAvCHE8bSTn3tHLz I1tg== X-Gm-Message-State: ALQs6tBKdKlzVkRGucVbuAx4RPy3etKAzhs+2gAKu1oWx56Doi4FpyhR MyEGMdtuiseAjz8yrDO+1uryC1y3nN0= X-Google-Smtp-Source: AB8JxZr8Fm/xHJMn1GxSePAnlf/p/cGM+Zx36KinPX99l2yk5JCwsXhkrhuBE05yfAn5AuE7pDoW/w== X-Received: by 2002:ac8:41e:: with SMTP id v30-v6mr35800649qtg.270.1525713217861; Mon, 07 May 2018 10:13:37 -0700 (PDT) Subject: Re: [PATCH v2 02/21] nptl: Fix testcases for new pthread cancellation mechanism To: Zack Weinberg , libc-alpha@sourceware.org References: <20180507024909.5598-1-zackw@panix.com> <20180507024909.5598-2-zackw@panix.com> From: Adhemerval Zanella Openpgp: preference=signencrypt Autocrypt: addr=adhemerval.zanella@linaro.org; prefer-encrypt=mutual; keydata= xsFNBFcVGkoBEADiQU2x/cBBmAVf5C2d1xgz6zCnlCefbqaflUBw4hB/bEME40QsrVzWZ5Nq 8kxkEczZzAOKkkvv4pRVLlLn/zDtFXhlcvQRJ3yFMGqzBjofucOrmdYkOGo0uCaoJKPT186L NWp53SACXguFJpnw4ODI64ziInzXQs/rUJqrFoVIlrPDmNv/LUv1OVPKz20ETjgfpg8MNwG6 iMizMefCl+RbtXbIEZ3TE/IaDT/jcOirjv96lBKrc/pAL0h/O71Kwbbp43fimW80GhjiaN2y WGByepnkAVP7FyNarhdDpJhoDmUk9yfwNuIuESaCQtfd3vgKKuo6grcKZ8bHy7IXX1XJj2X/ BgRVhVgMHAnDPFIkXtP+SiarkUaLjGzCz7XkUn4XAGDskBNfbizFqYUQCaL2FdbW3DeZqNIa nSzKAZK7Dm9+0VVSRZXP89w71Y7JUV56xL/PlOE+YKKFdEw+gQjQi0e+DZILAtFjJLoCrkEX w4LluMhYX/X8XP6/C3xW0yOZhvHYyn72sV4yJ1uyc/qz3OY32CRy+bwPzAMAkhdwcORA3JPb kPTlimhQqVgvca8m+MQ/JFZ6D+K7QPyvEv7bQ7M+IzFmTkOCwCJ3xqOD6GjX3aphk8Sr0dq3 4Awlf5xFDAG8dn8Uuutb7naGBd/fEv6t8dfkNyzj6yvc4jpVxwARAQABzUlBZGhlbWVydmFs IFphbmVsbGEgTmV0dG8gKExpbmFybyBWUE4gS2V5KSA8YWRoZW1lcnZhbC56YW5lbGxhQGxp bmFyby5vcmc+wsF3BBMBCAAhBQJXFRpKAhsDBQsJCAcDBRUKCQgLBRYCAwEAAh4BAheAAAoJ EKqx7BSnlIjv0e8P/1YOYoNkvJ+AJcNUaM5a2SA9oAKjSJ/M/EN4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ux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180507024909.5598-2-zackw@panix.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 06/05/2018 23:49, Zack Weinberg wrote: > On 26 Feb 2018, Adhemerval Zanella wrote: >> With upcoming fix for BZ#12683, pthread cancellation does not act for: >> >> 1. If syscall is blocked but with some side effects already having >> taken place (e.g. a partial read or write). >> 2. After the syscall has returned. >> >> The main change is due the fact programs need to act in syscalls with >> side-effects (for instance, to avoid leak of allocated resources or >> handle partial read/write). >> >> This patch changes the NPTL testcase that assumes the old behavior and >> also remove the tst-cancel-wrappers.sh test (which checks for symbols >> that will not exist anymore). > > It's OK and expected that we have to adjust test cases that were > expecting the old behavior ... > >> For tst-cancel{2,3} case it remove the pipe close because it might >> cause the write syscall to return with side effects if the close is >> executed before the pthread cancel. > > ... however, this change appears to be wrong. If cancellation is > broken, these tests will now deadlock rather than failing cleanly. On current cancellation implementation the thread will finish regardless and sigcancel_handler will act whether there is side-effects or not (the pipe close). The issue is cancellation should not happen if syscall returns but some side effects already took place, in this case the pipe close. > > If I understand correctly, the problem you're trying to avoid is that > the 'tf' thread could conceivably receive the closed-pipe event before > the cancellation signal, even though the 'do_test' thread triggers the > cancellation signal first. I don't know of any way to fix this 100%, > but I think it would be good enough to use pthread_timedjoin_np to > sleep for a hundred milliseconds or so in the 'do_test' thread, and > then close the pipe if the 'tf' thread is still alive. Yes, although for this specific case I am not sure if this could happen in practice. I assume if a thread issues a 'signal' followed by a 'close', the signal target thread will receive the events in a ordered manner, i.e, the signal handler will be activated before the syscall sees any side-effects (the close). It seems to be Linux behaviour, but I am not sure if a different system might act differently. And I try to avoid the timing check, such as pthread_timedjoin_np, because they tend to quite fragile in practice for such cases (due either to system load when testing glibc, machine performance, etc.). I will remove the close removal changes in next iteration. > > (tst-cancel4.c appears to be trying to ensure that cancellations are > pending with a pthread_barrier_t, but as far as I know there's no > guarantee that if a thread does > > pthread_cancel(th); > pthread_barrier_wait(ba); > > where 'th' also waits on 'ba', the SIGCANCEL will actually be > delivered before the barrier unblocks, either. Feh.) > >> It also changes how to call the read syscall on tst-backtrace{5,6} >> to use syscall instead of read cancelable syscall to avoid need to >> handle the cancelable bridge function calls. It requires a change >> on powerpc syscall implementation to create a stackframe, since >> powerpc backtrace rely on such information. > > It doesn't look technically difficult to me to handle an additional > stack frame or two in the trace. They're always going to be there, > aren't they? In the new world order, the stack trace will always be > > 0 handle_signal > 1 > 2 __syscall_cancel_arch > 3 __syscall_cancel > 4 read > 5 fn > 6 fn > 7 fn > 8 do_test > > won't it? I think teaching the backtrace logic about this would be > better than needing to use a raw syscall() and then mess with the > PowerPC implementation of syscall(). I might feel differently about > this change if __read_nocancel were a public API, but it isn't... With your current suggestion to powerpc syscall bits, there is no need to actually change the powerpc syscall implementation besides an additional CFI mechanism. But I do not mind to change the testcase on the bz12683 fix itself, the only advantage I see is by using indirect syscall there is no need to actually change it again. > >> Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32, >> aarch64-linux-gnu, arm-linux-gnueabihf, powerpc64le-linux-gnu, >> powerpc-linux-gnu, sparcv9-linux-gnu, and sparc64-linux-gnu. > > When you say checked, do you mean you actually ran the test cases, or > did you just compile them (perhaps with a cross-compiler)? It is a full make check on native machines. > >> * nptl/Makefile [$(run-built-tests) = yes] (tests-special): Remove >> tst-cancel-wrappers.sh. >> * nptl/tst-cancel-wrappers.sh: Remove file. > > This part is OK. > >> * nptl/tst-cancel4.c (tf_write): Handle cancelled syscall with >> side-effects. >> (tf_send): Likewise. > > This part is also OK. I think the test can still fail spuriously due > to races, but this one can't deadlock, at least, so we can live with it. > >> * sysdeps/unix/sysv/linux/powerpc/syscall.S (syscall): Create stack >> frame. > > This ChangeLog entry belongs to patch 1. Ack. I will remove it. > > zw >