DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: john.mcnamara@intel.com, dmitry.kozliuk@gmail.com,
	stable@dpdk.org, Anatoly Burakov <anatoly.burakov@intel.com>,
	Xueqin Lin <xueqin.lin@intel.com>,
	Zhihong Peng <zhihongx.peng@intel.com>
Subject: [PATCH 2/3] mem: fix ASan shadow for remapped memory segments
Date: Fri, 15 Apr 2022 19:31:26 +0200	[thread overview]
Message-ID: <20220415173127.3838-3-david.marchand@redhat.com> (raw)
In-Reply-To: <20220415173127.3838-1-david.marchand@redhat.com>

When releasing some memory, the allocator can choose to return some
pages to the OS. At the same time, this memory was poisoned in ASAn
shadow. Doing the latter made it impossible to remap this same page
later.
On the other hand, without this poison, the OS would pagefault in any
case for this page.

Remove the poisoning for unmapped pages.

Bugzilla ID: 994
Fixes: 6cc51b1293ce ("mem: instrument allocator for ASan")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/malloc_elem.h |  4 ++++
 lib/eal/common/malloc_heap.c | 12 +++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/eal/common/malloc_elem.h b/lib/eal/common/malloc_elem.h
index 228f178418..b859003722 100644
--- a/lib/eal/common/malloc_elem.h
+++ b/lib/eal/common/malloc_elem.h
@@ -272,6 +272,10 @@ old_malloc_size(struct malloc_elem *elem)
 
 #else /* !RTE_MALLOC_ASAN */
 
+static inline void
+asan_set_zone(void *ptr __rte_unused, size_t len __rte_unused,
+	uint32_t val __rte_unused) { }
+
 static inline void
 asan_set_freezone(void *ptr __rte_unused, size_t size __rte_unused) { }
 
diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index 6c572b6f2c..5913d9f862 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -860,6 +860,7 @@ malloc_heap_free(struct malloc_elem *elem)
 	size_t len, aligned_len, page_sz;
 	struct rte_memseg_list *msl;
 	unsigned int i, n_segs, before_space, after_space;
+	bool unmapped_pages = false;
 	int ret;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
@@ -999,6 +1000,13 @@ malloc_heap_free(struct malloc_elem *elem)
 
 		/* don't care if any of this fails */
 		malloc_heap_free_pages(aligned_start, aligned_len);
+		/*
+		 * Clear any poisoning in ASan for the associated pages so that
+		 * next time EAL maps those pages, the allocator can access
+		 * them.
+		 */
+		asan_set_zone(aligned_start, aligned_len, 0x00);
+		unmapped_pages = true;
 
 		request_sync();
 	} else {
@@ -1032,7 +1040,9 @@ malloc_heap_free(struct malloc_elem *elem)
 
 	rte_mcfg_mem_write_unlock();
 free_unlock:
-	asan_set_freezone(asan_ptr, asan_data_len);
+	/* Poison memory range if belonging to some still mapped pages. */
+	if (!unmapped_pages)
+		asan_set_freezone(asan_ptr, asan_data_len);
 
 	rte_spinlock_unlock(&(heap->lock));
 	return ret;
-- 
2.23.0


  parent reply	other threads:[~2022-04-15 17:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15 17:31 [PATCH 0/3] Enable ASan in GHA David Marchand
2022-04-15 17:31 ` [PATCH 1/3] test/mem: disable ASan when accessing unallocated mem David Marchand
2022-04-20 14:48   ` Burakov, Anatoly
2022-04-15 17:31 ` David Marchand [this message]
2022-04-20 14:47   ` [PATCH 2/3] mem: fix ASan shadow for remapped memory segments Burakov, Anatoly
2022-04-21  9:37     ` David Marchand
2022-04-21  9:50       ` David Marchand
2022-04-21 13:18       ` Burakov, Anatoly
2022-04-26 12:54         ` Burakov, Anatoly
2022-04-26 14:15           ` David Marchand
2022-04-26 16:07             ` Burakov, Anatoly
2022-04-27 15:32               ` Burakov, Anatoly
2022-04-15 17:31 ` [PATCH 3/3] ci: build some job with ASan David Marchand
2022-05-05  9:29 ` [PATCH v2 0/2] Enable ASan in GHA David Marchand
2022-05-05  9:29   ` [PATCH v2 1/2] test/mem: disable ASan when accessing unallocated mem David Marchand
2022-05-05  9:29   ` [PATCH v2 2/2] ci: build some job with ASan David Marchand
2022-05-10 19:22     ` Aaron Conole
2022-05-11 12:01   ` [PATCH v2 0/2] Enable ASan in GHA David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220415173127.3838-3-david.marchand@redhat.com \
    --to=david.marchand@redhat.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=john.mcnamara@intel.com \
    --cc=stable@dpdk.org \
    --cc=xueqin.lin@intel.com \
    --cc=zhihongx.peng@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).