From patchwork Thu Mar 16 12:11:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1757878 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) 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=rAXeR+iu; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=K6TKlhaA; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PcmMg1046z1yWs for ; Thu, 16 Mar 2023 23:11:43 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=UdShOZCf5RmL7uOee/6RW1gSTHvAgFtgILHgkmOXPko=; b=rAXeR+iu+BLKwZ kaN9AWg5X3kOlMWESWufVjSJRLM8H6SdmGswkfBFQCp9PoTXDziM1a7r6gvy3ESEP8AxKSA9ravdd TzuhDrHEd+lLMNzdP9xAWnVBab7weU/44KXZw2LBesOeW7aR3HDMlUxy1Zbr2e4Lr4YuZaIBAQwrj W4aJKK0Pc1Tqe6Q+DbPMwriZfKQOjPRWfX6o61hvCTgfwDLZCuZoGxX+KCrMjPxwXWzWGJRJpkvLp +0b9siZaBDycKbBGEkwhhO108OnLReL6TIOce8SDQ/4jrPe5FqmwBCvRTmH+F18bcM4nohdhfA89H /3coMkkN7onFNuYOusqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcmS5-00GLgQ-2X; Thu, 16 Mar 2023 12:11:25 +0000 Received: from m126.mail.126.com ([220.181.12.36]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcmS2-00GLeL-1l for opensbi@lists.infradead.org; Thu, 16 Mar 2023 12:11:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=n23gG IFuVscqSA0/A3/7wqkQGd3GlpK7sLkt4dFgCbA=; b=K6TKlhaALVhGjmV1Y2l0q 9e7vJO8vP0Y0/NREn89gSj05V8KN2oOElaozDqEYBOiUD72In8xwmG91YzMeMjG0 lYiVUP4WuCLB8BPYVq/O9VHUlPnd+gh5d2e9OAHZCn6BoubZ2aqCNuM/Lxxqi34P w4VQ44E+7SK1y7XQTaSNF4= Received: from x390.lan (unknown [58.246.230.147]) by zwqz-smtp-mta-g5-0 (Coremail) with SMTP id _____wDHPk9gBxNkic+0AA--.29314S2; Thu, 16 Mar 2023 20:11:13 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v2] lib: sbi: Fix how to check whether the domain contains fw_region Date: Thu, 16 Mar 2023 20:11:11 +0800 Message-Id: <20230316121111.122741-1-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CM-TRANSID: _____wDHPk9gBxNkic+0AA--.29314S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxXF1xGFW8Zryxtw13Kw43Awb_yoWrArW5pa 45AF12gr4Iqr1UZwnrGa1DXFWvy348tayqk398CwnYy3WxAFyDCr4kZw1j9F9rAF97Aa1U uFs2gr1DCF43XaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zE9a93UUUUU= X-Originating-IP: [58.246.230.147] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1xU0Ol53a0EVYAACs4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230316_051123_159942_7BF757B7 X-CRM114-Status: GOOD ( 12.79 ) X-Spam-Score: -0.2 (/) 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: Because firmware is split into rw/rx segments, it cannot be recorded by a root_fw_region. This problem is solved by adding a flag fw_region_inited to sbi_domain. Signed-off-by: Xiang W --- v2 changes: Remove unused have_fw_reg Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -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 X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Because firmware is split into rw/rx segments, it cannot be recorded by a root_fw_region. This problem is solved by adding a flag fw_region_inited to sbi_domain. Signed-off-by: Xiang W Reviewed-by: Himanshu Chauhan Reviewed-by: Anup Patel --- v2 changes: Remove unused have_fw_reg include/sbi/sbi_domain.h | 2 ++ lib/sbi/sbi_domain.c | 28 +++++++--------------------- lib/utils/fdt/fdt_domain.c | 1 + 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h index eaca7f0..124ea90 100644 --- a/include/sbi/sbi_domain.h +++ b/include/sbi/sbi_domain.h @@ -122,6 +122,8 @@ struct sbi_domain { bool system_reset_allowed; /** Is domain allowed to suspend the system */ bool system_suspend_allowed; + /** Identifies whether to include the firmware region */ + bool fw_region_inited; }; /** The root domain instance */ diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 4d7b80a..d6e9ff6 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -30,7 +30,6 @@ static struct sbi_hartmask root_hmask = { 0 }; #define ROOT_REGION_MAX 16 static u32 root_memregs_count = 0; -static struct sbi_domain_memregion root_fw_region; static struct sbi_domain_memregion root_memregs[ROOT_REGION_MAX + 1] = { 0 }; struct sbi_domain root = { @@ -39,6 +38,7 @@ struct sbi_domain root = { .regions = root_memregs, .system_reset_allowed = true, .system_suspend_allowed = true, + .fw_region_inited = false, }; bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid) @@ -69,14 +69,6 @@ ulong sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom, return ret; } -static void domain_memregion_initfw(struct sbi_domain_memregion *reg) -{ - if (!reg) - return; - - sbi_memcpy(reg, &root_fw_region, sizeof(*reg)); -} - void sbi_domain_memregion_init(unsigned long addr, unsigned long size, unsigned long flags, @@ -255,7 +247,6 @@ static int sanitize_domain(const struct sbi_platform *plat, struct sbi_domain *dom) { u32 i, j, count; - bool have_fw_reg; struct sbi_domain_memregion treg, *reg, *reg1; /* Check possible HARTs */ @@ -288,17 +279,11 @@ static int sanitize_domain(const struct sbi_platform *plat, } } - /* Count memory regions and check presence of firmware region */ + /* Count memory regions */ count = 0; - have_fw_reg = false; - sbi_domain_for_each_memregion(dom, reg) { - if (reg->order == root_fw_region.order && - reg->base == root_fw_region.base && - reg->flags == root_fw_region.flags) - have_fw_reg = true; + sbi_domain_for_each_memregion(dom, reg) count++; - } - if (!have_fw_reg) { + if (!dom->fw_region_inited) { sbi_printf("%s: %s does not have firmware region\n", __func__, dom->name); return SBI_EINVAL; @@ -732,8 +717,7 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid) sbi_domain_memregion_init(scratch->fw_start, scratch->fw_rw_offset, (SBI_DOMAIN_MEMREGION_M_READABLE | SBI_DOMAIN_MEMREGION_M_EXECUTABLE), - &root_fw_region); - domain_memregion_initfw(&root_memregs[root_memregs_count++]); + &root_memregs[root_memregs_count++]); sbi_domain_memregion_init((scratch->fw_start + scratch->fw_rw_offset), (scratch->fw_size - scratch->fw_rw_offset), @@ -741,6 +725,8 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid) SBI_DOMAIN_MEMREGION_M_WRITABLE), &root_memregs[root_memregs_count++]); + root.fw_region_inited = true; + /* Root domain allow everything memory region */ sbi_domain_memregion_init(0, ~0UL, (SBI_DOMAIN_MEMREGION_READABLE | diff --git a/lib/utils/fdt/fdt_domain.c b/lib/utils/fdt/fdt_domain.c index adcb94b..bb6d17d 100644 --- a/lib/utils/fdt/fdt_domain.c +++ b/lib/utils/fdt/fdt_domain.c @@ -358,6 +358,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque) return SBI_EINVAL; memcpy(®ions[val32++], reg, sizeof(*reg)); } + dom->fw_region_inited = root.fw_region_inited; /* Read "boot-hart" DT property */ val32 = -1U;