Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp7104196rdb; Fri, 15 Dec 2023 19:29:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2iLvuBnwgeWPa7CGZfkVcNKMRRS0IFHobtig2X+qI9LMkVEmbvb97qvyCPGO0wt71C1pv X-Received: by 2002:a0c:e805:0:b0:67f:1ca:8c38 with SMTP id y5-20020a0ce805000000b0067f01ca8c38mr5465560qvn.52.1702697363043; Fri, 15 Dec 2023 19:29:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702697363; cv=none; d=google.com; s=arc-20160816; b=YwRvGbgpdVO8g0JyxzWP/rL/gXvCdK6QddoLpRnLczQNJwjm2dLI76bohcAogI6YfS UQ/YnMNeJ+GuGaK/7LxXlhYmM23G0Ho7yyJwsEUOiBshXkia0RHLll5geE9VhZi/8WDm u7ma2tnCQIP3ngwQwQbuuD1j52QlpDtsv65Z0eN++uyyrTD2z3nxbG+i6XfMuZXTULE0 J+OTSmrHzBRv5/UX8nKfuQle84E3QDVtXD2MF1j8PxOmtTdQ2BlkZ8/6KKycIiJKg6hn 3t6xue/7IKp4NUxtYFcOOKP3Uvk7NGFT5fJdjPWbd8NQgJJAPzXtAjzCuZpU1soIxH86 wARw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SXxCqM/e1FB55uLwmZS35mh8NG7r88Szct15Gk8BhFo=; fh=vHhjxHftTECn/hRvIWNlq1eDzDsn74Roqz0kmRcPgcE=; b=UYlgTNSpeRopUD5/qCfkF5RJvPQwcGqZzcktOSPN8jl3YplGlijjntpF+OvbkpT9Q/ k0Czkjy1V09+2StjC5i357XDO11y84N64NNBvuXttLR266WE/acWUwTLI34Nzdg89NBB fTRNUjpV9Be9gpLkUTgXVFDGiUImGCoSRk+xBpCIVfLnKIxRB2QAzyFYcM3PMyem9cVF P0xNmM1Tw3ReYK0xZGjsy2I7SKp4tp9bftMBmqBGuwY119tgg+evnbEP3CLX1dv7b6+3 pji8OvY/t/4nARSyv8KygMXu8zWwpZBu7rGqE1iUOb8ciAL3rRMmFgkwA3IjIbzbmmIK JbIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CWnhaoch; spf=pass (google.com: domain of linux-kernel+bounces-1994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1994-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g5-20020a0ce4c5000000b0067f2a09a20csi169963qvm.487.2023.12.15.19.29.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 19:29:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CWnhaoch; spf=pass (google.com: domain of linux-kernel+bounces-1994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1994-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B73FE1C248EA for ; Sat, 16 Dec 2023 03:29:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0758A1E4A1; Sat, 16 Dec 2023 03:27:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="CWnhaoch" X-Original-To: linux-kernel@vger.kernel.org Received: from out-176.mta0.migadu.com (out-176.mta0.migadu.com [91.218.175.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FE7F1A27A for ; Sat, 16 Dec 2023 03:27:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702697237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SXxCqM/e1FB55uLwmZS35mh8NG7r88Szct15Gk8BhFo=; b=CWnhaochAsy6lJqiTdhs4ALt36jqcdkjrNNJLlyCebEcFi77MIzyYchlT3ZKJp1qkdUw+a g0rIYF+ygVVf8ox5ZVu6ZtsSjccEjMWnuC+TuJrABdg1a1z78QjuI4/k+JkyWcRCwukZQH B+GcssvUHU4Q2y2LmE/gokgKLEfZqPU= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: Kent Overstreet , tglx@linutronix.de, x86@kernel.org, tj@kernel.org, peterz@infradead.org, mathieu.desnoyers@efficios.com, paulmck@kernel.org, keescook@chromium.org, dave.hansen@linux.intel.com, mingo@redhat.com, will@kernel.org, longman@redhat.com, boqun.feng@gmail.com, brauner@kernel.org Subject: [PATCH 19/50] locking/mutex: split out mutex_types.h Date: Fri, 15 Dec 2023 22:26:18 -0500 Message-ID: <20231216032651.3553101-9-kent.overstreet@linux.dev> In-Reply-To: <20231216032651.3553101-1-kent.overstreet@linux.dev> References: <20231216024834.3510073-1-kent.overstreet@linux.dev> <20231216032651.3553101-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Trimming down sched.h dependencies: we don't want to include more than the base types. Signed-off-by: Kent Overstreet Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Signed-off-by: Kent Overstreet --- include/linux/mutex.h | 52 +-------------------------- include/linux/mutex_types.h | 71 +++++++++++++++++++++++++++++++++++++ include/linux/sched.h | 2 +- 3 files changed, 73 insertions(+), 52 deletions(-) create mode 100644 include/linux/mutex_types.h diff --git a/include/linux/mutex.h b/include/linux/mutex.h index a33aa9eb9fc3..0dfba5df6524 100644 --- a/include/linux/mutex.h +++ b/include/linux/mutex.h @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef CONFIG_DEBUG_LOCK_ALLOC # define __DEP_MAP_MUTEX_INITIALIZER(lockname) \ @@ -33,49 +34,6 @@ #ifndef CONFIG_PREEMPT_RT -/* - * Simple, straightforward mutexes with strict semantics: - * - * - only one task can hold the mutex at a time - * - only the owner can unlock the mutex - * - multiple unlocks are not permitted - * - recursive locking is not permitted - * - a mutex object must be initialized via the API - * - a mutex object must not be initialized via memset or copying - * - task may not exit with mutex held - * - memory areas where held locks reside must not be freed - * - held mutexes must not be reinitialized - * - mutexes may not be used in hardware or software interrupt - * contexts such as tasklets and timers - * - * These semantics are fully enforced when DEBUG_MUTEXES is - * enabled. Furthermore, besides enforcing the above rules, the mutex - * debugging code also implements a number of additional features - * that make lock debugging easier and faster: - * - * - uses symbolic names of mutexes, whenever they are printed in debug output - * - point-of-acquire tracking, symbolic lookup of function names - * - list of all locks held in the system, printout of them - * - owner tracking - * - detects self-recursing locks and prints out all relevant info - * - detects multi-task circular deadlocks and prints out all affected - * locks and tasks (and only those tasks) - */ -struct mutex { - atomic_long_t owner; - raw_spinlock_t wait_lock; -#ifdef CONFIG_MUTEX_SPIN_ON_OWNER - struct optimistic_spin_queue osq; /* Spinner MCS lock */ -#endif - struct list_head wait_list; -#ifdef CONFIG_DEBUG_MUTEXES - void *magic; -#endif -#ifdef CONFIG_DEBUG_LOCK_ALLOC - struct lockdep_map dep_map; -#endif -}; - #ifdef CONFIG_DEBUG_MUTEXES #define __DEBUG_MUTEX_INITIALIZER(lockname) \ @@ -131,14 +89,6 @@ extern bool mutex_is_locked(struct mutex *lock); /* * Preempt-RT variant based on rtmutexes. */ -#include - -struct mutex { - struct rt_mutex_base rtmutex; -#ifdef CONFIG_DEBUG_LOCK_ALLOC - struct lockdep_map dep_map; -#endif -}; #define __MUTEX_INITIALIZER(mutexname) \ { \ diff --git a/include/linux/mutex_types.h b/include/linux/mutex_types.h new file mode 100644 index 000000000000..fdf7f515fde8 --- /dev/null +++ b/include/linux/mutex_types.h @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_MUTEX_TYPES_H +#define __LINUX_MUTEX_TYPES_H + +#include +#include +#include +#include +#include + +#ifndef CONFIG_PREEMPT_RT + +/* + * Simple, straightforward mutexes with strict semantics: + * + * - only one task can hold the mutex at a time + * - only the owner can unlock the mutex + * - multiple unlocks are not permitted + * - recursive locking is not permitted + * - a mutex object must be initialized via the API + * - a mutex object must not be initialized via memset or copying + * - task may not exit with mutex held + * - memory areas where held locks reside must not be freed + * - held mutexes must not be reinitialized + * - mutexes may not be used in hardware or software interrupt + * contexts such as tasklets and timers + * + * These semantics are fully enforced when DEBUG_MUTEXES is + * enabled. Furthermore, besides enforcing the above rules, the mutex + * debugging code also implements a number of additional features + * that make lock debugging easier and faster: + * + * - uses symbolic names of mutexes, whenever they are printed in debug output + * - point-of-acquire tracking, symbolic lookup of function names + * - list of all locks held in the system, printout of them + * - owner tracking + * - detects self-recursing locks and prints out all relevant info + * - detects multi-task circular deadlocks and prints out all affected + * locks and tasks (and only those tasks) + */ +struct mutex { + atomic_long_t owner; + raw_spinlock_t wait_lock; +#ifdef CONFIG_MUTEX_SPIN_ON_OWNER + struct optimistic_spin_queue osq; /* Spinner MCS lock */ +#endif + struct list_head wait_list; +#ifdef CONFIG_DEBUG_MUTEXES + void *magic; +#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC + struct lockdep_map dep_map; +#endif +}; + +#else /* !CONFIG_PREEMPT_RT */ +/* + * Preempt-RT variant based on rtmutexes. + */ +#include + +struct mutex { + struct rt_mutex_base rtmutex; +#ifdef CONFIG_DEBUG_LOCK_ALLOC + struct lockdep_map dep_map; +#endif +}; + +#endif /* CONFIG_PREEMPT_RT */ + +#endif /* __LINUX_MUTEX_TYPES_H */ diff --git a/include/linux/sched.h b/include/linux/sched.h index 3762809652da..e8892789969b 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include -- 2.43.0