Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4489563ybp; Mon, 7 Oct 2019 09:11:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqyrIK8QTMh16+eSODqnO4bDDlOY/oRC3UjnY32kloU5cOdRhymiynmp8p30DYuJAmAod68F X-Received: by 2002:a50:fd10:: with SMTP id i16mr30492887eds.239.1570464700013; Mon, 07 Oct 2019 09:11:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570464700; cv=none; d=google.com; s=arc-20160816; b=nh/w29aWlIspuXLdQp2Twy2G7gRj2sgvr6dyE5Lg1ZJCYy6MLN9PDR/RpLpcvncJPF njM/5/nhGwW85JO5DEgFq02ZzHPlXofWTkOO+AjX+yz6kQ1sv2eidt5b/BsjCj2YKfKi 95paqyUfl+kbCbTlSHaEyOk3g1gL+vDYjgLv3qJwbWtrFMN/joYG6dZSzqHsfboC122D tx8s420F6rueHzPcJaOEslvhmh2gfYRJ/PDHQz5h/Eztbg5iu0VikUlCn5wqhJV6qsnZ x0wNtHcTUuv7SmvnOcr0lXXQuQxy2BNWr1J55V/TyYlyniPiAbpQe4S15Veo0mJrgo53 Cg8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=OYnf5Eb8n9ykt/uD7msDqCGImCXIjmz3mqehpAtin5w=; b=n+aaxAaF445cXg9cU/N75PVnciJgbO1FlV0unbzV34rIXT3vyyM5z6c8za+8VrMYVf KCidNGOskcCwhJJ8qn4bDm7eQv2iOmYIClgzGZuux4f7cxFgFNNuem39KC4CJHtbIou/ 11VPq7CO8+cAV0p1KSWgP7AQ9jO95nMMgKxmwUTJx3EUpR+cAolD43gRl6tEXmik8Efy g1HzQCMVEfFJs6B0h1R/k09/Jox1zBdUVon+0bHhoMsAIkVRv4vyteUhiy7RWGbbAbWl p3u9H2hyTqIi+Xpe9KtTxaPtptt4cpOOfEXQSy3NjgEoFpnRkJ5zSoNsEAaLQRtsRlDP Skpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=i1yGJLhi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1si8511136ede.268.2019.10.07.09.11.16; Mon, 07 Oct 2019 09:11:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=i1yGJLhi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728634AbfJGQIZ (ORCPT + 99 others); Mon, 7 Oct 2019 12:08:25 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:32989 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727711AbfJGQIZ (ORCPT ); Mon, 7 Oct 2019 12:08:25 -0400 Received: by mail-io1-f67.google.com with SMTP id z19so29916643ior.0 for ; Mon, 07 Oct 2019 09:08:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=OYnf5Eb8n9ykt/uD7msDqCGImCXIjmz3mqehpAtin5w=; b=i1yGJLhiLyuMdojyTXTTab15PI1V480jrKDuDZL9zx2s46oSYkji95PIveIRZxXRvm JNOhyzE2x/SaKj9y0VqFm6ds+W6txWfFoYz9wBw8d9f6eo+OMEVxNl+gjjtZx++LvFOW ay1YMXKcJNTrjhrGkSxiqABUUzgTRSjIRsjNo2IQ89+kqwHJY4jnuCbOWXy4TQ30nrCx wZekK7T5a/L9b9D8dNZIYOEwEpXZgOAuzr5uQtmWYwCQfyv57dWxGD/D1WAbIPsgP3NZ pDemS16N8xJPf/hJUlo9oCOl8ouutkgwl2UU/YSeHP9u0VX3rVC1AXDqSyyaMnCtyd4a tywA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=OYnf5Eb8n9ykt/uD7msDqCGImCXIjmz3mqehpAtin5w=; b=jGBTsGKWE8+F/EUlfE9zNzf1fiBsdVtO2rPbyvnDR+3fsgF9+NRSS4hRbIMcKrcM4s PJMRZFwIEeNhwCAY+p6+zrkY1gUynZZTdfZSDuC0uYXnpvxSWQShnfvp0GuXrRu/JY9h b6YThYLXSBYLdEYD9Q5/B5Cm9A3tvBN1izQP2jwOVQJr0vSZ+Ai86DPIFPF0xXdOnTq0 eHbLFDyVQdiuyqZ6bsMlUg/egOPzoQ09csmsm9jIIADfRpeYc9bbDz/2983B/mYfbi1v Jsxfef6nJ7IKdsLZSa/zdod5e0etX9hTV0K0wv2dCMqOTxU+WxE9ST+MawKB76jXvpfW Fg8w== X-Gm-Message-State: APjAAAXjr5PruQxCYmUUsUmSWLUmV5DQVzEGTOL+Yvub24Fw93mbTNxr uPFwa2q4iZpU7e/nGkqkb3G2IA== X-Received: by 2002:a02:c654:: with SMTP id k20mr27301575jan.96.1570464504223; Mon, 07 Oct 2019 09:08:24 -0700 (PDT) Received: from localhost (c-73-95-159-87.hsd1.co.comcast.net. [73.95.159.87]) by smtp.gmail.com with ESMTPSA id k66sm6121262iof.25.2019.10.07.09.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 09:08:23 -0700 (PDT) Date: Mon, 7 Oct 2019 09:08:23 -0700 (PDT) From: Paul Walmsley X-X-Sender: paulw@viisi.sifive.com To: Vincent Chen cc: Christoph Hellwig , linux-riscv@lists.infradead.org, palmer@sifive.com, linux-kernel@vger.kernel.org, aou@eecs.berkeley.edu Subject: Re: [PATCH 4/4] riscv: remove the switch statement in do_trap_break() In-Reply-To: <20190927224711.GI4700@infradead.org> Message-ID: References: <1569199517-5884-1-git-send-email-vincent.chen@sifive.com> <1569199517-5884-5-git-send-email-vincent.chen@sifive.com> <20190927224711.GI4700@infradead.org> User-Agent: Alpine 2.21.9999 (DEB 301 2018-08-15) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Vincent, On Fri, 27 Sep 2019, Christoph Hellwig wrote: > On Mon, Sep 23, 2019 at 08:45:17AM +0800, Vincent Chen wrote: > > To make the code more straightforward, replacing the switch statement > > with if statement. > > > > Suggested-by: Paul Walmsley > > Signed-off-by: Vincent Chen ... > I like where this is going, but I think this can be improved further > given that fact that report_bug has a nice stub for the > !CONFIG_GENERIC_BUG case. > > How about: > > if (user_mode(regs)) > force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)regs->sepc); > else if (report_bug(regs->sepc, regs) == BUG_TRAP_TYPE_WARN) > regs->sepc += get_break_insn_length(regs->sepc); > else > die(regs, "Kernel BUG"); > Christoph's suggestion looks good to me. What do you think about this modification to your patch? - Paul From: Vincent Chen Date: Mon, 23 Sep 2019 08:45:17 +0800 Subject: [PATCH] riscv: remove the switch statement in do_trap_break() To make the code more straightforward, replace the switch statement with an if statement. Suggested-by: Paul Walmsley Signed-off-by: Vincent Chen [paul.walmsley@sifive.com: removed CONFIG_GENERIC_BUG tests per Christoph's suggestion; cleaned up patch description] Cc: Christoph Hellwig Link: https://lore.kernel.org/linux-riscv/20190927224711.GI4700@infradead.org/ Signed-off-by: Paul Walmsley --- arch/riscv/kernel/traps.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 93742df9067f..45b82be00714 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -124,24 +124,13 @@ static inline unsigned long get_break_insn_length(unsigned long pc) asmlinkage void do_trap_break(struct pt_regs *regs) { - 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_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 { + if (user_mode(regs)) force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)(regs->sepc)); - } + else if (report_bug(regs->sepc, regs) == BUG_TRAP_TYPE_WARN) + regs->sepc += get_break_insn_length(regs->sepc); + else + die(regs, "Kernel BUG"); } #ifdef CONFIG_GENERIC_BUG -- 2.23.0