Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp297826lqh; Mon, 6 May 2024 21:55:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUhvSrHr4lkV62TegmJBn96i69aRuOxIdjsXsVu/TfQsA4c0E4EiN8AEn1wHhpLEArzsOJuw5UoFptyKQpiOjv+CG8qWsVbebaBgVPJxQ== X-Google-Smtp-Source: AGHT+IE/mEXyTLw8A5PxiJxoAHq0o1Y//y2pjI6v6jVq0tS9NVhZeEoNyH3scQDiQhDALzuiPrH3 X-Received: by 2002:a17:906:d10d:b0:a59:deaf:e81d with SMTP id b13-20020a170906d10d00b00a59deafe81dmr937624ejz.33.1715057738966; Mon, 06 May 2024 21:55:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715057738; cv=pass; d=google.com; s=arc-20160816; b=1HckG+sMLvpKYEh74+Lfr4m2hQr87FZX4lYfVvNmv26+WvEEPXXkjrgXCSUNpb92o+ YDCCbFSHFXoiT/c2oZcSvtr21TVJXm16NRhmubmZbIvUmyZ1IXNk0eGqSujLfGVkyOat ovif9nSeMY59vadsfNAPMzU4FQtBzKJoQOQGcQO+IRH5lXPUCDbcrJcK2A631qgLtNCt 6ALea3dyP66Tsp6yKrm7AgVbMy3gUzKuw//I9cq2aOzg+67Mea9Bp4BUZFMixVFWrlwE E3A8g2h5hWAKj961lCNhQri5ENWaigA7aQat9VcnEUc3ralzXInQa368rV+ISq16PJj5 saAA== 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=B5TEm22m8AhcjBDC3yb2+ACT2qc5jdCH9i9C2IPWAkE=; fh=Ak3ndqXoXBAisuw/jKttRfO+cCr9Eq3AMM6EKt/IOqY=; b=NK38FZctpO6g9mPNSwFOrVxxb/HeBl0u5erfSevLqaPO2nar0yi2wJFTpgtFr4jNwo KUXYXG7h7DbD6VnLZ+qRy13o80eJyqqHVsBfpqMbdMx8Q2UKdSdi0XtoNw+SuO8Ut4VC qOoKpWAOnvnGLePLuHuG04IZeKnEWU4pbeirfuf5TdmB74GN+neDNKukqcARdDKyWYAF 9NuZX5FOepaU/ljNTeYrV1+7t/XKzQ69JIL28mbk70zpncyGObecSe2aRyVBvVy4GPU6 lTXKItvLH7O7REROld5ETNh4+oSjHz5DEz1DiOzo52ti0FaqLdL6aQHrXelDANd6yOK6 gjcA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Jl2uy3zP; 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-170659-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170659-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. [147.75.80.249]) by mx.google.com with ESMTPS id xa22-20020a170907b9d600b00a59a6b941ebsi3842219ejc.640.2024.05.06.21.55.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 21:55:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170659-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Jl2uy3zP; 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-170659-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170659-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 86D321F254D5 for ; Tue, 7 May 2024 04:55:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98EDC6DD0D; Tue, 7 May 2024 04:55:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Jl2uy3zP" 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 D30296BFA4 for ; Tue, 7 May 2024 04:55:02 +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=1715057704; cv=none; b=ufl01+ZvEq6v7khmeDM//erGxfpAC4VEHCom3fHvh+zAaTP/lYtfeJMMfuUjdpw2gZgbEirtDrY6DT+S2+eGbmNFROaUQIaNZE/n5chKo4OarUKCWZAq7qe0IfZt9Ao1jeev8tgk01PNXeGCqmRhDGMimo8wcs4N0NIabI3gHvM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057704; c=relaxed/simple; bh=LJozwWFo00icSc+ph1GrGuSQds/hXTBjQ8rp7ambAo8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FBEkFZ9L8dJWWWr+2E7r1jEpzAPu5eohzi/gGScxPu/65uVSlnWHF6enfsNfjoJLIGa7jDCKG8tSrvuZV7taeZ/xMzTiqKseLN3ALOFsRJWK3fUcbNnjdNYRzGKZNY9A5nSzaS0CRkwLbDhZBQ2b8TuoUvTGDQyWZTV6WybKG7k= 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=Jl2uy3zP; 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-de468af2b73so5917862276.0 for ; Mon, 06 May 2024 21:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715057702; x=1715662502; 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=B5TEm22m8AhcjBDC3yb2+ACT2qc5jdCH9i9C2IPWAkE=; b=Jl2uy3zP/Vdcj/ApST/FlgX0jLLb+mlqQviZtBcC1BT8oQrIKowrNxylcvsYGG652M iojTrVGLIoqqZZ07qcXqYsmjhLqmy6vnO/y+/3f+LIH9ocudEBiytii1MRBW8e2+vOqY dTL7Jaz9CNuBCtvtspgI9PMeITcpYJ4RPFhH+/ist7Q5lF61y1F3yCrCHsjuPBE2yK0U +bs6vhu7JRTeXipT6+C3PuM5APlelQ/RAJVVfr0zxRcLbs8zqSCy6HJqx2bsJaw7FMVI AWvk/Fi7cTfNlLdArgPU6tfpr169RXHtew2cWQobtUdLsfDslMbmQA5LY0vkDuxFv1GQ 1/jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715057702; x=1715662502; 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=B5TEm22m8AhcjBDC3yb2+ACT2qc5jdCH9i9C2IPWAkE=; b=aw/6AlXyNRBr63xqCWw1vhnU8QtrzfmCFVjA208WJiNGimPDqs7ux9LbDkFru7I959 dEC7ru641GzqJA5FuYxHPVW5CW8qBwFET1tZ/aVjh1tSH6Wvs9UQR1QHGN+ZQE1cU0oP aw1VIAZQr3V4Ach8J0aXltVT5t9aXHTEUUm8KnHgY+H2AcTfUvg6W5zZGQnXpD0Zz8Cw /Bh9dXUe9kYPNTKOj83IjkmwhL6IJACr82sHVQNJz0EosbHkDXqe0KDU/aP1LDdkUezz TsyGwTQJ/+frb1/tmt4HXBb6eEwz6rsBoCaVvRUrdgW8pAfSYN8PcfiaTFftFS3L7DQq eRpw== X-Gm-Message-State: AOJu0YzBv/wzgu4BrULUDwU92FRCP19MF6ub0UY4gfaIZrtf8IRux4op 0pCs7bHEfQkeJMQrKWM65I4drF+z90U9lRc/56QjVUPIACLxz3CSiLf0UNl2ilbLGNNbDvSnB5N D22N3jgc/3n8Y4fqcFhvIPcofTN9F1ABUVHz2jzH9Dvh0WWCGaKZBVvQJqCYqraW3ZWqzHzBm6p 4Oj+2ocNuv++qNygCAaOkm5TVbK9e8n2rj1KmdR89cz18m X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:6902:701:b0:dcb:e4a2:1ab1 with SMTP id k1-20020a056902070100b00dcbe4a21ab1mr4171430ybt.11.1715057701501; Mon, 06 May 2024 21:55:01 -0700 (PDT) Date: Mon, 6 May 2024 21:54:32 -0700 In-Reply-To: <20240507045450.895430-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: <20240507045450.895430-1-jstultz@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240507045450.895430-4-jstultz@google.com> Subject: [PATCH v10 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, Metin Kaya , 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 Tested-by: K Prateek Nayak Tested-by: Metin Kaya Reviewed-by: Metin Kaya Reviewed-by: Valentin Schneider 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 v10: * Handle null lock ptr, to simplify later code, as suggested by Metin Kaya --- kernel/locking/mutex.c | 25 ------------------------- kernel/locking/mutex.h | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 6d843a0978a5..4b7193fd3be9 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..cbff35b9b7ae 100644 --- a/kernel/locking/mutex.h +++ b/kernel/locking/mutex.h @@ -20,6 +20,33 @@ 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) +{ + if (!lock) + return NULL; + 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.45.0.rc1.225.g2a3ae87e7f-goog