Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1750406lqz; Mon, 1 Apr 2024 16:45:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXG679bWl8PXvrC6bxs7smX3XfuSk5ayGradErof/7G+6NT1A2ge1azZguumshwWfU0Gi0RJ9/sCVlVCUmKVhMWVDPCQdCzDwmnWP7NEA== X-Google-Smtp-Source: AGHT+IGzzv97/NO0zSpNEbtGmyMtuJOgPVTKM7WUnI/veFvhSQOP/lzmu2zi12DCZdERX4lcnP/i X-Received: by 2002:a50:d482:0:b0:56b:a8ea:9642 with SMTP id s2-20020a50d482000000b0056ba8ea9642mr9039042edi.14.1712015130774; Mon, 01 Apr 2024 16:45:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712015130; cv=pass; d=google.com; s=arc-20160816; b=wG0fL8R0Ij71BcSPpW2QJanmJlxC9er5PS2LhBx4y1EHJfkpPkQ+drEzexSshz7X0Q Xxo6NBQ+KqEabZpHmCM3JHXn67I6N7mx2OyFaetd9NKafDBaTY0pRlYkK7xsVToubTDN Q8A3KJ0VF+I5hK69Pv/47SgJno5+b7T9qkgopNuXj8+AkhOJnRDV2cg00p5bng3E328y vIibWNPOlZY9gyKEehLldBdtJcsMa5HoMGVo3TOvoewhgUE69y8xRnMVZ26IaULDItAG TjY55DFKppPdlqxsSe7DvemWdzS4BKd/Yq6lm8Q5+G2XKYmCEwYlbRaNeIoHjedRJZH0 L/+g== 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=0uc0GIwNX9TQ2eyKhoV3DbzxqwGn/ULqzDV9v8PRZss=; fh=CAq+MFEKKjJy5jyw+pqNOeDGlDhGAe1gUm7slWeEdnw=; b=lbz7Dj0gizNeQWSIFShZw/fHitYT5IDyOK9ZtGEs3J7trPz51QwXuz7Rr4kGdc16WU m/F+AfMkDkeS6w6NsjkJrQOFQcxNmF9Hdu6lJj8adsozxihAiWF5sCdDMaXPLsgzagHG d9TLbGc/F3mYuLeikpuUOXuq+ofvMWYNwoyZ/OYWQmfkhnoOfN2l26uxMn5z0iElJhZB pEepfwSIgAFr3OmPlfiewKxQzd+rtJJUUzpATgussBYt4lgpt5Icb3qpP9f1jMz6gqTq gPzsSj/b/RpQp12mgM4Zos/7lAhvcp6Swt59Ehti/HRA+aRD7XxbuwPbxMYU8w8PCZ+B oxPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=e3+qatwX; 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-127191-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127191-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 r28-20020a50aadc000000b0056c364362cdsi5123152edc.614.2024.04.01.16.45.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 16:45:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127191-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=e3+qatwX; 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-127191-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127191-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 590101F228C8 for ; Mon, 1 Apr 2024 23:45:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0277D58229; Mon, 1 Apr 2024 23:44:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="e3+qatwX" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 427D858100 for ; Mon, 1 Apr 2024 23:44:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712015096; cv=none; b=lLDkato9Jjf1rhmeoHFlhn+LcxTBKCG7rblv8dDfhQK+8X9Z2rUHj7kUg2v7TEbsrXPKu0aoerKPDRhc7Z4f6Px0h8NVzUJ2KTg0epne88AUj5ItCpZqWgCSOFzG4tIm4l6Zu44S9QDP6upsl/DmQ329s+3GW2ach0/2Ku2Z3gE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712015096; c=relaxed/simple; bh=Er0fnT9u3Ba8OTtjlVXsTFy29JrXcDtlgfYMhmhcLWU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=B1hxC1agJDwtMAhQZ6xFzdbA9TmzdQbk7dao6u06OUbhLaoZ7eooDlwWMeC9yiuP73J3BiWsPxuj1EAS5Ca6v8ltMVRZXorI0TJtafEglV+S8YCVLgkrxD1xz+5F6H4eJmQ6jmymJBh8ekQWyeg3FyxjiXZm8+umCB9BHTGaNW0= 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=e3+qatwX; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-610c23abd1fso85876777b3.0 for ; Mon, 01 Apr 2024 16:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712015093; x=1712619893; 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=0uc0GIwNX9TQ2eyKhoV3DbzxqwGn/ULqzDV9v8PRZss=; b=e3+qatwXFHTNtVE4Ynq8cJiLnEInTOqstn/Quc8vRj9rio3E/VXf5+Jvf0ZSgVI6y0 ElOv/XSyyX4SX05AqCq911gnv59Kb4JXlnS0UlpHewJeW/4FFTUKi9DpNA5odXVXxHQW tR7c6CQaBls+kmSTMaPXjfZtlGiyKESjPGX6S8/6bpHzCk3eKNjdpFm4W5KSV/sCyx2F RD1NGgdU/YC9XVKVl7N+FrCEbr5V6sgyJddluaZZBNbahGVvYeS/FqA4ksjuqBLAChP0 NzRwWsb/haryQ5lz+8YDFtQAvs6bt+0eRMB6Uh7pQ+kdoFSj/SKMxH2DLHaMOc92no2h vcKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712015093; x=1712619893; 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=0uc0GIwNX9TQ2eyKhoV3DbzxqwGn/ULqzDV9v8PRZss=; b=P1Soy3Uja1baCiorP0xwqkrYSfvzcT2VpaUzxQWhv01fSry45W/+dpvgYFtqlDNxKT MAle8TsWyNgAcwBZRFwn7X6rV4STu7/Ip1HcPffIEGeoa0KYzWnKOrQ18MxaUxfzwaIN /vc8B7nznJmttKPsBR/qnXiv2iP3JyiSsWJH8L/9QRgjuaQGkdLrqSODjVtj+vrgoJLj Hxu7pzM7oJlkMgvZQ6COYPnS7NuvVS/C5LFxOZ/A2LYF8wXdp8TF3EioG0NCXB80SVdW vqlhcTM1NZwnKjWFv1BJZamTnnGoLh5b+y6ElQA5Js8YnNx+yWqGjE1XnlFWigmJ/zlv 3Daw== X-Gm-Message-State: AOJu0Ywi4Y+SuTfyD9j5VpwJZNLjkms09vtdW6uuqRmp5LErfY6YpTsZ TbKpvWqot2nQEti0buW+QEZNPNi9U9pFQcTnboZgC0C5cMxUDMeUUtb4pqJHIT5Er25SQ+S2DCb jJuryafLXCvDKoYK7xyk0kStNe3pGaz9xzRs8jTsT38RbLwRqq0auUlQwx4kMnweMOhv0sy8fCZ vLNYGDenAuYddDL+sAFCA7HBPbg+2mXBIXWGW1qCZi6v9P X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:690c:f12:b0:614:9623:90ca with SMTP id dc18-20020a05690c0f1200b00614962390camr1743830ywb.6.1712015092791; Mon, 01 Apr 2024 16:44:52 -0700 (PDT) Date: Mon, 1 Apr 2024 16:44:25 -0700 In-Reply-To: <20240401234439.834544-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: <20240401234439.834544-1-jstultz@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240401234439.834544-4-jstultz@google.com> Subject: [RESEND][PATCH v9 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 Tested-by: K Prateek Nayak 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.478.gd926399ef9-goog