Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934200AbcCIU5s (ORCPT ); Wed, 9 Mar 2016 15:57:48 -0500 Received: from mail-ob0-f170.google.com ([209.85.214.170]:32790 "EHLO mail-ob0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934063AbcCIU5m (ORCPT ); Wed, 9 Mar 2016 15:57:42 -0500 MIME-Version: 1.0 In-Reply-To: References: <06079088639eddd756e2092b735ce4a682081308.1457486598.git.luto@kernel.org> <20160309085631.GA3247@gmail.com> <20160309113449.GZ29662@port70.net> From: Andy Lutomirski Date: Wed, 9 Mar 2016 12:57:20 -0800 Message-ID: Subject: Re: [musl] Re: [RFC PATCH] x86/vdso/32: Add AT_SYSINFO cancellation helpers To: Linus Torvalds Cc: Ingo Molnar , Andy Lutomirski , "the arch/x86 maintainers" , Linux Kernel Mailing List , Borislav Petkov , "musl@lists.openwall.com" , Andrew Morton , Thomas Gleixner , Peter Zijlstra Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2407 Lines: 66 On Wed, Mar 9, 2016 at 11:47 AM, Linus Torvalds wrote: > On Wed, Mar 9, 2016 at 3:34 AM, Szabolcs Nagy wrote: >>> >>> Could someone remind me why cancellation points matter to user-space? >> >> because of standards. > > So quite frankly, if we have to do kernel support for this, then let's > do it right, instead of just perpetuating a hack that was done in user > space in a new way. > > We already have support for cancelling blocking system calls early: we > do it for fatal signals (exactly because we know that it's ok to > return -EINTR without failing POSIX semantics - the dying thread will > never actually *see* the -EINTR because it's dying). > > I suspect that what you guys want is the same semantics as a fatal > signal (return early with -EINTR), but without the actual fatality > (you want to do cleanup in the cancelled thread). > How safe would this be in a multithreaded process? For example, if open() gets canceled in the "killable" sense, is it guaranteed that no file descriptor will be allocated? > I suspect that we could fairly easily give those kinds of semantics. > We could add a new flag to the sigaction (sa_flags) that says "this > signal interrupts even uninterruptible system calls". > > Would that be good for you? > > And if not, can you explain the exact semantics you need? IThere might > be some reason why you cannot reserve a particular signal for this, > for example, but I'd like to know more precisely.. > > Because this "let's compare addresses" seems just excessively hacky. > It's a clever little hack when you're doing user space and don't want > to rely on kernel changes, but now that Andy is actuallty trying to > push kernel changes it turns into just disgusting. > Let me try to summarize my understanding of the semantics. Thread A sends thread B a signal. Thread B wants to ignore the signal and defer handling unless it's either in a particular syscall and returns -EINTR or unless the thread is about to do the syscall. This would all be trivial if there were a way to set up a signal that is *only* delivered in response to a syscall, no? SA_ONLY_IN_SYSCALL, perhaps? Frankly, I'm a bir surprised that musl didn't take the approach of "pthread cancellation is not such a great idea -- let's just not support it". > Linus -- Andy Lutomirski AMA Capital Management, LLC