Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp164328rbb; Fri, 23 Feb 2024 16:12:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUbZ5mBe/d28+EWG3o5oEL7sD3b/pKMM0XxB/s9kmTFenvAr3WxUlVHP5wnOOZzgCMQXnY4lcbAtKiAItELADmnyx0U8RUcUT0DjTAlJg== X-Google-Smtp-Source: AGHT+IG9Wphik8LCyt329WE2V3ztRGbNE73Pmob/lNkXHukteZED1vX3tSsssYIke0mCGh1uNcYt X-Received: by 2002:a19:8c1b:0:b0:512:ea8d:f2f9 with SMTP id o27-20020a198c1b000000b00512ea8df2f9mr724111lfd.14.1708733561507; Fri, 23 Feb 2024 16:12:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708733561; cv=pass; d=google.com; s=arc-20160816; b=IsclHvAAf81E2OVxMBmYcyS1YieJIGDyqvkKYm6a11G4/LmBusTQJK/EOHEC/LVsZI g6UZAMM7Z9KPRFYhwD8sE9BYDy1NbK/cTBb3FANjrdPjOe3UVNhLe0xA3V49nmE2reuE je2co+iS5mCWeTq/s3G2n00u9CKE7kr3Q4dK+SYHpIZ5suWeuhxZrxynQnIrOMKeaSuq 8jtZ7FsADzNiA2Esib3p0XKvSS+gnXzjW9RK2hAdXLQ6ef3SV6LWNVEFWL/j1wFf1hlS 7qNWVlPsMyRjhnhdnoavX+XzWvhXfaPbn8C3OxGo/paxw1BRt0ksqMqw2hR3iGLnfqOF TzJg== 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=11JYsWA+tSpUAfCtvYdWCKKR13hGRqHQrhgIeQOqs68=; fh=CAq+MFEKKjJy5jyw+pqNOeDGlDhGAe1gUm7slWeEdnw=; b=vTcZf1g0KJ9Ci4QeLeXDiKWB7aD8OSiFpQGhN4qyZgu+sHwJlc9u+cOcrC/QGOfR0O XjuD8Bvgvme2MqRpFTz1ZLkxw+cnBf7P2O7nr89afJxGZI1JCl7/VYDzI5DfRZQQvpPi 1/uh0IT5bZ4gXOF3YAJw8n3SrGhB+hXJ3gyjmSmN1L7sFFuZFzv5KZW6bNR/OvP9D5N0 6WdffG0ieVZ0Vn9Ui6Tj72N0q2nqzejWCsUsoRzNpc6tYcLyLU8g1vhOfIHsBtWuXHLW vkTUV427A8mb3V2k4wnxKI5sdeqk9qWkVtUL8bTpLcvO1bI+chSL804MroKqFx+lMn1/ FWoQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=o5GKo3Kn; 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-79346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79346-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f23-20020a170906139700b00a3e7b030235si58669ejc.502.2024.02.23.16.12.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 16:12:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=o5GKo3Kn; 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-79346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79346-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1824D1F225C1 for ; Sat, 24 Feb 2024 00:12:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5636B3FEF; Sat, 24 Feb 2024 00:12:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="o5GKo3Kn" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 93F5E15D1 for ; Sat, 24 Feb 2024 00:12:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708733530; cv=none; b=J4h64J4i40ceD7lG7Bv7DHq2J/KezQ3RBNdY8VX3GE1yTVf4aWdSI80Yw6HGZDtXTLOrSzOGPK8O50i/K5DB70BZD+t0okSPZLBaOnNdTTZmPGlB34epNFk2lCriMvdje76CwGyaCVbVLXJZeNt1EhT9NZ9HVt7R5SFRQGVJnDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708733530; c=relaxed/simple; bh=/MvRuZlBTMH7KRo3ZudNtaXjF43JnT01+5/C5gO6rww=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=agTv9Ir4zCHZ3IX/jrhsIQ4xvNdvtwHcL3po4oT+lblD+YeUkpGzSSLu8N0CIbWKDCB1gQrewO9DBH+BVz2JRd4GEbpmH7I35QMDB4AgqIY2UdrVW+qL08wuCMhPH4FKtk7//QhTO93hxPQGAp1224klhaFpKDN97YFMC7nPcSA= 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=o5GKo3Kn; arc=none smtp.client-ip=209.85.219.202 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-f202.google.com with SMTP id 3f1490d57ef6-dc6b2682870so1418633276.0 for ; Fri, 23 Feb 2024 16:12:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708733527; x=1709338327; 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=11JYsWA+tSpUAfCtvYdWCKKR13hGRqHQrhgIeQOqs68=; b=o5GKo3KnZmd4oulgoa+pgjdraWMGFGmnRQJKlU9bWKx3sy63NOQr4GIbobA5WhXJhI Koq6L/GX8cAXLZOKA1chOECue+3k7phXYBZH2Y7UBOWAXqV7rbkQbUCRTx9Zjwqv4nqu 6lZZeX+PcpwQXiwjRxjAcn6Th+Q2UJ9lBNdCK67YYEn8RMymu2IHzWqxtLVDsSFN1SVi H9yN6IK4iAI3QtIEkYwAJ5QliWIcmE/OL2BWwVFW257O05xd0NehRFn1iA9K+QclWih1 sBnqxVrL95NctFzVIGqPs7ewhy5tcebGnd9gWtT2boQnZSuDmyukODwEuHewxOkk0Ztn bO2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708733527; x=1709338327; 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=11JYsWA+tSpUAfCtvYdWCKKR13hGRqHQrhgIeQOqs68=; b=qGgEc9dpP567Zu5tRBoF69LGFXa6j/g7k6Vm8GIa73kURzag/zuPyt1NLmK/pWE/4K oX7c7Fwpt/dne5uUsIgjYlSoAiO89ox4Fh7FC8KS7BD1rWRZ6Br1/dFbowR4VTd1XUYs in7tTGlO058XahMddIAJJNxAUYljzodlAML72FK57glOTU2jM2vbHpemhe/tXsPBeXbC hj1vtk4yyxmFFKM+h8nK6X2UCzz892kGW9IGFlSkKl0+9MmFcUEyCFMY0P7WyT6ACq2U tvyxuYcwO4elZWxTc+hK3nUtm9JonwG4TsIP1hZmZO31uT39+9jB/oaNXtZgsLaJb/ta qcZQ== X-Gm-Message-State: AOJu0Yyk+0/wHx3cnrzYinQSRhJuuaj1iIapwoVHNtVbs6VNSeT2VSXP 40136rQg3bZ3bipnyzp+6TPDW0On74NPVmxhtG56O0NXrzky7aOKp/svsn/eLjDzIWFtSVSfHLE ZP5gfMQnkttqdbBU0ErAYtdl/Vm4OhuukiA1BZCBJ1pZJleOK8RecVKHs7q4igwBcVcckJEme8H Q3Dk3bwJKihVeZHRKqXxCoLL6PwN3iGmXXmc5BtwKYbs5m X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:6902:1003:b0:dc6:e5e9:f3af with SMTP id w3-20020a056902100300b00dc6e5e9f3afmr365170ybt.9.1708733527490; Fri, 23 Feb 2024 16:12:07 -0800 (PST) Date: Fri, 23 Feb 2024 16:11:43 -0800 In-Reply-To: <20240224001153.2584030-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: <20240224001153.2584030-1-jstultz@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240224001153.2584030-4-jstultz@google.com> Subject: [RESEND][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.44.0.rc0.258.g7320e95886-goog