Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4980662ioa; Wed, 27 Apr 2022 16:00:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBADLQQhKBxebYb+j3awrcRu83jz9B/7m5rzUy8LgJ2b6Wx6jfnmJgu+Wj52jH6uAWVkOX X-Received: by 2002:a17:906:2310:b0:6f3:dad4:e285 with SMTP id l16-20020a170906231000b006f3dad4e285mr907206eja.9.1651100422750; Wed, 27 Apr 2022 16:00:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651100422; cv=none; d=google.com; s=arc-20160816; b=KO0sykhw+Q7Zb9PxvvUXPXTdWOvWCRJnScqW67ZxHNkHvBluKdKVg4yjb+np2XWXwz UUOXodHlSX0oz8QJzmDIad3QKjVMp+9d1Cz9Zvk7ZLbAPFGTGwJvyFLmJUXxoVYOGTE7 E5NP3nepSuTIRks7+LMT+wOaWpB6NgQ9hfjp/DCdSCeutgs15+4DzM0hJByqCNjgFGfE Dz5CNkva9oBLjqOaiYs6zQyf/6ueZQhcgbMW0qSot27Stg1t/WUgcaG92/cKL1C8MQB3 Ndr/dr79EUIiISATLoIWKyWNSdHqJKXvP0brljLrLZ5nyzSctnoYYW/Q+fZxqrepnp21 MjlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=ys0a4gDBM+t84srUU37QZcDxFdnTRurU0skH95Xa6BE=; b=RE4OiHGAtVUJrdouZuA0RGxqyMbOg2vVs9TqOYv8Ls/lVKMNxON5WkGqP2eioLHYCY K/JscuwWgzFjytbpFVAVUnG1LeFiJSzkGIruHj8iKM8g/5EsdVFTiQpAnxXAASIRHwwh TAUmRkxV3hX7mt2E2Deug1mjo3Mv+2A+lP6uhfnTqjJWu7T/ItEa4HBz85vTiXee26oO rx1E/wJFFWHgyMv5SCwaAyZDsmqFdZkFN41nh6LmYRKoqKl8MHjfysqIqPsgNL838Wat isaPRuSdFxIRreEncBR7gHCo3UJhPB9ExPjQ+jND9sMrn6pU2+7j6jeV9jmE/fOmyX6R 70Gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j25-20020aa7de99000000b00425c2dd8b9asi2396125edv.296.2022.04.27.15.59.59; Wed, 27 Apr 2022 16:00:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234563AbiD0V4b (ORCPT + 99 others); Wed, 27 Apr 2022 17:56:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbiD0V41 (ORCPT ); Wed, 27 Apr 2022 17:56:27 -0400 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F28F34F445; Wed, 27 Apr 2022 14:53:14 -0700 (PDT) Received: from in01.mta.xmission.com ([166.70.13.51]:52896) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1njpax-0044AO-B2; Wed, 27 Apr 2022 15:53:11 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:35982 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1njpav-00BOen-6l; Wed, 27 Apr 2022 15:53:10 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: linux-kernel@vger.kernel.org, rjw@rjwysocki.net, mingo@kernel.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, mgorman@suse.de, bigeasy@linutronix.de, Will Deacon , tj@kernel.org, linux-pm@vger.kernel.org, Peter Zijlstra , Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org, Chris Zankel , Max Filippov , inux-xtensa@linux-xtensa.org, Kees Cook , Jann Horn References: <878rrrh32q.fsf_-_@email.froward.int.ebiederm.org> <20220426225211.308418-6-ebiederm@xmission.com> <20220427145646.GC17421@redhat.com> <20220427150053.GD17421@redhat.com> Date: Wed, 27 Apr 2022 16:52:43 -0500 In-Reply-To: <20220427150053.GD17421@redhat.com> (Oleg Nesterov's message of "Wed, 27 Apr 2022 17:00:54 +0200") Message-ID: <871qxi5h3o.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1njpav-00BOen-6l;;;mid=<871qxi5h3o.fsf@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX1/dRW6uGwzPPdDcp4HFC3w+8KCOzLk/q1o= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Virus: No X-Spam-DCC: XMission; sa03 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ******;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 1492 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 4.4 (0.3%), b_tie_ro: 3.1 (0.2%), parse: 1.23 (0.1%), extract_message_metadata: 5 (0.3%), get_uri_detail_list: 2.9 (0.2%), tests_pri_-1000: 3.4 (0.2%), tests_pri_-950: 1.14 (0.1%), tests_pri_-900: 0.92 (0.1%), tests_pri_-90: 83 (5.6%), check_bayes: 82 (5.5%), b_tokenize: 7 (0.5%), b_tok_get_all: 8 (0.5%), b_comp_prob: 2.2 (0.1%), b_tok_touch_all: 61 (4.1%), b_finish: 0.78 (0.1%), tests_pri_0: 1375 (92.2%), check_dkim_signature: 0.43 (0.0%), check_dkim_adsp: 2.9 (0.2%), poll_dns_idle: 1.49 (0.1%), tests_pri_10: 2.8 (0.2%), tests_pri_500: 8 (0.5%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 6/9] signal: Always call do_notify_parent_cldstop with siglock held X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Oleg Nesterov writes: > On 04/27, Oleg Nesterov wrote: >> >> On 04/26, Eric W. Biederman wrote: >> > >> > @@ -2209,6 +2213,34 @@ static int ptrace_stop(int exit_code, int why, int clear_code, >> > spin_lock_irq(¤t->sighand->siglock); >> > } >> > >> > + /* Don't stop if current is not ptraced */ >> > + if (unlikely(!current->ptrace)) >> > + return (clear_code) ? 0 : exit_code; >> > + >> > + /* >> > + * If @why is CLD_STOPPED, we're trapping to participate in a group >> > + * stop. Do the bookkeeping. Note that if SIGCONT was delievered >> > + * across siglock relocks since INTERRUPT was scheduled, PENDING >> > + * could be clear now. We act as if SIGCONT is received after >> > + * TASK_TRACED is entered - ignore it. >> > + */ >> > + if (why == CLD_STOPPED && (current->jobctl & JOBCTL_STOP_PENDING)) >> > + gstop_done = task_participate_group_stop(current); >> > + >> > + /* >> > + * Notify parents of the stop. >> > + * >> > + * While ptraced, there are two parents - the ptracer and >> > + * the real_parent of the group_leader. The ptracer should >> > + * know about every stop while the real parent is only >> > + * interested in the completion of group stop. The states >> > + * for the two don't interact with each other. Notify >> > + * separately unless they're gonna be duplicates. >> > + */ >> > + do_notify_parent_cldstop(current, true, why); >> > + if (gstop_done && ptrace_reparented(current)) >> > + do_notify_parent_cldstop(current, false, why); >> >> This doesn't look right too. The parent should be notified only after >> we set __state = TASK_TRACED and ->exit code. >> >> Suppose that debugger sleeps in do_wait(). do_notify_parent_cldstop() >> wakes it up, debugger calls wait_task_stopped() and then it will sleep >> again, task_stopped_code() returns 0. >> >> This can be probably fixed if you remove the lockless (fast path) >> task_stopped_code() check in wait_task_stopped(), but this is not >> nice performance-wise... Another detail I have overlooked. Thank you. Or we can change task_stopped_code look something like: static int *task_stopped_code(struct task_struct *p, bool ptrace) { if (ptrace) { - if (task_is_traced(p) && !(p->jobctl & JOBCTL_LISTENING)) + if (p->ptrace && !(p->jobctl & JOBCTL_LISTENING)) return &p->exit_code; } else { if (p->signal->flags & SIGNAL_STOP_STOPPED) return &p->signal->group_exit_code; } return NULL; } I probably need to do a little bit more to ensure that it isn't an actual process exit_code in p->exit_code. But the we don't have to limit ourselves to being precisely in the task_is_traced stopped place for the fast path. > On the other hand, I don't understand why did you move the callsite > of do_notify_parent_cldstop() up... just don't do this? My goal and I still think it makes sense (if not my implementation) is to move set_special_state as close as possible to schedule(). That way we can avoid sleeping spin_locks clobbering it and making our life difficult. My hope is we can just clean up ptrace_stop instead of making it more complicated and harder to follow. Not that I am fundamentally opposed to the quiesce bit but the code is already very hard to follow because of all it's nuance and complexity, and I would really like to reduce that complexity if we can possibly figure out how. Eric