Skip to contentSkip to conversation

kernel/user.c: fix build when POLL not enabled

PATCH In review Randy Dunlap 3 participants 4 messages Aug 3, 2021 – Aug 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/user.c: fix build when POLL not enabled

Fix build errors in kernel/user.c when CONFIG_EPOLL is not set/enabled.

../kernel/user.c: In function ‘free_user’:
../kernel/user.c:141:30: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?

  percpu_counter_destroy(&up->epoll_watches);
                              ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                 from ../kernel/user.c:17:
../kernel/user.c: In function ‘alloc_uid’:
../kernel/user.c:189:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
   if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
                                 ^
../kernel/user.c:203:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
    percpu_counter_destroy(&new->epoll_watches);
                                 ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                 from ../kernel/user.c:17:
../kernel/user.c: In function ‘uid_cache_init’:
../kernel/user.c:225:37: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
  if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
                                     ^

Also fix type: "cpunter" -> "counter" in a panic message.

Fixes e75b89477811 ("fs/epoll: use a per-cpu counter for user's watches count")
Cc Andrew Morton <[email protected]>
Cc Nick Piggin <[email protected]>
Cc Mark Brown <[email protected]>
---
 kernel/user.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/user.c +9 -1
@@ -137,9 +137,11 @@ static void free_user(struct user_struct
 	__releases(&uidhash_lock)
 {
 	uid_hash_remove(up);
+#ifdef CONFIG_EPOLL
 	spin_unlock_irqrestore(&uidhash_lock, flags);
 	percpu_counter_destroy(&up->epoll_watches);
 	kmem_cache_free(uid_cachep, up);
+#endif
 }
 
 /*
@@ -186,10 +188,12 @@ struct user_struct *alloc_uid(kuid_t uid
 
 		new->uid = uid;
 		refcount_set(&new->__count, 1);
+#ifdef CONFIG_EPOLL
 		if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
 			kmem_cache_free(uid_cachep, new);
 			return NULL;
 		}
+#endif
 		ratelimit_state_init(&new->ratelimit, HZ, 100);
 		ratelimit_set_flags(&new->ratelimit, RATELIMIT_MSG_ON_RELEASE);
 
@@ -200,7 +204,9 @@ struct user_struct *alloc_uid(kuid_t uid
 		spin_lock_irq(&uidhash_lock);
 		up = uid_hash_find(uid, hashent);
 		if (up) {
+#ifdef CONFIG_EPOLL
 			percpu_counter_destroy(&new->epoll_watches);
+#endif
 			kmem_cache_free(uid_cachep, new);
 		} else {
 			uid_hash_insert(new, hashent);
@@ -222,8 +228,10 @@ static int __init uid_cache_init(void)
 	for(n = 0; n < UIDHASH_SZ; ++n)
 		INIT_HLIST_HEAD(uidhash_table + n);
 
+#ifdef CONFIG_EPOLL
 	if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
-		panic("percpu cpunter alloc failed");
+		panic("percpu counter alloc failed");
+#endif
 
 	/* Insert the root user immediately (init already runs as root) */
 	spin_lock_irq(&uidhash_lock);
#1 lore raw

Excerpts from Randy Dunlap's message of August 4, 2021 6:46 am:

Quoted 21 lines

Fix build errors in kernel/user.c when CONFIG_EPOLL is not set/enabled.

../kernel/user.c: In function ‘free_user’:
../kernel/user.c:141:30: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?

  percpu_counter_destroy(&up->epoll_watches);
                              ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                 from ../kernel/user.c:17:
../kernel/user.c: In function ‘alloc_uid’:
../kernel/user.c:189:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
   if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
                                 ^
../kernel/user.c:203:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
    percpu_counter_destroy(&new->epoll_watches);
                                 ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                 from ../kernel/user.c:17:
../kernel/user.c: In function ‘uid_cache_init’:
../kernel/user.c:225:37: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
  if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
                                     ^
Quoted 1 line

Also fix type: "cpunter" -> "counter" in a panic message.

Gah, thanks Randy. The ifdefs aren't horrible but could I suggest a slight tweak?

--
From: Randy Dunlap <[email protected]>
Subject: [PATCH] kernel/user.c: fix build when EPOLL not enabled

Fix build errors in kernel/user.c when CONFIG_EPOLL is not set/enabled.

../kernel/user.c: In function ‘free_user’:
../kernel/user.c:141:30: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?

  percpu_counter_destroy(&up->epoll_watches);
                              ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                 from ../kernel/user.c:17:
../kernel/user.c: In function ‘alloc_uid’:
../kernel/user.c:189:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
   if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
                                 ^
../kernel/user.c:203:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
    percpu_counter_destroy(&new->epoll_watches);
                                 ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                 from ../kernel/user.c:17:
../kernel/user.c: In function ‘uid_cache_init’:
../kernel/user.c:225:37: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
  if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
                                     ^

Also fix type: "cpunter" -"counter" in a panic message.

Fixes e75b89477811 ("fs/epoll: use a per-cpu counter for user's watches count")
[np: move ifdefs into wrapper functions, slightly improve panic message]
Cc Andrew Morton <[email protected]>
Cc Nick Piggin <[email protected]>
Cc Mark Brown <[email protected]>
---
 kernel/user.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
kernel/user.c +20 -5
index a2673f940506..57d53568cb33 100644
@@ -129,6 +129,21 @@ static struct user_struct *uid_hash_find(kuid_t uid, struct hlist_head *hashent)
 	return NULL;
 }
 
