From patchwork Mon Aug 14 11:36:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1820994 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ign+oIAd; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=Z+yzwM5b; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPXRq4TH1z1yfP for ; Mon, 14 Aug 2023 21:36:55 +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=3M++L9XhWw6J1yGflNH9j945VosXL84GD7J+yLMA8KQ=; b=ign+oIAdZ2HRci 5IaZCIO6GeYShRIEo8abaiu8m5Z7hBM2O0PsmOMimZm0LcbA9Y+GjDOT9tEy92Hx4JHTEaUx64qCK Xn18TAoUEAkhqLWTBTj0VxtcYaIklzQ3N+CvqkIkIMkwx1LJOdqnggZGkCLiBkOrlcLFz40wFhzL1 TzW0erxTwHZbrz0+Xdi+W3Fq5OCyUHcnVpeFz/SBa25y11dKOwUhjPq+yKh3eveVefgFAOCqP04P3 cFnqQEfl0C233Mf+jL298F+U1f2I9HtPsunv7f4+zdTXel1RNH7L2cojfAks/OGn/DizDBpQd0B7L nI+u8KcynpKkM1k9PJNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qVVsF-00Gy6W-34; Mon, 14 Aug 2023 11:36:39 +0000 Received: from m126.mail.126.com ([220.181.12.29]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qVVsC-00Gy5J-2n for opensbi@lists.infradead.org; Mon, 14 Aug 2023 11:36:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=5v8ZU /whGQzZBK0jCWiFrZkyosOMmpOmO4UJ27eJ6Qk=; b=Z+yzwM5by3CLXhVB51qvg cOk4r0AKGOzdCRmNZnICMmApJQ9/jI0LYS310G22iYTs+bn0FxmEFf7d2k68XpXa Os+dLjgKlIL6LwjrtrweQPs0PXkDg5to5N/OLRaLf4MsMe4Prr0EOD1U4LlbLTRf metiGcZbnr9v4MjSyDSEhI= Received: from t490.lan (unknown [210.22.74.39]) by zwqz-smtp-mta-g1-1 (Coremail) with SMTP id _____wBnbeG5Edpk9EaSBw--.11649S3; Mon, 14 Aug 2023 19:36:28 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v2 1/2] platform: Allow platforms to specify the size of tlb fifo Date: Mon, 14 Aug 2023 19:36:17 +0800 Message-Id: <20230814113618.153524-2-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230814113618.153524-1-wxjstz@126.com> References: <20230814113618.153524-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wBnbeG5Edpk9EaSBw--.11649S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxur1DXF4xWr4DAw1kXF47Arb_yoW5KFy8pF ZrCFn3Ka1xKFyxt34xAanruFWrGa1F9rWUKryjq34fAFyxXFn5JrnxJF4jyrnrJrs7Aay2 qFs2vr4UCF15ur7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zNksqLUUUUU= X-Originating-IP: [210.22.74.39] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiFx3LOlpEG-ZfQgABsU X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230814_043637_254762_C373E2F7 X-CRM114-Status: GOOD ( 11.93 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: For some platforms with a particularly high number of harts, if the tlb fifo is too small, it case harts to wait. Platforms should be allowed to specify the size of the tlb fifo. Signed-off-by: Xiang W --- include/sbi/sbi_platform.h | 29 +++++++++++++++++++++++++++++ include/sbi/sbi_tlb.h | 2 -- lib/sbi/sbi_tlb.c | 4 ++-- 3 files changed, 31 insertions(+), 4 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org For some platforms with a particularly high number of harts, if the tlb fifo is too small, it case harts to wait. Platforms should be allowed to specify the size of the tlb fifo. Signed-off-by: Xiang W --- include/sbi/sbi_platform.h | 29 +++++++++++++++++++++++++++++ include/sbi/sbi_tlb.h | 2 -- lib/sbi/sbi_tlb.c | 4 ++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 3e9616f..5929042 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -39,6 +39,8 @@ #define SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET (0x60 + __SIZEOF_POINTER__) /** Offset of hart_index2id in struct sbi_platform */ #define SBI_PLATFORM_HART_INDEX2ID_OFFSET (0x60 + (__SIZEOF_POINTER__ * 2)) +/** Offset of tlb_fifo_num_entries in struct sbi_platform */ +#define SBI_PLARFORM_TLB_FIFO_NUM_ENTRIES (0x60 + (__SIZEOF_POINTER__ * 3)) #define SBI_PLATFORM_TLB_RANGE_FLUSH_LIMIT_DEFAULT (1UL << 12) @@ -192,6 +194,15 @@ struct sbi_platform { * 2. HART id < SBI_HARTMASK_MAX_BITS */ const u32 *hart_index2id; + + /** + * For some systems with too many harts, too small tlb fifo + * may cause harts to wait. For such systems, this number + * can be increased. + * + * This value can be change in platform_override->fw_init + */ + u32 tlb_fifo_num_entries; }; /** @@ -243,6 +254,11 @@ _Static_assert( == SBI_PLATFORM_HART_INDEX2ID_OFFSET, "struct sbi_platform definition has changed, please redefine " "SBI_PLATFORM_HART_INDEX2ID_OFFSET"); +_Static_assert( + offsetof(struct sbi_platform, tlb_fifo_num_entries) + == SBI_PLARFORM_TLB_FIFO_NUM_ENTRIES, + "struct sbi_platform definition has changed, please redefine " + "SBI_PLARFORM_TLB_FIFO_NUM_ENTRIES"); /** Get pointer to sbi_platform for sbi_scratch pointer */ #define sbi_platform_ptr(__s) \ @@ -370,6 +386,19 @@ static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat, return true; return false; } +/** + * Get number of tlb fifo entries + * + * @param plat pointer to struct sbi_platform + * + * @return number of tlb fifo entries +*/ +static inline u32 sbi_platform_tlb_fifo_num_entries(const struct sbi_platform *plat) +{ + if(plat && plat->tlb_fifo_num_entries) + return plat->tlb_fifo_num_entries; + return 8; +} /** * Check whether given HART is allowed to do cold boot diff --git a/include/sbi/sbi_tlb.h b/include/sbi/sbi_tlb.h index 48f1962..55dcab0 100644 --- a/include/sbi/sbi_tlb.h +++ b/include/sbi/sbi_tlb.h @@ -20,8 +20,6 @@ /* clang-format on */ -#define SBI_TLB_FIFO_NUM_ENTRIES 8 - struct sbi_scratch; struct sbi_tlb_info { diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 26a87f3..92648da 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -422,7 +422,7 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot) return SBI_ENOMEM; } tlb_fifo_mem_off = sbi_scratch_alloc_offset( - SBI_TLB_FIFO_NUM_ENTRIES * SBI_TLB_INFO_SIZE); + sbi_platform_tlb_fifo_num_entries(plat) * SBI_TLB_INFO_SIZE); if (!tlb_fifo_mem_off) { sbi_scratch_free_offset(tlb_fifo_off); sbi_scratch_free_offset(tlb_sync_off); @@ -453,7 +453,7 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot) ATOMIC_INIT(tlb_sync, 0); sbi_fifo_init(tlb_q, tlb_mem, - SBI_TLB_FIFO_NUM_ENTRIES, SBI_TLB_INFO_SIZE); + sbi_platform_tlb_fifo_num_entries(plat), SBI_TLB_INFO_SIZE); return 0; } From patchwork Mon Aug 14 11:36:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1820993 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=a4VdeMRV; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=fHOyawR7; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPXRq43z1z1yfg for ; Mon, 14 Aug 2023 21:36:55 +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=Ju0KbPaldxS1Bc+yhWU8x0rliuL3ENLuUJKkxcBiQOo=; b=a4VdeMRVkcefgt eEeNCh1ev9g1ah8Mb4S12k1wmuyXnNNWzH/QlxD2WHgjFpuMiVuGc6JewnxCZQGSKP+zM6l5HsTTq yYtFUVDs3CBvfLLTGyPNm5bo+pH5xeEazwS2m8OghNVkea99F5B/PT+IO5EXf7MY700PH6s+/YjWg dTedcRItBm+KnLpoI3bvpEsgzyN/4GHaeBoxHeQuLjpDyFojTn3VJiy51VM38fmtZy9nMR8/T0Czb JEpzlwShQ1NIS5gTrbWMnNJaRqsUZvCeb01rFBTdkrDQafBJj/lur6BEGziX5TsaW4q/AnzXUVQmF V/9F3Ac9CWKvj6asiQ7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qVVsG-00Gy6m-27; Mon, 14 Aug 2023 11:36:40 +0000 Received: from m126.mail.126.com ([220.181.12.36]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qVVsE-00Gy5K-0I for opensbi@lists.infradead.org; Mon, 14 Aug 2023 11:36:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=CdIvN 05kMGiXJ8yLt28vyK9EFE+HieyIqwHOm78THAg=; b=fHOyawR7efmDKleh5APYd N+WBJcuNVa8v79dyx8ou9okGue7HAbnrcUI0zXorSHO/uEgZ/pRi8g1yRGc3R6AI tFMuTBZP9Vkq5dal+jq9SBaZm97Rpu5I4hgBCdYwuIHRhIeT2QRVkXFnMztThmOv YHRyQzjuLuYIxRx23MB84s= Received: from t490.lan (unknown [210.22.74.39]) by zwqz-smtp-mta-g1-1 (Coremail) with SMTP id _____wBnbeG5Edpk9EaSBw--.11649S4; Mon, 14 Aug 2023 19:36:30 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v2 2/2] lib: sbi: alloc tlb fifo by sbi_malloc Date: Mon, 14 Aug 2023 19:36:18 +0800 Message-Id: <20230814113618.153524-3-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230814113618.153524-1-wxjstz@126.com> References: <20230814113618.153524-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wBnbeG5Edpk9EaSBw--.11649S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kr4DAFykXrW8uFW7Jw4UXFb_yoW5JryfpF ZFkF1Dtr4IyrykKrW7Aa1DZryfK34v93y7Gryjgr95Ja4UZr1rJr93Ar1Ut3WkJrZIyw1a kwsFvryfuF15Gr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRY0PfUUUUU= X-Originating-IP: [210.22.74.39] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5B3LOlpEGjQ6ywABsI X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230814_043638_519610_BBC68913 X-CRM114-Status: GOOD ( 11.12 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: If the system is defined from tlb_fifo_num_entries, the scratch may be too small to hold the fifo, so it is alloc through the heap. Signed-off-by: Xiang W --- lib/sbi/sbi_tlb.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 RCVD_IN_MSPIKE_L3 RBL: Low reputation (-3) [220.181.12.36 listed in bl.mailspike.net] 0.0 RCVD_IN_MSPIKE_BL Mailspike blacklisted 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 If the system is defined from tlb_fifo_num_entries, the scratch may be too small to hold the fifo, so it is alloc through the heap. Signed-off-by: Xiang W --- lib/sbi/sbi_tlb.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 92648da..517ef90 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,6 @@ static unsigned long tlb_sync_off; static unsigned long tlb_fifo_off; -static unsigned long tlb_fifo_mem_off; static unsigned long tlb_range_flush_limit; static void tlb_flush_all(void) @@ -407,7 +407,7 @@ int sbi_tlb_request(ulong hmask, ulong hbase, struct sbi_tlb_info *tinfo) int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot) { int ret; - void *tlb_mem; + void *tlb_mem = NULL; atomic_t *tlb_sync; struct sbi_fifo *tlb_q; const struct sbi_platform *plat = sbi_platform_ptr(scratch); @@ -421,16 +421,16 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot) sbi_scratch_free_offset(tlb_sync_off); return SBI_ENOMEM; } - tlb_fifo_mem_off = sbi_scratch_alloc_offset( + tlb_mem = sbi_malloc( sbi_platform_tlb_fifo_num_entries(plat) * SBI_TLB_INFO_SIZE); - if (!tlb_fifo_mem_off) { + if (!tlb_mem) { sbi_scratch_free_offset(tlb_fifo_off); sbi_scratch_free_offset(tlb_sync_off); return SBI_ENOMEM; } ret = sbi_ipi_event_create(&tlb_ops); if (ret < 0) { - sbi_scratch_free_offset(tlb_fifo_mem_off); + sbi_free(tlb_mem); sbi_scratch_free_offset(tlb_fifo_off); sbi_scratch_free_offset(tlb_sync_off); return ret; @@ -440,7 +440,7 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot) } else { if (!tlb_sync_off || !tlb_fifo_off || - !tlb_fifo_mem_off) + !tlb_mem) return SBI_ENOMEM; if (SBI_IPI_EVENT_MAX <= tlb_event) return SBI_ENOSPC; @@ -448,7 +448,6 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot) tlb_sync = sbi_scratch_offset_ptr(scratch, tlb_sync_off); tlb_q = sbi_scratch_offset_ptr(scratch, tlb_fifo_off); - tlb_mem = sbi_scratch_offset_ptr(scratch, tlb_fifo_mem_off); ATOMIC_INIT(tlb_sync, 0);