xmalloc patches
v2 cover xmalloc patches
These are the remaining patches to xmalloc_tlsf.c that stem from debugging the problem that led to commit 56ad6265 "x86/msi: fix loop termination condition in pci_msi_conf_write_intercept()".
Paul Durrant (2):
xmalloc: remove struct xmem_pool init_region
xmalloc: add a Kconfig option to poison free pool memory
xen/Kconfig.debug | 7 +++++++ xen/common/string.c | 20 ++++++++++++++++++ xen/common/xmalloc_tlsf.c | 44 +++++++++++++-------------------------- xen/include/xen/string.h | 2 ++ xen/include/xen/xmalloc.h | 2 -- 5 files changed, 43 insertions(+), 32 deletions(-)
---
v2:
- Patch #1 of v1 of the series already commmitted, so dropped
- Patch #2 now removes the init_region
Signature · 7 lines
2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 1/2 xmalloc: remove struct xmem_pool init_region
This patch dispenses with the init_region. It's simply not necessary (pools will still happily grow and shrink on demand in its absence) and the code can be shortended by removing it. It also avoids the sole evaluation of ADD_REGION without holding the pool lock (which is unsafe).
---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
v2:
- remove init_region instead of fixing the locking
--- xen/common/xmalloc_tlsf.c | 34 ++++------------------------------ xen/include/xen/xmalloc.h | 2 -- 2 files changed, 4 insertions(+), 32 deletions(-)
xen/common/xmalloc_tlsf.c +4 -30
@@ -101,7 +101,6 @@ struct xmem_pool {spinlock_t lock; -unsigned long init_size;unsigned long max_size;unsigned long grow_size;
@@ -115,7 +114,6 @@ struct xmem_pool {struct list_head list; -void *init_region;char name[MAX_POOL_NAME_LEN ]; };
@@ -287,14 +285,13 @@ struct xmem_pool *xmem_pool_create(const char *name, xmem_pool_get_memory get_mem, xmem_pool_put_memory put_mem, - unsigned long init_size, unsigned long max_size, unsigned long grow_size) { struct xmem_pool *pool;int pool_bytes, pool_order; -BUG_ON (max_size && (max_size < init_size)); +BUG_ON (max_size && (max_size < grow_size)); pool_bytes =ROUNDUP_SIZE (sizeof (*pool)); pool_order =get_order_from_bytes (pool_bytes);
@@ -305,23 +302,18 @@ struct xmem_pool *xmem_pool_create(memset (pool,0 , pool_bytes);/* Round to next page boundary */ - init_size =ROUNDUP_PAGE (init_size); max_size =ROUNDUP_PAGE (max_size); grow_size =ROUNDUP_PAGE (grow_size);/* pool global overhead not included in used size */ pool->used_size =0 ; - pool->init_size = init_size; pool->max_size = max_size; pool->grow_size = grow_size; pool->get_mem = get_mem; pool->put_mem = put_mem;strlcpy (pool->name, name,sizeof (pool->name)); -/* always obtain init_region lazily now to ensure it is get_mem'd -* in the same "context" as all other regions */ -spin_lock_init (&pool->lock);spin_lock (&pool_list_lock);
@@ -340,7 +332,6 @@ unsigned long xmem_pool_get_total_size(struct xmem_pool *pool) {unsigned long total; total =ROUNDUP_SIZE (sizeof (*pool)) - + pool->init_size + (pool->num_regions -1 ) * pool->grow_size;return total; }
@@ -352,13 +343,6 @@ void xmem_pool_destroy(struct xmem_pool *pool)if ( pool ==NULL )return ; -/* User is destroying without ever allocating from this pool */ -if (xmem_pool_get_used_size (pool) ==BHDR_OVERHEAD ) - { -ASSERT (!pool->init_region); - pool->used_size -=BHDR_OVERHEAD ; - } -/* Check for memory leaks in this pool */ if (xmem_pool_get_used_size (pool) ) printk("memory leak in pool: %s (%p). "
@@ -380,14 +364,6 @@ void *xmem_pool_alloc(unsigned long size, struct xmem_pool *pool)int fl, sl;unsigned long tmp_size; -if ( pool->init_region ==NULL ) - { -if ( (region = pool->get_mem (pool->init_size)) ==NULL ) - goto out; -ADD_REGION (region, pool->init_size, pool); - pool->init_region = region; - } - size = (size <MIN_BLOCK_SIZE ) ?MIN_BLOCK_SIZE :ROUNDUP_SIZE (size);/* Rounding up the requested size and calculating fl and sl */
@@ -401,8 +377,7 @@ void *xmem_pool_alloc(unsigned long size, struct xmem_pool *pool)/* Not found */ if ( size > (pool->grow_size -2 *BHDR_OVERHEAD ) ) goto out_locked; -if ( pool->max_size && (pool->init_size + - pool->num_regions * pool->grow_size +if ( pool->max_size && (pool->num_regions * pool->grow_size > pool->max_size) ) goto out_locked;spin_unlock (&pool->lock);
@@ -551,9 +526,8 @@ static void *xmalloc_whole_pages(unsigned long size, unsigned long align)static void tlsf_init (void ) { - xenpool =xmem_pool_create ( -"xmalloc" , xmalloc_pool_get, xmalloc_pool_put, -PAGE_SIZE ,0 ,PAGE_SIZE ); + xenpool =xmem_pool_create ("xmalloc" , xmalloc_pool_get, + xmalloc_pool_put,0 ,PAGE_SIZE );BUG_ON (!xenpool); }
xen/include/xen/xmalloc.h +0 -2
@@ -84,7 +84,6 @@ typedef void (xmem_pool_put_memory)(void *ptr);* @name: name of the pool * @get_mem: callback function used to expand pool * @put_mem: callback function used to shrink pool -* @init_size: inital pool size (in bytes) * @max_size: maximum pool size (in bytes) - set this as 0 for no limit * @grow_size: amount of memory (in bytes) added to pool whenever required *
@@ -94,7 +93,6 @@ struct xmem_pool *xmem_pool_create(const char *name, xmem_pool_get_memory get_mem, xmem_pool_put_memory put_mem, - unsigned long init_size, unsigned long max_size, unsigned long grow_size);
Signature · 7 lines
2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/2] xmalloc: remove struct xmem_pool init_region
Quoted 4 lines · Paul Durrant
This patch dispenses with the
init_region. It's simply not necessary (pools will still happily grow and shrink on demand in its absence) and the code can be shortended by removing it. It also avoids the sole evaluation ofADD_REGIONwithout holding the pool lock (which is unsafe).
Oh, so you've figured there can be even more code removed than we first thought. Nice.
xen/common/xmalloc_tlsf.c void xmem_pool_destroy(struct xmem_pool *pool) · line 360
Quoted 10 lines
xen/common/xmalloc_tlsf.c +0
-6@@ -352,13 +343,6 @@ void xmem_pool_destroy(struct xmem_pool *pool)if ( pool ==NULL )return ; -/* User is destroying without ever allocating from this pool */ -if (xmem_pool_get_used_size (pool) ==BHDR_OVERHEAD ) - { -ASSERT (!pool->init_region); - pool->used_size -=BHDR_OVERHEAD ; - }
I can see that the ASSERT() can (and needs to) go away. But I don't think you've changed anything elsewhere that would also allow the entire if() to go away.
xen/common/xmalloc_tlsf.c void *xmem_pool_alloc(unsigned long size, struct xmem_pool *pool) · line 389
Quoted 11 lines
xen/common/xmalloc_tlsf.c +0
-7@@ -380,14 +364,6 @@ void *xmem_pool_alloc(unsigned long size, struct xmem_pool *pool)int fl, sl;unsigned long tmp_size; -if ( pool->init_region ==NULL ) - { -if ( (region = pool->get_mem (pool->init_size)) ==NULL ) - goto out; -ADD_REGION (region, pool->init_size, pool); - pool->init_region = region; - }
I.e. the code further down in this function turned out to not depend on there being at least one region in the pool, other than I was afraid it would. Good - even more pretty a change.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/2] xmalloc: remove struct xmem_pool init_region
Quoted 23 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 05 July 2019 13:12
To: Paul Durrant <[email protected]>
Cc: [email protected]; Julien Grall <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Stefano Stabellini <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH v2 1/2] xmalloc: remove structxmem_poolinit_regionQuoted 4 lines · Paul Durrant
This patch dispenses with the
init_region. It's simply not necessary (pools will still happily grow and shrink on demand in its absence) and the code can be shortended by removing it. It also avoids the sole evaluation ofADD_REGIONwithout holding the pool lock (which is unsafe).Oh, so you've figured there can be even more code removed than we first thought. Nice.
Quoted 4 lines
xen/common/xmalloc_tlsf.c +0
-0@@ -352,13 +343,6 @@ void xmem_pool_destroy(struct xmem_pool *pool)if ( pool ==NULL )return ;
Quoted 10 lines
xen/common/xmalloc_tlsf.c void xmem_pool_destroy(struct xmem_pool *pool) · line 360
Quoted 6 lines
xen/common/xmalloc_tlsf.c +0
-6-/* User is destroying without ever allocating from this pool */ -if (xmem_pool_get_used_size (pool) ==BHDR_OVERHEAD ) - { -ASSERT (!pool->init_region); - pool->used_size -=BHDR_OVERHEAD ; - }I can see that the
ASSERT()can (and needs to) go away. But I don't think you've changed anything elsewhere that would also allow the entireif()to go away.
I think so. AFAICT the size check against BHDR_OVERHEAD is entirely to avoid reporting presence of the init_region as a leak. I.e. in the presence of an init_region, the used_size would never drop below BHDR_OVERHEAD. Without an init_region, used_size should drop all the way (back) to 0 when the last xfree() is done.
Quoted 5 lines
Quoted 5 lines
xen/common/xmalloc_tlsf.c +0
-0@@ -380,14 +364,6 @@ void *xmem_pool_alloc(unsigned long size, struct xmem_pool *pool)int fl, sl;unsigned long tmp_size;
Quoted 11 lines
xen/common/xmalloc_tlsf.c void *xmem_pool_alloc(unsigned long size, struct xmem_pool *pool) · line 389
Quoted 7 lines
xen/common/xmalloc_tlsf.c +0
-7-if ( pool->init_region ==NULL ) - { -if ( (region = pool->get_mem (pool->init_size)) ==NULL ) - goto out; -ADD_REGION (region, pool->init_size, pool); - pool->init_region = region; - }I.e. the code further down in this function turned out to not depend on there being at least one region in the pool, other than I was afraid it would. Good - even more pretty a change.
Nope. All the lists can start empty :-)
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich
Reviewed-byRe: [Xen-devel] [PATCH v2 1/2] xmalloc: remove struct xmem_pool init_region
Quoted 19 lines · Paul Durrant
Quoted 8 lines
From: Jan Beulich <[email protected]>
Sent: 05 July 2019 13:12Quoted 4 lines · Paul Durrant
xen/common/xmalloc_tlsf.c +0
-0@@ -352,13 +343,6 @@ void xmem_pool_destroy(struct xmem_pool *pool)if ( pool ==NULL )return ;Quoted 10 lines
xen/common/xmalloc_tlsf.c void xmem_pool_destroy(struct xmem_pool *pool) · line 360
Quoted 6 lines
xen/common/xmalloc_tlsf.c +0
-6-/* User is destroying without ever allocating from this pool */ -if (xmem_pool_get_used_size (pool) ==BHDR_OVERHEAD ) - { -ASSERT (!pool->init_region); - pool->used_size -=BHDR_OVERHEAD ; - }I can see that the
ASSERT()can (and needs to) go away. But I don't think you've changed anything elsewhere that would also allow the entireif()to go away.
Quoted 5 lines
I think so. AFAICT the size check against
BHDR_OVERHEADis entirely to avoid reporting presence of theinit_regionas a leak. I.e. in the presence of aninit_region, theused_sizewould never drop belowBHDR_OVERHEAD. Without aninit_region,used_sizeshould drop all the way (back) to 0 when the lastxfree()is done.
But the old code asserted that there was _no_ init region, and then reduced pool->used_size. And the state of the pool when there is no init region doesn't change with your patch. If anything this if() was bogus altogether, which I think was the case now that I've looked more closely at how / when ->used_size gets updated. I would have wanted to check the original code (which ours was cloned from) to see whether they've changed this piece at some time, but the site doesn't seem to be properly working (anymore).
Do you agree that ->used_size could equal BHDR_OVERHEAD only when there's exactly one region, and when that one region has no outstanding allocations? Seeing the region removal in xmem_pool_free() I also can't seem to see how the init region would have been excluded from getting freed here, at which point asserting whether there is (ever was) one looks even more fishy.
Actually there's a perhaps telling comment in xmem_pool_create():
/* always obtain init_region lazily now to ensure it is get_mem'd
* in the same "context" as all other regions */
This suggests to me that originally the init region was set up right here, at which point that assertion would have made sense. And there we go - I'm not at all surprised that this stems from 6009f4ddb2 ('Transcendent memory ("tmem") for Xen'), with no mention at all in the commit message as to why the allocator needed to be changed.
IOW - as long as you agree with the analysis, and as long as a reference to the above commit rendering stale that entire if() gets added to the description (which may still be reasonable to do while committing):
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/2] xmalloc: remove struct xmem_pool init_region
Quoted 30 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 05 July 2019 13:54
To: Paul Durrant <[email protected]>
Cc: JulienGrall <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; KonradRzeszutek Wilk <[email protected]>; Tim (Xen.org) <[email protected]>; WeiLiu <[email protected]>
Subject: Re: [PATCH v2 1/2] xmalloc: remove structxmem_poolinit_regionQuoted 19 lines · Paul Durrant
Quoted 18 lines
From: Jan Beulich <[email protected]>
Sent: 05 July 2019 13:12xen/common/xmalloc_tlsf.c void xmem_pool_destroy(struct xmem_pool *pool) · line 360
Quoted 10 lines · Paul Durrant
xen/common/xmalloc_tlsf.c +0
-6@@ -352,13 +343,6 @@ void xmem_pool_destroy(struct xmem_pool *pool)if ( pool ==NULL )return ; -/* User is destroying without ever allocating from this pool */ -if (xmem_pool_get_used_size (pool) ==BHDR_OVERHEAD ) - { -ASSERT (!pool->init_region); - pool->used_size -=BHDR_OVERHEAD ; - }I can see that the
ASSERT()can (and needs to) go away. But I don't think you've changed anything elsewhere that would also allow the entireif()to go away.
Quoted 8 lines
Quoted 5 lines
I think so. AFAICT the size check against
BHDR_OVERHEADis entirely to avoid reporting presence of theinit_regionas a leak. I.e. in the presence of aninit_region, theused_sizewould never drop belowBHDR_OVERHEAD. Without aninit_region,used_sizeshould drop all the way (back) to 0 when the lastxfree()is done.But the old code asserted that there was _no_ init region, and then reduced
pool->used_size.
Oh yes, I was completely blind to that '!' as it only made sense to me the other way round.
Quoted 4 lines
And the state of the pool when there is no
init region doesn't change with your patch. If anything thisif()was bogus altogether, which I think was the case now that I've looked more closely at how / when ->used_size gets updated.
Yes, I think it was indeed totally bogus.
Quoted 4 lines
I would
have wanted to check the original code (which ours was cloned from) to see whether they've changed this piece at some time, but the site doesn't seem to be properly working (anymore).
The code is over a decade old according to the boilerplate at the top so probably not surprising.
Quoted 4 lines
Do you agree that ->used_size could equal
BHDR_OVERHEADonly when there's exactly one region, and when that one region has no outstanding allocations?
Yes, hence me getting fooled into thinking this was because because init_region was not freed.
Quoted 7 lines
Seeing the region removal in
xmem_pool_free()I also can't seem to see how the init region would have been excluded from getting freed here, at which point asserting whether there is (ever was) one looks even more fishy.Actually there's a perhaps telling comment in
xmem_pool_create():
Quoted 8 lines
/* always obtain
init_regionlazily now to ensure it is get_mem'd
* in the same "context" as all other regions */This suggests to me that originally the init region was set up right here, at which point that assertion would have made sense. And there we go - I'm not at all surprised that this stems from
6009f4ddb2('Transcendent memory ("tmem") for Xen'), with no mention at all in the commit message as to why the allocator needed to be changed.
Oh... another casualty.
Quoted 7 lines
IOW - as long as you agree with the analysis, and as long as a reference to the above commit rendering stale that entire
if()gets added to the description (which may still be reasonable to do while committing):Reviewed-by Jan Beulich <[email protected]>
Thanks. If you want me to re-work the comment then let me know, otherwise I'm totally happy for you to do it on commit.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/2 xmalloc: add a Kconfig option to poison free pool memory
In reply to Paul DurrantThis patch adds XMEM_POOL_POISON to the Kconfig DEBUG options. If set, free blocks (greater than MIN_BLOCK_SIZE) will be poisoned with 0xAA bytes which will then be verified when memory is subsequently allocated. This can help in spotting heap corruption, particularly use-after-free.
---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
v2:
- Change Kconfig option name to XMEM_POOL_POISON
- Add an implementation of memchr_inv() and use that
--- xen/Kconfig.debug | 7 +++++++ xen/common/string.c | 20 ++++++++++++++++++++ xen/common/xmalloc_tlsf.c | 10 ++++++++++ xen/include/xen/string.h | 2 ++ 4 files changed, 39 insertions(+)
xen/Kconfig.debug +7 -0
@@ -105,6 +105,13 @@ config DEBUG_TRACE either directly to the console or are printed to console in case of a system crash. +config XMEM_POOL_POISON + bool "Poison free xenpool blocks" + default DEBUG + ---help--- + Poison free blocks with 0xAA bytes and verify them when a block is + allocated in order to spot use-after-free issues. + endif # DEBUG || EXPERT endmenu
xen/common/string.c +20 -0
@@ -423,6 +423,26 @@ void *(memchr)(const void *s, int c, size_t n) }#endif +/** +* memchr_inv - Find an unmatching character in an area of memory. +* @s: The memory area +* @c: The byte that is expected +* @n: The size of the area. +* +* returns the address of the first occurrence of a character other than @c, +* or %NULL if the whole buffer contains just @c. +*/ +void *memchr_inv (const void *s,int c,size_t n) +{ +const unsigned char *p = s; + +while (n--) +if ((unsigned char )c != *p++) +return (void *)(p -1 ); + +return NULL ; +} +/* * Local variables: * mode: C
xen/common/xmalloc_tlsf.c +10 -0
@@ -238,6 +238,11 @@ static inline void EXTRACT_BLOCK(struct bhdr *b, struct xmem_pool *p, int fl, } } b->ptr.free_ptr = (struct free_ptr ) {NULL ,NULL }; +#ifdef CONFIG_XMEM_POOL_POISON +if ( (b->size &BLOCK_SIZE_MASK ) >MIN_BLOCK_SIZE ) +ASSERT (!memchr_inv (b->ptr.buffer +MIN_BLOCK_SIZE ,0xAA , + (b->size &BLOCK_SIZE_MASK ) -MIN_BLOCK_SIZE )); +#endif /* CONFIG_XMEM_POOL_POISON */ }/**
@@ -245,6 +250,11 @@ static inline void EXTRACT_BLOCK(struct bhdr *b, struct xmem_pool *p, int fl,*/ static inline void INSERT_BLOCK (struct bhdr *b,struct xmem_pool *p,int fl,int sl) { +#ifdef CONFIG_XMEM_POOL_POISON +if ( (b->size &BLOCK_SIZE_MASK ) >MIN_BLOCK_SIZE ) +memset (b->ptr.buffer +MIN_BLOCK_SIZE ,0xAA , + (b->size &BLOCK_SIZE_MASK ) -MIN_BLOCK_SIZE ); +#endif /* CONFIG_XMEM_POOL_POISON */ b->ptr.free_ptr = (struct free_ptr ) {NULL , p->matrix[fl][sl]};if ( p->matrix[fl][sl] ) p->matrix[fl][sl]->ptr.free_ptr.prev = b;
xen/include/xen/string.h +2 -0
@@ -106,6 +106,8 @@ void *memchr(const void *, int, size_t);#define memchr (s, c, n) __builtin_memchr(s, c, n)#endif +void *memchr_inv (const void *,int ,size_t ); +#define is_char_array (x) __builtin_types_compatible_p(typeof(x), char[])/* safe_xxx always NUL-terminates and returns !=0 if result is truncated. */
Signature · 7 lines
2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/2] xmalloc: add a Kconfig option to poison free pool memory
xen/Kconfig.debug config DEBUG_TRACE · line 113
Quoted 12 lines · Paul Durrant
xen/Kconfig.debug +6
-0@@ -105,6 +105,13 @@ config DEBUG_TRACE either directly to the console or are printed to console in case of a system crash. +config XMEM_POOL_POISON + bool "Poison free xenpool blocks" + default DEBUG + ---help--- + Poison free blocks with 0xAA bytes and verify them when a block is + allocated in order to spot use-after-free issues.
There looks to be a spaces vs tabs problem here: Only the help text has tabs for initial indentation.
Quoted 15 lines
xen/common/xmalloc_tlsf.c +5
-0@@ -238,6 +238,11 @@ static inline void EXTRACT_BLOCK(struct bhdr *b, struct xmem_pool *p, int fl, } } b->ptr.free_ptr = (struct free_ptr ) {NULL ,NULL }; +#ifdef CONFIG_XMEM_POOL_POISON +if ( (b->size &BLOCK_SIZE_MASK ) >MIN_BLOCK_SIZE ) +ASSERT (!memchr_inv (b->ptr.buffer +MIN_BLOCK_SIZE ,0xAA , + (b->size &BLOCK_SIZE_MASK ) -MIN_BLOCK_SIZE )); +#endif /* CONFIG_XMEM_POOL_POISON */ }/**
xen/common/xmalloc_tlsf.c static inline void EXTRACT_BLOCK(struct bhdr *b, struct xmem_pool *p, int fl, · line 257
Quoted 8 lines
xen/common/xmalloc_tlsf.c +5
-0@@ -245,6 +250,11 @@ static inline void EXTRACT_BLOCK(struct bhdr *b, struct xmem_pool *p, int fl,*/ static inline void INSERT_BLOCK (struct bhdr *b,struct xmem_pool *p,int fl,int sl) { +#ifdef CONFIG_XMEM_POOL_POISON +if ( (b->size &BLOCK_SIZE_MASK ) >MIN_BLOCK_SIZE ) +memset (b->ptr.buffer +MIN_BLOCK_SIZE ,0xAA , + (b->size &BLOCK_SIZE_MASK ) -MIN_BLOCK_SIZE ); +#endif /* CONFIG_XMEM_POOL_POISON */
Can you tie together the two instances of 0xAA via a #define, please?
It would also be nice if both #ifdef blocks were separated from their neighboring code by a blank line, despite the file using blank lines rather sparingly so far.
With the adjustments here I think it would be best if you could also resend patch 1 with the slightly adjusted commit message.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/2] xmalloc: add a Kconfig option to poison free pool memory
Quoted 17 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 05 July 2019 14:41
To: Paul Durrant <[email protected]>; [email protected]
Cc: Julien Grall <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Stefano Stabellini <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH v2 2/2] xmalloc: add aKconfigoption to poison free pool memoryQuoted 6 lines · Paul Durrant
xen/Kconfig.debug +0
-0@@ -105,6 +105,13 @@ config DEBUG_TRACE either directly to the console or are printed to console in case of a system crash.
Quoted 9 lines
xen/Kconfig.debug config DEBUG_TRACE · line 113
Quoted 6 lines
xen/Kconfig.debug +6
-0+config XMEM_POOL_POISON + bool "Poison free xenpool blocks" + default DEBUG + ---help--- + Poison free blocks with 0xAA bytes and verify them when a block is + allocated in order to spot use-after-free issues.There looks to be a spaces vs tabs problem here: Only the help text has tabs for initial indentation.
Oh yes. I'll fix that.
Quoted 14 lines
Quoted 14 lines
xen/common/xmalloc_tlsf.c +5
-0@@ -238,6 +238,11 @@ static inline void EXTRACT_BLOCK(struct bhdr *b, struct xmem_pool *p, int fl, } } b->ptr.free_ptr = (struct free_ptr ) {NULL ,NULL }; +#ifdef CONFIG_XMEM_POOL_POISON +if ( (b->size &BLOCK_SIZE_MASK ) >MIN_BLOCK_SIZE ) +ASSERT (!memchr_inv (b->ptr.buffer +MIN_BLOCK_SIZE ,0xAA , + (b->size &BLOCK_SIZE_MASK ) -MIN_BLOCK_SIZE )); +#endif /* CONFIG_XMEM_POOL_POISON */ }
Quoted 14 lines
xen/common/xmalloc_tlsf.c static inline void EXTRACT_BLOCK(struct bhdr *b, struct xmem_pool *p, int fl, · line 257
Quoted 10 lines
xen/common/xmalloc_tlsf.c +5
-0/** @@ -245,6 +250,11 @@ static inline void EXTRACT_BLOCK(struct bhdr *b, struct xmem_pool *p, int fl,*/ static inline void INSERT_BLOCK (struct bhdr *b,struct xmem_pool *p,int fl,int sl) { +#ifdef CONFIG_XMEM_POOL_POISON +if ( (b->size &BLOCK_SIZE_MASK ) >MIN_BLOCK_SIZE ) +memset (b->ptr.buffer +MIN_BLOCK_SIZE ,0xAA , + (b->size &BLOCK_SIZE_MASK ) -MIN_BLOCK_SIZE ); +#endif /* CONFIG_XMEM_POOL_POISON */ Can you tie together the two instances of
0xAAvia a #define, please?
Ok, sure.
Quoted 6 lines
It would also be nice if both #ifdef blocks were separated from their neighboring code by a blank line, despite the file using blank lines rather sparingly so far.
With the adjustments here I think it would be best if you could also resend patch 1 with the slightly adjusted commit message.
Alright, will do.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 24 lines
-----Original Message-----
From: Paul Durrant <[email protected]>
Sent: 05 July 2019 10:03
To: [email protected]
Cc: Paul Durrant <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Stefano Stabellini <[email protected]>; Tim (Xen.org) <[email protected]>; Wei Liu <[email protected]>
Subject: [PATCH v2 0/2] xmalloc patchesThese are the remaining patches to
xmalloc_tlsf.cthat stem from debugging the problem that led to commit56ad6265"x86/msi: fix loop termination condition inpci_msi_conf_write_intercept()".Paul Durrant (2):
xmalloc: remove structxmem_poolinit_region
xmalloc: add aKconfigoption to poison free pool memoryxen/Kconfig.debug | 7 +++++++ xen/common/string.c | 20 ++++++++++++++++++ xen/common/xmalloc_tlsf.c | 44 +++++++++++++-------------------------- xen/include/xen/string.h | 2 ++ xen/include/xen/xmalloc.h | 2 -- 5 files changed, 43 insertions(+), 32 deletions(-)
Quoted 4 lines
---
v2:
- Patch #1 of v1 of the series already commmitted, so dropped
- Patch #2 now removes theinit_region
^ For clarity that's old patch #2, new patch #1.
Paul
Quoted 12 lines
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
--
2.20.1.2.gb21ebb671
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel