From nobody Fri Oct 18 08:39:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1720801166; cv=none; d=zohomail.com; s=zohoarc; b=MncuyZtTKdZ3GV0ibHuStCyTB7FgnOdqB4aHqtZEwdlX5qSUTrpKWaLfFyQrfP8Lxr5EdUiidP7WfEdgdz9bQ7UG7x1HGEWCsEcqhy/3O56Z7YcyFScZWik3bCuXUpCMOFTATG6HUmFe4KZpWjYB248LsODRBZlj8uOtWXQ1U1M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720801166; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wnR0lQfCiZrZB2pYI/iZQqNx4LzjeoRWt1LANtUWrVY=; b=ZDjWAOLIMpPCKjHHkyoDSXuP8d31d70uOPKtcvk6L5zi4R48odnqagVDQDj4eVdLYRvPNip1LHaDxPlwz6raCQiCIcVNf3VrWlv0RBYquBF6TnyL9j8+MhqfowAr1hINZzBYxh8qh44FFuyFlASnIBbwjC02CKpCJEAK58oRTj8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1720801166053448.07062546214; Fri, 12 Jul 2024 09:19:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.758148.1167487 (Exim 4.92) (envelope-from ) id 1sSIz8-0004Wo-UL; Fri, 12 Jul 2024 16:19:02 +0000 Received: by outflank-mailman (output) from mailman id 758148.1167487; Fri, 12 Jul 2024 16:19: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 1sSIz8-0004WI-NQ; Fri, 12 Jul 2024 16:19:02 +0000 Received: by outflank-mailman (input) for mailman id 758148; Fri, 12 Jul 2024 16:19: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 1sSIz7-00040X-IQ for xen-devel@lists.xenproject.org; Fri, 12 Jul 2024 16:19:01 +0000 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [2a00:1450:4864:20::536]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7209ec4a-406a-11ef-8776-851b0ebba9a2; Fri, 12 Jul 2024 18:18:59 +0200 (CEST) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5854ac817afso2829789a12.2 for ; Fri, 12 Jul 2024 09:18:59 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bb9604f7sm4669169a12.15.2024.07.12.09.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 09:18:58 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 7209ec4a-406a-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720801139; x=1721405939; 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=wnR0lQfCiZrZB2pYI/iZQqNx4LzjeoRWt1LANtUWrVY=; b=lSCp4Cc/PTWxq/7qRzPBu6lXm80ywlWCafTDm4hGd2XpeB51S/XEdKPYzaYiqngM7u BWVxoPZoriLXjLC+JGoWvhbgYvF6G1Bx2VaISOQRjL3Tt2B4qhQrE8Fi/M0EgFYMBNy6 RG6O1xmGu7cgTE+btpGn/ZsLLZUMPVIZK7kn4SwfDP/QBmNPE36NyPcvsZWpumL+WQkq sWc42IraLHshVD12HEgN9jenoMgU0CamsE5476n5xIKM/x6dQIajLDap598f/Dden+16 GADa+TbUdkWc3ATN3xI/vo0wMqUJ9MrpaXGNxuZUqjE42e0/4iSajG9gTmORuiBHewx3 WIdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720801139; x=1721405939; 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=wnR0lQfCiZrZB2pYI/iZQqNx4LzjeoRWt1LANtUWrVY=; b=aue5wtDYOyTNt77KCBkHq5RHqfX8LbNbLmy/hj3fEXVXYXwA87eN/T0VmT/3R4B6Ja xm/TP8ehAIv+KEH3RHizo+JbVDGqYAT4B+HXsDfc/5Og2t35PhJAMLNCuLXPNG0jHJAn cLe6NHsfSY68YgC3eUmyBv9cAKJNZg8NAs+3R4JKHOPR/K8bHpGpz+kzv0XNPlmKwgHl YdacDnEWUm15sBox96ndPrAminkpUfMyK/aintwGmuEMmG8TGcXyUCG+bHTsODwVDqhc 4GyeChQhsBxzyBYXNJEJO1cTdBeP2fIjZyJ8Bp3ThpRkb1Yc1PFrjOmPCD+tm3p4DEvA u9Vg== X-Gm-Message-State: AOJu0YzsLYrZVzbkETfomQ+DT3KKKvWo5eeFcSHH1po1s3cO3q9ORGMs X8nn0VRUDLO5NR0A6z2EYnBv1sZbkV30Zlx6vygzRcsK283GWWuUmtLy2C2o X-Google-Smtp-Source: AGHT+IElo5yBxcnuOD1tObFjCmJxahwTzdOmlQV86IIWtIO8gilmED3rdM9dA0bKJmDVSjjZmP5iXg== X-Received: by 2002:a50:d518:0:b0:585:437c:d7fc with SMTP id 4fb4d7f45d1cf-594bc7c7e61mr7402934a12.32.1720801138545; Fri, 12 Jul 2024 09:18: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 v10 2/5] xen/riscv: introduce decode_cause() stuff Date: Fri, 12 Jul 2024 18:18:51 +0200 Message-ID: <335b0b49720b3524b6c89c5ce62d3377a4bb1fb8.1720799487.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1720801167525116600 Content-Type: text/plain; charset="utf-8" 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 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_cau= se, 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 on= e. --- 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 =20 #include +#include #include =20 -void do_trap(struct cpu_user_regs *cpu_regs) +static const char *decode_trap_cause(unsigned long cause) +{ + static const char *const trap_causes[] =3D { + [CAUSE_MISALIGNED_FETCH] =3D "Instruction Address Misaligned", + [CAUSE_FETCH_ACCESS] =3D "Instruction Access Fault", + [CAUSE_ILLEGAL_INSTRUCTION] =3D "Illegal Instruction", + [CAUSE_BREAKPOINT] =3D "Breakpoint", + [CAUSE_MISALIGNED_LOAD] =3D "Load Address Misaligned", + [CAUSE_LOAD_ACCESS] =3D "Load Access Fault", + [CAUSE_MISALIGNED_STORE] =3D "Store/AMO Address Misaligned", + [CAUSE_STORE_ACCESS] =3D "Store/AMO Access Fault", + [CAUSE_USER_ECALL] =3D "Environment Call from U-Mode", + [CAUSE_SUPERVISOR_ECALL] =3D "Environment Call from S-Mode", + [CAUSE_MACHINE_ECALL] =3D "Environment Call from M-Mode", + [CAUSE_FETCH_PAGE_FAULT] =3D "Instruction Page Fault", + [CAUSE_LOAD_PAGE_FAULT] =3D "Load Page Fault", + [CAUSE_STORE_PAGE_FAULT] =3D "Store/AMO Page Fault", + [CAUSE_FETCH_GUEST_PAGE_FAULT] =3D "Instruction Guest Page Fault", + [CAUSE_LOAD_GUEST_PAGE_FAULT] =3D "Load Guest Page Fault", + [CAUSE_VIRTUAL_INST_FAULT] =3D "Virtualized Instruction Fault", + [CAUSE_STORE_GUEST_PAGE_FAULT] =3D "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 =3D 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 =3D csr_read(CSR_SCAUSE); + + printk("Unhandled exception: %s\n", decode_cause(cause)); + die(); } =20 +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"); --=20 2.45.2