From patchwork Wed Jul 24 15:31:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13741093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A34DC49EA1 for ; Wed, 24 Jul 2024 15:31:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.764283.1174653 (Exim 4.92) (envelope-from ) id 1sWdxf-0005SB-Gx; Wed, 24 Jul 2024 15:31:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 764283.1174653; Wed, 24 Jul 2024 15:31:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWdxf-0005RR-9Q; Wed, 24 Jul 2024 15:31:27 +0000 Received: by outflank-mailman (input) for mailman id 764283; Wed, 24 Jul 2024 15:31:26 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWdxd-0005Od-VT for xen-devel@lists.xenproject.org; Wed, 24 Jul 2024 15:31:25 +0000 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [2a00:1450:4864:20::233]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c892aca8-49d1-11ef-8776-851b0ebba9a2; Wed, 24 Jul 2024 17:31:23 +0200 (CEST) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2ee910d6a9eso10076811fa.1 for ; Wed, 24 Jul 2024 08:31:23 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ef26f1bc4asm14240491fa.40.2024.07.24.08.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 08:31:22 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c892aca8-49d1-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721835083; x=1722439883; darn=lists.xenproject.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=5G2pjQd0Lv6vwExyaSIrvv5vmUPPgawgWplARMvkx+E=; b=Mrsda4eaC9nBeobRf4UuXBCtazwOdLvRunCaoKrFLrrRil8deqV/VOHXtib2IjCNxq Io8YYc/gql/q1LD/E0nBK9gkyJiQ1uo05gPdXrpsFJiqe/hsqtwQCnJfPYqhth7ZjCDR 6jpBkpQTTpcivWE9JiP639wAWg4UkGmKGrX3DgNLQ1baoEWdnd55Bb4T0cKJANnIOPyk efSv49lg4GTJLIP1kqYdSFqEE1xtgQA0kV5oSTr1kV6EP204iphZEnnk/bZUjc70LNQs lLJg4f2ucqlHXCUpJFh/kgJNLukecDNokMpQCwL/Wsq7aqbZvPURKSijLVs4jTzD1NAY 1sYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721835083; x=1722439883; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5G2pjQd0Lv6vwExyaSIrvv5vmUPPgawgWplARMvkx+E=; b=bfif6kH84Yfz09kKanwZWERD5fSoz1GKCYuPNWWQp5bkDWHi/1LEedRR9g+OjWcv2R c7KurY01Zboxs21KEU0ZFinmTNsj2qemqklnXxuAhKbSXkCB1Ni9a5VYWeooDBRallLg 9apye8aeSZcMrt8YAMO279cXJ8qFgJOzFx1dMOsgE9KMQH1K8QSzOL3/q8ZKoDENgxcU xjIEhXRl0+ywr4GP99Ggapok5fdu8TiNWxYJtWl211+Xch7+C2UqRBuKzyBn89fuHMI8 lFBWV8zAi6lME/N4nm19XcByTfZofMDTs5K22tWot713xnemXu0SWhHvzOUNEVhAL7WV Gs3A== X-Gm-Message-State: AOJu0YxNmbKvpb/0y9ZcxNAXufGR3wEAH8BTJRlaAQNNHAmL5X5BkCt3 np2Cr8FiS0e1keckOrKPNQs1qzcKd7uHiLtYw3r6s5Kup8IfBTPRavJMGuk8 X-Google-Smtp-Source: AGHT+IEUnSTWoqw7sceknY8fvoknuG0Nuu+QDZ2ocZ66OWkjz85ttdEXvrTQKmznCSQhtObHHduKxw== X-Received: by 2002:a2e:b618:0:b0:2ee:daf3:5d30 with SMTP id 38308e7fff4ca-2f03a4f64a2mr154841fa.0.1721835082374; Wed, 24 Jul 2024 08:31:22 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Jan Beulich Subject: [PATCH v11 1/5] xen/riscv: use printk() instead of early_printk() Date: Wed, 24 Jul 2024 17:31:15 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 As common code is available it is better to use printk() instead of early_printk(). Also the printing of "Hello from RISC-V world" is dropped as it is useless and "All set up is enough". Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in V11: - Nothing changed. Only rebase. --- Changes in V10: - add Acked-by: Jan Beulich --- Changes in V9: - new patch --- xen/arch/riscv/setup.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 8bb5bdb2ae..e3cb0866d5 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -23,9 +23,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id, { remove_identity_mapping(); - early_printk("Hello from C env\n"); - - early_printk("All set up\n"); + printk("All set up\n"); for ( ;; ) asm volatile ("wfi"); From patchwork Wed Jul 24 15:31:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13741091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04393C3DA7F for ; Wed, 24 Jul 2024 15:31:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.764285.1174668 (Exim 4.92) (envelope-from ) id 1sWdxg-0005j7-6g; Wed, 24 Jul 2024 15:31:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 764285.1174668; Wed, 24 Jul 2024 15:31:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWdxf-0005gN-Vf; Wed, 24 Jul 2024 15:31:27 +0000 Received: by outflank-mailman (input) for mailman id 764285; Wed, 24 Jul 2024 15:31:27 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWdxe-0005Od-VV for xen-devel@lists.xenproject.org; Wed, 24 Jul 2024 15:31:26 +0000 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [2a00:1450:4864:20::22d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c91e95c8-49d1-11ef-8776-851b0ebba9a2; Wed, 24 Jul 2024 17:31:24 +0200 (CEST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2f01e9f53ebso26080041fa.2 for ; Wed, 24 Jul 2024 08:31:24 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ef26f1bc4asm14240491fa.40.2024.07.24.08.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 08:31:22 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c91e95c8-49d1-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721835084; x=1722439884; darn=lists.xenproject.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=56J2Umln9ekAx0H/k4L6hwTUoVJfEpVRZy78p69qzAA=; b=TM9Kz0hVSzv2cWqrhw/LUFZ2K4AFfGjTUEdSL9/UjLyI79bRCofPl2t/Zp68hq93M8 WsVH9ajq73i4cJwe2lvEPyhhH1VXvfrAh71ep89CouOuI034O5ygHmZf3CcCrLozFLbn vyNc101BXQNWzGrfCESfXfFzTNzFeNRM78wxPP6svNHWiAhuuDnWh+ZrcPW7rkgJ9Cko 2TZP8IOBHlvAkdIRmjylqbAu2HbUmh+76dRywtWuzW+rp2p10yn1gzdURpEQyN+p1Jjz Kg3ZqsaDVcxJzl37eMo+uZFv7k0bSP8YWGsJq3xG7RoQFGRDXSDc71jDsX+s+lMWJkwX ZMCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721835084; x=1722439884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=56J2Umln9ekAx0H/k4L6hwTUoVJfEpVRZy78p69qzAA=; b=KCjMVoDTeL7IOe55+V5wJYCj4d9jnxbjr35aEWnHaouJ8BiB7W+uDX4Ofe7L2T62kF fT9sAOA3t1c5tKRkENqkUA1/MBvKux7SB1nMwXdt/sJNZdx91BhbVQA/Cia2QCYzqlxs FJaFZ8HPlm+NTKFtjE9W9tSsOkuwyXcj4Ig0DbsPfg2sJts8UNggPUoqEqI0UikE6mhl 3V2HdYhXoMMfbaIhJIpaFbb/e22aJFWCp8mw9zhQfdiyrG7VzA08LaDX6tdBBUyS5oCP jbeg47mu/WQ77WlWlEndzQJTEzSzVLLnzqnWexSNT7mkvcGkN1FwzlOcgBQImXPnxnxZ CtZg== X-Gm-Message-State: AOJu0YxSlpClRgooC3dovsABtu7WWXmHVQAOe8jZXIk2fkjThPC8f+lb 2bV8kB8Ju50LF13p74LTnsT7ijTQ/YRKqYyNw2qRQmn5oz1KKuhh3Eo5P1f0 X-Google-Smtp-Source: AGHT+IH9oAwGr69eOcDYaniQ9eUobwcMuu+2onf6MtRizoPSP06ODrFSCoaTHWWIZx6UK06SxpUSUQ== X-Received: by 2002:a05:651c:b1e:b0:2ef:2c27:6680 with SMTP id 38308e7fff4ca-2f039c79ea1mr2186621fa.12.1721835083200; Wed, 24 Jul 2024 08:31:23 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Jan Beulich Subject: [PATCH v11 2/5] xen/riscv: introduce decode_cause() stuff Date: Wed, 24 Jul 2024 17:31:16 +0200 Message-ID: <335b0b49720b3524b6c89c5ce62d3377a4bb1fb8.1721731887.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 The patch introduces stuff needed to decode a reason of an exception. Signed-off-by: Oleksii Kurochko Acked-by: Alistair Francis Acked-by: Jan Beulich --- Changes in V11: - Nothing changed. Only rebase. --- Changes in V10: - add Acked-by: Jan Beulich --- Changes in V9: - This patch was reverted as breaks both release and randconfig builds. I don't see the failures now. ( probably it was because of printk usage which was not ready at that moment ). - drop inclusion of and - add for CAUSE_* in decode_trap_cause(). --- Changes in V8: - fix typo in return string from decode_reserved_interrupt_cause - add Acked-by: Alistair Francis --- Changes in V7: - Nothing changed. Only rebase. --- Changes in V6: - Remove usage of LINK_TO_LOAD() due to the MMU being enabled first. - Change early_printk() to printk() --- Changes in V5: - Remove from riscv/traps/c as nothing would require inclusion. - decode_reserved_interrupt_cause(), decode_interrupt_cause(), decode_cause, do_unexpected_trap() were made as static they are expected to be used only in traps.c - use LINK_TO_LOAD() for addresses which can be linker time relative. --- Changes in V4: - fix string in decode_reserved_interrupt_cause() --- Changes in V3: - Nothing changed --- Changes in V2: - Make decode_trap_cause() more optimization friendly. - Merge the pathc which introduces do_unexpected_trap() to the current one. --- xen/arch/riscv/traps.c | 80 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index 5415cf8d90..37cec40dfa 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -9,13 +9,91 @@ #include #include +#include #include -void do_trap(struct cpu_user_regs *cpu_regs) +static const char *decode_trap_cause(unsigned long cause) +{ + static const char *const trap_causes[] = { + [CAUSE_MISALIGNED_FETCH] = "Instruction Address Misaligned", + [CAUSE_FETCH_ACCESS] = "Instruction Access Fault", + [CAUSE_ILLEGAL_INSTRUCTION] = "Illegal Instruction", + [CAUSE_BREAKPOINT] = "Breakpoint", + [CAUSE_MISALIGNED_LOAD] = "Load Address Misaligned", + [CAUSE_LOAD_ACCESS] = "Load Access Fault", + [CAUSE_MISALIGNED_STORE] = "Store/AMO Address Misaligned", + [CAUSE_STORE_ACCESS] = "Store/AMO Access Fault", + [CAUSE_USER_ECALL] = "Environment Call from U-Mode", + [CAUSE_SUPERVISOR_ECALL] = "Environment Call from S-Mode", + [CAUSE_MACHINE_ECALL] = "Environment Call from M-Mode", + [CAUSE_FETCH_PAGE_FAULT] = "Instruction Page Fault", + [CAUSE_LOAD_PAGE_FAULT] = "Load Page Fault", + [CAUSE_STORE_PAGE_FAULT] = "Store/AMO Page Fault", + [CAUSE_FETCH_GUEST_PAGE_FAULT] = "Instruction Guest Page Fault", + [CAUSE_LOAD_GUEST_PAGE_FAULT] = "Load Guest Page Fault", + [CAUSE_VIRTUAL_INST_FAULT] = "Virtualized Instruction Fault", + [CAUSE_STORE_GUEST_PAGE_FAULT] = "Guest Store/AMO Page Fault", + }; + + if ( cause < ARRAY_SIZE(trap_causes) && trap_causes[cause] ) + return trap_causes[cause]; + return "UNKNOWN"; +} + +static const char *decode_reserved_interrupt_cause(unsigned long irq_cause) +{ + switch ( irq_cause ) + { + case IRQ_M_SOFT: + return "M-mode Software Interrupt"; + case IRQ_M_TIMER: + return "M-mode Timer Interrupt"; + case IRQ_M_EXT: + return "M-mode External Interrupt"; + default: + return "UNKNOWN IRQ type"; + } +} + +static const char *decode_interrupt_cause(unsigned long cause) +{ + unsigned long irq_cause = cause & ~CAUSE_IRQ_FLAG; + + switch ( irq_cause ) + { + case IRQ_S_SOFT: + return "Supervisor Software Interrupt"; + case IRQ_S_TIMER: + return "Supervisor Timer Interrupt"; + case IRQ_S_EXT: + return "Supervisor External Interrupt"; + default: + return decode_reserved_interrupt_cause(irq_cause); + } +} + +static const char *decode_cause(unsigned long cause) +{ + if ( cause & CAUSE_IRQ_FLAG ) + return decode_interrupt_cause(cause); + + return decode_trap_cause(cause); +} + +static void do_unexpected_trap(const struct cpu_user_regs *regs) { + unsigned long cause = csr_read(CSR_SCAUSE); + + printk("Unhandled exception: %s\n", decode_cause(cause)); + die(); } +void do_trap(struct cpu_user_regs *cpu_regs) +{ + do_unexpected_trap(cpu_regs); +} + void vcpu_show_execution_state(struct vcpu *v) { BUG_ON("unimplemented"); From patchwork Wed Jul 24 15:31:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13741090 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5298FC3DA7E for ; Wed, 24 Jul 2024 15:31:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.764284.1174658 (Exim 4.92) (envelope-from ) id 1sWdxf-0005Uq-NW; Wed, 24 Jul 2024 15:31:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 764284.1174658; Wed, 24 Jul 2024 15:31:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWdxf-0005TO-GC; Wed, 24 Jul 2024 15:31:27 +0000 Received: by outflank-mailman (input) for mailman id 764284; Wed, 24 Jul 2024 15:31:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWdxe-0005Oj-Ab for xen-devel@lists.xenproject.org; Wed, 24 Jul 2024 15:31:26 +0000 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [2a00:1450:4864:20::22e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c94115f3-49d1-11ef-bbfe-fd08da9f4363; Wed, 24 Jul 2024 17:31:24 +0200 (CEST) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2f035ae1083so7913341fa.3 for ; Wed, 24 Jul 2024 08:31:24 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ef26f1bc4asm14240491fa.40.2024.07.24.08.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 08:31:23 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c94115f3-49d1-11ef-bbfe-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721835084; x=1722439884; darn=lists.xenproject.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=mVzv7Lf3WsrGUV8320pTvF4jrk7P38KxVVOYJq9PCXU=; b=jdnpYO8/Sl3NXW61FqfANxGv8Xk8Lt+Ba6u9PyyYbos8FMlEE/CjlyVK2a/PF9Ahg7 eSQSIqDt0hJUfB2BrlNkxBq9q4YGfod4Ahfr4fxYZWF2u0KzfFsQDW/dzvTxEKkXlm80 Bxrk8p/u3uk5CF6PKFoRkT80mQWTVpYbuBhQ9TJXKxMioec86yOZc3f0iZBhqbF2UIXO GuKY12WDFENnwJ67tj9LgLUXe9FGfJgNlbsO8fAM6zcjyN//7H8j9SZX7SexFaF10RZ3 C2RXtmonO2UK1NsJiaHJ3S4hk59EyhEDq1pAknxieFgkPNn7x/DI6PkGDk8/+zF5biGc OvtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721835084; x=1722439884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mVzv7Lf3WsrGUV8320pTvF4jrk7P38KxVVOYJq9PCXU=; b=NANxyPIVhHdt8coLIeDKkStZe5+9UDwdv/4k9w0UnUynNja0jRovaBlbek1/qLplkJ 3+hXyTIdbe7O3hhVgPcIb68ytsKWZmZgJuhe1inHp0kEYlddeFEcLELSwoq4Qc6Ag4/5 5rBpa8DW33ajF/Oy27DP0ZCd11rh5t/Ox/HIdgbfXORxyvOWwz6ndOyoc4td2S/OhCXD 3NFCh5Nw3si6b5QHwGADKXGHB3/6OnmLp4vw1D92gq2J3BerJkwy3XRbhDxF2KfH8CqP rmsUZELmGnS+vh4gwgXLguZLc0zr3e2uokjn/I3aFZRcY5gA/i6BAYOIwFqA0QjI3dsx e88Q== X-Gm-Message-State: AOJu0Yy2mVE8XzvNB7oVQ2H7FAj7ByoGBXBlMwH2agdAdJ1AIvSv8ttG 22DQpk2QFryvkDDVrJzEhybVoUgStZ/Y1EnSD0RZj3yGkWQHhu7vhjdim462 X-Google-Smtp-Source: AGHT+IFTfVE2OSbKfPeAzMl0JaPOdVB8BEcT/RiMeGKr+zDRJDb13/LT83G1YiwAl8BTH0zdipBXBQ== X-Received: by 2002:a2e:a4a3:0:b0:2ef:2e3f:35da with SMTP id 38308e7fff4ca-2f039dbfbf0mr1225811fa.45.1721835083784; Wed, 24 Jul 2024 08:31:23 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Jan Beulich Subject: [PATCH v11 3/5] xen/riscv: introduce trap_init() Date: Wed, 24 Jul 2024 17:31:17 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Note that trap_init() isn't declared with the __init attribute to avoid removing __init when multi-CPU support for Xen is added. Signed-off-by: Oleksii Kurochko Reviewed-by: Alistair Francis Acked-by: Jan Beulich --- Changes in V11: - update the commit message - add Acked-by: Jan Beulich --- Changes in V10: - update the commit message --- Changes in V9: - drop inclusion of in setup.c - drop #include - ... - introduce stub for void arch_get_xen_caps(xen_capabilities_info_t *info); - resolve rebase conflicts. --- Changes in V8: - nothing changed. only rebase was done. --- Changes in V7: - #define cast_to_bug_frame(addr) ((const struct bug_frame *)(addr)). - remove unnecessary comments in trap_init() function. --- Changes in V6: - trap_init() is now called after enabling the MMU. - Add additional explanatory comments. --- Changes in V5: - Nothing changed --- Changes in V4: - Nothing changed --- Changes in V3: - Nothing changed --- Changes in V2: - Rename setup_trap_handler() to trap_init(). - Add Reviewed-by to the commit message. --- xen/arch/riscv/include/asm/traps.h | 1 + xen/arch/riscv/setup.c | 3 +++ xen/arch/riscv/traps.c | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/xen/arch/riscv/include/asm/traps.h b/xen/arch/riscv/include/asm/traps.h index 3fef318478..c30118e095 100644 --- a/xen/arch/riscv/include/asm/traps.h +++ b/xen/arch/riscv/include/asm/traps.h @@ -9,6 +9,7 @@ void do_trap(struct cpu_user_regs *cpu_regs); void handle_trap(void); +void trap_init(void); #endif /* __ASSEMBLY__ */ diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index e3cb0866d5..a6a29a1508 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -8,6 +8,7 @@ #include #include +#include void arch_get_xen_caps(xen_capabilities_info_t *info) { @@ -23,6 +24,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, { remove_identity_mapping(); + trap_init(); + printk("All set up\n"); for ( ;; ) diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index 37cec40dfa..cb18b30ff2 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -12,6 +12,18 @@ #include #include +/* + * Initialize the trap handling. + * + * The function is called after MMU is enabled. + */ +void trap_init(void) +{ + unsigned long addr = (unsigned long)&handle_trap; + + csr_write(CSR_STVEC, addr); +} + static const char *decode_trap_cause(unsigned long cause) { static const char *const trap_causes[] = { From patchwork Wed Jul 24 15:31:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13741089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F37C8C3DA63 for ; Wed, 24 Jul 2024 15:31:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.764286.1174686 (Exim 4.92) (envelope-from ) id 1sWdxh-0006K0-EA; Wed, 24 Jul 2024 15:31:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 764286.1174686; Wed, 24 Jul 2024 15:31:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWdxh-0006JB-AB; Wed, 24 Jul 2024 15:31:29 +0000 Received: by outflank-mailman (input) for mailman id 764286; Wed, 24 Jul 2024 15:31:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWdxf-0005Od-VW for xen-devel@lists.xenproject.org; Wed, 24 Jul 2024 15:31:27 +0000 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [2a00:1450:4864:20::22d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c9b6fadd-49d1-11ef-8776-851b0ebba9a2; Wed, 24 Jul 2024 17:31:25 +0200 (CEST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2ef2d582e31so38976521fa.2 for ; Wed, 24 Jul 2024 08:31:25 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ef26f1bc4asm14240491fa.40.2024.07.24.08.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 08:31:24 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c9b6fadd-49d1-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721835085; x=1722439885; darn=lists.xenproject.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=bpktRcDF4JrvwzNydeWsiF50yQbYjN8viWEOOJ/BjaU=; b=hGRw7yGdLUCk6LwVIMhK6Gfi+FUyO4VVBomGkhwNa3bv8IpBRatDtKsAHyXTTbmJBA f0OjEDWfpAugXSNYyEfzzgZFrvVCmYHF+jlCoEpgGlg1MfZ3ebPvLZX6DEEoow4KjBGd 5czRDPo4L/4ajAdmD68EnmrcL6E/ovEBpMAlJGvlng1meIVn/0NZXXPhKyBOdkPI2VAM e6/B3jVAsW2B3D7gzNT1rkTsj9WZkczS3JjbbM5lm2a3b4RRxxk8L9/Iv+LazsihmDKb oDkaTvTxeySdx0Sjlell2fDwi9YekKFU8tbMI55WevAY5lfRQFt2z9HWRqydUGB+VDjT qChg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721835085; x=1722439885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bpktRcDF4JrvwzNydeWsiF50yQbYjN8viWEOOJ/BjaU=; b=ANlELxkhBhzOYnJkIBNsYswwtkoGixV2dE8JUB2w1+ZBuBg1ugM04bW3/O3CFbb4Mq 86nsWr61F+yskP5jtou0Pb5PZzvqZ0/xdVpXn5kKwiPhe4OiTr6DQZxWrA3PZJSWxGGN TZ5qoP7Phlyo+HVQrTVsAOX4/PCPM3GrP/+ITzvF6o/Loi67+D/YgznAZCko8GGuDkyq S8Xxw76j829nCJmkXp1aGwZlPxit4zlyYPYmocRhtDX6Fn7YDcIELk2P9PHjXXABhyD1 jhY9DMtNMBxNNAw47kSdKwtihTdQshr/8LD/TAnCeMIujhEM4rWzEFMneTzNaqLtrtEk G4iQ== X-Gm-Message-State: AOJu0YyWaQbw+l4Gn4vEsmKtVo0Q4Di9pwpQBQuZn0RUtEY4eS7RgygQ 449FOGd1m8/EQqNPlNhJsCauclQfiOL/dPm3JAJ5PXMeUqw/YSydIc0NtzWx X-Google-Smtp-Source: AGHT+IELHpp33w+d2EYJm05wyLCODNBCJpRwvJRY8k7ZAX0tgnXUa47x7DGhJXJpLl7gMEbK/r92dw== X-Received: by 2002:a2e:a543:0:b0:2ef:18b7:440a with SMTP id 38308e7fff4ca-2f039cdb6b2mr2098601fa.22.1721835084463; Wed, 24 Jul 2024 08:31:24 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko Subject: [PATCH v11 4/5] xen/riscv: enable GENERIC_BUG_FRAME Date: Wed, 24 Jul 2024 17:31:18 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 To have working BUG(), WARN(), ASSERT, run_in_exception_handler() it is needed to enable GENERIC_BUG_FRAME. ebreak is used as BUG_insn so when macros from are used, an exception with BREAKPOINT cause will be generated. ebreak triggers a debug trap, which starts in debug mode and is then filtered by every mode. A debugger will first handle the debug trap and check if ebreak was set by it or not. If not, CAUSE_BREAKPOINT will be generated for the mode where the ebreak instruction was executed. Also, is needed to be included for the reason that panic() and printk() are used in common/bug.c and RISC-V fails if it is not included. Signed-off-by: Oleksii Kurochko --- Changes in V11: - update the commit message - change "%lx" to "%#x" for PC register printing. - drop +1 in argument of is_kernel_text(pc) and is_kernel_inittext(pc). - drop return for case CAUSE_BREAKPOINT. - add break to default and add a blank like above it. - add a comment CAUSE_BREAKPOINT is handled instead of illegal instruction. --- Changes in V10: - put 'select GENERIC_BUG_FRAME' in "Config RISCV". - rework do_trap() to not fetch an instruction in case when the cause of trap is BUG_insn. - drop read_instr() and is_valid_bug_insn(). - update the commit message. --- Changes in V9: - Rebase on the top of current staging. - use GENERIC_BUG_FRAME as now we have common code available. - add xen/lib.h to bug.c to fix a compilation error around printk. - update the commit message. - update the code of read_instr() in traps.c - fold two-s if into 1 in do_trap. --- Changes in V8: - remove Pointless initializer of id. - make bug_frames[] array constant. - remove cast_to_bug_frame(addr). - rename is_valig_bugaddr to is_valid_bug_insn(). - add check that read_instr is used only on xen code - update the commit message. --- Changes in V7: - move to this patch the definition of cast_to_bug_frame() from the previous patch. - update the comment in bug.h. - update the comment above do_bug_frame(). - fix code style. - add comment to read_instr func. - add space for bug_frames in lds.S. --- Changes in V6: - Avoid LINK_TO_LOAD() as bug.h functionality expected to be used after MMU is enabled. - Change early_printk() to printk() --- Changes in V5: - Remove "#include " from as there is no any need in it anymore - Update macros GET_INSN_LENGTH: remove UL and 'unsigned int len;' from it - Remove " include " from risc/setup.c. it is not needed in the current version of the patch - change an argument type from vaddr_t to uint32_t for is_valid_bugaddr and introduce read_instr() to read instruction properly as the length of qinstruction can be either 32 or 16 bits. - Code style fixes - update the comments before do_bug_frame() in riscv/trap.c - Refactor is_valid_bugaddr() function. - introduce macros cast_to_bug_frame(addr) to hide casts. - use LINK_TO_LOAD() for addresses which are linker time relative. --- Changes in V4: - Updates in RISC-V's : * Add explanatory comment about why there is only defined for 32-bits length instructions and 16/32-bits BUG_INSN_{16,32}. * Change 'unsigned long' to 'unsigned int' inside GET_INSN_LENGTH(). * Update declaration of is_valid_bugaddr(): switch return type from int to bool and the argument from 'unsigned int' to 'vaddr'. - Updates in RISC-V's traps.c: * replace /xen and /asm includes * update definition of is_valid_bugaddr():switch return type from int to bool and the argument from 'unsigned int' to 'vaddr'. Code style inside function was updated too. * do_bug_frame() refactoring: * local variables start and bug became 'const struct bug_frame' * bug_frames[] array became 'static const struct bug_frame[] = ...' * remove all casts * remove unneeded comments and add an explanatory comment that the do_bug_frame() will be switched to a generic one. * do_trap() refactoring: * read 16-bits value instead of 32-bits as compressed instruction can be used and it might happen than only 16-bits may be accessible. * code style updates * re-use instr variable instead of re-reading instruction. - Updates in setup.c: * add blank line between xen/ and asm/ includes. --- Changes in V3: - Rebase the patch "xen/riscv: introduce an implementation of macros from " on top of patch series [introduce generic implementation of macros from bug.h] --- Changes in V2: - Remove __ in define namings - Update run_in_exception_handler() with register void *fn_ asm(__stringify(BUG_FN_REG)) = (fn); - Remove bug_instr_t type and change it's usage to uint32_t --- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/traps.c | 35 ++++++++++++++++++++++++++++++++++- xen/common/bug.c | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig index b4b354a778..f531e96657 100644 --- a/xen/arch/riscv/Kconfig +++ b/xen/arch/riscv/Kconfig @@ -1,6 +1,7 @@ config RISCV def_bool y select FUNCTION_ALIGNMENT_16B + select GENERIC_BUG_FRAME config RISCV_64 def_bool y diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index cb18b30ff2..6802827eb5 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -5,6 +5,7 @@ * RISC-V Trap handlers */ +#include #include #include @@ -103,7 +104,39 @@ static void do_unexpected_trap(const struct cpu_user_regs *regs) void do_trap(struct cpu_user_regs *cpu_regs) { - do_unexpected_trap(cpu_regs); + register_t pc = cpu_regs->sepc; + unsigned long cause = csr_read(CSR_SCAUSE); + + switch ( cause ) + { + /* + * ebreak is used as BUG_insn so when macros from are + * used, an exception with BREAKPOINT cause will be generated. + * + * ebreak triggers a debug trap, which starts in debug mode and is + * then filtered by every mode. A debugger will first handle the + * debug trap and check if ebreak was set by it or not. If not, + * CAUSE_BREAKPOINT will be generated for the mode where the ebreak + * instruction was executed. + */ + case CAUSE_BREAKPOINT: + if ( do_bug_frame(cpu_regs, pc) >= 0 ) + { + if ( !(is_kernel_text(pc) || is_kernel_inittext(pc)) ) + { + printk("Something wrong with PC: %#lx\n", pc); + die(); + } + + cpu_regs->sepc += GET_INSN_LENGTH(*(uint16_t *)pc); + } + + break; + + default: + do_unexpected_trap(cpu_regs); + break; + } } void vcpu_show_execution_state(struct vcpu *v) diff --git a/xen/common/bug.c b/xen/common/bug.c index b7c5d8fd4d..75cb35fcfa 100644 --- a/xen/common/bug.c +++ b/xen/common/bug.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include From patchwork Wed Jul 24 15:31:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13741092 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4598CC3DA61 for ; Wed, 24 Jul 2024 15:31:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.764287.1174697 (Exim 4.92) (envelope-from ) id 1sWdxi-0006aZ-Ro; Wed, 24 Jul 2024 15:31:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 764287.1174697; Wed, 24 Jul 2024 15:31:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWdxi-0006aS-Mp; Wed, 24 Jul 2024 15:31:30 +0000 Received: by outflank-mailman (input) for mailman id 764287; Wed, 24 Jul 2024 15:31:29 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWdxg-0005Od-Vc for xen-devel@lists.xenproject.org; Wed, 24 Jul 2024 15:31:28 +0000 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [2a00:1450:4864:20::22b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ca1b5c54-49d1-11ef-8776-851b0ebba9a2; Wed, 24 Jul 2024 17:31:26 +0200 (CEST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2ee910d6a9eso10077391fa.1 for ; Wed, 24 Jul 2024 08:31:26 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ef26f1bc4asm14240491fa.40.2024.07.24.08.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 08:31:24 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ca1b5c54-49d1-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721835085; x=1722439885; darn=lists.xenproject.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=4O/hwQwHF6rfJLVATnZjtAz9ttGqfT93bsxm/gvlyso=; b=Fx02EhSWbV36Y2XPEQJhk4I3PD1/abDRG4Axwf3C9J3R/UkDK8tM/L+K3sUM/qJnoj 2cYjw9B0lFsfi6HHaSccH8iJPwnHGFfInCHQjXcV6QECpZcCXeOC6Yu79HiUEU/6V0zz InFMCYbtJo8u9E1MjZ6BYIXxZ9CxbEhDuZlj18yxZowyrvUzuUBWzVR6jWBVINSCa6jM ORjmyMccpUlUmVMFtOQOZQJm2wNE/QwtCcWr+z8UseqSSXNuSYkte8/K6kelchcMIAED eWOAht0WGh0PJ0N2mY2hMfj+vRB3GH75JIz8B8ZPSiUdIa85hyxt+kTK1QZYCNriU10U ecww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721835085; x=1722439885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4O/hwQwHF6rfJLVATnZjtAz9ttGqfT93bsxm/gvlyso=; b=f99J9Kf15C1th2Qn3XXy0rtTCxAWAPYcCD6B3WyjnTQqlhbdAp6bUppC8J3goWHNWp BtBlIRV9e5UItRUZ5rtVZ7d0/S1CHFZkyKk/UU3fSl4MeT2DN0IEnIYr4qOFmodyqT6q ZbgQPJI5bneRzMp3zMX+1diU3jEZ3YFZ/mRB547yuqjKSNow2Lo1PzE12yhu9dJoQqQJ 2/++dH0GnL/RmMnAtiOBO/Lhb+RdygL4FXWmoZYw/8krYtHYc8Js1lRMJPWLmr+xA1VX t7tCNUj47xzUkaORzIeR0j9KZsvi5AbBmGY8goUq2TdOCRxTi+9XLzt6HLb9SwJ7l6kd tz8w== X-Gm-Message-State: AOJu0YyHQZ4ecA450fmPIePkzd6G5ZqePwoESKD8GAnfMS1quueliCfp x8SUNLMzPa9fCDbk+yJTPus49+FpfsuPbm3+VKJ8y76J/QKjO4wXuAbNrRxN X-Google-Smtp-Source: AGHT+IFwW9NRyjYW7BQrQYvv6ZlUZAHMK5dZdh4otNlSjFLdBd76AEtDTO4J0u1G65gJH33NGBAHAg== X-Received: by 2002:a2e:a4cd:0:b0:2ee:7c35:d892 with SMTP id 38308e7fff4ca-2f032d43da6mr6452101fa.17.1721835085036; Wed, 24 Jul 2024 08:31:25 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis Subject: [PATCH v11 5/5] xen/riscv: test basic exception handling stuff Date: Wed, 24 Jul 2024 17:31:19 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Introduces testing of some macros from . Also wraps this testing into SELF_TESTS config to not produce a noise in the log related to functionality testing ( in the current case, it is macros from xen/bug.h ) when CONFIG_SELF_TESTS is disabled. Signed-off-by: Oleksii Kurochko Acked-by: Alistair Francis --- xen/arch/riscv/setup.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index a6a29a1508..4defad68f4 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -19,6 +19,22 @@ void arch_get_xen_caps(xen_capabilities_info_t *info) unsigned char __initdata cpu0_boot_stack[STACK_SIZE] __aligned(STACK_SIZE); +#ifdef CONFIG_SELF_TESTS +static void test_run_in_exception(const struct cpu_user_regs *regs) +{ + printk("If you see this message, "); + printk("run_in_exception_handler is most likely working\n"); +} + +static void test_macros_from_bug_h(void) +{ + run_in_exception_handler(test_run_in_exception); + WARN(); + printk("If you see this message, "); + printk("WARN is most likely working\n"); +} +#endif + void __init noreturn start_xen(unsigned long bootcpu_id, paddr_t dtb_addr) { @@ -26,6 +42,10 @@ void __init noreturn start_xen(unsigned long bootcpu_id, trap_init(); +#ifdef CONFIG_SELF_TESTS + test_macros_from_bug_h(); +#endif + printk("All set up\n"); for ( ;; )