From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 0EEA23F411A for ; Wed, 5 Aug 2026 09:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785920757; cv=none; b=STsYrsqS1nhkvwvFW6Q///kXrUQjrf3aQE+N0RHXGjfOjuU0W0nyAi/KvPbEqabHfKGfrAots1Fs6hcms3uvxYR4vr7Du/84odFmAGOK6xHuNkmjTzFVE8jaNVG+uOVy16D/NcbJPKvbffYfteOeRHdHzYa7d31QCtt2De7ZhO8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785920757; c=relaxed/simple; bh=SXldiWeSBHh/RUC+pz/Z3pn8xriVxkGMlcAH6wkwwtQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kyW29TK+yoBQCuDsOYCL5nsMaPyEktMQD2UgYbnLpp1NJACqM2rv3gw0vzdFechMHD7H5XhoI5V8fvfikUc1TIJlAWNjIrDJXc3TwnZpeDfUc+aZ+O5nQ2Y2DEFzSdTU0mEhrNlao2N8qmN0FhwU5kXtpjZNCj7WeGpnCvg/M78= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FVDb8ACi; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=epMZSieD; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FVDb8ACi"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="epMZSieD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785920750; 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=AJv5koF079AhpRKjQRIs6WVbtzHWEnWNzOeKXg3GqUM=; b=FVDb8ACi6tKK/a3SG0YAtKt8OlC0PFwrBIMz4t4OGbAr8MgS+gt3Fl5TLFkSG1ymVGMbx3 xYTAz5+qFzEU8iLjO4V27bsGVkeL38mM3hWAjG5/7J8bnmhRSY5qI1TEtqaxB/fYRoaIuf BSf4VHlyNG8XLwuK+OulUNchArekeUs= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-271-ndFiLKEFPSClMqEWFHmPtw-1; Wed, 05 Aug 2026 05:05:48 -0400 X-MC-Unique: ndFiLKEFPSClMqEWFHmPtw-1 X-Mimecast-MFC-AGG-ID: ndFiLKEFPSClMqEWFHmPtw_1785920748 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4955843c6cdso6268875e9.1 for ; Wed, 05 Aug 2026 02:05:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1785920748; x=1786525548; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AJv5koF079AhpRKjQRIs6WVbtzHWEnWNzOeKXg3GqUM=; b=epMZSieD2PtVv3ZVBw4pVSHrly9CR95y9r9Y49rkuTZ3gz2/l9pbqp6PDK0UTSLoMY haIbuXzMzMzqMLsPvuuQmGwJjahJWr4e8YgblS1LpdIDNBsNAka+JQnuU69fckbEzi55 M/AWlZAJxStiqfjDs5Cl3a5YkGVTcb4evIr4aZ7B/wx12HrFn43zqYWbmfzg0xHStgjO vTbAjbaBql8ttQ6qsQUmwgzElHVaRx/4Hh1+jcidrlocpD9xrenqGSoaqXBy9Tp5291Z kv9p+ydjBKm6YYoTQMbuVRZctT6cTi9z7fEWFsUtreAh3f78Zt6IxTyohYl8yP9aXWE2 olog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785920748; x=1786525548; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AJv5koF079AhpRKjQRIs6WVbtzHWEnWNzOeKXg3GqUM=; b=q5gxb4fVo3CFL2j2NaOtniNHdcwtcVkuLQvOlisc11b6RO6Ol774mKofH1Muuk9duI MMCKX9T0WmD39TZ2rYkTMvjWvkM9jmKG83BvKoZWF2vzpm8GfaokzUFhwlTP0eBngpd4 Y6V9NgziJukLrkJsBcl+VtnUsm1bUXsbi6FNRztDFWb2fMUotobHLPntYhQzZmWrrPrm BbnWmwepFinSsoz8OHVaVuuny2vyrnSYInNSP+4aQedQmFIpcJhu7zAsEr1TysPL5ygf AeLOd8/VukxHTMmnq4KWXyUS+/7iG23xuE/uRKFe9C9Qik0567OYJT5Q1XXams2kddXg AfLg== X-Forwarded-Encrypted: i=1; AHgh+Rp2TZm0rJzDPEn6UPOv1SV7AdpS6Ur0WInZfyb1fpAQMtX3U+OsFlIVdJvZSYimcR0EKAsRDViBYmORTqU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw99GzpGydTMc388dFNLz6OgRal1+CmukCAi7w6vPslO57/QCQn lpYb+DTTjHFxNw5pdS9hKMWXtWoHTwqycF7meblFmjVAkdbZuAeZPL6apeohSZbN8ZnJC9FU7K+ AmJCmEUbz++YSE6pnl9ISlCEierETzKrXAeojJHrLSfVFTYYSvrZpgNprp17PyymxMQ== X-Gm-Gg: AR+sD12iYEwDUFUv5jMmtHmpoeaotfuHhQCXR3qfqWSi9wVNDg473hR+eb4djIctzPa spHp5whwAVOrfmtFT6AuCIVLLdUKOR7UuQZ9lfoxYM1nfJSdvAmrSVVSLgRp31QJovsMWqlKBmm 6cT4lfADYp5w4PU/MVagu3lnPajXhZPN8NKYYAtY+O6SxkF9RDRaK2/DOXrussCnvVwXm4XIr7Z wXVodw5XDPB2It7ac7/FpZ5vj4XIhxXeza/OCOknfEkgCcJwWr9WcoGEBXalfc35TxyJV+K4VSP ykzFpxr5rQXzcuCbOC4FyD30U1uTmByZGwUkLAbM85ssNcyQkJoZzmA5Ibl+JsmF+1zRbnbu25Q 5YTym/QXJhIpYgaHEN1nOlAJTYgr7hmKRuKEBB6rmv55DB4zh+1lHk3k1WpjxhiXyt2Waq+2oYj Q= X-Received: by 2002:a05:600c:c490:b0:493:c337:db0e with SMTP id 5b1f17b1804b1-4994e7ece20mr57702765e9.18.1785920747592; Wed, 05 Aug 2026 02:05:47 -0700 (PDT) X-Received: by 2002:a05:600c:c490:b0:493:c337:db0e with SMTP id 5b1f17b1804b1-4994e7ece20mr57701825e9.18.1785920747044; Wed, 05 Aug 2026 02:05:47 -0700 (PDT) Received: from [192.168.188.103] (ip239-44-231-195.pool-bba.aruba.it. [195.231.44.239]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4994e04db3asm84916885e9.15.2026.08.05.02.05.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Aug 2026 02:05:46 -0700 (PDT) Message-ID: <14b8701a-44a6-40dc-b46a-46096ea5bca2@redhat.com> Date: Wed, 5 Aug 2026 11:05:45 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] netdevsim: fix deadlock in nsim_bus_dev_max_vfs_write() To: Slawomir Stepien Cc: syzbot , syzkaller-bugs@googlegroups.com, Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot@lists.linux.dev References: Content-Language: en-US From: Paolo Abeni In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 8/5/26 10:55 AM, Slawomir Stepien wrote: > On sie 04, 2026 16:33, Paolo Abeni wrote: >> On 7/31/26 11:55 AM, syzbot wrote: >>> From: Slawomir Stepien >>> >>> There is an ABBA deadlock between the devlink instance lock and the debugfs >>> active file reference mechanism. >>> >>> When a device is being removed (e.g., via nsim_drv_remove()), the driver >>> acquires the devlink instance lock and then calls >>> debugfs_remove_recursive(). This function blocks waiting for all active >>> file operations on the debugfs files to complete. >>> >>> Concurrently, if a user writes to the "max_vfs" debugfs file, the VFS layer >>> acquires an active reference to the file. The write handler, >>> nsim_bus_dev_max_vfs_write(), then attempts to acquire the devlink instance >>> lock, which is already held by the removal task. >>> >>> This creates a circular dependency resulting in a deadlock: >>> >>> INFO: task blocked for more than 143 seconds. >>> Call Trace: >>> wait_for_completion+0x2ca/0x5e0 kernel/sched/completion.c:153 >>> __debugfs_file_removed fs/debugfs/inode.c:751 [inline] >>> remove_one+0x2df/0x3b0 fs/debugfs/inode.c:758 >>> __simple_recursive_removal+0x215/0x520 fs/libfs.c:623 >>> debugfs_remove+0x5b/0x70 fs/debugfs/inode.c:781 >>> nsim_dev_debugfs_exit drivers/net/netdevsim/dev.c:372 [inline] >>> nsim_drv_remove+0xc0/0x170 drivers/net/netdevsim/dev.c:1803 >>> >>> INFO: task blocked for more than 143 seconds. >>> Call Trace: >>> __mutex_lock+0x7bf/0x1550 kernel/locking/mutex.c:821 >>> nsim_bus_dev_max_vfs_write+0x229/0x3d0 drivers/net/netdevsim/dev.c:276 >>> full_proxy_write+0x127/0x1f0 fs/debugfs/file.c:388 >>> vfs_write+0x296/0xba0 fs/read_write.c:685 >>> >>> To fix this, use devl_trylock() in nsim_bus_dev_max_vfs_write() instead of >>> devl_lock(). If the lock cannot be acquired, return -EBUSY. This aborts the >>> write operation, releases the debugfs active file reference, and allows the >>> pending debugfs_remove_recursive() to proceed. >>> >>> Assisted-by: Gemini:gemini-3.5-flash Gemini:gemini-3.1-pro-preview syzbot >>> Reported-by: syzbot+3147c5de186107ffc7a1@syzkaller.appspotmail.com >>> Closes: https://syzkaller.appspot.com/bug?extid=3147c5de186107ffc7a1 >>> Link: https://syzkaller.appspot.com/ai_job?id=fcdda182-bebf-49ab-ada0-d4d2e814ebf7 >>> Signed-off-by: Slawomir Stepien >>> >>> --- >>> diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c >>> index aed9ad5f1..421cd7327 100644 >>> --- a/drivers/net/netdevsim/dev.c >>> +++ b/drivers/net/netdevsim/dev.c >>> @@ -273,7 +273,11 @@ static ssize_t nsim_bus_dev_max_vfs_write(struct file *file, >>> return -ENOMEM; >>> >>> nsim_dev = file->private_data; >>> - devl_lock(priv_to_devlink(nsim_dev)); >>> + if (!devl_trylock(priv_to_devlink(nsim_dev))) { >>> + ret = -EBUSY; >> >> I think this should return restart_syscall(). This kind of schema is >> calling for trouble, but for netdevsim should be okish. > > Thanks Paolo for your comment! > > Can you explain a bit more? What is your reasoning here? Is it, that we expect that we could have > the lock in e.g. 1ns, so it is worth restarting without bothering userspace[1]? > > I see a lot of: > > if (!rtnl_trylock()) > return restart_syscall(); > > Why this pattern is so popular? Is it for the same reason as above? > > [1] https://kernel-internals.org/syscalls/restart-block/ If you don't restart, the write will randomly fail when the lock is contended, as reported by sashiko gemini: https://sashiko.dev/#/patchset/b7bf56ea-7522-4163-acd5-aaa69ad03b3a%40mail.kernel.org the user-experience will be terrible at best. Also, I missed this other report initially: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/b7bf56ea-7522-4163-acd5-aaa69ad03b3a%40mail.kernel.org it looks like the above is not a complete fix. /P