Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp355551pxu; Wed, 25 Nov 2020 05:07:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxV02FqI20umT2yltdV6tzef+pBmHt4GOvkBGwWatB3ew9CqYkvEh9zIuReh+Sk4DfGmWAZ X-Received: by 2002:a05:6402:1c1c:: with SMTP id ck28mr3465242edb.336.1606309639947; Wed, 25 Nov 2020 05:07:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606309639; cv=none; d=google.com; s=arc-20160816; b=OjNUFKk7cRCVLaShL+FADSD0ozQTJF0RHkkGMa5YSU+0HchZqCzjJaKqWfljNkkg0i SwCk1b9g4d3bi3aZJMtONuIDdWkoBMEFNFvr2cTDJhthfeLoy8P1U33NBSUgXaAKhRO4 +vKeLcM20/6ztsyq4TXmXlks2EjJxZ16bv3KPP0abYtyG0ME6JguzrbJCsS1fCmDhMg9 RTWmTBOwAhG86EW5OG7vRFYnSHZdwh4/KhBlLJPYkO+aVPW6VPY1dFO8oBCvba6bZvMK A5hK1++zTWZTxFEBM517yc6Vx5PFZwZO29dYxSVgmAJtTc2JHjKt3i765bKfdRkHeFfP XDRg== 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=ChnPSnYSrpAjn5eTsO0Dj+lGuaPW578KWibnvzMSe1s=; b=zZzvsdBxSzZ3UZrZt1kz83CfkpeVPnLjVd1GNKnESzvMwyRBxVBkNUdZ4hB/is+xXk j2itN6vMvL3CkFtPXl6iTG5xdAWsjvH7pXXYg00JXaHhPdaKwUwM8gcICWjYe/ldkeiD mQ45a8aVdGxGw7exzjcc+LEBRdEulmVP1BFKBo3+VAqIbSCtTxiIWVKKyDyyDBuEZwKw 7cZAxG7LzOG+A+6iiApom2YAWLT8zXeMG/Xqiq1bkKhQ4YYSI0zTmltKxEigCJi5LRUS lJPGKPPzXQEEUJ87WN2dPlnUfGJMKIT5HN87FHCQnPsef5kq4PKCoTh927S2RV5wuFWk gs1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=Y6M+MFFB; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g18si1093513edh.40.2020.11.25.05.06.56; Wed, 25 Nov 2020 05:07:19 -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=@infradead.org header.s=merlin.20170209 header.b=Y6M+MFFB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729612AbgKYNEb (ORCPT + 99 others); Wed, 25 Nov 2020 08:04:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729309AbgKYNEa (ORCPT ); Wed, 25 Nov 2020 08:04:30 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE33AC0613D4 for ; Wed, 25 Nov 2020 05:04:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; 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=ChnPSnYSrpAjn5eTsO0Dj+lGuaPW578KWibnvzMSe1s=; b=Y6M+MFFBNdQVG+SaBH+zvFK7yT cx9WLVC+PvDZNVj7/xYuMaPImYxELOZp9nWHbG5C5COTigQSXSNTgpH3pkQzJHr0RB1izGsuk25R4 THCA1GMBTjjZ/SJu1G8rmAp4p2QnChJhikMX4KwYVu29QePA1eNe7ICqRdAGrsvvvWZUOivr/92tM 8g98wJO6m9uRaL6m2wbczzgu/iSGj1ysJ+Xu/3SgjM3TyFGJpCkmM2LcGRAgDQvqz4Xg3sBKdR8LD LuNA4YsFeO2D2Q/DxCi4tfarongVszLj9HvCYJU3FCdHkSJPlJP0dGv86fpooOa8S0oa/Xl1QtxT7 0xdWYZBQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1khuSE-0005Lk-Jb; Wed, 25 Nov 2020 13:03:26 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A89643012DF; Wed, 25 Nov 2020 14:03:22 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9135920D6FE65; Wed, 25 Nov 2020 14:03:22 +0100 (CET) Date: Wed, 25 Nov 2020 14:03:22 +0100 From: Peter Zijlstra To: "Joel Fernandes (Google)" Cc: Nishanth Aravamudan , Julien Desfossez , Tim Chen , Vineeth Pillai , Aaron Lu , Aubrey Li , tglx@linutronix.de, linux-kernel@vger.kernel.org, mingo@kernel.org, torvalds@linux-foundation.org, fweisbec@gmail.com, keescook@chromium.org, kerrnel@google.com, Phil Auld , Valentin Schneider , Mel Gorman , Pawan Gupta , Paolo Bonzini , vineeth@bitbyteword.org, Chen Yu , Christian Brauner , Agata Gruza , Antonio Gomez Iglesias , graf@amazon.com, konrad.wilk@oracle.com, dfaggioli@suse.com, pjt@google.com, rostedt@goodmis.org, derkling@google.com, benbjiang@tencent.com, Alexandre Chartre , James.Bottomley@hansenpartnership.com, OWeisse@umich.edu, Dhaval Giani , Junaid Shahid , jsbarnes@google.com, chris.hyser@oracle.com, Ben Segall , Josh Don , Hao Luo , Tom Lendacky , Aubrey Li , "Paul E. McKenney" , Tim Chen Subject: Re: [PATCH -tip 22/32] sched: Split the cookie and setup per-task cookie on fork Message-ID: <20201125130322.GW2414@hirez.programming.kicks-ass.net> References: <20201117232003.3580179-1-joel@joelfernandes.org> <20201117232003.3580179-23-joel@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201117232003.3580179-23-joel@joelfernandes.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 17, 2020 at 06:19:52PM -0500, Joel Fernandes (Google) wrote: > +static bool sched_core_get_task_cookie(unsigned long cookie) > +{ > + struct sched_core_cookie *ptr = (struct sched_core_cookie *)cookie; > + > + /* > + * NOTE: sched_core_put() is not done by put_task_cookie(). Instead, it > + * is done after the stopper runs. > + */ > + sched_core_get(); > + return refcount_inc_not_zero(&ptr->refcnt); See below, but afaict this should be refcount_inc(). > +} > + /* > + * t1 joining t2 > + * CASE 1: > + * before 0 0 > + * after new cookie new cookie > + * > + * CASE 2: > + * before X (non-zero) 0 > + * after 0 0 > + * > + * CASE 3: > + * before 0 X (non-zero) > + * after X X > + * > + * CASE 4: > + * before Y (non-zero) X (non-zero) > + * after X X > + */ > + if (!t1->core_task_cookie && !t2->core_task_cookie) { > + /* CASE 1. */ > + cookie = sched_core_alloc_task_cookie(); > + if (!cookie) > + goto out_unlock; > + > + /* Add another reference for the other task. */ > + if (!sched_core_get_task_cookie(cookie)) { afaict this should be refcount_inc(), as this can never fail and if it does, it's an error. > + ret = -EINVAL; > + goto out_unlock; > + } > + > + wr.tasks[0] = t1; > + wr.tasks[1] = t2; > + wr.cookies[0] = wr.cookies[1] = cookie; > + > + } else if (t1->core_task_cookie && !t2->core_task_cookie) { > + /* CASE 2. */ > + sched_core_put_task_cookie(t1->core_task_cookie); > + sched_core_put_after_stopper = true; > + > + wr.tasks[0] = t1; /* Reset cookie for t1. */ > + > + } else if (!t1->core_task_cookie && t2->core_task_cookie) { > + /* CASE 3. */ > + if (!sched_core_get_task_cookie(t2->core_task_cookie)) { afaict this can never fail either, because you're calling in here with a reference on t2 > + ret = -EINVAL; > + goto out_unlock; > + } > + > + wr.tasks[0] = t1; > + wr.cookies[0] = t2->core_task_cookie; > + > + } else { > + /* CASE 4. */ > + if (!sched_core_get_task_cookie(t2->core_task_cookie)) { Same. > + ret = -EINVAL; > + goto out_unlock; > + } > + sched_core_put_task_cookie(t1->core_task_cookie); > + sched_core_put_after_stopper = true; > + > + wr.tasks[0] = t1; > + wr.cookies[0] = t2->core_task_cookie; > + }