From nobody Tue Mar 3 04:56:17 2026 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=1771604401; cv=none; d=zohomail.com; s=zohoarc; b=WPBqc/iJB9umDVBPR+kgnMk8KLcKZzMahi9u6CexQWcJsSsZTPS5NfHTrlkGtXcesc0EbCXMKYoxcQ3CjL4fS70f9Ob6Uks9yjCMyHA8kr90WZ/nMQ0SL/hhhAizOfmy92/llagYcboD2unTO1GXf7xQ3Nc7eyLaxi9KHGAn92c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604401; 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=LVcUz3go1ll+YJIGlumu2dTw8eguMhCxN9OercwjZDI=; b=GXwW2OZiiRmO+q9t4vwydUViAf2G1G/OPG7gsx50yfXFyyAdc96OE6qZQgBkRYK3B1XonG9C7gWBLMQVUe6SH1cd4X2y4dJtgWW5B90qLRbk148/C/6Bv07Z/0b96kZOYqRWf3bPaglxfuxSfOYTX7RsBWqMs4mvVeibIlGCkNA= 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 1771604401165274.58524998016526; Fri, 20 Feb 2026 08:20:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237345.1539783 (Exim 4.92) (envelope-from ) id 1vtTE7-0002vM-B3; Fri, 20 Feb 2026 16:19:35 +0000 Received: by outflank-mailman (output) from mailman id 1237345.1539783; Fri, 20 Feb 2026 16:19:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTE6-0002uM-JO; Fri, 20 Feb 2026 16:19:34 +0000 Received: by outflank-mailman (input) for mailman id 1237345; Fri, 20 Feb 2026 16:19:33 +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 1vtTE5-0000QF-1W for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:33 +0000 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [2a00:1450:4864:20::333]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id efbaaea8-0e77-11f1-b164-2bf370ae4941; Fri, 20 Feb 2026 17:19:31 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4806f3fc50bso25267825e9.0 for ; Fri, 20 Feb 2026 08:19:31 -0800 (PST) Received: from fedora (user-109-243-67-101.play-internet.pl. [109.243.67.101]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43796a6c1bfsm56991068f8f.13.2026.02.20.08.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:29 -0800 (PST) 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: efbaaea8-0e77-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604370; x=1772209170; 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=LVcUz3go1ll+YJIGlumu2dTw8eguMhCxN9OercwjZDI=; b=CzeyzsZjuhdp/nIFRyeEcHvL49z9phXXI56AG299PMzLzy/6+yEXm853eQeOw9H544 V6nPezqQvNWhmhx/kC7Tq5ChH1OFC32yyG8uZtXUBkOTJpxModNaXZhXKj6GyVb6VUc3 XUd1hBBMpC2l/v/DkKXnPgYWaFVzDbnZJcy0cqjQDdU0NLCwwmBAm4++sYmJNk2Yhzm0 kWJoJQd9EosiaZ3pbjkfH0B+jMeG8wCLR4s66PgQckgpD1KkcDMmniFpHG+z4N1lhbXm cvnEf6V8cOjzwZgsb6KlsyV0j8foLgeTamzjLCCfO0p3BQT0vhjLpvPYtI5WozevnLTr nrhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604370; x=1772209170; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LVcUz3go1ll+YJIGlumu2dTw8eguMhCxN9OercwjZDI=; b=a6xzsrPIqxIi4CIDLko2BsH1AVqlDWv8Pxw7QI06M/vsMNifu18VWZY2RD1oG6ult+ 3AvEQInK6o4CDzfJatl6x1TcFfkwv4/1IhpbH/q3OA6nEykFdA4wls9QtUHzQMMuWGPj 8XsG93dai54nazGtoMMmSHh6xIqCHCA7CbIgr1Q7XaQ1CMkkVpbTZGERQGSeCj28zENZ sEXVyKWElyg2NNN5YmGlzzOf/QM82USOH64nplri0RK1bsZK/YXpZZX2WnmwetYTT+Sx Gq8BFoE+mW/m5+f5Ayn4bjKeRZW7uxlai2SbHBs4WqHde2ZOGAEoQXhKqjgJH0eEHnSQ qw+Q== X-Gm-Message-State: AOJu0YyN83T2u4HF8WK7Z3jrvlNPtY2POxBJO8NzyBNC/+OMAHE4ppcC xirlHRISRUnt7DBovF0WQ0d4sCqCHXGFqGGO1PwMWSG5iqpLgbNNvf7VPn/4sA== X-Gm-Gg: AZuq6aLWuUuJUvozgwkiAKh7TjuR/f17Sk8aMVi7iHHmXVnM0PnSuHNaO33zjSslY+0 ZABSHJuB36axSza8eCfP/CFc8FUAYI751Tn1Cpkos0hAvDIgL7ZWV1zHyg2BOzHANZb9oeThHWV Rf1wGP9Vh7zCO4x/jmaHZbGUfH8RR1zjK4oRh21noFCSaB5UFBfQ9x6gwy0Yth7ViGL666qIbY8 yTcrOdXBu00Ee2PwfNI6zMRKf0lwJyRRW7HsG/jrNxpfZE7su8HC6wjbr7xMjiNp/l+Ltv8Addf ZfR14AFA3lobv39c1OJ9ybv9aHxwtrpHmLLdPqpJmfTK5g+qqPUVZS0fkGFamZcKyfBXcz7a9Ux ntb6ab6oeblWmsqTVa6uSl2jFCsouXcAUPKxRx8JK4c4EdigwtfEMNzL48ZEDl4QkztvKsraVfl FcdEppcTzHuJYkfd52q4N/uaqx9YYCS5127LIakcEkHYi5AdXMzZhXA3LqiZh0XcyiRQ== X-Received: by 2002:a05:600c:3516:b0:477:9b4a:a82 with SMTP id 5b1f17b1804b1-483a963df3cmr542505e9.35.1771604370417; Fri, 20 Feb 2026 08:19:30 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Oleksii Kurochko , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v5 11/14] xen/riscv: implement reprogram_timer() via SBI Date: Fri, 20 Feb 2026 17:19:06 +0100 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1771604403078158500 Content-Type: text/plain; charset="utf-8" Implement reprogram_timer() on RISC-V using the standard SBI timer call. The privileged architecture only defines machine-mode timer interrupts (using mtime/mtimecmp). Therefore, timer services for S/HS/VS mode must be provided by M-mode via SBI calls. SSTC (Supervisor-mode Timer Control) is optional and is not supported on the boards available to me, so the only viable approach today is to program the timer through SBI. reprogram_timer() enables/disables the supervisor timer interrupt and programs the next timer deadline using sbi_set_timer(). If the SBI call fails, the code panics, because sbi_set_timer() is expected to return either 0 or -ENOSUPP (this has been stable from early OpenSBI versions to the latest ones). The SBI spec does not define a standard negative error code for this call, and without SSTC there is no alternative method to program the timer, so the SBI timer call must be available. reprogram_timer() currently returns int for compatibility with the existing prototype. While it might be cleaner to return bool, keeping the existing signature avoids premature changes in case sbi_set_timer() ever needs to return other values (based on which we could try to avoid panic-ing) in the future. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v5: - Nothing changed. Only rebase. --- Changes in v4: - Add Acked-by: Jan Beulich . --- Changes in v3: - Correct the comments in reprogram_timer(). - Move enablement of timer interrupt after sbi_set_timer() to avoid potentially receiving a timer interrupt between these 2 operations. --- Changes in v2: - Add TODO comment above sbi_set_timer() call. - Update the commit message. --- xen/arch/riscv/stubs.c | 5 ----- xen/arch/riscv/time.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index eedf8bf9350a..2f3a0ce76af9 100644 --- a/xen/arch/riscv/stubs.c +++ b/xen/arch/riscv/stubs.c @@ -21,11 +21,6 @@ nodemask_t __read_mostly node_online_map =3D { { [0] =3D= 1UL } }; =20 /* time.c */ =20 -int reprogram_timer(s_time_t timeout) -{ - BUG_ON("unimplemented"); -} - void send_timer_event(struct vcpu *v) { BUG_ON("unimplemented"); diff --git a/xen/arch/riscv/time.c b/xen/arch/riscv/time.c index 2c7af0a5d63b..7efa76fdbcb1 100644 --- a/xen/arch/riscv/time.c +++ b/xen/arch/riscv/time.c @@ -7,6 +7,9 @@ #include #include =20 +#include +#include + unsigned long __ro_after_init cpu_khz; /* CPU clock frequency in kHz. */ uint64_t __ro_after_init boot_clock_cycles; =20 @@ -40,6 +43,46 @@ static void __init preinit_dt_xen_time(void) cpu_khz =3D rate / 1000; } =20 +int reprogram_timer(s_time_t timeout) +{ + uint64_t deadline, now; + int rc; + + if ( timeout =3D=3D 0 ) + { + /* Disable timer interrupt */ + csr_clear(CSR_SIE, BIT(IRQ_S_TIMER, UL)); + + return 1; + } + + deadline =3D ns_to_ticks(timeout) + boot_clock_cycles; + now =3D get_cycles(); + if ( deadline <=3D now ) + return 0; + + /* + * TODO: When the SSTC extension is supported, it would be preferable = to + * use the supervisor timer registers directly here for better + * performance, since an SBI call and mode switch would no longer + * be required. + * + * This would also reduce reliance on a specific SBI implementat= ion. + * For example, it is not ideal to panic() if sbi_set_timer() re= turns + * a non-zero value. Currently it can return 0 or -ENOSUPP, and + * without SSTC we still need an implementation because only the + * M-mode timer is available, and it can only be programmed in + * M-mode. + */ + if ( (rc =3D sbi_set_timer(deadline)) ) + panic("%s: timer wasn't set because: %d\n", __func__, rc); + + /* Enable timer interrupt */ + csr_set(CSR_SIE, BIT(IRQ_S_TIMER, UL)); + + return 1; +} + void __init preinit_xen_time(void) { if ( acpi_disabled ) --=20 2.53.0