From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 48341332912; Fri, 17 Oct 2025 15:17:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760714259; cv=none; b=NT1hV9c2yySbS/HBKCNTMfsbVoNXZD032foKVUqUnLbgJ+fNH1nyNMdJ36ReQrLLXGwBtSOqiSAi2yQzUEp5diNhWHnKbUF/D39KNenngdUwJHEmUsii1/xVUFGVJdtD6T57uCGd7FzyjqOAVm73mDnUfKgEVeM0eBQ0gRez3hg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760714259; c=relaxed/simple; bh=70TN6uJLtL6/y8tOmhiJLgiorjdltspeBsGs0lpr2kI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uqcPqp6S0L4ppu//2RxgUjmdOc9PgmZSt804Jp1JMv4rtJ0kzY+CXrj6ccQI4UG8zRXQyC4EMY2SMtybfQ85qffxHSZqCwIhxMV+zxG3J3KqwwxrVPBS990o4kbs6bXbG3RgorQOC9IR1Hl1t7lRNygcMH4g++yTBkGXtu0YRrM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FkdNz5ah; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FkdNz5ah" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFDCBC4CEE7; Fri, 17 Oct 2025 15:17:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760714259; bh=70TN6uJLtL6/y8tOmhiJLgiorjdltspeBsGs0lpr2kI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FkdNz5ahZ+3PUEK+6IcX0qnvV8ZBSJQyeQHGTGGseU5jggHQRIWaxxGsUuyN6A9Tm +d9I4uJghMEbm5TP/xYACslLzyGiO1HtodNj+p1m6HxfMClq5mM/v0OHsZzc3JICu0 +BycpsnJ5hQaz1CPuEdwDU/PPwWO8tryWqNeVKjQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Le Chen , Alexei Starovoitov , KaFai Wan , Yonghong Song , Sasha Levin Subject: [PATCH 6.12 082/277] bpf: Avoid RCU context warning when unpinning htab with internal structs Date: Fri, 17 Oct 2025 16:51:29 +0200 Message-ID: <20251017145150.128493786@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251017145147.138822285@linuxfoundation.org> References: <20251017145147.138822285@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: KaFai Wan [ Upstream commit 4f375ade6aa9f37fd72d7a78682f639772089eed ] When unpinning a BPF hash table (htab or htab_lru) that contains internal structures (timer, workqueue, or task_work) in its values, a BUG warning is triggered: BUG: sleeping function called from invalid context at kernel/bpf/hashtab.c:244 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 14, name: ksoftirqd/0 ... 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 call_rcu(), deferring the actual freeing to an RCU callback that executes within the RCU_SOFTIRQ context. 2. During cleanup of hash tables containing internal structures, htab_map_free_internal_structs() is invoked, which includes cond_resched() or cond_resched_rcu() calls to yield the CPU during potentially long operations. However, cond_resched() or cond_resched_rcu() cannot be safely called from atomic RCU softirq context, leading to the BUG warning when attempting to reschedule. Fix this by changing from ->free_inode() to ->destroy_inode() and rename bpf_free_inode() to bpf_destroy_inode() for BPF objects (prog, map, link). This allows direct inode freeing without RCU callback scheduling, avoiding the invalid context warning. Reported-by: Le Chen Closes: https://lore.kernel.org/all/1444123482.1827743.1750996347470.JavaMail.zimbra@sjtu.edu.cn/ Fixes: 68134668c17f ("bpf: Add map side support for bpf timers.") Suggested-by: Alexei Starovoitov Signed-off-by: KaFai Wan Acked-by: Yonghong Song Link: https://lore.kernel.org/r/20251008102628.808045-2-kafai.wan@linux.dev Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c index 9aaf5124648bd..746b5644d9a19 100644 --- a/kernel/bpf/inode.c +++ b/kernel/bpf/inode.c @@ -775,7 +775,7 @@ static int bpf_show_options(struct seq_file *m, struct dentry *root) return 0; } -static void bpf_free_inode(struct inode *inode) +static void bpf_destroy_inode(struct inode *inode) { enum bpf_type type; @@ -790,7 +790,7 @@ const struct super_operations bpf_super_ops = { .statfs = simple_statfs, .drop_inode = generic_delete_inode, .show_options = bpf_show_options, - .free_inode = bpf_free_inode, + .destroy_inode = bpf_destroy_inode, }; enum { -- 2.51.0