Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp853307pxb; Fri, 22 Apr 2022 12:39:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7lfJRud5nFJM8RoumlQw/8+SzVxvgkyKJoxRitbawIBhHLnmLcqruyN7oq592+/Ls4KIP X-Received: by 2002:a17:90b:1b52:b0:1d2:8d55:ad6d with SMTP id nv18-20020a17090b1b5200b001d28d55ad6dmr7166852pjb.223.1650656350179; Fri, 22 Apr 2022 12:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650656350; cv=none; d=google.com; s=arc-20160816; b=tVDSOPrYbYXlMk7KpEDW3aghC/1t0p+q2ijlx3SJxuaH2LnURWTiI/oe3DQowbU8Xx OG6aNZZzlCdQhQTkzQGz77C5SQvS4F6PoEzfN+K4cLWpM/j8WNCodW95s1Dg8zJBzpHw yf/fKR/uroteX/VLkrpUnV8CqwbgdzJm/wNowX7GwOyGlEi7JUad7a5rOQbhAdGkdG7U uG6C6eN+q3TXiSllyYk8GutDrEYHFrF70peZRr4cYII9b1aHT4wobdkv4TV3NTVl/kAD pJDLaXRcX/WhaJpCg9Z2HFu1zHKkPOXdQaNOIYKukoyFYbS/ikY8Ryd70mQsRrBcPzJ0 1Hsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=HDKHu1E76IDSGv1OM3uK8i7f9RkzuL23ZGT+an3JVfA=; b=sZ0aF956zoZWy33ocjgL9Fe7CuQCjxGInnQi32XMIcrZFeI9Ed/OUO0mKu7bdnCYj2 eN+N+bso4BW13bNkdE0c2A5OkhGfQga4vHCqzp1+V/3rHnF8WPU+MKgYNjIxtBMPa7Xe yk2cjTAcLS6Qy9isGrkbUiJz8oN1cNIZTuU3sIhPIK+CBvqpE/2OQWUGcoRMllIPAr4h 27Sy8d4tqQT4c/eb1eHnPcB93K+du+nKw/0ViAoT5dZqUtdeDN2ma8Qv7ryrgljhzgS+ FaEjvspvyddMzxCNuu7BtLY5DU5apzrZ8+EWHBqy6upaxU7tYHQnBDacTYIWdTrRXR0T scoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=k8RHSSpP; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id kk8-20020a17090b4a0800b001d0adade18bsi13689466pjb.0.2022.04.22.12.39.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:39:10 -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; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=k8RHSSpP; 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 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 167AD1F46F5; Fri, 22 Apr 2022 11:44:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392146AbiDUUCC (ORCPT + 99 others); Thu, 21 Apr 2022 16:02:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351747AbiDUUCB (ORCPT ); Thu, 21 Apr 2022 16:02:01 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 377954D9F9; Thu, 21 Apr 2022 12:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=HDKHu1E76IDSGv1OM3uK8i7f9RkzuL23ZGT+an3JVfA=; b=k8RHSSpPio9cut8zxiDXw+oWYN nqQx7cidp5PFTX1VQvaplpGZSmPE6vshU3YO6wnnys/QSmKvZiIhsD/4Iq0av8WWK4q6JqzdjA3Oe ZcpzVv+Rmg3vPhknwZ8OVIdG+JheDQW3t0vDg3C8sPD7MOnXe5jJDsIFGcnCVTnUvS1hNexAHjUky SPz2+fvggaBRvrp8rJ1+vDsz67swOoxCVm5aKbo9v8VAt+t7lZ6mrTjvRQMzpy7PxJm8Ym0SlXieh ZSnl9dXJXbjd83hFbFgOP74BZIDmevx8yBGKonUxuUPBUf7gKTf9e0j6yshGds151meSr92yB+c9h hQYBWhmg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhcx3-007VdD-1b; Thu, 21 Apr 2022 19:58:53 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 8CAC49861C1; Thu, 21 Apr 2022 21:58:52 +0200 (CEST) Date: Thu, 21 Apr 2022 21:58:52 +0200 From: Peter Zijlstra To: Oleg Nesterov Cc: rjw@rjwysocki.net, mingo@kernel.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, mgorman@suse.de, ebiederm@xmission.com, bigeasy@linutronix.de, Will Deacon , linux-kernel@vger.kernel.org, tj@kernel.org, linux-pm@vger.kernel.org Subject: Re: [PATCH v2 2/5] sched,ptrace: Fix ptrace_check_attach() vs PREEMPT_RT Message-ID: <20220421195852.GP2731@worktop.programming.kicks-ass.net> References: <20220421150248.667412396@infradead.org> <20220421150654.817117821@infradead.org> <20220421182325.GC20402@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220421182325.GC20402@redhat.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 21, 2022 at 08:23:26PM +0200, Oleg Nesterov wrote: > On 04/21, Peter Zijlstra wrote: > > > > Rework ptrace_check_attach() / ptrace_unfreeze_traced() to not rely on > > task->__state as much. > > Looks good after the quick glance... but to me honest I got lost and > I need to apply these patches and read the code carefully. > > However, I am not able to do this until Monday, sorry. Sure, no worries. Take your time. > Just one nit for now, > > > static void ptrace_unfreeze_traced(struct task_struct *task) > > { > > - if (READ_ONCE(task->__state) != __TASK_TRACED) > > + if (!task_is_traced(task)) > > return; > > > > WARN_ON(!task->ptrace || task->parent != current); > > > > - /* > > - * PTRACE_LISTEN can allow ptrace_trap_notify to wake us up remotely. > > - * Recheck state under the lock to close this race. > > - */ > > spin_lock_irq(&task->sighand->siglock); > > - if (READ_ONCE(task->__state) == __TASK_TRACED) { > > + if (task_is_traced(task)) { > > I think ptrace_unfreeze_traced() should not use task_is_traced() at all. > I think a single lockless > > if (task->jobctl & JOBCTL_DELAY_WAKEKILL) > return; > > at the start should be enough? I think so. That is indeed cleaner. I'll make the change if I don't see anything wrong with it in the morning when the brain has woken up again ;-) > > Nobody else can set this flag. It can be cleared by the tracee if it was > woken up, so perhaps we can check it again but afaics this is not strictly > needed. > > > +// WARN_ON_ONCE(!(task->jobctl & JOBCTL_DELAY_WAKEKILL)); > > Did you really want to add the commented WARN_ON_ONCE? I did that because: @@ -1472,8 +1479,7 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_lo request == PTRACE_INTERRUPT); if (!ret) { ret = compat_arch_ptrace(child, request, addr, data); - if (ret || request != PTRACE_DETACH) - ptrace_unfreeze_traced(child); + ptrace_unfreeze_traced(child); } Can now call unfreeze too often. I left the comment in because I need to think more about why Eric did that and see if it really is needed.