From patchwork Wed Jul 10 11:22:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Orzel X-Patchwork-Id: 13729213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CFE7FC3DA42 for ; Wed, 10 Jul 2024 11:30:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.756902.1165630 (Exim 4.92) (envelope-from ) id 1sRVWU-0006r4-O9; Wed, 10 Jul 2024 11:30:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 756902.1165630; Wed, 10 Jul 2024 11:30:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sRVWU-0006qx-Lf; Wed, 10 Jul 2024 11:30:10 +0000 Received: by outflank-mailman (input) for mailman id 756902; Wed, 10 Jul 2024 11:30:09 +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 1sRVOt-00011k-Ob for xen-devel@lists.xenproject.org; Wed, 10 Jul 2024 11:22:19 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on20620.outbound.protection.outlook.com [2a01:111:f403:240a::620]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a9c43a52-3eae-11ef-8776-851b0ebba9a2; Wed, 10 Jul 2024 13:22:18 +0200 (CEST) Received: from BN9P222CA0017.NAMP222.PROD.OUTLOOK.COM (2603:10b6:408:10c::22) by CH3PR12MB7692.namprd12.prod.outlook.com (2603:10b6:610:145::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.20; Wed, 10 Jul 2024 11:22:10 +0000 Received: from BN3PEPF0000B070.namprd21.prod.outlook.com (2603:10b6:408:10c:cafe::6) by BN9P222CA0017.outlook.office365.com (2603:10b6:408:10c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36 via Frontend Transport; Wed, 10 Jul 2024 11:22:10 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B070.mail.protection.outlook.com (10.167.243.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.5 via Frontend Transport; Wed, 10 Jul 2024 11:22:09 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.39; Wed, 10 Jul 2024 06:22:09 -0500 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.2507.39 via Frontend Transport; Wed, 10 Jul 2024 06:22:07 -0500 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: a9c43a52-3eae-11ef-8776-851b0ebba9a2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NKRHZ5jb8SOGZUdDfViQy4fLM6wNiNmPHJhgd4uVxcml81aocyQxgdqmomfJIrlBRx78xlA4As99t9jdEJhnijJuyogXm770Y8DU2qBoO3ic5mwF2n30pUeYOH6BIVCATeElIHon//e+z114e/rkONpon5aTcg9RY1NcT6yEcz1EyQAchYRccX5GsWeRR7Yz04WKqEfmgTjNpO9Ffaaq5kiUZxwXaajDob01Ic6kBWB9yzNjir5rJ6W/mPLvp0auWDrM2lZYSmHZdYEngQ2TA0iv5ZIrnnQCJev1haOnXTYbYEvWcE+vX5vAfcYjceC5Bo99FHKiuNyPWOK/QbH1sw== 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=Z43cZeKSdhq3v6JXln/ykC0j1uv41JjKp5FJGFs3XtE=; b=YjExbOcqpfmGB9XyFMkJWCdgXzPQe70kK+g3/AleptwziRDrzvFbhYsDnar9VK9d1Ppz2yck3fEa3WcRdzicJCpYlZAXVyzNe1ttv81qOS5vSxcohnLNepxz3ncR3/scmcavYg9Oj4/4/4+pRXNgh8Lkc9fTrb01FiLhBUIQk/vnS1MpdsbPDZNRpbqPmnv4l2I5OpWdvLyK1JsSMXBEWIcjOlNjOj7oGuyHRUGkZCMnzEBniYn/N8XL805fEIWqoqy4YdySOD0H5niPG1CY0o3QX1rim62SNQ6LiLyTYvW7c7HuGECOTb0Ioy7TnXUJYZazC33syW9hwRSDuppT/w== 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 (0) 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=Z43cZeKSdhq3v6JXln/ykC0j1uv41JjKp5FJGFs3XtE=; b=5eigp3WEKqXsLgiw61C9MlZs66CGYjU0COs9Prsbt4bc+Qnc6X5SqldBZdXlvesuh738QvXWk6CpwydctSwr4epWUQvU5+IzLqVurq47JUCjK8vCRORo8JecN++waolmDsPCh6YY7a2dIVEnHdJNJdgHNe/Y1Usu4l8rWAKX0UA= 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 (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 , Luca Fancellu Subject: [PATCH for-4.20 v2] xen/arm: bootfdt: Fix device tree memory node probing Date: Wed, 10 Jul 2024 13:22:04 +0200 Message-ID: <20240710112204.33542-1-michal.orzel@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: michal.orzel@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B070:EE_|CH3PR12MB7692:EE_ X-MS-Office365-Filtering-Correlation-Id: a546f256-c261-4f3a-7b5f-08dca0d28a14 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: dl6RomFeiMtPoQIZk/bH4uFZs0BsziWXv0mRqACO9XTIR3XpKpHx/1JNXlftKQBfdL7ldJ7WWYGnYiMngkyBCCyaUjT0+pjQZ9onLpIiKUTLmsuSXlzhAvx3WN9JOYRwyKdkMOcC4LfKWNxI6hwagGztCEtfKWnLBEyChcibp/Ca210fVoH+7R4v2ujD1/8wGbJe4fuJXY6gZ3E7KygcMotz5XgX9cWj66nc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OSYrA15kxfO4oal1GnLFd2kVZ0kVl2ZAiLjT/0R4dFamn+o2cI72qsl4LYFf0uSq+Dw4fW5hLOtPVnqy69P7GGjmraR6R+tFXmzwUn2sEFwXgq0A0LSL1LiHblC6ZyH64SysUpThHrv7d/ikHlvEKwlnxJTPQ8GdIr 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:(13230040)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2024 11:22:09.7442 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a546f256-c261-4f3a-7b5f-08dca0d28a14 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: BN3PEPF0000B070.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7692 Memory node probing is done as part of early_scan_node() that is called for each node with depth >= 1 (root node is at depth 0). According to Devicetree Specification v0.4, chapter 3.4, /memory node can only exists as a top level node. However, Xen incorrectly considers all the nodes with unit node name "memory" as RAM. This buggy behavior can result in a failure if there are other nodes in the device tree (at depth >= 2) with "memory" as unit node name. An example can be a "memory@xxx" node under /reserved-memory. Fix it by introducing device_tree_is_memory_node() to perform all the required checks to assess if a node is a proper /memory node. Fixes: 3e99c95ba1c8 ("arm, device tree: parse the DTB for RAM location and size") Signed-off-by: Michal Orzel Reviewed-by: Luca Fancellu Tested-by: Luca Fancellu Reviewed-by: Julien Grall --- Changes in v2: - improve the length check --- xen/arch/arm/bootfdt.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 6e060111d95b..f2892fce0a9c 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -83,6 +83,32 @@ static bool __init device_tree_node_compatible(const void *fdt, int node, return false; } +/* + * Check if a node is a proper /memory node according to Devicetree + * Specification v0.4, chapter 3.4. + */ +static bool __init device_tree_is_memory_node(const void *fdt, int node, + int depth) +{ + const char *type; + int len; + + if ( depth != 1 ) + return false; + + if ( !device_tree_node_matches(fdt, node, "memory") ) + return false; + + type = fdt_getprop(fdt, node, "device_type", &len); + if ( !type ) + return false; + + if ( (len <= strlen("memory")) || strcmp(type, "memory") ) + return false; + + return true; +} + void __init device_tree_get_reg(const __be32 **cell, uint32_t address_cells, uint32_t size_cells, paddr_t *start, paddr_t *size) @@ -448,7 +474,7 @@ static int __init early_scan_node(const void *fdt, * populated. So we should skip the parsing. */ if ( !efi_enabled(EFI_BOOT) && - device_tree_node_matches(fdt, node, "memory") ) + device_tree_is_memory_node(fdt, node, depth) ) rc = process_memory_node(fdt, node, name, depth, address_cells, size_cells, bootinfo_get_mem()); else if ( depth == 1 && !dt_node_cmp(name, "reserved-memory") )