Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2722440ybt; Mon, 22 Jun 2020 05:33:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPXFD2DblFfG1SG3vaIUFNklxuBQoBH0NuoSIa7BN6lsfucvkQPRawdrK1oyCU1PtXm9B6 X-Received: by 2002:aa7:c714:: with SMTP id i20mr11740928edq.215.1592829216626; Mon, 22 Jun 2020 05:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592829216; cv=none; d=google.com; s=arc-20160816; b=0cfoHrP5FQfqUBtnarkXfBmg3e87PJe8nbDPOiGI9YUKljyUapGgc8q87brFExravh t+nXDWZFglcgrBe9Qnn/poOLrGYpC7l6swLY0oG+nRdFN/+y//w2Qg0GMSW052wpKqCj EGbxqA8mYfJI5k1nPuDNq9wDrUQtSh97t0X9XeONy/B02TQlqWKB4S7om5mUUcLd7IGy H40Yid9jWn+HbFFGHQRo1x3SNpb3fbb3sIYxcvYJBB2xSgp3kQhfB6wp63IgZi6P7P4o 7O6NwZ1Lp0XQeHhNcVuJPhl8IWxbW4dLxth+QbGuT2S+lx4vrcU/I4LcFWEiymIQMfv1 iX8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=42LWtrJBoO+ztSWHNOTIFwQCSKBhRqeTr03sfAQCvKY=; b=esFLGk/3pOml29EI1dMrFno4f57J7TRfkWCIvnT5Im7EMHmeCJz5bnfYy6mbN9JDmQ O3G4UDRbsxkYf+jxG9d5ddflCns1XOM0oC6ZEJ00FyMTmuTIvyQHTp2NsaAu+kS6HPjp yxvwSbvrNNwWV3Ukp5Teuhk9gPFpQzVKG53FFQkPcpa9acOCubf468P3DmRNxPnR2yf0 lqYJytQHH86UMzaZ4dGbEFxoiCtLkR2og/itKhN1d0EkpKEJYTK7sgHXHmVVP27Cktp5 PSMnOyOX+VXO6tJyFYxlbg8gybhLCpopPbk/oN6hMThfcCHomQZVZ3JM0GAJSb4HVgR9 tJMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si9182233ejb.289.2020.06.22.05.33.14; Mon, 22 Jun 2020 05:33:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728148AbgFVM3b (ORCPT + 99 others); Mon, 22 Jun 2020 08:29:31 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:36667 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728101AbgFVM3a (ORCPT ); Mon, 22 Jun 2020 08:29:30 -0400 Received: from ip5f5af08c.dynamic.kabel-deutschland.de ([95.90.240.140] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jnLZl-000475-Q4; Mon, 22 Jun 2020 12:29:25 +0000 Date: Mon, 22 Jun 2020 14:29:25 +0200 From: Christian Brauner To: Oleg Nesterov Cc: Dominique Martinet , Alexander Kapshuk , linux-kernel@vger.kernel.org, ebiederm@xmission.com, akpm@linux-foundation.org, liuzhiqiang26@huawei.com, joel@joelfernandes.org, paulmck@linux.vnet.ibm.com, kernel test robot Subject: Re: [PATCH] kernel/signal.c: Export symbol __lock_task_sighand Message-ID: <20200622122925.khcilncycuzb4xki@wittgenstein> References: <20200621133704.77896-1-alexander.kapshuk@gmail.com> <20200622062527.GA6516@redhat.com> <20200622083905.c3nurmkbo5yhd6lj@wittgenstein> <20200622102401.GA12377@nautica> <20200622113610.okzntx7jmnk6n7au@wittgenstein> <20200622120259.GD6516@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200622120259.GD6516@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 22, 2020 at 02:03:00PM +0200, Oleg Nesterov wrote: > On 06/22, Christian Brauner wrote: > > > > On Mon, Jun 22, 2020 at 12:24:01PM +0200, Dominique Martinet wrote: > > > Christian Brauner wrote on Mon, Jun 22, 2020: > > > > On Mon, Jun 22, 2020 at 08:25:28AM +0200, Oleg Nesterov wrote: > > > >> current->sighand is stable and can't go away. Unless "current" is exiting and > > > >> has already passed exit_notify(). So I don't think net/9p needs this helper. > > > > > > > > From what I can gather from the thread (cf. [1]) that is linked in the > > > > commit message the main motivation for all of this is sparse not being > > > > happy and not some bug. (Maybe I'm not seeing something though.) > > > > > > > > The patch itself linked here doesn't seem to buy anything. I agree with > > > > Oleg. Afaict, lock_task_sighand() would only be needed here if the task > > > > wouldn't be current. So maybe it should just be dropped from the series. > > > > > > Sure. I honestly have no idea on what guarantees we have from the task > > > being current here as opposed to any other task -- I guess that another > > > thread calling exit for exemple would have to wait? > > > > When a thread in a non-trivial thread-group (sorry for the math > > reference :)) execs it'll unshare its struct sighand. > > Well, not really... > > The execing threads will kill other other threads, then it will check I know but I didn't want to go into that much detail but you're right of course! :) > if ->sighand should be unshared. The latter is very unlikely, I don't > think CLONE_SIGHAND without CLONE_THREAD is actually used today. It is a supported case however unlikely. I just tried to answer Dominique's specific question pointing out that even in that unlikely case sighand_struct is stable. Just as an fyi, CLONE_SIGHAND with CLONE_VM but without CLONE_THREAD is actually used quite a bit, e.g. in newlib, in stress-ng, and in criu. Actually for some use-cases with userfaultfd if you want to handle pagefaults in the child, you'd want CLONE_VM which enforces CLONE_SIGHAND so that would be another use-case afaict. And honestly, quite often this combo is used in helper processes that share as much context as possible without CLONE_THREAD to do as little work as possible in terms of allocations and so on in the kernel. (Another interesting use-case could arise with CLONE_SIGHAND + CLONE_CLEAR_SIGHAND as it allows you to reset both the parent's and child's signal handler in one shot.) > > But this doesn't really matter. I mean, even if you race with another > thread doing exec/exit/whatever, current->sighand is stable. Unless, again, > current has already exited (called exit_notify()). > > > The new struct > > sighand will be assigned using rcu_assign_pointer() so afaik (Paul or > > Oleg can yell at me if I'm talking nonsense) any prior callers will see > > the prior sighand value. > > Yes, but see above. > > If tsk is not current, then (in general) it is not safe to use tsk->sighand > directly. It can can be changed by exec (as you explained), or you can hit > tsk->sighand == NULL if you race with exit. > > Oleg. >