Re: [PATCH net v4] net: lapb: Add locking to the lapb module
From: Xie He <hidden>
Date: 2021-01-21 06:02:16
Also in:
lkml
On Wed, Jan 20, 2021 at 12:42 PM Xie He [off-list ref] wrote:
With this patch, there is still a problem that lapb_unregister may run concurrently with other LAPB API functions (such as lapb_data_received). This other LAPB API function can get the lapb->lock after lapb->lock is released by lapb_unregister, and continue to do its work. This is not correct. We can fix this problem by adding a new field "bool stop" to "struct lapb_cb" (just like "bool t1timer_stop, t2timer_stop"), and make every API function abort whenever it sees lapb->stop == true after getting the lock. Alternatively we can also require the callers (the LAPB drivers) to never call lapb_unregister concurrently with other LAPB APIs. They should make sure all LAPB API functions are only called after lapb_register ends and before lapb_unregister starts. This is a reasonable requirement, because if they don't follow this requirement, even if we do the fix in the LAPB module (as said above), the LAPB driver will still get the "LAPB_BADTOKEN" error from the LAPB module. This is not desirable and I think LAPB drivers should avoid this from happening. So I think this problem may not need to be fixed here in the LAPB module because the LAPB drivers should deal with this problem anyway.
Never mind, I have sent a v5 to deal with this problem. In v5, I made lapb_unregister wait for the "lapb" refcnt to drop, so that we can make sure all other API calls have finished. Please see my v5.