From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (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 7B6DF224AF1 for ; Tue, 28 Oct 2025 14:48:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761662934; cv=none; b=FyA7IT2kqAbcrGEJFs3IzvlC9NvMjvpqAqwTwnTsVqFpeKaUXh2oVoLZVifRymvSmMkcik0UghZ7/TZNG3R/3yRs3ELBc88gMPzVHlmu5QQDwqqxBOw6f+uKIqB9RaAuY/73Ew6AFhmh+9fYiYfl84PZhkRuU1M1ZBBYg9nXleI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761662934; c=relaxed/simple; bh=nsp/vYBKPAKXSXwyzefzj3kkAqAeGqOO5aOAfMQ1t1U=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=lVWJdunS7EL7d0F6tr5Q8ifxAQZifwrep/mkXhlX1YzjarMB9Iwit31R2GpI/AAo9zR85hVroIegNd73ZwugP12+Y1wZX7dkeXz3R5gkOpTsfvnDUiK4srIPXXlm6JrYL/2UVmDCaZ22mXfLER2PXMWt5A1ad6lridrUy+Pcx0c= 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=GQKaAQq/; arc=none smtp.client-ip=95.215.58.170 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="GQKaAQq/" Message-ID: <971495da-bc0e-46d4-bda4-5e9b8310ca3e@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1761662930; 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=KO8xNdDiC0GfQKPOVB85ZS7KFE86udwGgsf60vNTK3g=; b=GQKaAQq/twkOLdGTujtKKebi9ryX/7K8MOLDeRG7WGWYcBwDj4BxC5Evs2/h9PHfViwS19 8XHqPtRsvDDGpiX6s7bCti+YucePdyFRYzd5RnLKGRMf+gMvpos+hEyGh4TS9vj2trJgSY 1DElGaNSIt2pkbOza2k3VLgPK3prR+g= Date: Tue, 28 Oct 2025 22:48:39 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf v3 3/4] bpf: Free special fields when update local storage maps To: Amery Hung Cc: bpf@vger.kernel.org, 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, linux-kernel@vger.kernel.org, kernel-patches-bot@fb.com References: <20251026154000.34151-1-leon.hwang@linux.dev> <20251026154000.34151-4-leon.hwang@linux.dev> <377791b5-2294-4ced-a0d3-918c7e078b2b@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Leon Hwang In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2025/10/28 01:04, Amery Hung wrote: > On Mon, Oct 27, 2025 at 9:15 AM Leon Hwang wrote: >> >> Hi Amery, >> >> On 2025/10/27 23:44, Amery Hung wrote: >>> On Sun, Oct 26, 2025 at 8:41 AM Leon Hwang wrote: [...] >>>> selem = SELEM(old_sdata); >>>> goto unlock; >>>> } >>>> @@ -654,6 +656,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap, >>>> >>>> /* Third, remove old selem, SELEM(old_sdata) */ >>>> if (old_sdata) { >>>> + bpf_obj_free_fields(smap->map.record, old_sdata->data); >>> >>> Is this really needed? bpf_selem_free_list() later should free special >>> fields in this selem. >>> >> >> Yes, it’s needed. The new selftest confirms that the special fields are >> not freed when updating a local storage map. >> > > Hmmm. I don't think so. > >> Also, bpf_selem_unlink_storage_nolock() doesn’t invoke >> bpf_selem_free_list(), unlike bpf_selem_unlink_storage(). So we need to >> call bpf_obj_free_fields() here explicitly to free those fields. >> > > bpf_selem_unlink_storage_nolock() unlinks the old selem and adds it to > old_selem_free_list. Later, bpf_selem_free_list() will call > bpf_selem_free() to free selem in bpf_selem_free_list, which should > also free special fields in the selem. > > The selftests may have checked the refcount before an task trace RCU > gp and thought it is a leak. I added a 300ms delay before the checking > program runs and the test did not detect any leak even without this > specific bpf_obj_free_fields(). Yeah, you're right. Thanks for the clear explanation. I also verified it by adding a 300ms delay. So this bpf_obj_free_fields() call isn't needed — I'll drop it in the next revision. Thanks, Leon