Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2357296rdf; Mon, 6 Nov 2023 11:37:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIu+dlXpxfB1rkdNzJFdsEZ3I6dxfexFfL6OIIYd1wtZJXLgVc/BzLlepPhA1v2rMnuTvn X-Received: by 2002:a17:902:c402:b0:1cc:5ce4:f64b with SMTP id k2-20020a170902c40200b001cc5ce4f64bmr721130plk.8.1699299434615; Mon, 06 Nov 2023 11:37:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699299434; cv=none; d=google.com; s=arc-20160816; b=miCVIAdPEP8NG6nz4sB7BwVAnl0dvfemeM4ZVJuZ6iF5p77nzNnefT53Mx7LR5H7Rx GIz0R2Ii8FA4JnXCFMUST3ZFytYjnwqYG8rpJwswnTjgo88hQUeOzMfxfon4BdCOvp7q qsufFa5dVY/EknUNhmtB4TJXorYqc5uz2EouVsnF0z7fra4UXLA8aAWGfiebXfi3neVk eRJSGQlFPy6dr66lyrJmvW+s5i7hTpMBsfM5kqDI9bdSuhr2fyFPJIxK1+VVJER6YOHI Dkion/DUIySsIYDGP3o26Mf6PiftHH8H2T5ByOJH0WapMn8W3Umjhfzioxifh7KnET54 VECg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=rmX5Q7SFKWcrt3zpGHMTaKC5ErTWRpzWqGhGcyC8r+o=; fh=S3wray6v+X/inSyuiRNSFDiFiXQj3q+N5v4vkWpo59k=; b=YPWh/c4Wvz6KZpP98HpJCA4jsBBLeprYUkjc9or75WkTEVwqvqweQQn9zf7gIxT8RR 2f/kKj2qsKp8S/LOqhyQUaOnzlNaiy6OKAnT6g04iWOAZnfJb4b6YfbMHOHdyFVqZsgS 2TKEqLDePBolJ2IapQ86NwF32Ov1XDK7A4RsIVKpCJOxOkhi/rofbhckkHZXVH+2r2dZ yiJ/4QNClbEPDomAu9huiYoUP7C+SXjnHHGUwFGrvf6QSryD8HvA5HA/j6JPaZUMtm9U tNCwnXImE+1Qxl0qNLCUy88joseZ4hXdBY9AX/0Ol58W+cPFgcyPld1oQrCYj/DDuWCJ 7aeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=X2CBGIjD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id t21-20020a170902d15500b001cc0f6028bbsi8074745plt.402.2023.11.06.11.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 11:37:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=X2CBGIjD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0CD2F804B285; Mon, 6 Nov 2023 11:36:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232990AbjKFTgC (ORCPT + 99 others); Mon, 6 Nov 2023 14:36:02 -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-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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 06 Nov 2023 11:36:57 -0800 (PST) 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, 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.869.gea05f2083d-goog