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 492ED192D97 for ; Tue, 7 Oct 2025 01:26:06 +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=1759800368; cv=none; b=qvr7KvM4KCkme78/7r2ANu/QfqurERHKpyW//ko9dAhYWbeluHKzW8h7LjsOK0fQBYiklXK++j1XqzIZMoWqzfc9N3il52vfMx8Du02t77dBSxNcNSbzK0beFNi1SMKrpqe9c20pkBp2HsUfqUedNLhLW7tdyUZxuVd4jOfU85A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759800368; c=relaxed/simple; bh=uOMat6atBpB9CzH0j4UgHm20CJlM2/lwXSkOsos6dZA=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=KQAulAa7svV3YW8+Did1GCzgPvq4N8Kpp+kiJZjfrIQXKAPr+iOSj2xmhnGk0+V2CO0S1Ec8gt+AuBZdisnfxPQfS2hDWhCWwSTWZsDKRPN6Wm3n1fLr7NrhGh1BE/WzuJnfsjJKurMP+J9VxgUWamkOv89qZY8/JbdA5J36XRM= 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=cBzN/kPC; 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="cBzN/kPC" Message-ID: <9671e39c68dd45736dcd1547baba9616e6a07ed2.camel@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1759800364; 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=uOMat6atBpB9CzH0j4UgHm20CJlM2/lwXSkOsos6dZA=; b=cBzN/kPCgfpW5NxFVU/utzMF9WYyfFGxHbiDERfxl4aGwpTk2IY97G6yjmUFdAbjSlCNDE nKmNkN0G7Z25YdiSJqxl9O3hnhir33j0AtmKG9bkGKnr9Inv+alGw8cNmsNqjgS8tKRRcU x5suXX/V2+JkM3zhXBO5pyMRaHgj1HQ= Subject: Re: [PATCH bpf 1/2] bpf: Avoid RCU context warning when unpinning htab with internal structs X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: KaFai Wan To: Andrii Nakryiko Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, 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, shuah@kernel.org, toke@redhat.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Le Chen Date: Tue, 07 Oct 2025 09:25:54 +0800 In-Reply-To: References: <20251003084528.502518-1-kafai.wan@linux.dev> <20251003084528.502518-2-kafai.wan@linux.dev> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT On Mon, 2025-10-06 at 16:58 -0700, Andrii Nakryiko wrote: > On Fri, Oct 3, 2025 at 1:47=E2=80=AFAM KaFai Wan wr= ote: > >=20 > > When unpinning a BPF hash table (htab or htab_lru) that contains intern= al > > structures (timer, workqueue, or task_work) in its values, a BUG warnin= g > > is triggered: > > =C2=A0BUG: sleeping function called from invalid context at > > kernel/bpf/hashtab.c:244 > > =C2=A0in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 14, name: > > ksoftirqd/0 > > =C2=A0... > >=20 > > The issue arises from the interaction between BPF object unpinning and > > RCU callback mechanisms: > > 1. BPF object unpinning uses ->free_inode() which schedules cleanup via > > =C2=A0=C2=A0 call_rcu(), deferring the actual freeing to an RCU callbac= k that > > =C2=A0=C2=A0 executes within the RCU_SOFTIRQ context. > > 2. During cleanup of hash tables containing internal structures, > > =C2=A0=C2=A0 htab_map_free_internal_structs() is invoked, which include= s > > =C2=A0=C2=A0 cond_resched() or cond_resched_rcu() calls to yield the CP= U during > > =C2=A0=C2=A0 potentially long operations. > >=20 > > However, cond_resched() or cond_resched_rcu() cannot be safely called f= rom > > atomic RCU softirq context, leading to the BUG warning when attempting > > to reschedule. > >=20 > > Fix this by changing from ->free_inode() to ->destroy_inode() for BPF > > objects (prog, map, link). This allows direct inode freeing without > > RCU callback scheduling, avoiding the invalid context warning. > >=20 > > Reported-by: Le Chen > > Closes: > > https://lore.kernel.org/all/1444123482.1827743.1750996347470.JavaMail.z= imbra@sjtu.edu.cn/ > > Fixes: 68134668c17f ("bpf: Add map side support for bpf timers.") > > Suggested-by: Alexei Starovoitov > > Signed-off-by: KaFai Wan > > --- > > =C2=A0kernel/bpf/inode.c | 2 +- > > =C2=A01 file changed, 1 insertion(+), 1 deletion(-) > >=20 > > diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c > > index f90bdcc0a047..65c2a71d7de1 100644 > > --- a/kernel/bpf/inode.c > > +++ b/kernel/bpf/inode.c > > @@ -790,7 +790,7 @@ const struct super_operations bpf_super_ops =3D { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .statfs=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D simple_statfs, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .drop_inode=C2=A0=C2=A0=C2= =A0=C2=A0 =3D inode_just_drop, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .show_options=C2=A0=C2=A0 = =3D bpf_show_options, > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .free_inode=C2=A0=C2=A0=C2=A0=C2= =A0 =3D bpf_free_inode, > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .destroy_inode=C2=A0 =3D bpf_free= _inode, >=20 > s/bpf_free_inode/bpf_destroy_inode/ then? ok, done in v2. >=20 > > =C2=A0}; > >=20 > > =C2=A0enum { > > -- > > 2.43.0 > >=20 --=20 Thanks, KaFai