Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp201255iob; Mon, 2 May 2022 17:04:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyM8L1axmeHqsUEBF+MTXzTHa4H2c5Mym/BzCWAbF6wXEClAfqFfhH+PFtrMFpBzKdgoPAv X-Received: by 2002:a63:5b13:0:b0:3c2:163c:b9cb with SMTP id p19-20020a635b13000000b003c2163cb9cbmr6118698pgb.145.1651536241899; Mon, 02 May 2022 17:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651536241; cv=none; d=google.com; s=arc-20160816; b=FNcbzbrjD3GIcldf5LNQ9R8VawMC7N5gJ4VOL0PY5sR7HY/fAhck7t8dL11dEggOcN vYwdBUqTAchMM0P0o/XvnihyLhH7x1I89fXIEm5H0waN3PkhptaTcEIdlDLLCBAWHwB4 z/R/wJNOK0bn6ePaBlrqnJWdjPHZWKFHtcSvqNAyOrplbUJhoTVWmevfe3J7DptO760Z Col+fJMdUR1cmm4GKRxpoeoQg5LhNJBYEebmcMrWceNQEZN7I5hxmW0jyrhe4iS6r5to mw8Bw2Vzt4lnt1Z0OLbAM1i67nXLCY1P7jWZVPDaJulS0L3Gq5T5f8RnkzX/DtxCamM8 JmGg== 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=T7Fft58FedMgqyP3YlVwHPkygstzltaLGlpthm8riRo=; b=zbmnhXmAx09gTLkcf3sWpw/5xPtnfXytlRUkD8WiR07ryQSKgHyW67QUc99U8SQWOb KxJaxxv+6MVU9Oumm3au5NsoaQkQMSO6+foL2/QNVy5b4A0UNadJLftVT/RV4LpmNwCk oq5YEK1em6/NpIK0Xq6UhSdin1Cu0+KsLgYpOmIrud8+PBvSyl0i5xRL/3h2BfAbrgZi k0iIN1EoS+aSfxf2f91DZTgta0HUKUyVBQQhFw2vyAS1M+1RZL5k7VWSy1MH1xH1r7RJ /emJ2x5++cKiFlz3oPdyxxdq2Aue7WecWxQQJ0YIppJXDsdIl/Snb82UjrJpJmR6DN3Y HZ1g== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id nd15-20020a17090b4ccf00b001c68e9e0e68si734922pjb.36.2022.05.02.17.04.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 17:04:01 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EEEE533E98; Mon, 2 May 2022 17:03:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243057AbiEBQjd (ORCPT + 99 others); Mon, 2 May 2022 12:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241337AbiEBQjb (ORCPT ); Mon, 2 May 2022 12:39:31 -0400 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9A3055BE; Mon, 2 May 2022 09:36:01 -0700 (PDT) Received: from in02.mta.xmission.com ([166.70.13.52]:60884) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nlZ1i-00DCkL-Hp; Mon, 02 May 2022 10:35:58 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:36694 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nlZ1h-0037gA-G0; Mon, 02 May 2022 10:35:58 -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 , linux-xtensa@linux-xtensa.org, Kees Cook , Jann Horn , linux-ia64@vger.kernel.org References: <87k0b7v9yk.fsf_-_@email.froward.int.ebiederm.org> <20220429214837.386518-7-ebiederm@xmission.com> <20220502153934.GD17276@redhat.com> Date: Mon, 02 May 2022 11:35:50 -0500 In-Reply-To: <20220502153934.GD17276@redhat.com> (Oleg Nesterov's message of "Mon, 2 May 2022 17:39:35 +0200") Message-ID: <87levjrixl.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=1nlZ1h-0037gA-G0;;;mid=<87levjrixl.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX1/z6Qf/UXEKB8pTQyW3Pw5hOTrbz9KRVus= 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=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Virus: No X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ***;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 483 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 3.8 (0.8%), b_tie_ro: 2.7 (0.6%), parse: 0.81 (0.2%), extract_message_metadata: 3.3 (0.7%), get_uri_detail_list: 1.78 (0.4%), tests_pri_-1000: 3.2 (0.7%), tests_pri_-950: 0.97 (0.2%), tests_pri_-900: 0.86 (0.2%), tests_pri_-90: 67 (13.8%), check_bayes: 65 (13.5%), b_tokenize: 8 (1.6%), b_tok_get_all: 10 (2.1%), b_comp_prob: 2.7 (0.6%), b_tok_touch_all: 42 (8.6%), b_finish: 0.71 (0.1%), tests_pri_0: 390 (80.7%), check_dkim_signature: 0.61 (0.1%), check_dkim_adsp: 4.2 (0.9%), poll_dns_idle: 2.8 (0.6%), tests_pri_10: 1.81 (0.4%), tests_pri_500: 6 (1.3%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH v2 07/12] ptrace: Don't change __state X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Oleg Nesterov writes: > On 04/29, Eric W. Biederman wrote: >> >> Stop playing with tsk->__state to remove TASK_WAKEKILL while a ptrace >> command is executing. > > Eric, I'll read this patch and the rest of this series tomorrow. > Somehow I failed to force myself to read yet another version after > weekend ;) That is quite alright. > plus I don't really understand this one... > >> #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) >> #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) >> -#define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED) >> +#define TASK_TRACED __TASK_TRACED > ... >> static inline void signal_wake_up(struct task_struct *t, bool resume) >> { >> - signal_wake_up_state(t, resume ? TASK_WAKEKILL : 0); >> + unsigned int state = 0; >> + if (resume) { >> + state = TASK_WAKEKILL; >> + if (!(t->jobctl & JOBCTL_PTRACE_FROZEN)) >> + state |= __TASK_TRACED; >> + } >> + signal_wake_up_state(t, state); > > Can't understand why is this better than the previous version which removed > TASK_WAKEKILL if resume... Looks a bit strange to me. But again, I didn't > look at the next patches yet. The goal is to replace the existing mechanism with an equivalent one, so that we don't have to be clever and deal with it being slightly different in one case. The difference is how does signal_pending_state affect how schedule will sleep in ptrace_stop. As the patch is constructed currently (and how the existing code works) is that signal_pending_state will always sleep if ptrace_freeze_traced completes successfully. When TASK_WAKEKILL was included in TASK_TRACED schedule might refuse to sleep even though ptrace_freeze_traced completed successfully. As you pointed out wait_task_inactive would then fail, keeping ptrace_check_attach from succeeded. Other than complicating the analysis by adding extra states we need to consider when reviewing the patch, the practical difference is for Peter's plans to fix PREEMPT_RT or the freezer wait_task_inactive needs to cope with the final being changed by something else. (TASK_FROZEN in the freezer case). I can only see that happening by removing the dependency on the final state in wait_task_inactive. Which we can't do if we depend on wait_task_inactive failing if the process is in the wrong state. >> @@ -2209,11 +2209,8 @@ static int ptrace_stop(int exit_code, int why, int clear_code, >> spin_lock_irq(¤t->sighand->siglock); >> } >> >> - /* >> - * schedule() will not sleep if there is a pending signal that >> - * can awaken the task. >> - */ >> - set_special_state(TASK_TRACED); >> + if (!__fatal_signal_pending(current)) >> + set_special_state(TASK_TRACED); > > This is where I stuck. This probably makes sense, but what does it buy > for this particular patch? > > And if we check __fatal_signal_pending(), why can't ptrace_stop() simply > return ? Again this is about preserving existing behavior as much as possible to simplify analsysis of the patch. The current code depends upon schedule not sleeping if there was a fatal signal received before ptrace_stop is called. With TASK_WAKEKILL removed from TASK_TRACED that no longer happens. Just not setting TASK_TRACED when !__fatal_signal_pending has the same effect. At a practical level I think it also has an impact on patch: "10/12 ptrace: Only return signr from ptrace_stop if it was provided". At a minimum the code would need to do something like: if (__fatal_signal_pending(current)) { return clear_code ? 0 : exit_code; } With a little bit of care put in to ensure everytime the logic changes that early return changes too. I think that just complicates things unnecessarily. Eric