From patchwork Wed Sep 15 09:03:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1528268 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: 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=vYkRdNTf; 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=eciiqcD0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H8Z5Q29Wrz9sRK for ; Wed, 15 Sep 2021 19:03:54 +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:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=R4OK3AgCBzFIfLDPf5d4YqnkLi5lDRGmUBMtzo/rHxo=; b=vYkRdNTfWkuADy 6wuC+xFViQNST33iOLizluSLzXL48woMiafuYyTwlmSsS+JicvR36eOwZ/zZNFUTLFznzFlGLv5qj gXCXEN1twkfnEPlCdvbgV849+Vf4Wlyoq+Md7bZ7AYBeISkmZdya//DAn6QsSzRbCvCWJ4gkxQNlH YEIlAABWPICWjWerlbhK1oCpMswbnXzt7/nBPd2zNoEzG3na8ogOOor/xuEF0lGmo15dwyF8RLzDZ RCSYS8IUTe/AL7x1dQn6A1ygsMGf43zQ8NmpHHjHUus4tH1jd6nhuhGOm4kHyp7BHx7izIPhjjyng 0AePJohYjC8FaAVPT/xw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQQpV-008aGF-D6; Wed, 15 Sep 2021 09:03:45 +0000 Received: from mail-m963.mail.126.com ([123.126.96.3]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQQpQ-008aE5-6i for opensbi@lists.infradead.org; Wed, 15 Sep 2021 09:03:43 +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=lg4L7 3vOoCvwi8gQi6SAs1Q0fROQsIqT92sQLIhpI3s=; b=eciiqcD0dpS9j0SKWVHUW He/SHDYigUxOiWUNvDuLM+nNiE1tcD1hCVGjDxHbOryw5mfcB/vmwVz2HGHZTpw8 wQHMrvDsfJbZYM0BVoprjWNG4H+5aUPVvYUg6aEjZYui+Vha0EWClLi0ufN69z61 gCX+AuxLsuh3CmCyKyAx+w= Received: from x390.lan (unknown [210.22.74.80]) by smtp8 (Coremail) with SMTP id NORpCgAn3VXntkFh6Mx1Pw--.21658S2; Wed, 15 Sep 2021 17:03:36 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: atish.patra@wdc.com, anup.patel@wdc.com, Xiang W Subject: [PATCH V2 1/2] lib: sbi: add some macros to detect BUG at runtime Date: Wed, 15 Sep 2021 17:03:29 +0800 Message-Id: <20210915090330.23354-1-wxjstz@126.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CM-TRANSID: NORpCgAn3VXntkFh6Mx1Pw--.21658S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7Wr4rJrWkXryDCF4UZr4xJFb_yoWDJrg_Aa srZ348GrsIvayvqFy2vFn8Jr4UKw4Fyr1DZF4Fqa9Ik3ZrK393G3Z5Kr9IqFW8Kr4kur4r uasrAryxCF15GjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUUznQUUUUUU== X-Originating-IP: [210.22.74.80] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1wgPOl53XChaXQAAsw X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210915_020340_734128_DF7A0D74 X-CRM114-Status: UNSURE ( 7.03 ) X-CRM114-Notice: Please train this message. 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: Two macros are mainly added. One is called BUG(), which is used to put in unreachable branches. One named BUG_ON, used for assertion. Signed-off-by: Xiang W --- include/sbi/sbi_console.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [123.126.96.3 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.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 Two macros are mainly added. One is called BUG(), which is used to put in unreachable branches. One named BUG_ON, used for assertion. Signed-off-by: Xiang W --- include/sbi/sbi_console.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h index e24ba5f..e75a279 100644 --- a/include/sbi/sbi_console.h +++ b/include/sbi/sbi_console.h @@ -11,6 +11,7 @@ #define __SBI_CONSOLE_H__ #include +#include struct sbi_console_device { /** Name of the console device */ @@ -51,4 +52,16 @@ struct sbi_scratch; int sbi_console_init(struct sbi_scratch *scratch); +#define BUG() do { \ + sbi_printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ + while (1) \ + wfi(); \ + __builtin_unreachable(); \ +} while (0) + +#define BUG_ON(cond) do { \ + if (!(cond)) \ + BUG(); \ +} while (0) + #endif From patchwork Wed Sep 15 09:03:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1528267 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: 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=EQ2hcyJ/; 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=buD2jcFv; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H8Z5Q2WMgz9sSn for ; Wed, 15 Sep 2021 19:03:54 +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=sgvkhKnoU8XbL4OPaoy5lFGpKTUX1LEN/K5H43M611Q=; b=EQ2hcyJ/vxsHZc SSNhV752gxqLdYVYgN5i0iTVIx3ZAIjbSTGZcNNY0LVzjGOnlLlX8SaL2peQ/Y+ipGnUsveGR3LOG NQM8G8P46y3yPODDERZQn0skYTTCjawHHfQoF9EjkFChVJZKZ/vriTTCH5Fxi4pSE4QE4+GV7+r5B MS7snqMRT29eza83wjfFth59MLGlEXBozOeF6iyCyszLAuqohZPrLEyeI0FQviDKKTltp8XIK2dpl zuua20yg+ppUnqM5kqjFz6y/QJdXPz1T99mJ6v6up36Om6jshjLkf27JwFMugkYZqWAzk1WU1rHq8 zypsDDZvJ/sftcNia75w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQQpX-008aH7-Ix; Wed, 15 Sep 2021 09:03:47 +0000 Received: from mail-m963.mail.126.com ([123.126.96.3]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQQpT-008aFR-Mi for opensbi@lists.infradead.org; Wed, 15 Sep 2021 09:03:45 +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=lCtkD kT4aQJYtxgkT3iwg08h+ZSQPPykCbZWXIL8TNs=; b=buD2jcFvHBdy0vSWxUj6w QulG578H2Zmu/oIZVCDEJibiYRso1pqsGud9XRRko/IkGYSIte1vsVVq9bFxA7yy E1MwvFR5IlcsdKkWF9Srb3pyQ5ESog78JzNaYgw6/gvd3Gv30pr7N3DwvGQHfvm2 qRHOaZ6sSJofR9a2MvffYo= Received: from x390.lan (unknown [210.22.74.80]) by smtp8 (Coremail) with SMTP id NORpCgAn3VXntkFh6Mx1Pw--.21658S3; Wed, 15 Sep 2021 17:03:42 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: atish.patra@wdc.com, anup.patel@wdc.com, Xiang W Subject: [PATCH V2 2/2] lib: sbi: Add runtime bug detection for csr_read_num/csr_write_num/misa_string Date: Wed, 15 Sep 2021 17:03:30 +0800 Message-Id: <20210915090330.23354-2-wxjstz@126.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210915090330.23354-1-wxjstz@126.com> References: <20210915090330.23354-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: NORpCgAn3VXntkFh6Mx1Pw--.21658S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrtr45Gw15Cr1fXFy5WrWUtwb_yoWfAFg_Cr n3uw1xK3yDAF4qv3WUArWkArZ3t34rtF1UGa4Sqwn0gFyIkrW8Gw17t3srGF18uF1ftr4f ua4rJryfGry5WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUjTGQ3UUUUU== X-Originating-IP: [210.22.74.80] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi2Q4POlpECV2MrgAAsK X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210915_020344_189128_E9CCF78F X-CRM114-Status: UNSURE ( 6.41 ) X-CRM114-Notice: Please train this message. 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: Signed-off-by: Xiang W --- lib/sbi/riscv_asm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c index 4c24a51..281e50a 100644 --- a/lib/sbi/riscv_asm.c +++ b/lib/sbi/riscv_asm.c @@ -11,6 +11,7 @@ #include #include List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Xiang W --- lib/sbi/riscv_asm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c index 4c24a51..281e50a 100644 --- a/lib/sbi/riscv_asm.c +++ b/lib/sbi/riscv_asm.c @@ -11,6 +11,7 @@ #include #include #include +#include /* determine CPU extension, return non-zero support */ int misa_extension_imp(char ext) @@ -75,6 +76,7 @@ void misa_string(int xlen, char *out, unsigned int out_sz) out[pos++] = '8'; break; default: + BUG(); return; } } @@ -134,6 +136,7 @@ unsigned long csr_read_num(int csr_num) #endif default: + BUG(); break; }; @@ -197,6 +200,7 @@ void csr_write_num(int csr_num, unsigned long val) switchcase_csr_write_16(CSR_MHPMEVENT16, val) default: + BUG(); break; };