Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp675712ybi; Fri, 24 May 2019 09:36:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwm2brOn5wxSmznwDgFJOpLxC/irrY3HdVFecpna3QZj808uw+gKvdYizyHhB3bbtdoT8AA X-Received: by 2002:a17:902:7891:: with SMTP id q17mr26103695pll.236.1558715796791; Fri, 24 May 2019 09:36:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558715796; cv=none; d=google.com; s=arc-20160816; b=vbesKKelD8mwOKrVfjuneDGUUfNC91/kP9gFIpV6mxZnUhoy6v51TZszeijJlyg8Zk gaKgXseIkWa1H0YFJ/Wl+sqvMVIpXS4Us+K7S9uVywxl3yaSNfeksiV/1pf00j8N9GgG dcbJCqsKiUfmP0NApdHa4xoMjQ/RuCMLAoPETG0/0T4kFbq6SU3YmMENnJxk5SnUFvX4 YMyTTBf3tkUnxNJnF6IJvC0R+jGqQCh+CryF6XxGvpmTrb4jKlydowKO6pRYg2IOxvMh yplrjmbBnbqPRPiguQo1oNO1tZK16tEycahdPDc3+tFWXqWO/eLwneukBL1zLrypHPPV klbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=B/WIJ/PCiAYQ7uuqze/9sDC4IDKCN3DVDqAxv+0NFIc=; b=gCIVOKMYehi+06JktFAnXtIkeO860bbUz6b+v+kSvq5+FpDjRW660SMI2UjJrXMv3B 1FAkS748cMLf1BN+3HzbcTlhlgy8M+PBd+JuU8GnB2HqjE8PlDWoX9S2GmxyF81rbqcf jWl0kU3MzsBre4N2uD9P7o0wEr+ocxGgnSSLk9mwq0Sd15OjphR+dKS79bPnWtib4ymT VnDWJwbfIePKN+/ym1dbWP165qGFvqkJZlBG7bw1I4szMbVGtNMfvdbdVvHK16nZuOQe iLt2uT32+6ZWeB+bUika0h60uJhBQBaVG9HQiO6gRubQ9qe6puZAm6DZXRuP9UtMmQEp i6Kw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q65si4778627pjq.96.2019.05.24.09.36.19; Fri, 24 May 2019 09:36:36 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390955AbfEXQdd (ORCPT + 99 others); Fri, 24 May 2019 12:33:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52266 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390021AbfEXQdc (ORCPT ); Fri, 24 May 2019 12:33:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B100D309704F; Fri, 24 May 2019 16:33:16 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.159]) by smtp.corp.redhat.com (Postfix) with SMTP id A78C8608CD; Fri, 24 May 2019 16:33:11 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 24 May 2019 18:33:16 +0200 (CEST) Date: Fri, 24 May 2019 18:33:10 +0200 From: Oleg Nesterov To: Deepa Dinamani Cc: David Laight , 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() Message-ID: <20190524163310.GG2655@redhat.com> References: <20190522161407.GB4915@redhat.com> <4f7b6dbeab1d424baaebd7a5df116349@AcuMS.aculab.com> <20190523145944.GB23070@redhat.com> <345cfba5edde470f9a68d913f44fa342@AcuMS.aculab.com> <20190523163604.GE23070@redhat.com> <20190524141054.GB2655@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 24 May 2019 16:33:32 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/24, Deepa Dinamani wrote: > > On Fri, May 24, 2019 at 7:11 AM Oleg Nesterov wrote: > > > > On 05/23, 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 > > > > I think everything was correct, > > There were 2 things that were wrong: > > 1. If an unblocked signal was received, after the ep_poll(), then the > return status did not indicate that. Yes, > This is expected behavior > according to man page. If this is indeed what is expected then the man > page should note that signal will be delivered in this case and return > code will still be 0. > > "EINTR > The call was interrupted by a signal handler before either any of the > requested events occurred or the timeout expired; see signal(7)." and what do you think the man page could say? This is obviously possible for any syscall, and we can't avoid this. A signal can come right after syscall insn completes. The signal handler will be called but this won't change $rax, user-space can see return code == 0 or anything else. And this doesn't differ from the case when the signal comes before syscall returns. > 2. The restoring of the sigmask is done right in the syscall part and > not while exiting the syscall and if you get a blocked signal here, > you will deliver this to userspace. So I assume that this time you are talking about epoll_pwait() and not epoll_wait()... And I simply can't understand you. But yes, if the original mask doesn't include the pending signal it will be delivered while the syscall can return success/timout or -EFAULT or anything. This is correct, see above. > > > b. State after 854a6ed56839a > > > > obviously buggy, > > Ok, then can you point out what specifically was wrong with > 854a6ed56839a? Cough. If nothing else the lost -EINTR? > And, not how it could be more simple? Well, I already sent the patch and after that I even showed you the code with the patch applied. See https://lore.kernel.org/lkml/20190523143340.GA23070@redhat.com/ > > What you are saying looks very confusing to me, I will assume that you > > meant something like > > > > - a signal SIG_XXX was blocked before sys_epoll_pwait() was called > > > > - sys_epoll_pwait(sigmask) unblocks SIG_XXX according to sigmask > > > > - sys_epoll_pwait() calls do_epoll_wait() which returns success > > > > - SIG_XXX comes after that and it is "never noticed" > > > > Yes. Everything is correct. And see my reply to David, SIG_XXX can even > > come _before_ sys_epoll_pwait() was called. > > No, I'm talking about a signal that was not blocked. OK, see above. > > > So the question is does the userspace have to know about this signal > > > or not. > > > > If userspace needs to know about SIG_XXX it should not block it, that is all. > > What should be the return value if a signal is detected after a fd completed? Did you mean "if a signal is detected after a ready fd was already found" ? In this case the return value should report success. But I have already lost, this all looks irrelevant wrt to fix we need. > > > What [b] does is to move the signal check closer to the restoration of > > > the signal. > > > > FOR NO REASON, afaics (to simplify, lets forget the problem with the wrong > > return value you are trying to fix). > > As I already pointed out, the restoring of the sigmask is done during > the syscall and not while exiting the syscall and if you get a blocked > signal here, you will deliver this to userspace. > > > And even if there were ANY reason to do this, note that (with or without this > > fix) the signal_pending() check inside restore_user_sigmask() can NOT help, > > simply because SIG_XXX can come right after this check. > > This I pointed out already that we should probably make this sequence atomic. See above. Oleg.