Skip to content

Commit

Permalink
devlink: avoid potential loop in devlink_rel_nested_in_notify_work()
Browse files Browse the repository at this point in the history
[ Upstream commit 5808672 ]

In case devlink_rel_nested_in_notify_work() can not take the devlink
lock mutex. Convert the work to delayed work and in case of reschedule
do it jiffie later and avoid potential looping.

Suggested-by: Paolo Abeni <pabeni@redhat.com>
Fixes: c137743 ("devlink: introduce object and nested devlink relationship infra")
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20240205171114.338679-1-jiri@resnulli.us
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Jiri Pirko authored and gregkh committed Feb 16, 2024
1 parent 82ae47c commit 319d215
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions net/devlink/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct devlink_rel {
u32 obj_index;
devlink_rel_notify_cb_t *notify_cb;
devlink_rel_cleanup_cb_t *cleanup_cb;
struct work_struct notify_work;
struct delayed_work notify_work;
} nested_in;
};

Expand All @@ -70,7 +70,7 @@ static void __devlink_rel_put(struct devlink_rel *rel)
static void devlink_rel_nested_in_notify_work(struct work_struct *work)
{
struct devlink_rel *rel = container_of(work, struct devlink_rel,
nested_in.notify_work);
nested_in.notify_work.work);
struct devlink *devlink;

devlink = devlinks_xa_get(rel->nested_in.devlink_index);
Expand All @@ -96,13 +96,13 @@ static void devlink_rel_nested_in_notify_work(struct work_struct *work)
return;

reschedule_work:
schedule_work(&rel->nested_in.notify_work);
schedule_delayed_work(&rel->nested_in.notify_work, 1);
}

static void devlink_rel_nested_in_notify_work_schedule(struct devlink_rel *rel)
{
__devlink_rel_get(rel);
schedule_work(&rel->nested_in.notify_work);
schedule_delayed_work(&rel->nested_in.notify_work, 0);
}

static struct devlink_rel *devlink_rel_alloc(void)
Expand All @@ -123,8 +123,8 @@ static struct devlink_rel *devlink_rel_alloc(void)
}

refcount_set(&rel->refcount, 1);
INIT_WORK(&rel->nested_in.notify_work,
&devlink_rel_nested_in_notify_work);
INIT_DELAYED_WORK(&rel->nested_in.notify_work,
&devlink_rel_nested_in_notify_work);
return rel;
}

Expand Down

0 comments on commit 319d215

Please sign in to comment.