mirror of
https://github.com/torvalds/linux.git
synced 2026-10-07 19:16:02 +02:00
net/mlx5: devcom, Base component size on linked devices
mlx5_devcom_comp_get_size() returns the component's kref count. That
kref is bumped in mlx5_devcom_register_component() under comp_list_lock,
before the comp_dev is linked onto comp_dev_list_head under comp->sem.
The event broadcast (mlx5_devcom_locked_send_event()) walks that list.
Hence, a caller can read the expected size, but send_event won't be sent
to all peers. In the SD group registration path, this lets a member
broadcast its role-election event over an incomplete list, electing a
primary that never completes the group, is never marked ready, and
leaves the group with a stale primary.
Track the number of linked comp_devs in a dedicated counter, maintained
under comp->sem together with the list add/remove, and return it from
mlx5_devcom_comp_get_size().
Fixes: 9bb1ac8073 ("net/mlx5: devcom, Add component size getter")
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Akiva Goldberger <agoldberger@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260915113459.3934760-2-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
39c6580765
commit
d09e8f6465
|
|
@ -37,6 +37,7 @@ struct mlx5_devcom_comp {
|
|||
struct mlx5_devcom_key key;
|
||||
mlx5_devcom_event_handler_t handler;
|
||||
struct kref ref;
|
||||
int nr_devs;
|
||||
bool ready;
|
||||
struct rw_semaphore sem;
|
||||
struct lock_class_key lock_key;
|
||||
|
|
@ -170,6 +171,7 @@ devcom_alloc_comp_dev(struct mlx5_devcom_dev *devc,
|
|||
|
||||
down_write(&comp->sem);
|
||||
list_add_tail(&devcom->list, &comp->comp_dev_list_head);
|
||||
WRITE_ONCE(comp->nr_devs, comp->nr_devs + 1);
|
||||
up_write(&comp->sem);
|
||||
|
||||
return devcom;
|
||||
|
|
@ -182,6 +184,7 @@ devcom_free_comp_dev(struct mlx5_devcom_comp_dev *devcom)
|
|||
|
||||
down_write(&comp->sem);
|
||||
list_del(&devcom->list);
|
||||
WRITE_ONCE(comp->nr_devs, comp->nr_devs - 1);
|
||||
up_write(&comp->sem);
|
||||
|
||||
kref_put(&devcom->devc->ref, mlx5_devcom_dev_release);
|
||||
|
|
@ -284,7 +287,7 @@ int mlx5_devcom_comp_get_size(struct mlx5_devcom_comp_dev *devcom)
|
|||
{
|
||||
struct mlx5_devcom_comp *comp = devcom->comp;
|
||||
|
||||
return kref_read(&comp->ref);
|
||||
return READ_ONCE(comp->nr_devs);
|
||||
}
|
||||
|
||||
int mlx5_devcom_locked_send_event(struct mlx5_devcom_comp_dev *devcom,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user