From: Quanyang Wang <quanyang.w...@windriver.com>

This reverts commit ab3bdf9a2e54f682a95c05538af71e0e6ef8223d.

Since the commit ("microblaze: add <asm/barrier.h> to <asm/bitops.h>")
has fixed the compile error for microblaze, let's bring back the
mainline patch which introduces list_del_init_careful.

Signed-off-by: Quanyang Wang <quanyang.w...@windriver.com>
---
 include/linux/list.h | 20 +++++++++++++++++++-
 kernel/sched/wait.c  |  2 +-
 mm/filemap.c         |  7 +------
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/include/linux/list.h b/include/linux/list.h
index c9d2a10062b3..a18c87b63376 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -282,6 +282,24 @@ static inline int list_empty(const struct list_head *head)
        return READ_ONCE(head->next) == head;
 }
 
+/**
+ * list_del_init_careful - deletes entry from list and reinitialize it.
+ * @entry: the element to delete from the list.
+ *
+ * This is the same as list_del_init(), except designed to be used
+ * together with list_empty_careful() in a way to guarantee ordering
+ * of other memory operations.
+ *
+ * Any memory operations done before a list_del_init_careful() are
+ * guaranteed to be visible after a list_empty_careful() test.
+ */
+static inline void list_del_init_careful(struct list_head *entry)
+{
+       __list_del_entry(entry);
+       entry->prev = entry;
+       smp_store_release(&entry->next, entry);
+}
+
 /**
  * list_empty_careful - tests whether a list is empty and not being modified
  * @head: the list to test
@@ -297,7 +315,7 @@ static inline int list_empty(const struct list_head *head)
  */
 static inline int list_empty_careful(const struct list_head *head)
 {
-       struct list_head *next = head->next;
+       struct list_head *next = smp_load_acquire(&head->next);
        return (next == head) && (next == head->prev);
 }
 
diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
index 8dde24120479..21005b980a6b 100644
--- a/kernel/sched/wait.c
+++ b/kernel/sched/wait.c
@@ -394,7 +394,7 @@ int autoremove_wake_function(struct wait_queue_entry 
*wq_entry, unsigned mode, i
        int ret = default_wake_function(wq_entry, mode, sync, key);
 
        if (ret)
-               list_del_init(&wq_entry->entry);
+               list_del_init_careful(&wq_entry->entry);
 
        return ret;
 }
diff --git a/mm/filemap.c b/mm/filemap.c
index 48c70cbcfbd1..00bfb23c599f 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1092,13 +1092,8 @@ static int wake_page_function(wait_queue_entry_t *wait, 
unsigned mode, int sync,
         * After this list_del_init(&wait->entry) the wait entry
         * might be de-allocated and the process might even have
         * exited.
-        *
-        * We _really_ should have a "list_del_init_careful()" to
-        * properly pair with the unlocked "list_empty_careful()"
-        * in finish_wait().
         */
-       smp_mb();
-       list_del_init(&wait->entry);
+       list_del_init_careful(&wait->entry);
        return (flags & WQ_FLAG_EXCLUSIVE) != 0;
 }
 
-- 
2.25.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#10495): 
https://lists.yoctoproject.org/g/linux-yocto/message/10495
Mute This Topic: https://lists.yoctoproject.org/mt/85948449/21656
Group Owner: linux-yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to