From patchwork Tue Jul 2 11:23:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13719430 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 644E9C3064D for ; Tue, 2 Jul 2024 11:24:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.752359.1160561 (Exim 4.92) (envelope-from ) id 1sObc6-0001ph-Ul; Tue, 02 Jul 2024 11:23:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 752359.1160561; Tue, 02 Jul 2024 11:23:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sObc6-0001ov-Pb; Tue, 02 Jul 2024 11:23:58 +0000 Received: by outflank-mailman (input) for mailman id 752359; Tue, 02 Jul 2024 11:23:58 +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 1sObc6-0001m7-45 for xen-devel@lists.xenproject.org; Tue, 02 Jul 2024 11:23:58 +0000 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [2a00:1450:4864:20::235]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 91c2d0fe-3865-11ef-aaf1-7f3abd7486c0; Tue, 02 Jul 2024 13:23:56 +0200 (CEST) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2ec61eeed8eso50369231fa.0 for ; Tue, 02 Jul 2024 04:23:56 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee5161fb73sm16149981fa.33.2024.07.02.04.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 04:23:54 -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: 91c2d0fe-3865-11ef-aaf1-7f3abd7486c0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719919435; x=1720524235; 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=L0kvZbIwg1P0mhVOPWpS762W5yQg7NFjtIVmRuw6584=; b=Le+N02QphNp+Hx8OufdExGBj9V7pWqGKf7IlKXmnZbr9kwBIbiKqyJWfE/t59W7zrt zvkrsnfCpekcnwajcSJFMwRbBEISca8+QxZwOGaU803ebO+rpu8ZavSuoTOtmnEt1GDI gCAy61J3vdIenWDvcOf8pEXMqcKN0NO0wt+SHfexZcf1cNixkyyZ2VSJHtc1THwXL74/ Ybd2VJY2vYo9086ofHjougrEGa5fH9n0EuC6VrfmSIrEZYypAchEomwTHuaSL9HF864E kYf+IepKOROmp6XjzcWGG2YjzrEKIHcua9TVxTmLtXusmyTiSY1n0PJA8S8SH9Ze/kfh ylHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719919435; x=1720524235; 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=L0kvZbIwg1P0mhVOPWpS762W5yQg7NFjtIVmRuw6584=; b=tE8eBbjObEFVClUk/lir69mWw4nWQguIPB0GmNUTktm8vFEBkRQ+HmL9gv6LSegk8h RltxdQ0+15oBE8erMZmrEbR8W7rNsUIPsBxI2e/FV7P5qezTm9cAwMD6IUcU0+OQaNFz l6YYeGawaosCNA+J2aDwtTXKAaVLTRdqlHBOu5xaxG3EPMDV7qGcofG54xn3YQ/9U0xt 34X04taHmLShxagHyemalZ3hKT5MtqUidpuPahmnOQabOH2U3x7E8/wQUQ0VxemxfTZa FTy08GIIl7Mmw8fnwe5+53ebxX5CjPr6UedD04cpS0xVpA0b/iXqXBkTHkZ5Ho8YuRhq ct6A== X-Gm-Message-State: AOJu0Yyqe1SpJZrqxPqCLDj0mqLxBmcBImnsl6dU+geY0QYlsxyXaTCv atE7qpEqszrY0C8DJxhTW/Xft4mr1Bk5vG1S6zsbo/1OMyNldqDk7w8iFiFx X-Google-Smtp-Source: AGHT+IFziYw3KhCffJR57gsm6MaJhnTZA0BJrtpkAe2mBdjSNoxtUVxNMMYxY/bGE0g8qR5naBzYMA== X-Received: by 2002:a2e:a548:0:b0:2ec:6639:120a with SMTP id 38308e7fff4ca-2ee5e33a582mr60578951fa.10.1719919435018; Tue, 02 Jul 2024 04:23:55 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v9 1/5] xen/riscv: use printk() instead of early_printk() Date: Tue, 2 Jul 2024 13:23:46 +0200 Message-ID: <22c78705e4559a049e72950dc311513f1c15e489.1719918148.git.oleksii.kurochko@gmail.com> 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 --- 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 Tue Jul 2 11:23:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13719431 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 73F3BC3065E for ; Tue, 2 Jul 2024 11:24:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.752360.1160566 (Exim 4.92) (envelope-from ) id 1sObc7-0001ta-8V; Tue, 02 Jul 2024 11:23:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 752360.1160566; Tue, 02 Jul 2024 11:23:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sObc7-0001sI-1G; Tue, 02 Jul 2024 11:23:59 +0000 Received: by outflank-mailman (input) for mailman id 752360; Tue, 02 Jul 2024 11:23:58 +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 1sObc6-0001mD-6q for xen-devel@lists.xenproject.org; Tue, 02 Jul 2024 11:23:58 +0000 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [2a00:1450:4864:20::22a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 926905be-3865-11ef-92e8-0d9d20120eaa; Tue, 02 Jul 2024 13:23:57 +0200 (CEST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2ebec2f11b7so45956101fa.2 for ; Tue, 02 Jul 2024 04:23:57 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee5161fb73sm16149981fa.33.2024.07.02.04.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 04:23:55 -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: 926905be-3865-11ef-92e8-0d9d20120eaa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719919436; x=1720524236; 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=6BfiwtMm7MMPr/ZmXTaMofeIOTWuXGENJ246OGl6NYg=; b=dMtL2tnglFBNrmRoRv5TFaItaRMEjA3wu9lb4oKY/UIN3VlccZtqwE1V3CEz57zA8Q cc65CIiDCVV3HvRJasz10BW5XBbJV8xkgCVdxwWzrmpZfaA0trlXmSl5EeiUx75+zRxs aqXBAhcjwl0anf/OUbWoiQISUxaeY6qg1guodLbl2x7dZmdLiRd+N6mwUEbofJWKo2xi cB7eD35l9RX6GUgBHemd75lGpPyZ3wf+MuGboGqL0V7itCr6cYcL3XDym7MdbjhFfjTQ H/XIe3U+qe9wZ26pZvS102WqcEC5NkkrjtGWeWypPTgaOrthyGb5DUFECAxT6FnsoeA7 nvFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719919436; x=1720524236; 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=6BfiwtMm7MMPr/ZmXTaMofeIOTWuXGENJ246OGl6NYg=; b=mcpy+DukeU32IaFekFATMQBRjXUUctkLo4PHMVcSHK1sdcavt4WvHvq5TdZS9+Rf5B fYLQ4Is+jajB71eZYePSG3RqUynrmxNEgeF/86FJVfoZUb7WubV4zocfHZKu5c9i7Y84 Md8husjirQ/xLcFNlUzbohhbzRr90SkhWw91a1PQOI5M5ZqczdvslymTTv30i6LV8Mi9 zAUsXQLyTdXzjcMiFSB9krL2ZVYfI494EsjYkFuQwzhm5RtXh41U6bXeiXZE/sgjT7Fp hTZxmyXuiSHCWAaG9ImVrTgsvLeuSah+cu4b1olYgwG5nliGD6DnXY0cExRuOiczd2zx qNjQ== X-Gm-Message-State: AOJu0Yzc0a1Uop4NyTtzZnbigte+cXlUl6LkFTQDj9LlfDdbBVXbipng 4ZzMRJtF9Ksv5qvDwXyMPHvU2Zg1/iLPl+ihpkUpsVl39WkGKiSymP26PynO X-Google-Smtp-Source: AGHT+IE9KF4lKKQ4RhAW0d6YuxQEKRwjd6S/Nb4rUg3IYT13YDl7SwK6mzVEMwNlpXGw5adVrtjj4g== X-Received: by 2002:a05:651c:1511:b0:2ec:4d82:9e93 with SMTP id 38308e7fff4ca-2ee5e6bcb43mr62237861fa.44.1719919436370; Tue, 02 Jul 2024 04:23:56 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v9 2/5] xen/riscv: introduce decode_cause() stuff Date: Tue, 2 Jul 2024 13:23:47 +0200 Message-ID: <3b93bb33b42cb6e86a38cd95a098e60447666e2e.1719918148.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 --- 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 Tue Jul 2 11:23:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13719427 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 4ED15C41513 for ; Tue, 2 Jul 2024 11:24:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.752361.1160585 (Exim 4.92) (envelope-from ) id 1sObc8-0002T8-Bq; Tue, 02 Jul 2024 11:24:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 752361.1160585; Tue, 02 Jul 2024 11:24:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sObc8-0002SL-89; Tue, 02 Jul 2024 11:24:00 +0000 Received: by outflank-mailman (input) for mailman id 752361; Tue, 02 Jul 2024 11:23:59 +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 1sObc6-0001mD-SC for xen-devel@lists.xenproject.org; Tue, 02 Jul 2024 11:23:58 +0000 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [2a00:1450:4864:20::22c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9323a9f8-3865-11ef-92e8-0d9d20120eaa; Tue, 02 Jul 2024 13:23:58 +0200 (CEST) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2ebec2f11b7so45956341fa.2 for ; Tue, 02 Jul 2024 04:23:58 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee5161fb73sm16149981fa.33.2024.07.02.04.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 04:23:56 -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: 9323a9f8-3865-11ef-92e8-0d9d20120eaa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719919437; x=1720524237; 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=D+B8xBmNcCIo57qB2YroROGMOiu001L1f4uYSEWgPoA=; b=bgKaLRPNnH/6HUYQnndymQoCV5ohNXL/yKk3DYegs3suvOFZctZMb3pdr+2QbCFObw X0tYsSmxt2tVxQnwqXkfm2KpcU+sVXceqqDa1U0yWwTvjnGG43Tybz84cPSFDFoYvB2V lrNhFgIktXB9X57p9HzWLCCzX251GAW/0i/ZDRY+Y0zHKnFgCoo5fuQ2kqTMWkeSaZYV P4bxyIlliSxFJ9GwHkH0NkSt4B/o1kFOYGxdYotZuzc1S3aCoJK3F6ntsFdRFvYqWeuB 4s3BFClai6Lnd8Sb8LR/og+/BM4Wu9ickCXsgYC3es9KlfI56ROAFtkjDFKPDLKOLQG2 UQdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719919437; x=1720524237; 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=D+B8xBmNcCIo57qB2YroROGMOiu001L1f4uYSEWgPoA=; b=TgSLL0cn2yEaD2RPxf0kOnaTkAb5tIm7DFEn5hGPq5AZu+OkEG1E/6IyYD2YalQLe3 TgSmvpYH3yub/Py3FukWPhmKQygb24phYuXVX1Vyd0x/YwGamdEQ8kozHzR83eg1pRv5 BZqGWVKmVLz5wOPqra0MdDYYIpjO0iMyLOyxD8X/58kKFtHq4l0Y/vStxz2QHo0GmBBe 9SESatzYsnki9093iE+UoZgQpTvRG0sV/HEAMvjZBdal+LIBIj4mdbMq1wYETSCSMJ0X XtjMDeVbrWdgcuAGF4sW+Z2PwFxn/en5r3AvJBGsahzk7zTcW7cHCGhlIO40ed5cJbsC LuTg== X-Gm-Message-State: AOJu0YyHG6uF8xo+G+74ioGtU8Dg6q32xQmqioBARGSgM/shiR0v/b4w wzIcrOB0VyL61Ys0AKo81ZOzPNQDIBrX5JBNRITFrUuPP35i2+DsX5jIxz+M X-Google-Smtp-Source: AGHT+IE1gKqgEzNkm0qflfc256ah5L6MMRtuh9OLgISEUhbAFxZEdVP2dp1xg0TjdcTzEurdxB+7vQ== X-Received: by 2002:a2e:a813:0:b0:2ee:7a3e:4728 with SMTP id 38308e7fff4ca-2ee7a3e48d9mr1958171fa.53.1719919437437; Tue, 02 Jul 2024 04:23:57 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v9 3/5] xen/riscv: introduce trap_init() Date: Tue, 2 Jul 2024 13:23:48 +0200 Message-ID: <83b9053330e4dae38e926c99f47d0ef11d9dd31d.1719918148.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Signed-off-by: Oleksii Kurochko Reviewed-by: Alistair Francis --- 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 Tue Jul 2 11:23:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13719429 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 03EE7C3065D for ; Tue, 2 Jul 2024 11:24:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.752362.1160594 (Exim 4.92) (envelope-from ) id 1sObcA-0002kQ-Hy; Tue, 02 Jul 2024 11:24:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 752362.1160594; Tue, 02 Jul 2024 11:24:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sObcA-0002kF-Ev; Tue, 02 Jul 2024 11:24:02 +0000 Received: by outflank-mailman (input) for mailman id 752362; Tue, 02 Jul 2024 11:24:01 +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 1sObc9-0001m7-4r for xen-devel@lists.xenproject.org; Tue, 02 Jul 2024 11:24:01 +0000 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [2a00:1450:4864:20::22f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 93ce3950-3865-11ef-aaf1-7f3abd7486c0; Tue, 02 Jul 2024 13:23:59 +0200 (CEST) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2ed5ac077f5so48545841fa.1 for ; Tue, 02 Jul 2024 04:23:59 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee5161fb73sm16149981fa.33.2024.07.02.04.23.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 04:23:58 -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: 93ce3950-3865-11ef-aaf1-7f3abd7486c0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719919439; x=1720524239; 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=hEIsWsvrlXl4/YcR0JMfIfMbkJsSh1CWtuRxJ27QKeY=; b=mjYufUq8+mgghRdUihQLdQ0QnbXlkHXJSv9e0o6nrDCYcw791Kzu3xKovS/0zeEXlj QJ33KUDfBCNjND+qW9OPqxrE4LOZ79vSbU1oKg77SNUNJk9sRCWi4xXUVsSsESvGH0v0 cv5uEsgqAA/TDH+QthfLbWEui/PS5+G473IA7AUK1MTJxjucV/2KNbknhtHn3IP7g9E8 Goa+7BMuSM69dXypYNLHvWqq+Y/3jpTolmXI1kbtJd2h2JkHXisnfNsYlEfyOaWVmLI+ SYOev5peLkzXgp71KZu7H1YMCQDLU/HSXNkuvrhoo6WJAvaXoXXtryzS+nkT11vLhO+3 uxQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719919439; x=1720524239; 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=hEIsWsvrlXl4/YcR0JMfIfMbkJsSh1CWtuRxJ27QKeY=; b=htoUUvAAzK91VDoqOvmMYOcPenriscTdSirenftkYN7iGHh9y5LB6FI9QylKt1xllw xkxK9IBFw+ljN22gdr88M8Y1BJKgdzkQW4iZr8cyuSBYGNmEQoufjmRj1PanAXWVH0B1 ByAOpVK77Fd2MhjbtM7gNfLwr6uorKQgy2jfSERn5Zr/0NRfqiiAURkJlhAuujY7bxmo Pumx0wy+QoiiGowbcV7gLUy9m2qpdRdffnnXqGcjVoNTOWs4hY8fgJkBbHN1gVVTBO7J 3gCUcpK4UdGuU6Xff0Rs6pzca+pNydFQlbuOuRLqGWnnP4nQ8U6GvIBS2kMlS8udJug0 b1SQ== X-Gm-Message-State: AOJu0YwljEgJRx7YDdUxhca8ie07DeZofp/RB6m4l03vDsCx4j5ciNWX r/DndHseimIsCV90EO9UTVfIQ+81m7CDldYIAZsdctBg8b2CqQwQYRsm7Jbp X-Google-Smtp-Source: AGHT+IEClPxEScxTwOZDx/lM2//DicvvbS2F0zthvwNfRMHFUtUpJW46VjOET/t7OoKVDOZ/OVSDLQ== X-Received: by 2002:a05:651c:893:b0:2ee:6277:a888 with SMTP id 38308e7fff4ca-2ee6277a9f3mr53920421fa.38.1719919438650; Tue, 02 Jul 2024 04:23:58 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v9 4/5] xen/riscv: enable GENERIC_BUG_FRAME Date: Tue, 2 Jul 2024 13:23:49 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/traps.c | 31 +++++++++++++++++++++++++++++++ xen/common/bug.c | 1 + 3 files changed, 33 insertions(+) diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig index b4b354a778..74ad019fe7 100644 --- a/xen/arch/riscv/Kconfig +++ b/xen/arch/riscv/Kconfig @@ -5,6 +5,7 @@ config RISCV config RISCV_64 def_bool y select 64BIT + select GENERIC_BUG_FRAME config ARCH_DEFCONFIG string diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index cb18b30ff2..7ba16252fc 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -5,6 +5,7 @@ * RISC-V Trap handlers */ +#include #include #include @@ -101,8 +102,38 @@ static void do_unexpected_trap(const struct cpu_user_regs *regs) die(); } +static bool is_valid_bug_insn(uint32_t insn) +{ + return insn == BUG_INSN_32 || + (insn & COMPRESSED_INSN_MASK) == BUG_INSN_16; +} + +/* Should be used only on Xen code */ +static uint32_t read_instr(unsigned long pc) +{ + uint16_t instr16 = *(uint16_t *)pc; + + ASSERT(is_kernel_text(pc + 1) || is_kernel_inittext(pc + 1)); + + if ( GET_INSN_LENGTH(instr16) == 2 ) + return instr16; + + ASSERT(is_kernel_text(pc + 3) || is_kernel_inittext(pc + 3)); + + return *(uint32_t *)pc; +} + void do_trap(struct cpu_user_regs *cpu_regs) { + register_t pc = cpu_regs->sepc; + uint32_t instr = read_instr(pc); + + if ( ( is_valid_bug_insn(instr) ) && ( do_bug_frame(cpu_regs, pc) >= 0 ) ) + { + cpu_regs->sepc += GET_INSN_LENGTH(instr); + return; + } + do_unexpected_trap(cpu_regs); } 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 Tue Jul 2 11:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13719428 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 DF622C3065C for ; Tue, 2 Jul 2024 11:24:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.752363.1160605 (Exim 4.92) (envelope-from ) id 1sObcC-00032C-3E; Tue, 02 Jul 2024 11:24:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 752363.1160605; Tue, 02 Jul 2024 11:24:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sObcB-000323-VD; Tue, 02 Jul 2024 11:24:03 +0000 Received: by outflank-mailman (input) for mailman id 752363; Tue, 02 Jul 2024 11:24:02 +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 1sObcA-0001m7-Gs for xen-devel@lists.xenproject.org; Tue, 02 Jul 2024 11:24:02 +0000 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [2a00:1450:4864:20::232]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 94aa26d5-3865-11ef-aaf1-7f3abd7486c0; Tue, 02 Jul 2024 13:24:01 +0200 (CEST) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2ec52fbb50aso48157091fa.3 for ; Tue, 02 Jul 2024 04:24:00 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee5161fb73sm16149981fa.33.2024.07.02.04.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 04:23:59 -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: 94aa26d5-3865-11ef-aaf1-7f3abd7486c0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719919440; x=1720524240; 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=EYmnnYmgVza05GF6fpOBaADbngQ5M4w1OoEJiW0icp8=; b=W5ZTzFUQOux2RJ8Buswq9fw9famJXf03G1CKqiPuWxOMJpLNaeIbsDvWj5udzivTKV iGwrMIdOIKQKr2C+EL6eY9pdXb5Gu2kYHTq1IfXg5iJJ6F7sXrls3mOSBxqIwqUxvFbu QrAVpam1A5+tCe5UCVDTpp8okCfhT75WWTjK93zOLSaXDgt71GhzfIfwgWFMNI0+WLzP RMt1dW94yJLIkYs9xa1P2crQY9cXI2cc8/HOyTM5CJVSXyhricIrFLPaONrsXz0yPmtm vHA66EEh9/oeC7YdfQf+/fEOWgOObyuTXfPDX9KlBioshHAlZmdG2mK5PCkYbfvQKJcq daYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719919440; x=1720524240; 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=EYmnnYmgVza05GF6fpOBaADbngQ5M4w1OoEJiW0icp8=; b=asovltt8sBDXsIVo6tx1m0tA1lk/BoHeOZ9efMFBhUMn1Ys5nSvInrNjb5KWVIK7/r CGpcyfw/Mqx3e16zOidxr1RWAeImiW63xaalCwp7zV2b08iqhNWWoocDKqOeiB3zJNDj wCQtPsuqFQRNRtRFflzpIQbDkkdqw7kOX5V6EC4sJjkM+kwwkBsI67ivVCJ8aSq29FwG MZl+TiLCNhvCheFZEH21Mp1/4gQ1DjgxbWabfA1zzGqWPEE9duuG7yxBYkbD87LAUpdR lI1lVNe304Irx32biwxsaJb0uKQnIFzIwq7DoTV6YN6x5om+q2CYkpR6Fnu1aesbN17h QNmw== X-Gm-Message-State: AOJu0YzD9llM92ze8HYYJmwqdwgYO7T8zN24NX1I4JMuQKxKp05JWfoH 0h70G9N1MYz90Oyo/vl/Jpho4xwJRTNBgTqY7xFFahMIp5ESYROD9SiEDEkk X-Google-Smtp-Source: AGHT+IHYTf6HF0P3BWYkFwBSVYHBFrWyjoQVEpopSu2ldqdVn8B7GSlePCb+UyIE/s1epVk5jRn+fA== X-Received: by 2002:a2e:a5c4:0:b0:2ee:5ec1:1838 with SMTP id 38308e7fff4ca-2ee5ec11928mr75360291fa.30.1719919439742; Tue, 02 Jul 2024 04:23:59 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v9 5/5] xen/riscv: test basic handling stuff Date: Tue, 2 Jul 2024 13:23:50 +0200 Message-ID: <62cce91351f00f80cb1c7701906e2d8cd3301ec1.1719918148.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Signed-off-by: Oleksii Kurochko Acked-by: Alistair Francis --- xen/arch/riscv/setup.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index a6a29a1508..4f06203b46 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -19,6 +19,20 @@ void arch_get_xen_caps(xen_capabilities_info_t *info) unsigned char __initdata cpu0_boot_stack[STACK_SIZE] __aligned(STACK_SIZE); +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"); +} + void __init noreturn start_xen(unsigned long bootcpu_id, paddr_t dtb_addr) { @@ -26,6 +40,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, trap_init(); + test_macros_from_bug_h(); + printk("All set up\n"); for ( ;; )