Skip to contentSkip to conversation

irq_work: Don't reinvent the wheel but use existing llist API

PATCH In review Frederic Weisbecker 3 participants 4 messages Oct 31, 2017 – Nov 12, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irq_work: Don't reinvent the wheel but use existing llist API

From: Byungchul Park <[email protected]>

Although llist provides proper APIs, they are not used. Make them used.

---
 kernel/irq_work.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/irq_work.c +1 -5
index bcf107c..e2ebe8c 100644
@@ -138,11 +138,7 @@ static void irq_work_run_list(struct llist_head *list)
 		return;
 
 	llnode = llist_del_all(list);
-	while (llnode != NULL) {
-		work = llist_entry(llnode, struct irq_work, llnode);
-
-		llnode = llist_next(llnode);
-
+	llist_for_each_entry(work, llnode, llnode) {
 		/*
 		 * Clear the PENDING bit, after this point the @work
 		 * can be re-used.
Signature · 1 line
2.7.4
#1 lore raw

[tip:irq/core] irq/work: Don't reinvent the wheel but use existing llist API

irq/work: Don't reinvent the wheel but use existing llist API
Commit-ID:  16c0890dc66d258fdeccf7b15a133f3930b19143
Gitweb:     https://git.kernel.org/tip/16c0890dc66d258fdeccf7b15a133f3930b19143
Author:     Byungchul Park <[email protected]>
AuthorDate: Tue, 31 Oct 2017 02:46:54 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 31 Oct 2017 10:24:39 +0100

irq/work: Don't reinvent the wheel but use existing llist API

Use the proper llist APIs instead of open-coded variants of them.

---
 kernel/irq_work.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/irq_work.c +1 -5
index bcf107c..e2ebe8c 100644
@@ -138,11 +138,7 @@ static void irq_work_run_list(struct llist_head *list)
 		return;
 
 	llnode = llist_del_all(list);
-	while (llnode != NULL) {
-		work = llist_entry(llnode, struct irq_work, llnode);
-
-		llnode = llist_next(llnode);
-
+	llist_for_each_entry(work, llnode, llnode) {
 		/*
 		 * Clear the PENDING bit, after this point the @work
 		 * can be re-used.
#2 lore raw
In reply to Frederic Weisbecker

Quoting Frederic Weisbecker (2017-10-31 01:46:54)

Quoted 18 lines

From: Byungchul Park <[email protected]>

Although llist provides proper APIs, they are not used. Make them used.

---
 kernel/irq_work.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/irq_work.c +0 -0
index bcf107c..e2ebe8c 100644
@@ -138,11 +138,7 @@ static void irq_work_run_list(struct llist_head *list)
                return;
 

kernel/irq_work.c static void irq_work_run_list(struct llist_head *list) · line 144

Quoted 10 lines
kernel/irq_work.c +1 -5
        llnode = llist_del_all(list);
-       while (llnode != NULL) {
-               work = llist_entry(llnode, struct irq_work, llnode);
-
-               llnode = llist_next(llnode);
-
+       llist_for_each_entry(work, llnode, llnode) {
                /*
                 * Clear the PENDING bit, after this point the @work
                 * can be re-used.

I haven't seen this reported yet, but this requires llist_for_each_entry_safe() because as mentioned work can be linked into another cpu's runlist after the PENDING bit is cleared. -Chris

#3 lore raw

[tip:irq/core] irq/work: Use llist_for_each_entry_safe

irq/work: Use llist_for_each_entry_safe
Commit-ID:  d00a08cf9ee986ad6689ce8c6fd176aff679c106
Gitweb:     https://git.kernel.org/tip/d00a08cf9ee986ad6689ce8c6fd176aff679c106
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sun, 12 Nov 2017 13:02:51 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sun, 12 Nov 2017 13:15:14 +0100

irq/work: Use llist_for_each_entry_safe

The llist_for_each_entry() loop in irq_work_run_list() is unsafe because once the works PENDING bit is cleared it can be requeued on another CPU.

Use llist_for_each_entry_safe() instead.

Fixes 16c0890dc66d ("irq/work: Don't reinvent the wheel but use existing llist API")
Cc Frederic Weisbecker <[email protected]>
Cc Byungchul Park <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Petri Latvala <[email protected]>
---
 kernel/irq_work.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/irq_work.c +3 -3
index e2ebe8c..6647b33f 100644
@@ -128,9 +128,9 @@ bool irq_work_needs_cpu(void)
 
 static void irq_work_run_list(struct llist_head *list)
 {
-	unsigned long flags;
-	struct irq_work *work;
+	struct irq_work *work, *tmp;
 	struct llist_node *llnode;
+	unsigned long flags;
 
 	BUG_ON(!irqs_disabled());
 
@@ -138,7 +138,7 @@ static void irq_work_run_list(struct llist_head *list)
 		return;
 
 	llnode = llist_del_all(list);
-	llist_for_each_entry(work, llnode, llnode) {
+	llist_for_each_entry_safe(work, tmp, llnode, llnode) {
 		/*
 		 * Clear the PENDING bit, after this point the @work
 		 * can be re-used.