]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: mt_list: Use atomic operations to prevent compiler optims
authorOlivier Houchard <ohouchard@haproxy.com>
Fri, 24 Oct 2025 10:43:47 +0000 (12:43 +0200)
committerOlivier Houchard <cognet@ci0.org>
Fri, 24 Oct 2025 11:34:41 +0000 (13:34 +0200)
As a folow-up to f40f5401b9f24becc6fdd2e77d4f4578bbecae7f, explicitely
use atomic operations to set the prev and next fields, to make sure the
compiler can't assume anything about it, and just does it.

This should be backported after f40f5401b9 up to 2.8.

include/import/mt_list.h

index 4c1b3e286232d129d9708dc42ce84904f5ee72af..23f2911c6a490a920ded7023ed870bcffc4704ac 100644 (file)
@@ -264,8 +264,8 @@ static inline __attribute__((always_inline)) unsigned long mt_list_cpu_relax(uns
  */
 static inline struct mt_list *mt_list_init(struct mt_list *el)
 {
-       el->next = el;
-       el->prev = el;
+       __atomic_store_n(&el->next, el, __ATOMIC_RELAXED);
+       __atomic_store_n(&el->prev, el, __ATOMIC_RELAXED);
        return el;
 }
 
@@ -491,8 +491,8 @@ static MT_INLINE struct mt_list *mt_list_behead(struct mt_list *lh)
                        break;
                }
 
-               lh->next = lh;
-               lh->prev = lh;
+               __atomic_store_n(&lh->next, lh, __ATOMIC_RELAXED);
+               __atomic_store_n(&lh->prev, lh, __ATOMIC_RELAXED);
                __atomic_thread_fence(__ATOMIC_RELEASE);
 
                n->prev = p;
@@ -645,8 +645,8 @@ static MT_INLINE long mt_list_delete(struct mt_list *el)
                 * somebody may be using it already.
                 */
                if (el != n) {
-                       el->prev = el;
-                       el->next = el;
+                       __atomic_store_n(&el->prev, el, __ATOMIC_RELAXED);
+                       __atomic_store_n(&el->next, el, __ATOMIC_RELAXED);
                        __atomic_thread_fence(__ATOMIC_RELEASE);
                }