From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender-of-o59.zoho.eu (sender-of-o59.zoho.eu [136.143.169.59]) (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 C6B2A31B839 for ; Wed, 18 Mar 2026 17:43:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.59 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773855793; cv=pass; b=S4AZIKslkBHBp6wuttmL2XacFFwUbUEk5UMJQX5Jd3SWs48/60XySY0QOsToLFRu+IEfdOmk/vsP0yPaqRi73cXicmeneGTk+JxFRUcYbv5YPKqUHk+xXnIE+8gWvhEvICQoIiVXfmjnHlRmUtYF/IQA+ZOr6XfPn6QkD4wUoZ0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773855793; c=relaxed/simple; bh=RFTJfbUHbRx66915ZV5wpd9Z1zEyKiK8ymRPX76pOfc=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=IkkLmRDyXseLsqnZ7gHzcIu7oGztlcSFuuTqkBrSzgjMVtC6AwPwz2wLBRsepqviDGMziBw3MgbBD09ZdLh3piDc51d7zp80MDW5O3t/hLsZVrMk+RlRNNMie4Dff5wJBTus7JUbh83SaP1WlgZU2/TYIJQ8J/hngwImaZRQjvk= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=HrU9ggJD; arc=pass smtp.client-ip=136.143.169.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="HrU9ggJD" ARC-Seal: i=1; a=rsa-sha256; t=1773855788; cv=none; d=zohomail.eu; s=zohoarc; b=fTOzR/dFyH3/mGh8TFLxgx5xi4phN0Ky1bjZqVVQZG7tHQUzTwRYuEjNFj8ta55+jaqZqWLLcFhLM3EIWNgJwZDddZ5ewwQDtLBNAlKeTWgElqEmIkFHu8JELQAcCbOUPcLAM405TCjqkY3X2q+DzNHnU6kjuovnE2RaApC+Se4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773855788; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=U+7RX0M3vcK/8ezIGTC//Sx/J/bY3CJcXwYixZsa7gs=; b=lTFVkNFRCmhqIRMGlMr+X/zMbZuSJjNaGbJ6CLoK4bORDTUi+Ykqqmltl+ELm0VS/9cYhu6oydTwLPIllN5YaiKfvJxPxqluqdQyhD4o3nWsnlBOhCdeqZrGE1kFM4gTwITLM11MHDZikEwu7NLgeUxO+BrJK5OfXvw6myTeHYE= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773855788; s=zmail; d=objecting.org; i=objecting@objecting.org; h=Date:Date:From:From:To:To:CC:Subject:Subject:In-Reply-To:References:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To:Cc; bh=U+7RX0M3vcK/8ezIGTC//Sx/J/bY3CJcXwYixZsa7gs=; b=HrU9ggJDWe112OD7l+ijUFw5M3U3XDUqnso3IAD/KoMi5yT2c6mRrBx33WDbGKHl 6hle+NG5t7iSTuLmoQB3RQR0IPuVsNTzIB4+T7qOKmEL+qJ8ik4zdhFvl8ZHoxXaSRL gtFWXreO5WhkCfOKVCHVuXsPligOusiuJ0gh2ajw= Received: by mx.zoho.eu with SMTPS id 177385578533142.13684242115494; Wed, 18 Mar 2026 18:43:05 +0100 (CET) Date: Wed, 18 Mar 2026 17:43:06 +0000 From: Josh Law To: Andrew Morton CC: linux-kernel@vger.kernel.org, hlcj1234567@gmail.com Subject: Re: [PATCH] lib/assoc_array: fix stale nr_leaves_on_tree after gc User-Agent: Thunderbird for Android In-Reply-To: <20260318102319.0db807e1dc3e29fd1cde68b1@linux-foundation.org> References: <20260318164959.85841-1-objecting@objecting.org> <20260318102319.0db807e1dc3e29fd1cde68b1@linux-foundation.org> Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External On 18 March 2026 17:23:19 GMT, Andrew Morton = wrote: >On Wed, 18 Mar 2026 16:49:59 +0000 Josh Law w= rote: > >> In assoc_array_gc(), assoc_array_apply_edit() publishes the new tree >> root before nr_leaves_on_tree is updated, creating a window where the >> tree is visible with a stale leaf count=2E Move the nr_leaves_on_tree >> assignment before assoc_array_apply_edit() so the count is consistent >> when the new root becomes visible=2E >>=20 >> =2E=2E=2E >> >> --- a/lib/assoc_array=2Ec >> +++ b/lib/assoc_array=2Ec >> @@ -1711,8 +1711,8 @@ int assoc_array_gc(struct assoc_array *array, >> =20 >> gc_complete: >> edit->set[0]=2Eto =3D new_root; >> - assoc_array_apply_edit(edit); >> array->nr_leaves_on_tree =3D nr_leaves_on_tree; >> + assoc_array_apply_edit(edit); >> return 0; > >But assoc_array_apply_edit() alters array->nr_leaves_on_tree and now we >immediately overwrite that alteration? 2/2 No, unless if the resulting tree is completely empty (edit->array->root = =3D=3D NULL)=2E In that scenario, assoc_array_apply_edit() explicitly sets = edit->array->nr_leaves_on_tree =3D 0, but since it's zero, it overwrites 0 = with 0,=20 and In the assoc_array_gc() path, the edit struct is allocated with kzallo= c(),=20 and edit->adjust_count_on is never set (it stays NULL)=2E Because it's NUL= L, assoc_array_apply_edit() actually skips the block that alters array->nr_l= eaves_on_tree V/R Josh Law