Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1639861pxy; Mon, 2 Aug 2021 06:52:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsu8U+Dafn8lYKZxInZP9acHX9GuxZ/wxX5wwIhcXHSu7toVH7TycJcgjfBJNotzxcIK0D X-Received: by 2002:a02:cb4d:: with SMTP id k13mr1906485jap.31.1627912333606; Mon, 02 Aug 2021 06:52:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912333; cv=none; d=google.com; s=arc-20160816; b=qu5ZpM2Vl3oamZeoj6eMQoWitr6BpDxbOUguYltSi0WEZNDzJi6Th64tWB57dx5I+B P1G315VtcVJmj02ERUfPKuLDbFVX60O/j417xgcdj7lJlf2LWwDCs1G+J0JZPmDhVNCk 29px+HdqViz/sALyzvMH+EF9I2hd6Ex8UrUEV2hmFqibbtQEyAjzevy6XG5aASEoAS21 5iBPK875iXiZpqFSKYXogMEDO04lZxCxRR2hDdRcxGrvJtZEvCtvlPceILBKwuXQhVuQ XidkMvYhUDnhTaMy68bK2Li8Q2XnH3VepFM4wSIjrDViNmdVYjNicEOaBur2iapNgfSV +1gQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Ae6ShCczdBBcuv2AbjXuKtC/14VffyenhRV3YYa/fc8=; b=cYUCZg2EHTH2Du0NvtOw6Psb1JLn/Zhocba2GLFBjpTR/uVQBm5/FFbKXNVz+aKcNy 7T9AaLqF6x2VWI+QQ62zf/AJwo6oS/g+kM+2pDfRfn1MiCiJtoYh5LvkqtY8pAqiPhOz ssSLYaUX+wKc3bVDMvWXUPRI8NxwL5whS3MeOZBzpvqYpFE7QcG0W6xHDLMnxQPUb1Nt eDKLvcdYDloK6j5wQRZMF5+G+LE8ZXUlwmf7aHp4Skl5t3ccXmD8mpwwmmRJ4ttwc/lx EoN0RDMU4+gOA6inR9m+Whqw5/v7q8qqQFiJVJP8aIrjOjnpdrgg26PDvhYXQ+mWadSg fSJg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s14si13199326jar.33.2021.08.02.06.52.00; Mon, 02 Aug 2021 06:52:13 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234868AbhHBNuV (ORCPT + 99 others); Mon, 2 Aug 2021 09:50:21 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:12338 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234290AbhHBNrg (ORCPT ); Mon, 2 Aug 2021 09:47:36 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GdfM40V16z81wF; Mon, 2 Aug 2021 21:42:24 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 2 Aug 2021 21:47:13 +0800 Received: from thunder-town.china.huawei.com (10.174.179.0) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 2 Aug 2021 21:47:12 +0800 From: Zhen Lei To: Greg Kroah-Hartman , stable CC: Zhen Lei , Anna-Maria Gleixner , Mike Galbraith , Sasha Levin , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , linux-kernel Subject: [PATCH 4.4 02/11] futex: Cleanup refcounting Date: Mon, 2 Aug 2021 21:46:15 +0800 Message-ID: <20210802134624.1934-3-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20210802134624.1934-1-thunder.leizhen@huawei.com> References: <20210802134624.1934-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.179.0] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected 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 --- kernel/futex.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/futex.c b/kernel/futex.c index dbb38e14f6fcc8e..dab9c79a931a23e 100644 --- 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 futex_pi_state *pi_state, } } +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_state *pi_state) * 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 *uaddr, u32 uval, 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, -- 2.26.0.106.g9fadedd