eal/linux: clear asan after allocation and before prefaulting

Message ID 20240723083419.12435-1-amichon@kalrayinc.com (mailing list archive)
State Not Applicable, archived
Delegated to: David Marchand
Headers
Series eal/linux: clear asan after allocation and before prefaulting |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing pending Testing pending
ci/iol-compile-arm64-testing success Testing PASS

Commit Message

Alex Michon July 23, 2024, 8:34 a.m. UTC
Prefaulting may generate asan error.

Signed-off-by: Alex Michon <amichon@kalrayinc.com>
---
 .mailmap                     | 1 +
 lib/eal/linux/eal_memalloc.c | 5 +++++
 2 files changed, 6 insertions(+)
  

Comments

David Marchand Oct. 8, 2024, 9:36 a.m. UTC | #1
On Thu, Jul 25, 2024 at 9:25 AM Alex Michon <amichon@kalrayinc.com> wrote:
>
> Prefaulting may generate asan error.

I am a bit surprised of this fix.
Could you give details on how to reproduce this issue?
  
Alex Michon Oct. 22, 2024, 3:37 p.m. UTC | #2
Hello David,

I ran some more tests and it turns out that this issue was already fixed by this commit:
4d8bdd8b56 malloc: fix ASan handling for unmapped memory

Sorry about the noise,
Alex
  
David Marchand Oct. 22, 2024, 6:54 p.m. UTC | #3
Hello Alex,

On Tue, Oct 22, 2024 at 5:40 PM Alex Michon <amichon@kalrayinc.com> wrote:
>
> I ran some more tests and it turns out that this issue was already fixed by this commit:
> 4d8bdd8b56 malloc: fix ASan handling for unmapped memory
>
> Sorry about the noise,

No problem.
Thanks for the update.
  

Patch

diff --git a/.mailmap b/.mailmap
index 3f3f0442e5..b1655a4080 100644
--- a/.mailmap
+++ b/.mailmap
@@ -60,6 +60,7 @@  Alexey Kardashevskiy <aik@ozlabs.ru>
 Alex Kiselev <alex@bisonrouter.com> <alex@therouter.net>
 Alex Marginean <alexandru.marginean@nxp.com>
 Alex Markuze <alex@weka.io>
+Alex Michon <amichon@kalrayinc.com>
 Alex Porosanu <alexandru.porosanu@nxp.com>
 Alex Rosenbaum <alexr@nvidia.com> <alexr@mellanox.com>
 Alex Vesker <valex@nvidia.com>
diff --git a/lib/eal/linux/eal_memalloc.c b/lib/eal/linux/eal_memalloc.c
index e354efc95d..b9c631ea88 100644
--- a/lib/eal/linux/eal_memalloc.c
+++ b/lib/eal/linux/eal_memalloc.c
@@ -38,6 +38,8 @@ 
 #include "eal_memcfg.h"
 #include "eal_private.h"
 
+#include "malloc_elem.h"
+
 const int anonymous_hugepages_supported =
 #ifdef MAP_HUGE_SHIFT
 		1;
@@ -636,6 +638,9 @@  alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 		goto mapped;
 	}
 
+	/* Ensure the prefault doesn't trigger ASAN errors */
+	asan_set_zone(addr, alloc_sz, 0);
+
 	/* we need to trigger a write to the page to enforce page fault and
 	 * ensure that page is accessible to us, but we can't overwrite value
 	 * that is already there, so read the old value, and write itback.