Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Feb 2019 14:25:05 +0000 (UTC)
From:      Marius Strobl <marius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r344093 - stable/11/sys/net
Message-ID:  <201902131425.x1DEP5p2035494@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marius
Date: Wed Feb 13 14:25:05 2019
New Revision: 344093
URL: https://svnweb.freebsd.org/changeset/base/344093

Log:
  MFC: r333879, r342749
  
  - Even though 64-bit atomics are supported on i386 there are panics
    indicating that the code does not work correctly there. Switch
    to mutex based variant (and fix that while we're here).
    Reported by:	pho, kib
  
  - mp_ring: avoid items offset difference between iflib and mp_ring
    on architectures without 64-bit atomics
    Reported by:	Augustin Cavalier <waddlesplash@gmail.com>

Modified:
  stable/11/sys/net/mp_ring.c
  stable/11/sys/net/mp_ring.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/net/mp_ring.c
==============================================================================
--- stable/11/sys/net/mp_ring.c	Wed Feb 13 13:09:16 2019	(r344092)
+++ stable/11/sys/net/mp_ring.c	Wed Feb 13 14:25:05 2019	(r344093)
@@ -37,10 +37,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/malloc.h>
 #include <machine/cpu.h>
 
-#if defined(__powerpc__) || defined(__mips__)
-#define NO_64BIT_ATOMICS
-#endif
-
 #if defined(__i386__)
 #define atomic_cmpset_acq_64 atomic_cmpset_64
 #define atomic_cmpset_rel_64 atomic_cmpset_64
@@ -101,7 +97,7 @@ state_to_flags(union ring_state s, int abdicate)
 	return (BUSY);
 }
 
-#ifdef NO_64BIT_ATOMICS
+#ifdef MP_RING_NO_64BIT_ATOMICS
 static void
 drain_ring_locked(struct ifmp_ring *r, union ring_state os, uint16_t prev, int budget)
 {
@@ -291,7 +287,7 @@ ifmp_ring_alloc(struct ifmp_ring **pr, int size, void 
 	}
 
 	*pr = r;
-#ifdef NO_64BIT_ATOMICS
+#ifdef MP_RING_NO_64BIT_ATOMICS
 	mtx_init(&r->lock, "mp_ring lock", NULL, MTX_DEF);
 #endif
 	return (0);
@@ -325,7 +321,7 @@ ifmp_ring_free(struct ifmp_ring *r)
  *
  * Returns an errno.
  */
-#ifdef NO_64BIT_ATOMICS
+#ifdef MP_RING_NO_64BIT_ATOMICS
 int
 ifmp_ring_enqueue(struct ifmp_ring *r, void **items, int n, int budget)
 {
@@ -345,6 +341,7 @@ ifmp_ring_enqueue(struct ifmp_ring *r, void **items, i
 	if (n >= space_available(r, os)) {
 		counter_u64_add(r->drops, n);
 		MPASS(os.flags != IDLE);
+		mtx_unlock(&r->lock);
 		if (os.flags == STALLED)
 			ifmp_ring_check_drainage(r, 0);
 		return (ENOBUFS);
@@ -480,7 +477,7 @@ ifmp_ring_check_drainage(struct ifmp_ring *r, int budg
 	ns.flags = BUSY;
 
 
-#ifdef NO_64BIT_ATOMICS
+#ifdef MP_RING_NO_64BIT_ATOMICS
 	mtx_lock(&r->lock);
 	if (r->state != os.state) {
 		mtx_unlock(&r->lock);

Modified: stable/11/sys/net/mp_ring.h
==============================================================================
--- stable/11/sys/net/mp_ring.h	Wed Feb 13 13:09:16 2019	(r344092)
+++ stable/11/sys/net/mp_ring.h	Wed Feb 13 14:25:05 2019	(r344093)
@@ -40,6 +40,10 @@ typedef u_int (*mp_ring_drain_t)(struct ifmp_ring *, u
 typedef u_int (*mp_ring_can_drain_t)(struct ifmp_ring *);
 typedef void (*mp_ring_serial_t)(struct ifmp_ring *);
 
+#if defined(__powerpc__) || defined(__mips__) || defined(__i386__)
+#define MP_RING_NO_64BIT_ATOMICS
+#endif
+
 struct ifmp_ring {
 	volatile uint64_t	state __aligned(CACHE_LINE_SIZE);
 
@@ -54,7 +58,7 @@ struct ifmp_ring {
 	counter_u64_t		stalls;
 	counter_u64_t		restarts;	/* recovered after stalling */
 	counter_u64_t		abdications;
-#ifdef NO_64BIT_ATOMICS
+#ifdef MP_RING_NO_64BIT_ATOMICS
 	struct mtx		lock;
 #endif
 	void * volatile		items[] __aligned(CACHE_LINE_SIZE);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201902131425.x1DEP5p2035494>