From nobody Sun Feb 8 11:26:47 2026 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 4BEAC37C117 for ; Mon, 19 Jan 2026 14:23:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768832637; cv=none; b=ghwF7MvyutdTvZhdwbgNUF7alblkJfISOdMUUVJ57kP6OpcJOaQRfWBcXguYeycvrfo7keH0W96CC9pJX6Y5x1AwCzdXAymEYIwAJ43Ap4yLam0XX2QQsowjyzz78+DQ/ysh/dbuCRBTD1SOZqVGbYyb7pJzOg9ALHpS4kDK0uE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768832637; c=relaxed/simple; bh=l+kwMUsQimoxGi8L7uWCc3QAdNgoR9d+OzSkHX2cqgs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WILwuZn+I8j2wGDZu0e2JyhuD+tXz7gxiLUIcO1tgRuOUMQxz4c96afXjYRQXmp78GhknOiPZCsh8UMoMmdyfVzdP116Mz8geBbq1HI23sUbAPqlsjN1naLCvxzYJi4wAyPUWocV/7x/p5hoIwrsrxqA891vMhGz9pF1kfFle2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=oJJEhNwI; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="oJJEhNwI" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768832632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ny2Dbz5+1e/+8ujacpK/pSGHIZdtzJne97Rc5EYzZe4=; b=oJJEhNwI3HdqtrY/iRjl8AyZVFW2Zqc6yAgTfNdIJ0mbOfw6SnIpV43lT1vt9U3t3IhW9q AedoTn5RF84LH81JkpDZauxFxDpoMFjjtp/eVB48BQ+URCLP/L+bWSJfp9+I24wTMn4cuV ziUTKGl19jXu/luD8sCrwzn0IhCAAEA= From: Leon Hwang To: bpf@vger.kernel.org Cc: Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Leon Hwang , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-patches-bot@fb.com Subject: [PATCH bpf-next 1/3] bpf: Factor out bpf_lru_node_set_hash() helper Date: Mon, 19 Jan 2026 22:21:18 +0800 Message-ID: <20260119142120.28170-2-leon.hwang@linux.dev> In-Reply-To: <20260119142120.28170-1-leon.hwang@linux.dev> References: <20260119142120.28170-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The hash field is not used directly by the LRU list itself; it is consumed by the 'del_from_htab' callback when removing entries from the hash map. The hash initialization must be performed under the LRU lock to avoid a race where a popped LRU node is evicted and deleted from the hash map with an uninitialized hash value, if defer the hash setting to hashtab.c::prealloc_lru_pop(). Factor out a dedicated bpf_lru_node_set_hash() helper and document this requirement to make the ordering and locking constraints explicit. Signed-off-by: Leon Hwang --- kernel/bpf/bpf_lru_list.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/bpf_lru_list.c b/kernel/bpf/bpf_lru_list.c index e7a2fc60523f..c091f3232cc5 100644 --- a/kernel/bpf/bpf_lru_list.c +++ b/kernel/bpf/bpf_lru_list.c @@ -341,13 +341,27 @@ static void bpf_lru_list_pop_free_to_local(struct bpf= _lru *lru, raw_spin_unlock(&l->lock); } =20 +/* + * The hash field is consumed by the 'del_from_htab' callback rather than + * the LRU list itself. Initialize it while holding the LRU lock to avoid + * a race where a popped LRU node is evicted and removed from the hash map + * with an uninitialized hash value, if defer the hash setting to + * hashtab.c::prealloc_lru_pop(). + */ +static void bpf_lru_node_set_hash(struct bpf_lru *lru, + struct bpf_lru_node *node, + u32 hash) +{ + *(u32 *)((void *)node + lru->hash_offset) =3D hash; +} + static void __local_list_add_pending(struct bpf_lru *lru, struct bpf_lru_locallist *loc_l, int cpu, struct bpf_lru_node *node, u32 hash) { - *(u32 *)((void *)node + lru->hash_offset) =3D hash; + bpf_lru_node_set_hash(lru, node, hash); node->cpu =3D cpu; node->type =3D BPF_LRU_LOCAL_LIST_T_PENDING; bpf_lru_node_clear_ref(node); @@ -415,7 +429,7 @@ static struct bpf_lru_node *bpf_percpu_lru_pop_free(str= uct bpf_lru *lru, =20 if (!list_empty(free_list)) { node =3D list_first_entry(free_list, struct bpf_lru_node, list); - *(u32 *)((void *)node + lru->hash_offset) =3D hash; + bpf_lru_node_set_hash(lru, node, hash); bpf_lru_node_clear_ref(node); __bpf_lru_node_move(l, node, BPF_LRU_LIST_T_INACTIVE); } --=20 2.52.0