From nobody Sun Feb 8 07:25:31 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B934C7EE2C for ; Thu, 1 Jun 2023 05:59:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231768AbjFAF7g (ORCPT ); Thu, 1 Jun 2023 01:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231667AbjFAF7Y (ORCPT ); Thu, 1 Jun 2023 01:59:24 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C658C18D for ; Wed, 31 May 2023 22:59:07 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-65026629c1eso57925b3a.0 for ; Wed, 31 May 2023 22:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685599147; x=1688191147; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=luB7F5gyV9IZ2t1qXPs5v7WDUVowNcPRs+IYymLmMxo=; b=QiR19i8UT0lRAkiXRHp/mtsGysuaM5y0+5Li2juqrCj7QwZFqTGE0tSLYCC/CH2ZTf 0BQ13MyrxFE1ZjENkdwczkQgmxgU8paPsfNvIeT5Z4yLbMpF8m0tbk1zXXgK3nPt+6/M 3HVpz3U8ONs4a9eA5wu+5ckQanQ/QsYAUX9RfQNZfZm/4qvXcBZMlohVif/DbeORT/1x 4zSmw161pXVGJgmAMQsEbNrBBj+HtaAmoea6XGvI88x2VU7KO1SCvYEtF39qzq3BrafH QpEd/FONUUUp9pXDcE1d+odQZ4JTJtT9a5VTKOqCWluLZz40eX+YTV+Z3Ig6YOipIxm6 eJzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685599147; x=1688191147; 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=luB7F5gyV9IZ2t1qXPs5v7WDUVowNcPRs+IYymLmMxo=; b=eoYr6ZFiCFefppcFBFZlKPItM95QtmMIpeSRorCQhDjluiLMQxhn0shjIZgp4sMGcq ag0gHAxB5McX0o99ikoUxoCSq9cqdSjDQu89Y4FJNsdjr07PlY14RTuAyUQOMbTSgeS0 S5IIMVBu2hVm62iu+W5Om286ERIxTA7+AocnnTqDZSyzXuUf5IGSyKn4Y7TUyPKQ/4d+ Nl9U01beDI+eT02ETp+XqZLEKFnS3bghL1Y/5Blzo7i1zGmidYfx44osMlIJlvOQJ/f9 EKNz6BbTLxN9IoRnFNldLQoDwhiS+pVWPSVUaiRMDhdzpKSOdTKxkdDHuxQdvBf9/khm 56lw== X-Gm-Message-State: AC+VfDxB2Djr2VnLHQ4MDzBi/ql7Qriyh+co1930kEJlf15lE6XM1DsV LQmk1QWdwSSeKUKvHzLqBfw/nHloPt8dxelRktL2Ik3+f93OHGvKrhbKSB53Ho5CdjvoC/hHb7A X3O8L3EgIRD+JlsQkweV6efVD+yVRUa3bKcJDPlNMoerOMYwg0wD5F/h9SkH+8TpaN/UbK0M= X-Google-Smtp-Source: ACHHUZ61YsxzFzSxcLzENguWBQp0dZzIVWTE0JbN+5zJJ9MrISL/JuQrZx+VuQGk4OEWb4hVbUjg+xFalI4D X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a63:914b:0:b0:51b:3c11:fb17 with SMTP id l72-20020a63914b000000b0051b3c11fb17mr1594380pge.12.1685599146627; Wed, 31 May 2023 22:59:06 -0700 (PDT) Date: Thu, 1 Jun 2023 05:58:09 +0000 In-Reply-To: <20230601055846.2349566-1-jstultz@google.com> Mime-Version: 1.0 References: <20230601055846.2349566-1-jstultz@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230601055846.2349566-7-jstultz@google.com> Subject: [PATCH v4 06/13] 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" , kernel-team@android.com, Valentin Schneider , "Connor O'Brien" , John Stultz Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable 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: 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 ac3d2e350fac..8c9f9dffe473 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -56,31 +56,6 @@ __mutex_init(struct mutex *lock, const char *name, struc= t lock_class_key *key) } EXPORT_SYMBOL(__mutex_init); =20 -/* - * @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_FLA= GS); -} - 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 }; =20 +/* + * @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_FLA= GS); +} + #ifdef CONFIG_DEBUG_MUTEXES extern void debug_mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter); --=20 2.41.0.rc0.172.g3f132b7071-goog