From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A64B32F3C22 for ; Wed, 18 Mar 2026 17:23:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773854600; cv=none; b=mM9DKTYrikMXDOlWTcr0l5wAvqWccMJo7MuvM25QhhU6Ik1CIZMNSHzyWtqvmY0i+sbRo3+JdyWWyyUT37ht3ccnAwrMk3VP2fvIoAF4dsY8um/EORFea75GTtuZkNOkVKy6bIrmF+zIElIO/ba5BvNWD4wzQP1e5+AQrjXo7cE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773854600; c=relaxed/simple; bh=luyrij0ybPblRtprj3KDFowDNvNcnSQIOEETUtWuF5c=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=YzUR1LZgw+uWaEyhASrnGbgbeKMgTifUoCV8LMhdXc9x9T3hicabG7AmPggpLqKAnsmWj5c+bfAzDhQU77T+QtXR/vNs+Ife0HpXVwLgUMXWU/B79JZMvKMwbalRnhz7lXIALxqTJk383hnjpq+WRNu3L75pqr9Im3i/B9WZzYE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=flR/rrBl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="flR/rrBl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 154A9C2BCB1; Wed, 18 Mar 2026 17:23:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1773854600; bh=luyrij0ybPblRtprj3KDFowDNvNcnSQIOEETUtWuF5c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=flR/rrBlzXKQ6Qj4CU/8/w833FETU+U21s5dIuvqUDlUaTgUc0LG6JgeA+lhvZvJG tpdMuKaxiuY3mwLw1qa+l7B4Zo5zW2BzMg2zFHuz7Xd9DugxZepviRYz5nEocfUikg lG5N2iFJLSsS/qXBk4DtXw2uBEQrQEGxwQw6RIKE= Date: Wed, 18 Mar 2026 10:23:19 -0700 From: Andrew Morton To: Josh Law Cc: linux-kernel@vger.kernel.org, hlcj1234567@gmail.com Subject: Re: [PATCH] lib/assoc_array: fix stale nr_leaves_on_tree after gc Message-Id: <20260318102319.0db807e1dc3e29fd1cde68b1@linux-foundation.org> In-Reply-To: <20260318164959.85841-1-objecting@objecting.org> References: <20260318164959.85841-1-objecting@objecting.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 18 Mar 2026 16:49:59 +0000 Josh Law wrote: > 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. Move the nr_leaves_on_tree > assignment before assoc_array_apply_edit() so the count is consistent > when the new root becomes visible. > > ... > > --- a/lib/assoc_array.c > +++ b/lib/assoc_array.c > @@ -1711,8 +1711,8 @@ int assoc_array_gc(struct assoc_array *array, > > gc_complete: > edit->set[0].to = new_root; > - assoc_array_apply_edit(edit); > array->nr_leaves_on_tree = 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?