From nobody Tue Mar 3 03:02:46 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=1771604388; cv=none; d=zohomail.com; s=zohoarc; b=OAC57UNRrtiD8L5D4aP14u9PCt+WC2tX4LH/k5JAIrFBdUxqUOAXQi1PehfbQxLsd0YqtkFVfF843Zw3aaNysyzRCIIplRJja08usP3YsaBvS9gmhjMwyCf+BkWMHeF3MgBp60CoiK5L7K52dH9xHGp+ESqIqJGfYsCLZ8aHQ1E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604388; 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=VGHRmL2iWDUaQ6x5sen7QQ6MZAJ2q1tuNN96Ty+TTdE=; b=WLtLrvbKmcYkDpxQyW3XonExJoVYWmXrFXcaOAntfynv684u5Rq0Y++S3+iEk3DKLoNRSsk0tEDG9fk7Zck56EOBJ4QiNBiIdlIvqCPY8Br+6Zdbhima/TtNSToA4iKJXgmLeSn+v1lsBL+6aXLmvFHFd3SZY0TXOFQBVKUamVo= 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 1771604388745357.36780776324815; Fri, 20 Feb 2026 08:19:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237333.1539685 (Exim 4.92) (envelope-from ) id 1vtTDw-0000Sw-0I; Fri, 20 Feb 2026 16:19:24 +0000 Received: by outflank-mailman (output) from mailman id 1237333.1539685; Fri, 20 Feb 2026 16:19:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTDv-0000SD-Qw; Fri, 20 Feb 2026 16:19:23 +0000 Received: by outflank-mailman (input) for mailman id 1237333; Fri, 20 Feb 2026 16:19:22 +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 1vtTDu-0000Q4-BJ for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:22 +0000 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [2a00:1450:4864:20::429]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e8b2aab6-0e77-11f1-9ccf-f158ae23cfc8; Fri, 20 Feb 2026 17:19:19 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-4327790c4e9so1559300f8f.2 for ; Fri, 20 Feb 2026 08:19:19 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:18 -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: e8b2aab6-0e77-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604359; x=1772209159; 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=VGHRmL2iWDUaQ6x5sen7QQ6MZAJ2q1tuNN96Ty+TTdE=; b=ZQLrgv8eFLYDpJg95KnrAGIIavZTmeLkRnxv06MDoVAzytzIjfz9He51eiBQBZPA/+ sW6KJO9Ej/pkMXWYJA7xDt0DtgVxx8vJ0ZIsIKfpqqNKaUIbZ2LccySj3sZZH5UITa7V YvqVT07i9gBRMAdLzD5KPrwa6TEOm0bmfHPa4ZsEgz14RjsoeHASsbMflfs0jwHbfwJP 4uYYctL4sS/u8g+Tf4cdBIFQqCJ7AqT9J6ypk9P/MR3w5WB47GFX4jcQ4cGgWve9XGc3 tRjawvmvPmWL7W2qXTuWNKT+WLmUBZmYHbKfxXRHCX74bxBuqcizNtSFhlbvFJhyFVe3 jngA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604359; x=1772209159; 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=VGHRmL2iWDUaQ6x5sen7QQ6MZAJ2q1tuNN96Ty+TTdE=; b=Bwoh3DQ2B2ZCGboU76Mr25XXZdOke4rQ2eTzcFNbuHVjXDbBA0gqoU5JeWbVy0evtd taig8jAVlSw96ml3XmNUhV8OB0F3241jCeeObcQ0cEGRkhUj/opYyw2WSpW2jCuIbJnt EVgK252e1N1qpudxwgc5qfIT67V7RH61hlrnwyy5o1YZdPOojaNS9IqLqKcdCPaiK88s LSLZ8AqYVJF0qj/tv9CUevIlSe0hw2sT+9xQ2Fc/DhiAM9SJltIZShttuCQHZfgm6Vng fF+KpJqpTVudZKKk7LjOK12RHLXFeHMKVKhmgMsmPqP0VFsOaFLhzY2uAlLW26IWKdN8 L+6g== X-Gm-Message-State: AOJu0YyQrFhcZoAnSBuH8sspuEHAzUmKvFeqJD4Q4JPecDpqEQy3AAog ssHTBs8+IKljHgNYzYal9BlQmK6jjIUyIJQykuav6ebpPLDV9x2kieICfZ3JzQ== X-Gm-Gg: AZuq6aIpCwDzsomnfPtG/qmgUgtGeWIiplgi50mrmbN/GUOnAnw8wmZ1O8JsZZ3XaP5 2WaLP3Gfav3111EEgdWBTjDL4jtcARcJ7EU9jKNFBQm9LQuKMNR0nkMbhP9u0orTr9Y6GUFwgQp IvE83iK/P8braeEC8WRvqua0fwyW6mDqyVxG7ld07bu3YbKbaS8KdQRRK42dqidRZ/Ub7Zes5sF v3pFaA47OUVpeME4b+ejjO1ak1Z/LkRLCaji5jSLoc8+IuFYTIKWexJTHAkDKSpV+ePtaVwiVfd k+lvLg/XsvVER92TB1EatL1edCTO3eUsxkGddPLvbToSLrxbBRbDlg4acy1ZCsCvS8bNnD6A9HY BrKIOuwJsEjEauCVfpXRrOi/vcgz4nelcrma5h3YMZwkMYkaL7Adm2TdLP+lomt7MN/ljcBECt9 u+IdckcDy/sE7zSf79qsB8x7vWSXWUNzzv1gmZ8IiYR6C5zdwcg6nGXss23cTZ+czD2A== X-Received: by 2002:a05:6000:26cd:b0:436:369f:39f9 with SMTP id ffacd0b85a97d-4396f1a70b5mr756546f8f.57.1771604358526; Fri, 20 Feb 2026 08:19:18 -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 01/14] xen/riscv: detect and store supported hypervisor CSR bits at boot Date: Fri, 20 Feb 2026 17:18:56 +0100 Message-ID: <4f36d83e58bfba807660ebc1fc48e71ae056805a.1771590794.git.oleksii.kurochko@gmail.com> 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: 1771604392954158500 Content-Type: text/plain; charset="utf-8" Some hypervisor CSRs expose optional functionality and may not implement all architectural bits. Writing unsupported bits can either be ignored or raise an exception depending on the platform. Detect the set of writable bits for selected hypervisor CSRs at boot and store the resulting masks for later use. This allows safely programming these CSRs during vCPU context switching and avoids relying on hardcoded architectural assumptions. Note that csr_set() is used instead of csr_write() to write all ones to the mask, as the CSRRS instruction, according to the RISC-V specification, sets only those bits that are writable (note that the quote consider only non-read-only CSRs as writing to read-only CSRs according to the spec. will raise an exception): Any bit that is high in rs1 will cause the corresponding bit to be set in the CSR, if that CSR bit is writable. In contrast, the CSRRW instruction does not take CSR bit writability into account, which could lead to unintended side effects when writing all ones to a CSR. Masks are calculated at the moment only for hedeleg, henvcfg, hideleg, hstateen0 registers as only them are going to be used in the follow up patch. If the Smstateen extension is not implemented, hstateen0 cannot be read because the register is considered non-existent. Instructions that attempt to access a CSR that is not implemented or not visible in the current mode are reserved and will raise an illegal-instruction exception. Signed-off-by: Oleksii Kurochko Reviewed-by: Jan Beulich --- Changes in V5: - Move everything related to csr_masks to domain.c and make it static. - Move declaration of old variable in init_csr_masks() inside INIT_CSR_MAS= K. - Use csr_swap() in INIT_CSR_MASK(). --- Changes in V4: - Move csr_masks defintion to domain.c. Make it static as at the moment it is going to be used only in domain.c. - Rename and refactor X macros inside init_csr_masks(). --- Changes in V3: - New patch. --- xen/arch/riscv/domain.c | 30 ++++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/setup.h | 2 ++ xen/arch/riscv/setup.c | 2 ++ 3 files changed, 34 insertions(+) diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index b60320b90def..8b05f0f23b77 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -2,9 +2,39 @@ =20 #include #include +#include #include #include =20 +#include +#include + +struct csr_masks { + register_t hedeleg; + register_t henvcfg; + register_t hideleg; + register_t hstateen0; +}; + +static struct csr_masks __ro_after_init csr_masks; + +void __init init_csr_masks(void) +{ +#define INIT_CSR_MASK(csr, field) do { \ + register_t old; \ + old =3D csr_read(CSR_##csr); \ + csr_set(CSR_##csr, ULONG_MAX); \ + csr_masks.field =3D csr_swap(CSR_##csr, old); \ +} while (0) + + INIT_CSR_MASK(HEDELEG, hedeleg); + INIT_CSR_MASK(HENVCFG, henvcfg); + INIT_CSR_MASK(HIDELEG, hideleg); + + if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_smstateen) ) + INIT_CSR_MASK(HSTATEEN0, hstateen0); +} + static void continue_new_vcpu(struct vcpu *prev) { BUG_ON("unimplemented\n"); diff --git a/xen/arch/riscv/include/asm/setup.h b/xen/arch/riscv/include/as= m/setup.h index c9d69cdf5166..2215894cfbb1 100644 --- a/xen/arch/riscv/include/asm/setup.h +++ b/xen/arch/riscv/include/asm/setup.h @@ -11,6 +11,8 @@ void setup_mm(void); =20 void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len); =20 +void init_csr_masks(void); + #endif /* ASM__RISCV__SETUP_H */ =20 /* diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 9b4835960d20..bca6ca09eddd 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -137,6 +137,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, =20 riscv_fill_hwcap(); =20 + init_csr_masks(); + preinit_xen_time(); =20 intc_preinit(); --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604390; cv=none; d=zohomail.com; s=zohoarc; b=kanZ4XTv84LRj/aTHUujPFXyxXbp93tGytKFB3kbrM+thu7kT+puhATCIXKiFkLUHS7q7J1yipzcfCz5JlbSv7/+EnSnQXoYzaxbHwFj7ItKGXj9oZ7XCGbl7krq/nehheLfgRgKi6LXvzXR7XHMJLKjuMRcUkFfP4F7DYPUGQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604390; 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=eK3XS+ZcSRgZlqnrevGqXpYKxcWdI0GkuIch/PQdcy0=; b=awDbpjr3KG43Zc9J375uQNf5FoWqP0AfB8pNBKX5rLVIpGZZYDt+iRzSJM0YV8HMgxrOmPCxUKOvLK8usXaM43Zy76YlJv62v3EJ3GWzNVi2R0/WruL5iDT6QW7/lRntAZ3FuPQzcWP6N+FWNJ2rpIUqtJKHukNTQQdCn0FCAEE= 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 1771604390834731.7450084911455; Fri, 20 Feb 2026 08:19:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237334.1539693 (Exim 4.92) (envelope-from ) id 1vtTDw-0000bH-DI; Fri, 20 Feb 2026 16:19:24 +0000 Received: by outflank-mailman (output) from mailman id 1237334.1539693; Fri, 20 Feb 2026 16:19:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTDw-0000aV-6w; Fri, 20 Feb 2026 16:19:24 +0000 Received: by outflank-mailman (input) for mailman id 1237334; Fri, 20 Feb 2026 16:19:23 +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 1vtTDv-0000Q4-BO for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:23 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e9a2c0b4-0e77-11f1-9ccf-f158ae23cfc8; Fri, 20 Feb 2026 17:19:21 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-48375f10628so13917745e9.1 for ; Fri, 20 Feb 2026 08:19:21 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:19 -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: e9a2c0b4-0e77-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604360; x=1772209160; 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=eK3XS+ZcSRgZlqnrevGqXpYKxcWdI0GkuIch/PQdcy0=; b=NDgta6+CyvbVK2OUY/uGpTIJKsIfX+SQ6LFsR08RQ1ROYz4kzKCm9cQtYggz1+LUt3 wyf3SW0l9gDlvS2Q5Xr499f8ozS9caJMlFxR3llLkxaUFMAIhcT5RjbOodkq6T0YNNqu pC9XlXa/Zl4OXY+IoqKzneTQH9Uc2ER18AkIw+pEwHVpxA2Za95WVHfYBDo/6aTqam1Q R+vZqrdk4CBRWcVvShT9UAPY8+ISZXJTSK7mof5Wsf+hACrsaHrDftXxoQ2JZWNt0MgW bb/KB/cCliqzDmx1Bj5gY77hLTimSNDXedPVZBWrRVLskAHpoFZ3CS91R/SjryoZi0A2 dEQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604360; x=1772209160; 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=eK3XS+ZcSRgZlqnrevGqXpYKxcWdI0GkuIch/PQdcy0=; b=Kn1cRGLS9By5D7coJfsduro9jVbALWdfw5mozt80nKh/nRvcA21TNGwrMhBQEFTEok Wup5Waml3Qiv5f4bLCT9AHIXWSgzV/gX8ZoQLI9W/WLFeWtiJb9BMALWM2BDTB19tDuA SBKfa5nyBILPWQrghD+r7WP8QN14w93AcjktRnKWtPGDjNoLpXBZpS2I00Ieplz07dPH 0+VNYUwxIsADMmbpr60OEN5OSY1qibJ0FwKq3OGuG0g/Y0pqi2NvOSGmZ8UNwp4Lj24S N9dKQRxAf8xSsk58fHM3F7+rkA8xUexDtwSfEykL30e+YFfYNHYG2pD7mUtjycWiKDxM 7piA== X-Gm-Message-State: AOJu0Yye5ruioPtU0RGqGxo5HFDPSp43McUWfe6x0HjxODAjumZFMyKq 1hDKxJKFYp7bFM0oiCyNYYAl3pfCzFchi5wvl+PplCiktNbDBKJTs3R/AQLJzw== X-Gm-Gg: AZuq6aI4mA+LyZo6lHOE6iDfYxvCBiClDCCsJoxp2XHgbKONuQB/j0zs20khJI6+8Cu MW08ItSrWg6YRI1Js70EZ0RdTe/LV9NHD+SNR5zxzjYft4ItwuK14HCTCpvlFiNEaG/FrfuvATo gDNbTaTikeQZBI6zKhxpXKWOPXYBiq3S2zDhm8KhUMo9kEG0OgecLDazwHUdIeqdeLJOw+kfCe/ jYE8vwEhOT0po7Unxb5iy0pqq6MEmWyRKsRhZJ7+/TMOPXugODahkOxvtAgXp3fezRjxsv33IgS qqf45ooW43PVEF0rGP6WawEhkzeL0HLfLLamnbMmbzE9ZGSiM/hVC6gQMvQZBdFdYuL8wDDVOtV 8yLXKAGyFKxbF1IuJvSLy2JZVRM6fruo2Di3LAX2Z1W18mAZqqxdo+KuZn3HUvLg9UyQbsoJ1Nu 6pD7zaqjx2eN1l6HR6naCrgvrbykyIKyHh0+g3EckaJD+W3aaOiDTwDlkoo5xnm7xQJg== X-Received: by 2002:a05:600c:3e05:b0:477:7f4a:44b4 with SMTP id 5b1f17b1804b1-483a95b3df6mr1673015e9.1.1771604359949; Fri, 20 Feb 2026 08:19:19 -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 02/14] xen/riscv: implement vcpu_csr_init() Date: Fri, 20 Feb 2026 17:18:57 +0100 Message-ID: <3d301ac4ca901f0aa471d6c4234301a0199fe5f7.1771590794.git.oleksii.kurochko@gmail.com> 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: 1771604392853154100 Content-Type: text/plain; charset="utf-8" Introduce vcpu_csr_init() to initialise hypervisor CSRs that control vCPU execution and virtualization behaviour before the vCPU is first scheduled. The function configures trap and interrupt delegation to VS-mode by setting the appropriate bits in the hedeleg and hideleg registers, initializes hstatus so that execution enters VS-mode when control is passed to the guest, and restricts guest access to hardware performance counters by initializing hcounteren, as unrestricted access would require additional handling in Xen. When the Smstateen and SSAIA extensions are available, access to AIA CSRs and IMSIC guest interrupt files is enabled by setting the corresponding bits in hstateen0, avoiding unnecessary traps into Xen (note that SVSLCT(Supervisor Virtual Select) name is used intead of CSRIND as OpenSBI uses such name and riscv_encoding.h is mostly based on it). If the Svpbmt extension is supported, the PBMTE bit is set in henvcfg to allow its use for VS-stage address translation. Guest access to the ENVCFG CSR is also enabled by setting ENVCFG bit in hstateen0, as a guest may need to control certain characteristics of the U-mode (VU-mode when V=3D1) execution environment. For CSRs that may contain read-only bits (e.g. hedeleg, hideleg, hstateen0), to the written value a correspondent mask is applied to avoid divergence between the software state and the actual CSR contents. As hstatus is not part of struct arch_vcpu (it already resides in struct cpu_user_regs), introduce vcpu_guest_cpu_user_regs() to provide a uniform way to access hstatus and other guest CPU user registers. This establishes a consistent and well-defined initial CSR state for vCPUs prior to their first context switch. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v5: - Initialize of hstateen0 with SMSTATEEN0_HSENVCFG when a variable is defined. - Use |=3D for a code inside if (*_ssaia) case. - Put declaration of the registers hedeleg and hideleg together in arch_vc= pu structure as they are typically used together so better chances to be in the same cache line. --- Changes in v4: - Move local variable hstateen0 into narrower scope. - Code style fixes. - Move the call of vcpu_csr_init(v) after if ( is_idle_vcpu() ) check in arcg_vcpu_create(). --- Changes in v3: - Add hypervisor register used to initalize vCPU state. - Apply masks introduced before instead of csr_write()/csr_read() pattern. --- Changes in v2: - As hstatus isn't a part of arch_vcpu structure (as it is already a part = of cpu_user_regs) introduce vcpu_guest_cpu_user_regs() to be able to access hstatus and other CPU user regs. - Sort hideleg bit setting by value. Drop a stray blank. - Drop | when the first initialization of hcounteren and hennvcfg happen. - Introduce HEDELEG_DEFAULT. Sort set bits by value and use BIT() macros instead of open-coding it. - Apply pattern csr_write() -> csr_read() for hedeleg and hideleg instead of direct bit setting in v->arch.h{i,e}deleg as it could be that for some reason some bits of hedeleg and hideleg are r/o. The similar patter is used for hstateen0 as some of the bits could be r/= o. - Add check that SSAIA is avaialable before setting of SMSTATEEN0_AIA | SMSTATEEN0_IMSIC | SMSTATEEN0_SVSLCT bits. - Drop local variables hstatus, hideleg and hedeleg as they aren't used anymore. --- xen/arch/riscv/domain.c | 62 +++++++++++++++++++++ xen/arch/riscv/include/asm/current.h | 2 + xen/arch/riscv/include/asm/domain.h | 6 ++ xen/arch/riscv/include/asm/riscv_encoding.h | 2 + 4 files changed, 72 insertions(+) diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index 8b05f0f23b77..c9494db0fbe7 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -8,6 +8,7 @@ =20 #include #include +#include =20 struct csr_masks { register_t hedeleg; @@ -16,6 +17,21 @@ struct csr_masks { register_t hstateen0; }; =20 +#define HEDELEG_DEFAULT (BIT(CAUSE_MISALIGNED_FETCH, U) | \ + BIT(CAUSE_FETCH_ACCESS, U) | \ + BIT(CAUSE_ILLEGAL_INSTRUCTION, U) | \ + BIT(CAUSE_BREAKPOINT, U) | \ + BIT(CAUSE_MISALIGNED_LOAD, U) | \ + BIT(CAUSE_LOAD_ACCESS, U) | \ + BIT(CAUSE_MISALIGNED_STORE, U) | \ + BIT(CAUSE_STORE_ACCESS, U) | \ + BIT(CAUSE_USER_ECALL, U) | \ + BIT(CAUSE_FETCH_PAGE_FAULT, U) | \ + BIT(CAUSE_LOAD_PAGE_FAULT, U) | \ + BIT(CAUSE_STORE_PAGE_FAULT, U)) + +#define HIDELEG_DEFAULT (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP) + static struct csr_masks __ro_after_init csr_masks; =20 void __init init_csr_masks(void) @@ -35,6 +51,50 @@ void __init init_csr_masks(void) INIT_CSR_MASK(HSTATEEN0, hstateen0); } =20 +static void vcpu_csr_init(struct vcpu *v) +{ + v->arch.hedeleg =3D HEDELEG_DEFAULT & csr_masks.hedeleg; + + vcpu_guest_cpu_user_regs(v)->hstatus =3D HSTATUS_SPV | HSTATUS_SPVP; + + v->arch.hideleg =3D HIDELEG_DEFAULT & csr_masks.hideleg; + + /* + * VS should access only the time counter directly. + * Everything else should trap. + */ + v->arch.hcounteren =3D HCOUNTEREN_TM; + + if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_svpbmt) ) + v->arch.henvcfg =3D ENVCFG_PBMTE & csr_masks.henvcfg; + + if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_smstateen) ) + { + /* Allow guest to access CSR_SENVCFG */ + register_t hstateen0 =3D SMSTATEEN0_HSENVCFG; + + if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_ssaia) ) + /* + * If the hypervisor extension is implemented, the same three + * bits are defined also in hypervisor CSR hstateen0 but conce= rn + * only the state potentially accessible to a virtual machine + * executing in privilege modes VS and VU: + * bit 60 CSRs siselect and sireg (really vsiselect and + * vsireg) + * bit 59 CSRs siph and sieh (RV32 only) and stopi (really + * vsiph, vsieh, and vstopi) + * bit 58 all state of IMSIC guest interrupt files, inclu= ding + * CSR stopei (really vstopei) + * If one of these bits is zero in hstateen0, and the same bit= is + * one in mstateen0, then an attempt to access the correspondi= ng + * state from VS or VU-mode raises a virtual instruction excep= tion. + */ + hstateen0 |=3D SMSTATEEN0_AIA | SMSTATEEN0_IMSIC | SMSTATEEN0_= SVSLCT; + + v->arch.hstateen0 =3D hstateen0 & csr_masks.hstateen0; + } +} + static void continue_new_vcpu(struct vcpu *prev) { BUG_ON("unimplemented\n"); @@ -57,6 +117,8 @@ int arch_vcpu_create(struct vcpu *v) if ( is_idle_vcpu(v) ) return 0; =20 + vcpu_csr_init(v); + /* * As the vtimer and interrupt controller (IC) are not yet implemented, * return an error. diff --git a/xen/arch/riscv/include/asm/current.h b/xen/arch/riscv/include/= asm/current.h index 58c9f1506b7c..5fbee8182caa 100644 --- a/xen/arch/riscv/include/asm/current.h +++ b/xen/arch/riscv/include/asm/current.h @@ -48,6 +48,8 @@ DECLARE_PER_CPU(struct vcpu *, curr_vcpu); #define get_cpu_current(cpu) per_cpu(curr_vcpu, cpu) =20 #define guest_cpu_user_regs() ({ BUG_ON("unimplemented"); NULL; }) +#define vcpu_guest_cpu_user_regs(vcpu) \ + (&(vcpu)->arch.cpu_info->guest_cpu_user_regs) =20 #define switch_stack_and_jump(stack, fn) do { \ asm volatile ( \ diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/a= sm/domain.h index 5aec627a7adb..17be792afe7d 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -49,6 +49,12 @@ struct arch_vcpu { =20 struct cpu_info *cpu_info; =20 + register_t hcounteren; + register_t hedeleg; + register_t hideleg; + register_t henvcfg; + register_t hstateen0; + register_t vsatp; }; =20 diff --git a/xen/arch/riscv/include/asm/riscv_encoding.h b/xen/arch/riscv/i= nclude/asm/riscv_encoding.h index 1f7e612366f8..dd15731a86fa 100644 --- a/xen/arch/riscv/include/asm/riscv_encoding.h +++ b/xen/arch/riscv/include/asm/riscv_encoding.h @@ -228,6 +228,8 @@ #define ENVCFG_CBIE_INV _UL(0x3) #define ENVCFG_FIOM _UL(0x1) =20 +#define HCOUNTEREN_TM BIT(1, U) + /* =3D=3D=3D=3D=3D User-level CSRs =3D=3D=3D=3D=3D */ =20 /* User Trap Setup (N-extension) */ --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604394; cv=none; d=zohomail.com; s=zohoarc; b=jREnmPMhDpFIprzZXxAjb/4NoG7B04vmbFSa2hmZ2Bm3vDX1uZI129qQGiJZs1zuo0uEqaNQFvDJsPLqpWhk+A7Rf9km1fqN24JX/ojQJrPDR6XzjJRyZBGq+OpTH/EjcSefAud70GL9ovvqzN9b06mWJAUn6xhZuEJhGWICSe4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604394; h=Content-Type: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=wQxS5vKkI4AgCcQGHJP5Zmtdr2xZpVQrWww/XfYYZbE=; b=eYB0t2/B0MM0okxZHGnSIZ+NNdAEisy+/+wJUAuYZYNbkpK4+2DFx4Jf5P4CHbqmIg84iZHi82vDmbpssaH6Anfe843CXlpDFq+VcQ0gtveUYNnARqQuU1TmMzqfQNn2vSQg/WhZONbUgY0ACD9N9R9/4Dep1RGhxknt/c+3v/Y= 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 1771604394125377.4026246522925; Fri, 20 Feb 2026 08:19:54 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237335.1539710 (Exim 4.92) (envelope-from ) id 1vtTDx-000145-K3; Fri, 20 Feb 2026 16:19:25 +0000 Received: by outflank-mailman (output) from mailman id 1237335.1539710; Fri, 20 Feb 2026 16:19:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTDx-00013H-ET; Fri, 20 Feb 2026 16:19:25 +0000 Received: by outflank-mailman (input) for mailman id 1237335; Fri, 20 Feb 2026 16:19:23 +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 1vtTDv-0000QF-Gh for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:23 +0000 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [2a00:1450:4864:20::435]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ea46f877-0e77-11f1-b164-2bf370ae4941; Fri, 20 Feb 2026 17:19:22 +0100 (CET) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-436234ef0f0so1524683f8f.1 for ; Fri, 20 Feb 2026 08:19:22 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:20 -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: ea46f877-0e77-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604361; x=1772209161; 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=wQxS5vKkI4AgCcQGHJP5Zmtdr2xZpVQrWww/XfYYZbE=; b=KUaHzIJwqWeNJK8m3t7a45AB7J41Bg5L91JEkQrRYDN3GLtfgv+j7Se4Tq8NbaDWGJ NxywdHRwXmwjE8OvTCENGXSgfIlxcoLLOFcXHvCsDDHVW9a07SOnCZ6q6NpaX5Ac3iq/ pclZsrJ9aIu95lbwUWtpTUF3I7zjRs824hUVxz2z6zDI2g2yqlK3FJb2apJQeoswtyTc SIchrff04PMMysxIew/RKSDAfYmMUMYbtsYa6Tz+zwAYOXg63lHICyP6qdXbullleCSm QpZE7PmrglLdfT5NX7YcbMPkvPIFvOhONiayadqVyUWRwkKqJDXP3bNBlgHrzjWqkx8l k6zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604361; x=1772209161; 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=wQxS5vKkI4AgCcQGHJP5Zmtdr2xZpVQrWww/XfYYZbE=; b=rVpcYHrBdKBdtToznXK1dYfmQsI36jxAwuFg2FxsMad2VlcL84ZvVQn8KpPRYuBxmg 0UsiWQo96G/qOYXmCKzBbAZ7wCegMVD3xFWOPqEEysF+f4uY/bdwyhDZCQoz1XD4T56W a1mBpzX9XAagoaK/rdespNIKEp/vXthIs9Cx6cxpFmj4VB0/R+waD6G7pQi2H5Akuw2F awFDj1Q9Cdg/3hdLXzEHEcO4vtL5NOMQDBshjt1fQV+i7RFNWPGNaJUOSeHhIqfH9Fdc +Eh3qX7hH+7gvoC5FNZZPeOgtIRTupLLasXw/xunMYAGBrETwdmbQoyQhWrH3feKF/8c Qbew== X-Gm-Message-State: AOJu0YwXXE4TuqBx7v/8EV5Vb+W3+PlD5IYolD/71p9+ggvOuRNKXi7/ ZkBQ6VqzNOqwYd/OVyQhvdI2MDuk9OwwLJb/KFdt1LofCsLS/OT/xT3/jYZofw== X-Gm-Gg: AZuq6aJd7NiPmIs+g9W0zZp25sj0RlDFVXBpZh4NHQkr1EZiW5dUmTPudK14fjg+WyT w+BpxfxC2WZK6pcvmTdHVBLGXRfnA9kIPVUQVqiIf0IoW2nrkEY5TLgxmuEirunObfEcbmF0Akd pZ8/SwkSEpy+lzuzpLk4kTw1QqH4CLf1gLafthcS4hK8IzHaZnDdZYG8BbnO+N7vF7oJKAiJ19f wDgmoZTlz/o7x+y78R8EFbGvIFc1PPzwj86BFmiQgbMcO7AXFLicJ1aS0Uq5EVLqbh9C16qAC90 maP166FoxoSv3/evIZWIQ5VYdcrtyg/Dk5D7levlhD/GOMfFciZbjYFH+sGpwYZiQdU2Q3thowg /2h1OoK3e8IyQk3xlTMvOefr5Em12aMlLD387Kgoke51ez8jh58PfUmpfPB4o6y4V7ZDDO0N3oA 2rVO1KSn1Vka3r5Jt0vjvnRcs4uiIZ0XGm/FXiOq6gQmxs1/A7W6qDiKXM27HPnpH1lk1wBJCBm B40jrqO X-Received: by 2002:a05:6000:1aca:b0:436:3707:2be5 with SMTP id ffacd0b85a97d-4396f166a38mr820160f8f.15.1771604361146; Fri, 20 Feb 2026 08:19:21 -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 03/14] xen/riscv: introduce tracking of pending vCPU interrupts, part 1 Date: Fri, 20 Feb 2026 17:18:58 +0100 Message-ID: <8c2259991754f219ba030606f39d629eb365b01c.1771590794.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1771604396823154100 Based on Linux kernel v6.16.0. Note that smp_wmb() is used instead of smp_mb__before_atomic() as what we want to guarantee that if a bit in irqs_pending_mask is obversable that the correspondent bit in irqs_pending is observable too. Add lockless tracking of pending vCPU interrupts using atomic bitops. Two bitmaps are introduced: - irqs_pending =E2=80=94 interrupts currently pending for the vCPU - irqs_pending_mask =E2=80=94 bits that have changed in irqs_pending The design follows a multi-producer, single-consumer model, where the consumer is the vCPU itself. Producers may set bits in irqs_pending_mask without a lock. Clearing bits in irqs_pending_mask is performed only by the consumer via xchg(). The consumer must not write to irqs_pending and must not act on bits that are not set in the mask. Otherwise, extra synchronization should be provided. On RISC-V interrupts are not injected via guest registers, so pending interrupts must be recorded in irqs_pending (using the new vcpu_{un}set_interrupt() helpers) and flushed to the guest by updating HVIP before returning control to the guest. The consumer side is implemented in a follow-up patch. A barrier between updating irqs_pending and setting the corresponding mask bit in vcpu_set_interrupt()/vcpu_unset_interrupt() guarantees that if the consumer observes a mask bit set, the corresponding pending bit is also visible. This prevents missed interrupts during the flush. It is possible that a guest could have pending bit in the hardware register without being marked pending in irq_pending bitmap as: According to the RISC-V ISA specification: Bits hip.VSSIP and hie.VSSIE are the interrupt-pending and interrupt-enable bits for VS-level software interrupts. VSSIP in hip is an alias (writable) of the same bit in hvip. Additionally: When bit 2 of hideleg is zero, vsip.SSIP and vsie.SSIE are read-only zeros. Else, vsip.SSIP and vsie.SSIE are aliases of hip.VSSIP and hie.VSSIE. This means the guest may modify vsip.SSIP, which implicitly updates hip.VSSIP and the bit being written with 1 would also trigger an interrupt as according to the RISC-V spec: These conditions for an interrupt trap to occur must be evaluated in a bounded amount of time from when an interrupt becomes, or ceases to be, pending in sip, and must also be evaluated immediately following the execution of an SRET instruction or an explicit write to a CSR on which these interrupt trap conditions expressly depend (including sip, sie and sstatus). What means that IRQ_VS_SOFT must be synchronized separately, what is done in vcpu_sync_interrupts(). Note, also, that IRQ_PMU_OVF would want to be synced for the similar reason as IRQ_VS_SOFT, but isn't sync-ed now as PMU isn't supported now. For the remaining VS-level interrupt types (IRQ_VS_TIMER and IRQ_VS_EXT), the specification states they cannot be modified by the guest and are read-only because of: Bits hip.VSEIP and hie.VSEIE are the interrupt-pending and interrupt-enab= le bits for VS-level external interrupts. VSEIP is read-only in hip, and is the logical-OR of these interrupt sources: =E2=80=A2 bit VSEIP of hvip; =E2=80=A2 the bit of hgeip selected by hstatus.VGEIN; and =E2=80=A2 any other platform-specific external interrupt signal directe= d to VS-level. Bits hip.VSTIP and hie.VSTIE are the interrupt-pending and interrupt-enab= le bits for VS-level timer interrupts. VSTIP is read-only in hip, and is the logical-OR of hvip.VSTIP and any other platform-specific timer interrupt signal directed to VS-level. and When bit 10 of hideleg is zero, vsip.SEIP and vsie.SEIE are read-only zer= os. Else, vsip.SEIP and vsie.SEIE are aliases of hip.VSEIP and hie.VSEIE. When bit 6 of hideleg is zero, vsip.STIP and vsie.STIE are read-only zero= s. Else, vsip.STIP and vsie.STIE are aliases of hip.VSTIP and hie.VSTIE. and also, Bits sip.SEIP and sie.SEIE are the interrupt-pending and interrupt-enable bits for supervisor-level external interrupts. If implemented, SEIP is read-only in sip, and is set and cleared by the execution environment, typically through a platform-specific interrupt controller. Bits sip.STIP and sie.STIE are the interrupt-pending and interrupt-enable bits for supervisor-level timer interrupts. If implemented, STIP is read-only in sip, and is set and cleared by the execution environment Thus, for these interrupt types, it is sufficient to use vcpu_set_interrupt= () and vcpu_unset_interrupt(), and flush them during the call of vcpu_flush_interrupts() (which is introduced in follow up patch). vcpu_sync_interrupts(), which is called just before entering the VM, slightly bends the rule that the irqs_pending bit must be written first, followed by updating the corresponding bit in irqs_pending_mask. However, it still respects the core guarantee that the producer never clears the mask and only writes to irqs_pending if it is the one that flipped the corresponding mask bit from 0 to 1. Moreover, since the consumer won't run concurrently because vcpu_sync_interrupts() and the consumer path are going to be invoked sequentially immediately before VM entry, it is safe to slightly relax this ordering rule in vcpu_sync_interrupts(). Signed-off-by: Oleksii Kurochko --- Changes in v5: - Update the commit message(). - Rename c to curr. - Update vcpu_set_interrupt() to use test_and_set_bit() for irqs_pending bitmask too. - Move #ifdef CONFIG_RISCV_32 above the comment in vcpu_sync_interrupts(). --- Changes in v4: - Update the commit message. - Update the comments in vcpu_(un)set_interrupt() and add the the comment above smp_wmb() barrier. - call vcpu_kick() only if the pending_mask bit going from 0 to 1. - Code style fixes. - Update defintion of RISCV_VCPU_NR_IRQS to cover potential RV128 case and the case if AIA isn't used. - latch current into a local variable in check_for_pcpu_work(). --- Changes in v3: - Use smp_wb() instead of smp_mb__before_atomic(). - Add explanation of the change above in the commit message. - Move vcpu_sync_interrupts() here to producers side. - Introduce check_for_pcpu_work() to be clear from where vcpu_sync_interru= pts() is called. --- Changes in V2: - Move the patch before an introduction of vtimer. - Drop bitmap_zero() of irqs_pending and irqs_pending_mask bitmaps as vcpu structure starts out all zeros. - Drop const for irq argument of vcpu_{un}set_interrupt(). - Drop check "irq < IRQ_LOCAL_MAX" in vcpu_{un}set_interrupt() as it could lead to overrun of irqs_pending and irqs_pending_mask bitmaps. - Drop IRQ_LOCAL_MAX as there is no usage for it now. --- xen/arch/riscv/domain.c | 75 +++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/domain.h | 23 +++++++++ xen/arch/riscv/traps.c | 4 ++ 3 files changed, 102 insertions(+) diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index c9494db0fbe7..335c41f3e5a1 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -6,6 +6,7 @@ #include #include =20 +#include #include #include #include @@ -140,6 +141,80 @@ void arch_vcpu_destroy(struct vcpu *v) vfree((void *)&v->arch.cpu_info[1] - STACK_SIZE); } =20 +int vcpu_set_interrupt(struct vcpu *v, unsigned int irq) +{ + bool kick_vcpu; + + /* We only allow VS-mode software, timer, and external interrupts */ + if ( irq !=3D IRQ_VS_SOFT && + irq !=3D IRQ_VS_TIMER && + irq !=3D IRQ_VS_EXT ) + return -EINVAL; + + kick_vcpu =3D !test_and_set_bit(irq, v->arch.irqs_pending); + + /* + * The counterpart of this barrier is the one encoded implicitly in xc= hg() + * which is used in consumer part (vcpu_flush_interrupts()). + */ + smp_wmb(); + + kick_vcpu |=3D !test_and_set_bit(irq, v->arch.irqs_pending_mask); + + if ( kick_vcpu ) + vcpu_kick(v); + + return 0; +} + +int vcpu_unset_interrupt(struct vcpu *v, unsigned int irq) +{ + /* We only allow VS-mode software, timer, external interrupts */ + if ( irq !=3D IRQ_VS_SOFT && + irq !=3D IRQ_VS_TIMER && + irq !=3D IRQ_VS_EXT ) + return -EINVAL; + + clear_bit(irq, v->arch.irqs_pending); + /* + * The counterpart of this barrier is the one encoded implicitly in xc= hg() + * which is used in consumer part (vcpu_flush_interrupts()). + */ + smp_wmb(); + set_bit(irq, v->arch.irqs_pending_mask); + + return 0; +} + +void vcpu_sync_interrupts(struct vcpu *v) +{ + unsigned long hvip; + + /* Read current HVIP and VSIE CSRs */ + v->arch.vsie =3D csr_read(CSR_VSIE); + + /* Sync-up HVIP.VSSIP bit changes done by Guest */ + hvip =3D csr_read(CSR_HVIP); + if ( ((v->arch.hvip ^ hvip) & BIT(IRQ_VS_SOFT, UL)) && + !test_and_set_bit(IRQ_VS_SOFT, &v->arch.irqs_pending_mask) ) + { + if ( hvip & BIT(IRQ_VS_SOFT, UL) ) + set_bit(IRQ_VS_SOFT, &v->arch.irqs_pending); + else + clear_bit(IRQ_VS_SOFT, &v->arch.irqs_pending); + } + +#ifdef CONFIG_RISCV_32 + /* + * Sync-up AIA high interrupts. + * + * It is necessary to do only for CONFIG_RISCV_32 which isn't supported + * now. + */ +# error "Update v->arch.vsieh" +#endif +} + static void __init __maybe_unused build_assertions(void) { /* diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/a= sm/domain.h index 17be792afe7d..b7241f2a79b1 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -54,8 +54,26 @@ struct arch_vcpu { register_t hideleg; register_t henvcfg; register_t hstateen0; + register_t hvip; =20 register_t vsatp; + register_t vsie; + + /* + * VCPU interrupts + * + * We have a lockless approach for tracking pending VCPU interrupts + * implemented using atomic bitops. The irqs_pending bitmap represent + * pending interrupts whereas irqs_pending_mask represent bits changed + * in irqs_pending. Our approach is modeled around multiple producer + * and single consumer problem where the consumer is the VCPU itself. + * + * DECLARE_BITMAP() is needed here to support 64 vCPU local interrupts + * on RV32 host. + */ +#define RISCV_VCPU_NR_IRQS MAX(BITS_PER_LONG, 64) + DECLARE_BITMAP(irqs_pending, RISCV_VCPU_NR_IRQS); + DECLARE_BITMAP(irqs_pending_mask, RISCV_VCPU_NR_IRQS); }; =20 struct paging_domain { @@ -94,6 +112,11 @@ static inline void update_guest_memory_policy(struct vc= pu *v, =20 static inline void arch_vcpu_block(struct vcpu *v) {} =20 +int vcpu_set_interrupt(struct vcpu *v, unsigned int irq); +int vcpu_unset_interrupt(struct vcpu *v, unsigned int irq); + +void vcpu_sync_interrupts(struct vcpu *v); + #endif /* ASM__RISCV__DOMAIN_H */ =20 /* diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index 9fca941526f6..551f886e3a69 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -171,6 +171,10 @@ static void do_unexpected_trap(const struct cpu_user_r= egs *regs) =20 static void check_for_pcpu_work(void) { + struct vcpu *curr =3D current; + + vcpu_sync_interrupts(curr); + p2m_handle_vmenter(); } =20 --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604391; cv=none; d=zohomail.com; s=zohoarc; b=e1oOsTypOm4lOY3FLWH++kMhnZZLlFkxP3jb5qRVWHODDJPeyMVKXVj9w60KvCoUhZJJa544jT9tJoLELmfmXuWnHQbURjC7cwg9zuy6UPgcuMuPAW+HvjaNH38LcqDv8JOcX0t6cQWkWq2Qf6M7HS2TIwRF//1qpJT9h/fAE9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604391; 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=9kLRmTM6oplx9Q9iY0GyvVxh5tBWM0eKNh9+e6RhQFU=; b=DspxUBbG50pRqywF/MCxra+Hks8dt/G6u2V9qQ2zR6LDo3xuyeg3PkyuhPeVTCzEPJIgIi/Kvi6oHcP7hVrHHRPvEW36s6UT1em5BQ0WpGCXwgEFV1genf0nk2Kr5PERe1pDmPH0Lhl49he1VVSwgDceH1E1BHXzetDG0R8HIE8= 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 1771604391190218.29582286755294; Fri, 20 Feb 2026 08:19:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237336.1539719 (Exim 4.92) (envelope-from ) id 1vtTDy-0001K0-PE; Fri, 20 Feb 2026 16:19:26 +0000 Received: by outflank-mailman (output) from mailman id 1237336.1539719; Fri, 20 Feb 2026 16:19:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTDy-0001Jq-Lb; Fri, 20 Feb 2026 16:19:26 +0000 Received: by outflank-mailman (input) for mailman id 1237336; Fri, 20 Feb 2026 16:19:24 +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 1vtTDw-0000Q4-SQ for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:24 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id eaea89bd-0e77-11f1-9ccf-f158ae23cfc8; Fri, 20 Feb 2026 17:19:23 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-48370174e18so13579565e9.2 for ; Fri, 20 Feb 2026 08:19:23 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:21 -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: eaea89bd-0e77-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604362; x=1772209162; 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=9kLRmTM6oplx9Q9iY0GyvVxh5tBWM0eKNh9+e6RhQFU=; b=X9lulydD7EabLKOHfTb70CevckIMbgjL3X4pAEZGc0M8MfBXpTCnN7o78WHSE7NqrE vEyPtIEc4FdxZjYLVj+rHe3EIMz5+WC7km0qaifH10AvAM6IAVhzzdQaQmgshzscylom mrHJkIly/w+xf4mvVynt0ASm0+ICE6JHWEX0m71pkRGU9rie6wypobKPFqeHTyTAjvHa Yka8MHlW/7TuopLY5eV26rJ5jbDUvOfYsMvSNxyZ+ZwKFc0B7veAtEGOmLUDvd+bVhvf 7lL8jec44eRqlPkL1Uas3wrHd6GlThncXANA/qfj1V1YqebFZkTySZ1rzerHiwEAogPr VMKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604362; x=1772209162; 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=9kLRmTM6oplx9Q9iY0GyvVxh5tBWM0eKNh9+e6RhQFU=; b=LgYZX7hXYdz3UjvhJo8xW/K5kQaSpwLBWzw6/sPcKgz1sXN+igi3fkajRX1WwJPgMZ qK6ZaTeIvYcFmVm+7Vbzlur28RDGJ0SwaJsdlI+pZfwpRnwP4P0No9lTEqP/3gkgu5Ku OeWBjuVz8DblozgX9b00xVtcvdy62FYHWM59pqQgDy7IJaWwWFcsM1eCebiIcWSjLAL6 0dDBF/sx8MqY0X2KmXM4mExFT0W5EPYuPmoBmom6eUlpgR7paiCeHO4+M5AcUmOR5600 LCEnAfxeynLq/2ydiRcZQrhdXe6ZpCBi5TTYD52sIvQnUihYtRI/fWGoN5+d52V9giiO Rd+g== X-Gm-Message-State: AOJu0YzfI4iJQzO8RmAXWDyWFinjRNJ9wnsot0HAE3FdrwVbuOqrz3sY ZpEB7+BVu46G2GsCMfPM8aR/KjM4BoTwCdAf4TKKIb8VnaEERfW4jQAubjIKgQ== X-Gm-Gg: AZuq6aIoU+Ok082Nwo5s0qtcTMugg1BdiTJyuAxv2lhVw8adXGY6D3lIlwAjxYwxEdq R7DHp+rhujVed2qscszZfdFT0Zry+zoqIsyvS0C8l9fMSzcN/NPGAAEY1HEZPHKF+OhgjhlW2R8 BzlhLlpWBKES9FyokUEVAAQgPoZeQRov3JPqwuvPfoCBmi3TGp52d2fADMShAfGyZN5G3uCZiiI ZMdynb6tTWZvW+c0pLTS3jrKVjN7EY0pkNKlcT7hB2TqWRFVcCUWjQ/fm9lmovxAGkr4Crm/UfM KcJDhXeNtfr3IEGXMWS1Dv222iJKxdblNcdzTTuViBGr1D+UHNZmrNjcaj8frdgvIIsa9AJ5DWZ KFI/6hOlD+Gu5XGYikrgGboO8roSFRm5/+9zbzYu8PzqXy/iEzheUoYZsvjM1glxxlXiq1IonSj xvIxfnCPxIlsCUpLbJDEw/JjtX8AgJCA3UNj24Jc9F7/KxMppiRlzDeWeS3qALdBc9BA== X-Received: by 2002:a05:600c:6296:b0:47a:81b7:9a20 with SMTP id 5b1f17b1804b1-483a95c6774mr1480155e9.9.1771604362296; Fri, 20 Feb 2026 08:19:22 -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 04/14] xen/riscv: introduce tracking of pending vCPU interrupts, part 2 Date: Fri, 20 Feb 2026 17:18:59 +0100 Message-ID: <0d8d0f2240806a4bfaee4c5f395d6220ded00c18.1771590794.git.oleksii.kurochko@gmail.com> 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: 1771604392809154100 Content-Type: text/plain; charset="utf-8" This patch is based on Linux kernel 6.16.0. Add the consumer side (vcpu_flush_interrupts()) of the lockless pending interrupt tracking introduced in part 1 (for producers). According, to the design only one consumer is possible, and it is vCPU itself. vcpu_flush_interrupts() is expected to be ran (as guests aren't ran now due to the lack of functionality) before the hypervisor returns control to the guest. Producers may set bits in irqs_pending_mask without a lock. Clearing bits in irqs_pending_mask is performed only by the consumer via xchg() (with aquire semantics). The consumer must not write to irqs_pending and must not act on bits that are not set in the mask. Otherwise, extra synchronization should be provided. The worst thing which could happen with such approach is that a new pending bit will be set to irqs_pending bitmap during update of hvip variable in vcpu_flush_interrupt() but it isn't problem as the new pending bit won't be lost and just be proceded during the next flush. As AIA specs introduced hviph register which would want to be updated when guest related AIA code vcpu_update_hvip() is introduced instead of just open-code it in vcpu_flush_interrupts(). Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v5: - Reorder the defintions of local variables (mask, val, hvip) in vcpu_flush_interrupts(). Also, drop a blank line between them. - Move #ifdef CONFIG_RISCV_32 above the comment in vcpu_flush_interrupts() and align the comment properly. - Add Acked-by: Jan Beulich . --- Changes in v4: - Move defintion of hvip local variable to narrower space in vcpu_flush_interrupts(). - Use initializers for mask and val variables. - Use local variable c as an argument of vcpu_flush_interrupts() in check_for_pcpu_work(). --- Changes in v3: - Update the error message in case of RV32 from "hviph" to v->arch.hviph. - Make const argument of vcpu_update_hvip. - Move local variables mask and val inside if() in vcpu_flush_interrupts(). - Call vcpu_flush_interrupts() in check_pcpu_work(). - Move vcpu_update_hvip() inside if() in vcpu_flush_interrupts(). --- Changes in v2: - New patch. --- xen/arch/riscv/domain.c | 30 +++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/domain.h | 1 + xen/arch/riscv/traps.c | 2 ++ 3 files changed, 33 insertions(+) diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index 335c41f3e5a1..636349c8c7e8 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -215,6 +215,36 @@ void vcpu_sync_interrupts(struct vcpu *v) #endif } =20 +static void vcpu_update_hvip(const struct vcpu *v) +{ + csr_write(CSR_HVIP, v->arch.hvip); +} + +void vcpu_flush_interrupts(struct vcpu *v) +{ + if ( ACCESS_ONCE(v->arch.irqs_pending_mask[0]) ) + { + unsigned long mask =3D xchg(&v->arch.irqs_pending_mask[0], 0UL); + unsigned long val =3D ACCESS_ONCE(v->arch.irqs_pending[0]) & mask; + register_t *hvip =3D &v->arch.hvip; + + *hvip &=3D ~mask; + *hvip |=3D val; + + vcpu_update_hvip(v); + } + +#ifdef CONFIG_RISCV_32 + /* + * Flush AIA high interrupts. + * + * It is necessary to do only for CONFIG_RISCV_32 which isn't + * supported now. + */ +# error "Update v->arch.hviph" +#endif +} + static void __init __maybe_unused build_assertions(void) { /* diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/a= sm/domain.h index b7241f2a79b1..2a454bfc083c 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -116,6 +116,7 @@ int vcpu_set_interrupt(struct vcpu *v, unsigned int irq= ); int vcpu_unset_interrupt(struct vcpu *v, unsigned int irq); =20 void vcpu_sync_interrupts(struct vcpu *v); +void vcpu_flush_interrupts(struct vcpu *v); =20 #endif /* ASM__RISCV__DOMAIN_H */ =20 diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index 551f886e3a69..244264c92a79 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -175,6 +175,8 @@ static void check_for_pcpu_work(void) =20 vcpu_sync_interrupts(curr); =20 + vcpu_flush_interrupts(curr); + p2m_handle_vmenter(); } =20 --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604382; cv=none; d=zohomail.com; s=zohoarc; b=aaW59lgqmiUG2AN31grt3sz5oLoAVs1/Eolcrx46rGNFMeVpI8liAhNRdzEjhKCoKph91EC9DK2JLkYYmVvIhqTnYQq3TW/eJUMTwFir4Jh+jI4Sa/RLmIXhYiPQIBjHgHI2keXAvuptmk6RYtp5DuViOgmDhJqHBDXgG3JlgQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604382; 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=h8rDhEwL+Si1TVzLRrIFs43T5seQJmCokC0zj36jVKw=; b=KrmARh+0t2yCs21eJyYEvdpMf6VZn4rc2SMlIbrK5BcPddw0XBAAFi9M+CFgqc0U5Yy8sqFcxNsfzyUlWXqbydBJbZVQBApQbJaGq6RZGwo6W4vI4E2Lp/0DpHmtW+bL4e3fw+SUrK0qolq7RB+G1Ei1xXiAB12ksX5jSKyDjjo= 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 1771604382902904.82930746593; Fri, 20 Feb 2026 08:19:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237337.1539724 (Exim 4.92) (envelope-from ) id 1vtTDz-0001My-3K; Fri, 20 Feb 2026 16:19:27 +0000 Received: by outflank-mailman (output) from mailman id 1237337.1539724; Fri, 20 Feb 2026 16:19:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTDy-0001M4-SW; Fri, 20 Feb 2026 16:19:26 +0000 Received: by outflank-mailman (input) for mailman id 1237337; Fri, 20 Feb 2026 16:19:25 +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 1vtTDx-0000QF-C1 for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:25 +0000 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [2a00:1450:4864:20::42c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id eb99eeb8-0e77-11f1-b164-2bf370ae4941; Fri, 20 Feb 2026 17:19:24 +0100 (CET) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-43626796202so2065397f8f.3 for ; Fri, 20 Feb 2026 08:19:24 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:23 -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: eb99eeb8-0e77-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604363; x=1772209163; 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=h8rDhEwL+Si1TVzLRrIFs43T5seQJmCokC0zj36jVKw=; b=Mltsu189idcgA+MU02SEnGj3vyjtiWKRvclUcij6eoSzIwMucd0oORU1UHNGSjCFnV V6x/O0eNZ59jw4GOIz3Es3tXsJejF+78WzwGZ7qaSw468uVeFeYrEerCaLtWsAy127pA B1WGFGQECanCs01n5luu+HpbHzpKHwAyi079P6BzWH9GDpPMY8r3AdNoAsdWpNTBEYaF ppaje8orhrOvgGWl+ZCbL38g/8OJzzPMHGsFJvORjfWYiP3NNa3l+cOJxCdO4OzkI7DK qMz8Mjh8OAUubUObV2rVmrtYcF9vCyxTUy38c930o5zLCbRGYxpg+Ti0B0dohyey3MnT z9Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604363; x=1772209163; 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=h8rDhEwL+Si1TVzLRrIFs43T5seQJmCokC0zj36jVKw=; b=b7fcRwNRR+pxGhaVqPlax3e+rzavO9yD4oq970JrwTnnhzHo0YuNJVklxy8RvYt68t yS3UepytCWF8uyVnz9Qrg1mi7XJl5NuuyZBzm0gj7Piv0RzuFO/rSLhCMlXUEiH8TSeN rqLZK0Jp0RulrwAzONA62A3CE92VzFO5hUO+1rmDeu2QMTCYlXHCvmOpHbFWTy0Lus5B DkAfl0gmmkactOx8p9oAGn5oLJFBG034LjA8iXG4jPSBq7ndewAB2P4v2VWNaNoGFzgy /5ipYKIpqc0k6lx4L0tK613TC93UPSOuNX0EM+q0MkYHmljmmHQdoctjyDv4MSCaGKA4 Bd9Q== X-Gm-Message-State: AOJu0YwigyabrzhwfbLnOdwSSQ4i0xcXmGZbWqPyNB5Enw9ejkovXUOs 2UmTA/aIu7ZBahRcvKplUQY44YzWag7bN5uQdbzKUULpeP2E6g3Rzi6XcMf96w== X-Gm-Gg: AZuq6aLUefhGKddeaHsjadW6KuJYdrfasjaIywX6HH79VfIghI50T1E+KE4ibNCS3Ch a1MA9aN1FCZ6bkYw6BToGwk2CnA8wRWJI1WbYgPHf++ytM6tq26gHd2BEF93el1ReEVnBMx6v+s xDI+irNvMksIA/ua0tOt3DenK88HuovPzbpTKMIjwhjS/j4Emx/bCL4+mnO1sAJnIVXvdWHFwZ3 1f3kd1zidyg/atoT/eHgIuVLjZRrHkIeXP2ZnmwbiLlk6Atzw63zu11zIK0VDGXUyaXJ94Wks/v QxzNWrAlGl5+q4dJ7RuJD/Tyi46ARS0AA84/Rn6JOzzo7CSJ2rd+UyDDKti6ZaBkLAHMJqfd/zm GCrejBBRlGf0euoZ14GSEI1hoL4h8NC41QcBUAwSrKj4pM94uDFB+S0axNJzupjufJkSDPp6oY6 Vz03z7YlZ5OKLOgTttLmkSuEDkEumDsElrHtn/UXEc91wjk1OKkulPj3rNf8eP4y3hwGninw== X-Received: by 2002:a05:6000:40dc:b0:437:7268:8e1e with SMTP id ffacd0b85a97d-4396f181294mr829953f8f.51.1771604363451; Fri, 20 Feb 2026 08:19:23 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Oleksii Kurochko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Alistair Francis , Connor Davis Subject: [PATCH v5 05/14] xen/time: move ticks<->ns helpers to common code Date: Fri, 20 Feb 2026 17:19:00 +0100 Message-ID: <83299215f631fced495d25d0b11ea5449cf9d6d1.1771590794.git.oleksii.kurochko@gmail.com> 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: 1771604385005154100 Content-Type: text/plain; charset="utf-8" ticks_to_ns() and ns_to_ticks() are not architecture-specific, so provide a common implementation that is more resilient to overflow than the historical Arm version. This is not a practical issue for Arm, as the latest ARM ARM that timer frequency should be fixed at 1 GHz and older platforms used much lower rates, which is shy of 32-bit overflow. As the helpers are declared as static inline, they should not affect x86, which does not use them. On Arm, these helpers were historically implemented as out-of-line functions because the counter frequency was originally defined as static and unavaila= ble to headers [1]. Later changes [2] removed this restriction, but the helpers remained unchanged. Now they can be implemented as static inline without any issues. Centralising the helpers avoids duplication and removes subtle differences between architectures while keeping the implementation simple. Drop redundant includes where already pulls it in. No functional change is intended. [1] ddee56dc2994 arm: driver for the generic timer for ARMv7 [2] 096578b4e489 xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code Suggested-by: Jan Beulich Signed-off-by: Oleksii Kurochko Reviewed-by: Jan Beulich --- Changes in v4-v5: - Nothing changed. Only rebase. --- Changes in v3: - Add Reviewed-by: Jan Beulich . --- Changes in v2: - Move ns_to_ticks() and ticks_to_ns() to common code. --- xen/arch/arm/include/asm/time.h | 3 --- xen/arch/arm/time.c | 11 ----------- xen/arch/arm/vtimer.c | 2 +- xen/arch/riscv/include/asm/time.h | 5 ----- xen/arch/riscv/time.c | 1 + xen/include/xen/time.h | 11 +++++++++++ 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/include/asm/time.h b/xen/arch/arm/include/asm/tim= e.h index 49ad8c1a6d47..c194dbb9f52d 100644 --- a/xen/arch/arm/include/asm/time.h +++ b/xen/arch/arm/include/asm/time.h @@ -101,9 +101,6 @@ extern void init_timer_interrupt(void); /* Counter value at boot time */ extern uint64_t boot_count; =20 -extern s_time_t ticks_to_ns(uint64_t ticks); -extern uint64_t ns_to_ticks(s_time_t ns); - void preinit_xen_time(void); =20 void force_update_vcpu_system_time(struct vcpu *v); diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c index cc3fcf47b66a..a12912a106a0 100644 --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -27,7 +27,6 @@ #include #include #include -#include #include =20 uint64_t __read_mostly boot_count; @@ -47,16 +46,6 @@ unsigned int timer_get_irq(enum timer_ppi ppi) return timer_irq[ppi]; } =20 -/*static inline*/ s_time_t ticks_to_ns(uint64_t ticks) -{ - return muldiv64(ticks, SECONDS(1), 1000 * cpu_khz); -} - -/*static inline*/ uint64_t ns_to_ticks(s_time_t ns) -{ - return muldiv64(ns, 1000 * cpu_khz, SECONDS(1)); -} - static __initdata struct dt_device_node *timer; =20 #ifdef CONFIG_ACPI diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c index d2124b175521..2e85ff2b6e62 100644 --- a/xen/arch/arm/vtimer.c +++ b/xen/arch/arm/vtimer.c @@ -12,13 +12,13 @@ #include #include #include +#include #include =20 #include #include #include #include -#include #include #include #include diff --git a/xen/arch/riscv/include/asm/time.h b/xen/arch/riscv/include/asm= /time.h index 1e7801e2ea0e..be3875b9984e 100644 --- a/xen/arch/riscv/include/asm/time.h +++ b/xen/arch/riscv/include/asm/time.h @@ -24,11 +24,6 @@ static inline cycles_t get_cycles(void) return csr_read(CSR_TIME); } =20 -static inline s_time_t ticks_to_ns(uint64_t ticks) -{ - return muldiv64(ticks, MILLISECS(1), cpu_khz); -} - void preinit_xen_time(void); =20 #endif /* ASM__RISCV__TIME_H */ diff --git a/xen/arch/riscv/time.c b/xen/arch/riscv/time.c index e962f8518d78..2c7af0a5d63b 100644 --- a/xen/arch/riscv/time.c +++ b/xen/arch/riscv/time.c @@ -4,6 +4,7 @@ #include #include #include +#include #include =20 unsigned long __ro_after_init cpu_khz; /* CPU clock frequency in kHz. */ diff --git a/xen/include/xen/time.h b/xen/include/xen/time.h index fe0d7a578a99..2185dd26a439 100644 --- a/xen/include/xen/time.h +++ b/xen/include/xen/time.h @@ -8,6 +8,7 @@ #ifndef __XEN_TIME_H__ #define __XEN_TIME_H__ =20 +#include #include #include =20 @@ -75,6 +76,16 @@ extern void send_timer_event(struct vcpu *v); =20 void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds); =20 +static inline s_time_t ticks_to_ns(uint64_t ticks) +{ + return muldiv64(ticks, MILLISECS(1), cpu_khz); +} + +static inline uint64_t ns_to_ticks(s_time_t ns) +{ + return muldiv64(ns, cpu_khz, MILLISECS(1)); +} + #include =20 #endif /* __XEN_TIME_H__ */ --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604391; cv=none; d=zohomail.com; s=zohoarc; b=SZLO+cfmWN1NkMhBTkjOGW94vyEVsv7602M5Bd72JMbmDvG4RvnBTNh3E1ke+BMuhx5XOqzMaEFs+wkG/w+7DJi8BL0lsZvYmkSUDurXjBcQxz311udWnm5zz3YeDeQg4sCgKt3B+Xlb12RAf79zChsME3vAtZHosJijEWw01Gw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604391; h=Content-Type: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=vEV8dCoZsWR/xbos3xux/u5WeUz+dOOsBwMZ7zxnQ6E=; b=eUA4drkcInYHdajRXh1gPinrir/N4pfdh+258Vcz0uxvvFg/qzBhBcEMXTpKq2iT9DV9UwTr0Z1UhMmrPhoJNLisv8MoMyuKArrggYtZ5t1EDxci8Ku3fIjRXEv71Ds3vNfDWMktGt8BkR4nJk4UstdazO1zj4J1/qnZ3FBxwrY= 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 1771604391433183.48719759541143; Fri, 20 Feb 2026 08:19:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237338.1539733 (Exim 4.92) (envelope-from ) id 1vtTDz-0001Uz-Nw; Fri, 20 Feb 2026 16:19:27 +0000 Received: by outflank-mailman (output) from mailman id 1237338.1539733; Fri, 20 Feb 2026 16:19:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTDz-0001Tw-CC; Fri, 20 Feb 2026 16:19:27 +0000 Received: by outflank-mailman (input) for mailman id 1237338; Fri, 20 Feb 2026 16:19:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTDy-0000QF-8g for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:26 +0000 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [2a00:1450:4864:20::335]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ec58b540-0e77-11f1-b164-2bf370ae4941; Fri, 20 Feb 2026 17:19:25 +0100 (CET) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-48379a42f76so17969715e9.0 for ; Fri, 20 Feb 2026 08:19:25 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:24 -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: ec58b540-0e77-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604365; x=1772209165; 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=vEV8dCoZsWR/xbos3xux/u5WeUz+dOOsBwMZ7zxnQ6E=; b=OwU25nveJCZFvqy+Uz5gvC0VQQqFjKWyquipLJmfvhrgCMvqsPW9qIobD3BhIWSHrp vYC6OrFXcDgGKwziAmXEkZy5v2JqkYOySN2yXN/+omUmgBwc5vo66BBGW6s5Yn2Ad8NV mD4lFfm/A201zHKmT4+TtlJA3+gxhmbyhbRNLYHowreN7vVMlir/TUIFLnvIXCdgYNCj nZoERDBkn6Yulfgk1oQmXtKFUgbmdacHGpGuyeMOcy316jrIr2qd4pmqmmYkhIhZK2G+ fX9RxMROyUXg/CvWSEjuT5XZHYlPTi/MlXCNFLXRHAaQR9NamWN1ZOZnOOlxCycx4OvD loIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604365; x=1772209165; 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=vEV8dCoZsWR/xbos3xux/u5WeUz+dOOsBwMZ7zxnQ6E=; b=AMY0eEPT5Og+Ume2NlVWGaRLO2gdOi9uraimkRK7eBpP1xEv5pbo8FbGJQHWKBVPLG 2thgcfONZFXDndPQPsHwO1N/5zRV6tjA6C1P48v2XQHEwn9UT4/bUHVvjSu7JPeTzYNQ Gru7FrWTJFKGm0srrtHcyYwv5y2BwBD/G75OWctGdUGESZsQ9X1I+T/LIf/0gkqTud0r C6EAVU2+Ma4p0sApdpOIex+67C0TNh+dtmNjPdypb3sb7lRJ7oIEeIkQ6AP/LShOvibU mQOeBW+BYXM6kKm4zzeWDIzVaxHZN9Lvu7XsTq4texuCKU/Ho4b/LcDVM8VNxqGdp+qa UBtg== X-Gm-Message-State: AOJu0YzlHVYOo7fPXLlFNpWRi7Yrfw++RxfOEi9m6blNYfvj8LjzfjcQ hSCKJ6QfpPkxtcUL2sm5QdkfgDuLgO5Xb/Wqp79hy7nhGoYg84GbtMPmS26a0g== X-Gm-Gg: AZuq6aKTD92jjQ3z4KFZM9svAnXp/52n9T79gB1/1G1udBXWn0oz5w/IM4A/d27a29N XR5OC2F7i+wlNc5GCve/exlKPmeQeZvQkGgFrk7TMm6qZjyYeVCrEBPXdPzUKIkUwmSIbU/h8Ol /Droc2STAfUq6JsWunQKEH6XzNqFuG6l9RhOr3n3urH4VF2Xvnlluy4PZkAAledO4/6cu56/gxh WmDfn+hdn1ptIH29nmcBBV++d6DusHxLSEqx08M6bpfvZI9lIxRGpXu+DMtmwW26PqiztM0JATg dpYop7L13ib7semZ6J2BJRjbHM7qgDwTLn1NQiXlhofxa8csZPIvhJEixYWEsLPlLuP8wawWEZK mwAO4J09kprfbQLno1dRTzstMl9pNMx6k1lQToc9PBq76btGn0ydcK7/7/gxl1b9Wkx8eFuHvTl Y/sdZiK4WVrr7bNKyA9JbKvk3X4RC0cfJtlpuBpT0aZN9JVwdHslyNAHAtjZWKJcXUfQ== X-Received: by 2002:a05:600c:4454:b0:483:80b0:b245 with SMTP id 5b1f17b1804b1-483a95f89c2mr1243105e9.9.1771604364473; Fri, 20 Feb 2026 08:19:24 -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 06/14] xen/riscv: introduce basic vtimer infrastructure for guests Date: Fri, 20 Feb 2026 17:19:01 +0100 Message-ID: <79aa5e8baa32ef4dd2ce4b586ba265b24fce58a8.1771590794.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1771604392856154100 Lay the groundwork for guest timer support by introducing a per-vCPU virtual timer backed by Xen=E2=80=99s common timer infrastructure. The virtual timer is programmed in response to the guest SBI sbi_set_timer() call and injects a virtual supervisor timer interrupt into the vCPU when it expires. While a dedicated struct vtimer is not strictly required at present, it is expected to become necessary once SSTC support is introduced. In particular, it will need to carry additional state such as whether SSTC is enabled, the next compare value (e.g. for the VSTIMECMP CSR) to be saved and restored across context switches, and time delta state (e.g. HTIMEDELTA) required for use cases such as migration. Introducing struct vtimer now avoids a later refactoring. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v5: - Drop copyright line from asm/vtimer.h. - Add Acked-by: Jan Beulich . --- Changes in v4: - Add vcpu_timer_destroy() to void arch_vcpu_destroy(). --- Changes in v3: - use one container_of() to get vcpu instead of two container_of()s. --- Changes in v2: - Drop domain_vtimer_init() as it does nothing. - Drop "struct vcpu *v;" from struct vtimer as it could be taken from arch_vcpu using container_of(). - Drop vtimer_initialized, use t->status =3D=3D TIMER_STATUS_invalid instead to understand if timer was or wasn't initialized. - Drop inclusion of xen/domain.h as xen/sched.h already includes it. - s/ xen/time.h/ xen.timer.h in vtimer.c. - Drop ULL in if-conidtion in vtimer_set_timer() as with the cast it isn't necessary to have suffix ULL. - Add migrate timer to vtimer_set_timer() to be sure that vtimer will occur on pCPU it was ran, so the signalling to that vCPU will (commonly) be cheaper. - Check if the timeout has already expired and just inject the event in vtimer_vtimer_set_timer(). - Drop const for ticks argument of vtimer_set_timer(). - Merge two patches to one: - xen/riscv: introduce vtimer - xen/riscv: introduce vtimer_set_timer() and vtimer_expired() --- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/domain.c | 10 +++- xen/arch/riscv/include/asm/domain.h | 3 ++ xen/arch/riscv/include/asm/vtimer.h | 17 +++++++ xen/arch/riscv/vtimer.c | 71 +++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 xen/arch/riscv/include/asm/vtimer.h create mode 100644 xen/arch/riscv/vtimer.c diff --git a/xen/arch/riscv/Makefile b/xen/arch/riscv/Makefile index bc47e83b26d7..ffbd7062e214 100644 --- a/xen/arch/riscv/Makefile +++ b/xen/arch/riscv/Makefile @@ -22,6 +22,7 @@ obj-y +=3D traps.o obj-y +=3D vmid.o obj-y +=3D vm_event.o obj-y +=3D vsbi/ +obj-y +=3D vtimer.o =20 $(TARGET): $(TARGET)-syms $(OBJCOPY) -O binary -S $< $@ diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index 636349c8c7e8..7027b5e9aa20 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 struct csr_masks { register_t hedeleg; @@ -120,11 +121,14 @@ int arch_vcpu_create(struct vcpu *v) =20 vcpu_csr_init(v); =20 + if ( (rc =3D vcpu_vtimer_init(v)) ) + goto fail; + /* - * As the vtimer and interrupt controller (IC) are not yet implemented, + * As interrupt controller (IC) is not yet implemented, * return an error. * - * TODO: Drop this once the vtimer and IC are implemented. + * TODO: Drop this once IC is implemented. */ rc =3D -EOPNOTSUPP; goto fail; @@ -138,6 +142,8 @@ int arch_vcpu_create(struct vcpu *v) =20 void arch_vcpu_destroy(struct vcpu *v) { + vcpu_timer_destroy(v); + vfree((void *)&v->arch.cpu_info[1] - STACK_SIZE); } =20 diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/a= sm/domain.h index 2a454bfc083c..a30ee450b36a 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -8,6 +8,7 @@ #include =20 #include +#include =20 struct vcpu_vmid { uint64_t generation; @@ -49,6 +50,8 @@ struct arch_vcpu { =20 struct cpu_info *cpu_info; =20 + struct vtimer vtimer; + register_t hcounteren; register_t hedeleg; register_t hideleg; diff --git a/xen/arch/riscv/include/asm/vtimer.h b/xen/arch/riscv/include/a= sm/vtimer.h new file mode 100644 index 000000000000..111863610a92 --- /dev/null +++ b/xen/arch/riscv/include/asm/vtimer.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef ASM__RISCV__VTIMER_H +#define ASM__RISCV__VTIMER_H + +#include + +struct vtimer { + struct timer timer; +}; + +int vcpu_vtimer_init(struct vcpu *v); +void vcpu_timer_destroy(struct vcpu *v); + +void vtimer_set_timer(struct vtimer *t, uint64_t ticks); + +#endif /* ASM__RISCV__VTIMER_H */ diff --git a/xen/arch/riscv/vtimer.c b/xen/arch/riscv/vtimer.c new file mode 100644 index 000000000000..32d142bcdfcd --- /dev/null +++ b/xen/arch/riscv/vtimer.c @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include + +#include + +static void vtimer_expired(void *data) +{ + struct vtimer *t =3D data; + struct vcpu *v =3D container_of(t, struct vcpu, arch.vtimer); + + vcpu_set_interrupt(v, IRQ_VS_TIMER); +} + +int vcpu_vtimer_init(struct vcpu *v) +{ + struct vtimer *t =3D &v->arch.vtimer; + + init_timer(&t->timer, vtimer_expired, t, v->processor); + + return 0; +} + +void vcpu_timer_destroy(struct vcpu *v) +{ + struct vtimer *t =3D &v->arch.vtimer; + + if ( t->timer.status =3D=3D TIMER_STATUS_invalid ) + return; + + kill_timer(&v->arch.vtimer.timer); +} + +void vtimer_set_timer(struct vtimer *t, const uint64_t ticks) +{ + struct vcpu *v =3D container_of(t, struct vcpu, arch.vtimer); + s_time_t expires =3D ticks_to_ns(ticks - boot_clock_cycles); + + vcpu_unset_interrupt(v, IRQ_VS_TIMER); + + /* + * According to the RISC-V sbi spec: + * If the supervisor wishes to clear the timer interrupt without + * scheduling the next timer event, it can either request a timer + * interrupt infinitely far into the future (i.e., (uint64_t)-1), + * or it can instead mask the timer interrupt by clearing sie.STIE C= SR + * bit. + */ + if ( ticks =3D=3D ((uint64_t)~0) ) + { + stop_timer(&t->timer); + + return; + } + + if ( expires < NOW() ) + { + /* + * Simplify the logic if the timeout has already expired and just + * inject the event. + */ + stop_timer(&t->timer); + vcpu_set_interrupt(v, IRQ_VS_TIMER); + + return; + } + + migrate_timer(&t->timer, smp_processor_id()); + set_timer(&t->timer, expires); +} --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604387; cv=none; d=zohomail.com; s=zohoarc; b=gFKJucpD1cXuei8+Ro21TQdyTlanxIGZyFTq+J0zYQLwFeYLA05yma2kW/lPzkqeiDvtQDbp7rYinIHNsLd3vAZvB7oaFMdgv8Z5EHHQg0bW0XZwtqI4+NxtgsKwCdJTxueBwRb4EMOou2umAPjgbXHfHVsf35JIh7ao/wpH/yM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604387; 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=L59NZMHr94doMxHYbooYqU+b+678IT1cbuVKqM3ukd0=; b=QvDtKRQunKpUtF6kjluh3sbJc3MyeUVGduSd5RPuZZaUFA92FSmPa37hrFXUCbPQ3BlIYHkNQNJD6txpcAroLOgrozUJ5ORmqVqJsegJHtzICO+lsmgBrzBj67AkNiCW4R0tOB7M0sL8mXSng9ndyRUEi+hv4WhsWIgFWsx9lo8= 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 1771604387834607.9947095116082; Fri, 20 Feb 2026 08:19:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237339.1539749 (Exim 4.92) (envelope-from ) id 1vtTE1-00025X-S6; Fri, 20 Feb 2026 16:19:29 +0000 Received: by outflank-mailman (output) from mailman id 1237339.1539749; Fri, 20 Feb 2026 16:19:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTE1-00025G-Of; Fri, 20 Feb 2026 16:19:29 +0000 Received: by outflank-mailman (input) for mailman id 1237339; Fri, 20 Feb 2026 16:19:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTE0-0000Q4-7e for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:28 +0000 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [2a00:1450:4864:20::329]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ecf522b8-0e77-11f1-9ccf-f158ae23cfc8; Fri, 20 Feb 2026 17:19:26 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-483487335c2so21410585e9.2 for ; Fri, 20 Feb 2026 08:19:26 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:25 -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: ecf522b8-0e77-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604366; x=1772209166; 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=L59NZMHr94doMxHYbooYqU+b+678IT1cbuVKqM3ukd0=; b=S3q7A04RZNKuGVC2lv5LmiXS+HfLUSjRnlEYQSFSd+kY1/djYWxWGOCcCdzZAdC0vf krFp6ARERyCLLJe6K7Wh/wQa1mvJvgZvY89qfqWItbrYRqW27lK4dwN7kUq2Rx0BxNjh Txjd3VtTEmAHVd10ucZASWcLu3YIZwvshGmzlCgE1e5UOzAr6heQcs0oAMbIKQOdtbGw iZRRj4Z0t28xLDnFQEL60NDGD5Tu+JvXnOo0mNi0UGMojlE7AdidHCwBl4Chh7rJjoS7 asb7XttRLkAbhTN2xh9V/KMZE73GHp20+7LWgB/ievKBCT1uRccjeQbcF9Safwili0C6 Z9xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604366; x=1772209166; 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=L59NZMHr94doMxHYbooYqU+b+678IT1cbuVKqM3ukd0=; b=g30bC4tiGA6TiYCq0AxN7aDpEZDXb1q8biQpzhVqGUMLqI46Hq3YAvMZX72lg1Ozpi fq07J7nPRaxj3353/x3AMbctK5b6ULHtE4BUShaJ63HOpqlAXLvJYE56gIOOqwGbUiDY B1kKSlUretAoa+6cbtt+PVCoxrjZNCnyp4HXQTwJZZ8SwyXqPA2D9zdSo6v63S8usAqc Lb5MB2SzbVglZN6dNKU0AUXDtYpvWRycNwR+IZ1sdgV6QO9jorl0yiLTjJ3mipTjuY70 QiB/XceMmcFbtLThDnUq591Gn+os/iOs79GZaB5uyTkIu9EHSneuoiTuaW0toT1VTjX2 8SMg== X-Gm-Message-State: AOJu0Yy7jQW82Fm2OtdmwhnxG77jsXjdAVkRDJfErR0ykEAmkP4Zm4tD yRCcC3dr+3QF8U5Zc1VPGgHJ9QSmn9HfTCttGwXFPAZXjDrlrM6/C5Gb2EUbDQ== X-Gm-Gg: AZuq6aL04xf1LJdyNmv3B8TQtsKxLQ0IgFJC5Zst/YgHJSDUcFvL1nPCNZrkI+VfLeM yxywsRO7HOVj+HiuCDksuEVSwYXdso2u73vrIEIDp4Hl5P6KddhPD1azGVQ6yc2ppY0f63wrPcM VlD95Nhpoz2stXWWSinOVIy03qFf9BBvqgmcG0svyA2mO9RbArKtI/Jnq5I2PgjvrT0EzHpA6Sr 2gAzglBXfkFoLq+MLd5Ai0vP5EB/2o8FodcXpsYMpu/t4EshPXH7XQayfyBJnxL/5fud/eZ/pj7 acrlVDWrm6ujIyL3vMmiLPO7gM97s3d78bRvH3WotuRC1VJg4XwsmvW0uDQVK00a4itBM0AxX7x jZFiREkFFZl43RO4age6jJoq1+qo1spug/lQ/IPy8JL+kbICmpHldkRt3Th3rlo8Ok1m8pO5lKK gn31U6JBMC7AMgW341ZXJhMOLi2kqROIW//SSjavlhyps4iob+SDdf7kV8cEN6O8JVbw== X-Received: by 2002:a05:600c:3e8d:b0:47e:e9c9:23bc with SMTP id 5b1f17b1804b1-483a95f89b5mr1012965e9.30.1771604365821; Fri, 20 Feb 2026 08:19:25 -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 07/14] xen/riscv: introduce vcpu_kick() implementation Date: Fri, 20 Feb 2026 17:19:02 +0100 Message-ID: <0d0c9a359699240cd812e1ba68385a864666d102.1771590794.git.oleksii.kurochko@gmail.com> 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: 1771604388743154100 Content-Type: text/plain; charset="utf-8" Add a RISC-V implementation of vcpu_kick(), which unblocks the target vCPU and sends an event check IPI if the vCPU was running on another processor. This mirrors the behavior of Arm and enables proper vCPU wakeup handling on RISC-V. Remove the stub implementation from stubs.c, as it is now provided by arch/riscv/domain.c. Since vcpu_kick() calls perfc_incr(vcpu_kick), add perfcounter for vcpu_kick to handle the case when CONFIG_PERF_COUNTERS=3Dy. Although CONFIG_PERF_COUNTERS is not enabled by default, it can be enabled, for example, by randconfig what will lead to CI build issues. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v4-v5: - Nothing changed. Only rebase. --- Changes in v3: - Add asm/perfc_defn.h to provide vcpu_kick perfcoounter to cover the case when CONFIG_PERF_COUNTERS=3Dy. --- Changes in v2: - Add Acked-by: Jan Beulich . --- xen/arch/riscv/domain.c | 14 ++++++++++++++ xen/arch/riscv/include/asm/Makefile | 1 - xen/arch/riscv/include/asm/perfc_defn.h | 3 +++ xen/arch/riscv/stubs.c | 5 ----- 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 xen/arch/riscv/include/asm/perfc_defn.h diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index 7027b5e9aa20..fb5c21078172 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -1,9 +1,11 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include #include #include #include #include +#include #include =20 #include @@ -251,6 +253,18 @@ void vcpu_flush_interrupts(struct vcpu *v) #endif } =20 +void vcpu_kick(struct vcpu *v) +{ + bool running =3D v->is_running; + + vcpu_unblock(v); + if ( running && v !=3D current ) + { + perfc_incr(vcpu_kick); + smp_send_event_check_mask(cpumask_of(v->processor)); + } +} + static void __init __maybe_unused build_assertions(void) { /* diff --git a/xen/arch/riscv/include/asm/Makefile b/xen/arch/riscv/include/a= sm/Makefile index 3824f31c395c..86c56251d5d7 100644 --- a/xen/arch/riscv/include/asm/Makefile +++ b/xen/arch/riscv/include/asm/Makefile @@ -7,7 +7,6 @@ generic-y +=3D hypercall.h generic-y +=3D iocap.h generic-y +=3D irq-dt.h generic-y +=3D percpu.h -generic-y +=3D perfc_defn.h generic-y +=3D random.h generic-y +=3D softirq.h generic-y +=3D vm_event.h diff --git a/xen/arch/riscv/include/asm/perfc_defn.h b/xen/arch/riscv/inclu= de/asm/perfc_defn.h new file mode 100644 index 000000000000..8a4b945df662 --- /dev/null +++ b/xen/arch/riscv/include/asm/perfc_defn.h @@ -0,0 +1,3 @@ +/* This file is intended to be included multiple times. */ + +PERFCOUNTER(vcpu_kick, "vcpu: notify other vcpu") diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index daadff0138e4..eedf8bf9350a 100644 --- a/xen/arch/riscv/stubs.c +++ b/xen/arch/riscv/stubs.c @@ -203,11 +203,6 @@ void vcpu_block_unless_event_pending(struct vcpu *v) BUG_ON("unimplemented"); } =20 -void vcpu_kick(struct vcpu *v) -{ - BUG_ON("unimplemented"); -} - unsigned long hypercall_create_continuation(unsigned int op, const char *format, ...) { --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604396; cv=none; d=zohomail.com; s=zohoarc; b=VL5pwYbZnhlgphs1CSBQsvPWTqM6j1zebASmNvNjDt71PA+v7jrbt366CKr2SXc98kWpH5gpHRTq3LLDbVxfXT9pXfrXSUY+X1Em7hG47z8I4cxsmmQFQOJpM3ckDCQ3DwfiwA1hS/mjCNsCkmIpnjWTUl1St/dxNIyQVusO1CE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604396; 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=8IfTwwNG5f/qMELUo5yc+EiwaE+xRpKyZnUpo6oHC2Y=; b=gQAe39b1DwaFzuuyGjnsOh49BQFJoLS7bNasbFVsKwUq6jxMGAuQuJrAR6q2OeAA/Ek+Hjc5GTjZz0a6pkYZUjLSrBRyjdeZ55nv8vcm/24R+jVp48EQrMW8KmZaNJVchIk7XuCzwwlnxUTB1sg3ZDtRH92jXxGPQXKxOd9x8WQ= 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 1771604396282914.366051093936; Fri, 20 Feb 2026 08:19:56 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237340.1539758 (Exim 4.92) (envelope-from ) id 1vtTE4-0002Oq-6I; Fri, 20 Feb 2026 16:19:32 +0000 Received: by outflank-mailman (output) from mailman id 1237340.1539758; Fri, 20 Feb 2026 16:19:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTE4-0002Oa-0q; Fri, 20 Feb 2026 16:19:32 +0000 Received: by outflank-mailman (input) for mailman id 1237340; Fri, 20 Feb 2026 16:19:30 +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 1vtTE2-0000Q4-Km for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:30 +0000 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [2a00:1450:4864:20::42c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ee24eed1-0e77-11f1-9ccf-f158ae23cfc8; Fri, 20 Feb 2026 17:19:28 +0100 (CET) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-4376de3f128so1538330f8f.0 for ; Fri, 20 Feb 2026 08:19:28 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:26 -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: ee24eed1-0e77-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604368; x=1772209168; 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=8IfTwwNG5f/qMELUo5yc+EiwaE+xRpKyZnUpo6oHC2Y=; b=GiVLboqsfP9FtiMLzd6SitTgbusn9BpMkwkS7BorYQybvOkD8VOeKCN2z1t7XV5o8I 8exVXha4ZG8Y2/zyuMGO7CtWzyLnQ/pl8v2TDTuq13kSpXTAhwYHFshmIGpSaJLznrfE UTIAfLWkdBw+6wsZMtPzTOFQnpXuluvCf8LUygOcKgIj3e/C7wzrz7gmwLfU8+0Sc/Xz aAAOYbcBd2UVcIqqwYglU98xJ8QIzXSUuN9ENpd4tGc9wJilBgl16wwc0QVVpe521DOy K3B1BZGSxTNgpB3WXZa6hSuWRo2PLx03+VqY5YjjJ4LUOxrKdOmvSxyV5meCJswME5xr 2WIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604368; x=1772209168; 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=8IfTwwNG5f/qMELUo5yc+EiwaE+xRpKyZnUpo6oHC2Y=; b=IPx/AnUw/nIBX6yac0tnXdHDFbZvnDVblMU20c1Ns2sLEkp8ZH/NsFhNOJ4HwivbAS WUHUbcUuwhj/nKLKh81fndY1+sZFuFQ0imEQYDeo0aMVN/8Cm4DlW4WhkjcR1Xs34tuI w3/c8364iWO4ij2mW+XPxG+HOzDD77lrzxh96ZHAkQ7FghvJ/BRvMmvm1zAr7O/mY7c6 c/LTJrO0MPCCbt468Vxu60cePTvesdmylM2VWafhIUu54+/qETBNipx9cNS0dTNVt31j sG40o6NxftiPFtOp97kqdWrciqcjrPoPUyKOifQ1M/DOj5Nmjpre40ibKumTSN/3MngY oFUQ== X-Gm-Message-State: AOJu0YzpGUm6u2tTMKSnsAiqew1ZLT3uB1Z/rx4yAuP7zN/Dc4pXhXge 7i0U6sS8qOie28Aysj7ygBcNu8jiRlwSfJwNc++kC7QXf2lNiFGqm04MJXYT6A== X-Gm-Gg: AZuq6aKkv9g44R3TALCaLDKOTwxo+Ts76UitVjzWBcdeNqMlV5r6cL2hnJYFVTlwu9c MLAm8Hd5ofYLpff8g7ecMuJSZtIHKNmwfzKezcsWNxgVTsPtboMpukgyO9QkgK3gvEW151tbFiU 3zEIRfXrXVa0KYqb6Q6SHavSD9GMZCIzArvRkQ1NZOHUxUBWGnvvdB5BzNsMGyFuLyLHEgXd35U bOg9zE4A4U6re9UuqNeJs48aYIfSFLBLaVKdAPDmDYFvA4301tuAvoxUHYLqYqJF8U5434S7rIz 4VNGYhtrvqBYmv+7ler3s/HSfjVKVVflqst+enQfQ3srlW2zwtNAHMDSUXRVIDPilnsCE8REktH l6o9widPrCRQmwQBQeSin/HcCp68lN2cuqrz9be1o7qqyufy4N7LJB16boEEBIYO+Y96xqVwLVz 6gXllrNDs7TMEXUiaIDgRI1pLlehpWbTSB2oRumhnOZOH6/vvhF84ih8K5bFFUXHXw6r7Vkg== X-Received: by 2002:a05:6000:4026:b0:437:681e:cbc3 with SMTP id ffacd0b85a97d-4396f15e475mr839815f8f.13.1771604366958; Fri, 20 Feb 2026 08:19:26 -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 08/14] xen/riscv: add vtimer context switch helpers Date: Fri, 20 Feb 2026 17:19:03 +0100 Message-ID: <26ead013f23bef85423680f37f4e671c1f6ee8cd.1771590794.git.oleksii.kurochko@gmail.com> 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: 1771604396760158500 Content-Type: text/plain; charset="utf-8" Introduce vtimer_ctxt_switch_from() and vtimer_ctxt_switch_to() to handle virtual timer state across vCPU context switches. At present, vtimer_ctxt_switch_from() is a no-op because the RISC-V SSTC extension, which provides a virtualization-aware timer, is not yet supported. Xen therefore relies the virtual (SBI-based) timer. The virtual timer uses Xen's internal timer infrastructure and must be associated with the pCPU on which the vCPU is currently running so that timer events can be delivered efficiently. As a result, vtimer_ctxt_switch_= to() migrates the timer to the target pCPU when a vCPU is scheduled in. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v4-v5: - Nothing changed. Only rebase. --- Changes in v3: - s/vtimer_ctx_switch_to/vtimer_ctxt_switch_to - s/vtimer_ctx_switch_from/vtimer_ctxt_switch_from - Add Acked-by: Jan Beulich . --- Changes in v2: - Align the parameters names for vtimer_ctx_switch_from() and vtimer_ctx_= switch_to() in declarations to match the ones in the defintions to make Misra happy. - s/vtimer_save/vtimer_ctx_switch_from. - s/vtimer_restore/vtimer_ctx_switch_to. - Update the commit message. --- xen/arch/riscv/include/asm/vtimer.h | 3 +++ xen/arch/riscv/vtimer.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/xen/arch/riscv/include/asm/vtimer.h b/xen/arch/riscv/include/a= sm/vtimer.h index 111863610a92..b4d48d1a1732 100644 --- a/xen/arch/riscv/include/asm/vtimer.h +++ b/xen/arch/riscv/include/asm/vtimer.h @@ -14,4 +14,7 @@ void vcpu_timer_destroy(struct vcpu *v); =20 void vtimer_set_timer(struct vtimer *t, uint64_t ticks); =20 +void vtimer_ctxt_switch_from(struct vcpu *p); +void vtimer_ctxt_switch_to(struct vcpu *n); + #endif /* ASM__RISCV__VTIMER_H */ diff --git a/xen/arch/riscv/vtimer.c b/xen/arch/riscv/vtimer.c index 32d142bcdfcd..afd8a53a7387 100644 --- a/xen/arch/riscv/vtimer.c +++ b/xen/arch/riscv/vtimer.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include #include #include =20 @@ -69,3 +70,17 @@ void vtimer_set_timer(struct vtimer *t, const uint64_t t= icks) migrate_timer(&t->timer, smp_processor_id()); set_timer(&t->timer, expires); } + +void vtimer_ctxt_switch_from(struct vcpu *p) +{ + ASSERT(!is_idle_vcpu(p)); + + /* Nothing to do at the moment as SSTC isn't supported now. */ +} + +void vtimer_ctxt_switch_to(struct vcpu *n) +{ + ASSERT(!is_idle_vcpu(n)); + + migrate_timer(&n->arch.vtimer.timer, n->processor); +} --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604393; cv=none; d=zohomail.com; s=zohoarc; b=lv+MT5hqGbcDXSHiP9gK0fFdYAayF0t8x0FSNRVnIN6r+UsxxuMG6c+Zn9j3/25uoZ7E/8ojZcDCV/USn1CFvWLapHn5wzsdCCrdqmDE7fvsBd9O4bK7FIQBKddCGD7bOdVgMQzv15IoEKg4ggZjIW34mVp6WdzvvaNCC7uAHT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604393; h=Content-Type: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=J6aGuGPcNuPDYPCV7GwkHM9t8Lc+qUdl4ib7PfisxG8=; b=ZCnwQfLCcqIgbqSCaRH9eKxur0OBz83IDa/YJgEKmP2AeHIH7LtJAA6/+EQDrPk8I1XYtIrwamg+oTh9PcJsUIBijUHSVRi47HL1ZEmaw5NImlD6Ksrwpgni7lcUHT6mqPmgDKw4LWgooDU2blmZQOoPU2pxyl1Fs8fGJMa6zhQ= 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 1771604393118847.5146757334064; Fri, 20 Feb 2026 08:19:53 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237341.1539764 (Exim 4.92) (envelope-from ) id 1vtTE4-0002RG-It; Fri, 20 Feb 2026 16:19:32 +0000 Received: by outflank-mailman (output) from mailman id 1237341.1539764; Fri, 20 Feb 2026 16:19:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTE4-0002QD-AP; Fri, 20 Feb 2026 16:19:32 +0000 Received: by outflank-mailman (input) for mailman id 1237341; Fri, 20 Feb 2026 16:19:30 +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 1vtTE2-0000Q4-SE for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:30 +0000 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [2a00:1450:4864:20::42d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ee5bc87b-0e77-11f1-9ccf-f158ae23cfc8; Fri, 20 Feb 2026 17:19:29 +0100 (CET) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-4362c635319so2097773f8f.2 for ; Fri, 20 Feb 2026 08:19:29 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:27 -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: ee5bc87b-0e77-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604368; x=1772209168; 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=J6aGuGPcNuPDYPCV7GwkHM9t8Lc+qUdl4ib7PfisxG8=; b=UtCZMvNsUewN3dl7b484fGEpmCpA5wx7N4zu4EhoBBFEK+CUQGuW4oYuAin2jb3Yhh s11yDClK1e1mCwSFc78C4XBcrKRjZw3SNPkt9uDhFP1D+xjnIl339svmw6KScnlN06sT aUpxuGZehKXQU36t9SELH2py8QXeoEpAmlYm5As4Y1PAcUfd23jkg/fnflNWsJqX/0Zi Oxxd4RdBllPkWpW/NUsDAhFez3g/p3K3p/zmTgnht5PzRJ9rmA6G5eTVtOWw9aIArPiJ R/VnLPq7eTdyVldEB+5tj4dfn4YmFVE+L8/FPZpmirgKSDgvKE948njRHiKt7peyD4ky F59Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604368; x=1772209168; 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=J6aGuGPcNuPDYPCV7GwkHM9t8Lc+qUdl4ib7PfisxG8=; b=HEvvL+ScUAm2asxJuuZc+8vEmiprZpXF0j9PPEVhtsT4PQafjhZdffCfJ/dHK9AYxc tFw/rhS6KarIwbkLpepguUtq7Qh3c1/Bncz1/pkfLOB04n/29W9A7nPIqjP07BH6wYNh eRSCHQ3nM+dzGFa9JWhAln2WwlIFHHMb9Yg+5y8w8KK+6kEyRK0nvKZ9JhOCwJJVI+LJ 2u+2640xlgmqyjDDggEhlhNr7Am2LvJo1cypIwGYnac87mj/5OY1B4J0UozxON3gyu7B ylC3MdU3Rz+NPQO3Pkd55C1lODeFZ0czvqxziLSZ+PZ6LP4cuVFQXDdfnfNEzbpGMK73 lUng== X-Gm-Message-State: AOJu0YwI18DZ8F2bkwshYkqRXAK8UfGEdTY9fzjLi3GTXXcP7izWepZ2 YTm9C7nA6xTQOeHymEqLshjs3fgycJpgi1TTTAPrOD+GE+Gc92kLcyxuhmnlbw== X-Gm-Gg: AZuq6aJ7yAh0kcl2lmAyy5zsMGicxQeLs0NU11MhyoNTmZffxvdC9fc9DhpJbYMOg7k pJ4JVQOJmQMlmdsN77nPOzsaWruY02mufnv2cFOikVuNb0rGBbeG7UY6ijvgw6kPfl2dbrpCWhB 6xMpTl8y3sm4GN5pRyVHxJXc2oTrWHkYad4K+kVdTJRP9IwH0l5vnJVnXyMVArfXjuvtrQyzmYp WAXKjT/XzHvBnm1BtpUQ73rJILUclotcI8nheti20/RSRfa9w07b8Al0S5KnNdpGMhiLcQhH/PR GyVa7CNTtxEX9qUUrbtB5iYymp8SF6wyok0R0uGK7QjkGYHv39uiM9HPbDGyMXaoeAEaqbxoO7u xtRaYYxkpKiJU25o6vqybjcg15ZPx4nQQpulDEXDwCY/Rsu/RrKR29Q4O1zOvEWdZJZ9Soxcx6n 1xGOobJ/Dwq30lxlmonJ3idtsQZDTyTzoNbTTxsniUdy9mD+98prv4hz5paeIm73Owuw== X-Received: by 2002:a5d:64e5:0:b0:437:6806:994f with SMTP id ffacd0b85a97d-4396f14cb6fmr908975f8f.12.1771604367888; Fri, 20 Feb 2026 08:19:27 -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 09/14] xen/riscv: implement SBI legacy SET_TIMER support for guests Date: Fri, 20 Feb 2026 17:19:04 +0100 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1771604394728158500 Add handling of the SBI_EXT_0_1_SET_TIMER function ID to the legacy extension ecall handler. The handler now programs the vCPU=E2=80=99s virtual timer via vtimer_set_timer() and returns SBI_SUCCESS. This enables guests using the legacy SBI timer interface to schedule timer events correctly. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v3 - v5: - Nothing changed. Only rebase. --- Changes in v2: - Add Acked-by: Jan Beulich . --- xen/arch/riscv/vsbi/legacy-extension.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/arch/riscv/vsbi/legacy-extension.c b/xen/arch/riscv/vsbi/l= egacy-extension.c index 2e8df191c295..090c23440cea 100644 --- a/xen/arch/riscv/vsbi/legacy-extension.c +++ b/xen/arch/riscv/vsbi/legacy-extension.c @@ -7,6 +7,7 @@ =20 #include #include +#include =20 static void vsbi_print_char(char c) { @@ -44,6 +45,11 @@ static int vsbi_legacy_ecall_handler(unsigned long eid, = unsigned long fid, ret =3D SBI_ERR_NOT_SUPPORTED; break; =20 + case SBI_EXT_0_1_SET_TIMER: + vtimer_set_timer(¤t->arch.vtimer, regs->a0); + regs->a0 =3D SBI_SUCCESS; + break; + default: /* * TODO: domain_crash() is acceptable here while things are still = under --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604394; cv=none; d=zohomail.com; s=zohoarc; b=EnFkv8ALFmMkjoSUy4x+usxSYcl0fhwMaqdRBS9+ww7VnxQDXJ8qwOx02yyEJW7hcS5XEPpqjFr6lPVdQIpmuasLT/VLm0USPiVu//9lB0EfsgNIaoEZMHYmhDsTQc9ysbIYiAo461h843Q471GPJw/PO8fW1LcP7TzM+1gfhSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604394; h=Content-Type: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=3VAMf5wEbjWTV3qUp1H5TFWR6XdnKzjzMGvNMq2GKmE=; b=HzCGgns4BMLVxBpfoxy6xj/JmxkYUa6++bEjS8hCNG1aICSQUl6xC1QN6BbYy4r2QlJ3DE1sUjc6AO70QfyzMSbu62Xiv2Yz11JatmStcXI48f4m2O8ZhwnMvgax2LA35eLqNHv8cXZwIzhW2DuXf92sbWHsPp7yVtlPcj5oPOI= 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 1771604394461836.4421116839366; Fri, 20 Feb 2026 08:19:54 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237343.1539775 (Exim 4.92) (envelope-from ) id 1vtTE6-0002pH-9w; Fri, 20 Feb 2026 16:19:34 +0000 Received: by outflank-mailman (output) from mailman id 1237343.1539775; Fri, 20 Feb 2026 16:19:34 +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-0002oQ-3z; Fri, 20 Feb 2026 16:19:34 +0000 Received: by outflank-mailman (input) for mailman id 1237343; Fri, 20 Feb 2026 16:19:32 +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 1vtTE3-0000Q4-V6 for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:31 +0000 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [2a00:1450:4864:20::32f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ef079b3d-0e77-11f1-9ccf-f158ae23cfc8; Fri, 20 Feb 2026 17:19:30 +0100 (CET) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-48334ee0aeaso17009375e9.1 for ; Fri, 20 Feb 2026 08:19:30 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:28 -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: ef079b3d-0e77-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604369; x=1772209169; 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=3VAMf5wEbjWTV3qUp1H5TFWR6XdnKzjzMGvNMq2GKmE=; b=jGNQpjWrU8VIWmAKD9uYAFQLk2GxEGlPr1fjj5Fa6R6W1u9daTFnAjeDioKbVmflc4 XZvUi+TlN2CGSn+MVAXrEfdHESZSNfR9PIuOvKjaWqLtTiU6SC0yQI0Ke2q2WOqjPhd/ a1VePKAtukASbG1Srz+Akr1iHq+YWPDDMgvgh0u5GCoYC1zqun0rNVzfX0x9atsnwKii fv3ds78ZVww1leIDwfeuWq6rQOtG405bUVOz4KC8thrmOF7G7cPDdqapbkB1+EYCkdpA rBm+PqAzRnBLAA8NNvjO6Nn/pvFxo/kVB2nqM5YAYaaV9oqHgtPIbmzcZ2xAptGLm5PT tK5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604369; x=1772209169; 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=3VAMf5wEbjWTV3qUp1H5TFWR6XdnKzjzMGvNMq2GKmE=; b=uge/Gyr9Bpe0KpqNFDTsX9hoRuW6mxhzja7FAFrGxX8iNlP/rhEE4zkDZWxHcNuhtR fKeHdLsQiuOOSeKwgKouJL1Tfaojzhdspz9LvhVYK9eUB5rlY9cHMPtPCkW8KSOfiHuI Jg0ZP1rZRkgy+KtJdTbcwSlY3bWBl0MQ+hCWfD95G9Dp3S4puZipR1JNA/mDKDp9A34U 7gUNh+hYvaUyN9R4fbw03G08HjC1EpdxZNMCKHt9muvcjOBkjIhrjlXYWxR8urKilwtY irP98bCiXkH0mvSvlFkZyLn2Rfao31+h5oMJwtp4xxF+Sq6EgoT7+v3sdC3uzrpahuK/ 2RNg== X-Gm-Message-State: AOJu0Yw2rrnFunofG5yJtLPR8fSz9KRla0V2chWgz10GDRjoStipmjvJ PO/wlrR2GbOLDhV53VW1GUIJts6qJdBmMJQ9qjY+xqbhznJb1/6euYwtoWS+fA== X-Gm-Gg: AZuq6aIstN+Pihplvy8hQ5iTcROzoCMvHPCve15BFO0JJe2bZP8sCmnitYGA/qyOdW+ pmMurzj0LUFZdSZHyqilQQ3QZSPkrH4osjTu9KBYVmADIPaPC9WAPjaxh429slrl1jvMZH6Wwd8 BViUin8VEoBbakuRELaDBrehP8HwhvKB/STCvWSuahpku8xLi4C4x3aohFEvvtS45IK0NOSI6er df9Xj5BOv/rQHM4/aE7NmO6w4rJoBJhFXQKCWZ/uTsz9gF8kT+oHlRHNWEWuvQVoRW+jdhN3aOB 2OanJK1CGHiPWUJcvsGHX93/cyt+Z7q+0zuK0FPlmjeYJCvgBnKqWscVC3m091q5j8UKj0F4IVB Jg8P1pqzdhEZn9SouOsJ/i5XSwZD9BKT+twiL0IB/mcQHy2OVnMAHpJQ7l0uiiMG9CHST7AL39W iC64zZoIywofviQ7AWNQwMp64POu/uokohiRMIdzLk1FieORYOousbmCOulBCb0MbPlc+Heg== X-Received: by 2002:a05:600c:1f8f:b0:483:6d4e:9811 with SMTP id 5b1f17b1804b1-483a95ee3f2mr1262605e9.31.1771604369073; Fri, 20 Feb 2026 08:19:29 -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 10/14] xen/riscv: introduce sbi_set_timer() Date: Fri, 20 Feb 2026 17:19:05 +0100 Message-ID: <8f3a1ea2d841ce9f184583cdb9915bd39d760825.1771590794.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1771604396817154100 Introduce a function pointer for sbi_set_timer(), since different OpenSBI versions may implement the TIME extension with different extension IDs and/or function IDs. If the TIME extension is not available, fall back to the legacy timer mechanism. This is useful when Xen runs as a guest under another Xen, because the TIME extension is not currently virtualised and therefore will not appear as available. Despite of the fact that sbi_set_timer_v01 is introduced and used as fall back, SBI v0.1 still isn't fully supported (with the current SBI calls usage, sbi_rfence_v01 should be introduced too), so panic() in sbi_init() isn't removed. The sbi_set_timer() pointer will be used by reprogram_timer() to program Xen=E2=80=99s physical timer as without SSTC extension there is no any other option except SBI call to do that as only M-timer is available for us. Use dprintk() for all the cases to print that a speicifc SBI extension is available as it isn't really necessary in case of release builds. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v5: - Add inclusion of to to deal with the compila= tion issue: ./arch/riscv/include/asm/sbi.h:156:30: error: expected ')' before 'sbi_= set_timer' 156 | extern int (* __ro_after_init sbi_set_timer)(uint64_t stime_value= ); - Rephrase the first sentence of the comment above declaration of sbi_set_t= imer pointer to function. --- Changes in v4: - Add "stime_value is in absolute time" to the comment above declaration of sbi_set_timer() function pointer. - Add Acked-by: Jan Beulich . --- Changes in v3: - Init sbi_set_timer with sbi_set_timer_v01 as fallback value. - Sort SBI IDs in the same way as SBI EXT IDs are declared. - Add __ro_after_init for sbi_set_timer variable. - use dprintk instead of printk to print information if SBI ext is availab= le. --- Changes in v2: - Move up defintion of SBI_EXT_TIME_SET_TIMER and use the same padding as defintions around it. - Add an extra comment about stime_value granuality above declaration of sbi_set_timer function pointer. - Refactor implemetation of sbi_set_timer_v02(). - Provide fallback for sbi_set_timer_v01(). - Update the commit message. --- xen/arch/riscv/include/asm/sbi.h | 22 ++++++++++++++++++ xen/arch/riscv/sbi.c | 40 +++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/xen/arch/riscv/include/asm/sbi.h b/xen/arch/riscv/include/asm/= sbi.h index 79f7ff5c5501..ed7af200288f 100644 --- a/xen/arch/riscv/include/asm/sbi.h +++ b/xen/arch/riscv/include/asm/sbi.h @@ -13,6 +13,7 @@ #define ASM__RISCV__SBI_H =20 #include +#include =20 /* SBI-defined implementation ID */ #define SBI_XEN_IMPID 7 @@ -29,6 +30,7 @@ =20 #define SBI_EXT_BASE 0x10 #define SBI_EXT_RFENCE 0x52464E43 +#define SBI_EXT_TIME 0x54494D45 =20 /* SBI function IDs for BASE extension */ #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 @@ -48,6 +50,9 @@ #define SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA 0x5 #define SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID 0x6 =20 +/* SBI function IDs for TIME extension */ +#define SBI_EXT_TIME_SET_TIMER 0x0 + #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f000000 #define SBI_SPEC_VERSION_MINOR_MASK 0x00ffffff =20 @@ -134,6 +139,23 @@ int sbi_remote_hfence_gvma(const cpumask_t *cpu_mask, = vaddr_t start, int sbi_remote_hfence_gvma_vmid(const cpumask_t *cpu_mask, vaddr_t start, size_t size, unsigned long vmid); =20 +/* + * Programs the clock for next event at (or after) stime_value. stime_valu= e is + * in absolute time. This function must clear the pending timer interrupt = bit + * as well. + * + * If the supervisor wishes to clear the timer interrupt without schedulin= g the + * next timer event, it can either request a timer interrupt infinitely far + * into the future (i.e., (uint64_t)-1), or it can instead mask the timer + * interrupt by clearing sie.STIE CSR bit. + * + * The stime_value parameter represents absolute time measured in ticks. + * + * This SBI call returns 0 upon success or an implementation specific nega= tive + * error code. + */ +extern int (* __ro_after_init sbi_set_timer)(uint64_t stime_value); + /* * Initialize SBI library * diff --git a/xen/arch/riscv/sbi.c b/xen/arch/riscv/sbi.c index 425dce44c679..b4a7ae6940c1 100644 --- a/xen/arch/riscv/sbi.c +++ b/xen/arch/riscv/sbi.c @@ -249,6 +249,38 @@ static int (* __ro_after_init sbi_rfence)(unsigned lon= g fid, unsigned long arg4, unsigned long arg5); =20 +static int cf_check sbi_set_timer_v02(uint64_t stime_value) +{ + struct sbiret ret; + + ret =3D sbi_ecall(SBI_EXT_TIME, SBI_EXT_TIME_SET_TIMER, stime_value, +#ifdef CONFIG_RISCV_32 + stime_value >> 32, +#else + 0, +#endif + 0, 0, 0, 0); + + return sbi_err_map_xen_errno(ret.error); +} + +static int cf_check sbi_set_timer_v01(uint64_t stime_value) +{ + struct sbiret ret; + + ret =3D sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, +#ifdef CONFIG_RISCV_32 + stime_value >> 32, +#else + 0, +#endif + 0, 0, 0, 0); + + return sbi_err_map_xen_errno(ret.error); +} + +int (* __ro_after_init sbi_set_timer)(uint64_t stime_value) =3D sbi_set_ti= mer_v01; + int sbi_remote_sfence_vma(const cpumask_t *cpu_mask, vaddr_t start, size_t size) { @@ -324,7 +356,13 @@ int __init sbi_init(void) if ( sbi_probe_extension(SBI_EXT_RFENCE) > 0 ) { sbi_rfence =3D sbi_rfence_v02; - printk("SBI v0.2 RFENCE extension detected\n"); + dprintk(XENLOG_INFO, "SBI v0.2 RFENCE extension detected\n"); + } + + if ( sbi_probe_extension(SBI_EXT_TIME) > 0 ) + { + sbi_set_timer =3D sbi_set_timer_v02; + dprintk(XENLOG_INFO, "SBI v0.2 TIME extension detected\n"); } } else --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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 From nobody Tue Mar 3 03:02:46 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=1771604392; cv=none; d=zohomail.com; s=zohoarc; b=buJpIrcUPuw2wXd5rCoFdues8Cymoct9DKXMbQDZW6T8rj7Rd77SjBVA0Y2JfcO52ifSg3JR/nIEwCuDDP5tT4igYd8VzafVygdhz5c+YVUjpIDG2HaMyE0Ag+67A5yZobaLmdxGOVeWBCDJvrCWhGhRs72ycr3OZ6PdSzZLEk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604392; 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=5GY4TsUHAUh5mXYz+TDKp1K01nWPWnDSPZpe5v/E8oY=; b=RMJTB/T5/Ibcypj/Z7GNShYzlGX81UiaHxpa5sMVcfqOYfnXHA1KEHzphm5bE+2KnuHHMv6lMKdgSRLG5K8szDMQ/Ii51QFLgOnHllxFl0o03irG/oFpg7hDLbDE01lycQvPZuUwKPC4zGFxJ7lkEOkWNeLeo5VtbCPODRZsT9Y= 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 1771604392071222.35370084149383; Fri, 20 Feb 2026 08:19:52 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237346.1539787 (Exim 4.92) (envelope-from ) id 1vtTE7-0002zD-KV; Fri, 20 Feb 2026 16:19:35 +0000 Received: by outflank-mailman (output) from mailman id 1237346.1539787; 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 1vtTE7-0002y2-4O; Fri, 20 Feb 2026 16:19:35 +0000 Received: by outflank-mailman (input) for mailman id 1237346; 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-OL for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:33 +0000 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [2a00:1450:4864:20::330]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f079f1ce-0e77-11f1-b164-2bf370ae4941; Fri, 20 Feb 2026 17:19:32 +0100 (CET) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-483770e0b25so23237935e9.0 for ; Fri, 20 Feb 2026 08:19:32 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:31 -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: f079f1ce-0e77-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604372; x=1772209172; 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=5GY4TsUHAUh5mXYz+TDKp1K01nWPWnDSPZpe5v/E8oY=; b=LlE+dgt4BZzmbfveMoQNfmHAMAV2vnqMHXOL7k2C6bd5M89vzB4FQePgenAJadewhq aBntHrWVF1uNxkgxO6rFGWkXtpc6hP0gbn54jWlV2w6+ZWEZLLMphqN+VcOYSGEfHOZh 6mLnQa7GTKJzCqE2InHL0/x8ycNk0CXjIE0+N0hopmTmvnpNUpfV6zp48EC2QgXQTmu+ X6a9R9akFpalQxlJtMdhKaRAM8FOs5/9mI1W/CanvXEYPC4d545bNbv/x7rCASErym9g +aAzx7JuPkC0cZOjgmYbSwMlKszmhDIKQvW+9gIzXB9nkOfvsAWUa270xPr8zefQbD06 qHLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604372; x=1772209172; 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=5GY4TsUHAUh5mXYz+TDKp1K01nWPWnDSPZpe5v/E8oY=; b=ZCm9UrF99y3tuZQ9+ZkQ+U9+o2wJFnceIhg+zs3IoJ0m2tD5VDhMNCjT+bwli56lpX 1ZAhog9q+xVsOKJ1it1GOx0uAE3Dz4DJcWJILbpqWGNyBOkEjxbVL/Sgd7cknYex9KfH g8jHBt05RKNf2Hwo2fFAmHOnh7/Z7g7uALu8DX2Re0w+0FE95YRSfxGfdTrj+j0QrSfK SDISc3AAsPUckHMLpcSmuIpQZ7PHmpqWwU95X2vb0T5qZx+2NPXtbnKpkcjYGYSLLY1O lJTiyXVvKe2/0O4T73LTWGW+LXQMdItPKA+rOL6+Fwsrm8ThprboUyJ0c4f5eBI371EA 34Wg== X-Gm-Message-State: AOJu0YygTMeVQrNYYE/IFENnK1Yf/pDjda5iBErKMBMvn2eInFtDQVZM 6bzNw1QNfqVWRCkSh4/9pzwQK4sxmLqNRKTlytWUpG4K1QIk20MCvaHqTDLM2Q== X-Gm-Gg: AZuq6aK09UFcT0o71iFCftqyaKz3wOGiwk+hoPZ0gAdnmJcKhlltmctXVB+aMlD8wIu 11JSFei/BgGUVKV0IDaQei7WyMdPSlafM23PJKoyAlfSA4iAI7OO8FaoV0Khkd0kdIrHqLHd3jC lQlJXi4Mq9TEMv3iDQ438fNRdFCseIYq2gsXv+PQOkIqcD/Fl6jHZkSQdjTaFhq9fox++Zz2MjN mMzwfRCO737lJG/rsAmNAqahIG3k8U6rMsKL7adQzzh4BGwrR+dEsEs+LVgmzFzOzCzpU2zy5ur 5xa+tRYn2Zmdu6KngGcbE+p+YtYOadTIBEXpVJBsB9Zp6BdjuCdr3lt4dtcfigRLz8bRBkcrOaQ XdpJqq2WKxTMseEbsjqyPTLNrhVOaBkIpeRVGTP5MH9dht52AftVuZbKajW+t2Huk+ooIbFfON/ +ORBf7M0BGtGDxgfXiWmy46WHeEINgD3j9mky/mk3ajlA966TMgXDhVmCOxCW4Q2oYew== X-Received: by 2002:a05:600c:820a:b0:483:709e:f22d with SMTP id 5b1f17b1804b1-483a96379c1mr561955e9.27.1771604371507; Fri, 20 Feb 2026 08:19:31 -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 12/14] xen/riscv: handle hypervisor timer interrupts Date: Fri, 20 Feb 2026 17:19:07 +0100 Message-ID: <9a17019c5668935afba1f7d932a3ad8a413e2919.1771590794.git.oleksii.kurochko@gmail.com> 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: 1771604392917158500 Content-Type: text/plain; charset="utf-8" Introduce timer_interrupt() to process IRQ_S_TIMER interrupts. The handler disables further timer interrupts by clearing SIE.STIE and raises TIMER_SOFTIRQ so the generic timer subsystem can perform its processing. Update do_trap() to dispatch IRQ_S_TIMER to this new handler. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v4-v5: - Nothing changed. Only rebase. --- Changes in v3: - add Acked-by: Jan Beulich . --- Changes in v2: - Drop cause argument of timer_interrupt() as it isn't used inside the function and anyway it is pretty clear what is the cause inside timer_interrupt(). --- xen/arch/riscv/traps.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index 244264c92a79..326f2be62823 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 #include #include @@ -180,6 +181,15 @@ static void check_for_pcpu_work(void) p2m_handle_vmenter(); } =20 +static void timer_interrupt(void) +{ + /* Disable the timer to avoid more interrupts */ + csr_clear(CSR_SIE, BIT(IRQ_S_TIMER, UL)); + + /* Signal the generic timer code to do its work */ + raise_softirq(TIMER_SOFTIRQ); +} + void do_trap(struct cpu_user_regs *cpu_regs) { register_t pc =3D cpu_regs->sepc; @@ -221,6 +231,10 @@ void do_trap(struct cpu_user_regs *cpu_regs) intc_handle_external_irqs(cpu_regs); break; =20 + case IRQ_S_TIMER: + timer_interrupt(); + break; + default: intr_handled =3D false; break; --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604397; cv=none; d=zohomail.com; s=zohoarc; b=HoZG0ZdJZIoM98PB2lOfVJeSuge3kv94PrSUDzOLlXxU3z71Yr1YlFxfEcC+QjZMEEWZLtzgsW87ABoqpqMyWH02F2ippx3V0W1WiKR+uQo02MHmpu18ZiZhqDveeAbAvteUjooU98lBZtiZg4XqqmQ8Obrr/4eR+lfGUCrJEPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604397; 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=YUjjpoIwoAsmqBjVZlQVP03PbDqZ+GKG9bzz4eYhrug=; b=gEnAfMpZ/wSJ06kx+Bpn6fPhTdX5fmzHvnUiTuSpf4bS+dEWUpxDtULaKPjeulRqqYMkrA6UVllymBS0+p+IgUZ4v2Zvn6NDKC6+FA+ukSK6jwCxBTxTsrdj1m+OD7K1i5R7bh18HQVwSUUUVLqR5W3SwacX0Fw93olNOjwRjlU= 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 1771604397974483.79826218321455; Fri, 20 Feb 2026 08:19:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237348.1539803 (Exim 4.92) (envelope-from ) id 1vtTE9-0003YD-So; Fri, 20 Feb 2026 16:19:37 +0000 Received: by outflank-mailman (output) from mailman id 1237348.1539803; Fri, 20 Feb 2026 16:19:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTE9-0003X7-FS; Fri, 20 Feb 2026 16:19:37 +0000 Received: by outflank-mailman (input) for mailman id 1237348; Fri, 20 Feb 2026 16:19:35 +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 1vtTE6-0000QF-Oh for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:34 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f0f95195-0e77-11f1-b164-2bf370ae4941; Fri, 20 Feb 2026 17:19:33 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4836d4c26d3so21053935e9.2 for ; Fri, 20 Feb 2026 08:19:33 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:32 -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: f0f95195-0e77-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604372; x=1772209172; 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=YUjjpoIwoAsmqBjVZlQVP03PbDqZ+GKG9bzz4eYhrug=; b=TldlrxjB5beTKAEK6SWpnuXbM74lwB57UfIlKBVh4+Q3yR2/p0YdaABAF7XT+hNiiH J1G7rWSjaaQPRRfJz/JwfAYQWUt5iHTQ1E2XJMS90axUWonjQa71Fr2pjjxrZYtlQSyR PBav+a6TrSiTE85vm4gcf8ExtWA8FSYPiFeYlUcrmrR7i+2ad69z9SnaJyoDeprdL47Z 3u111rgOoT7jSthmiMJqc6IgfaQKjdQ4FZDQYWnOwePnY9ArlJMXPxE7+FJmEvh5GyOd C+8YkuNkwUl0SXIdbjEuvRKrxE1L+mbMVgW+cVtDznD2+8W/l94QjlxR5jiDqZml0011 Smiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604372; x=1772209172; 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=YUjjpoIwoAsmqBjVZlQVP03PbDqZ+GKG9bzz4eYhrug=; b=r0hWaAfNjqdC7b2USi/j3HQqudE3AcIfIzN82fMPYTfTkp14l3lYxdzufW0AY0orXv Im2SS/HN9ZdjTNyD5jTVzUxyvj1LGX69utU4fqwmhk72wRupizsuiby10ljE92uau7ul CDz3nPFmptBe9grrCIhd79seQWvlG7Udz9aUx3lcsgl5ps+hkgcyOkDwm864Ob6CZTAr HnSU+WU6L6t18vR8Jb8bG0NHqy0QDZ6/ISCQP4Rdwq2mZAMhXKXi5Zy9lX4j4woDzgIm HvWnPIVE9vnDIr9JHv/LKOnmCBht8gxvba/VQLx1tWEriC/hR/qAFsKziuVhfRl197Us 3+xQ== X-Gm-Message-State: AOJu0YyRP/SolNo+Y3T5m16oRv/qSEFQXnzmOz49v+mrooh7mmy/E2iY F+WoejNoMGV/b9amtY3ksg9bIvbudCckuvtbP4+n6DF+XilYE/pzO0YPjk0DgA== X-Gm-Gg: AZuq6aKUw+bWDaO7b9ZOMsJrxiU66tu2xqZHkBhDc9jq9T6E/PaIcMHpPciYPebRt8H BMr3p7XXB2DAJj67XG4wf+Txv36zMpvDaif8Rr5Sg686z18lwQlUnySNQKJ6qsun5X3nsvZDCBs /EAJ9YJE0Xne3XZQT47Y1QQgwoADX0BZh5j10i6kAVkYzCHgB5P4PiUOl9R5jqhHAwqQd9If4fw IgCc1s98PQzaMnAJ4jMDnlXUEL+DfQOX49lCsBou2Uleyo1QKLro258ehYrLsmclZ3A2OMDWc80 tA0J2O4pu5uhV1fKVRELpt2aKUPSemoee3e5J9GTif0fRdAbGFd0+KyUHigq4/+Xb7uKlWDHFa6 /leMkGNWhQWOWZ5DPbiquWE1Ic/Gm7QkQrLZm8OuKR9V619O4mPGAhe5yjAUOUvFGd5WgSoTFHZ gUTdPqv4tWzGVTg6/WuNAk7nz2t/jGXtLsedX4MONsv51EVNjjvbPHm2Su4opBEAUk8C4bLh62p sch X-Received: by 2002:a05:600c:4505:b0:477:7b16:5fb1 with SMTP id 5b1f17b1804b1-483a95a854amr1728915e9.7.1771604372512; Fri, 20 Feb 2026 08:19:32 -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 13/14] xen/riscv: init tasklet subsystem Date: Fri, 20 Feb 2026 17:19:08 +0100 Message-ID: <0119532189c85a4db110e5772a263aec22d9f3db.1771590794.git.oleksii.kurochko@gmail.com> 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: 1771604398680154100 Content-Type: text/plain; charset="utf-8" As the tasklet subsystem is now initialized, it is necessary to implement sync_local_execstate(), since it is invoked when something calls tasklet_softirq_action(), which is registered in tasklet_subsys_init(). Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v5: - It was something wrong with prev. rebase. So fix that and move removing of sync_local_execstate() and sync_vcpu_execstate() to the next patch. --- Changes in v4: - Nothing changed. Only rebase. --- Changes in v3: - add Acked-by: Jan Beulich . --- Changes in v2: - Update the commit message. - Move implementation of sync_vcpu_execstate() to separate commit as it doesn't connect to tasklet subsystem. --- xen/arch/riscv/setup.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index bca6ca09eddd..cae49bb29626 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -133,6 +134,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, panic("Booting using ACPI isn't supported\n"); } =20 + tasklet_subsys_init(); + init_IRQ(); =20 riscv_fill_hwcap(); --=20 2.53.0 From nobody Tue Mar 3 03:02:46 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=1771604868; cv=none; d=zohomail.com; s=zohoarc; b=TpnqHtod7KohM2BfrnxaPW8y+1LJnniBpG/Ffx2tdyvcMfklYGFbPfeUm7gpd8RujjzqTdb9SjugJdwQ0g595FRAVQYDwTnum6GuERRsxOH89lxGEp81tedibdHG6vSk7cqx0nxGEraGKw2nP1n3cqFo82eIs9OpsEB2h0mrBqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771604868; 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=mxX3OIZ6fZxPE5LWGOGy7jniho2pldOrYX/WsQ7ZseY=; b=KDlpO55O6FE6dCCQ7h7yzlKEZ3kLxvUwTxrWHK5KZCkLy+sINKnvDkDWVGQzYCY86U3HSoMYKu8tvq2UomkaoE0kwu2WD4zQ+UMqDEcbaJGXQL7sBlNa+A/UGFTR09P488Evqs9wuTAatDneEPf3pdM79GlYQajSq9cEASUgzt8= 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 1771604868461597.7377939032135; Fri, 20 Feb 2026 08:27:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1237427.1539819 (Exim 4.92) (envelope-from ) id 1vtTLm-0000Cd-LR; Fri, 20 Feb 2026 16:27:30 +0000 Received: by outflank-mailman (output) from mailman id 1237427.1539819; Fri, 20 Feb 2026 16:27:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTLm-0000CV-HG; Fri, 20 Feb 2026 16:27:30 +0000 Received: by outflank-mailman (input) for mailman id 1237427; Fri, 20 Feb 2026 16:27:29 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vtTE8-0000Q4-60 for xen-devel@lists.xenproject.org; Fri, 20 Feb 2026 16:19:36 +0000 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [2a00:1450:4864:20::42f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f19f704f-0e77-11f1-9ccf-f158ae23cfc8; Fri, 20 Feb 2026 17:19:34 +0100 (CET) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-436356740e6so2400953f8f.2 for ; Fri, 20 Feb 2026 08:19:34 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 08:19:33 -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: f19f704f-0e77-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771604374; x=1772209174; 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=mxX3OIZ6fZxPE5LWGOGy7jniho2pldOrYX/WsQ7ZseY=; b=aQ+mBjmditTabdtTiLen9Nn1Q5/ciZQezC6JmoZfKBlC0/4Z/Zjjig+CAh0ZddyTTM 76NQrtQa/gfUSq9r9TUQZZmK5pUuUhWzlZZrWmBpgYb7Szsib6/70rAuklOuuzv4Ad2G 0u/s0bYGsa7axWWJJC7aUGD67R5yRiBZpUoJlfzzG6uAlZTGFFJ2CmTzjQI7z7LQexff 63i0bzXWedx5peu2BOnXCxjkjeVDq8gaNVKyz+PU0hObRR12CyFN9xcFELZKFucbAISA uTb3gSNXBN6Iga6ivTZCtRjYsbdRaYIbbpuh06gll1c6pWhPgSKPBhpRvKXIYV9m5++P tHsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771604374; x=1772209174; 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=mxX3OIZ6fZxPE5LWGOGy7jniho2pldOrYX/WsQ7ZseY=; b=r5UiTyi4JQZW/eBMlFVZoFE56gNLpoUmk/Iqq6psJfArJnEoh6w5Pk44XO3n/oNlA5 jdcJh2HjDsSd7frqkPPSSz7IdleqWFOOQoXSNenE8Ahccl0pRn2IHog7B0VQGNeNJ724 bBJQpmHtJz+zdbLC8QcewlGWNuMKPoPJr2pkN3Cn4OmCc8SkFZGODvsyPC43HNuSlbHS WHvZLH3aq2FF6+dYmVUsYZy03/QZMC9jV2ZCtiqm9r4dcnv7yi8M/TnpAVKnZb9ABwyr vXTPN9eQ/ImOsZQGW2IVyV4oMKixN1Qc6YZ859TTrdrC3OcAu58eY94P7M3d9vseqWYr TKGA== X-Gm-Message-State: AOJu0Yzqp+mN5mGxgyNirx5QnmtkZMdWtb+/hvFj3jxwtpHP0zIWLPrn 7IvHHAaDJkXe93mErKYHG9PICCkXr95O0dcmasW2GvJy6R6flD2PcZBBQ1Jq0A== X-Gm-Gg: AZuq6aKa4KNQu3wOGshxZKQkwuVZyLSOayqLro28fbXp/zjJxSo5FlPFFQUvRkzA+ji Fx6GV1uvU18RJrgu+TwLIeyOe2NzxpCeChBRKwhqWM4QyvwOhWoeP7ja81K+PuO+bRn7YRkF0gA TduAj1f0gOQdldsWw3q8+ReEvY+532EEJuBAjG5XcB2a5cHav4la5Pg1NcKCSh8JrDuBLTrYigW lurjcWBel45VG/NxQDxkXgHr9fGq9P0IinSuUuy0FUfed6t83fAEK1n/itwD4wI2R0QZdBqiVEI 4ITzTOBiof9GV6MwWTmGy6pUP/1eLYJAoRpvDk8+sok7WAm5ij+u74EYGHPb02vPliCzRw4dQsb BF198VPADKPrBWJFp5QXP9mqAxbDgHuB2opyRL4JVndK/TcGJJnm5YMa9Oqy2McKdMsePNsZONs 8JISIvQcedqa6VN6YV/zUjJWsquHqsDnG+2YxSxBMxDPsq+bArjE/eZXkG/BcSO199DOItVw== X-Received: by 2002:a5d:5888:0:b0:436:1517:aeca with SMTP id ffacd0b85a97d-4396f157d2amr785935f8f.15.1771604373504; Fri, 20 Feb 2026 08:19:33 -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 14/14] xen/riscv: implement sync_vcpu_execstate() Date: Fri, 20 Feb 2026 17:19:09 +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: 1771604869917154101 Content-Type: text/plain; charset="utf-8" The scheduler may call this function to force synchronization of given vCPU's state. RISC-V does not support lazy context switching, so nothing is done in sync_vcpu_execstate() and sync_local_execstate(). Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v5: - It was something wrong with prev. rebase. Drop stubs for sync_local_execstate() and sync_vcpu_execstate() in this patch. --- Changes in v4: - Drop footer as [PATCH] sched: move vCPU exec state barriers is merged to upstream/staging. - Add Acked-by: Jan Beulich . --- Changes in v3: - Align sync_vcpu_execstate() with patch: [PATCH] sched: move vCPU exec state barriers --- Changes in v2: - New patch. --- xen/arch/riscv/domain.c | 10 ++++++++++ xen/arch/riscv/stubs.c | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index fb5c21078172..f3b22d05071d 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -265,6 +265,16 @@ void vcpu_kick(struct vcpu *v) } } =20 +void sync_local_execstate(void) +{ + /* Nothing to do -- no lazy switching */ +} + +void sync_vcpu_execstate(struct vcpu *v) +{ + /* Nothing to do -- no lazy switching */ +} + static void __init __maybe_unused build_assertions(void) { /* diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index 2f3a0ce76af9..acbb5b9123ea 100644 --- a/xen/arch/riscv/stubs.c +++ b/xen/arch/riscv/stubs.c @@ -91,16 +91,6 @@ void continue_running(struct vcpu *same) BUG_ON("unimplemented"); } =20 -void sync_local_execstate(void) -{ - BUG_ON("unimplemented"); -} - -void sync_vcpu_execstate(struct vcpu *v) -{ - BUG_ON("unimplemented"); -} - void startup_cpu_idle_loop(void) { BUG_ON("unimplemented"); --=20 2.53.0