From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B84622C15BE for ; Sun, 19 Jul 2026 16:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784479937; cv=none; b=uGMnVBPw8xK2XlilB8o8cT7s9gzgMhiOAr89b3NUlXmeKSIHOOHifnDZEgU2wE8Ki2eA5v7TkSVyEBBUFHxH7lTiJJe+sZdgta/V3MZV6y9VdZq4Kzf2YeEcu1fM/KXlJGGWFGKsuM1nKKU+Icj92XzIx9pTaMttHSkE+6o5WB0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784479937; c=relaxed/simple; bh=NVKPpShgMt6wqsRy3yY8Xn+njwWr2qFefFLtDElJUyY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=PytTkH2UDhaizy1szO7q+5o7f9G92vvH4K4gQ9kDMiUl/O7hqe5n6s20eH5Nfmuq/FEqfmixwtJ6malfJITf4EmG9Mxa//TxR4YYQb2PkYpGOckH8rWTXuKPx3VHQ/EngZH0cA3NKFug5gR4scWnI44cqzK7EmJqBV+UVpzjB8A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GI/bdTUm; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GI/bdTUm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784479934; h=from:from: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; bh=cbbtGtVhwIZMB1ryHa/6fbYJI6bDo/ZwZFWHJRgpGcs=; b=GI/bdTUmGI73MKSVKa7MgtfXBpHPxruD7QUf3Tqaj4o7sYYbYt3aJFDfewYTUuS6rx3eUo 9VDhKY73gXKu+hAAJ6nK6tYTvYtk/Pkf8bbOHgzRmZh9NU1UHzmVZFnw+XGOLoHNDgqgs/ PnXR2M5m82BINz7v+SEicvpotBT4g1M= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-NTHbCvaZNyq4yoiGhLhw5g-1; Sun, 19 Jul 2026 12:52:11 -0400 X-MC-Unique: NTHbCvaZNyq4yoiGhLhw5g-1 X-Mimecast-MFC-AGG-ID: NTHbCvaZNyq4yoiGhLhw5g_1784479929 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3FBB519560A1; Sun, 19 Jul 2026 16:52:09 +0000 (UTC) Received: from [10.22.80.25] (unknown [10.22.80.25]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 30ABE1954229; Sun, 19 Jul 2026 16:52:07 +0000 (UTC) Message-ID: Date: Sun, 19 Jul 2026 12:52:06 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] lockdep: Fix subclass resource leak in lockdep_unregister_key() To: Nilay Shroff , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , linux-kernel@vger.kernel.org Cc: Shin'ichiro Kawasaki , Geliang Tang References: <20260719152015.237188-1-nilay@linux.ibm.com> Content-Language: en-US From: Waiman Long In-Reply-To: <20260719152015.237188-1-nilay@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 On 7/19/26 11:20 AM, Nilay Shroff wrote: > When a dynamic lock key is unregistered using lockdep_unregister_key(), > lockdep routes the cleanup sequence through __lockdep_free_key_range() > with a hardcoded size of 1. > > This layout model assumes that a dynamic key only occupies its base > registration address (subclass 0). However, when a lock utilizes > nested acquisitions—either implicitly via networking paths (e.g., > bh_lock_sock_nested() passing SINGLE_DEPTH_NESTING) or explicitly via > mutex_lock_nested()—lockdep calculates virtual class tracking nodes > using pointer math offsets: > > Virtual Class Pointer = Base Address of Key + Subclass Index > > Because the unregister range size is strictly constrained to 1, lockdep > completely skips evaluating adjacent virtual subclass slots (key + 1 > through key + 7). Consequently, when dynamic structures (such as per- > queue network sockets) are repeatedly created, teardowned, and allocated > at fresh memory blocks, the subclass /1 structures and their historical > dependency chains are permanently orphaned in the global graph. Over > prolonged runtime and frequent reconnect loops, this asymmetry leads to > the absolute exhaustion of MAX_LOCKDEP_CHAIN_HLOCKS. > > Fix this by instructing lockdep_unregister_key() to look ahead across > the entire valid subclass allocation block range > (MAX_LOCKDEP_SUBCLASSES), ensuring that all related subclass matrix > definitions are completely zapped alongside the primary key. > > Cc: Shin'ichiro Kawasaki > Reported-by: Geliang Tang > Tested-by: Geliang Tang > Signed-off-by: Nilay Shroff > --- > kernel/locking/lockdep.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > index 2d4c5bab5af8..490904bee63e 100644 > --- a/kernel/locking/lockdep.c > +++ b/kernel/locking/lockdep.c > @@ -6606,7 +6606,7 @@ void lockdep_unregister_key(struct lock_class_key *key) > WARN_ON_ONCE(!found && debug_locks); > if (found) { > pf = get_pending_free(); > - __lockdep_free_key_range(pf, key, 1); > + __lockdep_free_key_range(pf, key, MAX_LOCKDEP_SUBCLASSES); > need_callback = prepare_call_rcu_zapped(pf); > nr_dynamic_keys--; > } I think you should add Fixes: 108c14858b9e ("locking/lockdep: Add support for dynamic keys") Other than that, Reviewed-by: Waiman Long