Skip to contentSkip to conversation

RCU usage in infiniband

Q Sebastian Andrzej Siewior 3 participants 6 messages Jul 8 InfiniBand

lore
Share & tools
lore
#0 lore raw

Hi,

I've been randomly starting at infiniband code and noticed it uses call_rcu() with a callback from its module.

| drivers/infiniband/hw/mlx5/devx.c: call_rcu(&event_sub->rcu, devx_free_subscription);
| drivers/infiniband/ulp/ipoib/ipoib_main.c: call_rcu(&neigh->rcu, ipoib_neigh_reclaim);

I don't see synchronize_rcu() and rcu_barrier() there so I've been asking myself what ensures that the callback completes before module is gone (via rmmod)? I would expect a rcu_barrier() in ipoib_cleanup_module() for instance.

Is the unload path so "late" that the callbacks run before the module is unmapped or is there something between the APIs that ensures this?

Sebastian

maintainer
#1 lore raw
Quoted 8 lines · Sebastian Andrzej Siewior

Hi,

I've been randomly starting at infiniband code and noticed it uses call_rcu() with a callback from its module.

| drivers/infiniband/hw/mlx5/devx.c: call_rcu(&event_sub->rcu, devx_free_subscription);
| drivers/infiniband/ulp/ipoib/ipoib_main.c: call_rcu(&neigh->rcu, ipoib_neigh_reclaim);

Quoted 7 lines

I don't see synchronize_rcu() and rcu_barrier() there so I've been asking myself what ensures that the callback completes before module is gone (via rmmod)? I would expect a rcu_barrier() in ipoib_cleanup_module() for instance.

Is the unload path so "late" that the callbacks run before the module is unmapped or is there something between the APIs that ensures this?

It wouldn't hurt to have a more explicit unload synchronize call, but there are already some existing ones on the path to unload a module that would cover anyhow

Jason

#2 lore raw
Quoted 14 lines · Jason Gunthorpe
Quoted 13 lines · Sebastian Andrzej Siewior

Hi,

I've been randomly starting at infiniband code and noticed it uses call_rcu() with a callback from its module.

| drivers/infiniband/hw/mlx5/devx.c: call_rcu(&event_sub->rcu, devx_free_subscription);
| drivers/infiniband/ulp/ipoib/ipoib_main.c: call_rcu(&neigh->rcu, ipoib_neigh_reclaim);

I don't see synchronize_rcu() and rcu_barrier() there so I've been asking myself what ensures that the callback completes before module is gone (via rmmod)? I would expect a rcu_barrier() in ipoib_cleanup_module() for instance.

Quoted 6 lines
Quoted 2 lines

Is the unload path so "late" that the callbacks run before the module is unmapped or is there something between the APIs that ensures this?

It wouldn't hurt to have a more explicit unload synchronize call, but there are already some existing ones on the path to unload a module that would cover anyhow

Where? Within the module core or somewhere within infiniband?

Quoted 1 line

Jason

Sebastian

maintainer
#3 lore raw
Quoted 15 lines · Sebastian Andrzej Siewior
Quoted 14 lines · Jason Gunthorpe
Quoted 13 lines · Sebastian Andrzej Siewior

Hi,

I've been randomly starting at infiniband code and noticed it uses call_rcu() with a callback from its module.

| drivers/infiniband/hw/mlx5/devx.c: call_rcu(&event_sub->rcu, devx_free_subscription);
| drivers/infiniband/ulp/ipoib/ipoib_main.c: call_rcu(&neigh->rcu, ipoib_neigh_reclaim);

I don't see synchronize_rcu() and rcu_barrier() there so I've been asking myself what ensures that the callback completes before module is gone (via rmmod)? I would expect a rcu_barrier() in ipoib_cleanup_module() for instance.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Is the unload path so "late" that the callbacks run before the module is unmapped or is there something between the APIs that ensures this?

It wouldn't hurt to have a more explicit unload synchronize call, but there are already some existing ones on the path to unload a module that would cover anyhow

Where? Within the module core or somewhere within infiniband?

Eg the uverbs path has a srcu synchronize IIRC before allowing the FDs to close which holds the module as well. But it probably isn't wise to rely on this

Jason

#4 lore raw
Quoted 5 lines · Jason Gunthorpe
Quoted 1 line

Where? Within the module core or somewhere within infiniband?

Eg the uverbs path has a srcu synchronize IIRC before allowing the FDs to close which holds the module as well. But it probably isn't wise to rely on this

But this is srcu. So this takes long enough so that we have a RCU grace period, too? But there is also RCU_LAZY which could stretch this a bit ;)

Quoted 1 line

Jason

Sebastian

#5 lore raw
Quoted 10 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Jason Gunthorpe
Quoted 1 line

Where? Within the module core or somewhere within infiniband?

Eg the uverbs path has a srcu synchronize IIRC before allowing the FDs to close which holds the module as well. But it probably isn't wise to rely on this

But this is srcu. So this takes long enough so that we have a RCU grace period, too? But there is also RCU_LAZY which could stretch this a bit ;)

Just to emphasize Sebastian's point here...

If a module uses call_rcu(), there needs to either be an rcu_barrier() or some explicit synchronization with the callbacks themselves before module-unload time. Any explicit synchronization must also include a wait for existing softirq handlers to complete, so rcu_barrier() is simpler and more maintainable.

Please note the rcu_barrier(). And that synchronize_rcu() is not a legitimate substitute for that rcu_barrier().

Similarly, if that module uses call_srcu(), there needs to either be an srcu_barrier() or explicit synchronization with the callbacks as mentioned above. Please note that neither rcu_barrier(), synchronize_rcu(), nor synchronize_srcu() are legitimate substitutes for that srcu_barrier().

The difference is that while rcu_barrier() waits for the completion of the callbacks queued by prior invocations of call_rcu(), synchronize_rcu() instead waits only for prior RCU readers to complete. So rcu_barrier() does not care about RCU readers and synchronize_rcu() does not care about RCU callbacks. And the same holds for SRCU.

Also, RCU does not wait for SRCU and vice versa.

Does that help?

Thanx, Paul