From patchwork Tue Jun 18 17:30:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 1949414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=U4NrpV2B; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=KX5eVS62; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W3YjL6ctfz20XR for ; Wed, 19 Jun 2024 03:32:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GvZqhzLN36/WM02IkEZ98ZjxqRkf4rFOsOjgB2g360s=; b=U4NrpV2BTlONZp 3qWKj+5rJl2SfgQLgzbV21IGb2nZ16uQBy1SfsKjH8IWOVJdFhjzE/aW6v+VGsqwK4zXtO6HfBfpM TY0QGE6qMfn0dOBEksn08rhD47t7swyk3Xdxxc9hDvHtHXkZdDSv5XnEyU9CEikDoqrt9N083nEJT 2c0rZsYiCYUFAvNCOqaaGwKNmF3i9RRnJdbGuC6u9Fzt4ICPpe0Ct5OXtzltgvqUTHhg++xx8SYVH /Zrcmbd/KP4ZPIWuzzp5OJGtz85NTP5rImX17mIgwZBcnewgUzqXBUGwciYKd5/ieHwJPLvUjOdCT mHvwqRNArOrEHp/8ZnTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJcgv-0000000G2nb-2bU6; Tue, 18 Jun 2024 17:32:21 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJcgs-0000000G2lb-3xWw for kvm-riscv@lists.infradead.org; Tue, 18 Jun 2024 17:32:20 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-70436048c25so4444900b3a.0 for ; Tue, 18 Jun 2024 10:32:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718731938; x=1719336738; darn=lists.infradead.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=ypkPbGYy/TpBDV9TrPXgJvZPqdy0Vxo2bZrG/RprffY=; b=KX5eVS62B3IHohiQ8Lq+1ZlBizZo3L7Y9R8enbiOZ6GaKQGFU4XXCdV3en43736hCJ 4+rLyS3cyWxYEohP3pUu6sAa9MSQjtyFaUyvwrjE7oR2Uier0UNcrzNmUiHRs0VSvzMs EKSJNt0ZN9W0/uXCpn1m+ingXRiR66sJS0A9kOCfZx1mcvgCtu9wSHoB49xUrBdzNaic UdeY87f9KvaGn8zAOhC/1ofG2sN1rfISHlYcOx6bYt7y5fOIV+hFEzgCEedR6B2rnxLi bg2myd0Gc0046KfCnZnPQ/m84KM3EURkL2GYMnlqC3TL+f2em/GCcEewKt7E02sTshoy RVeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718731938; x=1719336738; 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=ypkPbGYy/TpBDV9TrPXgJvZPqdy0Vxo2bZrG/RprffY=; b=eA9gQDqCFVGGGKBP0LYO/GZ4c//gBOzdiTwOHHlFhW7ywAgqdwCF9pc6YQqUocAbnQ hnqFmHbbLrkQKdpIhvs9PYq2Y4YgU3iupg5NopkuP7dVGSTa+xQLaVWHB0v8IHfnRoPD OC6pNu/8MHgzbvbCgh3a46bFSKdyuX3KYqyMbs4UtLzTUyOhhDqHC9JhqRHTRJ2lk+7r 7CVmLhwQA3vHEmRvgUq/QsbvkXXKR01T97c/zKOTl5+hDgpM2Vb5V0cZqAIL50IkIfRV JcUIWed49L/i9ooIclkQcqEfHuKlNnEJawiDQ1FGDVjrhIGyE8U8LKGyEmdycIO6+Y4M zT+g== X-Forwarded-Encrypted: i=1; AJvYcCWzUTAoTjBLxeBPDc24UPGnW7nHiJpGPEm8ZuGcwNRGxRNMhOgE7iU/6k4td2pdyFfMpxUrrHCXXTL7DgjVP4dKXXRaLxuBJNftFHrRTg== X-Gm-Message-State: AOJu0YwdYqolInZqVx3tEcZ6Hwp8uk7pHnX7gy/S/0xsG2j0v8yJxzvj Avy1kvGWs1V4Q3Y8TTiriZDRNe4lu7I76FlTcAvLEu2l9JCBx7A5 X-Google-Smtp-Source: AGHT+IEmDKZRwJWnZ4x8OKOuCT3HIiVjDep+N0dF149o+YWdExxKftpxAeLEZ49bfDbdiA9ETiWUJQ== X-Received: by 2002:a17:90b:3104:b0:2c2:dd1d:ce6a with SMTP id 98e67ed59e1d1-2c7b5dca8ccmr365401a91.45.1718731937685; Tue, 18 Jun 2024 10:32:17 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c4a75ee5a5sm13529305a91.17.2024.06.18.10.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 10:32:17 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH 1/4] riscv: Extend exception handling support for interrupts Date: Wed, 19 Jun 2024 01:30:50 +0800 Message-ID: <20240618173053.364776-2-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618173053.364776-1-jamestiotio@gmail.com> References: <20240618173053.364776-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240618_103219_051678_1F4988F0 X-CRM114-Status: GOOD ( 12.70 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add install_irq_handler() to enable tests to install interrupt handlers. Also add local_irq_enable() and local_irq_disable() to respectively enable and disable IRQs via the sstatus.SIE bit. Signed-off-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/csr.h | 2 ++ lib/riscv/asm/processor.h | 13 +++++++++++++ lib/riscv/processor.c | 27 +++++++++++++++++++++++---- [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [jamestiotio(at)gmail.com] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42b listed in] [list.dnswl.org] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add install_irq_handler() to enable tests to install interrupt handlers. Also add local_irq_enable() and local_irq_disable() to respectively enable and disable IRQs via the sstatus.SIE bit. Signed-off-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/csr.h | 2 ++ lib/riscv/asm/processor.h | 13 +++++++++++++ lib/riscv/processor.c | 27 +++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/riscv/asm/csr.h b/lib/riscv/asm/csr.h index 52608512..d5879d2a 100644 --- a/lib/riscv/asm/csr.h +++ b/lib/riscv/asm/csr.h @@ -11,6 +11,8 @@ #define CSR_STVAL 0x143 #define CSR_SATP 0x180 +#define SSTATUS_SIE (_AC(1, UL) << 1) + /* Exception cause high bit - is an interrupt if set */ #define CAUSE_IRQ_FLAG (_AC(1, UL) << (__riscv_xlen - 1)) diff --git a/lib/riscv/asm/processor.h b/lib/riscv/asm/processor.h index 32c499d0..767b1caa 100644 --- a/lib/riscv/asm/processor.h +++ b/lib/riscv/asm/processor.h @@ -5,6 +5,7 @@ #include #define EXCEPTION_CAUSE_MAX 16 +#define INTERRUPT_CAUSE_MAX 16 typedef void (*exception_fn)(struct pt_regs *); @@ -13,6 +14,7 @@ struct thread_info { unsigned long hartid; unsigned long isa[1]; exception_fn exception_handlers[EXCEPTION_CAUSE_MAX]; + exception_fn interrupt_handlers[INTERRUPT_CAUSE_MAX]; }; static inline struct thread_info *current_thread_info(void) @@ -20,7 +22,18 @@ static inline struct thread_info *current_thread_info(void) return (struct thread_info *)csr_read(CSR_SSCRATCH); } +static inline void local_irq_enable(void) +{ + csr_set(CSR_SSTATUS, SSTATUS_SIE); +} + +static inline void local_irq_disable(void) +{ + csr_clear(CSR_SSTATUS, SSTATUS_SIE); +} + void install_exception_handler(unsigned long cause, void (*handler)(struct pt_regs *)); +void install_irq_handler(unsigned long cause, void (*handler)(struct pt_regs *)); void do_handle_exception(struct pt_regs *regs); void thread_info_init(void); diff --git a/lib/riscv/processor.c b/lib/riscv/processor.c index ece7cbff..0dffadc7 100644 --- a/lib/riscv/processor.c +++ b/lib/riscv/processor.c @@ -36,10 +36,21 @@ void do_handle_exception(struct pt_regs *regs) { struct thread_info *info = current_thread_info(); - assert(regs->cause < EXCEPTION_CAUSE_MAX); - if (info->exception_handlers[regs->cause]) { - info->exception_handlers[regs->cause](regs); - return; + if (regs->cause & CAUSE_IRQ_FLAG) { + unsigned long irq_cause = regs->cause & ~CAUSE_IRQ_FLAG; + + assert(irq_cause < INTERRUPT_CAUSE_MAX); + if (info->interrupt_handlers[irq_cause]) { + info->interrupt_handlers[irq_cause](regs); + return; + } + } else { + assert(regs->cause < EXCEPTION_CAUSE_MAX); + + if (info->exception_handlers[regs->cause]) { + info->exception_handlers[regs->cause](regs); + return; + } } show_regs(regs); @@ -47,6 +58,14 @@ void do_handle_exception(struct pt_regs *regs) abort(); } +void install_irq_handler(unsigned long cause, void (*handler)(struct pt_regs *)) +{ + struct thread_info *info = current_thread_info(); + + assert(cause < INTERRUPT_CAUSE_MAX); + info->interrupt_handlers[cause] = handler; +} + void install_exception_handler(unsigned long cause, void (*handler)(struct pt_regs *)) { struct thread_info *info = current_thread_info(); From patchwork Tue Jun 18 17:30:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 1949415 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=xu6Vwzo3; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TnRmEBft; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W3YjP3zD3z20Ws for ; Wed, 19 Jun 2024 03:32:25 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=J7rKd9kk9i8HerQKsK7dFQFBUbm9/Rao2FU/qTNp8ZU=; b=xu6Vwzo3dXEjzv yx+St4v9VLT6dMidyheGS2LBivU9XbxbFLIuA75L6Z0+aEK6+IDGuydi8Qf3kAoxvS6UVi2qb6Y7z 3AaDFyvdODcwtSNu1rU6jyd2x2GtG5d/KRfJQtqHZNSoU9+0WunJHfJW1+IWmYS/DtD6BR0CtXTSx jGEVqgZD1XUtI1+GIBdZR+5e5Is9h9FDl9/Z6wL/z7dvNMFJzLa9v9SvjuctPtlgzZFSPZeZMbSu1 xig5t2RfKBYu35wLdOwa0bruuR+YTpki3iop7g9efTnQgWG3fJB0WBmV9MUBSKAYlic3XPpvGptVR nQ7eWf7SRYSzwUrxXkIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJcgy-0000000G2pX-1ObN; Tue, 18 Jun 2024 17:32:24 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJcgu-0000000G2me-3HD8 for kvm-riscv@lists.infradead.org; Tue, 18 Jun 2024 17:32:22 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-70601bcfddcso2016447b3a.3 for ; Tue, 18 Jun 2024 10:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718731940; x=1719336740; darn=lists.infradead.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=Blulmc7pIET82cKP+ePX3OT26FWkLZf8vE5qV2TfTZA=; b=TnRmEBftLgOl5+NH+ekIfqC+jQzM3saxbEtFS1g5hNg4aDnXO0HhSFouXRFdFbOUx7 jci87mzP5G8iU7kdEVX42kJlHFY3jNMm76tRyHRTX2gqLATevdJkSn0fAdi3T5IV96xe NlNkbhHs9lHaToVJyQKAIAhVl11oRzkx8cHD26WKDBHgUtaeTqSmDEynYDLsiR4iOqBL OWzyRsi7hoX9dqcj51+LhY/5LsLBSuVG3WZkr7Q/+eHBUC69HktrTkIzC9xZmxQEPMyA j+v1s/comTJ+GqanMup3Nk4Ur+J0+pKz/J/S0+nAguvzRURRABl4XNOZgYs4cTN+JuJN Mr1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718731940; x=1719336740; 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=Blulmc7pIET82cKP+ePX3OT26FWkLZf8vE5qV2TfTZA=; b=dz5JU2BpuTpQjkrTQIAITvE7uMu+SopJnt3aoj/qdYloW6KgKFjvlL86Z4ZkuroguI 5HAbQCfD9FOfuKw0hD27CeN1g7UTs69IUbrchaj7B08FfX8j4R6reDo059/JOAArNXQ4 nwOZRi+Z/CC2MDE4+bHbR4FmnKJWnuCKk7hzhqPLSxX80p7tR73XugWIeQR7M1MWIKX6 I7HGhaXwwCBmjiFsoj8xhfsABir0z2LXOWBePEfY6gVVHaOR5uPGHwTv6I4lOXpa158V g1nJND0EvmPEnkWbExsYyTE78zUhDSODJ68LSHbJqx0ca7xapNFDIaXd4jUCmt3Oeqhk 2QvA== X-Forwarded-Encrypted: i=1; AJvYcCU6xMMOgchTedq+ezLz0K5a3AsyjyBWiEDskfcjMRFB4H8mTQMYb4Bo1W/MjN7fwD/B3IEDojTFDyS2xI5kEOlSk7VVFjHIKqCwAZOZdA== X-Gm-Message-State: AOJu0YzgI05OrudEIa9IJPlc6nusaTAZ9WVXd45hmViU5l9UFnZH77R/ Ih+sOg6Q0129Dddv79m+jHkRE2lVa2YViwqKqyxM90xWWYdOnznJ X-Google-Smtp-Source: AGHT+IGx8S9jQ3ds3aVy2ZQbfAouACrLu1UZ1btjCp4nsn/uJImlHjZZR82m8v5QLbJBPdxDfrYm8g== X-Received: by 2002:a17:90b:f92:b0:2bd:ef6b:c33b with SMTP id 98e67ed59e1d1-2c7b4a682a0mr513360a91.0.1718731939782; Tue, 18 Jun 2024 10:32:19 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c4a75ee5a5sm13529305a91.17.2024.06.18.10.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 10:32:19 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH 2/4] riscv: Update exception cause list Date: Wed, 19 Jun 2024 01:30:51 +0800 Message-ID: <20240618173053.364776-3-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618173053.364776-1-jamestiotio@gmail.com> References: <20240618173053.364776-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240618_103220_842575_1AFBC3B5 X-CRM114-Status: UNSURE ( 9.11 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Update the list of exception and interrupt causes to follow the latest RISC-V privileged ISA specification (version 20240411). Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/csr.h | 15 +++++++++------ lib/riscv/asm/processor.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [jamestiotio(at)gmail.com] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:436 listed in] [list.dnswl.org] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Update the list of exception and interrupt causes to follow the latest RISC-V privileged ISA specification (version 20240411). Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/csr.h | 15 +++++++++------ lib/riscv/asm/processor.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/riscv/asm/csr.h b/lib/riscv/asm/csr.h index d5879d2a..c1777744 100644 --- a/lib/riscv/asm/csr.h +++ b/lib/riscv/asm/csr.h @@ -26,15 +26,18 @@ #define EXC_STORE_MISALIGNED 6 #define EXC_STORE_ACCESS 7 #define EXC_SYSCALL 8 -#define EXC_HYPERVISOR_SYSCALL 9 -#define EXC_SUPERVISOR_SYSCALL 10 +#define EXC_SUPERVISOR_SYSCALL 9 #define EXC_INST_PAGE_FAULT 12 #define EXC_LOAD_PAGE_FAULT 13 #define EXC_STORE_PAGE_FAULT 15 -#define EXC_INST_GUEST_PAGE_FAULT 20 -#define EXC_LOAD_GUEST_PAGE_FAULT 21 -#define EXC_VIRTUAL_INST_FAULT 22 -#define EXC_STORE_GUEST_PAGE_FAULT 23 +#define EXC_SOFTWARE_CHECK 18 +#define EXC_HARDWARE_ERROR 19 + +/* Interrupt causes */ +#define IRQ_SUPERVISOR_SOFTWARE 1 +#define IRQ_SUPERVISOR_TIMER 5 +#define IRQ_SUPERVISOR_EXTERNAL 9 +#define IRQ_COUNTER_OVERFLOW 13 #ifndef __ASSEMBLY__ diff --git a/lib/riscv/asm/processor.h b/lib/riscv/asm/processor.h index 767b1caa..5942ed2e 100644 --- a/lib/riscv/asm/processor.h +++ b/lib/riscv/asm/processor.h @@ -4,7 +4,7 @@ #include #include -#define EXCEPTION_CAUSE_MAX 16 +#define EXCEPTION_CAUSE_MAX 64 #define INTERRUPT_CAUSE_MAX 16 typedef void (*exception_fn)(struct pt_regs *); From patchwork Tue Jun 18 17:30:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 1949416 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=jLd0Ev0y; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WZrr5/4q; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W3YjS3Lpmz20Ws for ; Wed, 19 Jun 2024 03:32:28 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Lq6JAdq6u9VMY9jcQj4adP4EPDdRHHURaMX2xPlADaA=; b=jLd0Ev0y8IH62z 836FYDMBsj3Fi4bnaOdeVROEdDE+VvfUbpO9mqqJw2AqrG3XXMoTfDvxqhqcy6ujwOtv+KxNbBzMO D/XyrDCt3bHRytw9vRW2seB1UX2Htc75cqhJ6GGSKSeCaPQ5n1hLByCMVkm2+zGXtdDZQcUziYlso RxVBZ1FzKkmPlEgAdGGLu6ecojoRsUdmw/7iCpyqhm5QMB6L/bXUH9q/jHXA8fBgsV3ocVeaZSesF C0tX9GJQEtxzyeCX1/oOUQE+gjKuy1HBpuAtbzzxsiGqY+Z1f31f9Ie6kmKFYHE332oh+thl3itGa A5QCsbaKB1aJXc85BRow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJch1-0000000G2rx-0jEe; Tue, 18 Jun 2024 17:32:27 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJcgy-0000000G2oy-0YIX for kvm-riscv@lists.infradead.org; Tue, 18 Jun 2024 17:32:25 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2c19bba897bso4887379a91.2 for ; Tue, 18 Jun 2024 10:32:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718731943; x=1719336743; darn=lists.infradead.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=PWxGifUK2SvPEf1BO6CmMLPV00mCLKHwlYt6Zz7pgPc=; b=WZrr5/4qQnZ6/2GPjdD3DdSE02yE/E+xFWkbuNh+kUHBtlabHXABoOb3tNTDwYMbKz 4uF0BmoFECl87aXkoBbTv97Q2OTjzV9SnRynZo7WWJDzPAt2v5+/8NzKeDp36ufgvsCL 7uFhvv3mf1OOX4MypvHHKMCykkQLVflomkjM40f7QtsEMx3ROXOg+vdiykxTlkzQbQtu nZScbo3rlgi9RzK9yU+mmWiRcN+Pi75Qg3qU44BaLyp7y30dCkAKVv5peCDQ2nV/BiOq AMZpB1/lDHk3NnErSwL3ON1BTmrIEiwnzLc/XQTC23VyethfkfxFrjbKQufjLilGQWcH QxMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718731943; x=1719336743; 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=PWxGifUK2SvPEf1BO6CmMLPV00mCLKHwlYt6Zz7pgPc=; b=eCtTqIbsX999V5PeOIkq9j8dtmA7AGR2p7EHIUWePGDhBwPCANzpjj7zO8NUdwQA9k XD3jYeJUBbVr5LfnaO60FHu8uptT/IVb3dPqx1F2O4167zOVdFGKOsNu7xZs/kH69DU6 0Kg1TfNauVjsbc4Bt+mTXHhIPtgpK1zFWwOCgTa7f9ZI8g/k0ipHOZXp7ns8qR/7i0fp 812pun9p6aG6nwkJYRett7i+ayO7sxIukCL4ekmXqikUjJ5PY3Tnbsw4j0H4usJVztj+ tHzGPiSQ7WikiBWLN2m3TQbv5KwqXFFxjjWSw1Y2Qw+76g88ZgG4zxfGz5EofRuvT6b6 1gxw== X-Forwarded-Encrypted: i=1; AJvYcCUEc3pAi6MKtqG+s3SgDAHzDs3/ptk9ONcO+udkqNLPLEwfblws0TJmPTRm0g9qtNTTOV66YX6NalEN/WyN/f4dkj4AhY0BiG1RrrEnzw== X-Gm-Message-State: AOJu0YzIESEm4qcCpgNRP8pEMfr7xjHVwr0hq6ibZOUZ8KEn0/igful5 ledLA+VTT2jNoopZ3x42rT4zNjn9tNsyzl/YpGQEm7ZbnfbiUP5byDrGY4r1 X-Google-Smtp-Source: AGHT+IG0z7MBG/kZ+UiDHnDdP5GEeh4qij7yknA/KoUMASQ8r7/Z5Ko3g4gmX+10IevrwdjVn4XP2w== X-Received: by 2002:a17:90a:c908:b0:2c4:b12b:fcc with SMTP id 98e67ed59e1d1-2c7b5cc800fmr359986a91.27.1718731941941; Tue, 18 Jun 2024 10:32:21 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c4a75ee5a5sm13529305a91.17.2024.06.18.10.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 10:32:21 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH 3/4] riscv: Add methods to toggle interrupt enable bits Date: Wed, 19 Jun 2024 01:30:52 +0800 Message-ID: <20240618173053.364776-4-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618173053.364776-1-jamestiotio@gmail.com> References: <20240618173053.364776-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240618_103224_217949_E85EA0EA X-CRM114-Status: GOOD ( 13.24 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add some helper methods to toggle the interrupt enable bits in the SIE register. Signed-off-by: James Raphael Tiovalen --- riscv/Makefile | 1 + lib/riscv/asm/csr.h | 7 +++++++ lib/riscv/asm/interrupt.h | 12 ++++++++++++ lib/riscv/interrupt.c | 39 ++++++++++++++++++++++++++++++++ [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [jamestiotio(at)gmail.com] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:102b listed in] [list.dnswl.org] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add some helper methods to toggle the interrupt enable bits in the SIE register. Signed-off-by: James Raphael Tiovalen --- riscv/Makefile | 1 + lib/riscv/asm/csr.h | 7 +++++++ lib/riscv/asm/interrupt.h | 12 ++++++++++++ lib/riscv/interrupt.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 lib/riscv/asm/interrupt.h create mode 100644 lib/riscv/interrupt.c diff --git a/riscv/Makefile b/riscv/Makefile index 919a3ebb..108d4481 100644 --- a/riscv/Makefile +++ b/riscv/Makefile @@ -30,6 +30,7 @@ cflatobjs += lib/memregions.o cflatobjs += lib/on-cpus.o cflatobjs += lib/vmalloc.o cflatobjs += lib/riscv/bitops.o +cflatobjs += lib/riscv/interrupt.o cflatobjs += lib/riscv/io.o cflatobjs += lib/riscv/isa.o cflatobjs += lib/riscv/mmu.o diff --git a/lib/riscv/asm/csr.h b/lib/riscv/asm/csr.h index c1777744..da58b0ce 100644 --- a/lib/riscv/asm/csr.h +++ b/lib/riscv/asm/csr.h @@ -4,15 +4,22 @@ #include #define CSR_SSTATUS 0x100 +#define CSR_SIE 0x104 #define CSR_STVEC 0x105 #define CSR_SSCRATCH 0x140 #define CSR_SEPC 0x141 #define CSR_SCAUSE 0x142 #define CSR_STVAL 0x143 +#define CSR_SIP 0x144 #define CSR_SATP 0x180 #define SSTATUS_SIE (_AC(1, UL) << 1) +#define SIE_SSIE (_AC(1, UL) << 1) +#define SIE_STIE (_AC(1, UL) << 5) +#define SIE_SEIE (_AC(1, UL) << 9) +#define SIE_LCOFIE (_AC(1, UL) << 13) + /* Exception cause high bit - is an interrupt if set */ #define CAUSE_IRQ_FLAG (_AC(1, UL) << (__riscv_xlen - 1)) diff --git a/lib/riscv/asm/interrupt.h b/lib/riscv/asm/interrupt.h new file mode 100644 index 00000000..b760afbb --- /dev/null +++ b/lib/riscv/asm/interrupt.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASMRISCV_INTERRUPT_H_ +#define _ASMRISCV_INTERRUPT_H_ + +#include + +void toggle_software_interrupt(bool enable); +void toggle_timer_interrupt(bool enable); +void toggle_external_interrupt(bool enable); +void toggle_local_cof_interrupt(bool enable); + +#endif /* _ASMRISCV_INTERRUPT_H_ */ diff --git a/lib/riscv/interrupt.c b/lib/riscv/interrupt.c new file mode 100644 index 00000000..bc0e16f1 --- /dev/null +++ b/lib/riscv/interrupt.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024, James Raphael Tiovalen + */ +#include +#include +#include + +void toggle_software_interrupt(bool enable) +{ + if (enable) + csr_set(CSR_SIE, SIE_SSIE); + else + csr_clear(CSR_SIE, SIE_SSIE); +} + +void toggle_timer_interrupt(bool enable) +{ + if (enable) + csr_set(CSR_SIE, SIE_STIE); + else + csr_clear(CSR_SIE, SIE_STIE); +} + +void toggle_external_interrupt(bool enable) +{ + if (enable) + csr_set(CSR_SIE, SIE_SEIE); + else + csr_clear(CSR_SIE, SIE_SEIE); +} + +void toggle_local_cof_interrupt(bool enable) +{ + if (enable) + csr_set(CSR_SIE, SIE_LCOFIE); + else + csr_clear(CSR_SIE, SIE_LCOFIE); +} From patchwork Tue Jun 18 17:30:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 1949417 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Wjl5aQea; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WLQi2K09; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W3YjW2JRXz20Ws for ; Wed, 19 Jun 2024 03:32:31 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=se3nQqNyxdUvl+5ygXyKKdeOyYpvsiG8BD7hVmzLED8=; b=Wjl5aQeaOd40+g SWHBNJagZmMY1a28eqzafZqRFJXQwF4iz/zVLYXCfao5RGb93/KTw1o7lgHqovBh0YyGsz5Gs8xYj h36r8XXyWGTrp6EZIK2GCZtkB3LfFA0DC1OjKi6Ile1i+5bkphJL5ybbViDKTy/jxsf0qFC/cqMF6 nebvACP+DTB5t1BX9FtzJD/XSf/DgEjUJNd5v2iRgj/YMRnYIB4AbQNSeBvzmHdTkK1aiuPO/gZuZ PHir7OSvhK0Z4hqYTRnvnNXR4fqGiMosLgYotFOIub1lqp4ObO3ojQfOxoB417/IGDEbO17OcQMe6 NeFWqslFNJX/3EMZ7rBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJch3-0000000G2tN-4AcL; Tue, 18 Jun 2024 17:32:30 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJch0-0000000G2r0-30Mc for kvm-riscv@lists.infradead.org; Tue, 18 Jun 2024 17:32:28 +0000 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2c7b14bb4a5so43763a91.0 for ; Tue, 18 Jun 2024 10:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718731946; x=1719336746; darn=lists.infradead.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=uJ0IRqtJQTxYM5sbu/JBOLam6TAEXhPiQOr+HxYnzUE=; b=WLQi2K09xZwoYkq8mMoa5ZW/6DRikSYk+JlfgMJ05TBttb+tfC292SHjN5uKPzatxN XBRUZ3U9Z+6Gqq7jSS6lVXrs/TW+nkUKvpQSZurG3iXzcRUUDL4GiXAj5Bj4spCxVQ5I xdXl7G1FvdphKRBnw/EqJJZD+5K6qJhNzyefLD69Rk7A+jgPHimvm8s6md0e1/8kRLWF DY1V6HcrrFIPa5+TZhmrYnTsNIX5t4hN1L7dLrVMrkUWoUuX06FjPegS5f9eNXEAclXu XdRlQFeNAMMc5BXgdWBE6g5yt8SBGIUFzm5iOuGfDxbc1AiwZ4OzvAYPndr5hYfOzRmj 59rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718731946; x=1719336746; 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=uJ0IRqtJQTxYM5sbu/JBOLam6TAEXhPiQOr+HxYnzUE=; b=VEfmjCZc+zo1ZgpCiS472ExC6PTk1ItrE1sfpT3bGqiJ+/VxuOSFsfdEGregf4dJ8r roObzr2f7x/L4oGjx25biveOhqdbSdtyCyRFE3mbUMQm8xmULXvn/bT4nTHxjPSsjJpQ lKN08L1tSCTMqujnbOesyp+QN9q5xQB1xU8qm2phlRKJLPqkRCuy+G779F26gKDy4nHq 16Pf++acPGb48AaQ2J4pwNe87iE/hzZ88BjOhEheWk2vv9wh+EnmtHviP7KcTYT30PgL zC/h0IeQioMr43GKvl7FLsNASyWjgNFTJG5jBDzyfdg9HuriPLT4C0TfUYgj/yEb1G7F aNZw== X-Forwarded-Encrypted: i=1; AJvYcCVmH3DlsYmXY+M2p5yJReAPlBEV/IhZm93FAJRJucY/rCLmXcR4qp5uu6lVCrxgtf1q7gOD3KHGh9mffwuwmpAFGLAny4tytw2ND9UCng== X-Gm-Message-State: AOJu0Yw2NMiRz5OYf3pnJuSSjS/iI8ZCo/HkIpFdNUAKKvc6um/nH8f6 Dsi3aNPcj0oPXUozDqjr16bdVIiQh9aNxsfd9MF5G92RmdIx1NQUsCrbnyZ3 X-Google-Smtp-Source: AGHT+IHkLL4UhbVsE2pTLofbKhxmfl27h0FIlAgw5Vx/t7KgFu3OHOmecQE0PalhWlfXeyW89WK2Kw== X-Received: by 2002:a17:90a:6d24:b0:2c2:12d:fa01 with SMTP id 98e67ed59e1d1-2c6c951fa1bmr4819776a91.11.1718731945445; Tue, 18 Jun 2024 10:32:25 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c4a75ee5a5sm13529305a91.17.2024.06.18.10.32.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 10:32:25 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH 4/4] riscv: sbi: Add test for timer extension Date: Wed, 19 Jun 2024 01:30:53 +0800 Message-ID: <20240618173053.364776-5-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618173053.364776-1-jamestiotio@gmail.com> References: <20240618173053.364776-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240618_103226_790104_B63B8314 X-CRM114-Status: GOOD ( 18.02 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add a test for the set_timer function of the time extension. The test checks that: - The time extension is available - The time counter monotonically increases - The installed timer interrupt handler [...] Content analysis details: (-0.2 points, 5.0 required) 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:1036 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [jamestiotio(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add a test for the set_timer function of the time extension. The test checks that: - The time extension is available - The time counter monotonically increases - The installed timer interrupt handler is called - The timer interrupt is received within a reasonable time frame The timer interrupt delay can be set using the TIMER_DELAY environment variable. If the variable is not set, the default delay value is 1000000. The time interval used to validate the timer interrupt is between the specified delay and double the delay. Because of this, the test might fail if the delay is too short. Hence, we set the default delay value as the minimum value. This test has been verified on RV32 and RV64 with OpenSBI using QEMU. Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/csr.h | 6 ++++ lib/riscv/asm/sbi.h | 5 +++ riscv/sbi.c | 87 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) diff --git a/lib/riscv/asm/csr.h b/lib/riscv/asm/csr.h index da58b0ce..c4435650 100644 --- a/lib/riscv/asm/csr.h +++ b/lib/riscv/asm/csr.h @@ -12,6 +12,7 @@ #define CSR_STVAL 0x143 #define CSR_SIP 0x144 #define CSR_SATP 0x180 +#define CSR_TIME 0xc01 #define SSTATUS_SIE (_AC(1, UL) << 1) @@ -108,5 +109,10 @@ : "memory"); \ }) +#define wfi() \ +({ \ + __asm__ __volatile__("wfi" ::: "memory"); \ +}) + #endif /* !__ASSEMBLY__ */ #endif /* _ASMRISCV_CSR_H_ */ diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index d82a384d..eb4c77ef 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -18,6 +18,7 @@ enum sbi_ext_id { SBI_EXT_BASE = 0x10, SBI_EXT_HSM = 0x48534d, SBI_EXT_SRST = 0x53525354, + SBI_EXT_TIME = 0x54494D45, }; enum sbi_ext_base_fid { @@ -37,6 +38,10 @@ enum sbi_ext_hsm_fid { SBI_EXT_HSM_HART_SUSPEND, }; +enum sbi_ext_time_fid { + SBI_EXT_TIME_SET_TIMER = 0, +}; + struct sbiret { long error; long value; diff --git a/riscv/sbi.c b/riscv/sbi.c index 762e9711..6ad1dff6 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -6,8 +6,13 @@ */ #include #include +#include +#include +#include #include +static bool timer_work; + static void help(void) { puts("Test SBI\n"); @@ -19,6 +24,18 @@ static struct sbiret __base_sbi_ecall(int fid, unsigned long arg0) return sbi_ecall(SBI_EXT_BASE, fid, arg0, 0, 0, 0, 0, 0); } +static struct sbiret __time_sbi_ecall(int fid, unsigned long arg0) +{ + return sbi_ecall(SBI_EXT_TIME, fid, arg0, 0, 0, 0, 0, 0); +} + +static void timer_interrupt_handler(struct pt_regs *regs) +{ + timer_work = true; + toggle_timer_interrupt(false); + local_irq_disable(); +} + static bool env_or_skip(const char *env) { if (!getenv(env)) { @@ -112,6 +129,75 @@ static void check_base(void) report_prefix_pop(); } +static void check_time(void) +{ + struct sbiret ret; + unsigned long begin, end, duration; + const unsigned long default_delay = 1000000; + unsigned long delay = getenv("TIMER_DELAY") + ? MAX(strtol(getenv("TIMER_DELAY"), NULL, 0), default_delay) + : default_delay; + + report_prefix_push("time"); + + ret = __base_sbi_ecall(SBI_EXT_BASE_PROBE_EXT, SBI_EXT_TIME); + + if (ret.error) { + report_fail("probing for time extension failed"); + report_prefix_pop(); + return; + } + + if (!ret.value) { + report_skip("time extension not available"); + report_prefix_pop(); + return; + } + + begin = csr_read(CSR_TIME); + end = csr_read(CSR_TIME); + if (begin >= end) { + report_fail("time counter has decreased"); + report_prefix_pop(); + return; + } + + report_prefix_push("set_timer"); + + install_irq_handler(IRQ_SUPERVISOR_TIMER, timer_interrupt_handler); + local_irq_enable(); + + begin = csr_read(CSR_TIME); + ret = __time_sbi_ecall(SBI_EXT_TIME_SET_TIMER, csr_read(CSR_TIME) + delay); + + if (ret.error) { + report_fail("setting timer failed"); + install_irq_handler(IRQ_SUPERVISOR_TIMER, NULL); + report_prefix_pop(); + report_prefix_pop(); + return; + } + + toggle_timer_interrupt(true); + + while ((!timer_work) && (csr_read(CSR_TIME) <= (begin + delay))) + wfi(); + + end = csr_read(CSR_TIME); + report(timer_work, "timer interrupt received"); + + install_irq_handler(IRQ_SUPERVISOR_TIMER, NULL); + __time_sbi_ecall(SBI_EXT_TIME_SET_TIMER, -1); + + duration = end - begin; + if (timer_work) + report((duration >= delay) && (duration <= (delay + delay)), "timer delay honored"); + + report_prefix_pop(); + + report_prefix_pop(); +} + int main(int argc, char **argv) { @@ -122,6 +208,7 @@ int main(int argc, char **argv) report_prefix_push("sbi"); check_base(); + check_time(); return report_summary(); }