diff mbox series

[RFC,v4,01/11] eventfd: Increase the recursion depth of eventfd_signal()

Message ID 20210223115048.435-2-xieyongji@bytedance.com
State Superseded
Headers show
Series Introduce VDUSE - vDPA Device in Userspace | expand

Commit Message

Yongji Xie Feb. 23, 2021, 11:50 a.m. UTC
Increase the recursion depth of eventfd_signal() to 1. This
is the maximum recursion depth we have found so far.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
---
 fs/eventfd.c            | 2 +-
 include/linux/eventfd.h | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Jason Wang March 2, 2021, 6:44 a.m. UTC | #1
On 2021/2/23 7:50 下午, Xie Yongji wrote:
> Increase the recursion depth of eventfd_signal() to 1. This

> is the maximum recursion depth we have found so far.

>

> Signed-off-by: Xie Yongji <xieyongji@bytedance.com>



Acked-by: Jason Wang <jasowang@redhat.com>


It might be useful to explain how/when we can reach for this condition.

Thanks


> ---

>   fs/eventfd.c            | 2 +-

>   include/linux/eventfd.h | 5 ++++-

>   2 files changed, 5 insertions(+), 2 deletions(-)

>

> diff --git a/fs/eventfd.c b/fs/eventfd.c

> index e265b6dd4f34..cc7cd1dbedd3 100644

> --- a/fs/eventfd.c

> +++ b/fs/eventfd.c

> @@ -71,7 +71,7 @@ __u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n)

>   	 * it returns true, the eventfd_signal() call should be deferred to a

>   	 * safe context.

>   	 */

> -	if (WARN_ON_ONCE(this_cpu_read(eventfd_wake_count)))

> +	if (WARN_ON_ONCE(this_cpu_read(eventfd_wake_count) > EFD_WAKE_DEPTH))

>   		return 0;

>   

>   	spin_lock_irqsave(&ctx->wqh.lock, flags);

> diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h

> index fa0a524baed0..886d99cd38ef 100644

> --- a/include/linux/eventfd.h

> +++ b/include/linux/eventfd.h

> @@ -29,6 +29,9 @@

>   #define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)

>   #define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)

>   

> +/* Maximum recursion depth */

> +#define EFD_WAKE_DEPTH 1

> +

>   struct eventfd_ctx;

>   struct file;

>   

> @@ -47,7 +50,7 @@ DECLARE_PER_CPU(int, eventfd_wake_count);

>   

>   static inline bool eventfd_signal_count(void)

>   {

> -	return this_cpu_read(eventfd_wake_count);

> +	return this_cpu_read(eventfd_wake_count) > EFD_WAKE_DEPTH;

>   }

>   

>   #else /* CONFIG_EVENTFD */
Yongji Xie March 2, 2021, 10:32 a.m. UTC | #2
On Tue, Mar 2, 2021 at 2:44 PM Jason Wang <jasowang@redhat.com> wrote:
>
>
> On 2021/2/23 7:50 下午, Xie Yongji wrote:
> > Increase the recursion depth of eventfd_signal() to 1. This
> > is the maximum recursion depth we have found so far.
> >
> > Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
>
>
> Acked-by: Jason Wang <jasowang@redhat.com>
>
> It might be useful to explain how/when we can reach for this condition.
>

Fine.

Thanks,
Yongji
diff mbox series

Patch

diff --git a/fs/eventfd.c b/fs/eventfd.c
index e265b6dd4f34..cc7cd1dbedd3 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -71,7 +71,7 @@  __u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n)
 	 * it returns true, the eventfd_signal() call should be deferred to a
 	 * safe context.
 	 */
-	if (WARN_ON_ONCE(this_cpu_read(eventfd_wake_count)))
+	if (WARN_ON_ONCE(this_cpu_read(eventfd_wake_count) > EFD_WAKE_DEPTH))
 		return 0;
 
 	spin_lock_irqsave(&ctx->wqh.lock, flags);
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index fa0a524baed0..886d99cd38ef 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -29,6 +29,9 @@ 
 #define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
 #define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
 
+/* Maximum recursion depth */
+#define EFD_WAKE_DEPTH 1
+
 struct eventfd_ctx;
 struct file;
 
@@ -47,7 +50,7 @@  DECLARE_PER_CPU(int, eventfd_wake_count);
 
 static inline bool eventfd_signal_count(void)
 {
-	return this_cpu_read(eventfd_wake_count);
+	return this_cpu_read(eventfd_wake_count) > EFD_WAKE_DEPTH;
 }
 
 #else /* CONFIG_EVENTFD */