Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp906623pxp; Wed, 16 Mar 2022 20:52:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCzrYLwITP6CbdV7GJIrnkG1f/pbikgYuxry4DngqzsO8JuXW4bq3pmiOjjFlrGOgpIbEV X-Received: by 2002:a63:5366:0:b0:376:6e72:e9ff with SMTP id t38-20020a635366000000b003766e72e9ffmr2138255pgl.1.1647489129700; Wed, 16 Mar 2022 20:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647489129; cv=none; d=google.com; s=arc-20160816; b=wK8+wrGvYNzsPB9vslyN929e1dUEdsQeuy3+Fqxiy6xEj3fF4umgQLnTInswitt+Ez ako8mmpNEcI2gb/CZKZrprcJ+EafciF6ahIYK9mkpWPSp2y+LDuQMFcKHr8sHorGV86p sKArI1gGqxyI375eFZgDIikW5sjMi/thbI6dg4WeG6uD9wCbn/8n1+cm/UU9KMR1NISK BcX5cPjuyshPAqLyO7W36ieKl5Wj/KV8c9QvBOPf2Km+nY74v41CPNhWkhbSoOMS2m+M oYcjCKSdOdKkTbngAmbZi/CKYOTQ7699w20ei/inSUcf46RCrlxk3mrb7MZyU011citp 9XAw== 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:dkim-signature :dkim-signature:date; bh=KufJwsnfI5CF+IvC8AFaW/fYYl7ZQPnkJ0/TGFXMWf4=; b=igAd1nf3oQhmVNCQ35QmUtFEiYb5WHzjLOVpfCEdUtyaI62KOxPqKA3mwIBkOwYerF mVi1NdMYunR6gJVVI988d6K+NiU0i7njxIdBj0D4KW3yB5kHRaFbvRemk3O0JoTgejL4 5K1SKiWRLKJYh8Lqy7ewpd46esKu7Peq5WFKekzUgdSUG9jHVq1bfztiPPbvDRGuBkuS nQRlLYQS2GwXSbTS+Kyye5TehuZjiShbE4nDySRhhE5fcurX08pkZc8xiPWOZDQOYIRa R/6/+ELEsKS/+LzuLu+f1fnDFyd8d4vH+BV0pepfAccmY3mrVKgZ9jYvlhswCYM7S5ou HlOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=u3498QkU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rr70Ykgu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n3-20020a170903110300b001534a270decsi4035833plh.436.2022.03.16.20.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 20:52:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=u3498QkU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rr70Ykgu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D0C587D00A; Wed, 16 Mar 2022 20:40:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354495AbiCPIYl (ORCPT + 99 others); Wed, 16 Mar 2022 04:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234799AbiCPIYk (ORCPT ); Wed, 16 Mar 2022 04:24:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16097DF43 for ; Wed, 16 Mar 2022 01:23:24 -0700 (PDT) Date: Wed, 16 Mar 2022 09:23:19 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1647419001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KufJwsnfI5CF+IvC8AFaW/fYYl7ZQPnkJ0/TGFXMWf4=; b=u3498QkUVfjcu0P9/or7uHAM2kFHX8yrHC3/Ad7Hr8PtWbpM1SeXJ9qcYuDk8TGlxds1l9 J0njii7Fuqd3+3worrsQXicjU/B8GCTEv3Rl8MY783bkTAXdA0b4FRf3gaoCp16F/6rWPt qfAO+zksAHwHZPCFHEJkxg8/d35qRF5uC5nLS0JsCyAjtIGh8326wqP/cY2vlkTTXI/TbK kdlX8+NCPfpd4WNWcSVRtVfvhreS6Me5ApE28NHTKDSX8Byhl0CWk+2609xHKvSOMX2zaK YyxTzXuFlh/yvxswsTeFINOAl+cSDRVFRNnChMAltf6aY/IV0GRjP4V0zJp0UA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1647419001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KufJwsnfI5CF+IvC8AFaW/fYYl7ZQPnkJ0/TGFXMWf4=; b=rr70YkguRBrIGAO97ABRjUp0zDrOik+5WMNNmvkQECrFBjtcckXVVO6KvEFR2eLRbqY8Om qO9kX3x6nFof4nBQ== From: Sebastian Andrzej Siewior To: Oleg Nesterov Cc: linux-kernel@vger.kernel.org, Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Ingo Molnar , Juri Lelli , Mel Gorman , Peter Zijlstra , Steven Rostedt , Thomas Gleixner , Vincent Guittot Subject: Re: [PATCH] ptrace: fix ptrace vs tasklist_lock race on PREEMPT_RT. Message-ID: References: <20220314185429.GA30364@redhat.com> <20220315142944.GA22670@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220315142944.GA22670@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,T_SCC_BODY_TEXT_LINE 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 2022-03-15 15:29:46 [+0100], Oleg Nesterov wrote: > > > > --- a/kernel/sched/core.c > > > > +++ b/kernel/sched/core.c > > > > @@ -3239,7 +3239,8 @@ unsigned long wait_task_inactive(struct task_struct *p, unsigned int match_state > > > > * is actually now running somewhere else! > > > > */ > > > > while (task_running(rq, p)) { > > > > - if (match_state && unlikely(READ_ONCE(p->__state) != match_state)) > > > > + if (match_state && > > > > + unlikely(!task_state_match_eq(p, match_state))) > > > > return 0; > > > > > > So wait_task_inactive() can return 0 but the task can run after that, right? > > > This is not what we want... > > > > Without checking both states you may never observe the requested state > > because it is set to TASK_RTLOCK_WAIT while waiting for a lock. Other > > than that, it may run briefly because it tries to acquire a lock or just > > acquired and this shouldn't be different from a task spinning on a lock. > > I don't understand. wait_task_inactive() is used to ensure that this task > doesn't and can't run again, until debugger resumes these tracee. > > Now. Unless I missed something, the tracee can leave CPU with saved_state > = TRACED (so task_state_match_eq() returns T) and wait_task_inactive() will > return. Then later the tracee will park in schedule again, yes. > > But, for example, what if debugger clears TIF_BLOCKSTEP in between, while > the tracee is running? Can't this race with __switch_to_xtra() ? If you describe like that, then it appears better to only look at ->state. Otherwise, yes, you would see the expected state in ->saved_state and the task might still be on the CPU. Even if it is not actually running/ on the runqueue, it could be the case if the lock has been made available shortly after. > Oleg. Sebastian