From nobody Wed Dec 31 08:37:29 2025 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 81C4DC4167D for ; Mon, 6 Nov 2023 19:36:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232995AbjKFTgD (ORCPT ); Mon, 6 Nov 2023 14:36:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232891AbjKFTfy (ORCPT ); Mon, 6 Nov 2023 14:35:54 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59BA3D77 for ; Mon, 6 Nov 2023 11:35:45 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a828bdcfbaso67678747b3.2 for ; Mon, 06 Nov 2023 11:35:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699299344; x=1699904144; 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=rmX5Q7SFKWcrt3zpGHMTaKC5ErTWRpzWqGhGcyC8r+o=; b=X2CBGIjDJhspBsEYJlKbs03S7dCvyj2MKKbM3wO1ZNggOgV/fuHlyCLDSHvv+klLPp n8zQADn4BG/zn+fkLtXmcx9mPGucrPkznPw1SQ3kUWl8gGzDd7xA0tawdKcTR2Lknpyv s6mFrL1YJjG7XCZsvmsZojhvGwwj23IjnmeBwyxCpAvn0oVkfoToXF7AzsxDIzjIXetv hC7Uu4eGy8T+BVbZu7TqC4GHQmJetYmESeE3OEFrcQSuZ+zYmSGtOcCDdpMLMNRhMDrz e4HO7ikF0nvtr2CNBpdRXxqhSnURKBnQtPj21lKGuWY0uhdo5UFmCU2tNYYESXmISZs2 /22A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699299344; x=1699904144; 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=rmX5Q7SFKWcrt3zpGHMTaKC5ErTWRpzWqGhGcyC8r+o=; b=CHB06x3EA87kq7Td6lgajSui0P0NhF2VKeNpwznH9zzLdkelVziNpTUuvwZH3eLL4o yRyC9kqpXRQiymou99ZkuZ8tMxPb2BK0m4DyeD3f+aLKkcNFk6SXHPDluhZV2NrbxRfD xMU+dH1yDPgQxFWhXa/cb6sA88FdtO/xP3roBbG7wZtP7Yx7mvkV6X9kA3ax3dN804Bx 5ShSnM2JeT2rQKFiuqFZhJLb315ZQKhtzKuXhgufHIQiwjb4ZiuKK8BkFE5sJprQuLBI 5DZgrFng9IotJL66guzllKfd+VKtqVh5iOGxuMQTVJBPKHIr//UZ0UN38u6ORUVKPR5k kLUA== X-Gm-Message-State: AOJu0YwnTWFejn6ANjdOLqYQWRvdObwsSohJK16Vn74uC3MiDwMpnHUG kmlKtQH3wg7y9OkSl5eU2x/A63qQMV5GKLms/XdSsG174eW8ZRRUBzHHwP9JseDrZ2CMDRJJKPw O/Ej8U3Eq6GeqIbGRpzVKMPZok9h8hy3mgTzXxKchYQ9PBZlJxTO3d4cY/TtIQpNTxXvdizc= X-Google-Smtp-Source: AGHT+IE0cSl2KladoOk9DsoTcmrBwfiWeSwyIQHH3cn8WIQmivONyLaTUw7IkYkif6oZm157DDc/0oAIKYnn X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a0d:df4f:0:b0:5a7:af47:9dda with SMTP id i76-20020a0ddf4f000000b005a7af479ddamr231392ywe.9.1699299344416; Mon, 06 Nov 2023 11:35:44 -0800 (PST) Date: Mon, 6 Nov 2023 19:34:47 +0000 In-Reply-To: <20231106193524.866104-1-jstultz@google.com> Mime-Version: 1.0 References: <20231106193524.866104-1-jstultz@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231106193524.866104-5-jstultz@google.com> Subject: [PATCH v6 04/20] 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 4c63a197f6fe..2c5d1a9cf767 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.42.0.869.gea05f2083d-goog