[v2] malloc: fix adjacency check to also include segment list

Message ID 6a0a1a54d58a7c72380860c1da9e36d512c0ccd2.1542207435.git.anatoly.burakov@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] malloc: fix adjacency check to also include segment list |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Burakov, Anatoly Nov. 14, 2018, 3 p.m. UTC
  It may so happen that two memory locations may be adjacent in
virtual memory, but belong to different segment lists. With
current code, such segments will be concatenated. Fix the
adjacency checking code to also check if the adjacent malloc
elements belong to the same memseg list.

Fixes: 66cc45e293ed ("mem: replace memseg with memseg lists")

Cc: stable@dpdk.org

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---

Notes:
    v2: fixed typo in second comparison

 lib/librte_eal/common/malloc_elem.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Burakov, Anatoly Nov. 14, 2018, 4:04 p.m. UTC | #1
On 14-Nov-18 3:00 PM, Anatoly Burakov wrote:
> It may so happen that two memory locations may be adjacent in
> virtual memory, but belong to different segment lists. With
> current code, such segments will be concatenated. Fix the
> adjacency checking code to also check if the adjacent malloc
> elements belong to the same memseg list.
> 
> Fixes: 66cc45e293ed ("mem: replace memseg with memseg lists")
> 
> Cc: stable@dpdk.org
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---

Oops, reply tag was set wrong.
  
Thomas Monjalon Nov. 18, 2018, 1:15 p.m. UTC | #2
14/11/2018 16:00, Anatoly Burakov:
> It may so happen that two memory locations may be adjacent in
> virtual memory, but belong to different segment lists. With
> current code, such segments will be concatenated. Fix the
> adjacency checking code to also check if the adjacent malloc
> elements belong to the same memseg list.
> 
> Fixes: 66cc45e293ed ("mem: replace memseg with memseg lists")
> 
> Cc: stable@dpdk.org
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/common/malloc_elem.c b/lib/librte_eal/common/malloc_elem.c
index 1a74660de..9d3dcb6a9 100644
--- a/lib/librte_eal/common/malloc_elem.c
+++ b/lib/librte_eal/common/malloc_elem.c
@@ -316,13 +316,15 @@  remove_elem(struct malloc_elem *elem)
 static int
 next_elem_is_adjacent(struct malloc_elem *elem)
 {
-	return elem->next == RTE_PTR_ADD(elem, elem->size);
+	return elem->next == RTE_PTR_ADD(elem, elem->size) &&
+			elem->next->msl == elem->msl;
 }
 
 static int
 prev_elem_is_adjacent(struct malloc_elem *elem)
 {
-	return elem == RTE_PTR_ADD(elem->prev, elem->prev->size);
+	return elem == RTE_PTR_ADD(elem->prev, elem->prev->size) &&
+			elem->prev->msl == elem->msl;
 }
 
 /*