From nobody Sat May 18 06:04:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1703108859; cv=none; d=zohomail.com; s=zohoarc; b=KfFLfoq+FkE4v4N9SXnfxKoArvShgr1Cy7Qx5RhiYzK/ZrrdMBE6s4YEHhTSXtYBLmkSX9wcn8Tc68BvKsANYOjCKJJ4fD43UmzYM9KGKOlV99y/dhOYdnm1PnqrvK408bopoJPzhvOpqBk4J+RT09TR0a6afL96al5Fy4gkoe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703108859; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6KdFSdH2zzFSh/Vxa17ZlDTgVaBfMg8GwRykkQIML9g=; b=l7cQby5a3cO8Gey3wvCLzzpZ2A4h2tmbXqKKidzxZdSqW8wgQfNW6thvJMHNzMmMbkWj//VPdNvUhaC6XgUvDhl29/ub5P5NtoeBuJqBf6GyHjGDhyyAlKlVsbBDG0Fg7au1TXzuCjzCt5cfM3A8vYIZFF/eZUH2HQX+8Vai6x0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1703108859681586.033601590394; Wed, 20 Dec 2023 13:47:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.658318.1027438 (Exim 4.92) (envelope-from ) id 1rG4PX-0005j1-4t; Wed, 20 Dec 2023 21:47:27 +0000 Received: by outflank-mailman (output) from mailman id 658318.1027438; Wed, 20 Dec 2023 21:47:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rG4PX-0005is-1t; Wed, 20 Dec 2023 21:47:27 +0000 Received: by outflank-mailman (input) for mailman id 658318; Wed, 20 Dec 2023 21:47:25 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rG4PV-00059K-Of for xen-devel@lists.xenproject.org; Wed, 20 Dec 2023 21:47:25 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5a795307-9f81-11ee-9b0f-b553b5be7939; Wed, 20 Dec 2023 22:47:23 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5a795307-9f81-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1703108843; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=yk92W/mfN3XK5pyV+BunhluKT6FClpgUmPt9KQysWdw=; b=hWuGNTnWMlYQXzyT3WU42LS2orF1eULEqraebmWVgDKZXxhV/KBaAW5g BEAqcfKwIY5Y6yucJdm1iktSWFNRN7NwdpEw7hZpp+jlgychahEjwg/yC gtKMoXpUe4uRfo6L3CrkYBhw/sYQrgpv/lngLfCu7iy0CmFIV0kqu8AF6 g=; X-CSE-ConnectionGUID: X2YHk+T9TlSU1zBXUuZ2HQ== X-CSE-MsgGUID: LrgrxHZbSSGwWsvlSFSLVQ== Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 129369735 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.159.70 X-Policy: $RELAYED X-ThreatScanner-Verdict: Negative IronPort-Data: A9a23:GaN9g6JW/zyAgdOMFE+RupUlxSXFcZb7ZxGr2PjKsXjdYENS0DUHn TRMDGjSMvuKYTehfY8kbYripkpVsMSBzIVrSQFlqX01Q3x08seUXt7xwmUcnc+xBpaaEB84t ZV2hv3odp1coqr0/0/1WlTZhSAhk/nOHvylULKs1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpKrfrfwP9TlK6q4mhB5AZmPasjUGL2zBH5MrpOfcldEFOgKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0hK6aYD76vRxjnVaPpIAHOgdcS9qZwChxLid/ jnvWauYEm/FNoWU8AgUvoIx/ytWZcWq85efSZSzXFD6I+QrvBIAzt03ZHzaM7H09c5HW1Bu9 r8keQwJVS3alciG/a+JEMlV05FLwMnDZOvzu1llxDDdS/0nXYrCU+PB4towMDUY354UW6yEP oxANGspM0yojx5nYz/7DLoXmuuyi2a5WDpfsF+P/oI84nTJzRw327/oWDbQUoXQFJ4LzxnD+ woq+UzdGB4AJPytwwG+3W2TnfHLpg3AfLwrQejQGvlC3wTImz175ActfUu2p7y1h1CzX/pbK lcI4Ww+oK4q7kupQ9LhGRqirxasnDQRRt5RGO0S8xyWx+zf5APxLnMfUjdLZdgitck3bT8nz FmEm5XuHzMHmKKRYWKQ8PGTtzzaESoIKW4PYwcUQA1D5MPsyLzflTqWEIwlSvTsyISoSHevm 1hmsRTSmZ0j1/8r1OaHrGzDuA/1tLL5cxMHvCXuCzfNAhxCWGK1W2C5wQGEta0YfdbFHwDpg ZQSpySJAAkz4XCxeM+lGrxl8EmBvartDdElqQcH82Md3zqs4WW/Wotb/StzIkxkWu5dJmeyO B6M5VwItc8JVJdPUUOQS9vhY/nGMIC6TYi1PhwqRosmjmdNmP+vo3g1OB/4M5HFm0kwi6AvU ap3gu71ZUv2/Z9PlWLsL89EiO9D+8zL7T+LLXwN50j9gOX2ib/8YettDWZimchgs//V/l6Kr IkBXyZIoj0GONDDjuDs2dZ7BTg3wbITXPgad+Q/mja/Hzdb IronPort-HdrOrdr: A9a23:IOhBsqnXrGPeiES5GfQToRZJzNDpDfIg3DAbv31ZSRFFG/Fxl6 iV8sjzsiWE7wr5OUtQ/exoV5PhfZqxz/JICOoqTNKftWvdyQiVxehZhOOIqVDd8kXFh4hgPM xbEpSWZueeMbEDt7eZ3DWF X-Talos-CUID: 9a23:vnhp3m4C9VP6ouTm8dssxBQlOsNmTizhyEztel2SOVt0eue1cArF X-Talos-MUID: =?us-ascii?q?9a23=3At4gRIwzS+1HnJncthipE+lX/4f2aqIC0B1odsac?= =?us-ascii?q?MgPKrKhNrJTOmog+TfLZyfw=3D=3D?= X-IronPort-AV: E=Sophos;i="6.04,292,1695700800"; d="scan'208";a="129369735" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , George Dunlap , Jan Beulich , "Stefano Stabellini" , Wei Liu , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH] xen/xmalloc: XMEM_POOL_POISON improvements Date: Wed, 20 Dec 2023 21:47:16 +0000 Message-ID: <20231220214716.2510402-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1703108861098100003 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_tl= sf.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. Signed-off-by: Andrew Cooper Reviewed-by: Julien Grall --- CC: George Dunlap CC: Jan Beulich CC: Stefano Stabellini CC: Wei Liu CC: Julien Grall CC: Roger Pau Monn=C3=A9 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(-) diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c index 349b31cb4cc1..5e55fc463e7d 100644 --- a/xen/common/xmalloc_tlsf.c +++ b/xen/common/xmalloc_tlsf.c @@ -249,11 +249,14 @@ static inline void EXTRACT_BLOCK(struct bhdr *b, stru= ct xmem_pool *p, int fl, } b->ptr.free_ptr =3D (struct free_ptr) {NULL, NULL}; =20 -#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(); + } } =20 /** @@ -261,11 +264,10 @@ static inline void EXTRACT_BLOCK(struct bhdr *b, stru= ct xmem_pool *p, int fl, */ static inline void INSERT_BLOCK(struct bhdr *b, struct xmem_pool *p, int f= l, 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 */ =20 b->ptr.free_ptr =3D (struct free_ptr) {NULL, p->matrix[fl][sl]}; if ( p->matrix[fl][sl] ) --=20 2.30.2