Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp260621rdb; Tue, 19 Dec 2023 16:20:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcV7ZiXiOkocX/QdbeNQjW8kg5bD1fo2SK6zAtBTaVPRWYGGrWVFtQFyGHaw3hjmysYnIP X-Received: by 2002:a05:6a00:10d3:b0:68f:d1a7:1a3a with SMTP id d19-20020a056a0010d300b0068fd1a71a3amr20867783pfu.8.1703031654190; Tue, 19 Dec 2023 16:20:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703031654; cv=none; d=google.com; s=arc-20160816; b=vhsLcK2jT1sBQ8B8GW1D+/aqrY50bsJgqedNvEH7UZMj/Y3jGZk0EysBBNL/i6M8Se OMf8JTLGYbORXH/K9X9pR59bjgpG8BpDaVMl1nCM/Vcru/6MSuX1b1JdSL83o2RPGmKv FyEjSgI3VvHwf70zBgNOxtAKg7Eu3Q/mnZbOxfo+iXkmwvksfB13PUtC9DTFhhN73f8q B84yFIkH6bMOnpV1V0NzoQiQMX8Qgm/xPWmKNF3tnPbScX9Xxk6f0zjo7GsxEzYPAj/O xdv1J/R0loIOd/reIuSsYA1FOQ5hklhzhLYlsKc9ezaILFR+fau4Cg0upvcJy2MCL/hl QkTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=0tW3dssmUv9V5AQDOtaG+xQeN0OKPPQSNCn+KMrenwQ=; fh=CAq+MFEKKjJy5jyw+pqNOeDGlDhGAe1gUm7slWeEdnw=; b=jxHjoKEcZT7X2Qq5YGDBXE0UDj87VcXfTXTk2BRmBhPopHaY1t59EgqaTzbUd2YUwJ pu9ZZc+JkZAbxMjBTOCtR3PHu6aB8FnX2+CPi2NHfw0DaLTpxfx7nSQkC8XDcsca2ngx jNMiG0nej20W8nNQNIAgYWc2Uyd3eDo1H5xhpRIMMsI94BHOoKRvJK2J0/ACvAhl462o RbMcUCak1BO76MAUE2ijz+wPuTbyIrQ7/llTjE7XGM+ZF/IN4XZPbC0WYZS80eqLZDZs 9qosKY3Vg7XoXO+XxU0ul2jp/eHP3Yfzb4v4U8Pw2Af73wTuCffxtJ/yRYgIzpANUkoM hWwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Bc8+gGXX; spf=pass (google.com: domain of linux-kernel+bounces-6138-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6138-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id i7-20020a625407000000b006d275095934si8506520pfb.310.2023.12.19.16.20.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 16:20:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6138-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Bc8+gGXX; spf=pass (google.com: domain of linux-kernel+bounces-6138-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6138-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id BB761B256AC for ; Wed, 20 Dec 2023 00:20:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 447788F6D; Wed, 20 Dec 2023 00:19:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Bc8+gGXX" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECE6179D8 for ; Wed, 20 Dec 2023 00:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-6d7e5d286a1so158658b3a.1 for ; Tue, 19 Dec 2023 16:19:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1703031550; x=1703636350; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0tW3dssmUv9V5AQDOtaG+xQeN0OKPPQSNCn+KMrenwQ=; b=Bc8+gGXXJakE+E486djSQr59dDUPjbxX6xS+h58sq/bxJdc+OX9rraj1GdRcdzQowZ vC8WAlXRFlUGlUu4dZs9gGFPB+G1aEj6tasyM9Kq7/y+R6ImTxppDbZo/faw2FN08fo/ wa6jlMzSeT4WwZi3Dho5/1H1AIlgp1kaszq19yRrDV89LJxRa8cK0QCwwLQDaqkowsTX MI244NRSbA0Zmyywt//5/1IlGUQYF7tiB7KPB2MluFrdqYoJ+OStecMLomJiyDQx4m7A aSUGn50twE59RIrViza0aNEP1zZxkwDLbzjcS3j6iJN5qYol1K1crg3URBMTVgqHYNhT Ni9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703031550; x=1703636350; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0tW3dssmUv9V5AQDOtaG+xQeN0OKPPQSNCn+KMrenwQ=; b=TmDBhhY+e8iC3LPKmzmzUTS9/Awnyys9LiVk0T7cnjJ6L4XawS/5XlbEZhAZDXZ5jt GtGPkqjjRYAYJMQSMBA7l/hcggmQbUOsLrBzpH7zeTH/eXe6G7ztfE8VmOJWoV2WE0aR Z+qwjksvfOA8HW5olNvlYCiSR73JEuvnluAGtBWCsnS02slpQVdA0biMeRh7ksZJH8eP 3VTFaeCU1ODdhDTu98gLYcMGRvKoo3FYUQoKfTd2FZGP7P+3cMxvBkKZHOvOrop+rGOZ 6lKXRPcLSEwUuvLkscAdthQJEZ4l7/b5QOnX5fTOEEYoKOC39qRL/NzywDgnwVG6kXHx 8OLg== X-Gm-Message-State: AOJu0Yyd1yyfzZgr2AIf4yp+WB6u/jGvcsJfxaZ27zW+iPbJS6vzo2Vt BatcZ9iV/WtXUag+Zv5Ue151Ak6Zp7VSZr2g37rP9nI4AEmZZ8esRZpkmCAVv3vV8YpYmWZFIvl dYApJOLnGBM1qnLyGYUxleu/0i8/JhwDzfn3cDMugbRPNRacWpViG00eArI9pby5VZ6x4Y1Q= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:6a00:2d07:b0:6d9:39eb:dfb4 with SMTP id fa7-20020a056a002d0700b006d939ebdfb4mr115523pfb.3.1703031549341; Tue, 19 Dec 2023 16:19:09 -0800 (PST) Date: Tue, 19 Dec 2023 16:18:15 -0800 In-Reply-To: <20231220001856.3710363-1-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231220001856.3710363-1-jstultz@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231220001856.3710363-5-jstultz@google.com> Subject: [PATCH v7 04/23] locking/mutex: Expose __mutex_owner() From: John Stultz To: LKML Cc: Juri Lelli , Joel Fernandes , Qais Yousef , Ingo Molnar , Peter Zijlstra , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , Ben Segall , Zimuzo Ezeozue , Youssef Esmat , Mel Gorman , Daniel Bristot de Oliveira , Will Deacon , Waiman Long , Boqun Feng , "Paul E. McKenney" , Metin Kaya , Xuewen Yan , K Prateek Nayak , Thomas Gleixner , kernel-team@android.com, Valentin Schneider , "Connor O'Brien" , John Stultz Content-Type: text/plain; charset="UTF-8" From: Juri Lelli Implementing proxy execution requires that scheduler code be able to identify the current owner of a mutex. Expose __mutex_owner() for this purpose (alone!). Cc: Joel Fernandes Cc: Qais Yousef Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Valentin Schneider Cc: Steven Rostedt Cc: Ben Segall Cc: Zimuzo Ezeozue Cc: Youssef Esmat Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E. McKenney" Cc: Metin Kaya Cc: Xuewen Yan Cc: K Prateek Nayak Cc: Thomas Gleixner Cc: kernel-team@android.com Signed-off-by: Juri Lelli [Removed the EXPORT_SYMBOL] Signed-off-by: Valentin Schneider Signed-off-by: Connor O'Brien [jstultz: Reworked per Peter's suggestions] Signed-off-by: John Stultz --- v4: * Move __mutex_owner() to kernel/locking/mutex.h instead of adding a new globally available accessor function to keep the exposure of this low, along with keeping it an inline function, as suggested by PeterZ --- kernel/locking/mutex.c | 25 ------------------------- kernel/locking/mutex.h | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 73d98dd23eec..543774506fdb 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -56,31 +56,6 @@ __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key) } EXPORT_SYMBOL(__mutex_init); -/* - * @owner: contains: 'struct task_struct *' to the current lock owner, - * NULL means not owned. Since task_struct pointers are aligned at - * at least L1_CACHE_BYTES, we have low bits to store extra state. - * - * Bit0 indicates a non-empty waiter list; unlock must issue a wakeup. - * Bit1 indicates unlock needs to hand the lock to the top-waiter - * Bit2 indicates handoff has been done and we're waiting for pickup. - */ -#define MUTEX_FLAG_WAITERS 0x01 -#define MUTEX_FLAG_HANDOFF 0x02 -#define MUTEX_FLAG_PICKUP 0x04 - -#define MUTEX_FLAGS 0x07 - -/* - * Internal helper function; C doesn't allow us to hide it :/ - * - * DO NOT USE (outside of mutex code). - */ -static inline struct task_struct *__mutex_owner(struct mutex *lock) -{ - return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS); -} - static inline struct task_struct *__owner_task(unsigned long owner) { return (struct task_struct *)(owner & ~MUTEX_FLAGS); diff --git a/kernel/locking/mutex.h b/kernel/locking/mutex.h index 0b2a79c4013b..1c7d3d32def8 100644 --- a/kernel/locking/mutex.h +++ b/kernel/locking/mutex.h @@ -20,6 +20,31 @@ struct mutex_waiter { #endif }; +/* + * @owner: contains: 'struct task_struct *' to the current lock owner, + * NULL means not owned. Since task_struct pointers are aligned at + * at least L1_CACHE_BYTES, we have low bits to store extra state. + * + * Bit0 indicates a non-empty waiter list; unlock must issue a wakeup. + * Bit1 indicates unlock needs to hand the lock to the top-waiter + * Bit2 indicates handoff has been done and we're waiting for pickup. + */ +#define MUTEX_FLAG_WAITERS 0x01 +#define MUTEX_FLAG_HANDOFF 0x02 +#define MUTEX_FLAG_PICKUP 0x04 + +#define MUTEX_FLAGS 0x07 + +/* + * Internal helper function; C doesn't allow us to hide it :/ + * + * DO NOT USE (outside of mutex & scheduler code). + */ +static inline struct task_struct *__mutex_owner(struct mutex *lock) +{ + return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS); +} + #ifdef CONFIG_DEBUG_MUTEXES extern void debug_mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter); -- 2.43.0.472.g3155946c3a-goog