test/mem: disable ASan when accessing unallocated memory
authorDavid Marchand <david.marchand@redhat.com>
Thu, 5 May 2022 09:29:51 +0000 (11:29 +0200)
committerDavid Marchand <david.marchand@redhat.com>
Wed, 11 May 2022 12:05:30 +0000 (14:05 +0200)
As described in bugzilla, ASan reports accesses to all memory segment as
invalid, since those parts have not been allocated with rte_malloc.
Move __rte_no_asan to rte_common.h and disable ASan on a part of the test.

Bugzilla ID: 880
Fixes: 6cc51b1293ce ("mem: instrument allocator for ASan")
Cc: stable@dpdk.org
Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
app/test/test_memory.c
lib/eal/common/malloc_elem.h
lib/eal/include/rte_common.h

index 140ac3f..440e5ef 100644 (file)
  * - Try to read all memory; it should not segfault.
  */
 
+/*
+ * ASan complains about accessing unallocated memory.
+ * See: https://bugs.dpdk.org/show_bug.cgi?id=880
+ */
+__rte_no_asan
 static int
 check_mem(const struct rte_memseg_list *msl __rte_unused,
                const struct rte_memseg *ms, void *arg __rte_unused)
index c5f6589..952ce73 100644 (file)
@@ -7,6 +7,8 @@
 
 #include <stdbool.h>
 
+#include <rte_common.h>
+
 #define MIN_DATA_SIZE (RTE_CACHE_LINE_SIZE)
 
 /* dummy definition of struct so we can use pointers to it in malloc_elem struct */
@@ -131,12 +133,6 @@ malloc_elem_cookies_ok(const struct malloc_elem *elem)
 #define ASAN_MEM_TO_SHADOW(mem) \
        RTE_PTR_ADD(ASAN_MEM_SHIFT(mem), ASAN_SHADOW_OFFSET)
 
-#if defined(__clang__)
-#define __rte_no_asan __attribute__((no_sanitize("address", "hwaddress")))
-#else
-#define __rte_no_asan __attribute__((no_sanitize_address))
-#endif
-
 __rte_no_asan
 static inline void
 asan_set_shadow(void *addr, char val)
@@ -276,8 +272,6 @@ old_malloc_size(struct malloc_elem *elem)
 
 #else /* !RTE_MALLOC_ASAN */
 
-#define __rte_no_asan
-
 static inline void
 asan_set_zone(void *ptr __rte_unused, size_t len __rte_unused,
                uint32_t val __rte_unused) { }
index 6758702..d56a757 100644 (file)
@@ -267,6 +267,19 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  */
 #define __rte_cold __attribute__((cold))
 
+/**
+ * Disable AddressSanitizer on some code
+ */
+#ifdef RTE_MALLOC_ASAN
+#ifdef RTE_CC_CLANG
+#define __rte_no_asan __attribute__((no_sanitize("address", "hwaddress")))
+#else
+#define __rte_no_asan __attribute__((no_sanitize_address))
+#endif
+#else /* ! RTE_MALLOC_ASAN */
+#define __rte_no_asan
+#endif
+
 /*********** Macros for pointer arithmetic ********/
 
 /**