Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1267756rdb; Fri, 9 Feb 2024 16:24:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUtMSKx+6Z3c+FgLdZ790L0G+p1GyUtyGEu34beXrU1M+SOJDY3zLKiqJSQhSQPvwjSKIUKWhNabIgvkBGasM1SncOUZJxp/vIi6r1/rQ== X-Google-Smtp-Source: AGHT+IG7oyy1EvMBkOQoRV+1Wolv0xkxw5jhbchvjYvQ4W8f+BIaVqSjmJdbijuELgCtAZUzh1lW X-Received: by 2002:a05:620a:a18:b0:785:8b5f:dcbf with SMTP id i24-20020a05620a0a1800b007858b5fdcbfmr662542qka.53.1707524667338; Fri, 09 Feb 2024 16:24:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707524667; cv=pass; d=google.com; s=arc-20160816; b=mchOt64Fd+Uos4Ws202EaxPcpVB29aYIOu6doc76/S+AKetNYmZap5sZCCmX3hD6/d z9txyEEhye8kypV71kJidFLMYWulZegftFdA4PnG4Arc4Ol7iQNjFC2a/PnPPvqG6hlx zH59CDwT/NEx5ONYnyKx7a4MgQL4/+H221+AgYXJiNWGtjOcy40FFJ3R3IgIvyibZs3M a/frJL1LMNUdavZfBBAwEbvGXktCfdbM7JJ5g9GNrtCLNFdbSTH8laBxewvUzioikh6b Slv8LBEcLTZTAlETtuiN8f+RlnJ8jfM5Hoo5YvxBSz/hpLbXrISklsTENBE1LhxSzz0s zCnQ== ARC-Message-Signature: i=2; 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=z669vXCZHTlic+csHXc7vqHCpJ4DtGvq/gBFclWIjzM=; fh=EAB77puP5QUfuOSxEACfAASVUxkF4ZBu3g3mUJDp+4k=; b=VCy1W4LFRQekq54o5D18+2ywMpsH3ydTdf7amRgxFt+jywtYeN1oXIV3fbi8RwQZZi L6StgjI6G/zV8eCh1olzMopNO7mspNf1PVnP9DbYsI40bVsb9dP7r6+CxlyS6Op0Ja1Y N1k9M6Cq7Lw7bLmN/A/95zAkRA2tiATdRocxbCEy8kd7ITlv11F9BklBLC7eoDghqUTR sPJNB7Cy6Y0CTvwM0uOuvoQJIeLF0rSE0ANeHXwRUI/v9vZLa2Q/HDQOrZGCJmZsQA2g MX2l0aU+H6XIoV+JOmwEAz30BQFY6aaBJ+xU2hE6rfCmNR0syRnaJg391GyaCAWNz6dJ ofmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QnkTUmOt; arc=pass (i=1 spf=pass spfdomain=flex--jstultz.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-60181-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60181-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCV6Or0F4BefbfXNWYdvxyFQhzcwQkGEmtIO45mMWmB1Cxn5t0Tgo7xnWWEXKPS7B3hRGJ+p8y1gxWIJ4oWpBpsJBJyIq/qNUXwkG1lU/A== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e29-20020a05620a209d00b00785a436c916si659329qka.59.2024.02.09.16.24.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 16:24:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60181-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=@google.com header.s=20230601 header.b=QnkTUmOt; arc=pass (i=1 spf=pass spfdomain=flex--jstultz.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-60181-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60181-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0CDB91C22009 for ; Sat, 10 Feb 2024 00:24:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 669314A35; Sat, 10 Feb 2024 00:23:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QnkTUmOt" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 B44CA23BD for ; Sat, 10 Feb 2024 00:23:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707524624; cv=none; b=TYrb1153gmPO36ni2eCu7W+OwG5LFsMCvTPKi0qF9j2tb2etF5wVAOK8KpBVqoJOL9VieuVOo9o5aOVmA7NL8IX6Fc0tDJkBy6GY8pPGN68Ph3C8nrq6r3yjZ4MHwpK2UYI+Eofz7txUO9S9ehtbHVJ2MgDUqkVuT0SiSbPgdP8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707524624; c=relaxed/simple; bh=3DJbBrx4KmSxVmHiBdNSoYKl3Bct4nREpl0U7p4hoZw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gPNBjkNQ0ULE1l1bjy8bnZGzbOMDpvo4qXNQaAO+KslB+146bvZL4N/TB6BuKpVPggri5sbqo67H8B0FrIUlucYdopij36hb+rhjh1ZTxZNQnQD1qElmgM2WNUetqiHb/sTTVLxvBrtldYcpsIGn3wWNl0w9kYWAx+7d/ZkwBhI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QnkTUmOt; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b26783b4so2250960276.0 for ; Fri, 09 Feb 2024 16:23:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707524621; x=1708129421; 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=z669vXCZHTlic+csHXc7vqHCpJ4DtGvq/gBFclWIjzM=; b=QnkTUmOtwTGF34K8gZL0Pp6mIiHALad11qn6ji/utJJaSopYNHi8JHiVg9XihGofw5 RjY/imT3L4E0MTxe3ZdqKPsSB+u6lk9DVwPiCAA4f9bmkeHMoHtW+AWWfaHQl9FMxW5X LVr1y1R8EGlMdR8g1PJRdOeiJvF+G4mHUCcu6EFBL4a4cAeUSuZvJnJU6Cm58oxDHcSf 74xPIpM4VNzzLo3fxVPkgvMn0fXDjxLolq0cqKzsuOgUh+I0mm+K8sgO5s7OqoxbaKnv 2mMNUvYR70pGw05EWXCLgv6Gpz/CqW5HF8rQEdJTLr8gztSa575I11VtbGqI8CszGbiM wvTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707524621; x=1708129421; 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=z669vXCZHTlic+csHXc7vqHCpJ4DtGvq/gBFclWIjzM=; b=PvS5WAn9sH+/0jqofkeauVsoQxT7C7i4ZPCF5qv+RTt6KHzAYU9nEvIhKh80AwcUZq 5p4WHyPAcOOYnTpDxa8F2mP/3iyxF4iICYkfB5k90rlApEi2EQTkzEnuWgHSa9abLSZV Ciugr4CmT49mKV6pQTeZcVVLpvlIYIVhh5mkhv6hfIAqNrJtkpygy1GJJFjBAgp5OC/z CUBZcVPEev4jya1ACCJoCyF7nMPk+tSzmcyt+e4ndj7ciqulYWIPim89vvBmHag9A889 34Jy6oEZiJCz4FFSgHGttI3QhJ/qm5lHLJYX0VCXM6jAJLEq/hbPEdrFvYuPNaE034pC SmqA== X-Gm-Message-State: AOJu0Yyp+3d1U1AFt9UpVlVidOTTIShktOPSS4UC6+zDsQ2GZd7dDJO0 FkTs7k3MZ/JGcn0RmPxD+q7fwBUpMlyVzePqgDMTQ1gEcy9V+zyee7Wjv/ZjZtymnLvov7psSMA uydFedUxonCTZ3GP/8EOdkcJ7FVH0s2s6Vw6LDtWk+JPVGItlPZWP4wr3jEbj5YSdQrbWVa1NdL 0G3fMiLztLIQ+UieIXAqDrynPL4NFowGaBhlyyyLbDZ59h X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:6902:72e:b0:dc6:ee66:da6b with SMTP id l14-20020a056902072e00b00dc6ee66da6bmr20067ybt.7.1707524620974; Fri, 09 Feb 2024 16:23:40 -0800 (PST) Date: Fri, 9 Feb 2024 16:23:12 -0800 In-Reply-To: <20240210002328.4126422-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: <20240210002328.4126422-1-jstultz@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240210002328.4126422-4-jstultz@google.com> Subject: [PATCH v8 3/7] 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 7de72c610c65..5741641be914 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.687.g38aa6559b0-goog