From patchwork Wed Jul 31 18:16:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Haas X-Patchwork-Id: 1967260 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=EPkmObun; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=nndGNePY; 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=opensbi-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 4WZ0g24tcwz1yfG for ; Thu, 1 Aug 2024 04:17:02 +1000 (AEST) 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:References:In-Reply-To: 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: List-Owner; bh=ercJi1YdSjLb0aD3GCH+qXT26KZ5xuE4Yzw37LB8TWY=; b=EPkmObununAEIA EOCNzjy8f2qcgTzzw0WyqVgtB6Ig12I+91axQ+4wpR3WaBhdduYY2IZ2ONxqdqMb8Nu80ycFfxP2u NL2L3eii1gMjjTyI1wbj+fL7HFwfaoPMRvSzgPd1T3cCRhZ8hwicqwt2JRqCZmDMGAsC4AGP7nT+2 MtxQ84r9fhCtKelqYYTfffD0wb0V6Wwls2T9ROeT/chT3xAEsaaONHbZItgYKXmKH72b64ogudeHK qI1B48itZO1kYIF7fjs8SBV9pMABuu1YDX40juduPJw0mT5LvT/SXxcdwBtjyBuArMD7YABiSrIHk z/Fcz1K//e4PLArItKeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsV-000000026eS-1RJL; Wed, 31 Jul 2024 18:16:47 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsR-000000026cW-0KRa for opensbi@lists.infradead.org; Wed, 31 Jul 2024 18:16:46 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1fc5549788eso46882455ad.1 for ; Wed, 31 Jul 2024 11:16:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722449802; x=1723054602; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pzGPvPAc8iCms8LPkot1g1BHBmp9zel+Wy37/RXW/HQ=; b=nndGNePY8oxD2IB2NaMQ09y9V656rIKFEFt81gMPq6SCQCn9MxjB8vOKXc5CiOpeya 9h46cgDJv/bHlf2Qg5QpdQ/ZuFeC6NGvSvoQ1kuI10upFG5zYg8JiD+kmPErCwORd7DJ XGmNtrZGH31fduzHUTrGSTf/lDyWDkqwids5oAzpEKXs7bTvHsIGz6sM7IJwyVtPIUld TMSroCuUDrX1dA9D3NGB18zdperUq0eftstTC2e6llE3MhAnqFa5KjkfMXzd8YjDDDot +YBGCe5BC2hHgjS5upCSzJW3fmiI/I/1H9XpCHznAKV+QwLbLaduESB/qkoH+eS4vtg2 cZEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722449802; x=1723054602; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pzGPvPAc8iCms8LPkot1g1BHBmp9zel+Wy37/RXW/HQ=; b=tL4EYdp7SkuiEjAV2qEuJhtdkUOwZOR50j5zqI1VUakcz8Vqt0RG1QO/Gf0GNkAHuR kLGdL4bEhYqDglSA+5qzZDXsy20TYVjadgMonjrkAG84rkzfOIqk4hgkH7ctbDYQBC+v Uo2DYGZcy+RztU/ZvxzETMOv6dC9E3XKEP35GESMuvKzZtPG/NR2XKzfPd/5BFCnQ31R zzyyRr0xqVvCRQv9TmuKarVnY7AWuPhIbcmF57yFx6Nm2FG1qHa0s4sy6kfL7mzUoPDg vHO1+BGjy9vHSSXdXDSOk4Uxk8Ef75AJpk0u+bczhrIuo21Sw8g4M675+Tu9lGeqO06g FbDw== X-Gm-Message-State: AOJu0YwYvZEldxBJSQ9Ly9yimfrbl7dWqSNd5KRDY+18L99/U3hDBd4x 1zWoOMQU4pDXLPYqGIoNxVXuK0f+SXGvSvIW1qrqBXnW3J4Fjmp5pZMB5vpQ X-Google-Smtp-Source: AGHT+IFbecxc7yS80Hv5e3nt5KQ+MOIZSUGuLeWX8rxKg+TmE/cEa9WIJPdoelewRfPQ0D/agZtrmA== X-Received: by 2002:a17:903:18d:b0:1fb:80cb:f577 with SMTP id d9443c01a7336-1ff4ce337a0mr2267905ad.5.1722449802004; Wed, 31 Jul 2024 11:16:42 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fed7cfe767sm123283635ad.97.2024.07.31.11.16.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jul 2024 11:16:41 -0700 (PDT) From: Gregor Haas To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, Gregor Haas Subject: [PATCH 1/8] lib: sbi: Separate domain-handling code from memregion-handling code Date: Wed, 31 Jul 2024 11:16:22 -0700 Message-ID: <20240731181629.269898-2-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731181629.269898-1-gregorhaas1997@gmail.com> References: <20240731181629.269898-1-gregorhaas1997@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_111643_167574_45EB8FFD X-CRM114-Status: GOOD ( 21.80 ) X-Spam-Score: -1.8 (-) 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: The next changes in this patch series will add a large amount of functionality to the domain memregion abstraction. Split out memregions from domains, since sbi_domain.c is already almost 900 lines lo [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62c listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [gregorhaas1997(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gregorhaas1997(at)gmail.com] 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 The next changes in this patch series will add a large amount of functionality to the domain memregion abstraction. Split out memregions from domains, since sbi_domain.c is already almost 900 lines long. This commit verbatim moves code without modifying it, except to add new includes and integrate sbi_memregion.c into the build system. --- include/sbi/sbi_domain.h | 184 +--------------------- include/sbi/sbi_memregion.h | 199 ++++++++++++++++++++++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_domain.c | 296 +---------------------------------- lib/sbi/sbi_memregion.c | 301 ++++++++++++++++++++++++++++++++++++ 5 files changed, 507 insertions(+), 474 deletions(-) create mode 100644 include/sbi/sbi_memregion.h create mode 100644 lib/sbi/sbi_memregion.c diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h index a6e99c6..596bab3 100644 --- a/include/sbi/sbi_domain.h +++ b/include/sbi/sbi_domain.h @@ -14,150 +14,10 @@ #include #include #include +#include struct sbi_scratch; -/** Domain access types */ -enum sbi_domain_access { - SBI_DOMAIN_READ = (1UL << 0), - SBI_DOMAIN_WRITE = (1UL << 1), - SBI_DOMAIN_EXECUTE = (1UL << 2), - SBI_DOMAIN_MMIO = (1UL << 3) -}; - -/** Representation of OpenSBI domain memory region */ -struct sbi_domain_memregion { - /** - * Size of memory region as power of 2 - * It has to be minimum 3 and maximum __riscv_xlen - */ - unsigned long order; - /** - * Base address of memory region - * It must be 2^order aligned address - */ - unsigned long base; - /** Flags representing memory region attributes */ -#define SBI_DOMAIN_MEMREGION_M_READABLE (1UL << 0) -#define SBI_DOMAIN_MEMREGION_M_WRITABLE (1UL << 1) -#define SBI_DOMAIN_MEMREGION_M_EXECUTABLE (1UL << 2) -#define SBI_DOMAIN_MEMREGION_SU_READABLE (1UL << 3) -#define SBI_DOMAIN_MEMREGION_SU_WRITABLE (1UL << 4) -#define SBI_DOMAIN_MEMREGION_SU_EXECUTABLE (1UL << 5) - -#define SBI_DOMAIN_MEMREGION_ACCESS_MASK (0x3fUL) -#define SBI_DOMAIN_MEMREGION_M_ACCESS_MASK (0x7UL) -#define SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK (0x38UL) - -#define SBI_DOMAIN_MEMREGION_SU_ACCESS_SHIFT (3) - -#define SBI_DOMAIN_MEMREGION_SHARED_RDONLY \ - (SBI_DOMAIN_MEMREGION_M_READABLE | \ - SBI_DOMAIN_MEMREGION_SU_READABLE) - -#define SBI_DOMAIN_MEMREGION_SHARED_SUX_MRX \ - (SBI_DOMAIN_MEMREGION_M_READABLE | \ - SBI_DOMAIN_MEMREGION_M_EXECUTABLE | \ - SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) - -#define SBI_DOMAIN_MEMREGION_SHARED_SUX_MX \ - (SBI_DOMAIN_MEMREGION_M_EXECUTABLE | \ - SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) - -#define SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW \ - (SBI_DOMAIN_MEMREGION_M_READABLE | \ - SBI_DOMAIN_MEMREGION_M_WRITABLE | \ - SBI_DOMAIN_MEMREGION_SU_READABLE| \ - SBI_DOMAIN_MEMREGION_SU_WRITABLE) - -#define SBI_DOMAIN_MEMREGION_SHARED_SUR_MRW \ - (SBI_DOMAIN_MEMREGION_M_READABLE | \ - SBI_DOMAIN_MEMREGION_M_WRITABLE | \ - SBI_DOMAIN_MEMREGION_SU_READABLE) - - /* Shared read-only region between M and SU mode */ -#define SBI_DOMAIN_MEMREGION_IS_SUR_MR(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ - SBI_DOMAIN_MEMREGION_SHARED_RDONLY) - - /* Shared region: SU execute-only and M read/execute */ -#define SBI_DOMAIN_MEMREGION_IS_SUX_MRX(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ - SBI_DOMAIN_MEMREGION_SHARED_SUX_MRX) - - /* Shared region: SU and M execute-only */ -#define SBI_DOMAIN_MEMREGION_IS_SUX_MX(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ - SBI_DOMAIN_MEMREGION_SHARED_SUX_MX) - - /* Shared region: SU and M read/write */ -#define SBI_DOMAIN_MEMREGION_IS_SURW_MRW(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ - SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW) - - /* Shared region: SU read-only and M read/write */ -#define SBI_DOMAIN_MEMREGION_IS_SUR_MRW(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ - SBI_DOMAIN_MEMREGION_SHARED_SUR_MRW) - - /* - * Check if region flags match with any of the above - * mentioned shared region type - */ -#define SBI_DOMAIN_MEMREGION_IS_SHARED(_flags) \ - (SBI_DOMAIN_MEMREGION_IS_SUR_MR(_flags) || \ - SBI_DOMAIN_MEMREGION_IS_SUX_MRX(_flags) || \ - SBI_DOMAIN_MEMREGION_IS_SUX_MX(_flags) || \ - SBI_DOMAIN_MEMREGION_IS_SURW_MRW(_flags)|| \ - SBI_DOMAIN_MEMREGION_IS_SUR_MRW(_flags)) - -#define SBI_DOMAIN_MEMREGION_M_ONLY_ACCESS(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK) && \ - !(__flags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK)) - -#define SBI_DOMAIN_MEMREGION_SU_ONLY_ACCESS(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK) && \ - !(__flags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK)) - -/** Bit to control if permissions are enforced on all modes */ -#define SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS (1UL << 6) - -#define SBI_DOMAIN_MEMREGION_M_RWX \ - (SBI_DOMAIN_MEMREGION_M_READABLE | \ - SBI_DOMAIN_MEMREGION_M_WRITABLE | \ - SBI_DOMAIN_MEMREGION_M_EXECUTABLE) - -#define SBI_DOMAIN_MEMREGION_SU_RWX \ - (SBI_DOMAIN_MEMREGION_SU_READABLE | \ - SBI_DOMAIN_MEMREGION_SU_WRITABLE | \ - SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) - -/* Unrestricted M-mode accesses but enfoced on SU-mode */ -#define SBI_DOMAIN_MEMREGION_READABLE \ - (SBI_DOMAIN_MEMREGION_SU_READABLE | \ - SBI_DOMAIN_MEMREGION_M_RWX) -#define SBI_DOMAIN_MEMREGION_WRITEABLE \ - (SBI_DOMAIN_MEMREGION_SU_WRITABLE | \ - SBI_DOMAIN_MEMREGION_M_RWX) -#define SBI_DOMAIN_MEMREGION_EXECUTABLE \ - (SBI_DOMAIN_MEMREGION_SU_EXECUTABLE | \ - SBI_DOMAIN_MEMREGION_M_RWX) - -/* Enforced accesses across all modes */ -#define SBI_DOMAIN_MEMREGION_ENF_READABLE \ - (SBI_DOMAIN_MEMREGION_SU_READABLE | \ - SBI_DOMAIN_MEMREGION_M_READABLE) -#define SBI_DOMAIN_MEMREGION_ENF_WRITABLE \ - (SBI_DOMAIN_MEMREGION_SU_WRITABLE | \ - SBI_DOMAIN_MEMREGION_M_WRITABLE) -#define SBI_DOMAIN_MEMREGION_ENF_EXECUTABLE \ - (SBI_DOMAIN_MEMREGION_SU_EXECUTABLE | \ - SBI_DOMAIN_MEMREGION_M_EXECUTABLE) - -#define SBI_DOMAIN_MEMREGION_MMIO (1UL << 31) - unsigned long flags; -}; - /** Maximum number of domains */ #define SBI_DOMAIN_MAX_INDEX 32 @@ -246,48 +106,6 @@ bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid); ulong sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom, ulong hbase); -/** - * Initialize a domain memory region based on it's physical - * address and size. - * - * @param addr start physical address of memory region - * @param size physical size of memory region - * @param flags memory region flags - * @param reg pointer to memory region being initialized - */ -void sbi_domain_memregion_init(unsigned long addr, - unsigned long size, - unsigned long flags, - struct sbi_domain_memregion *reg); - -/** - * Check whether we can access specified address for given mode and - * memory region flags under a domain - * @param dom pointer to domain - * @param addr the address to be checked - * @param mode the privilege mode of access - * @param access_flags bitmask of domain access types (enum sbi_domain_access) - * @return true if access allowed otherwise false - */ -bool sbi_domain_check_addr(const struct sbi_domain *dom, - unsigned long addr, unsigned long mode, - unsigned long access_flags); - -/** - * Check whether we can access specified address range for given mode and - * memory region flags under a domain - * @param dom pointer to domain - * @param addr the start of the address range to be checked - * @param size the size of the address range to be checked - * @param mode the privilege mode of access - * @param access_flags bitmask of domain access types (enum sbi_domain_access) - * @return TRUE if access allowed otherwise FALSE - */ -bool sbi_domain_check_addr_range(const struct sbi_domain *dom, - unsigned long addr, unsigned long size, - unsigned long mode, - unsigned long access_flags); - /** Dump domain details on the console */ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix); diff --git a/include/sbi/sbi_memregion.h b/include/sbi/sbi_memregion.h new file mode 100644 index 0000000..8a62fc0 --- /dev/null +++ b/include/sbi/sbi_memregion.h @@ -0,0 +1,199 @@ + +#ifndef __SBI_MEMREGION_H__ +#define __SBI_MEMREGION_H__ + +#include + +/** Domain access types */ +enum sbi_domain_access { + SBI_DOMAIN_READ = (1UL << 0), + SBI_DOMAIN_WRITE = (1UL << 1), + SBI_DOMAIN_EXECUTE = (1UL << 2), + SBI_DOMAIN_MMIO = (1UL << 3) +}; + +/** Representation of OpenSBI domain memory region */ +struct sbi_domain_memregion { + /** + * Size of memory region as power of 2 + * It has to be minimum 3 and maximum __riscv_xlen + */ + unsigned long order; + /** + * Base address of memory region + * It must be 2^order aligned address + */ + unsigned long base; + /** Flags representing memory region attributes */ +#define SBI_DOMAIN_MEMREGION_M_READABLE (1UL << 0) +#define SBI_DOMAIN_MEMREGION_M_WRITABLE (1UL << 1) +#define SBI_DOMAIN_MEMREGION_M_EXECUTABLE (1UL << 2) +#define SBI_DOMAIN_MEMREGION_SU_READABLE (1UL << 3) +#define SBI_DOMAIN_MEMREGION_SU_WRITABLE (1UL << 4) +#define SBI_DOMAIN_MEMREGION_SU_EXECUTABLE (1UL << 5) + +#define SBI_DOMAIN_MEMREGION_ACCESS_MASK (0x3fUL) +#define SBI_DOMAIN_MEMREGION_M_ACCESS_MASK (0x7UL) +#define SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK (0x38UL) + +#define SBI_DOMAIN_MEMREGION_SU_ACCESS_SHIFT (3) + +#define SBI_DOMAIN_MEMREGION_SHARED_RDONLY \ + (SBI_DOMAIN_MEMREGION_M_READABLE | \ + SBI_DOMAIN_MEMREGION_SU_READABLE) + +#define SBI_DOMAIN_MEMREGION_SHARED_SUX_MRX \ + (SBI_DOMAIN_MEMREGION_M_READABLE | \ + SBI_DOMAIN_MEMREGION_M_EXECUTABLE | \ + SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) + +#define SBI_DOMAIN_MEMREGION_SHARED_SUX_MX \ + (SBI_DOMAIN_MEMREGION_M_EXECUTABLE | \ + SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) + +#define SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW \ + (SBI_DOMAIN_MEMREGION_M_READABLE | \ + SBI_DOMAIN_MEMREGION_M_WRITABLE | \ + SBI_DOMAIN_MEMREGION_SU_READABLE| \ + SBI_DOMAIN_MEMREGION_SU_WRITABLE) + +#define SBI_DOMAIN_MEMREGION_SHARED_SUR_MRW \ + (SBI_DOMAIN_MEMREGION_M_READABLE | \ + SBI_DOMAIN_MEMREGION_M_WRITABLE | \ + SBI_DOMAIN_MEMREGION_SU_READABLE) + + /* Shared read-only region between M and SU mode */ +#define SBI_DOMAIN_MEMREGION_IS_SUR_MR(__flags) \ + ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ + SBI_DOMAIN_MEMREGION_SHARED_RDONLY) + + /* Shared region: SU execute-only and M read/execute */ +#define SBI_DOMAIN_MEMREGION_IS_SUX_MRX(__flags) \ + ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ + SBI_DOMAIN_MEMREGION_SHARED_SUX_MRX) + + /* Shared region: SU and M execute-only */ +#define SBI_DOMAIN_MEMREGION_IS_SUX_MX(__flags) \ + ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ + SBI_DOMAIN_MEMREGION_SHARED_SUX_MX) + + /* Shared region: SU and M read/write */ +#define SBI_DOMAIN_MEMREGION_IS_SURW_MRW(__flags) \ + ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ + SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW) + + /* Shared region: SU read-only and M read/write */ +#define SBI_DOMAIN_MEMREGION_IS_SUR_MRW(__flags) \ + ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ + SBI_DOMAIN_MEMREGION_SHARED_SUR_MRW) + + /* + * Check if region flags match with any of the above + * mentioned shared region type + */ +#define SBI_DOMAIN_MEMREGION_IS_SHARED(_flags) \ + (SBI_DOMAIN_MEMREGION_IS_SUR_MR(_flags) || \ + SBI_DOMAIN_MEMREGION_IS_SUX_MRX(_flags) || \ + SBI_DOMAIN_MEMREGION_IS_SUX_MX(_flags) || \ + SBI_DOMAIN_MEMREGION_IS_SURW_MRW(_flags)|| \ + SBI_DOMAIN_MEMREGION_IS_SUR_MRW(_flags)) + +#define SBI_DOMAIN_MEMREGION_M_ONLY_ACCESS(__flags) \ + ((__flags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK) && \ + !(__flags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK)) + +#define SBI_DOMAIN_MEMREGION_SU_ONLY_ACCESS(__flags) \ + ((__flags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK) && \ + !(__flags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK)) + +/** Bit to control if permissions are enforced on all modes */ +#define SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS (1UL << 6) + +#define SBI_DOMAIN_MEMREGION_M_RWX \ + (SBI_DOMAIN_MEMREGION_M_READABLE | \ + SBI_DOMAIN_MEMREGION_M_WRITABLE | \ + SBI_DOMAIN_MEMREGION_M_EXECUTABLE) + +#define SBI_DOMAIN_MEMREGION_SU_RWX \ + (SBI_DOMAIN_MEMREGION_SU_READABLE | \ + SBI_DOMAIN_MEMREGION_SU_WRITABLE | \ + SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) + +/* Unrestricted M-mode accesses but enfoced on SU-mode */ +#define SBI_DOMAIN_MEMREGION_READABLE \ + (SBI_DOMAIN_MEMREGION_SU_READABLE | \ + SBI_DOMAIN_MEMREGION_M_RWX) +#define SBI_DOMAIN_MEMREGION_WRITEABLE \ + (SBI_DOMAIN_MEMREGION_SU_WRITABLE | \ + SBI_DOMAIN_MEMREGION_M_RWX) +#define SBI_DOMAIN_MEMREGION_EXECUTABLE \ + (SBI_DOMAIN_MEMREGION_SU_EXECUTABLE | \ + SBI_DOMAIN_MEMREGION_M_RWX) + +/* Enforced accesses across all modes */ +#define SBI_DOMAIN_MEMREGION_ENF_READABLE \ + (SBI_DOMAIN_MEMREGION_SU_READABLE | \ + SBI_DOMAIN_MEMREGION_M_READABLE) +#define SBI_DOMAIN_MEMREGION_ENF_WRITABLE \ + (SBI_DOMAIN_MEMREGION_SU_WRITABLE | \ + SBI_DOMAIN_MEMREGION_M_WRITABLE) +#define SBI_DOMAIN_MEMREGION_ENF_EXECUTABLE \ + (SBI_DOMAIN_MEMREGION_SU_EXECUTABLE | \ + SBI_DOMAIN_MEMREGION_M_EXECUTABLE) + +#define SBI_DOMAIN_MEMREGION_MMIO (1UL << 31) + unsigned long flags; +}; + +/** + * Initialize a domain memory region based on it's physical + * address and size. + * + * @param addr start physical address of memory region + * @param size physical size of memory region + * @param flags memory region flags + * @param reg pointer to memory region being initialized + */ +void sbi_domain_memregion_init(unsigned long addr, + unsigned long size, + unsigned long flags, + struct sbi_domain_memregion *reg); + +/** + * + * Traverse all of a domain's memory regions and sanitize + * them, while making sure they are formatted properly + * + * @param dom the domain for which to sanitize regions + */ +int sbi_domain_memregions_sanitize(struct sbi_domain *dom); + +/** + * Check whether we can access specified address for given mode and + * memory region flags under a domain + * @param dom pointer to domain + * @param addr the address to be checked + * @param mode the privilege mode of access + * @param access_flags bitmask of domain access types (enum sbi_domain_access) + * @return true if access allowed otherwise false + */ +bool sbi_domain_check_addr(const struct sbi_domain *dom, + unsigned long addr, unsigned long mode, + unsigned long access_flags); + +/** + * Check whether we can access specified address range for given mode and + * memory region flags under a domain + * @param dom pointer to domain + * @param addr the start of the address range to be checked + * @param size the size of the address range to be checked + * @param mode the privilege mode of access + * @param access_flags bitmask of domain access types (enum sbi_domain_access) + * @return TRUE if access allowed otherwise FALSE + */ +bool sbi_domain_check_addr_range(const struct sbi_domain *dom, + unsigned long addr, unsigned long size, + unsigned long mode, + unsigned long access_flags); + +#endif // __SBI_MEMREGION_H__ \ No newline at end of file diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 535aa70..d80d6cc 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -66,6 +66,7 @@ libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_console.o libsbi-objs-y += sbi_domain_context.o libsbi-objs-y += sbi_domain.o +libsbi-objs-y += sbi_memregion.o libsbi-objs-y += sbi_emulate_csr.o libsbi-objs-y += sbi_fifo.o libsbi-objs-y += sbi_fwft.o diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 374ac36..00ba870 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -96,199 +96,9 @@ ulong sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom, return ret; } -void sbi_domain_memregion_init(unsigned long addr, - unsigned long size, - unsigned long flags, - struct sbi_domain_memregion *reg) -{ - unsigned long base = 0, order; - - for (order = log2roundup(size) ; order <= __riscv_xlen; order++) { - if (order < __riscv_xlen) { - base = addr & ~((1UL << order) - 1UL); - if ((base <= addr) && - (addr < (base + (1UL << order))) && - (base <= (addr + size - 1UL)) && - ((addr + size - 1UL) < (base + (1UL << order)))) - break; - } else { - base = 0; - break; - } - - } - - if (reg) { - reg->base = base; - reg->order = order; - reg->flags = flags; - } -} - -bool sbi_domain_check_addr(const struct sbi_domain *dom, - unsigned long addr, unsigned long mode, - unsigned long access_flags) -{ - bool rmmio, mmio = false; - struct sbi_domain_memregion *reg; - unsigned long rstart, rend, rflags, rwx = 0, rrwx = 0; - - if (!dom) - return false; - - /* - * Use M_{R/W/X} bits because the SU-bits are at the - * same relative offsets. If the mode is not M, the SU - * bits will fall at same offsets after the shift. - */ - if (access_flags & SBI_DOMAIN_READ) - rwx |= SBI_DOMAIN_MEMREGION_M_READABLE; - - if (access_flags & SBI_DOMAIN_WRITE) - rwx |= SBI_DOMAIN_MEMREGION_M_WRITABLE; - - if (access_flags & SBI_DOMAIN_EXECUTE) - rwx |= SBI_DOMAIN_MEMREGION_M_EXECUTABLE; - - if (access_flags & SBI_DOMAIN_MMIO) - mmio = true; - - sbi_domain_for_each_memregion(dom, reg) { - rflags = reg->flags; - rrwx = (mode == PRV_M ? - (rflags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK) : - (rflags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK) - >> SBI_DOMAIN_MEMREGION_SU_ACCESS_SHIFT); - - rstart = reg->base; - rend = (reg->order < __riscv_xlen) ? - rstart + ((1UL << reg->order) - 1) : -1UL; - if (rstart <= addr && addr <= rend) { - rmmio = (rflags & SBI_DOMAIN_MEMREGION_MMIO) ? true : false; - if (mmio != rmmio) - return false; - return ((rrwx & rwx) == rwx) ? true : false; - } - } - - return (mode == PRV_M) ? true : false; -} - -/* Check if region complies with constraints */ -static bool is_region_valid(const struct sbi_domain_memregion *reg) -{ - if (reg->order < 3 || __riscv_xlen < reg->order) - return false; - - if (reg->order == __riscv_xlen && reg->base != 0) - return false; - - if (reg->order < __riscv_xlen && (reg->base & (BIT(reg->order) - 1))) - return false; - - return true; -} - -/** Check if regionA is sub-region of regionB */ -static bool is_region_subset(const struct sbi_domain_memregion *regA, - const struct sbi_domain_memregion *regB) -{ - ulong regA_start = regA->base; - ulong regA_end = regA->base + (BIT(regA->order) - 1); - ulong regB_start = regB->base; - ulong regB_end = regB->base + (BIT(regB->order) - 1); - - if ((regB_start <= regA_start) && - (regA_start < regB_end) && - (regB_start < regA_end) && - (regA_end <= regB_end)) - return true; - - return false; -} - -/** Check if regionA can be replaced by regionB */ -static bool is_region_compatible(const struct sbi_domain_memregion *regA, - const struct sbi_domain_memregion *regB) -{ - if (is_region_subset(regA, regB) && regA->flags == regB->flags) - return true; - - return false; -} - -/** Check if regionA should be placed before regionB */ -static bool is_region_before(const struct sbi_domain_memregion *regA, - const struct sbi_domain_memregion *regB) -{ - if (regA->order < regB->order) - return true; - - if ((regA->order == regB->order) && - (regA->base < regB->base)) - return true; - - return false; -} - -static const struct sbi_domain_memregion *find_region( - const struct sbi_domain *dom, - unsigned long addr) -{ - unsigned long rstart, rend; - struct sbi_domain_memregion *reg; - - sbi_domain_for_each_memregion(dom, reg) { - rstart = reg->base; - rend = (reg->order < __riscv_xlen) ? - rstart + ((1UL << reg->order) - 1) : -1UL; - if (rstart <= addr && addr <= rend) - return reg; - } - - return NULL; -} - -static const struct sbi_domain_memregion *find_next_subset_region( - const struct sbi_domain *dom, - const struct sbi_domain_memregion *reg, - unsigned long addr) -{ - struct sbi_domain_memregion *sreg, *ret = NULL; - - sbi_domain_for_each_memregion(dom, sreg) { - if (sreg == reg || (sreg->base <= addr) || - !is_region_subset(sreg, reg)) - continue; - - if (!ret || (sreg->base < ret->base) || - ((sreg->base == ret->base) && (sreg->order < ret->order))) - ret = sreg; - } - - return ret; -} - -static void swap_region(struct sbi_domain_memregion* reg1, - struct sbi_domain_memregion* reg2) -{ - struct sbi_domain_memregion treg; - - sbi_memcpy(&treg, reg1, sizeof(treg)); - sbi_memcpy(reg1, reg2, sizeof(treg)); - sbi_memcpy(reg2, &treg, sizeof(treg)); -} - -static void clear_region(struct sbi_domain_memregion* reg) -{ - sbi_memset(reg, 0x0, sizeof(*reg)); -} - static int sanitize_domain(struct sbi_domain *dom) { - u32 i, j, count; - bool is_covered; - struct sbi_domain_memregion *reg, *reg1; + u32 i, rc; /* Check possible HARTs */ if (!dom->possible_harts) { @@ -305,70 +115,11 @@ static int sanitize_domain(struct sbi_domain *dom) } } - /* Check memory regions */ - if (!dom->regions) { - sbi_printf("%s: %s regions is NULL\n", - __func__, dom->name); - return SBI_EINVAL; - } - sbi_domain_for_each_memregion(dom, reg) { - if (!is_region_valid(reg)) { - sbi_printf("%s: %s has invalid region base=0x%lx " - "order=%lu flags=0x%lx\n", __func__, - dom->name, reg->base, reg->order, - reg->flags); - return SBI_EINVAL; - } - } - - /* Count memory regions */ - count = 0; - sbi_domain_for_each_memregion(dom, reg) - count++; - - /* Check presence of firmware regions */ - if (!dom->fw_region_inited) { - sbi_printf("%s: %s does not have firmware region\n", + rc = sbi_domain_memregions_sanitize(dom); + if (rc) { + sbi_printf("%s: %s has unsanitizable regions\n", __func__, dom->name); - return SBI_EINVAL; - } - - /* Sort the memory regions */ - for (i = 0; i < (count - 1); i++) { - reg = &dom->regions[i]; - for (j = i + 1; j < count; j++) { - reg1 = &dom->regions[j]; - - if (!is_region_before(reg1, reg)) - continue; - - swap_region(reg, reg1); - } - } - - /* Remove covered regions */ - while(i < (count - 1)) { - is_covered = false; - reg = &dom->regions[i]; - - for (j = i + 1; j < count; j++) { - reg1 = &dom->regions[j]; - - if (is_region_compatible(reg, reg1)) { - is_covered = true; - break; - } - } - - /* find a region is superset of reg, remove reg */ - if (is_covered) { - for (j = i; j < (count - 1); j++) - swap_region(&dom->regions[j], - &dom->regions[j + 1]); - clear_region(&dom->regions[count - 1]); - count--; - } else - i++; + return rc; } /* @@ -401,37 +152,6 @@ static int sanitize_domain(struct sbi_domain *dom) return 0; } -bool sbi_domain_check_addr_range(const struct sbi_domain *dom, - unsigned long addr, unsigned long size, - unsigned long mode, - unsigned long access_flags) -{ - unsigned long max = addr + size; - const struct sbi_domain_memregion *reg, *sreg; - - if (!dom) - return false; - - while (addr < max) { - reg = find_region(dom, addr); - if (!reg) - return false; - - if (!sbi_domain_check_addr(dom, addr, mode, access_flags)) - return false; - - sreg = find_next_subset_region(dom, reg, addr); - if (sreg) - addr = sreg->base; - else if (reg->order < __riscv_xlen) - addr = reg->base + (1UL << reg->order); - else - break; - } - - return true; -} - void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix) { u32 i, j, k; @@ -613,12 +333,6 @@ int sbi_domain_root_add_memregion(const struct sbi_domain_memregion *reg) (ROOT_REGION_MAX <= root_memregs_count)) return SBI_EINVAL; - /* Check whether compatible region exists for the new one */ - sbi_domain_for_each_memregion(&root, nreg) { - if (is_region_compatible(reg, nreg)) - return 0; - } - /* Append the memregion to root memregions */ nreg = &root.regions[root_memregs_count]; sbi_memcpy(nreg, reg, sizeof(*reg)); diff --git a/lib/sbi/sbi_memregion.c b/lib/sbi/sbi_memregion.c new file mode 100644 index 0000000..8cb1eed --- /dev/null +++ b/lib/sbi/sbi_memregion.c @@ -0,0 +1,301 @@ +#include +#include +#include +#include +#include + +void sbi_domain_memregion_init(unsigned long addr, + unsigned long size, + unsigned long flags, + struct sbi_domain_memregion *reg) +{ + unsigned long base = 0, order; + + for (order = log2roundup(size) ; order <= __riscv_xlen; order++) { + if (order < __riscv_xlen) { + base = addr & ~((1UL << order) - 1UL); + if ((base <= addr) && + (addr < (base + (1UL << order))) && + (base <= (addr + size - 1UL)) && + ((addr + size - 1UL) < (base + (1UL << order)))) + break; + } else { + base = 0; + break; + } + + } + + if (reg) { + reg->base = base; + reg->order = order; + reg->flags = flags; + } +} + +/** Check if regionA is sub-region of regionB */ +static bool is_region_subset(const struct sbi_domain_memregion *regA, + const struct sbi_domain_memregion *regB) +{ + ulong regA_start = regA->base; + ulong regA_end = regA->base + (BIT(regA->order) - 1); + ulong regB_start = regB->base; + ulong regB_end = regB->base + (BIT(regB->order) - 1); + + if ((regB_start <= regA_start) && + (regA_start < regB_end) && + (regB_start < regA_end) && + (regA_end <= regB_end)) + return true; + + return false; +} + +/** Check if regionA can be replaced by regionB */ +static bool is_region_compatible(const struct sbi_domain_memregion *regA, + const struct sbi_domain_memregion *regB) +{ + if (is_region_subset(regA, regB) && regA->flags == regB->flags) + return true; + + return false; +} + +/* Check if region complies with constraints */ +static bool is_region_valid(const struct sbi_domain_memregion *reg) +{ + if (reg->order < 3 || __riscv_xlen < reg->order) + return false; + + if (reg->order == __riscv_xlen && reg->base != 0) + return false; + + if (reg->order < __riscv_xlen && (reg->base & (BIT(reg->order) - 1))) + return false; + + return true; +} + +/** Check if regionA should be placed before regionB */ +static bool is_region_before(const struct sbi_domain_memregion *regA, + const struct sbi_domain_memregion *regB) +{ + if (regA->order < regB->order) + return true; + + if ((regA->order == regB->order) && + (regA->base < regB->base)) + return true; + + return false; +} + + +static void swap_region(struct sbi_domain_memregion* reg1, + struct sbi_domain_memregion* reg2) +{ + struct sbi_domain_memregion treg; + + sbi_memcpy(&treg, reg1, sizeof(treg)); + sbi_memcpy(reg1, reg2, sizeof(treg)); + sbi_memcpy(reg2, &treg, sizeof(treg)); +} + +static void clear_region(struct sbi_domain_memregion* reg) +{ + sbi_memset(reg, 0x0, sizeof(*reg)); +} + +int sbi_domain_memregions_sanitize(struct sbi_domain *dom) +{ + int i, j, count; + bool is_covered; + struct sbi_domain_memregion *reg, *reg1; + + /* Check memory regions */ + if (!dom->regions) { + sbi_printf("%s: %s regions is NULL\n", + __func__, dom->name); + return SBI_EINVAL; + } + sbi_domain_for_each_memregion(dom, reg) { + if (!is_region_valid(reg)) { + sbi_printf("%s: %s has invalid region base=0x%lx " + "order=%lu flags=0x%lx\n", __func__, + dom->name, reg->base, reg->order, + reg->flags); + return SBI_EINVAL; + } + } + + /* Count memory regions */ + count = 0; + sbi_domain_for_each_memregion(dom, reg) + count++; + + /* Check presence of firmware regions */ + if (!dom->fw_region_inited) { + sbi_printf("%s: %s does not have firmware region\n", + __func__, dom->name); + return SBI_EINVAL; + } + + /* Sort the memory regions */ + for (i = 0; i < (count - 1); i++) { + reg = &dom->regions[i]; + for (j = i + 1; j < count; j++) { + reg1 = &dom->regions[j]; + + if (!is_region_before(reg1, reg)) + continue; + + swap_region(reg, reg1); + } + } + + /* Remove covered regions */ + while(i < (count - 1)) { + is_covered = false; + reg = &dom->regions[i]; + + for (j = i + 1; j < count; j++) { + reg1 = &dom->regions[j]; + + if (is_region_compatible(reg, reg1)) { + is_covered = true; + break; + } + } + + /* find a region is superset of reg, remove reg */ + if (is_covered) { + for (j = i; j < (count - 1); j++) + swap_region(&dom->regions[j], + &dom->regions[j + 1]); + clear_region(&dom->regions[count - 1]); + count--; + } else + i++; + } + + return SBI_OK; +} + + +bool sbi_domain_check_addr(const struct sbi_domain *dom, + unsigned long addr, unsigned long mode, + unsigned long access_flags) +{ + bool rmmio, mmio = false; + struct sbi_domain_memregion *reg; + unsigned long rstart, rend, rflags, rwx = 0, rrwx = 0; + + if (!dom) + return false; + + /* + * Use M_{R/W/X} bits because the SU-bits are at the + * same relative offsets. If the mode is not M, the SU + * bits will fall at same offsets after the shift. + */ + if (access_flags & SBI_DOMAIN_READ) + rwx |= SBI_DOMAIN_MEMREGION_M_READABLE; + + if (access_flags & SBI_DOMAIN_WRITE) + rwx |= SBI_DOMAIN_MEMREGION_M_WRITABLE; + + if (access_flags & SBI_DOMAIN_EXECUTE) + rwx |= SBI_DOMAIN_MEMREGION_M_EXECUTABLE; + + if (access_flags & SBI_DOMAIN_MMIO) + mmio = true; + + sbi_domain_for_each_memregion(dom, reg) { + rflags = reg->flags; + rrwx = (mode == PRV_M ? + (rflags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK) : + (rflags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK) + >> SBI_DOMAIN_MEMREGION_SU_ACCESS_SHIFT); + + rstart = reg->base; + rend = (reg->order < __riscv_xlen) ? + rstart + ((1UL << reg->order) - 1) : -1UL; + if (rstart <= addr && addr <= rend) { + rmmio = (rflags & SBI_DOMAIN_MEMREGION_MMIO) ? true : false; + if (mmio != rmmio) + return false; + return ((rrwx & rwx) == rwx) ? true : false; + } + } + + return (mode == PRV_M) ? true : false; +} + +static const struct sbi_domain_memregion *find_region( + const struct sbi_domain *dom, + unsigned long addr) +{ + unsigned long rstart, rend; + struct sbi_domain_memregion *reg; + + sbi_domain_for_each_memregion(dom, reg) { + rstart = reg->base; + rend = (reg->order < __riscv_xlen) ? + rstart + ((1UL << reg->order) - 1) : -1UL; + if (rstart <= addr && addr <= rend) + return reg; + } + + return NULL; +} + +static const struct sbi_domain_memregion *find_next_subset_region( + const struct sbi_domain *dom, + const struct sbi_domain_memregion *reg, + unsigned long addr) +{ + struct sbi_domain_memregion *sreg, *ret = NULL; + + sbi_domain_for_each_memregion(dom, sreg) { + if (sreg == reg || (sreg->base <= addr) || + !is_region_subset(sreg, reg)) + continue; + + if (!ret || (sreg->base < ret->base) || + ((sreg->base == ret->base) && (sreg->order < ret->order))) + ret = sreg; + } + + return ret; +} + +bool sbi_domain_check_addr_range(const struct sbi_domain *dom, + unsigned long addr, unsigned long size, + unsigned long mode, + unsigned long access_flags) +{ + unsigned long max = addr + size; + const struct sbi_domain_memregion *reg, *sreg; + + if (!dom) + return false; + + while (addr < max) { + reg = find_region(dom, addr); + if (!reg) + return false; + + if (!sbi_domain_check_addr(dom, addr, mode, access_flags)) + return false; + + sreg = find_next_subset_region(dom, reg, addr); + if (sreg) + addr = sreg->base; + else if (reg->order < __riscv_xlen) + addr = reg->base + (1UL << reg->order); + else + break; + } + + return true; +} \ No newline at end of file From patchwork Wed Jul 31 18:16:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Haas X-Patchwork-Id: 1967256 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=thWH+Wc8; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BPTYjcoS; 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=opensbi-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 4WZ0fz3Fwpz1yYq for ; Thu, 1 Aug 2024 04:16:59 +1000 (AEST) 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:References:In-Reply-To: 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: List-Owner; bh=9tDvvqD6htp4IC8V/YEdcYqw4K1zPX6rRvAUig7fDxA=; b=thWH+Wc8c5ifF8 sbKzfQ73beXic9KEGpUflxDA45WJhgFdzHke/k88L7plp1ckWL43awCCBFS3PCFtDeAVfwHv9PezN vhJR87PU72ALxulNNWOwA0xJoOmLDn3Qtglbf3NR7Mb5KNnL6fl5LgPB8rWa6z3mHpkAXmBFdHtXe 4pfQXellX4OqMW5JL5zMpvw5FL8unYlzG9IhnOpAtIdt1SzT7Dsu6KECF10kUbcI+H82Wiays8BNr q1D/YaxMWXVaGTqLg+EmhNo69gVX/cyOQexp78caIFjx4PzF2Cxt5kDE+H/Ohf/SknCLCN+B72PP0 8GUPKKYN6Xn1RhsBPyCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsU-000000026e0-3KKW; Wed, 31 Jul 2024 18:16:46 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsR-000000026cm-2X0z for opensbi@lists.infradead.org; Wed, 31 Jul 2024 18:16:44 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-70d25b5b6b0so4498728b3a.2 for ; Wed, 31 Jul 2024 11:16:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722449803; x=1723054603; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xC86kFxU1nLk24L8iG1rncEzjHrl8ejglYQy51N1K2Q=; b=BPTYjcoSyoM1Nv8iroRNNLs9TW1/DSvB+kT0vqIGRwwm36ZuPBjHkCXLw9UxEGkHWa Zk1lF/KovjWk4dOVrRJgZ5YVWtssynTdlmjSG+UGwc9JiRMDhTQLAOCkyizY8wbmwOQm 2WWnBAbanigOiblvJ0T7kBLyJF/Bxa0YRCpD8ZhxhMsqnx3umSUfrHmyRMs6U+9Vgw7X DGmiUllwaNo+wXhNwHaNNhHeh7+8qL5rKJclfCKJB9Xiuw12kyST/OD54gr4cNITcy78 hNYeOEWR+89btmxRy6E/P7Qp9HjbeGTp8F2/rqWL9MzH/X2Z6SnjtTZq5vYb5vKOE6Xs JgBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722449803; x=1723054603; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xC86kFxU1nLk24L8iG1rncEzjHrl8ejglYQy51N1K2Q=; b=HyUYIVBFR/srXc9MeAGSSZv8dWij1GpNbm+AL6+TwlA7ssAbIatklL0b4dYuKh52DR 52U7lE7xm57x+nGWp/ec9xpLwOJmPftRXzYxd8hnc5Y4yxflBHRvAd1jXOnpaMQu23os iMI+pS+X0+Cs6/wyWN1Yt0YMEFc8xdQ2wL7B/3r8k7Pl8IMYsQa3I09M1uQSFCuuTco6 L4DDnU74MS61W2CQx5zdlUd3/X3Qi3RnnszR9n5vfbju+xqaNAyTC3l6gwGQXQ+MSrNs BZhsdn42S6C+wxdlPj+ffP1QP+q0ZOvVXbezHZXyo0eiZYSvBP5EsEpjVxGsUmutbVzM TXrA== X-Gm-Message-State: AOJu0YxjmIilWmk5BvWLmMp3SjdfP8Ky3lqf0gBLfCy9gZc5WzshMoif uTvlfTcxp6v8IFq6d3akMto1Bf0a1HIbWzJPg5Tip/gkRP1dbsCwAFPP+sTZ X-Google-Smtp-Source: AGHT+IEbNU62ZAVOPJPLqo7SJgH3JrHYfr9vqazV3Gc4kzVqXYVtZ3AwNMA7yb487Ao/ScEyNdzt7A== X-Received: by 2002:a05:6a21:9990:b0:1c2:92a1:9320 with SMTP id adf61e73a8af0-1c68ce76314mr370798637.7.1722449802814; Wed, 31 Jul 2024 11:16:42 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-70ead71832csm10248440b3a.72.2024.07.31.11.16.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jul 2024 11:16:42 -0700 (PDT) From: Gregor Haas To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, Gregor Haas Subject: [PATCH 2/8] lib: sbi: Create sbi_domain_dump_memregions() Date: Wed, 31 Jul 2024 11:16:23 -0700 Message-ID: <20240731181629.269898-3-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731181629.269898-1-gregorhaas1997@gmail.com> References: <20240731181629.269898-1-gregorhaas1997@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_111643_757752_1C53717A X-CRM114-Status: GOOD ( 11.11 ) X-Spam-Score: -1.8 (-) 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: Move the memregion-dumping code out of sbi_domain.c and into sbi_memregion.c --- include/sbi/sbi_memregion.h | 3 +++ lib/sbi/sbi_domain.c | 37 + lib/sbi/sbi_memregion.c [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:433 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [gregorhaas1997(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gregorhaas1997(at)gmail.com] 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 Move the memregion-dumping code out of sbi_domain.c and into sbi_memregion.c --- include/sbi/sbi_memregion.h | 3 +++ lib/sbi/sbi_domain.c | 37 +-------------------------------- lib/sbi/sbi_memregion.c | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/include/sbi/sbi_memregion.h b/include/sbi/sbi_memregion.h index 8a62fc0..828d556 100644 --- a/include/sbi/sbi_memregion.h +++ b/include/sbi/sbi_memregion.h @@ -196,4 +196,7 @@ bool sbi_domain_check_addr_range(const struct sbi_domain *dom, unsigned long mode, unsigned long access_flags); +/** Dump domain memregion details on the console */ +void sbi_domain_dump_memregions(const struct sbi_domain *dom, const char *suffix); + #endif // __SBI_MEMREGION_H__ \ No newline at end of file diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 00ba870..868704e 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -155,8 +155,6 @@ static int sanitize_domain(struct sbi_domain *dom) void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix) { u32 i, j, k; - unsigned long rstart, rend; - struct sbi_domain_memregion *reg; sbi_printf("Domain%d Name %s: %s\n", dom->index, suffix, dom->name); @@ -173,40 +171,7 @@ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix) } sbi_printf("\n"); - i = 0; - sbi_domain_for_each_memregion(dom, reg) { - rstart = reg->base; - rend = (reg->order < __riscv_xlen) ? - rstart + ((1UL << reg->order) - 1) : -1UL; - - sbi_printf("Domain%d Region%02d %s: 0x%" PRILX "-0x%" PRILX " ", - dom->index, i, suffix, rstart, rend); - - k = 0; - - sbi_printf("M: "); - if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO) - sbi_printf("%cI", (k++) ? ',' : '('); - if (reg->flags & SBI_DOMAIN_MEMREGION_M_READABLE) - sbi_printf("%cR", (k++) ? ',' : '('); - if (reg->flags & SBI_DOMAIN_MEMREGION_M_WRITABLE) - sbi_printf("%cW", (k++) ? ',' : '('); - if (reg->flags & SBI_DOMAIN_MEMREGION_M_EXECUTABLE) - sbi_printf("%cX", (k++) ? ',' : '('); - sbi_printf("%s ", (k++) ? ")" : "()"); - - k = 0; - sbi_printf("S/U: "); - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE) - sbi_printf("%cR", (k++) ? ',' : '('); - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE) - sbi_printf("%cW", (k++) ? ',' : '('); - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) - sbi_printf("%cX", (k++) ? ',' : '('); - sbi_printf("%s\n", (k++) ? ")" : "()"); - - i++; - } + sbi_domain_dump_memregions(dom, suffix); sbi_printf("Domain%d Next Address%s: 0x%" PRILX "\n", dom->index, suffix, dom->next_addr); diff --git a/lib/sbi/sbi_memregion.c b/lib/sbi/sbi_memregion.c index 8cb1eed..1ef53dc 100644 --- a/lib/sbi/sbi_memregion.c +++ b/lib/sbi/sbi_memregion.c @@ -298,4 +298,45 @@ bool sbi_domain_check_addr_range(const struct sbi_domain *dom, } return true; +} + +void sbi_domain_dump_memregions(const struct sbi_domain *dom, const char *suffix) +{ + unsigned long rstart, rend; + struct sbi_domain_memregion *reg; + int i = 0, k; + + sbi_domain_for_each_memregion(dom, reg) { + rstart = reg->base; + rend = (reg->order < __riscv_xlen) ? + rstart + ((1UL << reg->order) - 1) : -1UL; + + sbi_printf("Domain%d Region%02d %s: 0x%" PRILX "-0x%" PRILX " ", + dom->index, i, suffix, rstart, rend); + + k = 0; + + sbi_printf("M: "); + if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO) + sbi_printf("%cI", (k++) ? ',' : '('); + if (reg->flags & SBI_DOMAIN_MEMREGION_M_READABLE) + sbi_printf("%cR", (k++) ? ',' : '('); + if (reg->flags & SBI_DOMAIN_MEMREGION_M_WRITABLE) + sbi_printf("%cW", (k++) ? ',' : '('); + if (reg->flags & SBI_DOMAIN_MEMREGION_M_EXECUTABLE) + sbi_printf("%cX", (k++) ? ',' : '('); + sbi_printf("%s ", (k++) ? ")" : "()"); + + k = 0; + sbi_printf("S/U: "); + if (reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE) + sbi_printf("%cR", (k++) ? ',' : '('); + if (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE) + sbi_printf("%cW", (k++) ? ',' : '('); + if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) + sbi_printf("%cX", (k++) ? ',' : '('); + sbi_printf("%s\n", (k++) ? ")" : "()"); + + i++; + } } \ No newline at end of file From patchwork Wed Jul 31 18:16:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Haas X-Patchwork-Id: 1967255 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=n6asJf2A; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UDhVLQM+; 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=opensbi-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 4WZ0fz5F0Rz20Mt for ; Thu, 1 Aug 2024 04:16:59 +1000 (AEST) 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:References:In-Reply-To: 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: List-Owner; bh=3r0zeHrCE3zGywM2MkWShKYf+EhmEHI0bGz48t7xjGc=; b=n6asJf2A0YM3Su dX1tWrTYQ79Vtrtc9gJE9MW/WMNKV9CnqqYfuW0b99ojEAAOllcBmsePVxMcaBqoZMaPHkVYUbKwM KLvxgVcOO7F95yTt4BI0a54mKbkfE4WrL5nqfhMXWgEFop9Evd5dSwiGjLGjREWSeHQ+GxjTSH96Q 1PJaFpK2B87k1jY6tz+oGsWMYdI2znKEc8apIPRKjAXJsK8v6blsPJj6jeZPeiHlhi16PS4NwFaG2 Lftn+9Ho9wJ4bFBu7PDMbf2URQwJ0q9gYX4Edan/og7vC3yLUGJRskc0YDzaAtYqeKgPXOvMXEqSu tue5JcEn2evKldPGp1WQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsY-000000026gY-1mML; Wed, 31 Jul 2024 18:16:50 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsS-000000026d7-312S for opensbi@lists.infradead.org; Wed, 31 Jul 2024 18:16:48 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-70d19d768c2so4594228b3a.3 for ; Wed, 31 Jul 2024 11:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722449804; x=1723054604; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VoJ2rkSJuPJISTp//mSzsZt7rOEzs1R4POtci8hg1BE=; b=UDhVLQM+hibNirjrEFDr+k8za33tmFRlTFVob5jwwe+oDRgGwt5tdUNzSYqGy8wa8C +OjVqoShins2+1M2qp0eeDVaNZTLtjLsNg3RqXQxAJFXJ+oysSCGy9oNFYrPiKCl+Qoa z/6lXJa/5ZeW2IyxycG0FiqV0yIvFKCxCCm15egSngfqIYs9+3t/H0OF8mE78e7xXeec LXKMMHPu90IY2KBjRdbVIWD5Le0iSbOkoztpYPWYWFQKCu8adw2hHHRt/IGTSCktmnWO S/eqh9+zcRUiCw90cAFRQ6mvKVPV3sSsHMKA1hu6hR718ePCj83cBpMfhnF8I7vEKxCq 7m2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722449804; x=1723054604; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VoJ2rkSJuPJISTp//mSzsZt7rOEzs1R4POtci8hg1BE=; b=WccdEWz3XEkW0kMAhGR7VQWwDnLY86dZMbIUHtnTLHoSN5YLkiGtrV6Gyhmf0PbeOs tRa1bM1yIa5f449oYpui1YeX7LowM7b8cxZoqSRva9FEuFsuwIj7IsA/qATBuQ9mRUqi h0oNsfSYomgqYq+140lLX6F1CVjpL2ClJPBiYoWev435FSqhFE1lKu3O+m37+1NHym8E JKYT3icxgMG4WyuB0TCdbHkkOmUHuSUFA3yx2rhoL8sDv9FBlLF9IiLVwO7vlrcv+jt2 RvVqd/t2zdK+eotyh3I/2xN/XVPLJRhdqJ6wkquOM9huAzVFB7UiTWtEwuvpC3xNIZ4Z ceqQ== X-Gm-Message-State: AOJu0YwThbJO6XExdsPtX0YQbMkDFP2OR1PfL6A27pJhneIy1UfZvlcq G1HhUjOYUpuUSbW9T9j8kh69Z4bUfioGLhZcHppX6I1Qoc9yYWkj8xH4mwhx X-Google-Smtp-Source: AGHT+IFn8aVkvLQmUWEwB6mbYByP7AEfuCFoSeEabqV9FZp7+M/8bNoboytJ7o8ufRjJdXJhuvnYSQ== X-Received: by 2002:a05:6a00:4650:b0:70b:1134:95a8 with SMTP id d2e1a72fcca58-7105d7bbc06mr57818b3a.23.1722449803748; Wed, 31 Jul 2024 11:16:43 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-70ead812efdsm10235934b3a.127.2024.07.31.11.16.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jul 2024 11:16:43 -0700 (PDT) From: Gregor Haas To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, Gregor Haas Subject: [PATCH 3/8] lib: sbi: Rename domain_memregion -> memregion Date: Wed, 31 Jul 2024 11:16:24 -0700 Message-ID: <20240731181629.269898-4-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731181629.269898-1-gregorhaas1997@gmail.com> References: <20240731181629.269898-1-gregorhaas1997@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_111644_842650_03A40E5A X-CRM114-Status: GOOD ( 18.33 ) X-Spam-Score: -1.8 (-) 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: Now that domains and memregions are separated into their own source files, rename all instances of struct sbi_domain_memregion to just struct sbi_memregion. Also, rename all of the memregion permissio [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:433 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [gregorhaas1997(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gregorhaas1997(at)gmail.com] 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 Now that domains and memregions are separated into their own source files, rename all instances of struct sbi_domain_memregion to just struct sbi_memregion. Also, rename all of the memregion permission defined from SBI_DOMAIN_MEMREGION_* to SBI_MEMREGION_*. This makes the code a little less clunky and verbose. --- docs/domain_support.md | 4 +- include/sbi/sbi_domain.h | 4 +- include/sbi/sbi_memregion.h | 196 +++++++++++------------ include/sbi/sbi_platform.h | 2 +- lib/sbi/sbi_domain.c | 40 ++--- lib/sbi/sbi_hart.c | 52 +++--- lib/sbi/sbi_memregion.c | 76 ++++----- lib/utils/fdt/fdt_domain.c | 24 +-- lib/utils/fdt/fdt_fixup.c | 10 +- lib/utils/ipi/aclint_mswi.c | 12 +- lib/utils/ipi/andes_plicsw.c | 6 +- lib/utils/irqchip/aplic.c | 12 +- lib/utils/irqchip/imsic.c | 13 +- lib/utils/irqchip/plic.c | 4 +- lib/utils/regmap/fdt_regmap_syscon.c | 4 +- lib/utils/serial/cadence-uart.c | 4 +- lib/utils/serial/fdt_serial_htif.c | 4 +- lib/utils/serial/uart8250.c | 4 +- lib/utils/timer/aclint_mtimer.c | 24 +-- lib/utils/timer/andes_plmt.c | 6 +- platform/generic/renesas/rzfive/rzfive.c | 2 +- platform/generic/sophgo/sg2042.c | 6 +- 22 files changed, 254 insertions(+), 255 deletions(-) diff --git a/docs/domain_support.md b/docs/domain_support.md index b34e43a..91677d3 100644 --- a/docs/domain_support.md +++ b/docs/domain_support.md @@ -8,7 +8,7 @@ features such as PMP, ePMP, IOPMP, SiFive Shield, etc. Important entities which help implement OpenSBI domain support are: -* **struct sbi_domain_memregion** - Representation of a domain memory region +* **struct sbi_memregion** - Representation of a domain memory region * **struct sbi_hartmask** - Representation of domain HART set * **struct sbi_domain** - Representation of a domain instance @@ -21,7 +21,7 @@ it is not mandatory for the OpenSBI platform support to populate domains. Domain Memory Region -------------------- -A domain memory region is represented by **struct sbi_domain_memregion** in +A domain memory region is represented by **struct sbi_memregion** in OpenSBI and has following details: * **order** - The size of a memory region is **2 ^ order** where **order** diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h index 596bab3..a712504 100644 --- a/include/sbi/sbi_domain.h +++ b/include/sbi/sbi_domain.h @@ -43,7 +43,7 @@ struct sbi_domain { /** Contexts for possible HARTs indexed by hartindex */ struct sbi_context *hartindex_to_context_table[SBI_HARTMASK_MAX_BITS]; /** Array of memory regions terminated by a region with order zero */ - struct sbi_domain_memregion *regions; + struct sbi_memregion *regions; /** HART id of the HART booting this domain */ u32 boot_hartid; /** Arg1 (or 'a1' register) of next booting stage for this domain */ @@ -130,7 +130,7 @@ int sbi_domain_register(struct sbi_domain *dom, * @return SBI_EALREADY if memory region conflicts with the existing one * @return SBI_EINVAL otherwise */ -int sbi_domain_root_add_memregion(const struct sbi_domain_memregion *reg); +int sbi_domain_root_add_memregion(const struct sbi_memregion *reg); /** * Add a memory range with its flags to the root domain diff --git a/include/sbi/sbi_memregion.h b/include/sbi/sbi_memregion.h index 828d556..0aa9a44 100644 --- a/include/sbi/sbi_memregion.h +++ b/include/sbi/sbi_memregion.h @@ -13,7 +13,7 @@ enum sbi_domain_access { }; /** Representation of OpenSBI domain memory region */ -struct sbi_domain_memregion { +struct sbi_memregion { /** * Size of memory region as power of 2 * It has to be minimum 3 and maximum __riscv_xlen @@ -25,123 +25,123 @@ struct sbi_domain_memregion { */ unsigned long base; /** Flags representing memory region attributes */ -#define SBI_DOMAIN_MEMREGION_M_READABLE (1UL << 0) -#define SBI_DOMAIN_MEMREGION_M_WRITABLE (1UL << 1) -#define SBI_DOMAIN_MEMREGION_M_EXECUTABLE (1UL << 2) -#define SBI_DOMAIN_MEMREGION_SU_READABLE (1UL << 3) -#define SBI_DOMAIN_MEMREGION_SU_WRITABLE (1UL << 4) -#define SBI_DOMAIN_MEMREGION_SU_EXECUTABLE (1UL << 5) - -#define SBI_DOMAIN_MEMREGION_ACCESS_MASK (0x3fUL) -#define SBI_DOMAIN_MEMREGION_M_ACCESS_MASK (0x7UL) -#define SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK (0x38UL) - -#define SBI_DOMAIN_MEMREGION_SU_ACCESS_SHIFT (3) - -#define SBI_DOMAIN_MEMREGION_SHARED_RDONLY \ - (SBI_DOMAIN_MEMREGION_M_READABLE | \ - SBI_DOMAIN_MEMREGION_SU_READABLE) - -#define SBI_DOMAIN_MEMREGION_SHARED_SUX_MRX \ - (SBI_DOMAIN_MEMREGION_M_READABLE | \ - SBI_DOMAIN_MEMREGION_M_EXECUTABLE | \ - SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) - -#define SBI_DOMAIN_MEMREGION_SHARED_SUX_MX \ - (SBI_DOMAIN_MEMREGION_M_EXECUTABLE | \ - SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) - -#define SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW \ - (SBI_DOMAIN_MEMREGION_M_READABLE | \ - SBI_DOMAIN_MEMREGION_M_WRITABLE | \ - SBI_DOMAIN_MEMREGION_SU_READABLE| \ - SBI_DOMAIN_MEMREGION_SU_WRITABLE) - -#define SBI_DOMAIN_MEMREGION_SHARED_SUR_MRW \ - (SBI_DOMAIN_MEMREGION_M_READABLE | \ - SBI_DOMAIN_MEMREGION_M_WRITABLE | \ - SBI_DOMAIN_MEMREGION_SU_READABLE) +#define SBI_MEMREGION_M_READABLE (1UL << 0) +#define SBI_MEMREGION_M_WRITABLE (1UL << 1) +#define SBI_MEMREGION_M_EXECUTABLE (1UL << 2) +#define SBI_MEMREGION_SU_READABLE (1UL << 3) +#define SBI_MEMREGION_SU_WRITABLE (1UL << 4) +#define SBI_MEMREGION_SU_EXECUTABLE (1UL << 5) + +#define SBI_MEMREGION_ACCESS_MASK (0x3fUL) +#define SBI_MEMREGION_M_ACCESS_MASK (0x7UL) +#define SBI_MEMREGION_SU_ACCESS_MASK (0x38UL) + +#define SBI_MEMREGION_SU_ACCESS_SHIFT (3) + +#define SBI_MEMREGION_SHARED_RDONLY \ + (SBI_MEMREGION_M_READABLE | \ + SBI_MEMREGION_SU_READABLE) + +#define SBI_MEMREGION_SHARED_SUX_MRX \ + (SBI_MEMREGION_M_READABLE | \ + SBI_MEMREGION_M_EXECUTABLE | \ + SBI_MEMREGION_SU_EXECUTABLE) + +#define SBI_MEMREGION_SHARED_SUX_MX \ + (SBI_MEMREGION_M_EXECUTABLE | \ + SBI_MEMREGION_SU_EXECUTABLE) + +#define SBI_MEMREGION_SHARED_SURW_MRW \ + (SBI_MEMREGION_M_READABLE | \ + SBI_MEMREGION_M_WRITABLE | \ + SBI_MEMREGION_SU_READABLE| \ + SBI_MEMREGION_SU_WRITABLE) + +#define SBI_MEMREGION_SHARED_SUR_MRW \ + (SBI_MEMREGION_M_READABLE | \ + SBI_MEMREGION_M_WRITABLE | \ + SBI_MEMREGION_SU_READABLE) /* Shared read-only region between M and SU mode */ -#define SBI_DOMAIN_MEMREGION_IS_SUR_MR(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ - SBI_DOMAIN_MEMREGION_SHARED_RDONLY) +#define SBI_MEMREGION_IS_SUR_MR(__flags) \ + ((__flags & SBI_MEMREGION_ACCESS_MASK) == \ + SBI_MEMREGION_SHARED_RDONLY) /* Shared region: SU execute-only and M read/execute */ -#define SBI_DOMAIN_MEMREGION_IS_SUX_MRX(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ - SBI_DOMAIN_MEMREGION_SHARED_SUX_MRX) +#define SBI_MEMREGION_IS_SUX_MRX(__flags) \ + ((__flags & SBI_MEMREGION_ACCESS_MASK) == \ + SBI_MEMREGION_SHARED_SUX_MRX) /* Shared region: SU and M execute-only */ -#define SBI_DOMAIN_MEMREGION_IS_SUX_MX(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ - SBI_DOMAIN_MEMREGION_SHARED_SUX_MX) +#define SBI_MEMREGION_IS_SUX_MX(__flags) \ + ((__flags & SBI_MEMREGION_ACCESS_MASK) == \ + SBI_MEMREGION_SHARED_SUX_MX) /* Shared region: SU and M read/write */ -#define SBI_DOMAIN_MEMREGION_IS_SURW_MRW(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ - SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW) +#define SBI_MEMREGION_IS_SURW_MRW(__flags) \ + ((__flags & SBI_MEMREGION_ACCESS_MASK) == \ + SBI_MEMREGION_SHARED_SURW_MRW) /* Shared region: SU read-only and M read/write */ -#define SBI_DOMAIN_MEMREGION_IS_SUR_MRW(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == \ - SBI_DOMAIN_MEMREGION_SHARED_SUR_MRW) +#define SBI_MEMREGION_IS_SUR_MRW(__flags) \ + ((__flags & SBI_MEMREGION_ACCESS_MASK) == \ + SBI_MEMREGION_SHARED_SUR_MRW) /* * Check if region flags match with any of the above * mentioned shared region type */ -#define SBI_DOMAIN_MEMREGION_IS_SHARED(_flags) \ - (SBI_DOMAIN_MEMREGION_IS_SUR_MR(_flags) || \ - SBI_DOMAIN_MEMREGION_IS_SUX_MRX(_flags) || \ - SBI_DOMAIN_MEMREGION_IS_SUX_MX(_flags) || \ - SBI_DOMAIN_MEMREGION_IS_SURW_MRW(_flags)|| \ - SBI_DOMAIN_MEMREGION_IS_SUR_MRW(_flags)) +#define SBI_MEMREGION_IS_SHARED(_flags) \ + (SBI_MEMREGION_IS_SUR_MR(_flags) || \ + SBI_MEMREGION_IS_SUX_MRX(_flags) || \ + SBI_MEMREGION_IS_SUX_MX(_flags) || \ + SBI_MEMREGION_IS_SURW_MRW(_flags)|| \ + SBI_MEMREGION_IS_SUR_MRW(_flags)) -#define SBI_DOMAIN_MEMREGION_M_ONLY_ACCESS(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK) && \ - !(__flags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK)) +#define SBI_MEMREGION_M_ONLY_ACCESS(__flags) \ + ((__flags & SBI_MEMREGION_M_ACCESS_MASK) && \ + !(__flags & SBI_MEMREGION_SU_ACCESS_MASK)) -#define SBI_DOMAIN_MEMREGION_SU_ONLY_ACCESS(__flags) \ - ((__flags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK) && \ - !(__flags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK)) +#define SBI_MEMREGION_SU_ONLY_ACCESS(__flags) \ + ((__flags & SBI_MEMREGION_SU_ACCESS_MASK) && \ + !(__flags & SBI_MEMREGION_M_ACCESS_MASK)) /** Bit to control if permissions are enforced on all modes */ -#define SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS (1UL << 6) +#define SBI_MEMREGION_ENF_PERMISSIONS (1UL << 6) -#define SBI_DOMAIN_MEMREGION_M_RWX \ - (SBI_DOMAIN_MEMREGION_M_READABLE | \ - SBI_DOMAIN_MEMREGION_M_WRITABLE | \ - SBI_DOMAIN_MEMREGION_M_EXECUTABLE) +#define SBI_MEMREGION_M_RWX \ + (SBI_MEMREGION_M_READABLE | \ + SBI_MEMREGION_M_WRITABLE | \ + SBI_MEMREGION_M_EXECUTABLE) -#define SBI_DOMAIN_MEMREGION_SU_RWX \ - (SBI_DOMAIN_MEMREGION_SU_READABLE | \ - SBI_DOMAIN_MEMREGION_SU_WRITABLE | \ - SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) +#define SBI_MEMREGION_SU_RWX \ + (SBI_MEMREGION_SU_READABLE | \ + SBI_MEMREGION_SU_WRITABLE | \ + SBI_MEMREGION_SU_EXECUTABLE) /* Unrestricted M-mode accesses but enfoced on SU-mode */ -#define SBI_DOMAIN_MEMREGION_READABLE \ - (SBI_DOMAIN_MEMREGION_SU_READABLE | \ - SBI_DOMAIN_MEMREGION_M_RWX) -#define SBI_DOMAIN_MEMREGION_WRITEABLE \ - (SBI_DOMAIN_MEMREGION_SU_WRITABLE | \ - SBI_DOMAIN_MEMREGION_M_RWX) -#define SBI_DOMAIN_MEMREGION_EXECUTABLE \ - (SBI_DOMAIN_MEMREGION_SU_EXECUTABLE | \ - SBI_DOMAIN_MEMREGION_M_RWX) +#define SBI_MEMREGION_READABLE \ + (SBI_MEMREGION_SU_READABLE | \ + SBI_MEMREGION_M_RWX) +#define SBI_MEMREGION_WRITEABLE \ + (SBI_MEMREGION_SU_WRITABLE | \ + SBI_MEMREGION_M_RWX) +#define SBI_MEMREGION_EXECUTABLE \ + (SBI_MEMREGION_SU_EXECUTABLE | \ + SBI_MEMREGION_M_RWX) /* Enforced accesses across all modes */ -#define SBI_DOMAIN_MEMREGION_ENF_READABLE \ - (SBI_DOMAIN_MEMREGION_SU_READABLE | \ - SBI_DOMAIN_MEMREGION_M_READABLE) -#define SBI_DOMAIN_MEMREGION_ENF_WRITABLE \ - (SBI_DOMAIN_MEMREGION_SU_WRITABLE | \ - SBI_DOMAIN_MEMREGION_M_WRITABLE) -#define SBI_DOMAIN_MEMREGION_ENF_EXECUTABLE \ - (SBI_DOMAIN_MEMREGION_SU_EXECUTABLE | \ - SBI_DOMAIN_MEMREGION_M_EXECUTABLE) - -#define SBI_DOMAIN_MEMREGION_MMIO (1UL << 31) +#define SBI_MEMREGION_ENF_READABLE \ + (SBI_MEMREGION_SU_READABLE | \ + SBI_MEMREGION_M_READABLE) +#define SBI_MEMREGION_ENF_WRITABLE \ + (SBI_MEMREGION_SU_WRITABLE | \ + SBI_MEMREGION_M_WRITABLE) +#define SBI_MEMREGION_ENF_EXECUTABLE \ + (SBI_MEMREGION_SU_EXECUTABLE | \ + SBI_MEMREGION_M_EXECUTABLE) + +#define SBI_MEMREGION_MMIO (1UL << 31) unsigned long flags; }; @@ -154,10 +154,10 @@ struct sbi_domain_memregion { * @param flags memory region flags * @param reg pointer to memory region being initialized */ -void sbi_domain_memregion_init(unsigned long addr, - unsigned long size, - unsigned long flags, - struct sbi_domain_memregion *reg); +void sbi_memregion_init(unsigned long addr, + unsigned long size, + unsigned long flags, + struct sbi_memregion *reg); /** * @@ -166,7 +166,7 @@ void sbi_domain_memregion_init(unsigned long addr, * * @param dom the domain for which to sanitize regions */ -int sbi_domain_memregions_sanitize(struct sbi_domain *dom); +int sbi_memregion_sanitize(struct sbi_domain *dom); /** * Check whether we can access specified address for given mode and diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 7b3ac4b..1814dbd 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -50,7 +50,7 @@ #include #include -struct sbi_domain_memregion; +struct sbi_memregion; struct sbi_ecall_return; struct sbi_trap_regs; struct sbi_hart_features; diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 868704e..22d5d8b 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -115,7 +115,7 @@ static int sanitize_domain(struct sbi_domain *dom) } } - rc = sbi_domain_memregions_sanitize(dom); + rc = sbi_memregion_sanitize(dom); if (rc) { sbi_printf("%s: %s has unsanitizable regions\n", __func__, dom->name); @@ -287,11 +287,11 @@ int sbi_domain_register(struct sbi_domain *dom, return 0; } -int sbi_domain_root_add_memregion(const struct sbi_domain_memregion *reg) +int sbi_domain_root_add_memregion(const struct sbi_memregion *reg) { int rc; bool reg_merged; - struct sbi_domain_memregion *nreg, *nreg1, *nreg2; + struct sbi_memregion *nreg, *nreg1, *nreg2; /* Sanity checks */ if (!reg || domain_finalized || !root.regions || @@ -346,7 +346,7 @@ int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size, { int rc; unsigned long pos, end, rsize; - struct sbi_domain_memregion reg; + struct sbi_memregion reg; pos = addr; end = addr + size; @@ -358,7 +358,7 @@ int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size, rsize = ((end - pos) < align) ? (end - pos) : align; - sbi_domain_memregion_init(pos, rsize, region_flags, ®); + sbi_memregion_init(pos, rsize, region_flags, ®); rc = sbi_domain_root_add_memregion(®); if (rc) return rc; @@ -441,7 +441,7 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid) u32 i; int rc; struct sbi_hartmask *root_hmask; - struct sbi_domain_memregion *root_memregs; + struct sbi_memregion *root_memregs; const struct sbi_platform *plat = sbi_platform_ptr(scratch); if (scratch->fw_rw_offset == 0 || @@ -478,16 +478,16 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid) root.possible_harts = root_hmask; /* Root domain firmware memory region */ - sbi_domain_memregion_init(scratch->fw_start, scratch->fw_rw_offset, - (SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_EXECUTABLE), - &root_memregs[root_memregs_count++]); + sbi_memregion_init(scratch->fw_start, scratch->fw_rw_offset, + (SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_EXECUTABLE), + &root_memregs[root_memregs_count++]); - sbi_domain_memregion_init((scratch->fw_start + scratch->fw_rw_offset), - (scratch->fw_size - scratch->fw_rw_offset), - (SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE), - &root_memregs[root_memregs_count++]); + sbi_memregion_init((scratch->fw_start + scratch->fw_rw_offset), + (scratch->fw_size - scratch->fw_rw_offset), + (SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE), + &root_memregs[root_memregs_count++]); root.fw_region_inited = true; @@ -498,11 +498,11 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid) * have access to SU region while previous entries will allow * access to M-mode regions. */ - sbi_domain_memregion_init(0, ~0UL, - (SBI_DOMAIN_MEMREGION_SU_READABLE | - SBI_DOMAIN_MEMREGION_SU_WRITABLE | - SBI_DOMAIN_MEMREGION_SU_EXECUTABLE), - &root_memregs[root_memregs_count++]); + sbi_memregion_init(0, ~0UL, + (SBI_MEMREGION_SU_READABLE | + SBI_MEMREGION_SU_WRITABLE | + SBI_MEMREGION_SU_EXECUTABLE), + &root_memregs[root_memregs_count++]); /* Root domain memory region end */ root_memregs[root_memregs_count].order = 0; diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index c366701..4dd1a25 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -288,38 +288,38 @@ unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch) */ static unsigned int sbi_hart_get_smepmp_flags(struct sbi_scratch *scratch, struct sbi_domain *dom, - struct sbi_domain_memregion *reg) + struct sbi_memregion *reg) { unsigned int pmp_flags = 0; - if (SBI_DOMAIN_MEMREGION_IS_SHARED(reg->flags)) { + if (SBI_MEMREGION_IS_SHARED(reg->flags)) { /* Read only for both M and SU modes */ - if (SBI_DOMAIN_MEMREGION_IS_SUR_MR(reg->flags)) + if (SBI_MEMREGION_IS_SUR_MR(reg->flags)) pmp_flags = (PMP_L | PMP_R | PMP_W | PMP_X); /* Execute for SU but Read/Execute for M mode */ - else if (SBI_DOMAIN_MEMREGION_IS_SUX_MRX(reg->flags)) + else if (SBI_MEMREGION_IS_SUX_MRX(reg->flags)) /* locked region */ pmp_flags = (PMP_L | PMP_W | PMP_X); /* Execute only for both M and SU modes */ - else if (SBI_DOMAIN_MEMREGION_IS_SUX_MX(reg->flags)) + else if (SBI_MEMREGION_IS_SUX_MX(reg->flags)) pmp_flags = (PMP_L | PMP_W); /* Read/Write for both M and SU modes */ - else if (SBI_DOMAIN_MEMREGION_IS_SURW_MRW(reg->flags)) + else if (SBI_MEMREGION_IS_SURW_MRW(reg->flags)) pmp_flags = (PMP_W | PMP_X); /* Read only for SU mode but Read/Write for M mode */ - else if (SBI_DOMAIN_MEMREGION_IS_SUR_MRW(reg->flags)) + else if (SBI_MEMREGION_IS_SUR_MRW(reg->flags)) pmp_flags = (PMP_W); - } else if (SBI_DOMAIN_MEMREGION_M_ONLY_ACCESS(reg->flags)) { + } else if (SBI_MEMREGION_M_ONLY_ACCESS(reg->flags)) { /* * When smepmp is supported and used, M region cannot have RWX * permissions on any region. */ - if ((reg->flags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK) - == SBI_DOMAIN_MEMREGION_M_RWX) { + if ((reg->flags & SBI_MEMREGION_M_ACCESS_MASK) + == SBI_MEMREGION_M_RWX) { sbi_printf("%s: M-mode only regions cannot have" "RWX permissions\n", __func__); return 0; @@ -328,18 +328,18 @@ static unsigned int sbi_hart_get_smepmp_flags(struct sbi_scratch *scratch, /* M-mode only access regions are always locked */ pmp_flags |= PMP_L; - if (reg->flags & SBI_DOMAIN_MEMREGION_M_READABLE) + if (reg->flags & SBI_MEMREGION_M_READABLE) pmp_flags |= PMP_R; - if (reg->flags & SBI_DOMAIN_MEMREGION_M_WRITABLE) + if (reg->flags & SBI_MEMREGION_M_WRITABLE) pmp_flags |= PMP_W; - if (reg->flags & SBI_DOMAIN_MEMREGION_M_EXECUTABLE) + if (reg->flags & SBI_MEMREGION_M_EXECUTABLE) pmp_flags |= PMP_X; - } else if (SBI_DOMAIN_MEMREGION_SU_ONLY_ACCESS(reg->flags)) { - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE) + } else if (SBI_MEMREGION_SU_ONLY_ACCESS(reg->flags)) { + if (reg->flags & SBI_MEMREGION_SU_READABLE) pmp_flags |= PMP_R; - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE) + if (reg->flags & SBI_MEMREGION_SU_WRITABLE) pmp_flags |= PMP_W; - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) + if (reg->flags & SBI_MEMREGION_SU_EXECUTABLE) pmp_flags |= PMP_X; } @@ -348,7 +348,7 @@ static unsigned int sbi_hart_get_smepmp_flags(struct sbi_scratch *scratch, static void sbi_hart_smepmp_set(struct sbi_scratch *scratch, struct sbi_domain *dom, - struct sbi_domain_memregion *reg, + struct sbi_memregion *reg, unsigned int pmp_idx, unsigned int pmp_flags, unsigned int pmp_log2gran, @@ -371,7 +371,7 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch, unsigned int pmp_log2gran, unsigned long pmp_addr_max) { - struct sbi_domain_memregion *reg; + struct sbi_memregion *reg; struct sbi_domain *dom = sbi_domain_thishart_ptr(); unsigned int pmp_idx, pmp_flags; @@ -394,7 +394,7 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch, break; /* Skip shared and SU-only regions */ - if (!SBI_DOMAIN_MEMREGION_M_ONLY_ACCESS(reg->flags)) { + if (!SBI_MEMREGION_M_ONLY_ACCESS(reg->flags)) { pmp_idx++; continue; } @@ -420,7 +420,7 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch, break; /* Skip M-only regions */ - if (SBI_DOMAIN_MEMREGION_M_ONLY_ACCESS(reg->flags)) { + if (SBI_MEMREGION_M_ONLY_ACCESS(reg->flags)) { pmp_idx++; continue; } @@ -446,7 +446,7 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch, unsigned int pmp_log2gran, unsigned long pmp_addr_max) { - struct sbi_domain_memregion *reg; + struct sbi_memregion *reg; struct sbi_domain *dom = sbi_domain_thishart_ptr(); unsigned int pmp_idx = 0; unsigned int pmp_flags; @@ -462,14 +462,14 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch, * If permissions are to be enforced for all modes on * this region, the lock bit should be set. */ - if (reg->flags & SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS) + if (reg->flags & SBI_MEMREGION_ENF_PERMISSIONS) pmp_flags |= PMP_L; - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE) + if (reg->flags & SBI_MEMREGION_SU_READABLE) pmp_flags |= PMP_R; - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE) + if (reg->flags & SBI_MEMREGION_SU_WRITABLE) pmp_flags |= PMP_W; - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) + if (reg->flags & SBI_MEMREGION_SU_EXECUTABLE) pmp_flags |= PMP_X; pmp_addr = reg->base >> PMP_SHIFT; diff --git a/lib/sbi/sbi_memregion.c b/lib/sbi/sbi_memregion.c index 1ef53dc..4abd20a 100644 --- a/lib/sbi/sbi_memregion.c +++ b/lib/sbi/sbi_memregion.c @@ -4,10 +4,10 @@ #include #include -void sbi_domain_memregion_init(unsigned long addr, +void sbi_memregion_init(unsigned long addr, unsigned long size, unsigned long flags, - struct sbi_domain_memregion *reg) + struct sbi_memregion *reg) { unsigned long base = 0, order; @@ -34,8 +34,8 @@ void sbi_domain_memregion_init(unsigned long addr, } /** Check if regionA is sub-region of regionB */ -static bool is_region_subset(const struct sbi_domain_memregion *regA, - const struct sbi_domain_memregion *regB) +static bool is_region_subset(const struct sbi_memregion *regA, + const struct sbi_memregion *regB) { ulong regA_start = regA->base; ulong regA_end = regA->base + (BIT(regA->order) - 1); @@ -52,8 +52,8 @@ static bool is_region_subset(const struct sbi_domain_memregion *regA, } /** Check if regionA can be replaced by regionB */ -static bool is_region_compatible(const struct sbi_domain_memregion *regA, - const struct sbi_domain_memregion *regB) +static bool is_region_compatible(const struct sbi_memregion *regA, + const struct sbi_memregion *regB) { if (is_region_subset(regA, regB) && regA->flags == regB->flags) return true; @@ -62,7 +62,7 @@ static bool is_region_compatible(const struct sbi_domain_memregion *regA, } /* Check if region complies with constraints */ -static bool is_region_valid(const struct sbi_domain_memregion *reg) +static bool is_region_valid(const struct sbi_memregion *reg) { if (reg->order < 3 || __riscv_xlen < reg->order) return false; @@ -77,8 +77,8 @@ static bool is_region_valid(const struct sbi_domain_memregion *reg) } /** Check if regionA should be placed before regionB */ -static bool is_region_before(const struct sbi_domain_memregion *regA, - const struct sbi_domain_memregion *regB) +static bool is_region_before(const struct sbi_memregion *regA, + const struct sbi_memregion *regB) { if (regA->order < regB->order) return true; @@ -91,26 +91,26 @@ static bool is_region_before(const struct sbi_domain_memregion *regA, } -static void swap_region(struct sbi_domain_memregion* reg1, - struct sbi_domain_memregion* reg2) +static void swap_region(struct sbi_memregion * reg1, + struct sbi_memregion * reg2) { - struct sbi_domain_memregion treg; + struct sbi_memregion treg; sbi_memcpy(&treg, reg1, sizeof(treg)); sbi_memcpy(reg1, reg2, sizeof(treg)); sbi_memcpy(reg2, &treg, sizeof(treg)); } -static void clear_region(struct sbi_domain_memregion* reg) +static void clear_region(struct sbi_memregion * reg) { sbi_memset(reg, 0x0, sizeof(*reg)); } -int sbi_domain_memregions_sanitize(struct sbi_domain *dom) +int sbi_memregion_sanitize(struct sbi_domain *dom) { int i, j, count; bool is_covered; - struct sbi_domain_memregion *reg, *reg1; + struct sbi_memregion *reg, *reg1; /* Check memory regions */ if (!dom->regions) { @@ -187,7 +187,7 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom, unsigned long access_flags) { bool rmmio, mmio = false; - struct sbi_domain_memregion *reg; + struct sbi_memregion *reg; unsigned long rstart, rend, rflags, rwx = 0, rrwx = 0; if (!dom) @@ -199,13 +199,13 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom, * bits will fall at same offsets after the shift. */ if (access_flags & SBI_DOMAIN_READ) - rwx |= SBI_DOMAIN_MEMREGION_M_READABLE; + rwx |= SBI_MEMREGION_M_READABLE; if (access_flags & SBI_DOMAIN_WRITE) - rwx |= SBI_DOMAIN_MEMREGION_M_WRITABLE; + rwx |= SBI_MEMREGION_M_WRITABLE; if (access_flags & SBI_DOMAIN_EXECUTE) - rwx |= SBI_DOMAIN_MEMREGION_M_EXECUTABLE; + rwx |= SBI_MEMREGION_M_EXECUTABLE; if (access_flags & SBI_DOMAIN_MMIO) mmio = true; @@ -213,15 +213,15 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom, sbi_domain_for_each_memregion(dom, reg) { rflags = reg->flags; rrwx = (mode == PRV_M ? - (rflags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK) : - (rflags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK) - >> SBI_DOMAIN_MEMREGION_SU_ACCESS_SHIFT); + (rflags & SBI_MEMREGION_M_ACCESS_MASK) : + (rflags & SBI_MEMREGION_SU_ACCESS_MASK) + >> SBI_MEMREGION_SU_ACCESS_SHIFT); rstart = reg->base; rend = (reg->order < __riscv_xlen) ? rstart + ((1UL << reg->order) - 1) : -1UL; if (rstart <= addr && addr <= rend) { - rmmio = (rflags & SBI_DOMAIN_MEMREGION_MMIO) ? true : false; + rmmio = (rflags & SBI_MEMREGION_MMIO) ? true : false; if (mmio != rmmio) return false; return ((rrwx & rwx) == rwx) ? true : false; @@ -231,12 +231,12 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom, return (mode == PRV_M) ? true : false; } -static const struct sbi_domain_memregion *find_region( +static const struct sbi_memregion *find_region( const struct sbi_domain *dom, unsigned long addr) { unsigned long rstart, rend; - struct sbi_domain_memregion *reg; + struct sbi_memregion *reg; sbi_domain_for_each_memregion(dom, reg) { rstart = reg->base; @@ -249,12 +249,12 @@ static const struct sbi_domain_memregion *find_region( return NULL; } -static const struct sbi_domain_memregion *find_next_subset_region( +static const struct sbi_memregion *find_next_subset_region( const struct sbi_domain *dom, - const struct sbi_domain_memregion *reg, + const struct sbi_memregion *reg, unsigned long addr) { - struct sbi_domain_memregion *sreg, *ret = NULL; + struct sbi_memregion *sreg, *ret = NULL; sbi_domain_for_each_memregion(dom, sreg) { if (sreg == reg || (sreg->base <= addr) || @@ -275,7 +275,7 @@ bool sbi_domain_check_addr_range(const struct sbi_domain *dom, unsigned long access_flags) { unsigned long max = addr + size; - const struct sbi_domain_memregion *reg, *sreg; + const struct sbi_memregion *reg, *sreg; if (!dom) return false; @@ -303,7 +303,7 @@ bool sbi_domain_check_addr_range(const struct sbi_domain *dom, void sbi_domain_dump_memregions(const struct sbi_domain *dom, const char *suffix) { unsigned long rstart, rend; - struct sbi_domain_memregion *reg; + struct sbi_memregion *reg; int i = 0, k; sbi_domain_for_each_memregion(dom, reg) { @@ -317,26 +317,26 @@ void sbi_domain_dump_memregions(const struct sbi_domain *dom, const char *suffix k = 0; sbi_printf("M: "); - if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO) + if (reg->flags & SBI_MEMREGION_MMIO) sbi_printf("%cI", (k++) ? ',' : '('); - if (reg->flags & SBI_DOMAIN_MEMREGION_M_READABLE) + if (reg->flags & SBI_MEMREGION_M_READABLE) sbi_printf("%cR", (k++) ? ',' : '('); - if (reg->flags & SBI_DOMAIN_MEMREGION_M_WRITABLE) + if (reg->flags & SBI_MEMREGION_M_WRITABLE) sbi_printf("%cW", (k++) ? ',' : '('); - if (reg->flags & SBI_DOMAIN_MEMREGION_M_EXECUTABLE) + if (reg->flags & SBI_MEMREGION_M_EXECUTABLE) sbi_printf("%cX", (k++) ? ',' : '('); sbi_printf("%s ", (k++) ? ")" : "()"); k = 0; sbi_printf("S/U: "); - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE) + if (reg->flags & SBI_MEMREGION_SU_READABLE) sbi_printf("%cR", (k++) ? ',' : '('); - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE) + if (reg->flags & SBI_MEMREGION_SU_WRITABLE) sbi_printf("%cW", (k++) ? ',' : '('); - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) + if (reg->flags & SBI_MEMREGION_SU_EXECUTABLE) sbi_printf("%cX", (k++) ? ',' : '('); sbi_printf("%s\n", (k++) ? ")" : "()"); i++; } -} \ No newline at end of file +} diff --git a/lib/utils/fdt/fdt_domain.c b/lib/utils/fdt/fdt_domain.c index 3623c6b..779acec 100644 --- a/lib/utils/fdt/fdt_domain.c +++ b/lib/utils/fdt/fdt_domain.c @@ -103,9 +103,9 @@ static int __fixup_find_domain_offset(void *fdt, int doff, void *p) return 0; } -#define DISABLE_DEVICES_MASK (SBI_DOMAIN_MEMREGION_READABLE | \ - SBI_DOMAIN_MEMREGION_WRITEABLE | \ - SBI_DOMAIN_MEMREGION_EXECUTABLE) +#define DISABLE_DEVICES_MASK (SBI_MEMREGION_READABLE | \ + SBI_MEMREGION_WRITEABLE | \ + SBI_MEMREGION_EXECUTABLE) static int __fixup_count_disable_devices(void *fdt, int doff, int roff, u32 perm, void *p) @@ -237,7 +237,7 @@ static int __fdt_parse_region(void *fdt, int domain_offset, u64 val64; const u32 *val; struct parse_region_data *preg = opaque; - struct sbi_domain_memregion *region; + struct sbi_memregion *region; /* * Non-root domains cannot add a region with only M-mode @@ -247,8 +247,8 @@ static int __fdt_parse_region(void *fdt, int domain_offset, * SU permission bits can't be all zeroes when M-mode permission * bits have at least one bit set. */ - if (!(region_access & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK) - && (region_access & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK)) + if (!(region_access & SBI_MEMREGION_SU_ACCESS_MASK) + && (region_access & SBI_MEMREGION_M_ACCESS_MASK)) return SBI_EINVAL; /* Find next region of the domain */ @@ -274,9 +274,9 @@ static int __fdt_parse_region(void *fdt, int domain_offset, region->order = val32; /* Read "mmio" DT property */ - region->flags = region_access & SBI_DOMAIN_MEMREGION_ACCESS_MASK; + region->flags = region_access & SBI_MEMREGION_ACCESS_MASK; if (fdt_get_property(fdt, region_offset, "mmio", NULL)) - region->flags |= SBI_DOMAIN_MEMREGION_MMIO; + region->flags |= SBI_MEMREGION_MMIO; preg->region_count++; @@ -293,7 +293,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque) struct sbi_hartmask assign_mask; struct parse_region_data preg; int *cold_domain_offset = opaque; - struct sbi_domain_memregion *reg; + struct sbi_memregion *reg; int i, err = 0, len, cpus_offset, cpu_offset, doffset; dom = sbi_zalloc(sizeof(*dom)); @@ -362,9 +362,9 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque) * 2) mmio regions protecting M-mode only mmio devices */ sbi_domain_for_each_memregion(&root, reg) { - if ((reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE) || - (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE) || - (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)) + if ((reg->flags & SBI_MEMREGION_SU_READABLE) || + (reg->flags & SBI_MEMREGION_SU_WRITABLE) || + (reg->flags & SBI_MEMREGION_SU_EXECUTABLE)) continue; if (preg.max_regions <= preg.region_count) { err = SBI_EINVAL; diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c index 974b1b8..fd45763 100644 --- a/lib/utils/fdt/fdt_fixup.c +++ b/lib/utils/fdt/fdt_fixup.c @@ -282,7 +282,7 @@ static int fdt_resv_memory_update_node(void *fdt, unsigned long addr, */ int fdt_reserved_memory_fixup(void *fdt) { - struct sbi_domain_memregion *reg; + struct sbi_memregion *reg; struct sbi_domain *dom = sbi_domain_thishart_ptr(); unsigned long filtered_base[PMP_COUNT] = { 0 }; unsigned char filtered_order[PMP_COUNT] = { 0 }; @@ -343,13 +343,13 @@ int fdt_reserved_memory_fixup(void *fdt) i = 0; sbi_domain_for_each_memregion(dom, reg) { /* Ignore MMIO or READABLE or WRITABLE or EXECUTABLE regions */ - if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO) + if (reg->flags & SBI_MEMREGION_MMIO) continue; - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE) + if (reg->flags & SBI_MEMREGION_SU_READABLE) continue; - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE) + if (reg->flags & SBI_MEMREGION_SU_WRITABLE) continue; - if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE) + if (reg->flags & SBI_MEMREGION_SU_EXECUTABLE) continue; if (i >= PMP_COUNT) { diff --git a/lib/utils/ipi/aclint_mswi.c b/lib/utils/ipi/aclint_mswi.c index 4ae6bb1..231a1d6 100644 --- a/lib/utils/ipi/aclint_mswi.c +++ b/lib/utils/ipi/aclint_mswi.c @@ -85,7 +85,7 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi) int rc; struct sbi_scratch *scratch; unsigned long pos, region_size; - struct sbi_domain_memregion reg; + struct sbi_memregion reg; /* Sanity checks */ if (!mswi || (mswi->addr & (ACLINT_MSWI_ALIGN - 1)) || @@ -117,11 +117,11 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi) for (pos = 0; pos < mswi->size; pos += ACLINT_MSWI_ALIGN) { region_size = ((mswi->size - pos) < ACLINT_MSWI_ALIGN) ? (mswi->size - pos) : ACLINT_MSWI_ALIGN; - sbi_domain_memregion_init(mswi->addr + pos, region_size, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE), - ®); + sbi_memregion_init(mswi->addr + pos, region_size, + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE), + ®); rc = sbi_domain_root_add_memregion(®); if (rc) return rc; diff --git a/lib/utils/ipi/andes_plicsw.c b/lib/utils/ipi/andes_plicsw.c index 413ac20..5ce64fc 100644 --- a/lib/utils/ipi/andes_plicsw.c +++ b/lib/utils/ipi/andes_plicsw.c @@ -103,9 +103,9 @@ int plicsw_cold_ipi_init(struct plicsw_data *plicsw) /* Add PLICSW region to the root domain */ rc = sbi_domain_root_add_memrange(plicsw->addr, plicsw->size, PLICSW_REGION_ALIGN, - SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE); + SBI_MEMREGION_MMIO | + SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE); if (rc) return rc; diff --git a/lib/utils/irqchip/aplic.c b/lib/utils/irqchip/aplic.c index 10236e7..84cdae0 100644 --- a/lib/utils/irqchip/aplic.c +++ b/lib/utils/irqchip/aplic.c @@ -169,7 +169,7 @@ int aplic_cold_irqchip_init(struct aplic_data *aplic) { int rc; u32 i, j, tmp; - struct sbi_domain_memregion reg; + struct sbi_memregion reg; struct aplic_delegate_data *deleg; u32 first_deleg_irq, last_deleg_irq; @@ -268,11 +268,11 @@ int aplic_cold_irqchip_init(struct aplic_data *aplic) ((first_deleg_irq < last_deleg_irq) && (last_deleg_irq == aplic->num_source) && (first_deleg_irq == 1))) { - sbi_domain_memregion_init(aplic->addr, aplic->size, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE), - ®); + sbi_memregion_init(aplic->addr, aplic->size, + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE), + ®); rc = sbi_domain_root_add_memregion(®); if (rc) return rc; diff --git a/lib/utils/irqchip/imsic.c b/lib/utils/irqchip/imsic.c index 7d6993e..d0f2e95 100644 --- a/lib/utils/irqchip/imsic.c +++ b/lib/utils/irqchip/imsic.c @@ -348,7 +348,7 @@ int imsic_data_check(struct imsic_data *imsic) int imsic_cold_irqchip_init(struct imsic_data *imsic) { int i, rc; - struct sbi_domain_memregion reg; + struct sbi_memregion reg; /* Sanity checks */ rc = imsic_data_check(imsic); @@ -378,12 +378,11 @@ int imsic_cold_irqchip_init(struct imsic_data *imsic) /* Add IMSIC regions to the root domain */ for (i = 0; i < IMSIC_MAX_REGS && imsic->regs[i].size; i++) { - sbi_domain_memregion_init(imsic->regs[i].addr, - imsic->regs[i].size, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE), - ®); + sbi_memregion_init(imsic->regs[i].addr, imsic->regs[i].size, + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE), + ®); rc = sbi_domain_root_add_memregion(®); if (rc) return rc; diff --git a/lib/utils/irqchip/plic.c b/lib/utils/irqchip/plic.c index 193e320..b1b3ba2 100644 --- a/lib/utils/irqchip/plic.c +++ b/lib/utils/irqchip/plic.c @@ -174,6 +174,6 @@ int plic_cold_irqchip_init(const struct plic_data *plic) plic_set_priority(plic, i, 0); return sbi_domain_root_add_memrange(plic->addr, plic->size, BIT(20), - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW)); + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_SHARED_SURW_MRW)); } diff --git a/lib/utils/regmap/fdt_regmap_syscon.c b/lib/utils/regmap/fdt_regmap_syscon.c index d87b6e0..bd031f5 100644 --- a/lib/utils/regmap/fdt_regmap_syscon.c +++ b/lib/utils/regmap/fdt_regmap_syscon.c @@ -242,8 +242,8 @@ static int regmap_syscon_init(void *fdt, int nodeoff, u32 phandle, } rc = sbi_domain_root_add_memrange(addr, size, PAGE_SIZE, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW)); + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_SHARED_SURW_MRW)); if (rc) goto fail_free_syscon; diff --git a/lib/utils/serial/cadence-uart.c b/lib/utils/serial/cadence-uart.c index 30fbb95..a9e6ea9 100644 --- a/lib/utils/serial/cadence-uart.c +++ b/lib/utils/serial/cadence-uart.c @@ -127,6 +127,6 @@ int cadence_uart_init(unsigned long base, u32 in_freq, u32 baudrate) sbi_console_set_device(&cadence_console); return sbi_domain_root_add_memrange(base, PAGE_SIZE, PAGE_SIZE, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW)); + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_SHARED_SURW_MRW)); } diff --git a/lib/utils/serial/fdt_serial_htif.c b/lib/utils/serial/fdt_serial_htif.c index 7d88e7a..d113cb5 100644 --- a/lib/utils/serial/fdt_serial_htif.c +++ b/lib/utils/serial/fdt_serial_htif.c @@ -33,8 +33,8 @@ static int serial_htif_init(void *fdt, int nodeoff, fdt_get_node_addr_size(fdt, nodeoff, 1, &tohost_addr, NULL); rc = sbi_domain_root_add_memrange(fromhost_addr, PAGE_SIZE, PAGE_SIZE, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW)); + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_SHARED_SURW_MRW)); if (rc) return rc; diff --git a/lib/utils/serial/uart8250.c b/lib/utils/serial/uart8250.c index 1fe053f..aec9456 100644 --- a/lib/utils/serial/uart8250.c +++ b/lib/utils/serial/uart8250.c @@ -136,6 +136,6 @@ int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift, sbi_console_set_device(&uart8250_console); return sbi_domain_root_add_memrange(base, PAGE_SIZE, PAGE_SIZE, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW)); + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_SHARED_SURW_MRW)); } diff --git a/lib/utils/timer/aclint_mtimer.c b/lib/utils/timer/aclint_mtimer.c index 9acb26e..41dbfb0 100644 --- a/lib/utils/timer/aclint_mtimer.c +++ b/lib/utils/timer/aclint_mtimer.c @@ -227,34 +227,34 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt, rc = sbi_domain_root_add_memrange(mt->mtimecmp_addr, mt->mtime_size + mt->mtimecmp_size, MTIMER_REGION_ALIGN, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE)); + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE)); if (rc) return rc; } else if (mt->mtimecmp_addr == (mt->mtime_addr + mt->mtime_size)) { rc = sbi_domain_root_add_memrange(mt->mtime_addr, mt->mtime_size + mt->mtimecmp_size, MTIMER_REGION_ALIGN, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE)); + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE)); if (rc) return rc; } else { rc = sbi_domain_root_add_memrange(mt->mtime_addr, mt->mtime_size, MTIMER_REGION_ALIGN, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE)); + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE)); if (rc) return rc; rc = sbi_domain_root_add_memrange(mt->mtimecmp_addr, mt->mtimecmp_size, MTIMER_REGION_ALIGN, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE)); + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE)); if (rc) return rc; } diff --git a/lib/utils/timer/andes_plmt.c b/lib/utils/timer/andes_plmt.c index 6e4bfaf..71be37f 100644 --- a/lib/utils/timer/andes_plmt.c +++ b/lib/utils/timer/andes_plmt.c @@ -83,9 +83,9 @@ int plmt_cold_timer_init(struct plmt_data *plmt) rc = sbi_domain_root_add_memrange( (unsigned long)plmt->time_val, plmt->size, PLMT_REGION_ALIGN, - SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE); + SBI_MEMREGION_MMIO | + SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE); if (rc) return rc; diff --git a/platform/generic/renesas/rzfive/rzfive.c b/platform/generic/renesas/rzfive/rzfive.c index 515bcd7..e13224d 100644 --- a/platform/generic/renesas/rzfive/rzfive.c +++ b/platform/generic/renesas/rzfive/rzfive.c @@ -45,7 +45,7 @@ static int renesas_rzfive_early_init(bool cold_boot, const struct fdt_match *mat * we grant full access. */ return sbi_domain_root_add_memrange(0x30000, 0x20000, 0x1000, - SBI_DOMAIN_MEMREGION_M_RWX); + SBI_MEMREGION_M_RWX); } static const struct fdt_match renesas_rzfive_match[] = { diff --git a/platform/generic/sophgo/sg2042.c b/platform/generic/sophgo/sg2042.c index ae2d702..6a2736d 100644 --- a/platform/generic/sophgo/sg2042.c +++ b/platform/generic/sophgo/sg2042.c @@ -36,9 +36,9 @@ static int sophgo_sg2042_early_init(bool cold_boot, SOPHGO_SG2042_TIMER_SIZE * SOPHGO_SG2042_TIMER_NUM, MTIMER_REGION_ALIGN, - (SBI_DOMAIN_MEMREGION_MMIO | - SBI_DOMAIN_MEMREGION_M_READABLE | - SBI_DOMAIN_MEMREGION_M_WRITABLE)); + (SBI_MEMREGION_MMIO | + SBI_MEMREGION_M_READABLE | + SBI_MEMREGION_M_WRITABLE)); return 0; From patchwork Wed Jul 31 18:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Haas X-Patchwork-Id: 1967257 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=pYbxkHE3; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=QSf69CsE; 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=opensbi-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 4WZ0fz3Zg9z20FK for ; Thu, 1 Aug 2024 04:16:59 +1000 (AEST) 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:References:In-Reply-To: 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: List-Owner; bh=JUekLn25zyBIOIsouGHCu6KWGnXscwuAoBodwA+/x9M=; b=pYbxkHE3N9HA5Y OOoWhdb7VrvxhjOaEgMCiEW9+JGuy8r54935riQcoyyBc0LiRrXkXofhlu+65nrtluS5jjlYplQx3 wtXO3BL+DkRsH9J6UzEu/riz7Nog+WcmTBi0U0z3t5HQzC5H3nO54kKvYzttgVSpImSd/k/Ua9yiy gfMyFseEqoxHP+X4CAxuyWVkSv0UuYH5wDzxuTOHrSnoN8lqI1r9XykZr5wXDF37cvdU91Rc72bn3 ikOQvkYiUc0HFReJidFHO22EY8L09hxYB04iddHYaXvrCfZlXZGgRHAdJJaMfSQdr7K07Rvt8OMMu XWUyFzKpm1BS8yVO5o+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsW-000000026fF-1rix; Wed, 31 Jul 2024 18:16:48 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsT-000000026dS-34bA for opensbi@lists.infradead.org; Wed, 31 Jul 2024 18:16:47 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1fd640a6454so45987095ad.3 for ; Wed, 31 Jul 2024 11:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722449805; x=1723054605; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wMPQnMNsezHWrX53AMt/eHKOnpHJBaVjm8qopUPTs0o=; b=QSf69CsEBT4pwMNcnpEUV/qiljUrUmXqhgbDfTkn+VXu4AT1aMJTlyKSs9TCiIk4aN nWdFysPoiN9n/gbh5RP9v/uWVHxdHYTY5AoKJy92Zqc4ytDMUp/FNH+eY7quOTPlZMia vmAgpgktbwkVxTTdDtVGR4KLEEe+qFyCi0KDTEQBRV4ucxHmQpn0zCoPiGzBwDtohsmV 7FZRzFb6RLX64F27JFvXq1RjcpPCElAch0skb3YWPLtzK1NM+l/tKldCMGSY1Ox1tJZ9 mVcr8UQUF384jC1HNNZZPH10wotVUvrML//30lo4Y5ja8dSblVFcW/eUOxvMH0m5QYnj JOnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722449805; x=1723054605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wMPQnMNsezHWrX53AMt/eHKOnpHJBaVjm8qopUPTs0o=; b=X2ZiIwMtnbbLOqtWrxNNhoEAqL3O4//Q1lLQIgDOhNNr/wgtZtuloR8GDChHsu/jwP EE2urtR/UJFF4qRzLN7WyVoVzkJfm4XFVf0/NR26GA767Ha9MIvAiJOmauyNWICSLJb+ 2Uir2luVolgRAAw6vb5YK3ZemYfF8MPCQAHROUkYEv88HN2e35Sx1KgZd0n0c8x+rzfs a8jrSh017GbNr+8rwJqdKz1kd6lg8ZxSNNyfbIwzgt1MqIEvXnQR8QGPwZJY3Af8Z+h5 YcRJrKGWAxKiIjMryKSznvIVReYMLIJZXX/dfNkEr4zyDbAE4Bwg8ECAajMzjbozj3yi sfsw== X-Gm-Message-State: AOJu0YyFWDQqmYrnxgThKl3+4T9WPsfwaCDR25n5wqF7bRq829885n7+ WSzhjQECd32X3popFKx9Kc+n4l7BikryaGeVbI1VGgzni/D4XzdLfGQJRCJ0 X-Google-Smtp-Source: AGHT+IGpZFnHVYGwKLfyY0MwMGDxCIJGfer14ZwMxHfeiTWZy8tqg5TX/pEnsroGLJoYth1LEXgYiQ== X-Received: by 2002:a17:902:f9c3:b0:1fc:60f1:1905 with SMTP id d9443c01a7336-1ff4d279f94mr1297125ad.61.1722449804698; Wed, 31 Jul 2024 11:16:44 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fed7fb497esm122723875ad.268.2024.07.31.11.16.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jul 2024 11:16:44 -0700 (PDT) From: Gregor Haas To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, Gregor Haas Subject: [PATCH 4/8] lib: sbi: memregion: Introduce memregion_start/end macros Date: Wed, 31 Jul 2024 11:16:25 -0700 Message-ID: <20240731181629.269898-5-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731181629.269898-1-gregorhaas1997@gmail.com> References: <20240731181629.269898-1-gregorhaas1997@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_111645_799530_527DDDB6 X-CRM114-Status: GOOD ( 10.60 ) X-Spam-Score: -1.8 (-) 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: Various disparate parts of the memregion handling code calculate the base and bounds of memregions. Standardize these calculations into two new macros: memregion_start() and memregion_end(). This will [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:635 listed in] [list.dnswl.org] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [gregorhaas1997(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gregorhaas1997(at)gmail.com] 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 Various disparate parts of the memregion handling code calculate the base and bounds of memregions. Standardize these calculations into two new macros: memregion_start() and memregion_end(). This will reduce the amount of code changes later, when we make memregions keep track of raw sizes rather than rounded orders. --- include/sbi/sbi_memregion.h | 6 ++++++ lib/sbi/sbi_memregion.c | 23 ++++++++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/sbi/sbi_memregion.h b/include/sbi/sbi_memregion.h index 0aa9a44..6e1b771 100644 --- a/include/sbi/sbi_memregion.h +++ b/include/sbi/sbi_memregion.h @@ -145,6 +145,12 @@ struct sbi_memregion { unsigned long flags; }; +#define memregion_start(reg) \ + ((reg)->base) + +#define memregion_end(reg) \ + ((reg)->order < __riscv_xlen) ? \ + (reg)->base + ((1UL << (reg)->order) - 1) : -1UL; /** * Initialize a domain memory region based on it's physical * address and size. diff --git a/lib/sbi/sbi_memregion.c b/lib/sbi/sbi_memregion.c index 4abd20a..8978793 100644 --- a/lib/sbi/sbi_memregion.c +++ b/lib/sbi/sbi_memregion.c @@ -37,10 +37,10 @@ void sbi_memregion_init(unsigned long addr, static bool is_region_subset(const struct sbi_memregion *regA, const struct sbi_memregion *regB) { - ulong regA_start = regA->base; - ulong regA_end = regA->base + (BIT(regA->order) - 1); - ulong regB_start = regB->base; - ulong regB_end = regB->base + (BIT(regB->order) - 1); + ulong regA_start = memregion_start(regA); + ulong regA_end = memregion_end(regA); + ulong regB_start = memregion_start(regB); + ulong regB_end = memregion_end(regB); if ((regB_start <= regA_start) && (regA_start < regB_end) && @@ -217,9 +217,8 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom, (rflags & SBI_MEMREGION_SU_ACCESS_MASK) >> SBI_MEMREGION_SU_ACCESS_SHIFT); - rstart = reg->base; - rend = (reg->order < __riscv_xlen) ? - rstart + ((1UL << reg->order) - 1) : -1UL; + rstart = memregion_start(reg); + rend = memregion_end(reg); if (rstart <= addr && addr <= rend) { rmmio = (rflags & SBI_MEMREGION_MMIO) ? true : false; if (mmio != rmmio) @@ -239,9 +238,8 @@ static const struct sbi_memregion *find_region( struct sbi_memregion *reg; sbi_domain_for_each_memregion(dom, reg) { - rstart = reg->base; - rend = (reg->order < __riscv_xlen) ? - rstart + ((1UL << reg->order) - 1) : -1UL; + rstart = memregion_start(reg); + rend = memregion_end(reg); if (rstart <= addr && addr <= rend) return reg; } @@ -307,9 +305,8 @@ void sbi_domain_dump_memregions(const struct sbi_domain *dom, const char *suffix int i = 0, k; sbi_domain_for_each_memregion(dom, reg) { - rstart = reg->base; - rend = (reg->order < __riscv_xlen) ? - rstart + ((1UL << reg->order) - 1) : -1UL; + rstart = memregion_start(reg); + rend = memregion_end(reg); sbi_printf("Domain%d Region%02d %s: 0x%" PRILX "-0x%" PRILX " ", dom->index, i, suffix, rstart, rend); From patchwork Wed Jul 31 18:16:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Haas X-Patchwork-Id: 1967258 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=lkrHlelG; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BKIFrWNg; 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=opensbi-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 4WZ0g12FS2z20Mw for ; Thu, 1 Aug 2024 04:17:01 +1000 (AEST) 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:References:In-Reply-To: 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: List-Owner; bh=a0XCOFiv6KRBgsnmV0AAKKwGm+3KtbezpmjBYRLlj8U=; b=lkrHlelGKoSZut U/eoXaUifP2SSgmx6s384BoZaPhws9LdWgI7vzlFXwg+50f2RyiSFkB9vOI0HIKMqzTf0tXOPTHjK LRlBuWt6hmBdrPas1cid5GnI4CLXKTnga9qBjua3wkyAMxpFvrOifwdFPPZyWb6vazVHINsd+SFbW D/XMO+/iCplIeVMs5y6q5/j2w2e3FNmMHHXaZmMy3Af8ZvZcTlmOjvPQYvPFBasVHdj7Gq4zPVQ0J 4WilKCAMn4i7OOicL/j6gTaG+Ku2WOtDFQA30CeCF0izU4SeAO26hVljmnXMN4qW5Gf36pRUi8OuT qt59NRgyKZrAsJNK/Wmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsa-000000026iV-3zW9; Wed, 31 Jul 2024 18:16:52 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsV-000000026dp-2XUt for opensbi@lists.infradead.org; Wed, 31 Jul 2024 18:16:49 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-7104f93a20eso822701b3a.1 for ; Wed, 31 Jul 2024 11:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722449806; x=1723054606; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vBtMgBOiQv5+IiJxT41dcejGtsH4vQ5/uLTfXQZW0zQ=; b=BKIFrWNgu4hjr1fqzyOWoYvlaRlNnTJlZkEa/i76ajS/HB3yspPFw6CQaAIW0Qy9JE N8PrpKm36I0ywj/ndcikV/7xflL9yTaGtOGbP3asaVcrL2AS1+kBnw5z6a/lo/GFt/e3 brYAIv2Uj8xW4yQA/Eg8MG9n5Nphcei5KqfqgpmG7xX+rEJwTdUo98cqQ8P2E1yELOoA XmK1ZQ1vJJ86wYYOAccGDQOG71Q/HcgDaGBK2Uf71zCqq+Kow6lqT7WXv7p8hN+W7iOW a+8C8oPcXkJ+vLFYRyEeuRCWwnnU1rxlCayF90Zjo8X1/kIs0CS4fzDzO6J3YwEKFDZj f0Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722449806; x=1723054606; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vBtMgBOiQv5+IiJxT41dcejGtsH4vQ5/uLTfXQZW0zQ=; b=hylgm7J+IeD+QiAUVCZ2SY8SMgCItAs1i5FzAC1gLAOxit1W2bCL50JTlmBfDumEEP KJU/JB4zHwgXghwK5VhGgXUDJNCvEmVTpqg/uHwO5UuydtiDxWNdSEvwVMAD60ehzTTW fbhsJ/iVul5btfXktmIbGE3MV1l8PkhOqsZL9OGPg5DRG9q6w1Ca3a3i0iK8lpAAphPB Qg8q1S3ExSYjwG10AYBYC9RQvS/ZAt1ZrkCt8f6O3NnRYKFpQdbvQtOAGsrcIdXzBs4u ap5iobYRjbczVMqTgOZ6c1YLEnfXR4eTBaT0RlpHdm+K2vp2RqC9AtxpQbsvrl3oUZLg mm6Q== X-Gm-Message-State: AOJu0Yz6F4n1bz5pjTrJ9eL4ENWjhRVL15X4Ww1hTiAXHLTWnGgOjxs8 tAG+zj3axhniM9qWx4Xj32+fS0edWzXa5V7b/95e1CL4+RgAV2RdbqViAi9J X-Google-Smtp-Source: AGHT+IEJU397HpjOU69rnZjRtG0Cgs6GwFGCf27QoyWJf5DMcjQQQvMTp7r9DYWAZvtt4zwXM+L4GQ== X-Received: by 2002:a05:6a20:1590:b0:1c4:7d53:bf76 with SMTP id adf61e73a8af0-1c68d0da5c1mr317145637.38.1722449805523; Wed, 31 Jul 2024 11:16:45 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-70eeb9aa93fsm5136723b3a.190.2024.07.31.11.16.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jul 2024 11:16:45 -0700 (PDT) From: Gregor Haas To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, Gregor Haas Subject: [PATCH 5/8] lib: sbi: memregion: Make memregions keep track of raw size rather than order Date: Wed, 31 Jul 2024 11:16:26 -0700 Message-ID: <20240731181629.269898-6-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731181629.269898-1-gregorhaas1997@gmail.com> References: <20240731181629.269898-1-gregorhaas1997@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_111647_790688_E94B6161 X-CRM114-Status: GOOD ( 28.17 ) X-Spam-Score: -1.8 (-) 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: In order to accomodate isolation primitives other than PMP (such as the forthcoming SMMTT implementation), make memregions keep track of their raw size rather than prerounding the size to a power-of-t [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:429 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [gregorhaas1997(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gregorhaas1997(at)gmail.com] 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 In order to accomodate isolation primitives other than PMP (such as the forthcoming SMMTT implementation), make memregions keep track of their raw size rather than prerounding the size to a power-of-two order. Not all isolation primitives have the same stringent naturally-aligned power-of-two requirements as PMP, and so we need a layer of abstraction between memregion information as it is discovered (from device trees or otherwise) and isolation information as applied using a specific primitive. This commit lays the groundwork for such an abstraction. --- docs/domain_support.md | 41 +++++++++++++++++++++++++------------ include/sbi/sbi_domain.h | 2 +- include/sbi/sbi_memregion.h | 10 ++++----- lib/sbi/sbi_domain.c | 18 ++++++++-------- lib/sbi/sbi_hart.c | 23 +++++++++++++++------ lib/sbi/sbi_memregion.c | 30 +++++++++++++++++---------- lib/utils/fdt/fdt_domain.c | 29 ++++++++++++++++++-------- lib/utils/fdt/fdt_fixup.c | 10 ++++----- 8 files changed, 102 insertions(+), 61 deletions(-) diff --git a/docs/domain_support.md b/docs/domain_support.md index 91677d3..33bd8d6 100644 --- a/docs/domain_support.md +++ b/docs/domain_support.md @@ -24,10 +24,9 @@ Domain Memory Region A domain memory region is represented by **struct sbi_memregion** in OpenSBI and has following details: -* **order** - The size of a memory region is **2 ^ order** where **order** - must be **3 <= order <= __riscv_xlen** -* **base** - The base address of a memory region is **2 ^ order** - aligned start address +* **size** - The size of a memory region, where the maximum size is encoded + as -1UL. +* **base** - The base address of a memory region. * **flags** - The flags of a memory region represent memory type (i.e. RAM or MMIO) and allowed accesses (i.e. READ, WRITE, EXECUTE, etc.) @@ -56,10 +55,16 @@ has following details: * **system_suspend_allowed** - Is domain allowed to suspend the system? The memory regions represented by **regions** in **struct sbi_domain** have -following additional constraints to align with RISC-V PMP requirements: +following additional constraints: * A memory region to protect OpenSBI firmware from S-mode and U-mode should always be present + +When applying the specific isolation primitive to the domain, there may be +other specific constraints on memory regions. These are listed below. + +To align with RISC-V PMP requirements: + * For two overlapping memory regions, one should be sub-region of another * Two overlapping memory regions should not be of same size * Two overlapping memory regions cannot have same flags @@ -138,17 +143,26 @@ The DT properties of a domain memory region DT node are as follows: * **compatible** (Mandatory) - The compatible string of the domain memory region. This DT property should have value *"opensbi,domain,memregion"* -* **base** (Mandatory) - The base address of the domain memory region. This - DT property should have a **2 ^ order** aligned 64 bit address (i.e. two - DT cells). -* **order** (Mandatory) - The order of the domain memory region. This DT - property should have a 32 bit value (i.e. one DT cell) in the range - **3 <= order <= __riscv_xlen**. +* **base** (Mandatory) - The base address of the domain memory region. If + **order** is specified (see below), this DT property should have a + **2 ^ order** aligned 64 bit address (i.e. two DT cells). Otherwise, if + **size** is specified (see below), this DT property should have a 64 bit + address (i.e. two DT cells). * **mmio** (Optional) - A boolean flag representing whether the domain memory region is a memory-mapped I/O (MMIO) region. * **devices** (Optional) - The list of device DT node phandles for devices which fall under this domain memory region. +Additionally, **one** of the two DT properties **must** be specified: + +* **size** - The size of the domain memory region. This DT property should + have a 64 bit value (i.e. two DT cells). The maximum possible size should + be encoded as `<0xFFFFFFFF 0xFFFFFFFF>`. +* **order** - The order of the domain memory region. This DT property should + have a 32 bit value (i.e. one DT cell) in the range **3 <= order <= __riscv_xlen**. + This property is kept for compatibility purposes; new device trees should + use the **size** property instead. + ### Domain Instance Node The domain instance DT node describes set of possible HARTs, set of memory @@ -237,6 +251,7 @@ be done: opensbi-domains { compatible = "opensbi,domain,config"; + /* Region using "order" property rather than size */ tmem: tmem { compatible = "opensbi,domain,memregion"; base = <0x0 0x80100000>; @@ -246,7 +261,7 @@ be done: tuart: tuart { compatible = "opensbi,domain,memregion"; base = <0x0 0x10011000>; - order = <12>; + size = <0x0 0x1000>; mmio; devices = <&uart1>; }; @@ -254,7 +269,7 @@ be done: allmem: allmem { compatible = "opensbi,domain,memregion"; base = <0x0 0x0>; - order = <64>; + size = <0xFFFFFFFF 0xFFFFFFFF>; }; tdomain: trusted-domain { diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h index a712504..74e3ea9 100644 --- a/include/sbi/sbi_domain.h +++ b/include/sbi/sbi_domain.h @@ -86,7 +86,7 @@ extern struct sbi_domain *domidx_to_domain_table[]; /** Iterate over each memory region of a domain */ #define sbi_domain_for_each_memregion(__d, __r) \ - for ((__r) = (__d)->regions; (__r)->order; (__r)++) + for ((__r) = (__d)->regions; (__r)->size; (__r)++) /** * Check whether given HART is assigned to specified domain diff --git a/include/sbi/sbi_memregion.h b/include/sbi/sbi_memregion.h index 6e1b771..99faba7 100644 --- a/include/sbi/sbi_memregion.h +++ b/include/sbi/sbi_memregion.h @@ -15,13 +15,11 @@ enum sbi_domain_access { /** Representation of OpenSBI domain memory region */ struct sbi_memregion { /** - * Size of memory region as power of 2 - * It has to be minimum 3 and maximum __riscv_xlen + * Size of memory region. The maximum value is encoded as -1UL */ - unsigned long order; + unsigned long size; /** * Base address of memory region - * It must be 2^order aligned address */ unsigned long base; /** Flags representing memory region attributes */ @@ -149,8 +147,8 @@ struct sbi_memregion { ((reg)->base) #define memregion_end(reg) \ - ((reg)->order < __riscv_xlen) ? \ - (reg)->base + ((1UL << (reg)->order) - 1) : -1UL; + (((reg)->size == -1UL) ? -1UL : (reg)->base + (reg)->size - 1) + /** * Initialize a domain memory region based on it's physical * address and size. diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 22d5d8b..e272d81 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -98,7 +98,7 @@ ulong sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom, static int sanitize_domain(struct sbi_domain *dom) { - u32 i, rc; + int i, rc; /* Check possible HARTs */ if (!dom->possible_harts) { @@ -302,7 +302,7 @@ int sbi_domain_root_add_memregion(const struct sbi_memregion *reg) nreg = &root.regions[root_memregs_count]; sbi_memcpy(nreg, reg, sizeof(*reg)); root_memregs_count++; - root.regions[root_memregs_count].order = 0; + root.regions[root_memregs_count].size = 0; /* Sort and optimize root regions */ do { @@ -315,19 +315,17 @@ int sbi_domain_root_add_memregion(const struct sbi_memregion *reg) return rc; } - /* Merge consecutive memregions with same order and flags */ + /* Merge consecutive memregions with same flags */ reg_merged = false; sbi_domain_for_each_memregion(&root, nreg) { nreg1 = nreg + 1; - if (!nreg1->order) + if (!nreg1->size) continue; - if (!(nreg->base & (BIT(nreg->order + 1) - 1)) && - (nreg->base + BIT(nreg->order)) == nreg1->base && - nreg->order == nreg1->order && + if ((nreg->base + nreg->size) == nreg1->base && nreg->flags == nreg1->flags) { - nreg->order++; - while (nreg1->order) { + nreg->size += nreg1->size; + while (nreg1->size) { nreg2 = nreg1 + 1; sbi_memcpy(nreg1, nreg2, sizeof(*nreg1)); nreg1++; @@ -505,7 +503,7 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid) &root_memregs[root_memregs_count++]); /* Root domain memory region end */ - root_memregs[root_memregs_count].order = 0; + root_memregs[root_memregs_count].size = 0; /* Root domain boot HART id is same as coldboot HART id */ root.boot_hartid = cold_hartid; diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 4dd1a25..e82045c 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -346,6 +346,11 @@ static unsigned int sbi_hart_get_smepmp_flags(struct sbi_scratch *scratch, return pmp_flags; } +static inline bool pmp_is_power_of_two(unsigned long order, unsigned long size) +{ + return order == __riscv_xlen ? true : BIT(order) == size; +} + static void sbi_hart_smepmp_set(struct sbi_scratch *scratch, struct sbi_domain *dom, struct sbi_memregion *reg, @@ -355,14 +360,16 @@ static void sbi_hart_smepmp_set(struct sbi_scratch *scratch, unsigned long pmp_addr_max) { unsigned long pmp_addr = reg->base >> PMP_SHIFT; + unsigned long order = log2roundup(reg->size); - if (pmp_log2gran <= reg->order && pmp_addr < pmp_addr_max) { - pmp_set(pmp_idx, pmp_flags, reg->base, reg->order); + if (pmp_is_power_of_two(order, reg->size) && + pmp_log2gran <= order && pmp_addr < pmp_addr_max) { + pmp_set(pmp_idx, pmp_flags, reg->base, order); } else { sbi_printf("Can not configure pmp for domain %s because" " memory region address 0x%lx or size 0x%lx " "is not in range.\n", dom->name, reg->base, - reg->order); + reg->size); } } @@ -451,6 +458,7 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch, unsigned int pmp_idx = 0; unsigned int pmp_flags; unsigned long pmp_addr; + unsigned long order; sbi_domain_for_each_memregion(dom, reg) { if (pmp_count <= pmp_idx) @@ -473,13 +481,16 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch, pmp_flags |= PMP_X; pmp_addr = reg->base >> PMP_SHIFT; - if (pmp_log2gran <= reg->order && pmp_addr < pmp_addr_max) { - pmp_set(pmp_idx++, pmp_flags, reg->base, reg->order); + order = log2roundup(reg->size); + + if (pmp_is_power_of_two(order, reg->size) && + pmp_log2gran <= order && pmp_addr < pmp_addr_max) { + pmp_set(pmp_idx++, pmp_flags, reg->base, order); } else { sbi_printf("Can not configure pmp for domain %s because" " memory region address 0x%lx or size 0x%lx " "is not in range.\n", dom->name, reg->base, - reg->order); + reg->size); } } diff --git a/lib/sbi/sbi_memregion.c b/lib/sbi/sbi_memregion.c index 8978793..56ee649 100644 --- a/lib/sbi/sbi_memregion.c +++ b/lib/sbi/sbi_memregion.c @@ -28,7 +28,7 @@ void sbi_memregion_init(unsigned long addr, if (reg) { reg->base = base; - reg->order = order; + reg->size = (order == __riscv_xlen) ? -1UL : BIT(order); reg->flags = flags; } } @@ -64,13 +64,14 @@ static bool is_region_compatible(const struct sbi_memregion *regA, /* Check if region complies with constraints */ static bool is_region_valid(const struct sbi_memregion *reg) { - if (reg->order < 3 || __riscv_xlen < reg->order) + unsigned int order = log2roundup(reg->size); + if (order < 3 || __riscv_xlen < order) return false; - if (reg->order == __riscv_xlen && reg->base != 0) + if (order == __riscv_xlen && reg->base != 0) return false; - if (reg->order < __riscv_xlen && (reg->base & (BIT(reg->order) - 1))) + if (order < __riscv_xlen && (reg->base & (BIT(order) - 1))) return false; return true; @@ -80,10 +81,17 @@ static bool is_region_valid(const struct sbi_memregion *reg) static bool is_region_before(const struct sbi_memregion *regA, const struct sbi_memregion *regB) { - if (regA->order < regB->order) + // Sentinel region always goes last + if (!regA->size) + return false; + + if (!regB->size) + return true; + + if (regA->size < regB->size) return true; - if ((regA->order == regB->order) && + if ((regA->size == regB->size) && (regA->base < regB->base)) return true; @@ -121,8 +129,8 @@ int sbi_memregion_sanitize(struct sbi_domain *dom) sbi_domain_for_each_memregion(dom, reg) { if (!is_region_valid(reg)) { sbi_printf("%s: %s has invalid region base=0x%lx " - "order=%lu flags=0x%lx\n", __func__, - dom->name, reg->base, reg->order, + "size=0x%lx flags=0x%lx\n", __func__, + dom->name, reg->base, reg->size, reg->flags); return SBI_EINVAL; } @@ -260,7 +268,7 @@ static const struct sbi_memregion *find_next_subset_region( continue; if (!ret || (sreg->base < ret->base) || - ((sreg->base == ret->base) && (sreg->order < ret->order))) + ((sreg->base == ret->base) && (sreg->size < ret->size))) ret = sreg; } @@ -289,8 +297,8 @@ bool sbi_domain_check_addr_range(const struct sbi_domain *dom, sreg = find_next_subset_region(dom, reg, addr); if (sreg) addr = sreg->base; - else if (reg->order < __riscv_xlen) - addr = reg->base + (1UL << reg->order); + else if (reg->size != -1UL) + addr = reg->base + reg->size; else break; } diff --git a/lib/utils/fdt/fdt_domain.c b/lib/utils/fdt/fdt_domain.c index 779acec..51d9e9d 100644 --- a/lib/utils/fdt/fdt_domain.c +++ b/lib/utils/fdt/fdt_domain.c @@ -233,7 +233,6 @@ static int __fdt_parse_region(void *fdt, int domain_offset, void *opaque) { int len; - u32 val32; u64 val64; const u32 *val; struct parse_region_data *preg = opaque; @@ -264,14 +263,26 @@ static int __fdt_parse_region(void *fdt, int domain_offset, val64 = (val64 << 32) | fdt32_to_cpu(val[1]); region->base = val64; - /* Read "order" DT property */ - val = fdt_getprop(fdt, region_offset, "order", &len); - if (!val || len != 4) - return SBI_EINVAL; - val32 = fdt32_to_cpu(*val); - if (val32 < 3 || __riscv_xlen < val32) - return SBI_EINVAL; - region->order = val32; + /* Read "size" DT property */ + val = fdt_getprop(fdt, region_offset, "size", &len); + if (!val || len != 8) { + // Check for older "order" property + val = fdt_getprop(fdt, region_offset, "order", &len); + if (!val || len != 4) { + return SBI_EINVAL; + } + + val64 = fdt32_to_cpu(*val); + if (val64 < 3 || __riscv_xlen < val64) + return SBI_EINVAL; + + val64 = BIT(val64); + } else { + val64 = ((uint64_t) fdt32_to_cpu(val[0])) << 32; + val64 |= fdt32_to_cpu(val[1]); + } + + region->size = val64; /* Read "mmio" DT property */ region->flags = region_access & SBI_MEMREGION_ACCESS_MASK; diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c index fd45763..20819f9 100644 --- a/lib/utils/fdt/fdt_fixup.c +++ b/lib/utils/fdt/fdt_fixup.c @@ -285,7 +285,7 @@ int fdt_reserved_memory_fixup(void *fdt) struct sbi_memregion *reg; struct sbi_domain *dom = sbi_domain_thishart_ptr(); unsigned long filtered_base[PMP_COUNT] = { 0 }; - unsigned char filtered_order[PMP_COUNT] = { 0 }; + unsigned long filtered_size[PMP_COUNT] = { 0 }; unsigned long addr, size; int err, parent, i, j; int na = fdt_address_cells(fdt, 0); @@ -362,23 +362,23 @@ int fdt_reserved_memory_fixup(void *fdt) addr = reg->base; for (j = 0; j < i; j++) { if (addr == filtered_base[j] - && filtered_order[j] < reg->order) { + && filtered_size[j] < reg->size) { overlap = true; - filtered_order[j] = reg->order; + filtered_size[j] = reg->size; break; } } if (!overlap) { filtered_base[i] = reg->base; - filtered_order[i] = reg->order; + filtered_size[i] = reg->size; i++; } } for (j = 0; j < i; j++) { addr = filtered_base[j]; - size = 1UL << filtered_order[j]; + size = filtered_size[j]; fdt_resv_memory_update_node(fdt, addr, size, j, parent); } From patchwork Wed Jul 31 18:16:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Haas X-Patchwork-Id: 1967254 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=1g490cj4; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Nw2uAKxV; 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=opensbi-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 4WZ0fz4YYZz20Fw for ; Thu, 1 Aug 2024 04:16:59 +1000 (AEST) 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:References:In-Reply-To: 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: List-Owner; bh=UEH8xqJIRKbCgAbMcgdw75OBu+BKuH90TMqtJmVH4qo=; b=1g490cj49hN6aN zoEUANCwpE69aCYEkxdPPI2ed0eJAGsGykmIF8bHLotkaDfCca1WoWBm4jDK0Rru5/IZoDnvF9BMO /2dqGYI8iXFm9qa0Z/i0G6psFcHdsGaig/kADFoCeuEeLRfjHuQBagjL+IQpNzl0Z18D70lOTqAfP l8xM4xbfGG5Tzy1QRL/G5h+LvQTaQN68Iz8z003FsPAtSqJTeU6zb8vsnUCFtSveq9S6ApEJMEhxd QVb68CDccXftqI44sh8EzSEJQ34s1psc3GoO34rjIpWTFIFJTIUf7DjV01QXdgOPdr4h34APoGYC4 ztTrzm3S6sha6pUQ/XYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsZ-000000026gx-128m; Wed, 31 Jul 2024 18:16:51 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsV-000000026e7-0e1X for opensbi@lists.infradead.org; Wed, 31 Jul 2024 18:16:49 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1fc6ee64512so43900695ad.0 for ; Wed, 31 Jul 2024 11:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722449806; x=1723054606; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NnyRMflh+Yozxj6FgzmPpMQzx1DAJug2qMpUgexFt94=; b=Nw2uAKxVFf7gws0t793UL7vB+qjLYYs+H2Nlp0O89TWECtpNQ+v08A13L6VglnJmkJ MOU533jshW0NVzRCFrxkGig6hIPo3Y9OiY2grZn+P3BlcUjxmM+YB1FBSDu+aJKqTK64 cdAZITkKfmBMS7FSMLM+nOFsihkVMVDLeVSpOGeevsspe+Eqh25cAkKzBNcZgM8YpaB9 R9w0/QOyCunMHqHw2vslYN0xhJLUROVUihrRVEkVaE5vbF3aJUVfdStHc3l5rI8xb9Mt mdwuTuPxh5TOs3rTudgIN4k9AmSZ8OaY3jRAELm+i3dOXAhL3g9lxjwQla8X/+37JJuZ KlWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722449806; x=1723054606; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NnyRMflh+Yozxj6FgzmPpMQzx1DAJug2qMpUgexFt94=; b=XwI7ltkTwPq7en+AEHWx7YHZWmmhiBjmpRlKFbdKE3GjLnzF7QLedCEdaDECFnMUQW q0GvMGumrrjJioPGfvl8mPXD9Gb8BR9JC2I8/JU08vYiyTgVWt4mSPWVfXGfXkjisIMR Ivs+AtXKv3e2Do9KhFbz8PkZ3pVY73u4xEo1a+BQMrXIJQTzr8KBzcgEXwTTdCAOSoTY llng/BWsQ760uwAgRIqVjkhkSkbp2npBUfp3KpHqEbAYCvavXrujD8vl2HWMfpIs4LsW +XDB66UgAv+ZaVCAH/KmavTLI8tPgk4ZA8QuBKe5kAT1LkBHtcmMeKifm1FgxhInS2OM f3+Q== X-Gm-Message-State: AOJu0YykyZhgE8EdScKNCQqD3xuirgVZdVSxuHaIdTrhWB+whEdq+WXX HOfditfOuvzTLVl+vic1rbu/yf1fYlYF+cmvh6N0W3w3KVCd0RaH6P9ws+JW X-Google-Smtp-Source: AGHT+IF8wnEBo4IG11UfDAxNvJt5aHgyAQDx5ke+/5+RjRz9wFiHIBI3Qc6G5bgd23l+MhpL/dRTZw== X-Received: by 2002:a17:902:e748:b0:1fb:4194:5b78 with SMTP id d9443c01a7336-1ff4d2339eamr1400365ad.47.1722449806307; Wed, 31 Jul 2024 11:16:46 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fed7f614c9sm122972855ad.224.2024.07.31.11.16.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jul 2024 11:16:46 -0700 (PDT) From: Gregor Haas To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, Gregor Haas Subject: [PATCH 6/8] lib: sbi: Do a merging pass on memregions whenever a domain is sanitized Date: Wed, 31 Jul 2024 11:16:27 -0700 Message-ID: <20240731181629.269898-7-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731181629.269898-1-gregorhaas1997@gmail.com> References: <20240731181629.269898-1-gregorhaas1997@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_111647_217553_DB81280D X-CRM114-Status: GOOD ( 21.36 ) X-Spam-Score: -1.8 (-) 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: Currently, memregions are only merged into each other (if consecutive) when adding a region to the root domain. This is also useful functionality for other secondary domains, so move this functionalit [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:630 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [gregorhaas1997(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gregorhaas1997(at)gmail.com] 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 Currently, memregions are only merged into each other (if consecutive) when adding a region to the root domain. This is also useful functionality for other secondary domains, so move this functionality into the memregion sanitization path. We also now manually need to recount root_memregs_count after calling sbi_memregion_sanitize(), since this was done in the merging pass before. --- lib/sbi/sbi_domain.c | 54 ++++++++------------- lib/sbi/sbi_memregion.c | 105 ++++++++++++++++++++++++++++------------ 2 files changed, 94 insertions(+), 65 deletions(-) diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index e272d81..6b7bcc5 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -99,6 +99,7 @@ ulong sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom, static int sanitize_domain(struct sbi_domain *dom) { int i, rc; + struct sbi_memregion *reg; /* Check possible HARTs */ if (!dom->possible_harts) { @@ -122,6 +123,15 @@ static int sanitize_domain(struct sbi_domain *dom) return rc; } + /* Recount root memregions since the above call may have consolidated + * or otherwise pruned memregions away */ + if (dom == &root) { + root_memregs_count = 0; + sbi_domain_for_each_memregion(dom, reg) { + root_memregs_count++; + } + } + /* * We don't need to check boot HART id of domain because if boot * HART id is not possible/assigned to this domain then it won't @@ -290,8 +300,7 @@ int sbi_domain_register(struct sbi_domain *dom, int sbi_domain_root_add_memregion(const struct sbi_memregion *reg) { int rc; - bool reg_merged; - struct sbi_memregion *nreg, *nreg1, *nreg2; + struct sbi_memregion *nreg; /* Sanity checks */ if (!reg || domain_finalized || !root.regions || @@ -302,39 +311,16 @@ int sbi_domain_root_add_memregion(const struct sbi_memregion *reg) nreg = &root.regions[root_memregs_count]; sbi_memcpy(nreg, reg, sizeof(*reg)); root_memregs_count++; - root.regions[root_memregs_count].size = 0; - - /* Sort and optimize root regions */ - do { - /* Sanitize the root domain so that memregions are sorted */ - rc = sanitize_domain(&root); - if (rc) { - sbi_printf("%s: sanity checks failed for" - " %s (error %d)\n", __func__, - root.name, rc); - return rc; - } + root.regions[root_memregs_count].size = 0; - /* Merge consecutive memregions with same flags */ - reg_merged = false; - sbi_domain_for_each_memregion(&root, nreg) { - nreg1 = nreg + 1; - if (!nreg1->size) - continue; - - if ((nreg->base + nreg->size) == nreg1->base && - nreg->flags == nreg1->flags) { - nreg->size += nreg1->size; - while (nreg1->size) { - nreg2 = nreg1 + 1; - sbi_memcpy(nreg1, nreg2, sizeof(*nreg1)); - nreg1++; - } - reg_merged = true; - root_memregs_count--; - } - } - } while (reg_merged); + /* Sanitize the root domain so that memregions are sorted */ + rc = sanitize_domain(&root); + if (rc) { + sbi_printf("%s: sanity checks failed for" + " %s (error %d)\n", __func__, + root.name, rc); + return rc; + } return 0; } diff --git a/lib/sbi/sbi_memregion.c b/lib/sbi/sbi_memregion.c index 56ee649..ee7403b 100644 --- a/lib/sbi/sbi_memregion.c +++ b/lib/sbi/sbi_memregion.c @@ -114,40 +114,11 @@ static void clear_region(struct sbi_memregion * reg) sbi_memset(reg, 0x0, sizeof(*reg)); } -int sbi_memregion_sanitize(struct sbi_domain *dom) +static void sort_memregions(struct sbi_domain *dom, int count) { - int i, j, count; - bool is_covered; + int i, j; struct sbi_memregion *reg, *reg1; - /* Check memory regions */ - if (!dom->regions) { - sbi_printf("%s: %s regions is NULL\n", - __func__, dom->name); - return SBI_EINVAL; - } - sbi_domain_for_each_memregion(dom, reg) { - if (!is_region_valid(reg)) { - sbi_printf("%s: %s has invalid region base=0x%lx " - "size=0x%lx flags=0x%lx\n", __func__, - dom->name, reg->base, reg->size, - reg->flags); - return SBI_EINVAL; - } - } - - /* Count memory regions */ - count = 0; - sbi_domain_for_each_memregion(dom, reg) - count++; - - /* Check presence of firmware regions */ - if (!dom->fw_region_inited) { - sbi_printf("%s: %s does not have firmware region\n", - __func__, dom->name); - return SBI_EINVAL; - } - /* Sort the memory regions */ for (i = 0; i < (count - 1); i++) { reg = &dom->regions[i]; @@ -160,6 +131,13 @@ int sbi_memregion_sanitize(struct sbi_domain *dom) swap_region(reg, reg1); } } +} + +static void overlap_memregions(struct sbi_domain *dom, int count) +{ + int i = 0, j; + bool is_covered; + struct sbi_memregion *reg, *reg1; /* Remove covered regions */ while(i < (count - 1)) { @@ -185,6 +163,71 @@ int sbi_memregion_sanitize(struct sbi_domain *dom) } else i++; } +} + +static void merge_memregions(struct sbi_domain *dom, int *nmerged) +{ + struct sbi_memregion *reg, *reg1, *reg2; + + /* Merge consecutive memregions with same flags */ + *nmerged = 0; + sbi_domain_for_each_memregion(dom, reg) { + reg1 = reg + 1; + if (!reg1->size) + continue; + + if ((reg->base + reg->size) == reg1->base && + reg->flags == reg1->flags) { + reg->size += reg1->size; + while (reg1->size) { + reg2 = reg1 + 1; + sbi_memcpy(reg1, reg2, sizeof(*reg1)); + reg1++; + } + (*nmerged)++; + } + } +} + +int sbi_memregion_sanitize(struct sbi_domain *dom) +{ + int count, nmerged; + struct sbi_memregion *reg; + + /* Check memory regions */ + if (!dom->regions) { + sbi_printf("%s: %s regions is NULL\n", + __func__, dom->name); + return SBI_EINVAL; + } + + sbi_domain_for_each_memregion(dom, reg) { + if (!is_region_valid(reg)) { + sbi_printf("%s: %s has invalid region base=0x%lx " + "size=0x%lx flags=0x%lx\n", __func__, + dom->name, reg->base, reg->size, + reg->flags); + return SBI_EINVAL; + } + } + + /* Count memory regions */ + count = 0; + sbi_domain_for_each_memregion(dom, reg) + count++; + + /* Check presence of firmware regions */ + if (!dom->fw_region_inited) { + sbi_printf("%s: %s does not have firmware region\n", + __func__, dom->name); + return SBI_EINVAL; + } + + do { + sort_memregions(dom, count); + overlap_memregions(dom, count); + merge_memregions(dom, &nmerged); + } while (nmerged); return SBI_OK; } From patchwork Wed Jul 31 18:16:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Haas X-Patchwork-Id: 1967261 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=a8LkJgf1; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UYzGflj3; 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=opensbi-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 4WZ0g24x4fz20Fw for ; Thu, 1 Aug 2024 04:17:02 +1000 (AEST) 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:References:In-Reply-To: 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: List-Owner; bh=Mo08IXoMons6/7ubfrlAd7RyV7P3i43DDHeeEpoYCpI=; b=a8LkJgf1ZhKpEM dP5EQ1wQhsC6GWM8sTzCJ0tvW6NOAThrSWXAvF3DPfwVHxLedwux/4PP/A5zVZuDdnEkcEulnz/zn V+xFT3mq/RkywG8fIlO+jMDx/xUtwftGEV5sesEvCjwREBqRYo+yar+d4cGDbGzid9qBLBWI1HUzt w3wgIMR1DeRRk5/tx3KWVBva9GdhjbnsGz6FdAieuevAcV7zxg1vm/dTAjuvQdrAqE9Ohg+ZGNmOE Nm62j5o74/qszEYyl0ULADnxWDfLsw87g4CtCy2/sm5+hYzVmna+8sDpob3BObqQd/ibVkZwhR0tx cfUse6IWAfDraWyaI3gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsc-000000026kD-3IcE; Wed, 31 Jul 2024 18:16:54 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsW-000000026eq-2iBw for opensbi@lists.infradead.org; Wed, 31 Jul 2024 18:16:51 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2cfcbdfa572so1609623a91.3 for ; Wed, 31 Jul 2024 11:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722449807; x=1723054607; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2EPi8n/lhFFOi+wlKVJcZnXb3+BsZiy99d7VwvySv5k=; b=UYzGflj328+VZyBUtoEbrHccwxN/k9Qv33fW9KFGMm7zXveWMq81gNLJwu5ev7Dtln iDblpv5xZtwc184nYgKboigroR4TwM66PZd/Um0QwOnfwZVQEBvYZrDRF4bFjBhVJT0Y zORMU+KBxFeF4DgVpqqL6lKkxrlhZuGH/kqx8rGpNOhWiYT10zyj0DiqLifEg42zj0Yi aWpJQT9Hj8DcraDsIQn9ai8LeNju8hVMFBO2V+v26xbtcaLFdb8QvqyxPMjj5nVSEGGz GSVqNByKL6wauy49m5RSfpBJfps960lrEpsOQ1BUJNDvJL6di5H6oqdE2eSgb3ahpOMk X5Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722449807; x=1723054607; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2EPi8n/lhFFOi+wlKVJcZnXb3+BsZiy99d7VwvySv5k=; b=Xuwvv7UGoTUiSQtvk7zGmKACg1sGG1p5HGTqdKZIIVRnFg2Nnqu2rcJMWfY/eOmrWb u6fDMpimH0eKc8Aj9WxJ9PomCi/9GsS5ThFAkux07+PRyDGabICAtHFANMMuz+z7sv6x RJJyFLxH/9BhS2dRNHyyzYWiF8WoR+gTuiS9HcuXLrAWGvTwb20oO/zci2acepN1brZj 5lzYsq7g447KxJwSJv06QfhQucXBWI3m9Xh0qD3j0w+bK2fBZAFmJ2hVXtukLz7T6iO7 jcGVOydquKBq+/fBvEml6IbfGhhFNALORgG1SUyihJNvv2Zvf175dr6o96tgRGb05tZH m/Mw== X-Gm-Message-State: AOJu0Yzca14Od56trPLaA3nLTStrMzy/kKrKDu0qhtDY/l9ymItCCEle LOzxWqEwYC2Xz6+Q7+w/SmlwQsVFMwWlg7G3pxhf2KusXgyoGYiqxumW+sjO X-Google-Smtp-Source: AGHT+IF13Rr+PWIJEP+VX5S3aqra1F/mHUpnzN0W+iL5TKCiJqRJHF87yEg96popccEvd7qVXJc98w== X-Received: by 2002:a17:90a:df0b:b0:2c9:635b:7271 with SMTP id 98e67ed59e1d1-2cfe78c66c6mr153743a91.21.1722449807178; Wed, 31 Jul 2024 11:16:47 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2cfdc44cc0dsm1696250a91.14.2024.07.31.11.16.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jul 2024 11:16:46 -0700 (PDT) From: Gregor Haas To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, Gregor Haas Subject: [PATCH 7/8] lib: sbi: Remove PMP assumptions from memregion Date: Wed, 31 Jul 2024 11:16:28 -0700 Message-ID: <20240731181629.269898-8-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731181629.269898-1-gregorhaas1997@gmail.com> References: <20240731181629.269898-1-gregorhaas1997@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_111648_794506_F9BC4577 X-CRM114-Status: GOOD ( 25.09 ) X-Spam-Score: -1.8 (-) 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: Move the application of PMP assumptions (naturally-aligned power-of-two) from memregion initialization time to isolation primitive application time. We introduce a new parameter to sbi_memregion_sanit [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:102d listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [gregorhaas1997(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gregorhaas1997(at)gmail.com] 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 Move the application of PMP assumptions (naturally-aligned power-of-two) from memregion initialization time to isolation primitive application time. We introduce a new parameter to sbi_memregion_sanitize(), indicating for which isolation primitive to sanitize the domain's memregions. During memregion discoverty time, this parameter is set to SBI_ISOLATION_UNKNOWN which simply keeps the memregions as-is. Then, later, when applying an isolation primitive (currently either PMP or SMEPMP), we call sbi_memregion_sanitize() again with SBI_ISOLATION_{PMP,SMEPMP} in order to finalize the memregions for application. --- include/sbi/sbi_domain.h | 2 + include/sbi/sbi_hart.h | 2 +- include/sbi/sbi_memregion.h | 19 ++++-- lib/sbi/sbi_domain.c | 27 ++------- lib/sbi/sbi_domain_context.c | 2 +- lib/sbi/sbi_hart.c | 16 ++++- lib/sbi/sbi_init.c | 6 +- lib/sbi/sbi_memregion.c | 109 ++++++++++++++++++++++++++++------- 8 files changed, 128 insertions(+), 55 deletions(-) diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h index 74e3ea9..8fbd081 100644 --- a/include/sbi/sbi_domain.h +++ b/include/sbi/sbi_domain.h @@ -44,6 +44,8 @@ struct sbi_domain { struct sbi_context *hartindex_to_context_table[SBI_HARTMASK_MAX_BITS]; /** Array of memory regions terminated by a region with order zero */ struct sbi_memregion *regions; + /** Current isolation mode */ + enum sbi_isolation_method isol_mode; /** HART id of the HART booting this domain */ u32 boot_hartid; /** Arg1 (or 'a1' register) of next booting stage for this domain */ diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 81ec061..81b08ab 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -123,7 +123,7 @@ unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch); unsigned int sbi_hart_pmp_log2gran(struct sbi_scratch *scratch); unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch); unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch); -int sbi_hart_pmp_configure(struct sbi_scratch *scratch); +int sbi_hart_isolation_configure(struct sbi_scratch *scratch); int sbi_hart_map_saddr(unsigned long base, unsigned long size); int sbi_hart_unmap_saddr(void); int sbi_hart_priv_version(struct sbi_scratch *scratch); diff --git a/include/sbi/sbi_memregion.h b/include/sbi/sbi_memregion.h index 99faba7..4f62a9a 100644 --- a/include/sbi/sbi_memregion.h +++ b/include/sbi/sbi_memregion.h @@ -2,6 +2,13 @@ #ifndef __SBI_MEMREGION_H__ #define __SBI_MEMREGION_H__ +/** Domain isolation types */ +enum sbi_isolation_method { + SBI_ISOLATION_UNKNOWN = 0, + SBI_ISOLATION_PMP, + SBI_ISOLATION_SMEPMP, +}; + #include /** Domain access types */ @@ -164,13 +171,15 @@ void sbi_memregion_init(unsigned long addr, struct sbi_memregion *reg); /** + * Sanitize a domain's memory regions based on the selected isolation + * type. This function should encode any constraints on region + * information, such as address alignment or sizing requirements. * - * Traverse all of a domain's memory regions and sanitize - * them, while making sure they are formatted properly - * - * @param dom the domain for which to sanitize regions + * @param dom the domain to sanitize + * @param type the isolation type to apply */ -int sbi_memregion_sanitize(struct sbi_domain *dom); +int sbi_memregion_sanitize(struct sbi_domain *dom, + enum sbi_isolation_method type); /** * Check whether we can access specified address for given mode and diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 6b7bcc5..638ffa9 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -116,7 +116,7 @@ static int sanitize_domain(struct sbi_domain *dom) } } - rc = sbi_memregion_sanitize(dom); + rc = sbi_memregion_sanitize(dom, SBI_ISOLATION_UNKNOWN); if (rc) { sbi_printf("%s: %s has unsanitizable regions\n", __func__, dom->name); @@ -328,28 +328,9 @@ int sbi_domain_root_add_memregion(const struct sbi_memregion *reg) int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size, unsigned long align, unsigned long region_flags) { - int rc; - unsigned long pos, end, rsize; struct sbi_memregion reg; - - pos = addr; - end = addr + size; - while (pos < end) { - rsize = pos & (align - 1); - if (rsize) - rsize = 1UL << sbi_ffs(pos); - else - rsize = ((end - pos) < align) ? - (end - pos) : align; - - sbi_memregion_init(pos, rsize, region_flags, ®); - rc = sbi_domain_root_add_memregion(®); - if (rc) - return rc; - pos += rsize; - } - - return 0; + sbi_memregion_init(addr, size, region_flags, ®); + return sbi_domain_root_add_memregion(®); } int sbi_domain_finalize(struct sbi_scratch *scratch, u32 cold_hartid) @@ -372,7 +353,7 @@ int sbi_domain_finalize(struct sbi_scratch *scratch, u32 cold_hartid) /* Domain boot HART index */ dhart = sbi_hartid_to_hartindex(dom->boot_hartid); - /* Ignore of boot HART is off limits */ + /* Ignore if boot HART is off limits */ if (!sbi_hartindex_valid(dhart)) continue; diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c index 49a2f76..750f016 100755 --- a/lib/sbi/sbi_domain_context.c +++ b/lib/sbi/sbi_domain_context.c @@ -48,7 +48,7 @@ static void switch_to_next_domain_context(struct sbi_context *ctx, for (int i = 0; i < pmp_count; i++) { pmp_disable(i); } - sbi_hart_pmp_configure(scratch); + sbi_hart_isolation_configure(scratch); /* Save current CSR context and restore target domain's CSR context */ ctx->sstatus = csr_swap(CSR_SSTATUS, dom_ctx->sstatus); diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index e82045c..df7ee98 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -378,10 +378,16 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch, unsigned int pmp_log2gran, unsigned long pmp_addr_max) { + int rc; struct sbi_memregion *reg; struct sbi_domain *dom = sbi_domain_thishart_ptr(); unsigned int pmp_idx, pmp_flags; + rc = sbi_memregion_sanitize(dom, SBI_ISOLATION_SMEPMP); + if (rc < 0) { + return rc; + } + /* * Set the RLB so that, we can write to PMP entries without * enforcement even if some entries are locked. @@ -453,6 +459,7 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch, unsigned int pmp_log2gran, unsigned long pmp_addr_max) { + int rc; struct sbi_memregion *reg; struct sbi_domain *dom = sbi_domain_thishart_ptr(); unsigned int pmp_idx = 0; @@ -460,6 +467,11 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch, unsigned long pmp_addr; unsigned long order; + rc = sbi_memregion_sanitize(dom, SBI_ISOLATION_PMP); + if (rc < 0) { + return rc; + } + sbi_domain_for_each_memregion(dom, reg) { if (pmp_count <= pmp_idx) break; @@ -540,7 +552,7 @@ int sbi_hart_unmap_saddr(void) return pmp_disable(SBI_SMEPMP_RESV_ENTRY); } -int sbi_hart_pmp_configure(struct sbi_scratch *scratch) +int sbi_hart_isolation_configure(struct sbi_scratch *scratch) { int rc; unsigned int pmp_bits, pmp_log2gran; @@ -564,7 +576,7 @@ int sbi_hart_pmp_configure(struct sbi_scratch *scratch) /* * As per section 3.7.2 of privileged specification v1.12, * virtual address translations can be speculatively performed - * (even before actual access). These, along with PMP traslations, + * (even before actual access). These, along with PMP translations, * can be cached. This can pose a problem with CPU hotplug * and non-retentive suspend scenario because PMP states are * not preserved. diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index d80efe9..34970b5 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -359,7 +359,7 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) * Configure PMP at last because if SMEPMP is detected, * M-mode access to the S/U space will be rescinded. */ - rc = sbi_hart_pmp_configure(scratch); + rc = sbi_hart_isolation_configure(scratch); if (rc) { sbi_printf("%s: PMP configure failed (error %d)\n", __func__, rc); @@ -438,7 +438,7 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch, * Configure PMP at last because if SMEPMP is detected, * M-mode access to the S/U space will be rescinded. */ - rc = sbi_hart_pmp_configure(scratch); + rc = sbi_hart_isolation_configure(scratch); if (rc) sbi_hart_hang(); @@ -459,7 +459,7 @@ static void __noreturn init_warm_resume(struct sbi_scratch *scratch, if (rc) sbi_hart_hang(); - rc = sbi_hart_pmp_configure(scratch); + rc = sbi_hart_isolation_configure(scratch); if (rc) sbi_hart_hang(); diff --git a/lib/sbi/sbi_memregion.c b/lib/sbi/sbi_memregion.c index ee7403b..3783a0a 100644 --- a/lib/sbi/sbi_memregion.c +++ b/lib/sbi/sbi_memregion.c @@ -4,13 +4,10 @@ #include #include -void sbi_memregion_init(unsigned long addr, - unsigned long size, - unsigned long flags, - struct sbi_memregion *reg) +static void memregion_sanitize_pmp(struct sbi_memregion *reg) { unsigned long base = 0, order; - + unsigned long addr = reg->base, size = reg->size; for (order = log2roundup(size) ; order <= __riscv_xlen; order++) { if (order < __riscv_xlen) { base = addr & ~((1UL << order) - 1UL); @@ -23,12 +20,20 @@ void sbi_memregion_init(unsigned long addr, base = 0; break; } - } + reg->base = base; + reg->size = (order == __riscv_xlen) ? -1UL : BIT(order); +} + +void sbi_memregion_init(unsigned long addr, + unsigned long size, + unsigned long flags, + struct sbi_memregion *reg) +{ if (reg) { - reg->base = base; - reg->size = (order == __riscv_xlen) ? -1UL : BIT(order); + reg->base = addr; + reg->size = size; reg->flags = flags; } } @@ -61,8 +66,7 @@ static bool is_region_compatible(const struct sbi_memregion *regA, return false; } -/* Check if region complies with constraints */ -static bool is_region_valid(const struct sbi_memregion *reg) +static bool is_region_valid_pmp(const struct sbi_memregion *reg) { unsigned int order = log2roundup(reg->size); if (order < 3 || __riscv_xlen < order) @@ -77,6 +81,25 @@ static bool is_region_valid(const struct sbi_memregion *reg) return true; } +/* Check if region complies with constraints */ +static bool is_region_valid(const struct sbi_memregion *reg, + enum sbi_isolation_method type) +{ + switch(type) { + case SBI_ISOLATION_UNKNOWN: + break; + + case SBI_ISOLATION_PMP: + case SBI_ISOLATION_SMEPMP: + return is_region_valid_pmp(reg); + + default: + return false; + } + + return true; +} + /** Check if regionA should be placed before regionB */ static bool is_region_before(const struct sbi_memregion *regA, const struct sbi_memregion *regB) @@ -189,7 +212,40 @@ static void merge_memregions(struct sbi_domain *dom, int *nmerged) } } -int sbi_memregion_sanitize(struct sbi_domain *dom) +static int memregion_sanitize(struct sbi_domain *dom, + struct sbi_memregion *reg, + enum sbi_isolation_method type) +{ + if (!reg) { + return SBI_EINVAL; + } + + switch (type) { + case SBI_ISOLATION_UNKNOWN: + break; + + case SBI_ISOLATION_PMP: + case SBI_ISOLATION_SMEPMP: + memregion_sanitize_pmp(reg); + break; + + default: + return SBI_EINVAL; + } + + if (!is_region_valid(reg, type)) { + sbi_printf("%s: %s has invalid region base=0x%lx " + "size=0x%lx flags=0x%lx\n", __func__, + dom->name, reg->base, reg->size, + reg->flags); + return SBI_EINVAL; + } + + return SBI_OK; +} + +int sbi_memregion_sanitize(struct sbi_domain *dom, + enum sbi_isolation_method type) { int count, nmerged; struct sbi_memregion *reg; @@ -201,20 +257,23 @@ int sbi_memregion_sanitize(struct sbi_domain *dom) return SBI_EINVAL; } - sbi_domain_for_each_memregion(dom, reg) { - if (!is_region_valid(reg)) { - sbi_printf("%s: %s has invalid region base=0x%lx " - "size=0x%lx flags=0x%lx\n", __func__, - dom->name, reg->base, reg->size, - reg->flags); - return SBI_EINVAL; - } + /* Make sure we're not refinalizing */ + if (type != SBI_ISOLATION_UNKNOWN && + dom->isol_mode != SBI_ISOLATION_UNKNOWN && + type != dom->isol_mode) { + sbi_printf("%s: %s attempting to resanitize memregions\n", + __func__, dom->name); + return SBI_EINVAL; } /* Count memory regions */ count = 0; - sbi_domain_for_each_memregion(dom, reg) + sbi_domain_for_each_memregion(dom, reg) { count++; + if (memregion_sanitize(dom, reg, type) < 0) { + return SBI_EINVAL; + } + } /* Check presence of firmware regions */ if (!dom->fw_region_inited) { @@ -229,6 +288,16 @@ int sbi_memregion_sanitize(struct sbi_domain *dom) merge_memregions(dom, &nmerged); } while (nmerged); + sbi_domain_for_each_memregion(dom, reg) { + if (!is_region_valid(reg, type)) { + sbi_printf("%s: %s has invalid region base=0x%lx " + "size=0x%lx flags=0x%lx\n", __func__, + dom->name, reg->base, reg->size, + reg->flags); + return SBI_EINVAL; + } + } + return SBI_OK; } From patchwork Wed Jul 31 18:16:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Haas X-Patchwork-Id: 1967259 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=Y2A3X327; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OrAorYQ0; 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=opensbi-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 4WZ0g10lLCz20Mv for ; Thu, 1 Aug 2024 04:17:01 +1000 (AEST) 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:References:In-Reply-To: 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: List-Owner; bh=5JHZShUn5BmvEnBKH3KG52ekCuxbD0HGuTbi2yY3bE0=; b=Y2A3X327EGDDda aFEIZNL3E+utmEL2YZklGA667+xazKzBaLZ7fBCQ/ZZNKdvZ1ZW1vQ2Kyw25FSjtnWek9OiieGcDc LEydQhKJUOTAIFA5AEt57/711gw++00iEMfwnqSnuGovsrd6vY0QdWlYOmsKAqW2cNKjEWtxyEIcL MCB24xqjJwFkXHUUI64BzH34v7A352vhMgvIhMKkqxUbKaetA7krJHGLuYKH3aSI5uyLMJ+kjzB/5 /wqoQ6r/WLofqFzJ3+2VLqAAoNN2hJJQ5Pn3vPQ2n1+6MyYyEk/1v5U2ZXnoyrIqU6GbyT9bhfUg7 E+lHG8kW+nwCQe2ujYCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsb-000000026jX-42Jr; Wed, 31 Jul 2024 18:16:53 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsX-000000026fG-1EcM for opensbi@lists.infradead.org; Wed, 31 Jul 2024 18:16:50 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-70d1cbbeeaeso4444870b3a.0 for ; Wed, 31 Jul 2024 11:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722449808; x=1723054608; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kmc2W94peZoWhT56Qs4Qb6A+5Mo3rnKlJlUVRz++Oyw=; b=OrAorYQ08jbWmVc7gMZisH6W/x8YlLBC1fit1wHbGlHuKFpIPcdabKyx4o0R2A7VbD ufaUpQg2vkwIuCBzSADbMwTh6lQ/ivAsc7wc6G4VGl9t3Wr9LHmVV2WdYz2MJP7cxG1j LAHFmteO8IP9q+ArGNd/G51M6VW6xvxdMI1k/CDlRQO/RoiP8JB8zMYJsRdO9FQrDIJ+ d3OuQBWgGhvqKkdN99zvtlXt9amgkf8mTnmACoxzEP0goA/kJDCa+ZRM/Sk0sfWolb9/ nl5LvyQCBdmKdo7zW9poTTxIFGpFURwKcW+58xtt+YlPL5h68CXFRl3spDfNhR02gYTL TI7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722449808; x=1723054608; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kmc2W94peZoWhT56Qs4Qb6A+5Mo3rnKlJlUVRz++Oyw=; b=jXjWVRzR/e3LKC7YQ8t0RPIHAPZIOeCAAGrExUsTdyEb84Nn9ckivTc20YzfEHe1us wYmUfnHvBNn5e5AmzC/XFjBMEw5AhcX08ParMzaOx5Ej/y0/IWF8hDfNcswTXDADIFbB 8UpVrPk42N+hbtQfYeMxJRHg8wTNaDFuiiNyc6EkDciRqn6pyS6xQsTGTpE8Z3ZaMMW2 pZAHHcobcfwZh9lKLwScuGse2+biwUG1DsXP9AKSObkhKfY4vDMqVqQgy1cVtkOjiNl2 sE1krc8x/qOiQIcWr5jg43KSnz1MbpA1Ixi/urOl88NQMVoz17R77x65F/uoSevJhDcY IBRg== X-Gm-Message-State: AOJu0YxAPa0Y49R7+voWTge7q9OAEypC5eqWgm4Z4+1FHPee9qJUaodR 0WrnhVzRZeaA8VtojJ/yh6AnIGZ4jm4Jcd+TobjLdQ89AuWlH/X/SK36ItQH X-Google-Smtp-Source: AGHT+IF3153iIgkCVJRvo7UKmAd+z+cIouJ9oTSkwHBgNYEdnntRg1f5/2ur5EeSStEXOgfYFbRrHw== X-Received: by 2002:a05:6a20:c6ce:b0:1c3:b210:418b with SMTP id adf61e73a8af0-1c68d2cef3cmr185816637.52.1722449807952; Wed, 31 Jul 2024 11:16:47 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fed7ee889asm123278225ad.126.2024.07.31.11.16.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jul 2024 11:16:47 -0700 (PDT) From: Gregor Haas To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, Gregor Haas Subject: [PATCH 8/8] lib: sbi: memregion: Move memregion_sanitize_pmp() closer to its call site Date: Wed, 31 Jul 2024 11:16:29 -0700 Message-ID: <20240731181629.269898-9-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731181629.269898-1-gregorhaas1997@gmail.com> References: <20240731181629.269898-1-gregorhaas1997@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_111649_379306_1E32E5E3 X-CRM114-Status: GOOD ( 11.34 ) X-Spam-Score: -1.8 (-) 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: This is a code movement change to move the previously created memregion_sanitize_pmp() function closer to its call site. --- lib/sbi/sbi_memregion.c | 44 ++++++++++++++++++++ 1 fi [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42d listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [gregorhaas1997(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gregorhaas1997(at)gmail.com] 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 This is a code movement change to move the previously created memregion_sanitize_pmp() function closer to its call site. --- lib/sbi/sbi_memregion.c | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/sbi/sbi_memregion.c b/lib/sbi/sbi_memregion.c index 3783a0a..7c5a977 100644 --- a/lib/sbi/sbi_memregion.c +++ b/lib/sbi/sbi_memregion.c @@ -4,28 +4,6 @@ #include #include -static void memregion_sanitize_pmp(struct sbi_memregion *reg) -{ - unsigned long base = 0, order; - unsigned long addr = reg->base, size = reg->size; - for (order = log2roundup(size) ; order <= __riscv_xlen; order++) { - if (order < __riscv_xlen) { - base = addr & ~((1UL << order) - 1UL); - if ((base <= addr) && - (addr < (base + (1UL << order))) && - (base <= (addr + size - 1UL)) && - ((addr + size - 1UL) < (base + (1UL << order)))) - break; - } else { - base = 0; - break; - } - } - - reg->base = base; - reg->size = (order == __riscv_xlen) ? -1UL : BIT(order); -} - void sbi_memregion_init(unsigned long addr, unsigned long size, unsigned long flags, @@ -212,6 +190,28 @@ static void merge_memregions(struct sbi_domain *dom, int *nmerged) } } +static void memregion_sanitize_pmp(struct sbi_memregion *reg) +{ + unsigned long base = 0, order; + unsigned long addr = reg->base, size = reg->size; + for (order = log2roundup(size) ; order <= __riscv_xlen; order++) { + if (order < __riscv_xlen) { + base = addr & ~((1UL << order) - 1UL); + if ((base <= addr) && + (addr < (base + (1UL << order))) && + (base <= (addr + size - 1UL)) && + ((addr + size - 1UL) < (base + (1UL << order)))) + break; + } else { + base = 0; + break; + } + } + + reg->base = base; + reg->size = (order == __riscv_xlen) ? -1UL : BIT(order); +} + static int memregion_sanitize(struct sbi_domain *dom, struct sbi_memregion *reg, enum sbi_isolation_method type)