From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751647AbdBCSEX (ORCPT ); Fri, 3 Feb 2017 13:04:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60780 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751527AbdBCSEV (ORCPT ); Fri, 3 Feb 2017 13:04:21 -0500 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 v5 07/21] futex: Add a new futex type field into futex_state Date: Fri, 3 Feb 2017 13:03:40 -0500 Message-Id: <1486145034-22210-8-git-send-email-longman@redhat.com> In-Reply-To: <1486145034-22210-1-git-send-email-longman@redhat.com> References: <1486145034-22210-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.26]); Fri, 03 Feb 2017 18:04:17 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As the futex_state structure will be overloaded in later patches to be used by non-PI futexes, it is necessary to add a type field to distinguish among different types of futexes. Signed-off-by: Waiman Long --- kernel/futex.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kernel/futex.c b/kernel/futex.c index 25881e6..928212c 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -193,6 +193,10 @@ #define FLAGS_CLOCKRT 0x02 #define FLAGS_HAS_TIMEOUT 0x04 +enum futex_type { + TYPE_PI = 0, +}; + /* * Futex state object: * - Priority Inheritance state @@ -212,6 +216,7 @@ struct futex_state { struct task_struct *owner; atomic_t refcount; + enum futex_type type; union futex_key key; }; @@ -905,13 +910,14 @@ static void put_futex_state(struct futex_state *state) return; /* - * If state->owner is NULL, the owner is most probably dying - * and has cleaned up the futex state already + * If state->owner is NULL and the type is TYPE_PI, the owner is + * most probably dying and has cleaned up the futex state already. */ if (state->owner) { task_pi_list_del(state, false); - rt_mutex_proxy_unlock(&state->pi_mutex, state->owner); + if (state->type == TYPE_PI) + rt_mutex_proxy_unlock(&state->pi_mutex, state->owner); } if (current->pi_state_cache) @@ -1064,7 +1070,7 @@ static int attach_to_pi_state(u32 uval, struct futex_state *pi_state, /* * Userspace might have messed up non-PI and PI futexes [3] */ - if (unlikely(!pi_state)) + if (unlikely(!pi_state || (pi_state->type != TYPE_PI))) return -EINVAL; WARN_ON(!atomic_read(&pi_state->refcount)); @@ -1182,6 +1188,7 @@ static int attach_to_pi_owner(u32 uval, union futex_key *key, /* Store the key for possible exit cleanups: */ pi_state->key = *key; + pi_state->type = TYPE_PI; WARN_ON(!list_empty(&pi_state->list)); list_add(&pi_state->list, &p->pi_state_list); -- 1.8.3.1