From nobody Sat Feb 7 12:07:35 2026 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (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 42204314B8E for ; Wed, 5 Nov 2025 15:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762355774; cv=none; b=KYxJ2fbOdmcFs0rUAqZ+qJ7xbUK4OX9j47b9sjUXk5S9Lm/b0gZYaXVOoIvfkqT0jMv+U2LFHY0oQncIqJHogPUF0cINjvoH2Zqhxs/kx1RSAaWMqfUOdclWA4Jal+ZCwildtv2At0oVqkCRAiidRbD6DKQwy6q9k581Iie721Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762355774; c=relaxed/simple; bh=b4xw3O7UfnfiZD5pTNztiPpsuje/8itnpv5WUO8bWHk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dcJcAc0+os3/iJswDtO1PyP7pXcdKD/HBtaI4DDp5FxCjtTPXEuscilVgsMADYP41Gl65u3dWSweurtXfOL8fqz4kbtwu4Q+fHh8SZnF2CiTOzDw/n+LqDFYjWjX7nTd+sS5Ms/a6V4af/vInuRfLGrFcnCTdiUDg/rvVbIUE5s= 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=c6LuRRBW; arc=none smtp.client-ip=95.215.58.183 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="c6LuRRBW" 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=1762355769; 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=wU180lrRJICTjdwwgpbUzGgOxt6kCHg/rdbuIH1C8eU=; b=c6LuRRBWkmBVXZiiIytDQFBpjqH2rAsY9fwzsKgHqkXXpVyrkbQvdJNo/s3AQc8CUQjdeW i2zW1paLZ3q+RvSMkmAYNznL3FUmJysbU+wptS8EO4TVZDAmcT4esMeSnyRnh/RSfW5G6n ffdba//qJpxl1lDzo9U5ijG5bDF7Yi8= From: Leon Hwang To: bpf@vger.kernel.org Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, ameryhung@gmail.com, linux-kernel@vger.kernel.org, kernel-patches-bot@fb.com, Leon Hwang Subject: [PATCH bpf-next v6 1/2] bpf: Free special fields when update [lru_,]percpu_hash maps Date: Wed, 5 Nov 2025 23:14:06 +0800 Message-ID: <20251105151407.12723-2-leon.hwang@linux.dev> In-Reply-To: <20251105151407.12723-1-leon.hwang@linux.dev> References: <20251105151407.12723-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" As [lru_,]percpu_hash maps support BPF_KPTR_{REF,PERCPU}, missing calls to 'bpf_obj_free_fields()' in 'pcpu_copy_value()' could cause the memory referenced by BPF_KPTR_{REF,PERCPU} fields to be held until the map gets freed. Fix this by calling 'bpf_obj_free_fields()' after 'copy_map_value[,_long]()' in 'pcpu_copy_value()'. Fixes: 65334e64a493 ("bpf: Support kptrs in percpu hashmap and percpu LRU h= ashmap") Signed-off-by: Leon Hwang Acked-by: Yonghong Song --- kernel/bpf/hashtab.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index f876f09355f0d..c8a9b27f8663b 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -934,15 +934,21 @@ static void free_htab_elem(struct bpf_htab *htab, str= uct htab_elem *l) static void pcpu_copy_value(struct bpf_htab *htab, void __percpu *pptr, void *value, bool onallcpus) { + void *ptr; + if (!onallcpus) { /* copy true value_size bytes */ - copy_map_value(&htab->map, this_cpu_ptr(pptr), value); + ptr =3D this_cpu_ptr(pptr); + copy_map_value(&htab->map, ptr, value); + bpf_obj_free_fields(htab->map.record, ptr); } else { u32 size =3D round_up(htab->map.value_size, 8); int off =3D 0, cpu; =20 for_each_possible_cpu(cpu) { - copy_map_value_long(&htab->map, per_cpu_ptr(pptr, cpu), value + off); + ptr =3D per_cpu_ptr(pptr, cpu); + copy_map_value_long(&htab->map, ptr, value + off); + bpf_obj_free_fields(htab->map.record, ptr); off +=3D size; } } --=20 2.51.2