[master] acfc992fa Complete the VSL memory fence pair

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Jul 29 10:42:07 UTC 2020


commit acfc992fad3ada1195431f7bbb17c892050c2070
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Mon Jul 27 13:32:44 2020 +0200

    Complete the VSL memory fence pair
    
    The log readers would not complete the acquire/release pair of memory
    fence operations when waiting for new data to appear in the shared memory
    log. With this, a VRMB() is issued after having waited for the
    VSL_ENDMARKER disappears, and before using any data after it (including
    the deciphered length data).

diff --git a/lib/libvarnishapi/vsl_cursor.c b/lib/libvarnishapi/vsl_cursor.c
index aa77fdc1c..cf5349ade 100644
--- a/lib/libvarnishapi/vsl_cursor.c
+++ b/lib/libvarnishapi/vsl_cursor.c
@@ -138,15 +138,6 @@ vslc_vsm_next(const struct VSL_cursor *cursor)
 		t = *(volatile const uint32_t *)c->next.ptr;
 		AN(t);
 
-		if (t == VSL_WRAPMARKER) {
-			/* Wrap around not possible at front */
-			assert(c->next.ptr != c->head->log);
-			c->next.ptr = c->head->log;
-			while (c->next.priv % VSL_SEGMENTS)
-				c->next.priv++;
-			continue;
-		}
-
 		if (t == VSL_ENDMARKER) {
 			if (VSM_StillValid(c->vsm, &c->vf) != VSM_valid)
 				return (vsl_e_abandon);
@@ -156,6 +147,19 @@ vslc_vsm_next(const struct VSL_cursor *cursor)
 			return (vsl_end);
 		}
 
+		/* New data observed. Ensure load ordering with the log
+		 * writer. */
+		VRMB();
+
+		if (t == VSL_WRAPMARKER) {
+			/* Wrap around not possible at front */
+			assert(c->next.ptr != c->head->log);
+			c->next.ptr = c->head->log;
+			while (c->next.priv % VSL_SEGMENTS)
+				c->next.priv++;
+			continue;
+		}
+
 		c->cursor.rec = c->next;
 		c->next.ptr = VSL_NEXT(c->next.ptr);
 


More information about the varnish-commit mailing list