From patchwork Sun Nov 30 11:16:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 2170240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=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 4dK4Hx4kF5z1yF2 for ; Sun, 30 Nov 2025 22:17:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: 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=SzrE72OcL+JTxE3ds1CIy36MzZI+VYZlAK9Wof7fsbk=; b=eYNA61hYh6QT5w 4ge/4ZQ+JeUKqnhsdXR4ubiR1UWDkoWLCvkZWqorHnPB77u0kRofPKwKXyIL2RfA4uxq6LnhIytai NtV6N4EP964ysteRYMzuTdkTkSfUSAQMXGj23KtFmMoVY6fjcMCbYxkb5ZBw1LQkLoDYJgYJAzzqr vHfJC4Zs6Adqk9/04eSVrLpBA0d7jtjWVhONhrdTe6d9P/6RbK/zILccaJnRKfLGXu4CMGRoWS0S5 VIlJAUinhxNxsmiwXXqRz/fPA2n7EkjwyclqO4T4h3qlChYNJ5oPEbqzHeRVTdtF663k93xjObc3m FI6igKagORXmsLlRal6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQF-00000002F8i-2Rvm; Sun, 30 Nov 2025 11:16:55 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQC-00000002F7v-49Gv for opensbi@lists.infradead.org; Sun, 30 Nov 2025 11:16:54 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7b86e0d9615so3892609b3a.0 for ; Sun, 30 Nov 2025 03:16:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1764501412; x=1765106212; 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=TkFuE/b601msZc5eQRcFw5QAnZfVLmZDWNmrfyUCp/4=; b=SpAfHrWlHxRHcrqZ6FLg7T1WSj/5twbw7WFBefN8wCQSILnuenSPmPFR5y4bfDTUaw Xb/iNNUW69NSOcd3XbL4Mr/5RB1BlgLZxrJgcFkiPBOQYfPHv4VQuBfrdadTLmw8qzgy JJRGvoCjA+v0SiFdY9nIWPUZNsDfZvlFiJr5tlj0COQUAYCZKuOc/NOu0kKZIgmEOCgd eU8xqcmUZ5L0m6ukvb3UBqmdh+yUVsG7VqepU8b396+wa4nA0QPi71XFbEl2CucpD9Gg jj9MVmuhQxDjVqYXejN5o0rxz8GSHK55wm91iVrdF0C/ZlAFYvSMes7fOreFOL8r87gr mdGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764501412; x=1765106212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TkFuE/b601msZc5eQRcFw5QAnZfVLmZDWNmrfyUCp/4=; b=uKeJgSeZTvwc597FxtB4VSRFv1/As0H65tDpgr+d/SUdqUVhmy/tchLA0p0flWY/u2 23KOJ2GkUEKeR2IwmhVyORxeZAV8rKrX1Chvr9Zaa04o3uOgeH2KAmwRqkICvG0L3qJL 00e2JaJUq61brhag1bR/67vrWAS30gIqI88p46AvdS+T27NDNICgZKfFRQvzKnf3R0pb 2bMrrz/SaTPk+UyaGQSWOiD721ERlOoupX5T9qKhFHpg19evwRjKR0ZqlL31pOVCRP0V Y4jZPbXDCCwBAAKNYkw8zTYOxVN9xKHVx02eixBKr3tdNU17FRs6J2yNeQN2NDxch/fd GLBg== X-Gm-Message-State: AOJu0YyrNhNcoItCg+u2yjgX3HLWNEFB7nP0rWRjvB4QeSvTY0YKkVaS zAdNd9bNOBQGzG7g11P9RTkDDZWXt2Y5UPRy7jir1DePKTK+33HUze23nSC32Ua/Xi/FojyWrxf Y5+A+/SzK31DbdHIEYJV5ckYAS7ym6hpuo0+70PObWzb7d2pmE4GCAssdqIMTB8zM8liRgdkr3W xMURD5iahAwfIwD3Jz/++uk1aTBk6Vn4PNpRXLxGrIPcxFpHGe X-Gm-Gg: ASbGncsAQ6Y5QKmLwMp+x6hmz7D6lD2E9oL2AiNl1JwIZ6VvKSHqvotRL9u5zebvHs0 hJw6K77v2UbLpSWECkygSvmRKHZt72wkvG4KWrL+R5evQjVKD9jG0gx1/yTcmuKR2CtUz1/4KP7 P0NYQsmP1ZqYieTfgojQkC9A7mDKS2kmsnsblOkz0LP8H2JTcmYlPPHu83tToeJdrmiAvjjHBLF atU4GzsLniwn2033pjbBeyt08BSu/gjGFMwOyKZevHlFHFiHDAiMkfhRflenuUx7RW+tRPyVhxU UKTIw8Kn5jLdwkT6dB8drnxmOM8E8uq1q5Dj0WtYsc3zVVXIoGKC4JMUkDknjCjXoJsDaUgTz+m uXDoNXAg6t3FpIxXiPeU0TBHuIveBegpzPZX/fvFghTm3gn1JjmVUPy5KA+Reirvdp7D0uif9j3 Ah5lJvnEoDu/FKfMk/45/c4Aq9dZU8cufTrog= X-Google-Smtp-Source: AGHT+IHEf8KYMfxBNnuR/YDQkyxOIrYuGGMUinJEyA9QwfvLghgcaRV0ZGu4+Hk1N6F9vC7jDFsf6w== X-Received: by 2002:a05:6a00:2d95:b0:792:574d:b12 with SMTP id d2e1a72fcca58-7c58c999802mr33340305b3a.10.1764501412035; Sun, 30 Nov 2025 03:16:52 -0800 (PST) Received: from hsinchu16.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7d1819277c5sm10027050b3a.4.2025.11.30.03.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Nov 2025 03:16:51 -0800 (PST) From: Yu-Chien Peter Lin To: opensbi@lists.infradead.org Cc: zong.li@sifive.com, greentime.hu@sifive.com, samuel.holland@sifive.com, Yu-Chien Peter Lin Subject: [RFC PATCH v3 1/6] include: sbi: sbi_platform: add sbi_platform_reserved_pmp_count() Date: Sun, 30 Nov 2025 19:16:38 +0800 Message-ID: <20251130111643.1291462-2-peter.lin@sifive.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20251130111643.1291462-1-peter.lin@sifive.com> References: <20251130111643.1291462-1-peter.lin@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251130_031653_039602_5E89090A X-CRM114-Status: GOOD ( 13.02 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add sbi_platform_reserved_pmp_count() function to calculate the total number of reserved PMP entries for a platform. Also add get_reserved_pmp_count() callback to allow platforms specifying their addi [...] Content analysis details: (-2.1 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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 Add sbi_platform_reserved_pmp_count() function to calculate the total number of reserved PMP entries for a platform. Also add get_reserved_pmp_count() callback to allow platforms specifying their additional reserved PMP requirements. Signed-off-by: Yu-Chien Peter Lin --- include/sbi/sbi_platform.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index d75c12de..0deeca9f 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -146,6 +147,8 @@ struct sbi_platform_operations { unsigned long log2len); /** platform specific pmp disable on current HART */ void (*pmp_disable)(unsigned int n); + /** Get number of additional reserved PMP entries. */ + u32 (*get_reserved_pmp_count)(void); }; /** Platform default per-HART stack size for exception/interrupt handling */ @@ -302,6 +305,38 @@ static inline u32 sbi_platform_tlb_fifo_num_entries(const struct sbi_platform *p return sbi_hart_count(); } +/** + * Get total number of reserved PMP entries for the platform. + * + * This includes: + * - One default PMP entry for sbi_hart_map_saddr() when smepmp is enabled + * - Additional platform-specific reserved PMP entries from get_reserved_pmp_count() + * + * @param plat pointer to struct sbi_platform + * + * @return total reserved PMP entry count for the platform + */ +static inline u32 sbi_platform_reserved_pmp_count(const struct sbi_platform *plat) +{ + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + u32 pmp_count = 0; + + if (!plat) + return 0; + + /* ++ * If smepmp is enabled, reserve at least one PMP entry ++ * for sbi_hart_map_saddr(). ++ */ + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP)) + pmp_count += 1; + + if (sbi_platform_ops(plat)->get_reserved_pmp_count) + pmp_count += sbi_platform_ops(plat)->get_reserved_pmp_count(); + + return pmp_count; +} + /** * Get total number of HARTs supported by the platform * From patchwork Sun Nov 30 11:16:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 2170242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=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 4dK4Hy3LLLz1yPJ for ; Sun, 30 Nov 2025 22:17:12 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=X5q96gpa5+tCaXMhqRY0FVSu+y9hRa1yvZgRbJzq7zQ=; b=wqdhtZYX8EYRd3 YYJ99QNPv7S6+S+rYI0sc6sGdvxbTotw1enRZCNZXDkEojNflRrFCgc3M1qjapD42CBhh5IcAV91s 0993iZLSD4Niug6yeTDvIYEciDPIlpGPfKxGERNo+530zBefDMmGCUcxhPhRN5d8Jhc00RJw3ozly btYlgzyIGylQj7zuuLdiji+NfR+G1M49GTBKABtSx/TRlqZ8iVxAVNaRaNbyoI8nBaug8mq1W0OYd 5TsKvr3cuLDuBEGftdjtFwy9cKckwoU6aW2OS2VUP25LdiQn+UgJHOos/SwfwJ7s7vQfkSfILKaOE 0gaoCIJlmV3opplh4zSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQH-00000002F9Q-0PXy; Sun, 30 Nov 2025 11:16:57 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQE-00000002F8M-3QJS for opensbi@lists.infradead.org; Sun, 30 Nov 2025 11:16:55 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-7aad4823079so2717655b3a.0 for ; Sun, 30 Nov 2025 03:16:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1764501414; x=1765106214; 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=B2K/DM9m5h9l9iIVTbzgC8xy6M0vcGUoDtw8u6byowc=; b=X5cNWNDvjQWIyH+cF3p6DjfAOTUEdse2CGGbQY+psZ0uzi1Jy6nuVmDfez6xQbT5yh QiT/6Y+K71Ur2WHQxfh3lsCIELtWQBCpfR8vqmqLaJ4e6yOkfgTZT2/OfdRKWbMVVGmG d98iL2WeHJdZEv3siE64uS4pSfidFkN9a8Bf1NwwEnRyC7XoFLNDs90efK5DgGDUMzxI Uz36Wfj+FHEBgJKEqTSh/dTsuC+8HJ9VbBFvE2k4VypJjDj9OaIzs6ZB6jbYK32549in UfeLFgkr0Hc/w9hYHVMY5Dw9WlrvRSJxv5/+u1y1yO9s5zPvs0AvxPesWPxnbv0oZpT6 yMfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764501414; x=1765106214; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=B2K/DM9m5h9l9iIVTbzgC8xy6M0vcGUoDtw8u6byowc=; b=AM4Xc57W3PsE6IQmX+8yEpoJXp987ADt9fGLEZDi75f6bPFgb5bcAp6vpsgBd2mkLq JNQm2cDWRouBw5vmUbTMJtLePrn8j1WltkDw7K1/dxIaR4qzdRkM33M/5Xbt603RL5bM Oefl0UbEz13HTDEzgVfEK05LOOcof1SPPmXK63mXyolQTsQZQVWFpfLX1PcptDTCOtu9 pI/lJVI2dL3LYQoD4Axu/iE9g6olXGHf1WN3u+1Ffje/XBbg2prAOAOtwvk66pLbvo1g Wd1367I6L+2dPSg25a/2+wuI7gSYSFp/qg9E3sCT5Y/pnfbrEfT6ttSFDfv6peMljS9k Q18A== X-Gm-Message-State: AOJu0YzTbxb2xYHPj9Cenbm31uZviKD1jspN0NgnMX3ol2TcYzKJKUJ0 eZri2SekBsEgdHOWWIgVNgp3u9R694KK13U41lS1i0WRattdecUtKIfyGHKiUU/yapCDXizWhD3 d3s8m2Ctr6UwqhlIvo9oMIdERmbm+Xpvhr0e04Lk1P/3riPfuaxV3rEBISVqHY3aEaODdN/NTfe GKm0xixE+ZFE1n4zdsZpC8qlRsWFMhrWPXaFCBVOLiUtcpKAil X-Gm-Gg: ASbGncusWw1h1XVhbZ//OZjB+Ijo+1lTFb1pBrbCbd6QhHsbXUz/GhFLyKwyr/JhEZm nODw0L7TUbK2lWQQojGerrHfRHTv3jK/i349gI45EUfnpUrRelNf2hhIF5A4aWUsrtM57CdVqJK WEsUc9qLCpY/2Bp2Z2XJyLJ1CGBza4Rkbd7fCc3YdDEd0CcWzULSatgR0pUxMu10tpa7wIgS915 GkLDuboN8sJFb5XbvFBPKmAfD/v+pl+JaqB3lyuQb41zGScY9lyNPN6VqKLwTLrAN91yRuU+QEM EFAZRdA/XWO/iPcd5nFDXFtoNR1xsal1bjFQW4jTt6LVt6rfj49ogXPeXoLDS90ohXqzt1nU1E3 ek4zFPXCpTbBBgmoTLuG9UH/Jqu9ku1aJ/5X1H3o0gef8qEa+yo3gH8iDUaLPuQZKLocFde+qvf xyhzM9iYTjMH+Lmj3ZQvXC2SZs8EdU2Sn29f0= X-Google-Smtp-Source: AGHT+IEWG9slAKcMZgtN/c35ML0NdLxU+1ZwOfes5ISHQ+xotxGFnMQrSjdgFf4Qwu+1AFdEq7hAxA== X-Received: by 2002:a05:6a00:bd81:b0:7ad:4136:944f with SMTP id d2e1a72fcca58-7c58c89cbe5mr35886911b3a.8.1764501413720; Sun, 30 Nov 2025 03:16:53 -0800 (PST) Received: from hsinchu16.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7d1819277c5sm10027050b3a.4.2025.11.30.03.16.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Nov 2025 03:16:53 -0800 (PST) From: Yu-Chien Peter Lin To: opensbi@lists.infradead.org Cc: zong.li@sifive.com, greentime.hu@sifive.com, samuel.holland@sifive.com, Yu-Chien Peter Lin Subject: [RFC PATCH v3 2/6] lib: sbi_init: print total and reserved PMP counts Date: Sun, 30 Nov 2025 19:16:39 +0800 Message-ID: <20251130111643.1291462-3-peter.lin@sifive.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20251130111643.1291462-1-peter.lin@sifive.com> References: <20251130111643.1291462-1-peter.lin@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251130_031654_862942_7537F2DB X-CRM114-Status: UNSURE ( 8.03 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.1 (--) 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: Show both total and reserved PMP counts in boot log. Signed-off-by: Yu-Chien Peter Lin --- lib/sbi/sbi_init.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 663b486b..bb449d49 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -163,6 +163,7 @@ static void sbi_boot_print_hart(struct sbi_sc [...] Content analysis details: (-2.1 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:435 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 Show both total and reserved PMP counts in boot log. Signed-off-by: Yu-Chien Peter Lin --- lib/sbi/sbi_init.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 663b486b..bb449d49 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -163,6 +163,7 @@ static void sbi_boot_print_hart(struct sbi_scratch *scratch, u32 hartid) int xlen; char str[256]; const struct sbi_domain *dom = sbi_domain_thishart_ptr(); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); if (scratch->options & SBI_SCRATCH_NO_BOOT_PRINTS) return; @@ -183,8 +184,10 @@ static void sbi_boot_print_hart(struct sbi_scratch *scratch, u32 hartid) sbi_printf("Boot HART Base ISA : %s\n", str); sbi_hart_get_extensions_str(scratch, str, sizeof(str)); sbi_printf("Boot HART ISA Extensions : %s\n", str); - sbi_printf("Boot HART PMP Count : %d\n", - sbi_hart_pmp_count(scratch)); + sbi_printf("Boot HART PMP Count : " + "%d (total), %d (reserved)\n", + sbi_hart_pmp_count(scratch), + sbi_platform_reserved_pmp_count(plat)); sbi_printf("Boot HART PMP Granularity : %u bits\n", sbi_hart_pmp_log2gran(scratch)); sbi_printf("Boot HART PMP Address Bits : %d\n", From patchwork Sun Nov 30 11:16:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 2170243 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=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 4dK4Hy5bkgz1yPK for ; Sun, 30 Nov 2025 22:17:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=g8I0L+7AiOlhLXpjxN8Nk1qL85uAiWBAknmgTdbgToA=; b=jsl+/29bj9OMdg JqKEr/Z06NpdQrOoanxC49tHsYXIVodLds7zagFDPCYvgPbMp8rfUp+idbZTjs37Cnmhh9wC0Gu18 t2BV1YMqvXYyh6E6axw/xtYLQKW/TuldUzc5vx7Q6HIAQY9/TLefIiv0Tqby89cSDWQhfxd/PhE3w BNXcynBox+n7D20syzZtUvVdiiaeYjHK5K5GxXOaTQxWghAtzoJK8R8lynQga0bruVu8nTd0Kd9wT fLFdN8OSehV9DkPvttUG/v2l9pw8da0CYe/JjSjV5+3T4+Nki6ITxlG/VgyxurnDEhEkVYUbLP6Jw JJm01UsLDoKxWbvyhKKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQI-00000002FA0-29r0; Sun, 30 Nov 2025 11:16:58 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQG-00000002F95-2fH2 for opensbi@lists.infradead.org; Sun, 30 Nov 2025 11:16:57 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-7bc248dc16aso2587101b3a.0 for ; Sun, 30 Nov 2025 03:16:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1764501416; x=1765106216; 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=hDJK5LiOIpk/nn06wmN3vUomDrnOAF3KgKYzIwoJlM8=; b=MaMk/ONFqTZn/b1Pu2O0cQuW2BslcDYZFrQ6JaqsfWi/rCSYGRxmLQKadZYZHiv94I ocUb/qMKMrMz7eECbSmkXZguzngrBI8ERMZlyDz5fiZO1MEzQUFn8ounZmb5uGU21MYV HfuCVdJKj6SQKJQti9VSXDWJK+gczNQ7VhYq8tD85mrP2pHoazBiuFTSVWsAp3oI3awo Lh98T4/e1JJDgwqO95l4rIwC/YmEsBGX26L3PFEx7L7ZhjDHU4DAz8JiU+DinPGlfb9j w9U/tBuicTiRQr2yBNuHXFTaEEgQigsSXQQvJCBPxZ1FlBg5Ph9JGWzvYDggZwLgXGnD cdxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764501416; x=1765106216; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=hDJK5LiOIpk/nn06wmN3vUomDrnOAF3KgKYzIwoJlM8=; b=QNXPrIyEdMqyuE4fi2h3CLq+3lnXjr+mfGRQr3RncSfrrIUUvMSwnDLUwT5gEweOU1 RoWCVObm89mAQDaDlOXyTl0Y/e5+YXkMsRTjoHOshAv37CmUOTkyxy7C/wHft2nvGC3+ Ivq8vSgoXknpHetbgfRgVGw/xUwiGLWp0VDnkOIkvQ4j5nieNHQOkSg1S22hmWMqvCeH 0eGYGwf0KtyZ25YwIN+RaOi3c/d/kPhQoZiflkrPK/GesiZnaGLknDXpp/DGbSCRjTrS a/e5yE65xWsAExyoKpPv7rc9hNltGbrXBK+dcvyszjOoa1SH9/B2kJxmYSSDRUdziXUd rE7Q== X-Gm-Message-State: AOJu0YwNqkPDXIYRQBpvi6rLtUbpqvU6HPMaXLFbHuPYHtNr5pqalA8b EXe+mbNYyjQJLjYouy1RXAnbTm6TwUEo7W62L+bq6g0yQo/70vNbLGyYgBqtT+8DvNzjRNpPf5J 90pHtV1H9UBf1I+PvNWDpmNH72AYnSOlK1panedMpQlRtbSacYHN6cYgUl2qHp2PAaWWIhk7Lpy ZNrGT1QXf0E6l0z7CuxKrdGo3yg4IdHoUtvkkFmGjQx4Qn4YVI X-Gm-Gg: ASbGncuQkgjHtDafEDspqN00XdyC7lSM+5PGuWcE5JjuFCjL+zvMR3kiSs+coDlmJOs GOu7RASleT8fPecR7e1OzFwIVExdzs3AgGskLSmyLu9CbqOOitwNBmomZvmX6V7X6D6GUlbCNgs eqwRyyWhkx9qbLuYPtjei1C+iL1lS+tOkqX9Lv3hOuWHQs50urT7XDqtYdFI9S56Ug3eCJwq7bu hM1HpOBzugvAZu2oetLR+iH9mteDZgwwdsKXZVv2KmWfwj4LowVIbcZROVFPxKz8vTt21NQ8sSX DJccnLmSxkYqJaGY1+8SElvZMRwL22Jx5o3M4hUx72iViRVfJ8utTV+Hah3pSu3gZF9+HKl/1Ee YNLhohS9AXs8kLbEI8CE54H4x7gX2dIPl9IHKLULzO2GXqyu7mDsywES00a2voZZd7GMvXVXza+ Zlg/arX71+ejI24y3Szsa14AJCdYk81nG1a5k= X-Google-Smtp-Source: AGHT+IFq/GnH8IodABYg1O9aldginolZ27er0UKSs4ObmtkbZOOsqde5+N856FggktGw/z9bS3e/QQ== X-Received: by 2002:a05:6a00:9294:b0:7ae:8821:96dd with SMTP id d2e1a72fcca58-7ca8977866dmr22772846b3a.24.1764501415334; Sun, 30 Nov 2025 03:16:55 -0800 (PST) Received: from hsinchu16.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7d1819277c5sm10027050b3a.4.2025.11.30.03.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Nov 2025 03:16:54 -0800 (PST) From: Yu-Chien Peter Lin To: opensbi@lists.infradead.org Cc: zong.li@sifive.com, greentime.hu@sifive.com, samuel.holland@sifive.com, Yu-Chien Peter Lin Subject: [RFC PATCH v3 3/6] lib: sbi: riscv_asm: support reserved PMP allocator Date: Sun, 30 Nov 2025 19:16:40 +0800 Message-ID: <20251130111643.1291462-4-peter.lin@sifive.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20251130111643.1291462-1-peter.lin@sifive.com> References: <20251130111643.1291462-1-peter.lin@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251130_031656_707754_95B40C51 X-CRM114-Status: GOOD ( 14.39 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add reserved PMP entry allocation and management functions to enable dynamic allocation of high-priority PMP entries. The allocator uses per-hart bitmaps stored in scratch space to track reserved PMP [...] Content analysis details: (-2.1 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:434 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 Add reserved PMP entry allocation and management functions to enable dynamic allocation of high-priority PMP entries. The allocator uses per-hart bitmaps stored in scratch space to track reserved PMP usage. New functions: - reserved_pmp_init(): Initialize allocator scratch space - reserved_pmp_alloc(): Allocate unused reserved PMP entry - reserved_pmp_free(): Release allocated PMP entry The coldboot hart calls reserved_pmp_init() during sbi_hart_init() to set up the tracking bitmaps for all harts. Signed-off-by: Yu-Chien Peter Lin --- include/sbi/riscv_asm.h | 6 +++ lib/sbi/riscv_asm.c | 92 +++++++++++++++++++++++++++++++++++++++++ lib/sbi/sbi_hart.c | 4 ++ 3 files changed, 102 insertions(+) diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h index ef48dc89..4fd0be2b 100644 --- a/include/sbi/riscv_asm.h +++ b/include/sbi/riscv_asm.h @@ -221,6 +221,12 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out, unsigned long *log2len); +int reserved_pmp_init(void); + +int reserved_pmp_alloc(unsigned int *pmp_id); + +int reserved_pmp_free(unsigned int pmp_id); + #endif /* !__ASSEMBLER__ */ #endif diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c index 3e44320f..6c81708f 100644 --- a/lib/sbi/riscv_asm.c +++ b/lib/sbi/riscv_asm.c @@ -9,10 +9,14 @@ #include #include +#include #include #include +#include #include +static unsigned long reserved_pmp_used_offset; + /* determine CPU extension, return non-zero support */ int misa_extension_imp(char ext) { @@ -432,3 +436,91 @@ int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out, return 0; } + +/** + * reserved_pmp_init() - Initialize the reserved PMP allocator + * + * This function initializes the reserved PMP allocator by allocating + * scratch space to track which reserved PMP entries are in use. + * + * Returns: 0 on success, negative error code on failure + */ +int reserved_pmp_init(void) +{ + if (reserved_pmp_used_offset) + return SBI_EINVAL; + + reserved_pmp_used_offset = sbi_scratch_alloc_offset( + sizeof(unsigned long) * BITS_TO_LONGS(PMP_COUNT)); + if (!reserved_pmp_used_offset) + return SBI_ENOMEM; + + return SBI_SUCCESS; +} + +/** + * reserved_pmp_alloc() - Allocate an unused reserved PMP entry + * @pmp_id: Pointer to store the allocated PMP entry ID + * + * Returns: 0 on success, negative error code on failure + * + * The allocated PMP entry should be used with the following + * programming sequence: + * - reserved_pmp_alloc(&pmp_id) + * - pmp_set(pmp_id, ...) + * - pmp_disable(pmp_id) + * - reserved_pmp_free(pmp_id) + */ +int reserved_pmp_alloc(unsigned int *pmp_id) +{ + const struct sbi_platform *plat = sbi_platform_thishart_ptr(); + u32 reserved_pmp_count = sbi_platform_reserved_pmp_count(plat); + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + unsigned long *reserved_pmp_used; + + if (!reserved_pmp_used_offset) + return SBI_EINVAL; + + reserved_pmp_used = sbi_scratch_offset_ptr(scratch, + reserved_pmp_used_offset); + + for (int n = 0; n < reserved_pmp_count; n++) { + if (bitmap_test(reserved_pmp_used, n)) + continue; + bitmap_set(reserved_pmp_used, n, 1); + *pmp_id = n; + return SBI_SUCCESS; + } + + /* PMP allocation failed - all reserved entries in use */ + return SBI_EFAIL; +} + +/** + * reserved_pmp_free() - Free a reserved PMP entry + * @pmp_id: PMP entry ID to free + * + * Returns: 0 on success, negative error code on failure + */ +int reserved_pmp_free(unsigned int pmp_id) +{ + const struct sbi_platform *plat = sbi_platform_thishart_ptr(); + u32 reserved_pmp_count = sbi_platform_reserved_pmp_count(plat); + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + unsigned long *reserved_pmp_used; + + if (!reserved_pmp_used_offset) + return SBI_EINVAL; + + reserved_pmp_used = sbi_scratch_offset_ptr(scratch, + reserved_pmp_used_offset); + + if (pmp_id >= reserved_pmp_count || + !bitmap_test(reserved_pmp_used, pmp_id)) { + return SBI_EINVAL; + } + + bitmap_clear(reserved_pmp_used, pmp_id, 1); + + return SBI_SUCCESS; +} diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index a91703b4..548fdecd 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -1031,6 +1031,10 @@ int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot) sizeof(struct sbi_hart_features)); if (!hart_features_offset) return SBI_ENOMEM; + + rc = reserved_pmp_init(); + if (rc) + return rc; } rc = hart_detect_features(scratch); From patchwork Sun Nov 30 11:16:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 2170239 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=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 4dK4Hx0rctz1yDg for ; Sun, 30 Nov 2025 22:17:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: 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=eVrC28EPdCuQeQhDnCjhsIZHMFKlDnDvGFB+o+iuvj0=; b=FiCJdxkWVnogNj LLAj673ZeWonW9R6uZRnmraH76L2Jfd0HhdMU4vD/MqyX56IYbFydbyrUTdo3dTvsjBWAh8zbnB2T CFqBK2bvVUSLICHZjILbIbC7C2DmSpttr1ij5AA9zQ76tk28xuFNKqnmpy4bZnt+zPFXL8457v1RO irb9DKyBSoUP03PB+3RWLWXsFM/o8knrJk7ntEv2boRdFoeO5F7i/lKvpEaYKWJyHrRTDuslvmf3L zGX6d+xdexOH42TC/3ekL7A0ZRDk7tytANeXm6h8rCj08rgvrBmVcgXQKe48li+tPzoBPnUf0HaAm rlC+UJPnrMYELHxA9kmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQL-00000002FB0-1Ups; Sun, 30 Nov 2025 11:17:01 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQI-00000002F9f-0zyG for opensbi@lists.infradead.org; Sun, 30 Nov 2025 11:16:59 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-7b9c17dd591so2788367b3a.3 for ; Sun, 30 Nov 2025 03:16:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1764501417; x=1765106217; 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=7NqOPBAzOtPh2mJ20WFaA367RdcfoPBYdzvqZTZ3afI=; b=Ch+yBN19ErPtQfXR1JfALWiPubV5+1FEkuva6HWPuockUR/+djaBmF3j3hNxx90n1z DLeLG00ZFdaP0ajmdWucG98v0/NXKYkVW+6v1ZTESvEGUM2L2neJyZmkvn9GL3clxBt/ iPKWbU6zrQ+64zOXBPQhTfVoDztIBQ3mLdZtTnpsvRGUS69XOMbR9n0mH3UalRnnLAt3 AmVi6ee7SSKJn3MPX6jhLyTzPywsWY5mPhwLsQXUzWtrG9y0sz9TU8yl0VWisdi3ISi6 YN7qS8xxhE5eLmxSW4KGbEC+WoEVeE5NN8NCYMFiJ+MiG6pdQujJqwpBfCCHyag/h+29 khMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764501417; x=1765106217; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7NqOPBAzOtPh2mJ20WFaA367RdcfoPBYdzvqZTZ3afI=; b=YWovnsa5ncoWHLqCPss7zIB1PcodL+7WQBHBKWBPES4LyUd2RqbZpjoMXgxUDj32DW uToBVtyHNPr9b1E0HcrtQGOQcbSjjNI/StuKEHNwhp/M63eAc85CwjS6JYYYbaUxIXuQ llHqMA3IBZnQjMcDz5d3AgzCIRLBnaLmd2mTg4ohimK2beuOW31l9w9VdXDVHbcjbzwB a0jqkfaTXsRELTQrmBxTl0iD5w91yqRbrkTFlOIl2xiTtDlL9fSZsikFpwbUZ0kmVAiP y7sjmbatPpg5CJhZ9LuUYW3qq+5XMAIp/OgPU0Q2nkciVzPrbCRWAiQxJpimcdwrJo10 LZhw== X-Gm-Message-State: AOJu0YxfwoJVCRm6ItTPfEdb/PuUYMp60kKuy8lwd5Y/WLRQrKqdiB2U EKNDZgMUMhzbBMrMuAAoMFkkskMJOed4chv7kmaYafuHocTiSntKRQ2ne8VkfgxV4PI+S+o5Ez7 P+/rKE3OI8w26kF3zRYGb1dDzVD9HjStGj3D/rKpQ0Ho5NxwBCLb82HUKXBbvnI9siE5EF3K1N8 zhBa9QhFSOlluqRXo9N4fe8gv74ngw5f6J6yaBIMYjKLy56lKI X-Gm-Gg: ASbGncsRvkY1ViVZQM7k9PJZzqox1PomRDcKyg2dqj0gBpvp0wzUcsVTS7XIFup1sxA JOOcRbVV8vHa3ZX9SEURilFAlmxYtxdO64vpyCCIDaU5+MSwJfQ9rKXd1sEk9l0lCRX+UDaaacf ECAqmaAPCQJRqiu/Mh6Q1cJwLCSmjiGWlrW/A2MuzgLs/MmvF278dkBIXrA7VA7cQaE5gNF5LeS DQR/WjmBarGA1hOjfdQovtemNf+pqTTxEnH+ZX9za2qJwj4G2FuC/noehaVI04XDsn+NwHR3rUj K4YgYJnt6Urdt0zxLD8OGP4/MASz/mTIvEZ8HcaFAjw2x0SD3Fn8b76iYKb7rUD13+g0HtS5kmn DZQLyiGf8KAbShC+aMSQDtdEiQ/g8tFlPZcoaQcO9vy5vcUGhok9QvsJF98V1LvmU01lcxDIlUL qE57xF6yBosMI8blM1eteyAtcDpIWFja62QdY= X-Google-Smtp-Source: AGHT+IGdW16MAj5avhZRt1sVUf7aIRZUwrHe/vwLhTJAhF+wBdMvW8EDn9aeKxxeAoHZrl+BWlScLw== X-Received: by 2002:a05:6a21:3288:b0:361:4f83:10f5 with SMTP id adf61e73a8af0-3637e0a57edmr23985401637.48.1764501416978; Sun, 30 Nov 2025 03:16:56 -0800 (PST) Received: from hsinchu16.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7d1819277c5sm10027050b3a.4.2025.11.30.03.16.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Nov 2025 03:16:56 -0800 (PST) From: Yu-Chien Peter Lin To: opensbi@lists.infradead.org Cc: zong.li@sifive.com, greentime.hu@sifive.com, samuel.holland@sifive.com, Yu-Chien Peter Lin Subject: [RFC PATCH v3 4/6] lib: sbi: sbi_hart: extend PMP handling to support multiple reserved entries Date: Sun, 30 Nov 2025 19:16:41 +0800 Message-ID: <20251130111643.1291462-5-peter.lin@sifive.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20251130111643.1291462-1-peter.lin@sifive.com> References: <20251130111643.1291462-1-peter.lin@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251130_031658_298542_E0266383 X-CRM114-Status: GOOD ( 21.07 ) X-Spam-Score: -2.1 (--) 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: Previously, OpenSBI supported only a single reserved PMP entry. Add support for multiple reserved PMP entries, with the count determined by the platform-specific sbi_platform_reserved_pmp_count() func [...] Content analysis details: (-2.1 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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 Previously, OpenSBI supported only a single reserved PMP entry. Add support for multiple reserved PMP entries, with the count determined by the platform-specific sbi_platform_reserved_pmp_count() function. Signed-off-by: Yu-Chien Peter Lin --- include/sbi/sbi_hart.h | 15 ---------- lib/sbi/sbi_domain_context.c | 6 ++-- lib/sbi/sbi_hart.c | 53 +++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index e66dd52f..6d5d0be7 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -105,21 +105,6 @@ enum sbi_hart_csrs { SBI_HART_CSR_MAX, }; -/* - * Smepmp enforces access boundaries between M-mode and - * S/U-mode. When it is enabled, the PMPs are programmed - * such that M-mode doesn't have access to S/U-mode memory. - * - * To give M-mode R/W access to the shared memory between M and - * S/U-mode, first entry is reserved. It is disabled at boot. - * When shared memory access is required, the physical address - * should be programmed into the first PMP entry with R/W - * permissions to the M-mode. Once the work is done, it should be - * unmapped. sbi_hart_map_saddr/sbi_hart_unmap_saddr function - * pair should be used to map/unmap the shared memory. - */ -#define SBI_SMEPMP_RESV_ENTRY 0 - struct sbi_hart_features { bool detected; int priv_version; diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c index 74ad25e8..d2269529 100644 --- a/lib/sbi/sbi_domain_context.c +++ b/lib/sbi/sbi_domain_context.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -102,6 +103,8 @@ static int switch_to_next_domain_context(struct hart_context *ctx, struct sbi_trap_context *trap_ctx; struct sbi_domain *current_dom, *target_dom; struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + const struct sbi_platform *plat = sbi_platform_thishart_ptr(); + u32 reserved_pmp_count = sbi_platform_reserved_pmp_count(plat); unsigned int pmp_count = sbi_hart_pmp_count(scratch); if (!ctx || !dom_ctx || ctx == dom_ctx) @@ -121,11 +124,10 @@ static int switch_to_next_domain_context(struct hart_context *ctx, spin_unlock(&target_dom->assigned_harts_lock); /* Reconfigure PMP settings for the new domain */ - for (int i = 0; i < pmp_count; i++) { + for (int i = reserved_pmp_count; i < pmp_count; i++) { /* Don't revoke firmware access permissions */ if (sbi_hart_smepmp_is_fw_region(i)) continue; - sbi_platform_pmp_disable(sbi_platform_thishart_ptr(), i); pmp_disable(i); } diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 548fdecd..a7235758 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -32,6 +32,7 @@ void (*sbi_hart_expected_trap)(void) = &__sbi_expected_trap; static unsigned long hart_features_offset; static DECLARE_BITMAP(fw_smepmp_ids, PMP_COUNT); static bool fw_smepmp_ids_inited; +static unsigned int saddr_pmp_id; static void mstatus_init(struct sbi_scratch *scratch) { @@ -349,6 +350,8 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch, unsigned long pmp_addr_max) { struct sbi_domain_memregion *reg; + const struct sbi_platform *plat = sbi_platform_thishart_ptr(); + u32 reserved_pmp_count = sbi_platform_reserved_pmp_count(plat); struct sbi_domain *dom = sbi_domain_thishart_ptr(); unsigned int pmp_idx, pmp_flags; @@ -358,15 +361,13 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch, */ csr_set(CSR_MSECCFG, MSECCFG_RLB); - /* Disable the reserved entry */ - pmp_disable(SBI_SMEPMP_RESV_ENTRY); + /* Disable the reserved entries */ + for (int i = 0; i < reserved_pmp_count; i++) + pmp_disable(i); /* Program M-only regions when MML is not set. */ - pmp_idx = 0; + pmp_idx = reserved_pmp_count; sbi_domain_for_each_memregion(dom, reg) { - /* Skip reserved entry */ - if (pmp_idx == SBI_SMEPMP_RESV_ENTRY) - pmp_idx++; if (!is_valid_pmp_idx(pmp_count, pmp_idx)) return SBI_EFAIL; @@ -405,11 +406,8 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch, csr_set(CSR_MSECCFG, MSECCFG_MML); /* Program shared and SU-only regions */ - pmp_idx = 0; + pmp_idx = reserved_pmp_count; sbi_domain_for_each_memregion(dom, reg) { - /* Skip reserved entry */ - if (pmp_idx == SBI_SMEPMP_RESV_ENTRY) - pmp_idx++; if (!is_valid_pmp_idx(pmp_count, pmp_idx)) return SBI_EFAIL; @@ -439,11 +437,14 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch, unsigned long pmp_addr_max) { struct sbi_domain_memregion *reg; + const struct sbi_platform *plat = sbi_platform_thishart_ptr(); + u32 reserved_pmp_count = sbi_platform_reserved_pmp_count(plat); struct sbi_domain *dom = sbi_domain_thishart_ptr(); - unsigned int pmp_idx = 0; + unsigned int pmp_idx; unsigned int pmp_flags; unsigned long pmp_addr; + pmp_idx = reserved_pmp_count; sbi_domain_for_each_memregion(dom, reg) { if (!is_valid_pmp_idx(pmp_count, pmp_idx)) return SBI_EFAIL; @@ -481,6 +482,19 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch, return 0; } +/* + * Smepmp enforces access boundaries between M-mode and + * S/U-mode. When it is enabled, the PMPs are programmed + * such that M-mode doesn't have access to S/U-mode memory. + * + * To give M-mode R/W access to the shared memory between M and + * S/U-mode, high-priority entry is reserved. It is disabled at boot. + * When shared memory access is required, the physical address + * should be programmed into the reserved PMP entry with R/W + * permissions to the M-mode. Once the work is done, it should be + * unmapped. sbi_hart_map_saddr/sbi_hart_unmap_saddr function + * pair should be used to map/unmap the shared memory. + */ int sbi_hart_map_saddr(unsigned long addr, unsigned long size) { /* shared R/W access for M and S/U mode */ @@ -492,8 +506,9 @@ int sbi_hart_map_saddr(unsigned long addr, unsigned long size) if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP)) return SBI_OK; - if (is_pmp_entry_mapped(SBI_SMEPMP_RESV_ENTRY)) + if (reserved_pmp_alloc(&saddr_pmp_id)) { return SBI_ENOSPC; + } for (order = MAX(sbi_hart_pmp_log2gran(scratch), log2roundup(size)); order <= __riscv_xlen; order++) { @@ -509,23 +524,29 @@ int sbi_hart_map_saddr(unsigned long addr, unsigned long size) } } - sbi_platform_pmp_set(sbi_platform_ptr(scratch), SBI_SMEPMP_RESV_ENTRY, + sbi_platform_pmp_set(sbi_platform_ptr(scratch), saddr_pmp_id, SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW, pmp_flags, base, order); - pmp_set(SBI_SMEPMP_RESV_ENTRY, pmp_flags, base, order); + pmp_set(saddr_pmp_id, pmp_flags, base, order); return SBI_OK; } int sbi_hart_unmap_saddr(void) { + int rc; + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP)) return SBI_OK; - sbi_platform_pmp_disable(sbi_platform_ptr(scratch), SBI_SMEPMP_RESV_ENTRY); - return pmp_disable(SBI_SMEPMP_RESV_ENTRY); + sbi_platform_pmp_disable(sbi_platform_ptr(scratch), saddr_pmp_id); + rc = pmp_disable(saddr_pmp_id); + if (rc) + return rc; + + return reserved_pmp_free(saddr_pmp_id); } int sbi_hart_pmp_configure(struct sbi_scratch *scratch) From patchwork Sun Nov 30 11:16:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 2170241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=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 4dK4Hy1DPqz1yFZ for ; Sun, 30 Nov 2025 22:17:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=S+UWMN/c8N2SAM5H0uYyAkam48/uRNQpI2W2zkbYvlI=; b=ME02mB7T9ZFriA Uvf7w/UgptOzJ3lHEsZfShEclcq+Vuvy8OaUn8USt0TVHW31QLyEzJCbJ8RovGcqc06q1KzJDvqiG G/wF19RDu/r5ElVNH2FR+dMMNGtAm/VDlgh2lzZGwN59kWdgAWziDhtNjb692S3Fajrnz6krJ13nR zB02eleKKajMxaXOmdksbr1zcDIKFMEphsP05uHAril1keYSmXxBs7hieuJ/pimO76rSqrF9kqloM eK6IfStjN9Y5hIUXRQyY5DVboNlNKg+UaN0zDYeATu6oLa5eWKPkEgpUIYhMvUMN9UAfhc1sW7Fn2 1SziFgyStu0IbA+1ESOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQM-00000002FCA-3EtQ; Sun, 30 Nov 2025 11:17:02 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQK-00000002FAb-1iOt for opensbi@lists.infradead.org; Sun, 30 Nov 2025 11:17:01 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-7b80fed1505so3889815b3a.3 for ; Sun, 30 Nov 2025 03:17:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1764501419; x=1765106219; 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=kjrVZ8847thmLMMiGLQTw2tBYXbwnlhGejq977xRoks=; b=Hhf/JqdD0nZjbjI3CUQn5OzkMyWa7wKnG9n4urpBPIl8rc9PEsJT40ZQszpKEshZF3 6rko5Ji5EZ//+0eD4edqf0DAdyNif/4jLB/IkG6jTknkWpfHyvDm/rHL2QkeJ9YC5umA b3tJqr3EC260DjvTFIoAdsGX9Iivwjpj3E2zvkb8V5KVTriBd3VALEw67g6NFsQa+mXK XkBUfITck73jilTYm4cfcU0+Pidu16gN1p9R5gn83+pdF7gxNuIPHCmh/ykKydsP61ZI rMt4EOxC9LVCg58GyQL3ixGMsOQc4C9oOnHxHU2p3qWxrYrwcUwpiWaiJBu5NM0valsH NKlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764501419; x=1765106219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kjrVZ8847thmLMMiGLQTw2tBYXbwnlhGejq977xRoks=; b=sR/KY+US3GvH6mwCk4lU6hVNJ7XNo/gwpwrNPIESOWmCwY6Lv9f6iYzGGuyYXyo11/ k7ZVxTYF20UBuAFt682DzRscDpqb8c3q+ilTAGJgeH/ofi+F7Xj39XZnryjgW9sQdMSr KHmVOn02Zl2Q8HmbgQBgZl12yQpYfIQKFxMs/EthkW3rGowXOOWLBlsRzw4cCv9mnrEB X6CaIL94+ya3KaFHuM70kH8zyQXYlzr3mjWe0FqhVXnuFWcLyyAvoOoh6Nq180VaF4s1 GFoN8fEDGhtIVQW/Etst99iLQrh7K13RKsCRUNgeYHsDxqhiPLDe2t1GxyHKQX+REIyf xyCw== X-Gm-Message-State: AOJu0YxwtZvaIID7vrnroYaUqmFGJB+OYuhpxT27SufEqkqscN8Z3nZR qhuDqImSGspjuQEKC5SqhIbyA1ZwcjE/SYX+dcGxCqC9WXVIjDqYtXZo+67SrDmovzMJBMvvTKL xv8hJZGj7eQPvqIvrtAC/mOHnJuvPjwGRzgpRGuP16ugT+/citVXmZikheTNRAVwNIFVjnXFEI1 2LHK0GnxAJsy8u3AogEGEX5wOjoAgmwWCjqThUAg9zCMnpo8f2 X-Gm-Gg: ASbGncvkjpxy19rBAuAv9lvGrbFzzCxZM/uIlS3zSy27z3tl9Yu9ug43V7UcOvggCXd t7LtabU//U/D1WPv7+uBsrOj+EXpggpsYOh+adaBahudpPof9FXGrUcUj+Ho9B1XY6Txk7ON7my 47W0tFGnw59Mc4S47TgVpsoN+nlGqp/2MwCIJ1AnGvP+Q/5fgHk4mUE6PfrYVeaQrvxOlcYhbfd BaF6sSMfkwLHtWKu8aCnTzD6g1UU5XeeVshNMxJDKd8mBgFl6UD7tlN3iHMjepmn5cltAqnyF/L GaiGCX9AirdbHXi/YpIo/7ZUiZYHb6KY1C76sBSBIYCAE52yJhjVa4zA671br/fAx5KlKabuLiG b7HwkW8TOzlTsramyYdA/KbwUbKkjD1oHuT0YCwVQ7NagBvRkCGEcYiGKmF+AfbuDJ1fsAHFI3K ojyJIcBG0m6ajwzxxuVo/TXe/69drk/ovPGUmjXzBY8YiW3A== X-Google-Smtp-Source: AGHT+IFeQ8akFF09bU0QTyHEi3YZMXFyfgl02yvDqqTbmG7z3xi9e/BR3n2JGILhK/q4PucEu7t6Zg== X-Received: by 2002:a05:6a20:6a10:b0:34f:b660:770d with SMTP id adf61e73a8af0-3614eddc713mr37118813637.55.1764501418636; Sun, 30 Nov 2025 03:16:58 -0800 (PST) Received: from hsinchu16.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7d1819277c5sm10027050b3a.4.2025.11.30.03.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Nov 2025 03:16:58 -0800 (PST) From: Yu-Chien Peter Lin To: opensbi@lists.infradead.org Cc: zong.li@sifive.com, greentime.hu@sifive.com, samuel.holland@sifive.com, Yu-Chien Peter Lin Subject: [RFC PATCH v3 5/6] lib: sbi: sbi_init: call sbi_hart_init() earlier Date: Sun, 30 Nov 2025 19:16:42 +0800 Message-ID: <20251130111643.1291462-6-peter.lin@sifive.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20251130111643.1291462-1-peter.lin@sifive.com> References: <20251130111643.1291462-1-peter.lin@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251130_031700_449966_FDA4066A X-CRM114-Status: UNSURE ( 7.64 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.1 (--) 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 sbi_hart_init() earlier in the initialization sequence, the function initializes reserved PMP regions before platform-specific early initialization. This allows platforms to call reserved_pmp_all [...] Content analysis details: (-2.1 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:430 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 sbi_hart_init() earlier in the initialization sequence, the function initializes reserved PMP regions before platform-specific early initialization. This allows platforms to call reserved_pmp_alloc() in their early_init hooks. Signed-off-by: Yu-Chien Peter Lin --- lib/sbi/sbi_init.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index bb449d49..88c2720e 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -262,11 +262,11 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) */ wake_coldboot_harts(scratch); - rc = sbi_platform_early_init(plat, true); + rc = sbi_hart_init(scratch, true); if (rc) sbi_hart_hang(); - rc = sbi_hart_init(scratch, true); + rc = sbi_platform_early_init(plat, true); if (rc) sbi_hart_hang(); @@ -421,11 +421,11 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch, if (rc) sbi_hart_hang(); - rc = sbi_platform_early_init(plat, false); + rc = sbi_hart_init(scratch, false); if (rc) sbi_hart_hang(); - rc = sbi_hart_init(scratch, false); + rc = sbi_platform_early_init(plat, false); if (rc) sbi_hart_hang(); From patchwork Sun Nov 30 11:16:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 2170238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=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 4dK4Hw40J1z1yCV for ; Sun, 30 Nov 2025 22:17:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=XyvJMcMvQbI3ysiQMcfwfEFihDLn5nqRKrM/BzVYdFk=; b=TmRdF+Q5of38Uf kXyhVEZMiQpEkymicJiW1mG/METgaFA/94RpzUOjmqF7WtpZqgNH3923Jtk9nCcJNk528XsLoxl42 LK0Z6p04uDnrdhfdeozOKCBQDA1kwZ9ZKEYj8b2HIOWu5ZnkeoK6ToorQ7GdDLp1pCJYG7tX/YoPy DwVL7rbhPdyicU3WRVHpSyRVvZDQXiR7uZjsfN/zMBDw5BX8Fy0IW1xsaqfF893i5QSNAY+qYscGA lJpaXyI4hBELKL7+mKEM1NUrmt3cSIpQO1dAaVSV0yScgF/tKHDTGW/tQFtyGCrkWXUOpjcI4fWZk q95lYdYuAALOn7GL8fvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQO-00000002FCu-0n5t; Sun, 30 Nov 2025 11:17:04 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPfQL-00000002FAz-1ACS for opensbi@lists.infradead.org; Sun, 30 Nov 2025 11:17:02 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-7bc0cd6a13aso1930087b3a.0 for ; Sun, 30 Nov 2025 03:17:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1764501420; x=1765106220; 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=hb7DazZJJNtRdWS53fRH8dKxkXF7Kg+wmNs9TAAIv+s=; b=FcmLLvQB2V+aoEj08EcgoEYQKnn+mJsKPIvaxee5KPvbe8xVpMHUA4TtzDE6ZkfB45 dy7n7bL2SoQm+Lj4dgMCrUKWqDjzLMUEzx/OCThiGYQ9SoDe8tgY+hPdMYKpHBop73cp 3QHzbm786IBwOv5we0xtDfOHHsIJ2MlIUXTzJIvDwtYcQ0PumEMgw39rubKWRTFuqoOr FbcfnwiKSKTzPpnzqKxQlRpvGgpsoTauAyH01aZ3UQxUD5NSoI3Y7OyX9ll3IF7dD3js K5AKaqKtUcGw/uged1DlzBooIB6/LMrGbsO6t9Yz6J/zax6Pv7ClQZBZt9l1VutbSBCJ yZFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764501420; x=1765106220; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=hb7DazZJJNtRdWS53fRH8dKxkXF7Kg+wmNs9TAAIv+s=; b=IqIBKP/5iEHwrPW0moOQ7WgWmy715rcyKwY9slKkPL6RO2Ls7BZy4fARwWIBasH70Z psswoFMCzPwZaHamwdSKsDGVz9lWX0+/TG0vBKq1a477eMbChV0LelDMRTrh5fb7wJVH 5tw7iv1F8lf6SKLv+x2TlDr26+tK16lPlG7BTKqOT7fb+XhkIHIdHyJH8VS13p6KNHuh nHjC9+zfVsAW/ZVnVSEySuR3OS7xId40z4i81kzVqzgeV7KVfnEOc3a/joTt21drQwxc PoeqRuzTWa0AlRhfRe+CPO/cGRHWt9YHevHz+ON8DBQYGFBwr0ByomAzq9AFjMzq7/HO 1Imw== X-Gm-Message-State: AOJu0YxtEEmXBzFSolZ535MrwDJjdZxpG30jZLdCHJ483Clca3NKWjvm hyiAJ4gbJwrvjM0ebYaGNR+5lDLhmg6F3z08tK1oStgROuSOoY7kB64O9GbsAd3vb4S1PUTJsk3 fEtG2cffJKbcnahOryT85F3sajKJtrhUmF17ddOPLoV3ld2AYKA3wDzg/VKv8WTMjRCeIz/BZ9d VYGsKHakfQK2U08YxpFa3bjJFvfcM/icj9v2frl4MnECQLRhG1 X-Gm-Gg: ASbGnctD9Q05/P5eSzCERiKTF68jQUMdZxOp3MRLm2v3OmXjlvnqLsf77tSjcUcXwjo JsaOZ3BurSjofRz8ne5S3b0hfh6iTq+6Lsi8QKBpbFoON3c7/7oot4u55ga6zPfBu2vmjPw39SL HqksH2uq+ZQ7tsi8IHRj9om5apS1bojukcvp5t38NV8omXUOmYqZo6YzFTcmlEjCh/bWaS8HzGe eqFUTUKOKPE/T8BO1HToxAnsUGp+207G9dPKfSVaGcCTy1mX+heiQGvqY7QJLAP3l97EMusALG+ asJIjCONxGyIzE3LpKhiCGtel2A/x0udyyUWimOxImicv0DtQmPtLDdO1Yz/tVYIxP66kPgyoIu hj4Gt0bQg7tEAXKTkgERiaG6DJovdSrI8dmFw9e59jq4SkbqpYTjmGazXFp+VDaCJueemWwECFM HufF5f/H8/viGH+L9Gve4qIeHYgY9Z9c/cuNnWiljEQk5f9A== X-Google-Smtp-Source: AGHT+IE91XdJ1r+dEjHmmOtgwDakDhz7TTvPAuxg4IuXo3VzPRMVysJuh00t7wGnB8bJo0GzurBRkQ== X-Received: by 2002:a05:6a00:1f0c:b0:783:44b9:cbc9 with SMTP id d2e1a72fcca58-7c41fbaf3b7mr39041477b3a.9.1764501420235; Sun, 30 Nov 2025 03:17:00 -0800 (PST) Received: from hsinchu16.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7d1819277c5sm10027050b3a.4.2025.11.30.03.16.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Nov 2025 03:16:59 -0800 (PST) From: Yu-Chien Peter Lin To: opensbi@lists.infradead.org Cc: zong.li@sifive.com, greentime.hu@sifive.com, samuel.holland@sifive.com, Yu-Chien Peter Lin Subject: [RFC PATCH v3 6/6] [TEMP] demonstrate hole protection using reserved PMP Date: Sun, 30 Nov 2025 19:16:43 +0800 Message-ID: <20251130111643.1291462-7-peter.lin@sifive.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20251130111643.1291462-1-peter.lin@sifive.com> References: <20251130111643.1291462-1-peter.lin@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251130_031701_368498_1A2F5020 X-CRM114-Status: GOOD ( 13.01 ) X-Spam-Score: -2.1 (--) 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 implementation shows how platforms can use the reserved PMP allocator to protect critical memory regions during early boot. Benefits of using reserved PMPs: 1) Reserved PMPs are not managed by domains - platforms have full control over them. Since reserved entries won't be freed, they can safely set lock bits (pmpcfg.L), u [...] Content analysis details: (-2.1 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:435 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 implementation shows how platforms can use the reserved PMP allocator to protect critical memory regions during early boot. Benefits of using reserved PMPs: 1) Reserved PMPs are not managed by domains - platforms have full control over them. Since reserved entries won't be freed, they can safely set lock bits (pmpcfg.L), unlike domain entries which must allow being temporarily revoked during context switches. 2) One can allocate 2 consecutive entries to create ToR mode regions to save PMP usage 3) The reserved PMPs have higher priority so their permissions are less likely to be overwritten by other entries Note: This is a demonstration patch and should not be merged. Signed-off-by: Yu-Chien Peter Lin --- platform/generic/sifive/fu540.c | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/platform/generic/sifive/fu540.c b/platform/generic/sifive/fu540.c index 83e57145..3f0fd032 100644 --- a/platform/generic/sifive/fu540.c +++ b/platform/generic/sifive/fu540.c @@ -8,6 +8,10 @@ */ #include +#include +#include +#include +#include #include #include @@ -20,9 +24,61 @@ static u64 sifive_fu540_tlbr_flush_limit(void) return 0; } +static u32 sifive_fu540_get_reserved_pmp_count(void) +{ + /* + * Reserve an entry for demonstrating hole protection + * on SiFive FU540. + */ + return 1; +} + +// This is a demonstration of PMP-based memory protection rather +// than protecting an actual memory hole. +static int sifive_fu540_hole_protection(void) +{ + int rc; + unsigned int pmp_id; + + rc = reserved_pmp_alloc(&pmp_id); + if (rc) + return rc; + + /* + * Protect the memory hole at 0x0 - 0x1000 by setting + * it as inaccessible (no R/W/X) with the lock bit set. + * This prevents any access to this region in all modes. + */ + rc = pmp_set(pmp_id, PMP_L, 0x0, 12); + if (rc) { + reserved_pmp_free(pmp_id); + return rc; + } + + return 0; +} + +static int sifive_fu540_early_init(bool cold_boot) +{ + int rc; + + /* Set up memory hole protection */ + rc = sifive_fu540_hole_protection(); + if (rc) + return rc; + + rc = generic_early_init(cold_boot); + if (rc) + return rc; + + return 0; +} + static int sifive_fu540_platform_init(const void *fdt, int nodeoff, const struct fdt_match *match) { generic_platform_ops.get_tlbr_flush_limit = sifive_fu540_tlbr_flush_limit; + generic_platform_ops.get_reserved_pmp_count = sifive_fu540_get_reserved_pmp_count; + generic_platform_ops.early_init = sifive_fu540_early_init; return 0; }