From nobody Sat May 4 07:10:35 2024 Delivered-To: importer@patchew.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; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1673880331; cv=pass; d=zohomail.com; s=zohoarc; b=VS4Vni09/CwmArOil4yQkFUEFM47WoTY6rm6XvX0gVQgUiXKxi2+TNE8Etw78NinnXWPskEZR8VIVp6nlhZ0lipjexCihPgvu6lYd4tvd+hbXMQhnk4do/lATAYvqeuMZBwm1DvJ9xa2I4KI3VQ0WYAPcsHrbkYJpVJYM9qOAXc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673880331; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=0JHRey8jQegVPl/scg0qC1Q1cBu4AxiKMGjEWCu71uc=; b=bSxQSjItrqlzhwewfEGNtkyOXtllvgj1qJNAHKVuzoLipL7Cznl3hy9BP+oxuP0aqkgCVa6fg4Zt2tMQloorLW6NSSbgvf1mmFQiEHs0Q4TQL+jMa4012ugRJ1Pkdh+vKFYhwWk5zgZZKEZcXncelomWxIu+pXi9OvNstqYgdjM= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 167388033198428.34825252031635; Mon, 16 Jan 2023 06:45:31 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.478741.742114 (Exim 4.92) (envelope-from ) id 1pHQjZ-0003k5-DY; Mon, 16 Jan 2023 14:45:13 +0000 Received: by outflank-mailman (output) from mailman id 478741.742114; Mon, 16 Jan 2023 14:45:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHQjZ-0003jr-AX; Mon, 16 Jan 2023 14:45:13 +0000 Received: by outflank-mailman (input) for mailman id 478741; Mon, 16 Jan 2023 14:45:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHQfj-0006p7-8c for xen-devel@lists.xenproject.org; Mon, 16 Jan 2023 14:41:15 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2085.outbound.protection.outlook.com [40.107.94.85]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d20b8972-95ab-11ed-91b6-6bf2151ebd3b; Mon, 16 Jan 2023 15:41:12 +0100 (CET) Received: from BN6PR17CA0057.namprd17.prod.outlook.com (2603:10b6:405:75::46) by BL3PR12MB6402.namprd12.prod.outlook.com (2603:10b6:208:3b2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.23; Mon, 16 Jan 2023 14:41:09 +0000 Received: from BN8NAM11FT092.eop-nam11.prod.protection.outlook.com (2603:10b6:405:75:cafe::dd) by BN6PR17CA0057.outlook.office365.com (2603:10b6:405:75::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.20 via Frontend Transport; Mon, 16 Jan 2023 14:41:09 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT092.mail.protection.outlook.com (10.13.176.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6002.13 via Frontend Transport; Mon, 16 Jan 2023 14:41:09 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 16 Jan 2023 08:41:08 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 16 Jan 2023 08:41:07 -0600 Received: from XIR-MICHALO-L1.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Mon, 16 Jan 2023 08:41:07 -0600 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: d20b8972-95ab-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L53WMuAg/YNQ1/alwxGdi6ZP12q2W0fPqQFJoSManfCAw3mc7J8D0bFnbOJNsuCfMw2vAswkH/kejETGHgazCHmkZyVeuhCUwbqeg8G9HBrpKT/+nXhE2PCUlSq3TOgr0WvrMdCpqvoQhpfcDKNHo6oOZLHFGRJF/WOizesjzDbqb0ZcGLBiBbef5XS4+UeR5Kgeg7raXJlsEttvS8Hh6/TZ4wBczljuuq7ivGCHO/HEbB3SWg7tlShIdIhyNzR6b6nOfs/55BDefJ/IDNpT97JHvf+I4I2SMbRvF3rfRkvqBQQooQA62TSF1AY6UumBm5Yrv04+B+sbIuUQdTxHtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0JHRey8jQegVPl/scg0qC1Q1cBu4AxiKMGjEWCu71uc=; b=fk21255Pq3+nt8CKWDh+naXhovWsn/7W2a1n+7tEY0QI0FoQM80y8c5ScK5/iKBBzcBsfwc/h+0RGF9a/Hy24uTM43J2kaReBSxCVxCERmYZ2XhH5uDhn3ZtMbQuoJlXS9yay4Imf/AUIe3jNdGiodAY+cElCGXy+jgSY52TtgqdsrdT4vYGV7/G/8EDQZEh6LS4pJYFocy+IRH1m4ZM6/I4SKb4ZAiEwH2c8luZs5gyoW6R9HAAaEaQjIvyzfC+1P6Xp2E8FCwpPHsZgcnsnoGQOVI2b5SMnnVT/SXJAPYzhKohYgCjIeE4lQDVLplCbF9/CS9dOZnSZZYa8PJxow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0JHRey8jQegVPl/scg0qC1Q1cBu4AxiKMGjEWCu71uc=; b=FSFassEGCaxEreBnzXEGo9PdyRwx8aeBEGnzBPNrp5D2T9Vj0RqupvywN0g1P//X4ik1zEkz+iW2G79JHeJ++7pTi0Djnvh8u6/UkTByDO1U0NBTklYyGGYRIi7ANVgYhKM1jXT07UZ/qvdlerKj1qEPEIvTRyVFNgRJc0cMcNc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; 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; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Michal Orzel To: CC: Michal Orzel , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH] xen/arm: Harden setup_frametable_mappings Date: Mon, 16 Jan 2023 15:41:05 +0100 Message-ID: <20230116144106.12544-1-michal.orzel@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT092:EE_|BL3PR12MB6402:EE_ X-MS-Office365-Filtering-Correlation-Id: 952691d1-0517-421d-80d2-08daf7cfb4f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4WJd9MhNBHkYqLa9OK5OaYoSytrdIDf18prXwvLBNDWwSVrIqSiVJXMfUXWQw7IH1yKQfJPsXzGkWlhGKh4GEhzTLfWkccux47GSiMozU2/CadOkLBc42ZyvtDODXz2RNZKXURlqBq7p8U5vFXgEuAvd99SNu7N8l0wq0gR2D7DsnvtyoBsmgRZ9m2U9JyU20/PEjrVLKv473a+4rsIy+4qbgIHaQL36wandES15yK9XdquPEnnRSrWn7dORdKMGATPcEbhLsxf04xiIfX0fnymZrkwR3ewEyUfKjOKnGbDQ/LFJMd7k8tDcxlcZuLyQ5wjGwaz2EdPeLhb2pgBotxUZ8DHJp5y/VGz91nQipQIkoyURuhucRD65naZnL0Y0Wz15pr9AFK2EbPLT0F+ajep9gCmmqvbypxZ3Gbl6EJRsaMTsxAwMnnfhPaUvrXUY95RpXef0Gm3RIDjyzA4ukFAQEwW9aD7DCB+OFtkn2cftzAiUKsjXMxNi1WWrs6q3o1DzJYENifGh++qkyVCsBCn3f+nFrjbFsaN/AAOaG7GzDUhLM33H3vX0BtiqlTscCAUB4tLeSCF474yYlsUrmT+MNbCbK1ltEYyFjrdJ9VKP7QCqpXMXWdbinyJf1UBCcQ8p3GgXXRqDJoQlcs14eZJamcTRDPucc9Qw2A0BgOZTxF2Oe4UIkNW1UaDwQbjn4sM2bn0OvyEmZ7D4LeDd8o5lsfNQj5idBJI/BVA86Do= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(39860400002)(376002)(136003)(396003)(451199015)(40470700004)(46966006)(36840700001)(82310400005)(70206006)(426003)(70586007)(41300700001)(2616005)(47076005)(26005)(186003)(8676002)(4326008)(6916009)(86362001)(36756003)(83380400001)(36860700001)(5660300002)(82740400003)(336012)(8936002)(54906003)(478600001)(316002)(40480700001)(1076003)(81166007)(2906002)(356005)(40460700003)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2023 14:41:09.1179 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 952691d1-0517-421d-80d2-08daf7cfb4f2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT092.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6402 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1673880332568100002 Content-Type: text/plain; charset="utf-8" The amount of supported physical memory depends on the frametable size and the number of struct page_info entries that can fit into it. Define a macro PAGE_INFO_SIZE to store the current size of the struct page_info (i.e. 56B for arm64 and 32B for arm32) and add a sanity check in setup_frametable_mappings to be notified whenever the size of the structure changes. Also call a panic if the calculated frametable_size exceeds the limit defined by FRAMETABLE_SIZE macro. Update the comments regarding the frametable in asm/config.h and take the opportunity to remove unused macro FRAMETABLE_VIRT_END on arm32. Signed-off-by: Michal Orzel Reviewed-by: Henry Wang Tested-by: Henry Wang --- xen/arch/arm/include/asm/config.h | 5 ++--- xen/arch/arm/include/asm/mm.h | 11 +++++++++++ xen/arch/arm/mm.c | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/include/asm/config.h b/xen/arch/arm/include/asm/c= onfig.h index 16213c8b677f..d8f99776986f 100644 --- a/xen/arch/arm/include/asm/config.h +++ b/xen/arch/arm/include/asm/config.h @@ -82,7 +82,7 @@ * ARM32 layout: * 0 - 12M * - * 32M - 128M Frametable: 24 bytes per page for 16GB of RAM + * 32M - 128M Frametable: 32 bytes per page for 12GB of RAM * 256M - 1G VMAP: ioremap and early_ioremap use this virtual address * space * @@ -95,7 +95,7 @@ * * 1G - 2G VMAP: ioremap and early_ioremap * - * 32G - 64G Frametable: 24 bytes per page for 5.3TB of RAM + * 32G - 64G Frametable: 56 bytes per page for 2TB of RAM * * 0x0000008000000000 - 0x00007fffffffffff (127.5TB, L0 slots [1..255]) * Unused @@ -127,7 +127,6 @@ #define FRAMETABLE_VIRT_START _AT(vaddr_t,0x02000000) #define FRAMETABLE_SIZE MB(128-32) #define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table)) -#define FRAMETABLE_VIRT_END (FRAMETABLE_VIRT_START + FRAMETABLE_SIZE - = 1) =20 #define VMAP_VIRT_START _AT(vaddr_t,0x10000000) #define VMAP_VIRT_SIZE _AT(vaddr_t, GB(1) - MB(256)) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 68adcac9fa8d..23dec574eb31 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -26,6 +26,17 @@ */ #define PFN_ORDER(_pfn) ((_pfn)->v.free.order) =20 +/* + * The size of struct page_info impacts the number of entries that can fit + * into the frametable area and thus it affects the amount of physical mem= ory + * we claim to support. Define PAGE_INFO_SIZE to be used for sanity checki= ng. +*/ +#ifdef CONFIG_ARM_64 +#define PAGE_INFO_SIZE 56 +#else +#define PAGE_INFO_SIZE 32 +#endif + struct page_info { /* Each frame can be threaded onto a doubly-linked list. */ diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 0fc6f2992dd1..a8c28fa5b768 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -676,6 +676,11 @@ void __init setup_frametable_mappings(paddr_t ps, padd= r_t pe) const unsigned long mapping_size =3D frametable_size < MB(32) ? MB(2) = : MB(32); int rc; =20 + BUILD_BUG_ON(sizeof(struct page_info) !=3D PAGE_INFO_SIZE); + + if ( frametable_size > FRAMETABLE_SIZE ) + panic("RAM size is too big to fit in a frametable area\n"); + frametable_base_pdx =3D mfn_to_pdx(maddr_to_mfn(ps)); /* Round up to 2M or 32M boundary, as appropriate. */ frametable_size =3D ROUNDUP(frametable_size, mapping_size); --=20 2.25.1