From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 B9698337BB2; Wed, 14 Jan 2026 18:44:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768416283; cv=none; b=DMEUjUZ7EZe0kI0fGnmvZH2F3HADaIxNH70EEPZtli8z7Xx4VT0qjc6Gc7jilPBqxCLAvHsuaDz2/RmxicYr7W+L9mQKjmS9NnenytE2Z8FQG+yCEX/3f14Y7IcI1ZwMJnPkZo78D26JWpn0DV+/WR3P3swqc6Ikv55WPpDsXfE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768416283; c=relaxed/simple; bh=ClypWUCcmZdhOgMSv7cAqWse/cL4IEXeAo2k6l1M1+U=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ue6MRNxzQWJ+Li1VJ/TWAt/6ugRGtNU12iqLJWjEofWSCj+T9pgducSO9/3OH79LDRSjSlFC6nSDx7Uaf8Qx9NT8Fh7yEGBP2LsNmG67KMDSqAKOpDGYhVqKm8qA1bhdOL7MWiqoNQYXMSBLFbf3ym9nMgf66bLplJC8xPjjh/0= 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=kUJ/7MOi; arc=none smtp.client-ip=91.218.175.189 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="kUJ/7MOi" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768416274; 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=8MuE08WjOKJJ911Tg0cdT6a/SadtO731OH3L0J+ZIjA=; b=kUJ/7MOi8ckRi8Q39kTf4knDQP3iSskFER8XOHkyRahsTZBtPaUNxXeVH5AhGvIOosaAMT Enux6nAn6cKwi/tOtLvyrjXE7ic1DwO0GWTZLzGCfTTuDLMxEjoowT+HcuCe2lRpoMN1nr vbGEKevRA0L3w6gzt7TvHzlFuodDrr4= Date: Wed, 14 Jan 2026 10:44:27 -0800 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v3 1/5] bpf: lru: Tidy hash handling in LRU code To: Leon Hwang Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Saket Kumar Bhaskar , "David S . Miller" , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-patches-bot@fb.com, bpf@vger.kernel.org References: <20260107151456.72539-1-leon.hwang@linux.dev> <20260107151456.72539-2-leon.hwang@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: <20260107151456.72539-2-leon.hwang@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 1/7/26 7:14 AM, Leon Hwang wrote: > The hash field is not used by the LRU list itself. > > Setting hash while manipulating the LRU list also obscures the intent > of the code and makes it harder to follow. > > Tidy this up by moving the hash assignment to prealloc_lru_pop(), > where the element is prepared for insertion into the hash table. > > Signed-off-by: Leon Hwang > --- > kernel/bpf/bpf_lru_list.c | 24 +++++++++--------------- > kernel/bpf/bpf_lru_list.h | 5 ++--- > kernel/bpf/hashtab.c | 5 ++--- > 3 files changed, 13 insertions(+), 21 deletions(-) > > diff --git a/kernel/bpf/bpf_lru_list.c b/kernel/bpf/bpf_lru_list.c > index e7a2fc60523f..f4e183a9c28f 100644 > --- a/kernel/bpf/bpf_lru_list.c > +++ b/kernel/bpf/bpf_lru_list.c > @@ -344,10 +344,8 @@ static void bpf_lru_list_pop_free_to_local(struct bpf_lru *lru, > 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) > + struct bpf_lru_node *node) > { > - *(u32 *)((void *)node + lru->hash_offset) = hash; > node->cpu = cpu; > node->type = BPF_LRU_LOCAL_LIST_T_PENDING; > bpf_lru_node_clear_ref(node); > @@ -393,8 +391,7 @@ __local_list_pop_pending(struct bpf_lru *lru, struct bpf_lru_locallist *loc_l) > return NULL; > } > > -static struct bpf_lru_node *bpf_percpu_lru_pop_free(struct bpf_lru *lru, > - u32 hash) > +static struct bpf_lru_node *bpf_percpu_lru_pop_free(struct bpf_lru *lru) > { > struct list_head *free_list; > struct bpf_lru_node *node = NULL; > @@ -415,7 +412,6 @@ static struct bpf_lru_node *bpf_percpu_lru_pop_free(struct bpf_lru *lru, > > if (!list_empty(free_list)) { > node = list_first_entry(free_list, struct bpf_lru_node, list); > - *(u32 *)((void *)node + lru->hash_offset) = hash; > bpf_lru_node_clear_ref(node); > __bpf_lru_node_move(l, node, BPF_LRU_LIST_T_INACTIVE); init the hash value later (after releasing l->lock) is not correct. The node is in the inactive list. The inactive list is one of the rotate and _evict_ candidates, meaning tgt_l->hash will be used in htab_lru_map_delete_node(). In practice, it does not matter if htab_lru_map_delete_node() cannot find the node in an incorrect bucket. However, it still should not use an uninitialized value to begin with. > index 441ff5bc54ac..c2d12db9036a 100644 > --- a/kernel/bpf/hashtab.c > +++ b/kernel/bpf/hashtab.c > @@ -296,12 +296,13 @@ static void htab_free_elems(struct bpf_htab *htab) > static struct htab_elem *prealloc_lru_pop(struct bpf_htab *htab, void *key, > u32 hash) > { > - struct bpf_lru_node *node = bpf_lru_pop_free(&htab->lru, hash); > + struct bpf_lru_node *node = bpf_lru_pop_free(&htab->lru); > struct htab_elem *l; > > if (node) { > bpf_map_inc_elem_count(&htab->map); > l = container_of(node, struct htab_elem, lru_node); > + l->hash = hash; > memcpy(l->key, key, htab->map.key_size); > return l; > }