+static int user_epoll_alloc(struct user_struct *up)
+{
+#ifdef CONFIG_EPOLL
+	return percpu_counter_init(&up->epoll_watches, 0, GFP_KERNEL);
+#endif
+	return 0;
+}
+
+static void user_epoll_free(struct user_struct *up)
+{
+#ifdef CONFIG_EPOLL
+	percpu_counter_destroy(&up->epoll_watches);
+#endif
+}
+
 /* IRQs are disabled and uidhash_lock is held upon function entry.
  * IRQ state (as stored in flags) is restored and uidhash_lock released
  * upon function exit.
@@ -138,7 +153,7 @@ static void free_user(struct user_struct *up, unsigned long flags)
 {
 	uid_hash_remove(up);
 	spin_unlock_irqrestore(&uidhash_lock, flags);
-	percpu_counter_destroy(&up->epoll_watches);
+	user_epoll_free(up);
 	kmem_cache_free(uid_cachep, up);
 }
 
@@ -186,7 +201,7 @@ struct user_struct *alloc_uid(kuid_t uid)
 
 		new->uid = uid;
 		refcount_set(&new->__count, 1);
-		if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
+		if (user_epoll_alloc(new)) {
 			kmem_cache_free(uid_cachep, new);
 			return NULL;
 		}
@@ -200,7 +215,7 @@ struct user_struct *alloc_uid(kuid_t uid)
 		spin_lock_irq(&uidhash_lock);
 		up = uid_hash_find(uid, hashent);
 		if (up) {
-			percpu_counter_destroy(&new->epoll_watches);
+			user_epoll_free(new);
 			kmem_cache_free(uid_cachep, new);
 		} else {
 			uid_hash_insert(new, hashent);
@@ -222,8 +237,8 @@ static int __init uid_cache_init(void)
 	for(n = 0; n < UIDHASH_SZ; ++n)
 		INIT_HLIST_HEAD(uidhash_table + n);
 
-	if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
-		panic("percpu cpunter alloc failed");
+	if (user_epoll_alloc(&root_user))
+		panic("root_user epoll percpu counter alloc failed");
 
 	/* Insert the root user immediately (init already runs as root) */
 	spin_lock_irq(&uidhash_lock);
Signature · 1 line
2.23.0
#2 lore raw
Quoted 24 lines · Nicholas Piggin

Excerpts from Randy Dunlap's message of August 4, 2021 6:46 am:

Quoted 21 lines

Fix build errors in kernel/user.c when CONFIG_EPOLL is not set/enabled.

../kernel/user.c: In function ‘free_user’:
../kernel/user.c:141:30: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?

   percpu_counter_destroy(&up->epoll_watches);
                               ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                  from ../kernel/user.c:17:
../kernel/user.c: In function ‘alloc_uid’:
../kernel/user.c:189:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
    if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
                                  ^
../kernel/user.c:203:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
     percpu_counter_destroy(&new->epoll_watches);
                                  ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                  from ../kernel/user.c:17:
../kernel/user.c: In function ‘uid_cache_init’:
../kernel/user.c:225:37: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
   if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
                                      ^
Quoted 1 line

Also fix type: "cpunter" -> "counter" in a panic message.

Quoted 2 lines

Gah, thanks Randy. The ifdefs aren't horrible but could I suggest a slight tweak?

Sure, no problem. Thanks.

Quoted 104 lines

--
From: Randy Dunlap <[email protected]>
Subject: [PATCH] kernel/user.c: fix build when EPOLL not enabled

