From patchwork Mon Sep 23 00:45:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 11155967 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D47F14ED for ; Mon, 23 Sep 2019 00:45:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1ABFD206C2 for ; Mon, 23 Sep 2019 00:45:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="St2r8TNc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="PmBToTGz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1ABFD206C2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0JpuIZA4nq0pZAoa65WrmzladS+qMP7k+zB0oBYXeBA=; b=St2r8TNc8FhaOenVgGUirxjUGF oBs66+Wy/M4czDAt0XcbdIupLYrOYEezFZt6hWIYMQy204r4oObq12noa7U3pL7afuwwv9mqdNGof M/zwzhFda5BYWkzJL3L76tSmTsU+bEtT6p6xOX9m2vnCUe/pJ0Qt19Z5HiVilHKARWrQ7rZ1PrU+U q1lx1JL9+/dpkXdGnBIPyUIjzpqfgoZPmZ6L/SkzdO8154KN5Bb5ydYyG8Ev+2+RICTN6BRvNCrkq g5qMaCtrShT/3f/Gsb+OqIw8gQ812nm0g5oqYNf5ecBogQ3BCFKwzjgxnDNsH9nQnNPxBmX/w3uXV +GV7aAgw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCCTz-00032p-7d; Mon, 23 Sep 2019 00:45:39 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCCTv-0002zw-Lz for linux-riscv@lists.infradead.org; Mon, 23 Sep 2019 00:45:37 +0000 Received: by mail-pf1-x444.google.com with SMTP id x127so8028852pfb.7 for ; Sun, 22 Sep 2019 17:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Xe6w22bWITBFPjRp++ggW69XwtTJrJMismAgnjjWSps=; b=PmBToTGz0+dZ/glKnK/OlEoCj1mNWi/zbC2c9P4ZtOaJh5w3AQinn0yAoCpOrlmf86 2m5U4WdDZn+vS7w6Sv06LAsngXesLM1oS1JbpoEkBq6R/k+gspCkfd/qRezSZbNlZxnD RIu54SEfR/BFLOqT7EwmoUeQ+E7JKNB73Agv7weHGFxcum3Gd2B+RAziKVcZC+eVPZaI qqQTsI9BGvWjYhqxWwpQ1JupMfdd8tqP6hCswZQdzlJanzfkDS84qxBBoDDdENWsZAdw uQBS/uv0EH5hERpRmTpVZWPVD5mi6v3VihJsIxwUiFqMGqKozQ5cEm4KxBnpjvW54buN Wibw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Xe6w22bWITBFPjRp++ggW69XwtTJrJMismAgnjjWSps=; b=q6D9eZ/VavyNUqEIrLy02r9hVNZ8jLikPygu/cvtE3AVffOUS9PR03c1f0QmlbgVn+ ckIt7UlNDkS1+jBBAEARTErxRQkhCbyw5KX6gvE8Ptbq7q4N3sfFOXbjl19yDlu96Hpy xKt4kk8jf2PbohQfqtoY6bBsDX55r0TUdVbTKo38Yet/mIbn7K0YkSmFVVRyGGJ3t0Fn ZXjRMqfu+A7Z+Eje1Qtek/Af1uWbWcCadDGwNF8TWE0hRJCGMUjPUzRDOOyzfu5YxRVT bPkL8amYKZvjGg0f957UgMEPkvH9SIK9vUWYbVUp8cnitF3fCIZxc1yUXixS6QqP3wOU Llzw== X-Gm-Message-State: APjAAAVHWaMG7jLlJ7ifqFGxX5qpVWO9LrlCj5hcXyo5x2rvqbe3hY3V ZPNls/PrOPXCh56RDxucWMuo4qZaCD4= X-Google-Smtp-Source: APXvYqxg4RUC/k2zKdp20whugiWXsLNyuWV+p9lSYD7axTO2cCrPhiQ6pzUiMr0f5rXmVr+g0e8oZA== X-Received: by 2002:a17:90a:2464:: with SMTP id h91mr18803713pje.9.1569199534032; Sun, 22 Sep 2019 17:45:34 -0700 (PDT) Received: from localhost.localdomain (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id l7sm9139392pjy.12.2019.09.22.17.45.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Sep 2019 17:45:33 -0700 (PDT) From: Vincent Chen To: linux-riscv@lists.infradead.org Subject: [PATCH 1/4] riscv: avoid kernel hangs when trapped in BUG() Date: Mon, 23 Sep 2019 08:45:14 +0800 Message-Id: <1569199517-5884-2-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com> References: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190922_174535_837498_4E2ADA9E X-CRM114-Status: GOOD ( 12.75 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) 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:444 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 Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vincent.chen@sifive.com, palmer@sifive.com, linux-kernel@vger.kernel.org, aou@eecs.berkeley.edu, paul.walmsley@sifive.com MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org When the CONFIG_GENERIC_BUG is disabled by disabling CONFIG_BUG, if a kernel thread is trapped by BUG(), the whole system will be in the loop that infinitely handles the ebreak exception instead of entering the die function. To fix this problem, the do_trap_break() will always call the die() to deal with the break exception as the type of break is BUG_TRAP_TYPE_BUG. Signed-off-by: Vincent Chen Reviewed-by: Christoph Hellwig --- arch/riscv/kernel/traps.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 424eb72d56b1..055a937aca70 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -124,23 +124,23 @@ static inline unsigned long get_break_insn_length(unsigned long pc) asmlinkage void do_trap_break(struct pt_regs *regs) { -#ifdef CONFIG_GENERIC_BUG if (!user_mode(regs)) { enum bug_trap_type type; type = report_bug(regs->sepc, regs); switch (type) { +#ifdef CONFIG_GENERIC_BUG case BUG_TRAP_TYPE_NONE: break; case BUG_TRAP_TYPE_WARN: regs->sepc += get_break_insn_length(regs->sepc); break; case BUG_TRAP_TYPE_BUG: +#endif /* CONFIG_GENERIC_BUG */ + default: die(regs, "Kernel BUG"); } } -#endif /* CONFIG_GENERIC_BUG */ - force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)(regs->sepc)); } From patchwork Mon Sep 23 00:45:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 11155969 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D70514ED for ; Mon, 23 Sep 2019 00:45:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0B46820830 for ; Mon, 23 Sep 2019 00:45:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Qzyc6bFH"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="KscoU/sk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B46820830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=uqFXIx3jRzrxEa6UIVjnb48NiCCtorU34Q3t7fGt7Cw=; b=Qzyc6bFHkvxGvhbubLmU/jSu2V WR/zeq5YqHe0noEcYHu/BQDPeEsMJmWRLnhqwObYUxtZEUlnCDj2pLMHFl10S0SJLa0QWhWSyvgJ3 /hpa0bt55KJUx9ob05sx1WbhJ2LSSvPKKMRVEJTiheTBqRP6xnBGjfmBBRUH0eaop3WIpUBHV2Wv4 XLOTqxieN+7kLO7P6A1/Xu95ypD4yhCn5E2c/V/sEfrqq3Y783aPiafuIWg/oqeLx0kxr+tBFzdyR hWVE7rRuhZBXztjgqGYA2jNHb5CePZQzqHo+ULEFdYdyzDiG8P7RiEMj63wTqF4Rp3cyksDsYwNqq v+oNElZw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCCU2-000366-2h; Mon, 23 Sep 2019 00:45:42 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCCTy-00031S-ID for linux-riscv@lists.infradead.org; Mon, 23 Sep 2019 00:45:39 +0000 Received: by mail-pl1-x643.google.com with SMTP id t10so5739190plr.8 for ; Sun, 22 Sep 2019 17:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Chejk/4+FmCtrFrzQ3cdh4eTfnbOVSILTOMfH5BS3rg=; b=KscoU/skknCbbY8YZs5H+cAOddHExj4kT3l2GqX65Qs42T2g2BLJ54/9rRxImmw1UJ 4T+vSMp30+jX7EQr7yLlnw1/JMWgD1jPDci+wH8ngsQUbX4sOABn5I6dcBkOO1Q2eVAm MM/HVsl6/x48oqbevT5I/loUiE1aaPKLNzNxdzPT+wjfs6/aFJl4CPxyN2uTncujwFEG RQhmbpjr/TruZWtqmbjS3M+ObiSvMNaBcUCcY1cUu2v5Kr9hJFHGVj4JOZD91LiZKs0Z 3KBUDZghfRVtT/2ak7BUWOsBhPvJwTL74as+9gWJsXjF0GvvNKGQG1lWKJq006JrUP5m DLHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Chejk/4+FmCtrFrzQ3cdh4eTfnbOVSILTOMfH5BS3rg=; b=efLooCEM0adgbvylx8wIS1fX6A5J/Ok7xhbHyxiyCdXp5t2rRZhvUkdHP2KuEa7taR URhNLSu8de5QCBwXim+/fmrkuh6vqJTTUxAXHVY5dQIS1w6fXeVSo7q+q7/dbWE4Fj8k 1kp7qJjipOP4XOG4R81QYDqgU5IqJCMvyNLxjs8UuHIYaEuJpQ3elbddh7/9LsULLxvl E9mIX+BSG5pRXCh/xCqeZbKBiV4FPR/y8r7x37QHU9VSvdrgtdPPL20g8sMonH02gXRn Pj8C04Lz3HJHQxTzoFM5OMQ3rlU39O6zqe9JyZL5x6Q4goDUBFa7F+g7XtmFWS26ECwC ztdA== X-Gm-Message-State: APjAAAX/LN6BdX/roRj+73CohyStfRF0n27PmgmbSJwanxUZ1JwaFnfP TmY0h0qXGmjEw7IKQp2ybOmW06Fz+2g= X-Google-Smtp-Source: APXvYqxTVhkh+52M6mkBzcoHkL548c6/8rX+BxMVIXbVMNx8toD/c9dkZqmokUYv/q5COofkwXP/Tg== X-Received: by 2002:a17:902:7615:: with SMTP id k21mr28543207pll.116.1569199537599; Sun, 22 Sep 2019 17:45:37 -0700 (PDT) Received: from localhost.localdomain (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id l7sm9139392pjy.12.2019.09.22.17.45.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Sep 2019 17:45:37 -0700 (PDT) From: Vincent Chen To: linux-riscv@lists.infradead.org Subject: [PATCH 2/4] rsicv: avoid sending a SIGTRAP to a user thread trapped in WARN() Date: Mon, 23 Sep 2019 08:45:15 +0800 Message-Id: <1569199517-5884-3-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com> References: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190922_174538_633078_0EE2E590 X-CRM114-Status: GOOD ( 12.14 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) 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:643 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 Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vincent.chen@sifive.com, palmer@sifive.com, linux-kernel@vger.kernel.org, aou@eecs.berkeley.edu, paul.walmsley@sifive.com MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org On RISC-V, when the kernel runs code on behalf of a user thread, and the kernel executes a WARN() or WARN_ON(), the user thread will be sent a bogus SIGTRAP. Fix the RISC-V kernel code to not send a SIGTRAP when a WARN()/WARN_ON() is executed. Signed-off-by: Vincent Chen Reviewed-by: Christoph Hellwig --- arch/riscv/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 055a937aca70..82f42a55451e 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -134,7 +134,7 @@ asmlinkage void do_trap_break(struct pt_regs *regs) break; case BUG_TRAP_TYPE_WARN: regs->sepc += get_break_insn_length(regs->sepc); - break; + return; case BUG_TRAP_TYPE_BUG: #endif /* CONFIG_GENERIC_BUG */ default: From patchwork Mon Sep 23 00:45:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 11155971 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F016C14E5 for ; Mon, 23 Sep 2019 00:45:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CCEA120830 for ; Mon, 23 Sep 2019 00:45:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FDbztTzY"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="fO39l9GW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCEA120830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=VDQg/aZZrhX1GTmmwpqicLb2bMzz+7UquBl3XO8W7LM=; b=FDbztTzY+H3XzuzlLdbQ8tiaMr C9FVrmykbW3K4dVGdND2gGboCitwUqZoGuACnMqTtWHSFDmF/HiaRz8Qp+AojWrWOvnR7iRcxOhrr 51bH4YuE2gBrKpx+mCcvWR5iPg+dxvuFZ/Jkz+Rr51fmBMBoiexTUlxmoT6TcKFtBJ/IH6Z86Z2Qz lp6wTorD1k0ZTCXoTVfW7iYXuZsYzMDBI7uIzgKu8BkSu8xCCdfkGLfm+maYs7KXYff9NQ0zJnvUQ esPoXeeLXOHO09PS/M43kU2ITIES8taeqmGlXLnptq2bIrbV0e6z0OeXiBnn+siGlyRnro826NxT/ Ne3zfiZA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCCU4-00038O-Ad; Mon, 23 Sep 2019 00:45:44 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCCU0-00034E-Nu for linux-riscv@lists.infradead.org; Mon, 23 Sep 2019 00:45:42 +0000 Received: by mail-pf1-x443.google.com with SMTP id q10so8063505pfl.0 for ; Sun, 22 Sep 2019 17:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=etFOng1NSMlGr92KlrcTFVrPRQRxbWjcN6/2wjvKnb8=; b=fO39l9GWblA4imhZOOmvXoFwH2V9A46JomP+wWxqplazbuPQxOAopvpwuMhDz6+x// EZ9rQ7jQojULwJl45Z2YA4CLQBGA2Jn5knfHZ7Pv5jo+e2v2yqE5fpO7/po15yIHZdCe xVSpfdNL9/no1QTzYtU6kdrZdi/+LCclix77edyqL21dMfqYMzz0rb7U97Xe+ABc8oYp QezHxT/VqeF0XVKX/v0ibo+OZvYy73cTFqwx4nSPIZryN5qI2C4KsTdV8bSHwKyxLMAJ S+f7Lh5dyiSl7RUB5rvKJwyaLNAZV8lddPDa/LksDBbMylUeVdBhOWw7CypoQVvDwrSy o8EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=etFOng1NSMlGr92KlrcTFVrPRQRxbWjcN6/2wjvKnb8=; b=I+Xan9JAN1Tz+krbecbTi7w1dGQr4r4UzTWhN9+jiF7eWrf3Mrdu7rkzNlOoRF/cbM lYcBp400TgSsqkQTjTpkkvO1e/3g4tMlH+5brAryQ3LRXM9rxW6sTzhSEyWYtxKpjNrK DRV9sPQNcr4E5x5VKy29QznJHhjcotEquu6JSSqRNSegcLeVPj2aA+4R4ICY5Ld/B48X 5o1jnKJ7I1+rqEiAOhXS3hA49Neb5SoX6YObwhFrAM4TrwIYsQ2aEDPyMMjBBqVUrXDS 2SaN7EqwIc+02lBC84Y7lNue9BRNsJM/HP00jYhiie/50XDtyh9ZG8vsI0DRrGj+0OkQ mBPQ== X-Gm-Message-State: APjAAAV2KhmIZFqGuDyaaqEp0qmbrbsGrO+PeonEP/T1hOzpH2LiIEFW 6tJFTzjN4dPXfhLBXqmpHsPkFzFCyzE= X-Google-Smtp-Source: APXvYqyxP0lWJyTG/EzXGCE+z0Ba/ovVgEyGLWvJbKiSiuNzBkE6CXeRmeSRUIIaJY5Qr03rNmPIog== X-Received: by 2002:a62:8702:: with SMTP id i2mr30820956pfe.187.1569199540103; Sun, 22 Sep 2019 17:45:40 -0700 (PDT) Received: from localhost.localdomain (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id l7sm9139392pjy.12.2019.09.22.17.45.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Sep 2019 17:45:39 -0700 (PDT) From: Vincent Chen To: linux-riscv@lists.infradead.org Subject: [PATCH 3/4] riscv: Correct the handling of unexpected ebreak in do_trap_break() Date: Mon, 23 Sep 2019 08:45:16 +0800 Message-Id: <1569199517-5884-4-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com> References: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190922_174540_811433_4C647ABE X-CRM114-Status: GOOD ( 10.07 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) 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:443 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 Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vincent.chen@sifive.com, palmer@sifive.com, linux-kernel@vger.kernel.org, aou@eecs.berkeley.edu, paul.walmsley@sifive.com MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org For the kernel space, all ebreak instructions are determined at compile time because the kernel space debugging module is currently unsupported. Hence, it should be treated as a bug if an ebreak instruction which does not belong to BUG_TRAP_TYPE_WARN or BUG_TRAP_TYPE_BUG is executed in kernel space. For the userspace, debugging module or user problem may intentionally insert an ebreak instruction to trigger a SIGTRAP signal. To approach the above two situations, the do_trap_break() will direct the BUG_TRAP_TYPE_NONE ebreak exception issued in kernel space to die() and will send a SIGTRAP to the trapped process only when the ebreak is in userspace. Signed-off-by: Vincent Chen Reviewed-by: Christoph Hellwig Signed-off-by: Vincent Chen Reviewed-by: Christoph Hellwig Signed-off-by: Paul Walmsley --- arch/riscv/kernel/traps.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 82f42a55451e..dd13bc90aeb6 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -130,8 +130,6 @@ asmlinkage void do_trap_break(struct pt_regs *regs) type = report_bug(regs->sepc, regs); switch (type) { #ifdef CONFIG_GENERIC_BUG - case BUG_TRAP_TYPE_NONE: - break; case BUG_TRAP_TYPE_WARN: regs->sepc += get_break_insn_length(regs->sepc); return; @@ -140,8 +138,9 @@ asmlinkage void do_trap_break(struct pt_regs *regs) default: die(regs, "Kernel BUG"); } - } - force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)(regs->sepc)); + } else + force_sig_fault(SIGTRAP, TRAP_BRKPT, + (void __user *)(regs->sepc)); } #ifdef CONFIG_GENERIC_BUG From patchwork Mon Sep 23 00:45:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 11155973 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5FC7F14E5 for ; Mon, 23 Sep 2019 00:45:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3D9F520830 for ; Mon, 23 Sep 2019 00:45:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="h7tAfqqp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="hXoD43kB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D9F520830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=t1W3S7HCu7xvDZuAQQaCQj0IopBxzKxLc6WQWZFAikA=; b=h7tAfqqpM0rP9Z+E20yS0bxyJI PGk6WLQOYOstajAkVs2GQyRwuuG0K330abugy+AyZm+m2prOR4jD7o734FLrwmlvffwGk18iq0OlP YwrPckL7jgp/sl6VP0VwKQZsLEDGVS3rGqhu7Jl+v6TwBMoLhZQ7h8eEyBf2IfOJGNcHRmJMtiSpa NrjLar9wWXfzK5zwwMpGGvWoOi4MV59Zge6zpm1zgJpxh7/XyxrNOymwm7CQlJStE64HZTheWmo8E 6FEDOAJ4IWBikHBww4TzoCTQdcPwWpYdtN6bVc0arBcr+W075wneGwIyKp6i3RJtb2QRNkH0+HXuk kc0mx9sw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCCU7-0003CK-6h; Mon, 23 Sep 2019 00:45:47 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCCU3-00037v-PV for linux-riscv@lists.infradead.org; Mon, 23 Sep 2019 00:45:45 +0000 Received: by mail-pf1-x443.google.com with SMTP id h195so8038491pfe.5 for ; Sun, 22 Sep 2019 17:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UolwQ0cu1AA/iqmfvkDUCTBOg9ROKFLAkl4FEYmNIH4=; b=hXoD43kBut3QYuGcML4svtO79QqkxZYAVBXnKO/MGgHR7hUFpdqDHXUJGqyaVrLgy8 DV7LV4TDe25ilVZwic5rdkCoG36xzbvnsyDAcZsmn3TF8Zo8azceRpEYc5ClD3aIxN2/ JunGFRWlnM9kuuljFmHzGYIxjGlCFWRkpdYwwhybOYG5dEcM6CeW40BlGLSIy7ueA3mr WFUDYTk7xrOAoLiYIzMoYVBFKibNFwTQOmi2eQeKfo/t5Kj85U18yRcW+yBMTolXDtwa ZkDjGGuWYQyeY7/xz4KVbi0dPEV/JWJPsHWL8R85YWjsh1Zl+7xwEExciAZIgcFImdvk r9xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UolwQ0cu1AA/iqmfvkDUCTBOg9ROKFLAkl4FEYmNIH4=; b=WVJUMY49XKksHJFELlNI6bfvpFttBIg6wKFeL3MlgEm82LTwjy1f+QQ18G1GAybvl7 +ZW6RPxGK3KOQq6vWuqKswoOgSyU6O4Rl8UuITqzdx+zqJuh+NwfM3W2y4sxa4VjLsyc Wa6p61ln39Q61xwrgJOtNqrPtrehrkpxTyA532/+Z1eAS6u4lKDhwgy/G0MyHkHKKXUV zM3peFjJXdEXPL2zHCzY5adR/Lc0zsrN8coo75HuOXgiq4psD+rAkA+JLQktyKyrECVy ZJVJKXa5C+U45JopOTeXlAdEZPsRz6a2eV8hbfhzV8chSZP0zmKFl+5ZnDXzroNiAmb6 8gtA== X-Gm-Message-State: APjAAAVDDPqSCMpvSDQT52jmBXX2cu2aWbfIQaJaUyzKAVQ7Vzdr0W24 xOiTi4D4r6UP+72AtayH0XfqP/NTJ4M= X-Google-Smtp-Source: APXvYqxgCsJWq73K4bZZuZ4ncyptKJaUKhytI6kBAarKqVdUsqYNrPKgHKP33BPUTwHvpg2aedoTFQ== X-Received: by 2002:a65:5a84:: with SMTP id c4mr26598583pgt.261.1569199543088; Sun, 22 Sep 2019 17:45:43 -0700 (PDT) Received: from localhost.localdomain (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id l7sm9139392pjy.12.2019.09.22.17.45.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Sep 2019 17:45:42 -0700 (PDT) From: Vincent Chen To: linux-riscv@lists.infradead.org Subject: [PATCH 4/4] riscv: remove the switch statement in do_trap_break() Date: Mon, 23 Sep 2019 08:45:17 +0800 Message-Id: <1569199517-5884-5-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com> References: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190922_174543_878243_87AE510E X-CRM114-Status: GOOD ( 11.43 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) 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:443 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 Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vincent.chen@sifive.com, palmer@sifive.com, linux-kernel@vger.kernel.org, aou@eecs.berkeley.edu, paul.walmsley@sifive.com MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org To make the code more straightforward, replacing the switch statement with if statement. Suggested-by: Paul Walmsley Signed-off-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Paul Walmsley --- arch/riscv/kernel/traps.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index dd13bc90aeb6..1ac75f7d0bff 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -124,23 +124,24 @@ static inline unsigned long get_break_insn_length(unsigned long pc) asmlinkage void do_trap_break(struct pt_regs *regs) { - if (!user_mode(regs)) { + if (user_mode(regs)) { + force_sig_fault(SIGTRAP, TRAP_BRKPT, + (void __user *)(regs->sepc)); + return; + } +#ifdef CONFIG_GENERIC_BUG + { enum bug_trap_type type; type = report_bug(regs->sepc, regs); - switch (type) { -#ifdef CONFIG_GENERIC_BUG - case BUG_TRAP_TYPE_WARN: + if (type == BUG_TRAP_TYPE_WARN) { regs->sepc += get_break_insn_length(regs->sepc); return; - case BUG_TRAP_TYPE_BUG: -#endif /* CONFIG_GENERIC_BUG */ - default: - die(regs, "Kernel BUG"); } - } else - force_sig_fault(SIGTRAP, TRAP_BRKPT, - (void __user *)(regs->sepc)); + } +#endif /* CONFIG_GENERIC_BUG */ + + die(regs, "Kernel BUG"); } #ifdef CONFIG_GENERIC_BUG