From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4608AC021B1 for ; Thu, 20 Feb 2025 09:29:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF8112802BA; Thu, 20 Feb 2025 04:29:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CA6F62802B8; Thu, 20 Feb 2025 04:29:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B47672802BA; Thu, 20 Feb 2025 04:29:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 948A92802B8 for ; Thu, 20 Feb 2025 04:29:33 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4043FA2FA0 for ; Thu, 20 Feb 2025 09:29:33 +0000 (UTC) X-FDA: 83139800226.21.7190D76 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf21.hostedemail.com (Postfix) with ESMTP id 99AB81C0009 for ; Thu, 20 Feb 2025 09:29:31 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iiyPKG8b; spf=pass (imf21.hostedemail.com: domain of mhiramat@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740043771; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BL8wksR5WNG+QJ0FbX357Pyu+1pFjdnY2j7SmTTB68I=; b=AOhq4poDMiNhPdDjfUv4fLzYgHID1q+To57FIVIwMX78B8mCFKzr+PMWGVUf6EcwmWEgwU 8vYtcv9/mSbsXYXMC6KntaOcE9bBzPizcD0JWTYcdiEx44RIEwB6m1F30FRGLuv3gMT58f 3/YPgrCX2lcmO08RvDV1oSm91aGuuBM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iiyPKG8b; spf=pass (imf21.hostedemail.com: domain of mhiramat@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740043771; a=rsa-sha256; cv=none; b=e2pRoQP6iziX6U7bfiakVOXyI0srE5hLFYySRlVclHoqO1bUzJHybxzXFxRXVec0HcZ88g M7BfBXxN27YTHfpwwpVwDSIzeUppyQyzxbsFEIXL2MaCG/XLudoCCAMkljoj/y7CFtH7p0 1m1yQi9czwZ0vB6b5n6+y/bVdzyOu04= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 726C46132F; Thu, 20 Feb 2025 09:29:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2863C4CED1; Thu, 20 Feb 2025 09:29:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740043770; bh=DpD8mweF0mlsSyJ1C8ZOC6x0nRyu9qCwYiQBLyd5+GA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=iiyPKG8bAKS7WFCBv8j8T3JdfNZx6qO+c3/S9+HIWUySilPQmtpJgDpPjBLbjsiQw bCuSmuJnZi/Mzm/jjBh5vOoeAW0HNN6JXbMbtKoSrFSO4AjDdO9IhRK8B95RWBi+Qp PDQapsuf3h3eO3S0bB9WTQWgX/tQPvFHdawhE7Ri9cYxfflu29+NtHgCn4TB5WW2hC fQOxYinI3KZu7ZByOd2YrcamxdCMMbWA9Zrr+exT0Sp4/EQKjcut8pJH4u6WkLNiFc VdgNBkjkLeugVeMmhk8Z5aQhRVqHrMJxaZAYpXPzPq5FQE6IuLWF8dFgLhmp9LUuoV HbNAKd7MV6Syw== Date: Thu, 20 Feb 2025 18:29:27 +0900 From: Masami Hiramatsu (Google) To: Waiman Long Cc: Steven Rostedt , Peter Zijlstra , Ingo Molnar , Will Deacon , Andrew Morton , Boqun Feng , Joel Granados , Anna Schumaker , Lance Yang , Kent Overstreet , Yongliang Gao , Tomasz Figa , Sergey Senozhatsky , linux-kernel@vger.kernel.org, Linux Memory Management List Subject: Re: [PATCH 1/2] hung_task: Show the blocker task if the task is hung on mutex Message-Id: <20250220182927.258e394c6ba5d76d4c57324b@kernel.org> In-Reply-To: References: <173997003868.2137198.9462617208992136056.stgit@mhiramat.tok.corp.google.com> <173997004932.2137198.7959507113210521328.stgit@mhiramat.tok.corp.google.com> <20250219112308.5d905680@gandalf.local.home> <0fa9dd8e-2d83-487e-bfb1-1f5d20cd9fe6@redhat.com> <20250219152435.35077ac3@gandalf.local.home> <20250220075639.298616eb494248d390417977@kernel.org> <20250219204153.65ed1f5e@gandalf.local.home> <9f9150b4-1cf5-4380-b431-419f70775a7d@redhat.com> <20250220115904.051e0cc55a9cb88302582ef4@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 99AB81C0009 X-Stat-Signature: q3r6w1ucrnhtyp1p7bto8nngxkzcscgo X-HE-Tag: 1740043771-44414 X-HE-Meta: U2FsdGVkX18FmqViH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FQvu6FY4HUTAG6N8e76HfkV6X9h/kspDxah2soIgMuvSeSpyC8q688ohwiH7Rrh6f6ag5xrCVq9vvy2/rAaPyX4gYEz51svl2AC3ZHa2zas2dr8Q/Mz7Imj4Wk8IOpq6YTWfvNQajBoUkLPwxDJTfv4MutvkYl6OLOnAfvFxpnmIz7Ps7is59NCPfRyId7MXY/vhDTBL+pNEQj+Ypk26+6l/dkGA3xv6cB7GFY7VErjWmbDchAEWmLX6dlDGd/gO7Ht2BSjul76b9ixpfrwN+N/UCaYfE9ZHsCaGk3m1Ydt5PkgKlttT4i61KqvRa1ek5UJ+R/zRbB/BXD3btddA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, 19 Feb 2025 22:37:04 -0500 Waiman Long wrote: > On 2/19/25 9:59 PM, Masami Hiramatsu (Google) wrote: > > On Wed, 19 Feb 2025 21:15:08 -0500 > > Waiman Long wrote: > > > >> On 2/19/25 8:41 PM, Steven Rostedt wrote: > >>> On Wed, 19 Feb 2025 20:36:13 -0500 > >>> Waiman Long wrote: > >>> > >>> > >>>>>>>> this field, we don't need to take lock, though taking the wait_lock may > >>>>>>>> still be needed to examine other information inside the mutex. > >>>>> Do we need to take it just for accessing owner, which is in an atomic? > >>>> Right. I forgot it is an atomic_long_t. In that case, no lock should be > >>>> needed. > >>> Now if we have a two fields to read: > >>> > >>> block_flags (for the type of lock) and blocked_on (for the lock) > >>> > >>> We need a way to synchronize the two. What happens if we read the type, and > >>> the task wakes up and and then blocks on a different type of lock? > >>> > >>> Then the lock read from blocked_on could be a different type of lock than > >>> what is expected. > >> That is different from reading the owner. In this case, we need to use > >> smp_rmb()/wmb() to sequence the read and write operations unless it is > >> guaranteed that they are in the same cacheline. One possible way is as > >> follows: > >> > >> Writer - setting them: > >> > >>     WRITE_ONCE(lock) > >>     smp_wmb() > >>     WRITE_ONCE(type) > >> > >> Clearing them: > >> > >>     WRITE_ONCE(type, 0) > >>     smp_wmb() > >>     WRITE_ONCE(lock, NULL) > >> > >> Reader: > >> > >>     READ_ONCE(type) > >> again: > >>     smp_rmb() > >>     READ_ONCE(lock) > >>     smp_rmb() > >>     if (READ_ONCE(type) != type) > >>         goto again > > What about mutex-rwsem-mutex case? > > > > mutex_lock(&lock1); > > down_read(&lock2); > > mutex_lock(&lock3); > > > > The worst scenario is; > > > > WRITE_ONCE(lock, &lock1) > > smp_wmb() > > WRITE_ONCE(type, MUTEX) READ_ONCE(type) -> MUTEX > > WRITE_ONCE(type, 0) > > smp_wmb() > > WRITE_ONCE(lock, NULL) > > WRITE_ONCE(lock, &lock2) READ_ONCE(lock) -> &lock2 > > smp_wmb() > > WRITE_ONCE(type, RWSEM) > > WRITE_ONCE(type, 0) > > smp_wmb() > > WRITE_ONCE(lock, NULL) > > WRITE_ONCE(lock, &lock3) > > smp_wmb() > > WRITE_ONCE(type, MUTEX) READ_ONCE(type) -> MUTEX == MUTEX > > WRITE_ONCE(type, 0) > > smp_wmb() > > WRITE_ONCE(lock, NULL) > > > > "OK, lock2 is a MUTEX!" > > > > So unless stopping the blocker task, we can not ensure this works. > > But unless decode the lock, we don't know the blocker task. > > That could only happen if the reader can get interrupted/preempted for a > long time. In that case, we may need to reread the lock again to be sure > that they are stable. Hm, actually read side should run under rcu read locked, so only interrupt matters. So I think this rarely happens. BTW, we don't need the lock address itself, but we need to know who is the owner. Maybe we can point the address of atomic_long_t? struct task_struct { atomic_long_t *blocked_on_owner; }; The problem is that mutex and rwsem are OK, but rt_mutex uses task_struct *. Maybe we can use atomic_long_t in rt_mutex too if the new Kconfig is enabled. Thank you, -- Masami Hiramatsu (Google)