xen/xmalloc: XMEM_POOL_POISON improvements
PATCH 1/1 xen/xmalloc: XMEM_POOL_POISON improvements
When in use, the spew:
(XEN) Assertion '!memchr_inv(b->ptr.buffer + MIN_BLOCK_SIZE, POISON_BYTE, (b->size & BLOCK_SIZE_MASK) - MIN_BLOCK_SIZE)' failed at common/xmalloc_tlsf.c:246
is unweidly and likely meaningless to non-Xen developers. Therefore:
* Switch to IS_ENABLED(). There's no need for full #ifdef-ary.
* Pull memchr_inv() out into the if(), and provide an error message which clearly states that corruption has been found.
---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
Observations from the debugging of:
https://github.com/Dasharo/dasharo-issues/issues/488
v2:
* Switch to printk()+BUG()
--- xen/common/xmalloc_tlsf.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
xen/common/xmalloc_tlsf.c +10 -8
@@ -249,11 +249,14 @@ 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 ,POISON_BYTE , - (b->size &BLOCK_SIZE_MASK ) -MIN_BLOCK_SIZE )); -#endif /* CONFIG_XMEM_POOL_POISON */ +if (IS_ENABLED (CONFIG_XMEM_POOL_POISON ) && + (b->size &BLOCK_SIZE_MASK ) >MIN_BLOCK_SIZE && +memchr_inv (b->ptr.buffer +MIN_BLOCK_SIZE ,POISON_BYTE , + (b->size &BLOCK_SIZE_MASK ) -MIN_BLOCK_SIZE ) ) + { +printk (XENLOG_ERR "XMEM Pool corruption found" ); +BUG (); + } }/**
@@ -261,11 +264,10 @@ 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 ) +if (IS_ENABLED (CONFIG_XMEM_POOL_POISON ) && + (b->size &BLOCK_SIZE_MASK ) >MIN_BLOCK_SIZE )memset (b->ptr.buffer +MIN_BLOCK_SIZE ,POISON_BYTE , (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] )
Signature · 1 line
2.30.2
Hi Andrew,
Quoted 11 lines · Andrew Cooper
When in use, the spew:
(XEN) Assertion '!memchr_inv(b->ptr.buffer + MIN_BLOCK_SIZE, POISON_BYTE, (b->size & BLOCK_SIZE_MASK) - MIN_BLOCK_SIZE)' failed at common/xmalloc_tlsf.c:246is unweidly and likely meaningless to non-Xen developers. Therefore:
* Switch to
IS_ENABLED(). There's no need for full #ifdef-ary.
* Pullmemchr_inv()out into theif(), and provide an error message which clearly states that corruption has been found.Signed-off-by Andrew Cooper <[email protected]>
With one remark:
Quoted 8 lines
---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
Quoted 5 lines
Observations from the debugging of:
https://github.com/Dasharo/dasharo-issues/issues/488v2:
* Switch to printk()+BUG()
I would suggest to add a sentence about the switch to printk() + BUG() in the commit message. Maybe:
"CONFIG_XMEM_POOL_POISON can be enabled even on production build. So we should switch from ASSERT() to BUG()."
Cheers,
Signature · 1 line
Julien Grall
Quoted 16 lines · Julien Grall
Hi Andrew,
Quoted 13 lines · Andrew Cooper
When in use, the spew:
(XEN) Assertion '!memchr_inv(b->ptr.buffer +
MIN_BLOCK_SIZE,POISON_BYTE, (b->size&BLOCK_SIZE_MASK) -MIN_BLOCK_SIZE)' failed atcommon/xmalloc_tlsf.c:246is unweidly and likely meaningless to non-Xen developers. Therefore:
* Switch to IS_ENABLED(). There's no need for full #ifdef-ary.
* Pullmemchr_inv()out into theif(), and provide an error message which
clearly states that corruption has been found.
Quoted 5 lines
Quoted 1 line
Signed-off-by Andrew Cooper <[email protected]>With one remark:
Reviewed-by Julien Grall <[email protected]>
Thanks. Will fix.
~Andrew