Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp246047rbe; Wed, 28 Feb 2024 20:05:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUTHB6npUB3sxmDuaLAugRLxY4ei1KzIOn69ZBmkayJKtk1/ClgQcsCIVL4eT9KLBZSnX/Z0iKCMy+B1P/i+ZSKkYFVMyUE3B6xY7qzmQ== X-Google-Smtp-Source: AGHT+IFRYsGzqFWOVovQ2PfysDXYcdySBZWGye9TvJytuevK3cBzhQPYzuZ0ZOWlr/6snjlQRrvr X-Received: by 2002:a0c:fbca:0:b0:68f:6314:e130 with SMTP id n10-20020a0cfbca000000b0068f6314e130mr1158415qvp.59.1709179552956; Wed, 28 Feb 2024 20:05:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709179552; cv=pass; d=google.com; s=arc-20160816; b=qUPgH0syOrUxVNN4X+iXnyGLRRrYKHwsYYffroR4SOcWE+4/dec/A/Jnro+aAtP8AU zuMiK17QW3ASbW1RQijX1LbA0osM6yqhr1iaf1xJvqHLml0nUiej58qVPK/orCh0tOfN PFkYd3WzHeJxUBb+H3iiAtwQJbgHdnSm5UaQ12e7bShnS6Nn86LgG8IShEavsdpdaEQp r8GpxAwKoVJ+5c72q9MGd0ukXG6ix9CjK9bOv0/jKzRXhnP9imAXoY9DlYI4UnNW777U pahLappQAd0uS68is/4+ZJ+L84dp0Hn+n3/QJhBx3sGoGdyLbHcmrzW5GPit85nrgc17 3LKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:from:cc :content-language:references:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature:dkim-filter; bh=5Ry3NcMAk/caocxSjb6fNKx9I4LOTLgwLsgLddKIu0Y=; fh=1bj1O8jBgQ1xkDnmWlAfdiTMXh795RRxEG6V12dOo/U=; b=v8XZ0aUy3dW5hj87Fdo7KwsIFvOrXu24gNU7dsohkc1yMrjNM4ExcmTnMHPpkeAU+L 1yPvVEBDzFLlAlmW2o2/MHnJMU8oGZESozq3hmR1hPcEovu0vyukir5t4PdrfGNnBmrn H/LdThGvAiYU5MGSEfDOQuiJw1Bi1QHDQy3VsUjK7Joaoc31ePfa/rCQQu9iCv73+80e Dqw0gU520fPd61h3GBovQoTpe6vEI3sjqJFKY96AZgBd61qQGzseb95xq1Jk/GUIIS8M 3OCQGm0SR15xiPWJIF8gNTzHRTK3MyUYAp6DDXNd/ygEFFZCS/s9JmC7NvRN2exJTNUL 6Kvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@candelatech.com header.s=default header.b=QPmun4xh; arc=pass (i=1 spf=pass spfdomain=candelatech.com dkim=pass dkdomain=candelatech.com dmarc=pass fromdomain=candelatech.com); spf=pass (google.com: domain of linux-wireless+bounces-4227-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-4227-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=candelatech.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id r5-20020ad45765000000b0068f70c5195bsi558574qvx.614.2024.02.28.20.05.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 20:05:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-4227-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@candelatech.com header.s=default header.b=QPmun4xh; arc=pass (i=1 spf=pass spfdomain=candelatech.com dkim=pass dkdomain=candelatech.com dmarc=pass fromdomain=candelatech.com); spf=pass (google.com: domain of linux-wireless+bounces-4227-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-4227-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=candelatech.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A134E1C2116A for ; Thu, 29 Feb 2024 04:05:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B179338396; Thu, 29 Feb 2024 04:05:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=candelatech.com header.i=@candelatech.com header.b="QPmun4xh" X-Original-To: linux-wireless@vger.kernel.org Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [148.163.129.52]) (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 94758381D9 for ; Thu, 29 Feb 2024 04:05:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.129.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709179539; cv=none; b=fCHCKthVqA0sC70v9Y5wQKO8vI5qjUJyzPq9mTchrvDE4+0tQlpUi8ApTyb0DWCU/HOng1XrnezKrDLOEHMQAaGQALUbgVWkw+hC2gwQXecm+k8Ncct1pOd3XQV9j4S8ZWV0ulhIlreIrchwGu1rN/g+mmitiWWKMl1B7pfnBzo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709179539; c=relaxed/simple; bh=RlZrw9YMEMldm7rl5qY5lQIo3gDi8jh9efWEZkJNERE=; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From: In-Reply-To:Content-Type; b=ev4ew1jKwGbXqEYFoHsq86+XgW8URlex+KjscfR+QVOcIb6HbMXAQSJeisqZ1vRwQaZJzXEn0hZxznJ2mFzgLQtTHqjty67RFX0ZkxOoZJ5wPOPk879R7nOHgWmZJpFFi2Tpp2wQXgD9s22s25IUY+2X4555fgz/ZLp6djbY2A0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=candelatech.com; spf=pass smtp.mailfrom=candelatech.com; dkim=pass (1024-bit key) header.d=candelatech.com header.i=@candelatech.com header.b=QPmun4xh; arc=none smtp.client-ip=148.163.129.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=candelatech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=candelatech.com X-Virus-Scanned: Proofpoint Essentials engine Received: from mail3.candelatech.com (mail2.candelatech.com [208.74.158.173]) by mx1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTP id 5EC7560005E; Thu, 29 Feb 2024 04:05:30 +0000 (UTC) Received: from [192.168.1.23] (unknown [98.97.35.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail3.candelatech.com (Postfix) with ESMTPSA id 6FD0613C2B0; Wed, 28 Feb 2024 20:05:29 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail3.candelatech.com 6FD0613C2B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=candelatech.com; s=default; t=1709179529; bh=RlZrw9YMEMldm7rl5qY5lQIo3gDi8jh9efWEZkJNERE=; h=Date:Subject:To:References:Cc:From:In-Reply-To:From; b=QPmun4xh8IvKpdnmdnUaBVz0xQ74o6sA+mBoxTnFSz+2hidALm4Uq1lbficae1s0i +keofDugIVmTMTqq4iOQWiDpQ9tkOPhtzcMuCBVG7YfokRWWoYyfzaHREwat1uyFI6 dTwmmtA7QfZ89Q5zovMjW7Lqet0hJ0Sg078/4oa8= Message-ID: <48cb4fab-a905-4793-8bfe-58157061e0f7@candelatech.com> Date: Wed, 28 Feb 2024 20:05:28 -0800 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Kernel deadlock in 6.7.5 + hacks, maybe debugfs related. To: Johannes Berg , linux-wireless References: <1c9fa9e5-09f1-0522-fdbc-dbcef4d255ca@candelatech.com> <95d56b9a-4b91-476f-bab3-7af0f28ff469@candelatech.com> <0f8a0451e547f318febcbe36823e1f9914cc684b.camel@sipsolutions.net> <33cc22b8-5852-42ae-9e80-8c3c58c36b6d@candelatech.com> <4a3edd404b84da53b56bb0a391cb42d00f42f4c5.camel@sipsolutions.net> <492a290b-752f-48c3-be16-59bdf7914487@candelatech.com> <366ed520b5f4b3cd603be11124f9b51e32ce8106.camel@sipsolutions.net> Content-Language: en-MW Cc: Madhan Sai From: Ben Greear Organization: Candela Technologies In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-MDID: 1709179531-0nBIxv8zTyoc X-MDID-O: us5;ut7;1709179531;0nBIxv8zTyoc;;b42792dba290a1257c3f0aaf1c60b0ff On 2/27/24 08:13, Johannes Berg wrote: > On Tue, 2024-02-27 at 15:58 +0100, Johannes Berg wrote: >> >> Which, btw, ignoring comments, braces, whitespace - then really just >> removes the line you're getting stuck on. >> >> So actually no ... invert the test? >> >> if (refcount_dec_and_test(...)) >> return; >> >> If it hit zero here, there's guaranteed to be no user, so we can return. >> >> If it's not zero yet, we might yet go into a new cancellation, so we >> need the rest of the function. >> > > This is what I wrote now: > > > Subject: [PATCH] debugfs: fix wait/cancellation handling during remove We are no longer able to reproduce a lockup, so please feel free to add: Tested-by: Madhan Sai Thanks, Ben > > Ben Greear further reports deadlocks during concurrent debugfs > remove while files are being accessed, even though the code in > question now uses debugfs cancellations. Turns out that despite > all the review on the locking, we missed completely that the > logic is wrong: if the refcount hits zero we can finish (and > need not wait for the completion), but if it doesn't we have > to trigger all the cancellations. As written, we can _never_ > get into the loop triggering the cancellations. Fix this, and > explain it better while at it. > > Cc: stable@vger.kernel.org > Fixes: 8c88a474357e ("debugfs: add API to allow debugfs operations cancellation") > Reported-by: Ben Greear > Closes: https://lore.kernel.org/r/1c9fa9e5-09f1-0522-fdbc-dbcef4d255ca@candelatech.com > Change-Id: I6c7aeff8c9d6628a8bc1ddcf332205a49d801f17 > Signed-off-by: Johannes Berg > --- > fs/debugfs/inode.c | 25 ++++++++++++++++++++----- > 1 file changed, 20 insertions(+), 5 deletions(-) > > diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c > index 034a617cb1a5..a40da0065433 100644 > --- a/fs/debugfs/inode.c > +++ b/fs/debugfs/inode.c > @@ -751,13 +751,28 @@ static void __debugfs_file_removed(struct dentry *dentry) > if ((unsigned long)fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT) > return; > > - /* if we hit zero, just wait for all to finish */ > - if (!refcount_dec_and_test(&fsd->active_users)) { > - wait_for_completion(&fsd->active_users_drained); > + /* if this was the last reference, we're done */ > + if (refcount_dec_and_test(&fsd->active_users)) > return; > - } > > - /* if we didn't hit zero, try to cancel any we can */ > + /* > + * If there's still a reference, the code that obtained it can > + * be in different states: > + * - The common case of not using cancellations, or already > + * after debugfs_leave_cancellation(), where we just need > + * to wait for debugfs_file_put() which signals the completion; > + * - inside a cancellation section, i.e. between > + * debugfs_enter_cancellation() and debugfs_leave_cancellation(), > + * in which case we need to trigger the ->cancel() function, > + * and then wait for debugfs_file_put() just like in the > + * previous case; > + * - before debugfs_enter_cancellation() (but obviously after > + * debugfs_file_get()), in which case we may not see the > + * cancellation in the list on the first round of the loop, > + * but debugfs_enter_cancellation() signals the completion > + * after adding it, so this code gets woken up to call the > + * ->cancel() function. > + */ > while (refcount_read(&fsd->active_users)) { > struct debugfs_cancellation *c; > > > > Can you test it and let me know if that works? > > Same as what we discussed, FWIW, other than the comments. > > johannes > -- Ben Greear Candela Technologies Inc http://www.candelatech.com