Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2389913pxb; Tue, 9 Mar 2021 00:58:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyU1HXx64Y8ODU4mm/AFWizJn/tpOX67UdfSifiFZDTrVKaidz4QViuoCXl0A6oPD/Wxa1I X-Received: by 2002:a05:6402:50c8:: with SMTP id h8mr2780920edb.360.1615280298778; Tue, 09 Mar 2021 00:58:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615280298; cv=none; d=google.com; s=arc-20160816; b=G5hDYU5HeMd311R0BCBkslOisfJyCLC4HUIW2H6/XHI8TOKGFhbj8VriM+co3T61UO 9EXFSsw6v0L38Y6N5xnjYri5n3mKDxJR7bXk7IGBN+6b58gZGywEnjk/Vf3ORWXC+3HU 3BpxDl7XLhOpGNrZ8R5/b/LFgupFNLjiRvKVTpdrCIG+MEoRUWtINNazzWvGTlYbNx2L Xva8gjl+DkSWUVc0zFkKkK3iJb3VFAr3/ahrx6C8kzDQRUNEeGB7HEc0Sl9pZ6eqqSb5 THR/ANAb/j9XirpqA4cO6KQx4mlYdmN+zel2YD3KlQExXzoWxbLdIVCJATPmiMGxliqt zamg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=k4YCi9TzxfvotEI0KHVk0DBixUOa/vI9Lyywwsk2fSU=; b=ZaZ/QTKPB2FKUFOMQ1BAZhBdhlYREjqaUgAKbIiqWLqskdLYl2EH4xBnc8q2T0K8Oz jwlvWiv9pyznRuWYWijo5UTN/a1+sSfBVDFX5tbOEylYQjFc0Ka7RtxpKS3N1I2ZWZ8m s4kJedtlYDBRkWdJ3HX5OJ6nY95b5L2jG6GMQZ1IFad+o4Ldx6SoqLIqYjU4b/aPhNPd lou2oWDkQe+D7DiQJGIVX+BJpp6roq9eTyMitGopl1up+sIvsaOQUQa4NT4rNBflG47l euGn4XfC1n+bBfk+OxnUUeniaDy6FOAusnjexx/sSlUHLNHAk1BC9SNHLpJMsQ7Hddsh kYqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EigNbIaF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si9309591edc.7.2021.03.09.00.57.55; Tue, 09 Mar 2021 00:58:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EigNbIaF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229481AbhCII45 (ORCPT + 99 others); Tue, 9 Mar 2021 03:56:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42476 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229641AbhCII4t (ORCPT ); Tue, 9 Mar 2021 03:56:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615280208; 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=k4YCi9TzxfvotEI0KHVk0DBixUOa/vI9Lyywwsk2fSU=; b=EigNbIaFFa+JrSQG3f0sR6c8fTgSR4BmzwIelh9Hsf9nj2WYDg9V2m8VOnwNxq4cMdiQIe HkRY6ou0ijvVRsHGFl5wDBUxSDnA1Z3SgUv9okcan5nZO2dhsL3O844I8CYfNsJMzpP21l Un/Zad7gg+tkazNyiyfN5ZKrB89Ckfg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-582-NQtAbCGcPM68MSVIDpfRAg-1; Tue, 09 Mar 2021 03:56:46 -0500 X-MC-Unique: NQtAbCGcPM68MSVIDpfRAg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 74CEB83DD22; Tue, 9 Mar 2021 08:56:45 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.193.174]) by smtp.corp.redhat.com (Postfix) with SMTP id EC598196E3; Tue, 9 Mar 2021 08:56:43 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 9 Mar 2021 09:56:45 +0100 (CET) Date: Tue, 9 Mar 2021 09:56:42 +0100 From: Oleg Nesterov To: Jim Newsome Cc: Andrew Morton , "Eric W. Biederman" , Christian Brauner , linux-kernel@vger.kernel.org Subject: Re: patch: do_wait: make PIDTYPE_PID case O(1) instead of O(n) Message-ID: <20210309085641.GB25222@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ah, and you forgot to CC lkml ;) let me resend my email. Hi Jim, Please do not use the attachments, just send the patch as plain text. See Documentation/process/submitting-patches.rst On 03/08, Jim Newsome wrote: > > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -1462,8 +1462,61 @@ static long do_wait(struct wait_opts *wo) > goto notask; > > set_current_state(TASK_INTERRUPTIBLE); > + > read_lock(&tasklist_lock); > tsk = current; > + > + if (wo->wo_type == PIDTYPE_PID) { > + // Optimization for PIDTYPE_PID. No need to iterate through child and > + // tracee lists to find the target task. I'd suggest to put this PIDTYPE_PID code into the new function. > + > + struct task_struct *real_parent = NULL; > + struct task_struct *target = NULL; > + bool do_regular_wait, do_ptrace_wait; > + > + // XXX: Do we need this? Or is the tasklist_lock sufficient? > + rcu_read_lock(); No, you don't need rcu lock, tasklist_lock is sufficient > + target = pid_task(wo->wo_pid, PIDTYPE_PID); > + if (!target) { > + rcu_read_unlock(); > + goto notask; This is wrong, you forgot to drop tasklist_lock. > + real_parent = !target->real_parent ? target->parent : > + target->real_parent; Hmm, I don't understand the line above... perhaps it connects to the question below. > + if (!real_parent) { > + // XXX: Is it a kernel bug to get here? Or would this be > + // true of the init process? Afaics, parent/real_parent can't be NULL if pid_task() succeeds. > + do_regular_wait = tsk == real_parent || > + (!(wo->wo_flags & __WNOTHREAD) && > + same_thread_group(tsk, real_parent)); > + do_ptrace_wait = target->ptrace && > + (tsk == target->parent || > + (!(wo->wo_flags & __WNOTHREAD) && > + same_thread_group(tsk, target->parent))); > + rcu_read_unlock(); > + > + if (do_regular_wait) { > + retval = > + wait_consider_task(wo, /* ptrace= */ 0, target); > + if (retval) { > + goto end; > + } > + } > + if (do_ptrace_wait) { > + retval = > + wait_consider_task(wo, /* ptrace= */ 1, target); > + if (retval) { > + goto end; > + } > + } > + read_unlock(&tasklist_lock); > + goto notask; This part looks correct at first glance... Please redo and send V2 ;) Oleg.