Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp1762984pxt; Sun, 8 Aug 2021 00:24:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvNfzDPjya9pX1iwhQc0TJ7P1YF5SCwRsGB1L8CJOEe5nPEipWfndeZsLlHyCmycs5T8c3 X-Received: by 2002:a92:870b:: with SMTP id m11mr199598ild.132.1628407458315; Sun, 08 Aug 2021 00:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628407458; cv=none; d=google.com; s=arc-20160816; b=BBqzSFzYL2sSkoKeE9CnWtqqzJDYbmEaNTnYzWWN/4XUKyL/VklAhA0enSrQPp8M9Y gdN6uquAXsm/tNu1s3zYHlVJr8a89CnR4h+mYuz515WoZjQYo603cwnD3jPTyQxJmwuM p0XKre8S4Xotir6CWN/F4O6ewOmce96Y/XltHJd5thEyZTFVlyuLKJQ1AKFDsByYHTwe HGHecCkV95HQSLd7FO7VA1Kgn2BqBOOCV3kN6HAlA6I9S6MerjzsEoPMpeIwQoOZRbHV UUn3c4O9afXRRNzzfuMDTuvIp7Jt5AU0dZgICl3T3UpKKpuebrn1HD1SCpxZtQFk8clM 1MyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=c5m0nUgO8Kj6nasYbcjqvhGtot2rKT8r0Gm8IwHwpC4=; b=eeRWsxLzfzf9rPWXgazD4p+Evdh35rRJP2EdDo1TYsT+cZQCGHkQKcSsnUkRg2j14K OWN/bcSaGzNZRgMdSzYQfHfaBNbMeCDHgTvYxVV5nXn89YVlac7j+SLuzZ0q1rOm3Wto qiOrUn8eyz+CZRpG73enR3VWOnQUXESM8i7J4CsIVdbJOPB/i6obuH0w9oDOewitKBud e6+KL3BsN3HdaW2bRQUWzBPkYgOtl+29dOf64czmPa7tTgu7d8Ny8O73RUzkBJNzdfB6 K/znZqeHCNKqJeqHnnpnf0AnRXSQKWwI+bT7sWgjGdUsXCeM35kPCoJplyt5dObepv4r tYhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="o/uyMCtZ"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si13637641jao.100.2021.08.08.00.24.07; Sun, 08 Aug 2021 00:24:18 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b="o/uyMCtZ"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbhHHHX0 (ORCPT + 99 others); Sun, 8 Aug 2021 03:23:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:55008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231328AbhHHHXV (ORCPT ); Sun, 8 Aug 2021 03:23:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7B27C60F02; Sun, 8 Aug 2021 07:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628407382; bh=q18wI37N9Ng3TVmmftyzIFDQXlXvP0TaDJNf2OjhR4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o/uyMCtZ+o//OBpmbtn9zalfupwxUGU3Bmd6IAo9uLAbKbX+FYOYTmFORNwEk/YBP tOVmLFbTMqy2YsRKUKqgst6tEWFRaYZKN58uIv/pQgNZJtfeycoQ5hnjQ/hAIQPloK 0u1F83QoNl4gDAJDCv/vtxoeqbNOGNCuIHZHesY0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , juri.lelli@arm.com, bigeasy@linutronix.de, xlpang@redhat.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jdesfossez@efficios.com, dvhart@infradead.org, bristot@redhat.com, Thomas Gleixner , Zhen Lei , Joe Korty Subject: [PATCH 4.4 02/11] futex: Cleanup refcounting Date: Sun, 8 Aug 2021 09:22:37 +0200 Message-Id: <20210808072217.401551055@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210808072217.322468704@linuxfoundation.org> References: <20210808072217.322468704@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra [ Upstream commit bf92cf3a5100f5a0d5f9834787b130159397cb22 ] Add a put_pit_state() as counterpart for get_pi_state() so the refcounting becomes consistent. Signed-off-by: Peter Zijlstra (Intel) Cc: juri.lelli@arm.com Cc: bigeasy@linutronix.de Cc: xlpang@redhat.com Cc: rostedt@goodmis.org Cc: mathieu.desnoyers@efficios.com Cc: jdesfossez@efficios.com Cc: dvhart@infradead.org Cc: bristot@redhat.com Link: http://lkml.kernel.org/r/20170322104151.801778516@infradead.org Signed-off-by: Thomas Gleixner Signed-off-by: Zhen Lei Acked-by: Joe Korty Signed-off-by: Greg Kroah-Hartman --- kernel/futex.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/kernel/futex.c +++ b/kernel/futex.c @@ -825,7 +825,7 @@ static int refill_pi_state_cache(void) return 0; } -static struct futex_pi_state * alloc_pi_state(void) +static struct futex_pi_state *alloc_pi_state(void) { struct futex_pi_state *pi_state = current->pi_state_cache; @@ -858,6 +858,11 @@ static void pi_state_update_owner(struct } } +static void get_pi_state(struct futex_pi_state *pi_state) +{ + WARN_ON_ONCE(!atomic_inc_not_zero(&pi_state->refcount)); +} + /* * Drops a reference to the pi_state object and frees or caches it * when the last reference is gone. @@ -901,7 +906,7 @@ static void put_pi_state(struct futex_pi * Look up the task based on what TID userspace gave us. * We dont trust it. */ -static struct task_struct * futex_find_get_task(pid_t pid) +static struct task_struct *futex_find_get_task(pid_t pid) { struct task_struct *p; @@ -1149,7 +1154,7 @@ static int attach_to_pi_state(u32 __user goto out_einval; out_attach: - atomic_inc(&pi_state->refcount); + get_pi_state(pi_state); raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); *ps = pi_state; return 0; @@ -2204,7 +2209,7 @@ retry_private: */ if (requeue_pi) { /* Prepare the waiter to take the rt_mutex. */ - atomic_inc(&pi_state->refcount); + get_pi_state(pi_state); this->pi_state = pi_state; ret = rt_mutex_start_proxy_lock(&pi_state->pi_mutex, this->rt_waiter,