linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ntb: Add mutex to make link_event_callback executed linearly.
@ 2025-08-25  9:15 fuyuanli
  2025-08-25 15:06 ` Dave Jiang
  2025-08-25 16:18 ` Logan Gunthorpe
  0 siblings, 2 replies; 5+ messages in thread
From: fuyuanli @ 2025-08-25  9:15 UTC (permalink / raw)
  To: jdmason, dave.jiang, allenbh; +Cc: ntb, linux-kernel, fuyuanli0722

Since the CPU selected by schedule_work is uncertain, multiple link_event
callbacks may be executed at same time. For example, after peer's link is
up, it is down quickly before local link_work completed. If link_cleanup
is added to the workqueue of another CPU, then link_work and link_cleanup
may be executed at the same time. So add a mutex to prevent them from being
executed concurrently.

Signed-off-by: fuyuanli <fuyuanli@didiglobal.com>
---
v2:
1) use guard() instead of lock & unlock functions.

v1:
Link: https://lore.kernel.org/all/aKiBi4ZDlbgzed%2Fz@didi-ThinkCentre-M930t-N000/
---
 drivers/ntb/ntb_transport.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 4f775c3e218f..eb875e3db2e3 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -59,6 +59,7 @@
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/uaccess.h>
+#include <linux/mutex.h>
 #include "linux/ntb.h"
 #include "linux/ntb_transport.h"
 
@@ -241,6 +242,9 @@ struct ntb_transport_ctx {
 	struct work_struct link_cleanup;
 
 	struct dentry *debugfs_node_dir;
+
+	/* Make sure workq of link event be executed serially */
+	struct mutex link_event_lock;
 };
 
 enum {
@@ -1024,6 +1028,7 @@ static void ntb_transport_link_cleanup_work(struct work_struct *work)
 	struct ntb_transport_ctx *nt =
 		container_of(work, struct ntb_transport_ctx, link_cleanup);
 
+	guard(mutex)(&nt->link_event_lock);
 	ntb_transport_link_cleanup(nt);
 }
 
@@ -1047,6 +1052,8 @@ static void ntb_transport_link_work(struct work_struct *work)
 	u32 val;
 	int rc = 0, i, spad;
 
+	guard(mutex)(&nt->link_event_lock);
+
 	/* send the local info, in the opposite order of the way we read it */
 
 	if (nt->use_msi) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ntb: Add mutex to make link_event_callback executed linearly.
  2025-08-25  9:15 [PATCH v2] ntb: Add mutex to make link_event_callback executed linearly fuyuanli
@ 2025-08-25 15:06 ` Dave Jiang
  2025-09-03  2:20   ` yuanli fu
  2025-08-25 16:18 ` Logan Gunthorpe
  1 sibling, 1 reply; 5+ messages in thread
From: Dave Jiang @ 2025-08-25 15:06 UTC (permalink / raw)
  To: jdmason, allenbh, ntb, linux-kernel, fuyuanli0722



On 8/25/25 2:15 AM, fuyuanli wrote:
> Since the CPU selected by schedule_work is uncertain, multiple link_event
> callbacks may be executed at same time. For example, after peer's link is
> up, it is down quickly before local link_work completed. If link_cleanup
> is added to the workqueue of another CPU, then link_work and link_cleanup
> may be executed at the same time. So add a mutex to prevent them from being
> executed concurrently.
> 
> Signed-off-by: fuyuanli <fuyuanli@didiglobal.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
> v2:
> 1) use guard() instead of lock & unlock functions.
> 
> v1:
> Link: https://lore.kernel.org/all/aKiBi4ZDlbgzed%2Fz@didi-ThinkCentre-M930t-N000/
> ---
>  drivers/ntb/ntb_transport.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index 4f775c3e218f..eb875e3db2e3 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
> @@ -59,6 +59,7 @@
>  #include <linux/slab.h>
>  #include <linux/types.h>
>  #include <linux/uaccess.h>
> +#include <linux/mutex.h>
>  #include "linux/ntb.h"
>  #include "linux/ntb_transport.h"
>  
> @@ -241,6 +242,9 @@ struct ntb_transport_ctx {
>  	struct work_struct link_cleanup;
>  
>  	struct dentry *debugfs_node_dir;
> +
> +	/* Make sure workq of link event be executed serially */
> +	struct mutex link_event_lock;
>  };
>  
>  enum {
> @@ -1024,6 +1028,7 @@ static void ntb_transport_link_cleanup_work(struct work_struct *work)
>  	struct ntb_transport_ctx *nt =
>  		container_of(work, struct ntb_transport_ctx, link_cleanup);
>  
> +	guard(mutex)(&nt->link_event_lock);
>  	ntb_transport_link_cleanup(nt);
>  }
>  
> @@ -1047,6 +1052,8 @@ static void ntb_transport_link_work(struct work_struct *work)
>  	u32 val;
>  	int rc = 0, i, spad;
>  
> +	guard(mutex)(&nt->link_event_lock);
> +
>  	/* send the local info, in the opposite order of the way we read it */
>  
>  	if (nt->use_msi) {


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ntb: Add mutex to make link_event_callback executed linearly.
  2025-08-25  9:15 [PATCH v2] ntb: Add mutex to make link_event_callback executed linearly fuyuanli
  2025-08-25 15:06 ` Dave Jiang
