From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965127AbdCVRlk (ORCPT ); Wed, 22 Mar 2017 13:41:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34464 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935483AbdCVRlL (ORCPT ); Wed, 22 Mar 2017 13:41:11 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EB25F811A9 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=longman@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EB25F811A9 From: Waiman Long To: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Arnaldo Carvalho de Melo , Davidlohr Bueso , Mike Galbraith , Scott J Norton , Waiman Long Subject: [PATCH-tip v6 06/22] futex: Consolidate pure pi_state_list add & delete codes to helpers Date: Wed, 22 Mar 2017 13:38:42 -0400 Message-Id: <1490204338-1856-7-git-send-email-longman@redhat.com> In-Reply-To: <1490204338-1856-1-git-send-email-longman@redhat.com> References: <1490204338-1856-1-git-send-email-longman@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 22 Mar 2017 17:41:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Two new helper functions (task_pi_list_add & task_pi_list_del) are created to consolidate all the pure pi_state_list addition and insertion codes. The set_owner argument in task_pi_list_add() will be needed in a later patch. Signed-off-by: Waiman Long --- kernel/futex.c | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/kernel/futex.c b/kernel/futex.c index 9a27a79..cff711d 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -824,6 +824,39 @@ static inline int get_futex_value(u32 *dest, u32 __user *from) /* * PI code: */ + +/** + * task_pi_list_add - add futex state object to a task's pi_state_list + * @task : task structure + * @state: futex state object + */ +static inline void task_pi_list_add(struct task_struct *task, + struct futex_state *state) +{ + raw_spin_lock_irq(&task->pi_lock); + WARN_ON(!list_empty(&state->list)); + list_add(&state->list, &task->pi_state_list); + state->owner = task; + raw_spin_unlock_irq(&task->pi_lock); +} + +/** + * task_pi_list_del - delete futex state object from a task's pi_state_list + * @state: futex state object + * @warn : warn if list is empty when set + */ +static inline void task_pi_list_del(struct futex_state *state, const bool warn) +{ + struct task_struct *task = state->owner; + + raw_spin_lock_irq(&task->pi_lock); + if (warn) + WARN_ON(list_empty(&state->list)); + list_del_init(&state->list); + state->owner = NULL; + raw_spin_unlock_irq(&task->pi_lock); +} + static int refill_futex_state_cache(void) { struct futex_state *state; @@ -876,9 +909,7 @@ static void put_futex_state(struct futex_state *state) * and has cleaned up the futex state already */ if (state->owner) { - raw_spin_lock_irq(&state->owner->pi_lock); - list_del_init(&state->list); - raw_spin_unlock_irq(&state->owner->pi_lock); + task_pi_list_del(state, false); rt_mutex_proxy_unlock(&state->pi_mutex, state->owner); } @@ -2213,19 +2244,10 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, * We fixed up user space. Now we need to fix the pi_state * itself. */ - if (pi_state->owner != NULL) { - raw_spin_lock_irq(&pi_state->owner->pi_lock); - WARN_ON(list_empty(&pi_state->list)); - list_del_init(&pi_state->list); - raw_spin_unlock_irq(&pi_state->owner->pi_lock); - } + if (pi_state->owner != NULL) + task_pi_list_del(pi_state, true); - pi_state->owner = newowner; - - raw_spin_lock_irq(&newowner->pi_lock); - WARN_ON(!list_empty(&pi_state->list)); - list_add(&pi_state->list, &newowner->pi_state_list); - raw_spin_unlock_irq(&newowner->pi_lock); + task_pi_list_add(newowner, pi_state); return 0; /* -- 1.8.3.1