From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 418B33E3150 for ; Fri, 24 Apr 2026 20:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777061559; cv=none; b=FM+nhP1gH8ezi2IBj9F2eZSUfMWSVtrkKkVeacTmjOoCmJ0d1UwJqzLDbRCehbz3FGiz+o1TW4PinW8H0VnGXpr4kXGJq6J1dv8bsVE9zYlNpCFeCxzqVLC1b5/xfqxxKOrCcvn9mPD8WfD7hLm8JvT7Mwml7XgHB5ATX5x4WF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777061559; c=relaxed/simple; bh=EDDonT/gV6kNf+AmN6XTlKHonw2AGAiFQ6rygvGJi48=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Khengts/EVDvrHJbtHyU2oxH+48TDILMqWIGAzfXhEPBtHKq5zKsyC5v8GX6VByjICvS13CRlle4lJYUp+X+PWtkCdwEFpFnBGLsEnJJAWxmiiv3RLhv7dvL1UgIew4nrEYQHUc90Sv+n1OtrW7Jl3a589PRuiwayBH8xmPEeoM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YgdN2Tjs; arc=none smtp.client-ip=209.85.128.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YgdN2Tjs" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-7a469383e0bso66793267b3.2 for ; Fri, 24 Apr 2026 13:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777061556; x=1777666356; darn=lists.linux.dev; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=54deu6wo5n8tEL/vkpg6EDb5n7YLGB8ILix5XPcjPNc=; b=YgdN2TjseDvZFyGvabcCn8IoTgN7Svn7sv5VNGEjz0moZu8Eg52d4wfg7WtLtSXf7w 03VXyCwKvlHa0641kAR44OOOGEWb7aqDhgZHBopyw5N36sUJUlN0Uv0hi8sb0YGKNi05 Jt+mHQgO6d8GoixxOLXRtRiNWyAmx+3T6cJ0+ZJmZU3inV9h3ulzbL9IaIVppNzPosb9 zzRSfL3sHgdxmI/GCuQODaHSljWh1GDtTfmQZw3tELIxWH+GilODOCd9TuQGZS8oVVBC QE67Rhpm98fDn+nAFFcRjpMWF0n9/VeH/jaw0BiVo2rk/pSZHNPPloBpRITVYeO/i5Ag smNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777061556; x=1777666356; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=54deu6wo5n8tEL/vkpg6EDb5n7YLGB8ILix5XPcjPNc=; b=tUUpQORW1PRSpDE6RO7Tyc9HSA9XoO5ZSjpZsmvB5kSuS5CdpCVl+js7KO5JHICfif P4rXl1SBgz3zA+DWoM2Hx/Tjxg44nEfMMrjcrJ8+Aa1WwGR1HW62OI7wuzlQkBT0D7A6 UyoZIQuz10GoLqZrpfbxEgbVjC7UmmRt4oGBNf4DYSd8Kxovu0fFoo6cSJ2BDS/zfeMO CCcuthVDmnEUV1ce39N5Gj0niLf1zVA+xDGsMWabN3OaW+RQPvCa1eUuGmJd0E5eSfJ+ U8/DJAXYdP9cMv6lXjSo2EG0Ov/AUdToPPqapMCFE1V/FRoVkuXkKTETdtHmgr3RBOXh dAYw== X-Gm-Message-State: AOJu0Ywgej6BbTZWLAmzi/8ESzv3pokVprFTKJ6vheoSQv9wnjBM7C5D jxs8CPBMykRdu7YL24oRTvGXRgFBsuNBBiWmsLG7hRVCMl1aLfwOYXCyj6lHaA== X-Gm-Gg: AeBDiesZBqigPDiAIJukv3RLRgRQqR02xpN1mbV4g1/ODitxw1/zdBuwHIye24XtZ/U /S/tpnjFd28oSqrJYrmvvI6N12jdoMjIVvTuxXQCHmrEniuG78jQGaUUkO3JcnL9llnlAFio8c4 uuqg2Mvt2ZuKhGKzLkkwi3kLiG2gI1JMq6OZw1MafcBZWKgyYPAzrqHJelSf/33QtBtYgIgN2mq CMpBjXO7jcXYZYZRKOzW4cb4VDQ301DJR8gzGWrjqI/2gXnozHxaMciRUN2JkGnPXAueGZwCVCl ujFEgwFCozfEOjX4vBmXs1zhPkfVeIzcw8xYzWfNdGTJ8OxAUFklfzfWjvg+WcHA/Yq0wsOiRD6 gWUSm6VHF4q8t3BrmxBvRhDVLThC7vPSJJokXXxEDzNJbpuUmED5wUCj7y8NAHsS//lrmA7VYOW pPWvDnJceWobdblbm3wx6tmzaPjJ8Kg0P9wKCwRuJ3dnA6qzrLZ5h3Qs+cDZriTx+2OdM= X-Received: by 2002:a05:690c:11:b0:79b:d56a:a7c2 with SMTP id 00721157ae682-7b9ed0108ccmr339263157b3.48.1777061555791; Fri, 24 Apr 2026 13:12:35 -0700 (PDT) Received: from zenbox ([2600:1700:18fb:6011:cc96:e003:f6cc:4ed]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7b9ee8c2083sm95503157b3.17.2026.04.24.13.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2026 13:12:35 -0700 (PDT) Date: Fri, 24 Apr 2026 16:12:34 -0400 From: Justin Suess To: sashiko@lists.linux.dev Cc: bpf@vger.kernel.org Subject: Re: [PATCH bpf-next v3 1/2] bpf: Implement dtor for struct file BTF ID Message-ID: References: <20260424192252.695240-2-utilityemal77@gmail.com> <20260424195958.AED4EC19425@smtp.kernel.org> Precedence: bulk X-Mailing-List: sashiko@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260424195958.AED4EC19425@smtp.kernel.org> On Fri, Apr 24, 2026 at 07:59:57PM +0000, sashiko-bot@kernel.org wrote: > Sashiko AI review found 1 potential issue(s): > - [High] Calling `fput()` directly from `bpf_file_release_dtor` can lead to a hard deadlock when invoked from NMI context. > -- > > commit 6368f91be1fd91bc9cb38d3498f35d279bad04c9 > Author: Justin Suess > > bpf: Implement dtor for struct file BTF ID > > This commit implements a destructor for struct file, allowing it to be > stored in a map as a referenced kptr. The destructor calls fput to > release the reference. > > > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > > index 2bb60200c2665e..ee5ceb82e4f812 100644 > > --- a/kernel/bpf/helpers.c > > +++ b/kernel/bpf/helpers.c > [ ... ] > > @@ -2752,6 +2753,13 @@ __bpf_kfunc void bpf_task_release_dtor(void *p) > > } > > CFI_NOSEAL(bpf_task_release_dtor); > > > > +__bpf_kfunc void bpf_file_release_dtor(void *file) > > +{ > > + fput((struct file *)file); > > +} > > Can this cause a deadlock if the destructor is invoked from NMI context? > > If an NMI-context BPF program (such as a perf event tracing program) > updates or deletes a map element containing a struct file kptr, the BPF > framework will synchronously invoke this destructor to clean up the old > kptr. > > When fput() drops the reference count to zero, it calls > __fput_deferred(). Since in_interrupt() evaluates to true in NMI > context, __fput_deferred() bypasses task_work_add() and instead calls > schedule_delayed_work(). > > This leads to the following call chain: > > bpf_file_release_dtor() > fput() > __fput_deferred() > schedule_delayed_work() > add_timer() > > The add_timer() function attempts to acquire the timer_base->lock raw > spinlock. If the NMI interrupted a thread that was already holding this > lock, the NMI handler will spin indefinitely waiting for it, resulting > in a hard deadlock. > > Would it be safer to defer the fput() operation using an explicitly > NMI-safe mechanism like irq_work_queue() to handle arbitrary BPF > contexts? > For (human) reviewer context: The NMI stuff needs to be addressed separately. [1] I guess the AI isn't gonna understand but just doing irq_work wouldn't be right either as it would break operation ordering for maps and fixing it here wouldn't fix the other dtors broken in NMI. (cgroup/task_struct) Anyways I think the AI didn't find any other problems and the test issue is fixed so this should be ready for another look. [1] : https://lore.kernel.org/bpf/20260421201035.1729473-1-utilityemal77@gmail.com/ > > + > > +CFI_NOSEAL(bpf_file_release_dtor); > > + > > #ifdef CONFIG_CGROUPS > [ ... ] > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20260424192252.695240-1-utilityemal77@gmail.com?part=1