@ 2025-08-25 16:18 ` Logan Gunthorpe
  1 sibling, 0 replies; 5+ messages in thread
From: Logan Gunthorpe @ 2025-08-25 16:18 UTC (permalink / raw)
  To: jdmason, dave.jiang, allenbh, ntb, linux-kernel, fuyuanli0722



On 2025-08-25 03:15, fuyuanli wrote:
> Since the CPU selected by schedule_work is uncertain, multiple link_event
> callbacks may be executed at same time. For example, after peer's link is
> up, it is down quickly before local link_work completed. If link_cleanup
> is added to the workqueue of another CPU, then link_work and link_cleanup
> may be executed at the same time. So add a mutex to prevent them from being
> executed concurrently.
> 
> Signed-off-by: fuyuanli <fuyuanli@didiglobal.com>

Looks good to me, thanks

Reviewed-by: Logan Gunthorpe <logang@deltatee.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ntb: Add mutex to make link_event_callback executed linearly.
  2025-08-25 15:06 ` Dave Jiang
@ 2025-09-03  2:20   ` yuanli fu
  2025-09-03 15:26     ` Dave Jiang
  0 siblings, 1 reply; 5+ messages in thread
From: yuanli fu @ 2025-09-03  2:20 UTC (permalink / raw)
  To: Dave Jiang; +Cc: jdmason, allenbh, ntb, linux-kernel

Dave Jiang <dave.jiang@intel.com> 于2025年8月25日周一 23:06写道:
>
>
>
> On 8/25/25 2:15 AM, fuyuanli wrote:
> > Since the CPU selected by schedule_work is uncertain, multiple link_event
> > callbacks may be executed at same time. For example, after peer's link is
> > up, it is down quickly before local link_work completed. If link_cleanup
> > is added to the workqueue of another CPU, then link_work and link_cleanup
> > may be executed at the same time. So add a mutex to prevent them from being
> > executed concurrently.
> >
> > Signed-off-by: fuyuanli <fuyuanli@didiglobal.com>
>
> Reviewed-by: Dave Jiang <dave.jiang@intel.com>

Hi Dave,

Hope you are doing well.

Just wanted to gently follow up on this patch which you had acked
before. Is there
anything else I can do to help get this merged? Perhaps it needs a rebase on a
different tree?

Thanks for your time and all your work!

Best regards,
Yuanli Fu


