From patchwork Tue Aug 1 04:31:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 109103 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1025226qge; Mon, 31 Jul 2017 21:31:38 -0700 (PDT) X-Received: by 10.99.117.19 with SMTP id q19mr17743727pgc.442.1501561898629; Mon, 31 Jul 2017 21:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501561898; cv=none; d=google.com; s=arc-20160816; b=GfOQgcej6SOq+4HDTCjwbIgPCsAeFNDT9eRpasIMdvs+9/rADhVaFhiOuajDbmDmL7 v0F+1DYx0yx5zvc+k394c/zNurGIgX91GlpdiM6AkyulvV6FHY4U7owT61nr96RabRfv PZGOqChHGzc5lTEqz/bozSVhqEDYmuTr5wGJmvogYX0b37+QckZyBJk9KXXfZt7xkC0B 3tE9D+/XEZA73/gYF5jEK7BR/VgTji38xwqhyqsnao0QcLeotL169uOA7kPLPinWD4Qw MUnEwabkl28RZe3e/+LAmGplrLlk5FmCMSRZS2XEN0MQxligwNeXncZbpo7nR0Zo9zoG 6xfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=yvj05JJHuXpH5Va0vD3/gHVnjk2ZBgzndkRFp65LUDs=; b=WhyfAhkWNijCmHWysYnR9TB7Fjj/zV4vSu/FR3bVxkYvYxfmyRUIzeo2ed6WGYqmsm vDbeP4jWUwKQ6HWjQpVTt7MVH6iEwv9CJ1USMfqujRNoyghUtEsv7RaKn+fdscM/PxkS Omw0JSTFltM2RDTOa/uvgN69QHzcIq+NGtJcGzrKCbju7ZmXrb3OR/RUE7qNeYwcTPTy 2zqUgXI39ZLG+mXeY52sPd7f/xT3JWBgzfJZi1E8gGEgi5V07mWigguv+NlSiLeQm3N1 58Fp4B4nEZmHUp2VPrTOA6ROZYqvtHoAginJwkt5lkS7olqPLXnIUaGJt/vrYogLNnqe eMhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=akCk/RCQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w188si17112155pfw.194.2017.07.31.21.31.38; Mon, 31 Jul 2017 21:31:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=akCk/RCQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751878AbdHAEbg (ORCPT + 26 others); Tue, 1 Aug 2017 00:31:36 -0400 Received: from mail-it0-f50.google.com ([209.85.214.50]:33106 "EHLO mail-it0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751827AbdHAEbe (ORCPT ); Tue, 1 Aug 2017 00:31:34 -0400 Received: by mail-it0-f50.google.com with SMTP id v127so17762606itd.0 for ; Mon, 31 Jul 2017 21:31:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=yvj05JJHuXpH5Va0vD3/gHVnjk2ZBgzndkRFp65LUDs=; b=akCk/RCQKTs0dRTXWIGNOFmJP8m9qnzs1QlxgTixhU7GpkJ3fhuBvB/maZVw/R3hJd blIUHlIwuSPQjG/x80o8ojO1PQS1UlBIOc8IJypDftGE0B2QmCm5qE++0HrfEp5fYpU7 Uf6VD9U1frLG1fFn/DNyyWqGeO2n0fp6vDzG8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=yvj05JJHuXpH5Va0vD3/gHVnjk2ZBgzndkRFp65LUDs=; b=KY8RdTFSG23yI/boi09bI27SgKSaCmHdOXsj3J4pHDgzqE2HtPU2E4Jb/QVP33dchD Xlj/rzsfEXcSAug5LRbDPzbaJbXsvBpt/ZdCoS5PvxaAJuXhrIsCMw8HDO4NTs3AwdJN WToKNGAXiyYHNT7EE7Lwg5JA45CJWBqgy7/RmF23KUwGNr047Fm5xMDJdBrnGgHxy0m6 07nI+x43i1NDUn8RaERcNe85Y9jkGwkeVsCfjN/3kpKE24fBzMDpfQVHOn2/km5bhC0r oKmJedGnx1U+WLP5IU+ZHgD2V8al7LNO0YjMD6QvMDFqDBOxtyhx9iTZoT//IkQG7kNB mZFw== X-Gm-Message-State: AIVw111QR1hJJUyJBRJ0ALbR5tIA23sMOwci7G3vLCM0TEwR9uk/Xfbg EaVlQx0UVG9dTs7+ X-Received: by 10.36.213.4 with SMTP id a4mr430558itg.127.1501561893679; Mon, 31 Jul 2017 21:31:33 -0700 (PDT) Received: from xanadu.home (modemcable065.157-23-96.mc.videotron.ca. [96.23.157.65]) by smtp.gmail.com with ESMTPSA id b185sm262370itc.1.2017.07.31.21.31.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Jul 2017 21:31:33 -0700 (PDT) Date: Tue, 1 Aug 2017 00:31:32 -0400 (EDT) From: Nicolas Pitre To: Thomas Gleixner cc: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org Subject: [PATCH] futex: allow for compiling out PI support Message-ID: User-Agent: Alpine 2.20 (LFD 67 2015-01-07) MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This makes it possible to preserve basic futex support and compile out the PI support when RT mutexes are not available. Signed-off-by: Nicolas Pitre --- include/linux/futex.h | 7 ++++++- init/Kconfig | 7 ++++++- kernel/futex.c | 22 ++++++++++++++++++++++ kernel/locking/rtmutex_common.h | 29 +++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/include/linux/futex.h b/include/linux/futex.h index 7c5b694864..f36bfd26f9 100644 --- a/include/linux/futex.h +++ b/include/linux/futex.h @@ -54,7 +54,6 @@ union futex_key { #ifdef CONFIG_FUTEX extern void exit_robust_list(struct task_struct *curr); -extern void exit_pi_state_list(struct task_struct *curr); #ifdef CONFIG_HAVE_FUTEX_CMPXCHG #define futex_cmpxchg_enabled 1 #else @@ -64,8 +63,14 @@ extern int futex_cmpxchg_enabled; static inline void exit_robust_list(struct task_struct *curr) { } +#endif + +#ifdef CONFIG_FUTEX_PI +extern void exit_pi_state_list(struct task_struct *curr); +#else static inline void exit_pi_state_list(struct task_struct *curr) { } #endif + #endif diff --git a/init/Kconfig b/init/Kconfig index 8514b25db2..5f0ef850e8 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1275,12 +1275,17 @@ config BASE_FULL config FUTEX bool "Enable futex support" if EXPERT default y - select RT_MUTEXES + imply RT_MUTEXES help Disabling this option will cause the kernel to be built without support for "fast userspace mutexes". The resulting kernel may not run glibc-based applications correctly. +config FUTEX_PI + bool + depends on FUTEX && RT_MUTEXES + default y + config HAVE_FUTEX_CMPXCHG bool depends on FUTEX diff --git a/kernel/futex.c b/kernel/futex.c index 16dbe4c938..ad0af4df1b 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -875,6 +875,8 @@ static struct task_struct *futex_find_get_task(pid_t pid) return p; } +#ifdef CONFIG_FUTEX_PI + /* * This task is holding PI mutexes at exit time => bad. * Kernel cleans up PI-state, but userspace is likely hosed. @@ -932,6 +934,8 @@ void exit_pi_state_list(struct task_struct *curr) raw_spin_unlock_irq(&curr->pi_lock); } +#endif + /* * We need to check the following states: * @@ -1799,6 +1803,15 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags, struct futex_q *this, *next; DEFINE_WAKE_Q(wake_q); + /* + * When PI not supported: return -ENOSYS if requeue_pi is true, + * consequently the compiler knows requeue_pi is always false past + * this point which will optimize away all the conditional code + * further down. + */ + if (!IS_ENABLED(CONFIG_FUTEX_PI) && requeue_pi) + return -ENOSYS; + if (requeue_pi) { /* * Requeue PI only works on two distinct uaddrs. This @@ -2594,6 +2607,9 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, struct futex_q q = futex_q_init; int res, ret; + if (!IS_ENABLED(CONFIG_FUTEX_PI)) + return -ENOSYS; + if (refill_pi_state_cache()) return -ENOMEM; @@ -2773,6 +2789,9 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags) struct futex_q *top_waiter; int ret; + if (!IS_ENABLED(CONFIG_FUTEX_PI)) + return -ENOSYS; + retry: if (get_user(uval, uaddr)) return -EFAULT; @@ -2983,6 +3002,9 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags, struct futex_q q = futex_q_init; int res, ret; + if (!IS_ENABLED(CONFIG_FUTEX_PI)) + return -ENOSYS; + if (uaddr == uaddr2) return -EINVAL; diff --git a/kernel/locking/rtmutex_common.h b/kernel/locking/rtmutex_common.h index 72ad45a9a7..8d039b928d 100644 --- a/kernel/locking/rtmutex_common.h +++ b/kernel/locking/rtmutex_common.h @@ -40,6 +40,9 @@ struct rt_mutex_waiter { /* * Various helpers to access the waiters-tree: */ + +#ifdef CONFIG_RT_MUTEXES + static inline int rt_mutex_has_waiters(struct rt_mutex *lock) { return !RB_EMPTY_ROOT(&lock->waiters); @@ -69,6 +72,32 @@ task_top_pi_waiter(struct task_struct *p) pi_tree_entry); } +#else + +static inline int rt_mutex_has_waiters(struct rt_mutex *lock) +{ + return false; +} + +static inline struct rt_mutex_waiter * +rt_mutex_top_waiter(struct rt_mutex *lock) +{ + return NULL; +} + +static inline int task_has_pi_waiters(struct task_struct *p) +{ + return false; +} + +static inline struct rt_mutex_waiter * +task_top_pi_waiter(struct task_struct *p) +{ + return NULL; +} + +#endif + /* * lock->owner state tracking: */