Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2243533ybm; Thu, 23 May 2019 13:42:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYQKuZBQE47csSiBDULiGXd0rOW8DZF83l9lhSiXXLDREUCAHWDIwWCci1xAYyHws/QXI3 X-Received: by 2002:a17:902:581:: with SMTP id f1mr48692788plf.343.1558644175046; Thu, 23 May 2019 13:42:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558644175; cv=none; d=google.com; s=arc-20160816; b=gvMoxiZoh3oI8A+peOABol5vT64wyBpdwl7nFUhD5JLaVLPDGVkvB8SzTpKyL4BvPO +91KYLSr+56wUE7xZOiWrnyrmP6zvggwYcXUwgT82vay2bx8DmOcfZ0KH/RERozAsXom CcRLfJ5YadthGBMyYi4VLp0bpndloS5q2Z30Q+t0ycpp6l5z8xVkKWTsqtNshBbNRgpu sABQaS/PM5QqPz7f7FkxbbsEnX2QHIX4Mnepyfmuxx/Bc+T0tmnuJM5tAe27xsj1eX3L xZ0oamaQL0pv+fBQCIUOSjZjsHVUghvkF8Pg4CMtV7J8k/yE8N2MoFn+R9u7Cjakr9OT T1Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=RIktXmsvo5WeogzuSAj6+oDuP7plh2sTZtJRWQFt6ug=; b=GLTKvlNLXh0WUHjAjtJTc+id06WWNBVOdfslUL1x8ga3V1JPrAsxm13ENoGh/IXLvz xqs6fxbVkLh0dHV+FO408LvwfaGC0sRj7l31RxEc7Sp1jaVf44ZY2SC6MOiBkj/xqHs0 NGIlUPeMPOu2IGkB9CzV55akXRLEz4RcgL1tlr08arGAtlSzh28Zl6eS1IzzfoHxHqd6 PW6tH5ok2J5hMPonhq190ZeruApXG+WQVFBOa/Q089c/rfpNdKTtegoAmmGcyPB7iDXJ lnhN0DCck6tmD0AzKdefPHelqfC0rdQJAdZtF04Dw6TG5ifuXR2P1mAam35zuJnELriH k3Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dPufqnue; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b22si819165plz.417.2019.05.23.13.42.39; Thu, 23 May 2019 13:42:55 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dPufqnue; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387828AbfEWUl3 (ORCPT + 99 others); Thu, 23 May 2019 16:41:29 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:43547 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387533AbfEWUl3 (ORCPT ); Thu, 23 May 2019 16:41:29 -0400 Received: by mail-io1-f68.google.com with SMTP id v7so5983263iob.10; Thu, 23 May 2019 13:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RIktXmsvo5WeogzuSAj6+oDuP7plh2sTZtJRWQFt6ug=; b=dPufqnuehyMrtZdGMJMje631CgWkoo4SYi03r1LoKlrNFi7pECzlXfviVjwgdwt6qr +0Va5D/ErNExW6RowUCW0ND57vVQn6ITR4sf6P890Tqhz7Y786dRhVOx5Pg0eAnS7A03 +OUZCte2B3TYRxxwY4M/nWN4Tu9zlwquT2eEn0u4HGTP0PTzVil0VOTj2k2q7ppbyr73 9+makKUyYdkDFQAlLzkQFN7BNedXjkVQqfESJP8vH+Bpr08s6PnZM7gdJJLGwjZjn4Fy QZztAOBYVwtso5wLUbSnyxSUmfFg3xgCt3k6aNetkQzuoQPAMiuSHqHNnOZKXq2BAdAP 3HLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RIktXmsvo5WeogzuSAj6+oDuP7plh2sTZtJRWQFt6ug=; b=f5kcP7LRxfKr1KSZM4VwuwSKUlERgvOWiSSsrfKXgFcunvYlPm8ZtbC53FJzKLyOl7 PTcG6DeaViSna6kjdOZvxUGWVvn5ZNcUpQBtOCbiDqzMWl6wghHgqIml3tONmz/FSNk+ D8ybVn3nAsnNoY+q7FqG6wc26UKcPBHYSnEDoNE9cYcWS+KNA2AASGEKikaj1TtKtp9/ +d3yqHukk84IJvSr60eWpb/m8HFAcw0GD82P5As2zKnBkx5fSKPVISzQL/B3Zf1ZUAXW 1WnW7VNcZTseAjtNu1AcpATgYoScUmviRSNnV7+og8NSe+OPOF8sAhz5n3i22E5fQ35a q9SQ== X-Gm-Message-State: APjAAAWcyuUJHzAfWVdP/vpW6lCzu+5VMglrd7T+zFdxwZS9rVbGrGAH VNlvmzb/u0OACbCMdibOPJWkcJ5W9ztXkl8PmEW/OW95 X-Received: by 2002:a6b:b843:: with SMTP id i64mr30640iof.81.1558644088494; Thu, 23 May 2019 13:41:28 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: From: Deepa Dinamani Date: Thu, 23 May 2019 13:41:17 -0700 Message-ID: Subject: Re: [PATCH v2] signal: Adjust error codes according to restore_user_sigmask() To: David Laight Cc: Oleg Nesterov , 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" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 23, 2019 at 11:06 AM Deepa Dinamani wrote: > > Ok, since there has been quite a bit of argument here, I will > backtrack a little bit and maybe it will help us understand what's > happening here. > There are many scenarios being discussed on this thread: > a. State of code before 854a6ed56839a > b. State after 854a6ed56839a > c. Proposed fix as per the patchset in question. > > Oleg, I will discuss these first and then we can discuss the > additional changes you suggested. > > Some background on why we have these syscalls that take sigmask as an > argument. This is just for the sake of completeness of the argument. > > These are particularly meant for a scenario(d) such as below: > > 1. block the signals you don't care about. > 2. syscall() > 3. unblock the signals blocked in 1. > > The problem here is that if there is a signal that is not blocked by 1 > and such a signal is delivered between 1 and 2(since they are not > atomic), the syscall in 2 might block forever as it never found out > about the signal. > > As per [a] and let's consider the case of epoll_pwait only first for simplicity. > > As I said before, ep_poll() is what checks for signal_pending() and is > responsible for setting errno to -EINTR when there is a signal. > > So if a signal is received after ep_poll() and ep_poll() returns > success, it is never noticed by the syscall during execution. > So the question is does the userspace have to know about this signal > or not. From scenario [d] above, I would say it should, even if all > the fd's completed successfully. > This does not happen in [a]. So this is what I said was already broken. > > What [b] does is to move the signal check closer to the restoration of > the signal. This way it is good. So, if there is a signal after > ep_poll() returns success, it is noticed and the signal is delivered > when the syscall exits. But, the syscall error status itself is 0. > > So now [c] is adjusting the return values based on whether extra > signals were detected after ep_poll(). This part was needed even for > [a]. > > Let me know if this clarifies things a bit. Just adding a little more clarification, there is an additional change between [a] and [b]. As per [a] we would just restore the signal instead of changing the saved_sigmask and the signal could get delivered right then. [b] changes this to happen at syscall exit: void restore_user_sigmask(const void __user *usigmask, sigset_t *sigsaved) { /* * When signals are pending, do not restore them here. * Restoring sigmask here can lead to delivering signals that the above * syscalls are intended to block because of the sigmask passed in. */ if (signal_pending(current)) { current->saved_sigmask = *sigsaved; set_restore_sigmask(); return; } -Deepa