From: Fernando Fernandez Mancera <fmancera@suse.de>
To: Guikun Yang <yangguikun19@qq.com>, Jiri Pirko <jiri@nvidia.com>,
Jacob Keller <jacob.e.keller@intel.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [BUG] devlink: region trigger leaks a permanent snapshot id slot on every successful auto-id capture
Date: Mon, 26 Oct 2026 17:29:51 +0100 [thread overview]
Message-ID: <b24c7e91-7fba-428f-b76b-ba19b07ad1d1@suse.de> (raw)
In-Reply-To: <tencent_BE912BA710539F285F9FCF28E854ABEFCD07@qq.com>
On 10/25/26 5:27 AM, Guikun Yang wrote:
> Hi Jiri, Jacob,
>
> devlink_nl_cmd_region_trigger() (net/devlink/region.c) allocates a
> snapshot id via __devlink_region_snapshot_id_get() when the request
> does not carry DEVLINK_ATTR_REGION_SNAPSHOT_ID, then creates the
> snapshot. On the success path it returns without ever releasing the
> caller's reference, so the id's refcount stays at 2 instead of dropping
> to the snapshot-only 1.
>
> __devlink_region_snapshot_id_get() is documented as:
>
> * Note that the caller of this function counts as a 'user', in order to
> * avoid race conditions. The caller must release its hold on the
> * snapshot by using devlink_region_snapshot_id_put.
>
> The netlink trigger is its own caller, and nothing in the kernel holds
> the id after the command returns, so the hold is never released.
>
> Consequences, per successful auto-id trigger:
>
> xa_alloc(&devlink->snapshot_ids, id, xa_mk_value(1)) /* count = 1 */
> __devlink_region_snapshot_create() /* count = 2 */
> ... success, no put ...
>
> Later, when the snapshot is deleted, devlink_region_snapshot_del()
> calls __devlink_snapshot_id_decrement(), bringing the count to 1.
> Since it is not zero, the id is NOT erased from the xarray:
>
> * If the count reaches zero, erase this id from the xarray, freeing it
> * up for future re-use by devlink_region_snapshot_id_get().
>
> The slot stays occupied forever. Every subsequent attempt to use that
> particular id fails:
>
> - __devlink_snapshot_id_insert() rejects it with -EEXIST (xa_load()
> finds the stale entry), so a user can never explicitly re-create a
> snapshot with that id;
> - reading or deleting "the snapshot with that id" returns -ENOENT,
> so there is also no way to clean the stale entry up.
>
Yes, this is right. I am sending a patch. I reproduced it on netdevsim
and Intel E825-C with ice driver.
Not sure if it is worth writing a selftest, might consider it as a
follow-up.
Thanks,
Fernando.
next prev parent reply other threads:[~2026-10-26 16:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-25 4:27 Guikun Yang
2026-10-26 16:29 ` Fernando Fernandez Mancera [this message]
2026-10-26 21:20 ` Jacob Keller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b24c7e91-7fba-428f-b76b-ba19b07ad1d1@suse.de \
--to=fmancera@suse.de \
--cc=jacob.e.keller@intel.com \
--cc=jiri@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=yangguikun19@qq.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®