From patchwork Mon Aug 2 13:46:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 490344 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:1185:0:0:0:0 with SMTP id f5csp1940538jas; Mon, 2 Aug 2021 06:48:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySkG/23TWpmbK7np8KGK+y43Sqmb3OriSMntKYW9Rql5MeBKjGwFXE3NhzFKOMa/SbiNLw X-Received: by 2002:a6b:7a04:: with SMTP id h4mr89037iom.149.1627912088919; Mon, 02 Aug 2021 06:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912088; cv=none; d=google.com; s=arc-20160816; b=z/Z6Jn0vBXP6mmeUWuuYBad7fLl3stdKPhAbTCOhoqMwk5WL5OiRmnyP/59mQc+GGu 9jy7hAfjEF96Ti5/CGb4qYfvrcZHGMO8zC+RY8J9zeFyTKYoBBzTnga9x7P/kbVWvb4/ wqod5z7Mc7WTIlRJHVZtHRPWKFmWg8esv7p/Y5JQbUZVE9PsfDiVj4fCTLCQBEU7DYC0 UZqaM04ed7EUpzEN0hLh3DMugQ0BXGNorTqpPAKzXLAxd4LQX2q0LzksipU3cCwznxmH yoMS8p8QvhYHcHzKIYkEVcATs9CPD+QsTxXA2ZMpP9MsQUFx5lps4DtTUyRvEQQJxnKP D4MQ== 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=ZHXHHQN+9z+B8nNWv+TWh9YFoTWOVFwihvKH3bqAUm6LMulgDBAJs2eUKLy9nldcXC FAif8+D8UOJtBfzpNYq2ejdaOMwvgQ3BBsxfb7IKnO1uo3rgswVpqkziTpr6qSoDWC28 jWMPTaCyc9VoZ7RyM3kkCJH8y6LFyVyZ2kv9KletFrsJ33+ScqZzAxNUJprc1kQ/mNkf WFQfJ83l0yOdF8RJvNpcV7cjsOkBLzXE+7eqEBL7n2CS13x2NWHJTPI5phCWK9f4eSJF gqwlLvsmlZT59+C/WawY8/mbhOqKF7uBoIx9LGpo6tckH6rUIF9ZCW9VTzCyV8ITF4g/ 0Ejw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 b15si12624707ioj.7.2021.08.02.06.48.08; Mon, 02 Aug 2021 06:48:08 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S234307AbhHBNsP (ORCPT + 12 others); Mon, 2 Aug 2021 09:48:15 -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 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: stable@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(-) -- 2.26.0.106.g9fadedd 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,