Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp564006ybi; Fri, 24 May 2019 08:01:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+xUJQBk+QgrZcMrUnPRVUoa98lbtO42pKpFjNjxdrbRIImdjpyK0UDbHu2FqlYu1v/Z/e X-Received: by 2002:a17:902:6ac6:: with SMTP id i6mr106623386plt.336.1558710099805; Fri, 24 May 2019 08:01:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558710099; cv=none; d=google.com; s=arc-20160816; b=NqqYu1ABJuiSTxYrIgv8bvmNyrPL1Q3lTPQvr60gzD31jPEwaeBw2TBZMKEg4HeVdS wVsmT7biwhtWYTYyoLAwfVXKQtGIkv38byMeW3gsHshAHJv7KXLNCozS1kLIpAZq4FJ8 xj2eKa+cspy4rFrLYGkZN7pbaYcY17Bl5TC9zo48qlUn7CS9PFpnhSF5MqtmlgqLifIf hRXkB7lYhnzgYQrOmNZBqzxE5veIh9K6Q5Kz6mSSF47wVRwVqrs9QYEbRZm38mkQbKVL kmD1/upfzFE8UcUJIhXT3V4ZL8yfhGgB4SgAZLCFWREZDm9ev0DgLZkThWG15Aju49Je e15A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=S+q3LDDf0Tnc7HGS/LC4jLrZlfFUjl3b/eVfU0YV0nQ=; b=ybe73tQVrFYOcS15LSEPuzRKXXNpstGRwtuoYRO2icWjtamG18MuaxOt8TB1VL0Xeq r5gxUBIqhDzNVUydA441szS0CHnNNJA55b5LyTyQ1bnfZBPx12eyI5q0xQilo6YhIhth Bp+WaEJ+5QnEn6Fx0A3wJie8n1gVYyeknQusVRJhvdOuEWOZhMcV4I8A/dHZSMrOyYSr T6senYtAHnmRKPmEXtKL6hnFIC/23uGq3aE7ctcD9sDcpYPb0422slZL85vYopmQ84zt GH59O5ErBygq4jqqvlPEDEuCIcrWcJKyQRSHAHQdRit5n0QiaT3/wrkvQxl6d03caGw4 9uDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q13si4172137pll.162.2019.05.24.08.01.21; Fri, 24 May 2019 08:01:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404134AbfEXO7v convert rfc822-to-8bit (ORCPT + 99 others); Fri, 24 May 2019 10:59:51 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:21958 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404054AbfEXO7u (ORCPT ); Fri, 24 May 2019 10:59:50 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-4-IqGpfYYFOqCYiNehhRN8dg-1; Fri, 24 May 2019 15:59:43 +0100 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 24 May 2019 15:59:42 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Fri, 24 May 2019 15:59:42 +0100 From: David Laight To: 'Oleg Nesterov' CC: 'Deepa Dinamani' , Linux Kernel Mailing List , Andrew Morton , Alexander Viro , Arnd Bergmann , "dbueso@suse.de" , "axboe@kernel.dk" , Davidlohr Bueso , Eric Wong , Jason Baron , Linux FS-devel Mailing List , linux-aio , Omar Kilani , Thomas Gleixner , "stable@vger.kernel.org" Subject: RE: [PATCH v2] signal: Adjust error codes according to restore_user_sigmask() Thread-Topic: [PATCH v2] signal: Adjust error codes according to restore_user_sigmask() Thread-Index: AQHVELwtsgR+BAQFXk2JV68Wk/7LjKZ4aINAgABVkoCAAB2x0P///TgAgAARdkCAAUypAIAAGykA Date: Fri, 24 May 2019 14:59:42 +0000 Message-ID: <766510cbbec640b18fd99f3946b37475@AcuMS.aculab.com> References: <20190522032144.10995-1-deepa.kernel@gmail.com> <20190522150505.GA4915@redhat.com> <20190522161407.GB4915@redhat.com> <4f7b6dbeab1d424baaebd7a5df116349@AcuMS.aculab.com> <20190523145944.GB23070@redhat.com> <345cfba5edde470f9a68d913f44fa342@AcuMS.aculab.com> <20190523163604.GE23070@redhat.com> <20190524132911.GA2655@redhat.com> In-Reply-To: <20190524132911.GA2655@redhat.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-MC-Unique: IqGpfYYFOqCYiNehhRN8dg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oleg Nesterov > Sent: 24 May 2019 14:29 > It seems that we all are just trying to confuse each other. I got lost. I'm always lost :-) > On 05/23, David Laight wrote: > > > > From: Oleg Nesterov > > > Sent: 23 May 2019 17:36 > > > On 05/23, David Laight wrote: > > > > > > > > From: Oleg Nesterov > > > > > On 05/23, David Laight wrote: > > ... > > > > > Not sure I understand... OK, suppose that you do > > > > > > > > > > block-all-signals; > > > > > ret = pselect(..., sigmask(SIG_URG)); > > > > > > > > > > if it returns success/timeout then the handler for SIG_URG should not be called? > > > > > > > > Ugg... > > > > Posix probably allows the signal handler be called at the point the event > > > > happens rather than being deferred until the system call completes. > > > > Queueing up the signal handler to be run at a later time (syscall exit) > > > > certainly makes sense. > > > > Definitely safest to call the signal handler even if success/timeout > > > > is returned. > > > > > > Why? > > > > > > > pselect() exists to stop the entry race, not the exit one. > > > > > > pselect() has to block SIG_URG again before it returns to user-mode, right? > > > > Yep. > > So the signal handler can't be called for a signal that happens after > > pselect() returns. > > Yes. And "after pselect() returns" actually means "after pselect() restores > the old sigmask while it returns to user mode". > > > > Suppose pselect() finds a ready fd, and this races with SIG_URG. > > > > You mean if SIG_URG is raised after a ready fd is found (or even timeout)? > > So the return value isn't EINTR. > > Yes. > > > (If an fd is readable on entry, the SIG_URG could have happened much earlier.) > > Why not? See the pseudo code above. It was blocked before pselect() was called. > So SIG_URG can be already pending when pselect() is called but since an fd is > already ready on entry pselect() restores the old sigmask (and thus blocks SIG_URG > again) and returns success. The handler is not called. > > However, if there is no a ready fd, pselect won't block. It will notice SIG_URG, > deliver this signal, and return -EINTR. To my mind changing the signal mask should be enough to get a masked signal handler called - even if the mask is reset before the syscall exits. There shouldn't be any need for an interruptible wait to be interrupted. I suspect that if you send a signal to a process that is looping in userspace (on a different) the signal handler is called on the next exit to userspace regardless as to whether the kernel blocks. epoll and pselect shouldn't be any different. Having the signal unmasked at any time should be enough to get it called. ... > > > What if SIG_URG comes right after pselect() blocks SIG_URG again? I mean, > > > how this differs the case when it comes before, but a ready fd was already > > > found? > > > > I suspect you need to defer the re-instatement of the original mask > > to the code that calls the signal handlers (which probably should > > be called with the programs signal mask). > > This is what the kernel does when the signal is delivered, the original mask > is restored after the signal handler runs. I'd have thought that the original signal mask (all blocked in the examples) should be restored before the signal handler is called. After all the signal handler is allowed to modify the processes signal mask. I've had horrid thoughts about SIG_SUSPEND :-) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)