Fix build errors in kernel/user.c when CONFIG_EPOLL is not set/enabled.

../kernel/user.c: In function ‘free_user’:
../kernel/user.c:141:30: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?

   percpu_counter_destroy(&up->epoll_watches);
                               ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                  from ../kernel/user.c:17:
../kernel/user.c: In function ‘alloc_uid’:
../kernel/user.c:189:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
    if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
                                  ^
../kernel/user.c:203:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
     percpu_counter_destroy(&new->epoll_watches);
                                  ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                  from ../kernel/user.c:17:
../kernel/user.c: In function ‘uid_cache_init’:
../kernel/user.c:225:37: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
   if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
                                      ^

Also fix type: "cpunter" -"counter" in a panic message.

Fixes e75b89477811 ("fs/epoll: use a per-cpu counter for user's watches count")
[np: move ifdefs into wrapper functions, slightly improve panic message]
Cc Andrew Morton <[email protected]>
Cc Nick Piggin <[email protected]>
Cc Mark Brown <[email protected]>
---
  kernel/user.c | 25 ++++++++++++++++++++-----
  1 file changed, 20 insertions(+), 5 deletions(-)
kernel/user.c +20 -5
index a2673f940506..57d53568cb33 100644
@@ -129,6 +129,21 @@ static struct user_struct *uid_hash_find(kuid_t uid, struct hlist_head *hashent)
  	return NULL;
  }
 
+static int user_epoll_alloc(struct user_struct *up)
+{
+#ifdef CONFIG_EPOLL
+	return percpu_counter_init(&up->epoll_watches, 0, GFP_KERNEL);
+#endif
+	return 0;
+}
+
+static void user_epoll_free(struct user_struct *up)
+{
+#ifdef CONFIG_EPOLL
+	percpu_counter_destroy(&up->epoll_watches);
+#endif
+}
+
  /* IRQs are disabled and uidhash_lock is held upon function entry.
   * IRQ state (as stored in flags) is restored and uidhash_lock released
   * upon function exit.
@@ -138,7 +153,7 @@ static void free_user(struct user_struct *up, unsigned long flags)
  {
  	uid_hash_remove(up);
  	spin_unlock_irqrestore(&uidhash_lock, flags);
-	percpu_counter_destroy(&up->epoll_watches);
+	user_epoll_free(up);
  	kmem_cache_free(uid_cachep, up);
  }
 
@@ -186,7 +201,7 @@ struct user_struct *alloc_uid(kuid_t uid)
 
  		new->uid = uid;
  		refcount_set(&new->__count, 1);
-		if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
+		if (user_epoll_alloc(new)) {
  			kmem_cache_free(uid_cachep, new);
  			return NULL;
  		}
@@ -200,7 +215,7 @@ struct user_struct *alloc_uid(kuid_t uid)
  		spin_lock_irq(&uidhash_lock);
  		up = uid_hash_find(uid, hashent);
  		if (up) {
-			percpu_counter_destroy(&new->epoll_watches);
+			user_epoll_free(new);
  			kmem_cache_free(uid_cachep, new);
  		} else {
  			uid_hash_insert(new, hashent);
@@ -222,8 +237,8 @@ static int __init uid_cache_init(void)
  	for(n = 0; n < UIDHASH_SZ; ++n)
  		INIT_HLIST_HEAD(uidhash_table + n);
 
-	if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
-		panic("percpu cpunter alloc failed");
+	if (user_epoll_alloc(&root_user))
+		panic("root_user epoll percpu counter alloc failed");
 
  	/* Insert the root user immediately (init already runs as root) */
  	spin_lock_irq(&uidhash_lock);
Signature · 1 line
~Randy
#3 lore raw
In reply to Nicholas Piggin
Quoted 70 lines · Nicholas Piggin

Excerpts from Randy Dunlap's message of August 4, 2021 6:46 am:

Quoted 21 lines

Fix build errors in kernel/user.c when CONFIG_EPOLL is not set/enabled.

../kernel/user.c: In function ‘free_user’:
../kernel/user.c:141:30: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?

  percpu_counter_destroy(&up->epoll_watches);
                              ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                 from ../kernel/user.c:17:
../kernel/user.c: In function ‘alloc_uid’:
../kernel/user.c:189:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
   if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
                                 ^
../kernel/user.c:203:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
    percpu_counter_destroy(&new->epoll_watches);
                                 ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                 from ../kernel/user.c:17:
../kernel/user.c: In function ‘uid_cache_init’:
../kernel/user.c:225:37: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
  if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
                                     ^