>
> > ---
> > v2:
> > 1) use guard() instead of lock & unlock functions.
> >
> > v1:
> > Link: https://lore.kernel.org/all/aKiBi4ZDlbgzed%2Fz@didi-ThinkCentre-M930t-N000/
> > ---
> >  drivers/ntb/ntb_transport.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> > index 4f775c3e218f..eb875e3db2e3 100644
> > --- a/drivers/ntb/ntb_transport.c
> > +++ b/drivers/ntb/ntb_transport.c
> > @@ -59,6 +59,7 @@
> >  #include <linux/slab.h>
> >  #include <linux/types.h>
> >  #include <linux/uaccess.h>
> > +#include <linux/mutex.h>
> >  #include "linux/ntb.h"
> >  #include "linux/ntb_transport.h"
> >
> > @@ -241,6 +242,9 @@ struct ntb_transport_ctx {
> >       struct work_struct link_cleanup;
> >
> >       struct dentry *debugfs_node_dir;
> > +
> > +     /* Make sure workq of link event be executed serially */
> > +     struct mutex link_event_lock;
> >  };
> >
> >  enum {
> > @@ -1024,6 +1028,7 @@ static void ntb_transport_link_cleanup_work(struct work_struct *work)
> >       struct ntb_transport_ctx *nt =
> >               container_of(work, struct ntb_transport_ctx, link_cleanup);
> >
> > +     guard(mutex)(&nt->link_event_lock);
> >       ntb_transport_link_cleanup(nt);
> >  }
> >
> > @@ -1047,6 +1052,8 @@ static void ntb_transport_link_work(struct work_struct *work)
> >       u32 val;
> >       int rc = 0, i, spad;
> >
> > +     guard(mutex)(&nt->link_event_lock);
> > +
> >       /* send the local info, in the opposite order of the way we read it */
> >
> >       if (nt->use_msi) {
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ntb: Add mutex to make link_event_callback executed linearly.
  2025-09-03  2:20   ` yuanli fu
@ 2025-09-03 15:26     ` Dave Jiang
  0 siblings, 0 replies; 5+ messages in thread
From: Dave Jiang @ 2025-09-03 15:26 UTC (permalink / raw)
  To: yuanli fu; +Cc: jdmason, allenbh, ntb, linux-kernel



On 9/2/25 7:20 PM, yuanli fu wrote:
> Dave Jiang <dave.jiang@intel.com> 于2025年8月25日周一 23:06写道:
>>
>>
>>
>> On 8/25/25 2:15 AM, fuyuanli wrote:
>>> Since the CPU selected by schedule_work is uncertain, multiple link_event
>>> callbacks may be executed at same time. For example, after peer's link is
>>> up, it is down quickly before local link_work completed. If link_cleanup
>>> is added to the workqueue of another CPU, then link_work and link_cleanup
>>> may be executed at the same time. So add a mutex to prevent them from being
>>> executed concurrently.
>>>
>>> Signed-off-by: fuyuanli <fuyuanli@didiglobal.com>
>>
>> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> 
> Hi Dave,
> 
> Hope you are doing well.
> 
> Just wanted to gently follow up on this patch which you had acked
> before. Is there
> anything else I can do to help get this merged? Perhaps it needs a rebase on a
> different tree?

Jon will merge it when he has a chance.

> 
> Thanks for your time and all your work!
> 
> Best regards,
> Yuanli Fu
> 
> 
>>
>>> ---
>>> v2:
>>> 1) use guard() instead of lock & unlock functions.
>>>
>>> v1:
>>> Link: https://lore.kernel.org/all/aKiBi4ZDlbgzed%2Fz@didi-ThinkCentre-M930t-N000/
>>> ---
>>>  drivers/ntb/ntb_transport.c | 7 +++++++
>>>  1 file changed, 7 insertions(+)
>>>
>>> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
>>> index 4f775c3e218f..eb875e3db2e3 100644
>>> --- a/drivers/ntb/ntb_transport.c
>>> +++ b/drivers/ntb/ntb_transport.c
>>> @@ -59,6 +59,7 @@
>>>  #include <linux/slab.h>
>>>  #include <linux/types.h>
>>>  #include <linux/uaccess.h>
>>> +#include <linux/mutex.h>
>>>  #include "linux/ntb.h"
>>>  #include "linux/ntb_transport.h"
>>>
>>> @@ -241,6 +242,9 @@ struct ntb_transport_ctx {
>>>       struct work_struct link_cleanup;
>>>
>>>       struct dentry *debugfs_node_dir;
>>> +
>>> +     /* Make sure workq of link event be executed serially */
>>> +     struct mutex link_event_lock;
>>>  };
>>>
>>>  enum {
>>> @@ -1024,6 +1028,7 @@ static void ntb_transport_link_cleanup_work(struct work_struct *work)
>>>       struct ntb_transport_ctx *nt =
>>>               container_of(work, struct ntb_transport_ctx, link_cleanup);
>>>
>>> +     guard(mutex)(&nt->link_event_lock);
>>>       ntb_transport_link_cleanup(nt);
>>>  }
>>>
>>> @@ -1047,6 +1052,8 @@ static void ntb_transport_link_work(struct work_struct *work)
>>>       u32 val;
>>>       int rc = 0, i, spad;
>>>
>>> +     guard(mutex)(&nt->link_event_lock);
>>> +
>>>       /* send the local info, in the opposite order of the way we read it */
>>>
>>>       if (nt->use_msi) {
>>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-09-03 15:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-25  9:15 [PATCH v2] ntb: Add mutex to make link_event_callback executed linearly fuyuanli
2025-08-25 15:06 ` Dave Jiang
2025-09-03  2:20   ` yuanli fu
2025-09-03 15:26     ` Dave Jiang
2025-08-25 16:18 ` Logan Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).