vlib: allocating buffers on thread-x and freeing them on thread-y causes
a crash on debug image (VPP-1151)

In debug image, there is extra code to validate the buffer when it is
freed. It uses the hash table to lookup the buffer index with spinlock
to prevent contention. However, there is one spinlock for each worker
thread. So allocating the buffer on thread-x and freeing the same buffer
on thread-y causes the validation to fail on thread-y. The fix is to
have only one spinlock, stored in vlib_global_main.

Change-Id: Ic383846cefe84a3e262255afcf82276742f0f62e
Signed-off-by: Steven <sluong@cisco.com>
(cherry picked from commit a7effa1b072463f12305a474f082aeaffb7ada4b)
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c
index 880cd95..400488d 100644
--- a/src/vlib/buffer.c
+++ b/src/vlib/buffer.c
@@ -185,7 +185,7 @@
       vlib_buffer_known_state_t k;
       u8 *msg, *result;
 
-      k = vlib_buffer_is_known (vm, b->next_buffer);
+      k = vlib_buffer_is_known (b->next_buffer);
       if (k != VLIB_BUFFER_KNOWN_ALLOCATED)
 	return format (0, "next 0x%x: %U",
 		       b->next_buffer, format_vlib_buffer_known_state, k);
@@ -243,7 +243,7 @@
 	  goto done;
 	}
 
-      k = vlib_buffer_is_known (vm, bi);
+      k = vlib_buffer_is_known (bi);
       if (k != known_state)
 	{
 	  msg = format (0, "is %U; expected %U",
@@ -317,7 +317,7 @@
 
       bi = b[0];
       b += 1;
-      known = vlib_buffer_is_known (vm, bi);
+      known = vlib_buffer_is_known (bi);
       if (known != expected_state)
 	{
 	  ASSERT (0);
@@ -328,8 +328,7 @@
 	}
 
       vlib_buffer_set_known_state
-	(vm, bi,
-	 is_free ? VLIB_BUFFER_KNOWN_FREE : VLIB_BUFFER_KNOWN_ALLOCATED);
+	(bi, is_free ? VLIB_BUFFER_KNOWN_FREE : VLIB_BUFFER_KNOWN_ALLOCATED);
     }
 }
 
@@ -580,7 +579,7 @@
 	  bi[i] = vlib_get_buffer_index (vm, b);
 
 	  if (CLIB_DEBUG > 0)
-	    vlib_buffer_set_known_state (vm, bi[i], VLIB_BUFFER_KNOWN_FREE);
+	    vlib_buffer_set_known_state (bi[i], VLIB_BUFFER_KNOWN_FREE);
 	  b = vlib_buffer_next_contiguous (b, fl->n_data_bytes);
 	}