Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2335057imm; Thu, 9 Aug 2018 11:03:59 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwknGEXeGqvSVv37+p/IcSJBMivwwXI5QFBFZL/cMJlnK3XkJfKWuXiNxUZAYW0O31ZHtrY X-Received: by 2002:a17:902:7d8f:: with SMTP id a15-v6mr3003785plm.332.1533837839065; Thu, 09 Aug 2018 11:03:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533837839; cv=none; d=google.com; s=arc-20160816; b=hvTTvM0BLgDzDQCpM1LAISb5ByAmgcwoJ7RHh/c3Mpx4CePRpcMg5UR2pPkaf41gF/ eRfxV3dTj6JcARXQp2wUm5+gGxgBXZhmt7XK0i7XxIG45Ddg/uH7ktv9HOxfdcHJCmk+ +P/sK4O3NJWiG96cpqEhujmmSbLBaW2b6FS4OQV6rZ51N/nc7ZiMpt2vy0YkpfGVA/Lf 9WXDqin8ZDc++XQWLtC6i+xXNN41TL39861ODW9SPHBwLQiZfvKc4Jz/YWjI64ftzA4R KMIJ1CvQOlsC57aJX+Mz8+1Z7vwEDxsbB8xqqZXARTnQPJLHIDF7GKYdd0LvhGrDUTLi rNEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:mime-version:user-agent :message-id:in-reply-to:date:references:cc:to:from :arc-authentication-results; bh=AuvtPf6QF+SFtMrYddHnPPMIG71ZlN56BQx9hSb0dho=; b=Bg/2gR75cyT1XBg6BZVjODPfbex72LTWH/DFxU/44UNrhATtlkFb1UOMaSU0mclBMm 2yi2yzANPHvyfre983ImBy35GdN+8Mpzw/4HCgJCjKH5/WOzsmXGhfSDuhQoW0KdA5se Am6wNSB/bMYt3hmLL0VmS4t8t4WrKou0ClMfcM32DQ9/tM69Vm7nR/FBoY4H5miyvOip oxEpB2XfPkC1lFhMidB4Gj6aJrQ5hbAh1C4AbyD8IhMRNdBC+zZpLWivJiVxT77d8b8A edqlplazUx0tqsCnN7vaoz4URPWwUXMF8PvRO8EhkHzqhgJfUt+k2w1JeqGjRPliIRPi jPXQ== 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 e66-v6si7882721pfk.198.2018.08.09.11.03.44; Thu, 09 Aug 2018 11:03:59 -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 S1726931AbeHIU2o (ORCPT + 99 others); Thu, 9 Aug 2018 16:28:44 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:52428 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbeHIU2o (ORCPT ); Thu, 9 Aug 2018 16:28:44 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out02.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1fnpGm-0004WO-Nv; Thu, 09 Aug 2018 12:02:44 -0600 Received: from [97.119.167.31] (helo=x220.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1fnpGX-0005zh-4h; Thu, 09 Aug 2018 12:02:44 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Cc: , , , , , , References: <201808091624383651898@zte.com.cn> Date: Thu, 09 Aug 2018 13:02:14 -0500 In-Reply-To: <201808091624383651898@zte.com.cn> (wen's message of "Thu, 9 Aug 2018 16:24:38 +0800 (CST)") Message-ID: <87lg9fv2op.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1fnpGX-0005zh-4h;;;mid=<87lg9fv2op.fsf@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=97.119.167.31;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+eS/74+6UjTrdhO3eu+Ie1fMxqSTOt9kQ= X-SA-Exim-Connect-IP: 97.119.167.31 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa07.xmission.com X-Spam-Level: X-Spam-Status: No, score=-0.9 required=8.0 tests=ALL_TRUSTED,BAYES_40, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01,T_TooManySym_02, T_TooManySym_03,XMSolicitRefs_0 autolearn=disabled version=3.4.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 BAYES_40 BODY: Bayes spam probability is 20 to 40% * [score: 0.3947] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.1 XMSolicitRefs_0 Weightloss drug * 0.0 T_TooManySym_02 5+ unique symbols in subject * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_03 6+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ; X-Spam-Relay-Country: X-Spam-Timing: total 15031 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 2.3 (0.0%), b_tie_ro: 1.62 (0.0%), parse: 0.78 (0.0%), extract_message_metadata: 12 (0.1%), get_uri_detail_list: 1.50 (0.0%), tests_pri_-1000: 2.7 (0.0%), tests_pri_-950: 1.11 (0.0%), tests_pri_-900: 0.95 (0.0%), tests_pri_-400: 24 (0.2%), check_bayes: 23 (0.2%), b_tokenize: 8 (0.1%), b_tok_get_all: 9 (0.1%), b_comp_prob: 1.86 (0.0%), b_tok_touch_all: 2.7 (0.0%), b_finish: 0.54 (0.0%), tests_pri_0: 170 (1.1%), check_dkim_signature: 0.49 (0.0%), check_dkim_adsp: 2.6 (0.0%), tests_pri_500: 14815 (98.6%), poll_dns_idle: 14797 (98.4%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH v5 3/6] signal: Add calculate_sigpending() X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org writes: > EricW.Biederman wrote: >> Add a function calculate_sigpending to test to see if any signals are >> pending for a new task immediately following fork. Signals have to >> happen either before or after fork. Today our practice is to push >> all of the signals to before the fork, but that has the downside that >> frequent or periodic signals can make fork take much much longer than >> normal or prevent fork from completing entirely. >> > >> + calculate_sigpending(); >> } >> /* >> diff --git a/kernel/signal.c b/kernel/signal.c >> index dddbea558455..1e06f1eba363 100644 >> --- a/kernel/signal.c >> +++ b/kernel/signal.c >> @@ -172,6 +172,17 @@ void recalc_sigpending(void) >> } >> +void calculate_sigpending(void) >> +{ >> + /* Have any signals or users of TIF_SIGPENDING been delayed >> + * until after fork? >> + */ >> + spin_lock_irq(¤t->sighand->siglock); >> + set_tsk_thread_flag(current, TIF_SIGPENDING); >> + recalc_sigpending(); >> + spin_unlock_irq(¤t->sighand->siglock); >> +} >> + > > The new function calculate_sigpending is similar to recalc_sigpending, > but recalc_sigpending has no spin_lock_irq(¤t->sighand->siglock) in it. > This gives recalc_sigpending more flexibility, > we may use spin_lock_irq or spin_lock_irqsave before recalc_sigpending . > eg: > > static int autofs4_write(struct autofs_sb_info *sbi, > struct file *file, const void *addr, int bytes) > { > ... > spin_lock_irqsave(¤t->sighand->siglock, flags); > sigdelset(¤t->pending.signal, SIGPIPE); > recalc_sigpending(); > spin_unlock_irqrestore(¤t->sighand->siglock, flags); > ... > } > > or: > void kernel_sigaction(int sig, __sighandler_t action) > { > spin_lock_irq(¤t->sighand->siglock); > ... > recalc_sigpending(); > ... > spin_unlock_irq(¤t->sighand->siglock); > } > > > But calculate_sigpending is currently hardwired to call spin_lock_irq. calculate_sigpending really only exists to keep the code comprehensible. It is only ever expected to be called in exactly one place so the lack of flexibility should not be a problem. Further the use of irqsave is discouraged unless it is necessary. The irqsave in autofs_write actually looks like a misfeature. We take a mutex a few lines earlier, so we know that irqs are enabled. Saving and restoring them is uncessary work. Further unless I am missing something that code path should be calling kernel_dequeue_signal, to ensure that any siginfo associated with that SIGPIPE gets dequeued. Eric