Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2286225ybb; Fri, 27 Mar 2020 02:39:40 -0700 (PDT) X-Google-Smtp-Source: ADFU+vteMxT3GvNhH6kQl7HqQ66si35Ykr9zqQNiBFyS5jRQn9IGQp5wlyz7zrw69/Zg3J8n+xAh X-Received: by 2002:a9d:23a6:: with SMTP id t35mr10434865otb.154.1585301979953; Fri, 27 Mar 2020 02:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585301979; cv=none; d=google.com; s=arc-20160816; b=XvKQT8fWgNl/IPIj2hc2rp6ShOaj6z7MgAQ9BZfQ9JayLA+NRd8mzyZVwMOBWCK7nL 1rzxrV/v9lHuQmcZQEx+YDyeDGIyX1sdA2wqNzASsNjcIvx6OJRqgiit6Zw3U18cCzIA W1v7uwMK2YnpgXCdg3r/zo6RFfQ2KHpbrY25dpTzrdVXua+KxgKYeSIvxB3up7wtoGrZ zSGc7IwLNimo5+eD51za9DZYGgci5D4RP4T/tvqQdK0Ovn088Bvt9i3bjcr4iBsr3OyF R++ykGNkVHf962dGwevsRN4I5oIsuEISCntQJBiL+fcO9+aZVi5ChfB9m+F0EmPeP0Tf ylQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=x9/k7pLBQXCwm7HGvR1QbvLQvbr1hh7C7rCsl4jVIp8=; b=ckU4hq9q+GC6MV3Fg+AknV/6dsnKSh1cvDgoDv1NqV4poD6vYY299IJsjqKSkKtDjm zIKpDyX8om8eewGM9C9efVrdl6Bn0ZEB22tQG5htdzarf6+eP3Zn4zPx5FCFCYs8R5s9 Ki0Xrqoz6ogwBJwDOhq8o1TQFrSr0IgDGKn2MhJJL/V2wFk4EuGY6WAEu6M239hU+H3O sC2s1Ic5hC9ZbFumR0C6khRYBuxtKHIAPprAzfrtcs8g2FM9Px5NMoGjCBM3IaYahxDn 2PMJQBoyxlU8BKCJ9AxfyAvGofsV14MYL5G5Elu0u641Dm7ZNFE+O7lyeC0q33CljxjC mwUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=GBagvQ3n; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y16si2201212oie.225.2020.03.27.02.39.26; Fri, 27 Mar 2020 02:39:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=GBagvQ3n; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727620AbgC0JiB (ORCPT + 99 others); Fri, 27 Mar 2020 05:38:01 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:55624 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbgC0JiB (ORCPT ); Fri, 27 Mar 2020 05:38:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=x9/k7pLBQXCwm7HGvR1QbvLQvbr1hh7C7rCsl4jVIp8=; b=GBagvQ3n3RtUHtNaZr+93PgyTz FoC+rqyv0fZwWLad3v3YTDiSA3bQpzsrz7DNe9lYbKu/dzX/LizYBtyQr3OjE6IusokaLyZ2KeYf9 Jko1nCvSwFcdzQHePIVaHU07umb3Wi7OsPwp3psxL1EJp7dF658jJoaDkIOcMGN4R+hporRkR+ihW kDC0SG9iSF0+gVcHHncvw8xzTvnx5HgY3xUcOyAVnP8yjOckwwMuNKqsmW5DNrxd6KWe20YGKXpK+ FGircB0FvGDmKCAXF6abyVAuu35YJTFUD0BN9MQ5gZdTBNO22i05ybmrmWmrmEpP/ANvWnvoQYQMH g3BSVfag==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jHlR7-0008Ch-Di; Fri, 27 Mar 2020 09:37:57 +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 DDD1A30066E; Fri, 27 Mar 2020 10:37:54 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id CD153203B8786; Fri, 27 Mar 2020 10:37:54 +0100 (CET) Date: Fri, 27 Mar 2020 10:37:54 +0100 From: Peter Zijlstra To: Qian Cai Cc: mingo@redhat.com, will@kernel.org, dbueso@suse.de, juri.lelli@redhat.com, longman@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH -next] locking/percpu-rwsem: fix a task_struct refcount Message-ID: <20200327093754.GS20713@hirez.programming.kicks-ass.net> References: <20200327031057.10866-1-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200327031057.10866-1-cai@lca.pw> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 26, 2020 at 11:10:57PM -0400, Qian Cai wrote: > There are some memory leaks due to a missing put_task_struct(). This is an absolutely inadequate changelog. There is no explaning what the actual race is and why this patch is correct. > Fixes: 7f26482a872c ("locking/percpu-rwsem: Remove the embedded rwsem") > Signed-off-by: Qian Cai > --- > kernel/locking/percpu-rwsem.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c > index a008a1ba21a7..6f487e5d923f 100644 > --- a/kernel/locking/percpu-rwsem.c > +++ b/kernel/locking/percpu-rwsem.c > @@ -123,8 +123,10 @@ static int percpu_rwsem_wake_function(struct wait_queue_entry *wq_entry, > struct percpu_rw_semaphore *sem = key; > > /* concurrent against percpu_down_write(), can get stolen */ > - if (!__percpu_rwsem_trylock(sem, reader)) > + if (!__percpu_rwsem_trylock(sem, reader)) { > + put_task_struct(p); > return 1; > + } If the trylock fails, someone else got the lock and we remain on the waitqueue. It seems like a very bad idea to put the task while it remains on the waitqueue, no? > > list_del_init(&wq_entry->entry); > smp_store_release(&wq_entry->private, NULL); > -- > 2.21.0 (Apple Git-122.2) >