From patchwork Fri Jan 12 20:07:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 1886225 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=2d8K0YlP; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=nGnzveG/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TBXf60tq4z1yPf for ; Sat, 13 Jan 2024 07:08:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CqOU6E/fmILrxzO1+PqTUQ2BhTLfjR8U6sXhToy/ht4=; b=2d8K0YlPXXbNS0+/iqndo45Xmf KYU3hpReX4ikGGddIbd2+zeRsV+R7Kbl9iGfl/9ymFKerZAf8FYYNXxvoAbSMs3HahoqQHK1S7eyT sP48gDsaObZmqZmr+LSYTQ2zG5au+utaDUG2KE4BCBMegT1pgzUACQRSLvOgyHf7ZvNvi16ASOEIJ 3Xc4dTinAnFr0AndGbaO1vHPE92FhBEu5Sa/NarFZqsi1gqakuomulUA3QWuFcNdX8FoC2q1cjWIj DOIcPjydhgJpu+LMPF+cbamefRHoz+yV94qFojcWMyaiAYfouO/9P9q3P+V/As4Y7HRhFTqC1NKz0 0/mVr3gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rONp2-003u3f-03; Fri, 12 Jan 2024 20:08:08 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rONos-003tsl-24; Fri, 12 Jan 2024 20:08:00 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CE8ABCE2470; Fri, 12 Jan 2024 20:07:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6629AC43390; Fri, 12 Jan 2024 20:07:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705090072; bh=Ftr3BKZw8coGMgoBGEKihNEJ4LajJ+HPG/Va2fa5Q/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nGnzveG/zSlluWPqK50MsRXFZgcqSqsT+b/j0PKAXVP7ZtdQyKAg1m3guf/d+IBVA 07pgc33Sbuh8cKPwsn4TbkcS4oenSfh3ljankCMJg+3KSR3xYKkq/FmivEMPbadwki Gnq+l6slqsgHmDwxM4NPuJLHDFpi9gubCjnjUfdn8Sxy8LDYoDjOakf6QcAqDVrAdr MDEBQQjx5CgxrWGB2llxj/Yj47M6+dU6XpmzgIP+dv/eye+gmUbhi9gVZJmKU4tJND 6j9+++zKYkaAyoMnCs8uOcZrzTy3AjyU8ipiPD0bw/T6SgAUz0oA+ED7fSzqWiE2Uf xFRtahWLY3/DA== From: Stephen Boyd To: Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Frank Rowand , Catalin Marinas , Will Deacon Subject: [PATCH 1/6] arm64: Unconditionally call unflatten_device_tree() Date: Fri, 12 Jan 2024 12:07:44 -0800 Message-ID: <20240112200750.4062441-2-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog In-Reply-To: <20240112200750.4062441-1-sboyd@kernel.org> References: <20240112200750.4062441-1-sboyd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240112_120758_874450_CC038352 X-CRM114-Status: GOOD ( 10.23 ) X-Spam-Score: -2.7 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Call this function unconditionally so that we can populate an empty DTB on platforms that don't boot with a firmware provided or builtin DTB. There's no harm in calling unflatten_device_tree() uncondi [...] Content analysis details: (-2.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2604:1380:40e1:4800:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Call this function unconditionally so that we can populate an empty DTB on platforms that don't boot with a firmware provided or builtin DTB. There's no harm in calling unflatten_device_tree() unconditionally. If there isn't a valid initial_boot_params dtb then unflatten_device_tree() returns early. Cc: Rob Herring Cc: Frank Rowand Cc: Catalin Marinas Cc: Will Deacon Cc: Signed-off-by: Stephen Boyd --- arch/arm64/kernel/setup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 417a8a86b2db..ede3d59dabf0 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -351,8 +351,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) /* Parse the ACPI tables for possible boot-time configuration */ acpi_boot_table_init(); - if (acpi_disabled) - unflatten_device_tree(); + unflatten_device_tree(); bootmem_init(); From patchwork Fri Jan 12 20:07:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 1886223 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Jq6wR9X1; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=pRzydyiS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TBXf31ksgz1yQ5 for ; Sat, 13 Jan 2024 07:08:11 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aq0wQCSGkYOTPQQZka2W9Tc3A/BNjaFDxorl+wK66v4=; b=Jq6wR9X1kI1/T0L27YGaDR54ja 7eI8uXG5YiCRYBN896AJA4nDgwGXaNrlpT1zo2TauzUEHpLZnVf3ukNKROMpgddSXPXQ3jIG+HrvG D/l3o0EZucqlL2Mqst1mXVGwb/pDBfpafAypn+7Va/aj1dNAT02OQXX+rkaNzbrlSIZh5n9on84Pq GzZIE2AF8DtsS8aAWiUeUWBgy5PLrWRwf8ZAYVM5hMBP24J+DljvjCP0l7obrryaZ7gsg7FTlT1UB mVMysTD8KRvv7uqnFQa2c4qYKjdktc/kVay34HN7chs3BGadFUv6+NAWKezQ9Eo+x7Up2h2mkYcIl S8GUfPbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rONoz-003u19-2X; Fri, 12 Jan 2024 20:08:05 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rONor-003tr7-2E; Fri, 12 Jan 2024 20:07:59 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 39A07B82392; Fri, 12 Jan 2024 20:07:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A051C433F1; Fri, 12 Jan 2024 20:07:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705090073; bh=hCAh9IJVjneFBmTI7MeY6517yfTJZxfzJ8kdqiP/+uU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pRzydyiSZaxydESQIgXX2hw/cVf7vyTmc+xuEwiwVlBKiyC2tWa8CvkSI8366MFYw 8SzWqLo/pkbptr5j5vAKr1z56Kk90vCACYI2PXj0ALa/bFf37lUixPzL04HSU6sU1C wqG2KjQY0pkoij12aFDltAVLeOZoCOwV99KVi/iKkJCnMGAdVUh4Fi0rOELKnCx7uD zAPLrjY6IzzNwVDG6Cs2gLMOIbsRQ4lfJrSkmxdEIpkF3Voe/+O2nWVrOTj03f+Fd2 qqrH++GNGcPFVa0oA8uzRTQgGRCHot6WZuRYR27/BoCvUWvV2N6obF523XhCQr7yHN aOfp871SxcCxw== From: Stephen Boyd To: Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Frank Rowand , Richard Weinberger , Anton Ivanov , Johannes Berg Subject: [PATCH 2/6] um: Unconditionally call unflatten_device_tree() Date: Fri, 12 Jan 2024 12:07:45 -0800 Message-ID: <20240112200750.4062441-3-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog In-Reply-To: <20240112200750.4062441-1-sboyd@kernel.org> References: <20240112200750.4062441-1-sboyd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240112_120757_893677_932F72FF X-CRM114-Status: GOOD ( 13.57 ) X-Spam-Score: -2.7 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Call this function unconditionally so that we can populate an empty DTB on platforms that don't boot with a command line provided DTB. There's no harm in calling unflatten_device_tree() unconditionall [...] Content analysis details: (-2.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2604:1380:4601:e00:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Call this function unconditionally so that we can populate an empty DTB on platforms that don't boot with a command line provided DTB. There's no harm in calling unflatten_device_tree() unconditionally. If there isn't a valid initial_boot_params dtb then unflatten_device_tree() returns early. Cc: Rob Herring Cc: Frank Rowand Cc: Richard Weinberger Cc: Anton Ivanov Cc: Johannes Berg Cc: Signed-off-by: Stephen Boyd --- arch/um/kernel/dtb.c | 14 +++++++------- drivers/of/unittest.c | 4 ---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/arch/um/kernel/dtb.c b/arch/um/kernel/dtb.c index 484141b06938..4954188a6a09 100644 --- a/arch/um/kernel/dtb.c +++ b/arch/um/kernel/dtb.c @@ -16,16 +16,16 @@ void uml_dtb_init(void) void *area; area = uml_load_file(dtb, &size); - if (!area) - return; + if (area) { + if (!early_init_dt_scan(area)) { + pr_err("invalid DTB %s\n", dtb); + memblock_free(area, size); + return; + } - if (!early_init_dt_scan(area)) { - pr_err("invalid DTB %s\n", dtb); - memblock_free(area, size); - return; + early_init_fdt_scan_reserved_mem(); } - early_init_fdt_scan_reserved_mem(); unflatten_device_tree(); } diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index e9e90e96600e..a8b27dd16ecf 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -4075,10 +4075,6 @@ static int __init of_unittest(void) add_taint(TAINT_TEST, LOCKDEP_STILL_OK); /* adding data for unittest */ - - if (IS_ENABLED(CONFIG_UML)) - unittest_unflatten_overlay_base(); - res = unittest_data_add(); if (res) return res; From patchwork Fri Jan 12 20:07:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 1886220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=SPRcze/w; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=OYIwB3Kd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TBXdz5zHDz1yPf for ; Sat, 13 Jan 2024 07:08:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4c9mWF8YgLblEXtBZS6u3l9ZtMToZFmO6GDr8hlYfo8=; b=SPRcze/wLozh4FyMwAFp524SFG VxXOlkOqaMgOKYqKYNjKpjBc/YvNCUI7HMAKaCwQje9nDquDsK8U7bT4+PID+33mQBuvN7u2/e6JL F4Sal/lPePu+Q3vStBUtfdxru7NoBmIJfek8P+gL/K1BsiygxF9l0fQ94gzAoF3Dyvoz3eMYiYkI8 5NVmzHya/Ruc8bzEeayqKZDopp31vG+M8UzxgwZKdhNXZumQGLiqbZBynDIlBuLJ+Wrf6gSlo3smK Dl3LjdhHKBEhFVXJw6R0zVE8Ec40mqyU1P8oN61tNRcTO3FQcGV4wzktHkYgHF8ir4Ok8mgn3/cvO GBaXZRDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rONov-003twh-1v; Fri, 12 Jan 2024 20:08:01 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rONoo-003tr6-2L; Fri, 12 Jan 2024 20:07:56 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 44A7761E47; Fri, 12 Jan 2024 20:07:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA086C43394; Fri, 12 Jan 2024 20:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705090074; bh=1E4tLOV0ALY1Bfj9SzYihrCA2jRIId2N3gEBgK6iS+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OYIwB3Kd1lvLubS58Ch++gSwaNSb/vqhoixvSQvAvgqJG87S3gmJYw5VUSlzDs3f5 csFg+vxWUSoiXPtNVuFSumlD4MkFRIRWVQQvyJHKayKu/EFkQOrj++jZToUtobBNP0 +a6lIT2voVAlju/kYLtDzryGwEZQ1405vmmM1W72JkVpv11hygoOYl+3eaBb67Uo8Z fgWZ5l39gqdPbykAVXITXpN2i2VUar5SMcArxxcXvSr7KPRGwOQkaOsf0FcM7oOit/ erSbIKrTVskKhMLrpWa6vgs3lAwIGQT3eFSn4oFjYtkdg8+ls0eBLzSmYOMruWNCnu TwQLUeGiY9tGQ== From: Stephen Boyd To: Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Frank Rowand Subject: [PATCH 3/6] of: Always unflatten in unflatten_and_copy_device_tree() Date: Fri, 12 Jan 2024 12:07:46 -0800 Message-ID: <20240112200750.4062441-4-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog In-Reply-To: <20240112200750.4062441-1-sboyd@kernel.org> References: <20240112200750.4062441-1-sboyd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240112_120754_802390_93C94A46 X-CRM114-Status: GOOD ( 11.23 ) X-Spam-Score: -2.7 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: We want to populate an empty DT whenever CONFIG_OF is enabled so that overlays can be applied and the DT unit tests can be run. Make unflatten_and_copy_device_tree() stop printing a warning if the 'in [...] Content analysis details: (-2.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2604:1380:4641:c500:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We want to populate an empty DT whenever CONFIG_OF is enabled so that overlays can be applied and the DT unit tests can be run. Make unflatten_and_copy_device_tree() stop printing a warning if the 'initial_boot_params' pointer is NULL. Instead, simply copy the dtb if there is one and then unflatten it. If there isn't a DT to copy, then the call to unflatten_device_tree() is largely a no-op, so nothing really changes here. Cc: Rob Herring Cc: Frank Rowand Signed-off-by: Stephen Boyd --- drivers/of/fdt.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index bf502ba8da95..b488ad86d456 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1318,6 +1318,21 @@ bool __init early_init_dt_scan(void *params) return true; } +static void __init copy_device_tree(void) +{ + int size; + void *dt; + + size = fdt_totalsize(initial_boot_params); + dt = early_init_dt_alloc_memory_arch(size, + roundup_pow_of_two(FDT_V17_SIZE)); + + if (dt) { + memcpy(dt, initial_boot_params, size); + initial_boot_params = dt; + } +} + /** * unflatten_device_tree - create tree of device_nodes from flat blob * @@ -1350,22 +1365,9 @@ void __init unflatten_device_tree(void) */ void __init unflatten_and_copy_device_tree(void) { - int size; - void *dt; + if (initial_boot_params) + copy_device_tree(); - if (!initial_boot_params) { - pr_warn("No valid device tree found, continuing without\n"); - return; - } - - size = fdt_totalsize(initial_boot_params); - dt = early_init_dt_alloc_memory_arch(size, - roundup_pow_of_two(FDT_V17_SIZE)); - - if (dt) { - memcpy(dt, initial_boot_params, size); - initial_boot_params = dt; - } unflatten_device_tree(); } From patchwork Fri Jan 12 20:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 1886221 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=i9w4Mfr2; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=m3UzQdLz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TBXf05pjyz1yQ5 for ; Sat, 13 Jan 2024 07:08:08 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vYDNvjesHTlIKCLwARGSpPK6wQdhLLHXvDXOfnsqfY4=; b=i9w4Mfr2h1aXGF0eGFDwZSx5qZ vJ9qeUsvRGaQCjdt2djw6p1N65/9TONmDs53B1Sn0BqZfcJ7WmVnj3g+vU/bIbOX6L0aK7p4pNiJJ 4xhPeV2ZxXFsHAJe+DM0pEhJCQBs0QxyRGyl7+nhY4gvPsa/+HdDAJH8bHa73WFW9y3QuzHxJfoO8 56koDa/ocqCzgzYj/nN3/TtH+gmoP3UHPXcNCTdiAj+Xi8W3GPz7dNcZO08aLPxwyzuFfBR6jVPs7 KDzGUtw3No8Z+vR4RvinIluX5l+hlWqCeF2DqkhB/6vyivq9EPHnrAxz7LFDzKNGtuELYsmTbWvm9 X02b2iVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rONox-003tyF-0u; Fri, 12 Jan 2024 20:08:03 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rONop-003trL-0p; Fri, 12 Jan 2024 20:07:57 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C4C9361E45; Fri, 12 Jan 2024 20:07:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38EF9C43330; Fri, 12 Jan 2024 20:07:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705090074; bh=MuWj9QthPbddxDViv2xChMAB0LdAS5I6Shz2oVWlz/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m3UzQdLzZZdjwFvzHAWKEZvD+Cab42B2q+YSDYLoUkgxb/afWAm1K1HVbEB8T4DR2 /7dW3Tl6B1DKqIqirS1GFyUUIuXDtHKXx/TdmLut2lEOlHbTKSzOcapo/y+c1CsZBy IBdCFlo+yIHwTyrI9wVqWTw5R1G1R4xxFQzaV5ml53zkC+9RaY/rPhNkq4Bl7lGbF5 gNZ0vLdeAxjow231PQuZlOYCrUywTxNNNOCfJm/ecN4cphX4A8tcoREDq0x5sEusaj xTdxP4DC6qiX2VyfFo3NxQs4wULNxInbgVOxKN2vXrjcIqnore+og7lRFLJZWOxc6G AMmuiqio79Q2Q== From: Stephen Boyd To: Rob Herring Cc: Frank Rowand , linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 4/6] of: Create of_root if no dtb provided by firmware Date: Fri, 12 Jan 2024 12:07:47 -0800 Message-ID: <20240112200750.4062441-5-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog In-Reply-To: <20240112200750.4062441-1-sboyd@kernel.org> References: <20240112200750.4062441-1-sboyd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240112_120755_379797_B59D68A2 X-CRM114-Status: GOOD ( 25.50 ) X-Spam-Score: -2.7 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Rowand When enabling CONFIG_OF on a platform where 'of_root' is not populated by firmware, we end up without a root node. In order to apply overlays and create subnodes of the root node, we need one. Create [...] Content analysis details: (-2.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2604:1380:4641:c500:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Frank Rowand When enabling CONFIG_OF on a platform where 'of_root' is not populated by firmware, we end up without a root node. In order to apply overlays and create subnodes of the root node, we need one. Create this root node by unflattening an empty builtin dtb. If firmware provides a flattened device tree (FDT) then the FDT is unflattened via setup_arch(). Otherwise, the call to unflatten(_and_copy)?_device_tree() will create an empty root node. We make of_have_populated_dt() return true only if the DTB was loaded by firmware so that existing callers don't change behavior after this patch. The call in the of platform code is removed because it prevents overlays from creating platform devices when the platform bus isn't fully initialized. Signed-off-by: Frank Rowand Link: https://lore.kernel.org/r/20230317053415.2254616-2-frowand.list@gmail.com Cc: Rob Herring [sboyd@kernel.org: Update of_have_populated_dt() to treat this empty dtb as not populated. Drop setup_of() initcall] Signed-off-by: Stephen Boyd --- drivers/of/Kconfig | 7 ++++++- drivers/of/Makefile | 2 +- drivers/of/empty_root.dts | 6 ++++++ drivers/of/fdt.c | 25 +++++++++++++++++++++++++ drivers/of/platform.c | 3 --- include/linux/of.h | 17 ++++++++++++----- 6 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 drivers/of/empty_root.dts diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index da9826accb1b..9628e48baa15 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -54,9 +54,14 @@ config OF_FLATTREE select CRC32 config OF_EARLY_FLATTREE - bool + bool "Functions for accessing Flat Devicetree (FDT) early in boot" select DMA_DECLARE_COHERENT if HAS_DMA && HAS_IOMEM select OF_FLATTREE + help + Normally selected by platforms that process an FDT that has been + passed to the kernel by the bootloader. If the bootloader does not + pass an FDT to the kernel and you need an empty devicetree that + contains only a root node to exist, then say Y here. config OF_PROMTREE bool diff --git a/drivers/of/Makefile b/drivers/of/Makefile index eff624854575..df305348d1cb 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -2,7 +2,7 @@ obj-y = base.o cpu.o device.o module.o platform.o property.o obj-$(CONFIG_OF_KOBJ) += kobj.o obj-$(CONFIG_OF_DYNAMIC) += dynamic.o -obj-$(CONFIG_OF_FLATTREE) += fdt.o +obj-$(CONFIG_OF_FLATTREE) += fdt.o empty_root.dtb.o obj-$(CONFIG_OF_EARLY_FLATTREE) += fdt_address.o obj-$(CONFIG_OF_PROMTREE) += pdt.o obj-$(CONFIG_OF_ADDRESS) += address.o diff --git a/drivers/of/empty_root.dts b/drivers/of/empty_root.dts new file mode 100644 index 000000000000..cf9e97a60f48 --- /dev/null +++ b/drivers/of/empty_root.dts @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-only +/dts-v1/; + +/ { + +}; diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index b488ad86d456..9fc7f8b4f48a 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -32,6 +32,13 @@ #include "of_private.h" +/* + * __dtb_empty_root_begin[] and __dtb_empty_root_end[] magically created by + * cmd_dt_S_dtb in scripts/Makefile.lib + */ +extern uint8_t __dtb_empty_root_begin[]; +extern uint8_t __dtb_empty_root_end[]; + /* * of_fdt_limit_memory - limit the number of regions in the /memory node * @limit: maximum entries @@ -1343,8 +1350,26 @@ static void __init copy_device_tree(void) */ void __init unflatten_device_tree(void) { + bool firmware_loaded = true; + + if (!initial_boot_params) { + initial_boot_params = (void *) __dtb_empty_root_begin; + /* fdt_totalsize() will be used for copy size */ + if (fdt_totalsize(initial_boot_params) > + __dtb_empty_root_end - __dtb_empty_root_begin) { + pr_err("invalid size in dtb_empty_root\n"); + return; + } + of_fdt_crc32 = crc32_be(~0, initial_boot_params, + fdt_totalsize(initial_boot_params)); + copy_device_tree(); + firmware_loaded = false; + } + __unflatten_device_tree(initial_boot_params, NULL, &of_root, early_init_dt_alloc_memory_arch, false); + if (!firmware_loaded) + of_node_set_flag(of_root, OF_EMPTY_ROOT); /* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ of_alias_scan(early_init_dt_alloc_memory_arch); diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 126d265aa7d8..20087bb8a46b 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -549,9 +549,6 @@ static int __init of_platform_default_populate_init(void) device_links_supplier_sync_state_pause(); - if (!of_have_populated_dt()) - return -ENODEV; - if (IS_ENABLED(CONFIG_PPC)) { struct device_node *boot_display = NULL; struct platform_device *dev; diff --git a/include/linux/of.h b/include/linux/of.h index 6a9ddf20e79a..390ad961ef01 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -151,6 +151,7 @@ extern struct device_node *of_stdout; #define OF_POPULATED_BUS 4 /* platform bus created for children */ #define OF_OVERLAY 5 /* allocated for an overlay */ #define OF_OVERLAY_FREE_CSET 6 /* in overlay cset being freed */ +#define OF_EMPTY_ROOT 7 /* the builtin empty root node */ #define OF_BAD_ADDR ((u64)-1) @@ -180,11 +181,6 @@ static inline bool is_of_node(const struct fwnode_handle *fwnode) &__of_fwnode_handle_node->fwnode : NULL; \ }) -static inline bool of_have_populated_dt(void) -{ - return of_root != NULL; -} - static inline bool of_node_is_root(const struct device_node *node) { return node && (node->parent == NULL); @@ -195,6 +191,17 @@ static inline int of_node_check_flag(const struct device_node *n, unsigned long return test_bit(flag, &n->_flags); } +/** + * of_have_populated_dt() - Has DT been populated by bootloader + * + * Return: True if a DTB has been populated by the bootloader and it isn't the + * empty builtin one. False otherwise. + */ +static inline bool of_have_populated_dt(void) +{ + return of_root != NULL && !of_node_check_flag(of_root, OF_EMPTY_ROOT); +} + static inline int of_node_test_and_set_flag(struct device_node *n, unsigned long flag) { From patchwork Fri Jan 12 20:07:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 1886224 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=MhyLKmL0; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Y8kgwibd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TBXf34yMNz1yXm for ; Sat, 13 Jan 2024 07:08:11 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Vxm7GroJb1jr7a7SKxct7zVVLJ9MIYxfQSDNcHJxJs8=; b=MhyLKmL066fEi76nBR1Qz2n85r p2gDkMXabQQvqlFG59UX23JfTwT7y0m+/rpf6+hmiBY6a4prdgo7majQgX8cPivkFpfdKZ1mD7y/6 ZKwsXVy+/Go2+LhR4eG3jfX7hZUlUtuEfvh+TAFdNcGf/ZSmDH9662bViJcZL4nxgBOEEa503RTbZ MYn+0+2nXRpH81cTqSo9B3sEe0W67YErHjewUsPbi6QGiKkMVhU9N0yfRrDupZg+5drvTjJtb5bWS ZF3f0VJNUd2vDqz7rNWF8UF8WJcCAJsLYSglDfjqQhHM2sRnhneR+nnt9rPhWvFOf7X16jzVvBL1k 7WVHr5nw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rONox-003tyc-22; Fri, 12 Jan 2024 20:08:03 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rONop-003tru-2e; Fri, 12 Jan 2024 20:07:57 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 56DAA61E52; Fri, 12 Jan 2024 20:07:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC66AC43601; Fri, 12 Jan 2024 20:07:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705090075; bh=QNmBS0brQeJSjUserQhzHk2Vt2IzcbhX82b9CN/v9CM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y8kgwibdxmE4vap0GuM/fVQuLavqIYEsi/kkmbe/DQ87QPH+0t1CqfbhrLlhb1UL7 HsKrA+qsZUl+LD2qh7XyoCRY68FeKquq9mWHhynzJkscVBNamnfsdrIokEUGS67SUs DPI8umccncrhCQPBTmfFVD9pIDflhg54WSTK/c+AFyumnZWqevRYptze5nxWAy/OKp yE/oFcwKeA8aWm8KE6nIeYSdurXI9VBChIHzWI0MMjdlCRZFqlE+p5Iv5QKxv/AAjV S9tenjVL7krLEEJ9qqZGhYxmpGtuN3+CCUhplyCBQyMn8i0jOHxtZGOf4SS6LTk4Eq iAbnScBTZWkxw== From: Stephen Boyd To: Rob Herring Cc: Frank Rowand , linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 5/6] of: unittest: treat missing of_root as error instead of fixing up Date: Fri, 12 Jan 2024 12:07:48 -0800 Message-ID: <20240112200750.4062441-6-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog In-Reply-To: <20240112200750.4062441-1-sboyd@kernel.org> References: <20240112200750.4062441-1-sboyd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240112_120755_901697_A6D35606 X-CRM114-Status: GOOD ( 12.67 ) X-Spam-Score: -5.4 (-----) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Rowand unflatten_device_tree() now ensures that the 'of_root' node is populated with the root of a default empty devicetree. Remove the unittest code that created 'of_root' if it was missing. Verify that 'of [...] Content analysis details: (-5.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [139.178.84.217 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Frank Rowand unflatten_device_tree() now ensures that the 'of_root' node is populated with the root of a default empty devicetree. Remove the unittest code that created 'of_root' if it was missing. Verify that 'of_root' is valid before attempting to attach the testcase-data subtree. Remove the unittest code that unflattens the unittest overlay base if architecture is UML because that is always done now. Signed-off-by: Frank Rowand Link: https://lore.kernel.org/r/20230317053415.2254616-3-frowand.list@gmail.com Cc: Rob Herring Signed-off-by: Stephen Boyd --- drivers/of/unittest.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index a8b27dd16ecf..742d919e8ab4 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1732,20 +1732,16 @@ static int __init unittest_data_add(void) return -EINVAL; } + /* attach the sub-tree to live tree */ if (!of_root) { - of_root = unittest_data_node; - for_each_of_allnodes(np) - __of_attach_node_sysfs(np); - of_aliases = of_find_node_by_path("/aliases"); - of_chosen = of_find_node_by_path("/chosen"); - of_overlay_mutex_unlock(); - return 0; + pr_warn("%s: no live tree to attach sub-tree\n", __func__); + kfree(unittest_data); + return -ENODEV; } EXPECT_BEGIN(KERN_INFO, "Duplicate name in testcase-data, renamed to \"duplicate-name#1\""); - /* attach the sub-tree to live tree */ np = unittest_data_node->child; while (np) { struct device_node *next = np->sibling; From patchwork Fri Jan 12 20:07:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 1886222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=kiN8r/s3; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=W9/SlA7d; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TBXf26Bmvz1yPf for ; Sat, 13 Jan 2024 07:08:10 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1vVRB30p0TE0ShEM895tQdqgtFH80Bg3fbBTjNboouk=; b=kiN8r/s3tMg22gS95CMzU6Va9U 2Tpi8rONdUTBobbfeUbitw8FsCe0pr3Bnko7FBjYDcG+7vUf1wO5R6Qu+KLoebgSJdUdfUOVbpzyS 6tmc4pWy2Calo0PcGHBHjUL7KWEJHxGPSNhbM6Vydy2aHH2n1uh3l0JXJ3T+9Li0yXH5143LMH3RW 1G4OCvqf4iDv6BYWQXOVEPzMMtqSNZ9QFSDXardC+ZaoIATr5gus6n+RyhEWWdUWiQLvqef5sS+HW 7fHf3tTu+OcHGIsdsakNptXjZHqmHT5JMHwrQ/VhEouWwkD6+Xtpk7rWDS83bKbQV/kjeIoFHs93W hE4gU7OQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rONoy-003u07-2U; Fri, 12 Jan 2024 20:08:04 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rONoq-003tsD-1R; Fri, 12 Jan 2024 20:07:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id EF51C61E5A; Fri, 12 Jan 2024 20:07:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51766C43394; Fri, 12 Jan 2024 20:07:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705090075; bh=ua+X20080YRjcHe0C1o6t3ehjcRZtGl3WAk/t15eQ/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W9/SlA7dwlMSfXI4eTDVjMoPuCuC9FE1VqpmUJNPyPwQcZ8vlOb3P4KZF4WInPPrS D8k7Eg93W+UcWyPzE34O9t7/0Rr/Jc5XD6DXkEd93rA65eBuxCnEml4DGbpVStHG91 KfzR94Rm5w+TjxilnrPr76MZfQCzXDw0Dnl4o8kaSyQYVsyfxyMT8lW7R/dRKq3C0K 4eCSbmy0jRzfvTWgthjDeZ4Q1Knu8TPgS+6KWnQYxLighp/oo63e1pZ3JTdIiz0hea iA41au/DcqhZ+iLg00zV0JqHCZ0cLYgx2ywejUbFVJO4av9lBILwhzoqmlQq8qLy9V uRIv5ur7Xhdug== From: Stephen Boyd To: Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Frank Rowand , David Gow , Brendan Higgins Subject: [PATCH 6/6] of: Add KUnit test to confirm DTB is loaded Date: Fri, 12 Jan 2024 12:07:49 -0800 Message-ID: <20240112200750.4062441-7-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog In-Reply-To: <20240112200750.4062441-1-sboyd@kernel.org> References: <20240112200750.4062441-1-sboyd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240112_120756_586028_B2B69B31 X-CRM114-Status: GOOD ( 17.75 ) X-Spam-Score: -5.4 (-----) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add a KUnit test that confirms a DTB has been loaded, i.e. there is a root node, and that the of_have_populated_dt() API works properly. Cc: Rob Herring Cc: Frank Rowand Cc: David Gow Cc: Brendan Higgins Signed-off-by: Stephen Boyd List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add a KUnit test that confirms a DTB has been loaded, i.e. there is a root node, and that the of_have_populated_dt() API works properly. Cc: Rob Herring Cc: Frank Rowand Cc: David Gow Cc: Brendan Higgins Signed-off-by: Stephen Boyd Reviewed-by: David Gow --- drivers/of/.kunitconfig | 3 ++ drivers/of/Kconfig | 9 ++++ drivers/of/Makefile | 2 + drivers/of/of_test.c | 98 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 drivers/of/.kunitconfig create mode 100644 drivers/of/of_test.c diff --git a/drivers/of/.kunitconfig b/drivers/of/.kunitconfig new file mode 100644 index 000000000000..5a8fee11978c --- /dev/null +++ b/drivers/of/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_OF=y +CONFIG_OF_KUNIT_TEST=y diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 9628e48baa15..a527ba8451d9 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -37,6 +37,15 @@ config OF_UNITTEST If unsure, say N here. This option is not safe to enable. +config OF_KUNIT_TEST + tristate "Devicetree KUnit DTB Test" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + This option builds KUnit unit tests for device tree infrastructure. + + If unsure, say N here, but this option is safe to enable. + config OF_ALL_DTBS bool "Build all Device Tree Blobs" depends on COMPILE_TEST diff --git a/drivers/of/Makefile b/drivers/of/Makefile index df305348d1cb..251d33532148 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -19,4 +19,6 @@ obj-y += kexec.o endif endif +obj-$(CONFIG_OF_KUNIT_TEST) += of_test.o + obj-$(CONFIG_OF_UNITTEST) += unittest-data/ diff --git a/drivers/of/of_test.c b/drivers/of/of_test.c new file mode 100644 index 000000000000..7609ad3081b9 --- /dev/null +++ b/drivers/of/of_test.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit tests for OF APIs + */ +#include +#include + +#include + +/* + * Test that the root node "/" exists. + */ +static void dtb_root_node_found_by_path(struct kunit *test) +{ + struct device_node *np; + + np = of_find_node_by_path("/"); + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, np); + of_node_put(np); +} + +/* + * Test that the of_root global variable is always populated when DT + * code is enabled. + */ +static void dtb_root_node_populates_of_root(struct kunit *test) +{ + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, of_root); +} + +static struct kunit_case dtb_test_cases[] = { + KUNIT_CASE(dtb_root_node_found_by_path), + KUNIT_CASE(dtb_root_node_populates_of_root), + {} +}; + +/* + * Test suite to confirm a live DTB is loaded. + */ +static struct kunit_suite dtb_suite = { + .name = "dtb", + .test_cases = dtb_test_cases, +}; + +/* + * Test that calling of_have_populated_dt() returns false when + * the OF_EMPTY_ROOT flag isn't set. + */ +static void of_have_populated_dt_false_when_flag_set(struct kunit *test) +{ + bool was_set; + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, of_root); + + was_set = of_node_test_and_set_flag(of_root, OF_EMPTY_ROOT); + KUNIT_EXPECT_FALSE(test, of_have_populated_dt()); + + if (!was_set) + of_node_clear_flag(of_root, OF_EMPTY_ROOT); +} + +/* + * Test that calling of_have_populated_dt() returns false when + * the OF_EMPTY_ROOT flag isn't set. + */ +static void of_have_populated_dt_true_when_flag_clear(struct kunit *test) +{ + bool was_set; + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, of_root); + + was_set = of_node_check_flag(of_root, OF_EMPTY_ROOT); + of_node_set_flag(of_root, OF_EMPTY_ROOT); + KUNIT_EXPECT_FALSE(test, of_have_populated_dt()); + + if (was_set) + of_node_set_flag(of_root, OF_EMPTY_ROOT); +} + +static struct kunit_case of_have_populated_dt_test_cases[] = { + KUNIT_CASE(of_have_populated_dt_false_when_flag_set), + KUNIT_CASE(of_have_populated_dt_true_when_flag_clear), + {} +}; + +/* + * Test suite to confirm behavior of of_have_populated_dt(). + */ +static struct kunit_suite of_have_populated_dt_suite = { + .name = "of_have_populated_dt", + .test_cases = of_have_populated_dt_test_cases, +}; + +kunit_test_suites( + &dtb_suite, + &of_have_populated_dt_suite, +); +MODULE_LICENSE("GPL");