Quoted 1 line

Also fix type: "cpunter" -> "counter" in a panic message.

Gah, thanks Randy. The ifdefs aren't horrible but could I suggest a slight tweak?

--
From: Randy Dunlap <[email protected]>
Subject: [PATCH] kernel/user.c: fix build when EPOLL not enabled

Fix build errors in kernel/user.c when CONFIG_EPOLL is not set/enabled.

../kernel/user.c: In function ‘free_user’:
../kernel/user.c:141:30: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?

  percpu_counter_destroy(&up->epoll_watches);
                              ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                 from ../kernel/user.c:17:
../kernel/user.c: In function ‘alloc_uid’:
../kernel/user.c:189:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
   if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
                                 ^
../kernel/user.c:203:33: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
    percpu_counter_destroy(&new->epoll_watches);
                                 ^~~~~~~~~~~~~
In file included from ../include/linux/sched/user.h:7:0,
                 from ../kernel/user.c:17:
../kernel/user.c: In function ‘uid_cache_init’:
../kernel/user.c:225:37: error: ‘struct user_struct’ has no member named ‘epoll_watches’; did you mean ‘nr_watches’?
  if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
                                     ^

Also fix type: "cpunter" -"counter" in a panic message.

Fixes e75b89477811 ("fs/epoll: use a per-cpu counter for user's watches count")
[np: move ifdefs into wrapper functions, slightly improve panic message]
Cc Andrew Morton <[email protected]>
Cc Nick Piggin <[email protected]>
Cc Mark Brown <[email protected]>
---
 kernel/user.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
kernel/user.c +0 -0
index a2673f940506..57d53568cb33 100644

kernel/user.c static struct user_struct *uid_hash_find(kuid_t uid, struct hlist_head *hashent) · line 137

Quoted 9 lines
kernel/user.c +6 -0
@@ -129,6 +129,21 @@ static struct user_struct *uid_hash_find(kuid_t uid, struct hlist_head *hashent)
 	return NULL;
 }
 
+static int user_epoll_alloc(struct user_struct *up)
+{
+#ifdef CONFIG_EPOLL
+	return percpu_counter_init(&up->epoll_watches, 0, GFP_KERNEL);
+#endif
+	return 0;
#else
	return 0;

#endif

Quoted 53 lines
kernel/user.c +14 -5
+}
+
+static void user_epoll_free(struct user_struct *up)
+{
+#ifdef CONFIG_EPOLL
+	percpu_counter_destroy(&up->epoll_watches);
+#endif
+}
+
 /* IRQs are disabled and uidhash_lock is held upon function entry.
  * IRQ state (as stored in flags) is restored and uidhash_lock released
  * upon function exit.
@@ -138,7 +153,7 @@ static void free_user(struct user_struct *up, unsigned long flags)
 {
 	uid_hash_remove(up);
 	spin_unlock_irqrestore(&uidhash_lock, flags);
-	percpu_counter_destroy(&up->epoll_watches);
+	user_epoll_free(up);
 	kmem_cache_free(uid_cachep, up);
 }
 
@@ -186,7 +201,7 @@ struct user_struct *alloc_uid(kuid_t uid)
 
 		new->uid = uid;
 		refcount_set(&new->__count, 1);
-		if (percpu_counter_init(&new->epoll_watches, 0, GFP_KERNEL)) {
+		if (user_epoll_alloc(new)) {
 			kmem_cache_free(uid_cachep, new);
 			return NULL;
 		}
@@ -200,7 +215,7 @@ struct user_struct *alloc_uid(kuid_t uid)
 		spin_lock_irq(&uidhash_lock);
 		up = uid_hash_find(uid, hashent);
 		if (up) {
-			percpu_counter_destroy(&new->epoll_watches);
+			user_epoll_free(new);
 			kmem_cache_free(uid_cachep, new);
 		} else {
 			uid_hash_insert(new, hashent);
@@ -222,8 +237,8 @@ static int __init uid_cache_init(void)
 	for(n = 0; n < UIDHASH_SZ; ++n)
 		INIT_HLIST_HEAD(uidhash_table + n);
 
-	if (percpu_counter_init(&root_user.epoll_watches, 0, GFP_KERNEL))
-		panic("percpu cpunter alloc failed");
+	if (user_epoll_alloc(&root_user))
+		panic("root_user epoll percpu counter alloc failed");
 
 	/* Insert the root user immediately (init already runs as root) */
 	spin_lock_irq(&uidhash_lock);
Signature · 1 line
2.23.0