From mboxrd@z Thu Jan 1 00:00:00 1970 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 F3837EE49B0 for ; Sat, 19 Aug 2023 06:18:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245437AbjHSGKL (ORCPT ); Sat, 19 Aug 2023 02:10:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245233AbjHSGJg (ORCPT ); Sat, 19 Aug 2023 02:09:36 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 164EC420E for ; Fri, 18 Aug 2023 23:09:35 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-689345528a6so2279689b3a.3 for ; Fri, 18 Aug 2023 23:09:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692425374; x=1693030174; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NvTghmzuV8RLCx/77uRR+YvfNpJgUdm8YXL2tJOnhW0=; b=Clwg2GNbQa+uguVlKHvVGRDH20BuvhUUIr6gzt77zrxfYPTheI96NA3Jc4e4/xptwz K+MDWqZEb9VK3wb3XYCR94zXEwtfAa92VzrzRfhj70TdIpbNXCIsl9BDjIWvqZqmJJwp A0n3sPu/8aDsYYpQMS5XUeHMylHhIEicZ8PW8oZ3TH94q5mVch9avR6MIpg5Owdys+HE FmjzdflX+8BcoYsuYDkN5rv+mgtZ5ZggplGviq5T1DtICivu3pTtEYWUY1cu2gpI/aRg hLSpMcqXdu18/ohIF+Z3JpdF1bJvLCiKN1U2/MtgWIWemUVe45qMjW/lCSDs0C6C5ZnA Q4Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692425374; x=1693030174; 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=NvTghmzuV8RLCx/77uRR+YvfNpJgUdm8YXL2tJOnhW0=; b=aZ+mFAKoMIzNkR/tMsRNr/p1KI78vC/kaIE4m7sD3Ku52savPPfLW1U8uAiVEUayjm 8VhZ0VNtGO6TyMenxLcRIZNy6c4hOfoGrkL13116jM1yNVy4lO17EQeS+FCMXy/lYUx/ FUl8uI0vYrINJKtDbNpZXETD3dS5Lnroys8pl7O70anWKScKkM0jiPCAFG7WyozeCAnE 3jEmd6G8Ld6VFBqZMgFmVHfhlAreftGRTmfJRWqeLnuC6QxvCwClXRs0R28UV57hSooy TRGgU30nEuIGaQvw4Wo1MZSNj0NjL+WVcL0CRoUfX4vCwPtt/A72eFAnXgfWQxoiUwjs MQ5A== X-Gm-Message-State: AOJu0YyD/5WaVp49QYS5XwG8Y5wRHglni22cZQtrlGspJrmeG23PVNcH WM2hxZfPqJ7Brcjab2onPb4/6uoZ8lhB6lhi2qmzMhX17QtmNZzBmvnGvVliJ7F++cofiiqiTBQ FhBkwRZ4UEP+2/3q5TSU2JRNbgEIXFtCl+NgBTCmWiVNAIfQC3eGWBTL3EBRH/gIkqjuxxs4= X-Google-Smtp-Source: AGHT+IEhgYdrQBANoeJ4ZDsew3Qm4wengxuMU0r8CHoZLwaxgDsLZeVkmM6Bv1ILEkQ/14l44NwVjCbhw3Ds X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:6a00:148d:b0:688:7820:af92 with SMTP id v13-20020a056a00148d00b006887820af92mr735210pfu.0.1692425374400; Fri, 18 Aug 2023 23:09:34 -0700 (PDT) Date: Sat, 19 Aug 2023 06:08:38 +0000 In-Reply-To: <20230819060915.3001568-1-jstultz@google.com> Mime-Version: 1.0 References: <20230819060915.3001568-1-jstultz@google.com> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog Message-ID: <20230819060915.3001568-5-jstultz@google.com> Subject: [PATCH v5 04/19] 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ef56556d6ab9..67ff08beebd6 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.42.0.rc1.204.g551eb34607-goog