From nobody Thu Jan 8 12:32:50 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; 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=1766595858; cv=none; d=zohomail.com; s=zohoarc; b=QAzwMSbm88Ff8FzAXBAXiecJ5bOvjxZWg3zxAevDSz6LfQFp+spbsRjM7imArNkaLnTLqxYh1DHY0ijrh3Lp7vj38NY0+WRcBxvnGVq7HbwFdhjYGjMnw6sxv56yFDsoYGDaWXbEUafSoXuGGHEw+w48/krzXKH0GXvn2Mhf/VY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595858; 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=wpMnoBhXlHEbQcv+4CcUZ/GWflidq/CRvs1qhabX/PA=; b=Usm2DNtBtYm4sqEGC+/Q4ZRDUkjx2JUE6MmhKwhafgdmUnI3FtR23LASSZQTV4FYBA5Ns0fouKsTWrIBmTKjwIFKYy3zfDvQwzkyk+7rOpDAtdXVJLm+PkgItelwZA8bzLRDyQpCRcJmIpr+zrNUyznqIic+XXA0HsKS8AIISDc= 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 1766595858964256.76574499859566; Wed, 24 Dec 2025 09:04:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192948.1511955 (Exim 4.92) (envelope-from ) id 1vYSGy-0003Cn-TW; Wed, 24 Dec 2025 17:03:40 +0000 Received: by outflank-mailman (output) from mailman id 1192948.1511955; Wed, 24 Dec 2025 17:03:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSGy-0003Cg-Ql; Wed, 24 Dec 2025 17:03:40 +0000 Received: by outflank-mailman (input) for mailman id 1192948; Wed, 24 Dec 2025 17:03:39 +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 1vYSGw-0003CV-UR for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:39 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7d646a97-e0ea-11f0-b15c-2bf370ae4941; Wed, 24 Dec 2025 18:03:38 +0100 (CET) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-b734fcbf1e3so1217307366b.3 for ; Wed, 24 Dec 2025 09:03:38 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:36 -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: 7d646a97-e0ea-11f0-b15c-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595817; x=1767200617; 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=wpMnoBhXlHEbQcv+4CcUZ/GWflidq/CRvs1qhabX/PA=; b=G9pcf8rlJ11GmoH/zo4K3aolXbeoCsyXum94q4bVwUbKf0QT5vjesdVZUjjg0isMZE TDJsGkKmA4qrG1mxMogeVEN10wJqks8CnSJFhvQzpYh1WFbDZgst2KqDDTBxjF3F9tan 62VA/L7m3D9mZbaYU2A/6Oe/Wcb1W5tUcuHIjqMmPJu/UrhPDw/jxl5OsUfWIpkDUgft RfJ54hdhHbsQ4y1CJ6sRmR0aQKwXdkvWuJDVZDfq931p9T1iabOXLwzskzBIPgGU8gYk PlM2acAO3mrJb9cJ+yI79QYDTCgmZuX58QXaoBjciBgW0cDlfgH1A6reYOHZVZEcbXa5 qZOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595817; x=1767200617; 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=wpMnoBhXlHEbQcv+4CcUZ/GWflidq/CRvs1qhabX/PA=; b=VB7wog8KxkkodcztIlpg3sMV8M1F+w5GrYANATkHqRNhet4gyGbW58EXQ/9Nx6p0sg p8kghPCCn23RFXW6pUoDUJOj97qrl61Q58HhC26gBIw2+yQXdwR6j+vHWYUGqxaJkwze 5/AICg9h+bOHljtH3CEuxYsoWlFLY5SiiuR3ic27InGpwRPO67ZVzpOZ6oe/pMqqzD48 DGF8QZMCoI+cv9jCj9vHMWhSaEo2wKQc3FHLyuSIeTsBP3GYTXoD2oB0WWlG5eGuHNvy GQ/BphQHzgvb6R4ZEX1/7Qu59gO/7b+0PDbuuC7OIpoOSKoRgbo/EoF0fpghoXW7e2nR Vb+A== X-Gm-Message-State: AOJu0YxCRrr3SXAN9V2Q13yfF8yWbdBDjj60GV9YPNxUzTvWItSxntrX Kg2s/jfNnXW5htHrGSs/WkR1h0GEQsoWsHWIvthMTOY/D3iZiLEZ/374nMGEfA== X-Gm-Gg: AY/fxX5QqjLhE0cyJZ9v5CY4t04PXMwbhHMIx/72QfXAzYQEkHODPr9QIdJZEBdk8kY TnrRG3Eu0T/fkydAwf3/UDOoAUJIzjXPq5uqQF75TPgIqu2zud0v683n85kri/jvDA0vrkaYae7 uX1IVxaGB2xm0sWnx/g2uLddXdEuLfUa5h60kp/RKH4tii+NQ1WwY5RkAppoTcj/bUDXilcR8pq Kwbcos58yohcGzbD1DpeuLvMG6tUDFQRUQWOqaEY6dJsSHLX44rWcVbkh48zQ9NDsRTPbk4jfIq S2j7HjEJEa7PmRyLVAr+gz62Puprh6Adb4yXCQoAbllUM4Bk8KcaFccXFy0ab7sMCGWVxoOvMC0 m94GsDQ8XOj+a8pvVnFcdW0tq7RDYykuJwfbKgRzQ818Vgx7xC+HjuuN+A6kf5ckI91MmGGH59c hpyeh6dwehc+nxnzpuszA3rqDhSTYyIelt4omicjhRghm1jucicorYHHY= X-Google-Smtp-Source: AGHT+IFGQXiCGFZ8YkznAaepnlm3r06T108zPJKrH4/O/E2AgvWDQNvAco8SXKUUx+l0Bwryvt9Q1w== X-Received: by 2002:a17:907:7245:b0:b83:13ee:5875 with SMTP id a640c23a62f3a-b8313ee5957mr212455666b.50.1766595817168; Wed, 24 Dec 2025 09:03:37 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 01/15] xen/riscv: introduce struct arch_vcpu Date: Wed, 24 Dec 2025 18:03:14 +0100 Message-ID: <3b531dff3755da010664111cf7d936ccba7c1f5d.1766595589.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595859669158500 Content-Type: text/plain; charset="utf-8" Introduce structure with VCPU's registers which describes its state. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/domain.h | 58 ++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/a= sm/domain.h index 316e7c6c8448..639cafdade99 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -22,9 +22,63 @@ struct hvm_domain struct arch_vcpu_io { }; =20 -struct arch_vcpu { +struct arch_vcpu +{ struct vcpu_vmid vmid; -}; + + /* Xen's state: Callee-saved registers and tp, gp, ra */ + struct + { + register_t s0; + register_t s1; + register_t s2; + register_t s3; + register_t s4; + register_t s5; + register_t s6; + register_t s7; + register_t s8; + register_t s9; + register_t s10; + register_t s11; + + register_t sp; + register_t gp; + + /* ra is used to jump to guest when creating new vcpu */ + register_t ra; + } xen_saved_context; + + /* CSRs */ + register_t hstatus; + register_t hedeleg; + register_t hideleg; + register_t hvip; + register_t hip; + register_t hie; + register_t hgeie; + register_t henvcfg; + register_t hcounteren; + register_t htimedelta; + register_t htval; + register_t htinst; + register_t hstateen0; +#ifdef CONFIG_RISCV_32 + register_t henvcfgh; + register_t htimedeltah; +#endif + + /* VCSRs */ + register_t vsstatus; + register_t vsip; + register_t vsie; + register_t vstvec; + register_t vsscratch; + register_t vscause; + register_t vstval; + register_t vsatp; + register_t vsepc; +} __cacheline_aligned; =20 struct paging_domain { spinlock_t lock; --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595852; cv=none; d=zohomail.com; s=zohoarc; b=TjwP0KsDIvcVko5q1sFOj5NEcofU6Ww+ofhbth5TWL1fpoAJIlhCkIf5ka8kQtgT0BxW/dbcMLdmOHc6N2ig9HyqYtfoS9zxe6hMJqQCApBIpkmp7CxxrP07rw+RZb/euZp7DnNSM3p1jw0lkht7HlGaWRylydCpZNvkO2xCVH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595852; 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=Z+CX4PM1TSlKhl6ge6jDhJJvdmvI/i39oU9Gt3HuqSc=; b=IlOyxTz7BjgVTU0hy1d1sB3cNEzEqCQLLNObF9mBIxekxodxfW6v3Oin9gWFLVcPKkjhZqH435/n3cPHQ8518y3Ag7NKU1KxXPKK0OW35Ivea5MJPHpvBdHhWxCZR8Cse1YfXjJ88X6pwS51nhBcAESLqnMIksW2v6Kuinlauys= 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 1766595852828160.30969125705076; Wed, 24 Dec 2025 09:04:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192949.1511963 (Exim 4.92) (envelope-from ) id 1vYSGz-0003Fz-7C; Wed, 24 Dec 2025 17:03:41 +0000 Received: by outflank-mailman (output) from mailman id 1192949.1511963; Wed, 24 Dec 2025 17:03:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSGz-0003Fp-29; Wed, 24 Dec 2025 17:03:41 +0000 Received: by outflank-mailman (input) for mailman id 1192949; Wed, 24 Dec 2025 17:03:40 +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 1vYSGx-0003CV-VW for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:39 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7e170a83-e0ea-11f0-b15c-2bf370ae4941; Wed, 24 Dec 2025 18:03:39 +0100 (CET) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-64baaa754c6so6082053a12.3 for ; Wed, 24 Dec 2025 09:03:39 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:37 -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: 7e170a83-e0ea-11f0-b15c-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595818; x=1767200618; 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=Z+CX4PM1TSlKhl6ge6jDhJJvdmvI/i39oU9Gt3HuqSc=; b=VAtxeBZmCjadwaNlu88IyJOVNNWkT8e3Hg1ZbbDjKwldjoPqMNz79K/BY3Heeiwyvt QQz1QfFlDXGIGzO4Z9wp/9yWxFu3LQVdkq8JL5AnEImtaFYiEAUzG/y4FPKcc6u1wCJ+ n6SFdVc2vsldKVlho1AUyNI2b5YtJIbh/80BtXrFLu3Eu7U3LWt1DCfJL0RQGyeLHUfd nSMP93pMUYPvSbJFAk47wjokOFAX+O+EfxiVMEDWv9/F2JQUtb6RjP9pjKANOrSX3biF rAc9BsSbaZk+4p+5Uet/3ZzbL2vtVI9nw0arFX01OLw8SUxKj8mzVA5z/7pxXPZWHDeO cHUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595818; x=1767200618; 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=Z+CX4PM1TSlKhl6ge6jDhJJvdmvI/i39oU9Gt3HuqSc=; b=qyNb0M3e/Rw4ee2kmkocChWB0eaQOwl863/wxhPDPO3A9L02fa/Sqo0ZhOTdZDnnZR eqmKhMkYYgjmqLTjzjH9Vhvu1g1oFmxgtPLVLUftdla2ensXvrcbxM50ANucWnYQGsd0 /5GjtAyz7naPoGBKJ12CVoXFBn3pWukwKp4QndmRRa5f0hNCrGR6Gdqfi4AJI/DcgjDk k3fZ/2D6LNJ/Jj5v6M3k87xVjcnIHPQ0zmM8UPEFHhrRMSm9S4QwHldJTAK3zj0WFkPL HOu36VFPw9YXltbZAhwOiv+Aw9U5bFpXdMXD+rz3wtMT6CALPo2UH+jKWzbfSUJ4WR0G 7hPg== X-Gm-Message-State: AOJu0YxK7yq9ku4qB6+IGMBR/x6Q8xjLh+pb9a/PTNA/dflCUu9Udfr6 yuwhi94fiK54okVZ8spZaDsp7pSjZifAIJ7nXMAD2eiWF+v4ussT9xvmHSK/FQ== X-Gm-Gg: AY/fxX5TRVpBJROm5sWpj+trU/WNSShBuASTFtY6C3TXTcP+xMzT851b6L7xuLmYcy4 vdJacovaGKr5tVVq69Zybauu2C2XNPKika/Cq6vz+3WVwfBvkGAtSAL9IOMin3X+QTFNNsl2Nma qjxeddRdMkD/2ZfoqB265W2rqieuicKPj/Z5jm0ZwKG4BEayaA0rJinoDCwGYPXnlT1fTnX6huC SbhG10gSd5Sj3K0zpUdmMabav/96DxaxThAFPqWCdLyCcqXM6qtifY3MXwR3L0pgT1qtw5RLKtt qo8Nuu++ceAGQhFW0KXKHIRG1Vf0XuS7s5ojvyBNV2g6JHOr/FLUFGH5Cod2FwJQpPQij6FoPeg CP5zfI4R2/VrAO/Bncc7kcIzf0KCgPdPAXLRaLZrRA4vbmZt9VZHChuPT3rNhK0yB6o8dejf7S4 ejcN2zklxUV/BjYyTrYWeUi62w4ZW0JFCOqSPFt0adUsv22pSwyvNWFa0= X-Google-Smtp-Source: AGHT+IH4u2/iCr5LDRPjPTjUt2EKuw6McarNGkOHJXK+wbRNb2InsTPLqP39yJFiwV7dZr3TMBqKDA== X-Received: by 2002:a17:906:308a:b0:b83:15cb:d491 with SMTP id a640c23a62f3a-b8315cc015bmr165100066b.53.1766595818113; Wed, 24 Dec 2025 09:03:38 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 02/15] xen/riscv: implement arch_vcpu_{create,destroy}() Date: Wed, 24 Dec 2025 18:03:15 +0100 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595853700158500 Content-Type: text/plain; charset="utf-8" Introduce architecture-specific functions to create and destroy VCPUs. Note that arch_vcpu_create() currently returns -EOPNOTSUPP, as the virtual timer and interrupt controller are not yet implemented. As part of this change, add continue_new_vcpu(), which will be used after the first context_switch() of a new vCPU. Since this functionality is not yet implemented, continue_new_vcpu() is currently provided as a stub. Update the STACK_SIZE definition and introduce STACK_ORDER (to align with other architectures) for allocating the vCPU stack. Introduce struct cpu_info, which will be allocated in arch_vcpu_create() and declare cpu_info inside arch_vcpu structure. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/domain.c | 56 ++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/config.h | 3 +- xen/arch/riscv/include/asm/current.h | 6 +++ xen/arch/riscv/include/asm/domain.h | 3 ++ xen/arch/riscv/stubs.c | 10 ----- 6 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 xen/arch/riscv/domain.c diff --git a/xen/arch/riscv/Makefile b/xen/arch/riscv/Makefile index 87c1148b0010..8863d4b15605 100644 --- a/xen/arch/riscv/Makefile +++ b/xen/arch/riscv/Makefile @@ -1,5 +1,6 @@ obj-y +=3D aplic.o obj-y +=3D cpufeature.o +obj-y +=3D domain.o obj-$(CONFIG_EARLY_PRINTK) +=3D early_printk.o obj-y +=3D entry.o obj-y +=3D imsic.o diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c new file mode 100644 index 000000000000..e5fda1af4ee9 --- /dev/null +++ b/xen/arch/riscv/domain.c @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include + +static void continue_new_vcpu(struct vcpu *prev) +{ + BUG_ON("unimplemented\n"); +} + +int arch_vcpu_create(struct vcpu *v) +{ + int rc =3D 0; + + BUILD_BUG_ON(sizeof(struct cpu_info) > STACK_SIZE); + + v->arch.stack =3D alloc_xenheap_pages(STACK_ORDER, MEMF_node(vcpu_to_n= ode(v))); + if ( !v->arch.stack ) + return -ENOMEM; + + v->arch.cpu_info =3D (struct cpu_info *)(v->arch.stack + + STACK_SIZE + - sizeof(struct cpu_info)); + memset(v->arch.cpu_info, 0, sizeof(*v->arch.cpu_info)); + + v->arch.xen_saved_context.sp =3D (register_t)v->arch.cpu_info; + v->arch.xen_saved_context.ra =3D (register_t)continue_new_vcpu; + + printk("Create vCPU with sp=3D%#lx, pc=3D%#lx, cpu_info(%#lx)\n", + v->arch.xen_saved_context.sp, v->arch.xen_saved_context.ra, + (unsigned long)v->arch.cpu_info); + + /* Idle VCPUs don't need the rest of this setup */ + if ( is_idle_vcpu(v) ) + return rc; + + /* + * As the vtimer and interrupt controller (IC) are not yet implemented, + * return an error. + * + * TODO: Drop this once the vtimer and IC are implemented. + */ + rc =3D -EOPNOTSUPP; + goto fail; + + return rc; + + fail: + arch_vcpu_destroy(v); + return rc; +} + +void arch_vcpu_destroy(struct vcpu *v) +{ + free_xenheap_pages(v->arch.stack, STACK_ORDER); +} diff --git a/xen/arch/riscv/include/asm/config.h b/xen/arch/riscv/include/a= sm/config.h index 1e08d3bf78be..86a95df018b5 100644 --- a/xen/arch/riscv/include/asm/config.h +++ b/xen/arch/riscv/include/asm/config.h @@ -143,7 +143,8 @@ =20 #define SMP_CACHE_BYTES (1 << 6) =20 -#define STACK_SIZE PAGE_SIZE +#define STACK_ORDER 3 +#define STACK_SIZE (PAGE_SIZE << STACK_ORDER) =20 #define IDENT_AREA_SIZE 64 =20 diff --git a/xen/arch/riscv/include/asm/current.h b/xen/arch/riscv/include/= asm/current.h index 0c3ea70c2ec8..58c9f1506b7c 100644 --- a/xen/arch/riscv/include/asm/current.h +++ b/xen/arch/riscv/include/asm/current.h @@ -21,6 +21,12 @@ struct pcpu_info { /* tp points to one of these */ extern struct pcpu_info pcpu_info[NR_CPUS]; =20 +/* Per-VCPU state that lives at the top of the stack */ +struct cpu_info { + /* This should be the first member. */ + struct cpu_user_regs guest_cpu_user_regs; +}; + #define set_processor_id(id) do { \ tp->processor_id =3D (id); \ } while (0) diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/a= sm/domain.h index 639cafdade99..a0ffbbc09c6f 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -49,6 +49,9 @@ struct arch_vcpu register_t ra; } xen_saved_context; =20 + struct cpu_info *cpu_info; + void *stack; + /* CSRs */ register_t hstatus; register_t hedeleg; diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index 164fc091b28a..eab826e8c3ae 100644 --- a/xen/arch/riscv/stubs.c +++ b/xen/arch/riscv/stubs.c @@ -126,16 +126,6 @@ void free_vcpu_struct(struct vcpu *v) BUG_ON("unimplemented"); } =20 -int arch_vcpu_create(struct vcpu *v) -{ - BUG_ON("unimplemented"); -} - -void arch_vcpu_destroy(struct vcpu *v) -{ - BUG_ON("unimplemented"); -} - void vcpu_switch_to_aarch64_mode(struct vcpu *v) { BUG_ON("unimplemented"); --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595858; cv=none; d=zohomail.com; s=zohoarc; b=RjyvK3jzXxl1FTUprgUR2bvwXFaI86g+1TKtd69Y7zmkrelBV1CEhjlHACc0ilkjOloXCeL0m3/jZ3QFvHgnKT5R3q00jGzo7lmbcLMwUVhIYf/5J3NHIMUNP/wJqj77eE9IZNFFPG9ZQTvzrrFphkFmf//ES1BRP8/4tU3eQww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595858; 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=eYGyfRUWi6/uVVhXroMlu9Z8bL0jkMCNXbGuPR68cNM=; b=bX4pKFFGW7hkZ1j5gWOgywqOlLhb9jvb+r87q5jv2sRePfv5w5gxYx6zXpZsdV5Gm3NzisOD1RSa5cwtss+ju1xJgmZaU6Q0UwRxeUaHW/gMB/3INzF+3WorLhE1N2k6ErheTYaZNp5Bx/g0AXOhTzPyUSC4Xl+8hoxFLyqyscQ= 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 1766595858127694.5764702480576; Wed, 24 Dec 2025 09:04:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192950.1511976 (Exim 4.92) (envelope-from ) id 1vYSH1-0003dq-CT; Wed, 24 Dec 2025 17:03:43 +0000 Received: by outflank-mailman (output) from mailman id 1192950.1511976; Wed, 24 Dec 2025 17:03:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSH1-0003dj-95; Wed, 24 Dec 2025 17:03:43 +0000 Received: by outflank-mailman (input) for mailman id 1192950; Wed, 24 Dec 2025 17:03:42 +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 1vYSH0-0003b7-9u for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:42 +0000 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [2a00:1450:4864:20::631]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7eb2c3c4-e0ea-11f0-9cce-f158ae23cfc8; Wed, 24 Dec 2025 18:03:40 +0100 (CET) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-b73a9592fb8so1149468466b.1 for ; Wed, 24 Dec 2025 09:03:40 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:38 -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: 7eb2c3c4-e0ea-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595819; x=1767200619; 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=eYGyfRUWi6/uVVhXroMlu9Z8bL0jkMCNXbGuPR68cNM=; b=A5WHCck/eKEbkoPJFUqyonrxJpV/dU0mZpjhYrHB9cuNLTU8I2OG6eFj6//lf5JJz6 DIJOZCs4bmSGP1UTV7LeMsSW1XEp5H+mPAB56NC1ksB74Cq4b1E3zyuMNrQgp5rzBD7b 2OtT22u2v/Wg3fHd58yw2+bD5E/8/YkIrs8H+m4IVu1dGOufyX0n4oxLCQ0sHzLkABip +gCbz6EhpfCkKghssBNEYfG6rnO7yAd9Foz7m2kEhFZ50YbVtuH32XaqcORWBWMpZU+k QU6TrdGDThLDauqe1EldA1ef94h3YdyT2s7JxW8FpyRdb+OYG3ExOW2sHunZuEhMG6LV nuIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595819; x=1767200619; 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=eYGyfRUWi6/uVVhXroMlu9Z8bL0jkMCNXbGuPR68cNM=; b=FMSY0ZIHsiDBJ4uUfy3nkbhkmAo9qkkGCjl6dRqSf4WlaainKZczRO8QV0xmqlmvUL jtwPvjbD0GWWb2c3qABXhIIt4eMBtoS4ElLUH8IQopYWj1knyen63Bb8/MrPS7yB3zDh k5ri6Qn1gWk94Ese3+hwXI3/4lx+p29dMAVNn7KhN/yZBByCyIiA6KHbQ/MSLjx8aDZp vKn/zfcrCTsfOt/uKFMv3bTOlAY1cVJX+6XIE9w3lkoUFv6g69TJmKuAAxBGq7/3QWX6 4Bjty4go2DpRFuuQXghNkMQBhrS9aitslUNDzRGNqJHCHj9uVZ5Bv5DG8pC9IJvHn9kd wE4w== X-Gm-Message-State: AOJu0YzGI+/sYFPcKzNt1S/y1mprhqU7pqDjQKzSzM64EYMMLfupv7fi parZV/JoSBEKPX4qXwZEkLVKVgOrBEIJvGtBjHg0WV2zaONtCV7p5GaWru7qQw== X-Gm-Gg: AY/fxX4jyE4749i5Lo7GfnHVjVyocMOKKtkC0cm9OjCINrAV7r/hI1n4WTFMbgMjwzr mFzUff0nWd894gz4MxRObk2kurp+fVioYvmqiUVQV52HBolVCT38eZueDqJ2rfNDIN6QFhVa5zv ftefum2dYbBFRA29DyuKKVmHjgAgb50DFhscrL8jWW/7gw35WB0gtztbqTlooOW4l13E+bqvBFc N3qOQOlBRGoWfggKKufMPd04FKp6NluDo0aV/0S45Nyt9zPvb+v2zdlzpWaRtbg17d5BLAuBIrc egDnx1V0p+AJt0dRjIvsEuTiggCFsCv5VRLfWfBGlfzD8FgLGo3mGje+Hs4iqHytB/rUwPUJMfr xBnZF9FdEYsQXvPg4DIKFqwkdSCN/D4fBPpXRjG1gA8jFce2tB9AfeXEShW//1IbGwQ6+P3XC6O LpdSpVil5evk9KwHLN5KEriqKpNAAJYfjWoQBeMbs7Blg0LSNNeyBAZ5bvxb+SQEDVJw== X-Google-Smtp-Source: AGHT+IGUckCWnWYOyuXH1beDmWPjVW2NAXJIsIoFW1Mos5tgYOhXiz+lRYQn8/fskyhC+hA73E/MOA== X-Received: by 2002:a17:907:602f:b0:b83:1341:b656 with SMTP id a640c23a62f3a-b831341b7f3mr161394466b.22.1766595819157; Wed, 24 Dec 2025 09:03:39 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 03/15] xen/riscv: implement vcpu_csr_init() Date: Wed, 24 Dec 2025 18:03:16 +0100 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595859747158500 Content-Type: text/plain; charset="utf-8" Implement function to initialize VCPU's CSR registers to delegate handling of some traps to VS-mode ( guest ), enable vstimecmp for VS-mode, and allow some AIA-related register (thier vs* copies ) for VS-mode. Add detection of Smstateen extension to properly initialize hstateen0 to allow guest to access AIA-added state. Add call of vcpu_csr_init() in arch_vcpu_create(). Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/cpufeature.c | 1 + xen/arch/riscv/domain.c | 63 +++++++++++++++++++++ xen/arch/riscv/include/asm/cpufeature.h | 1 + xen/arch/riscv/include/asm/riscv_encoding.h | 2 + 4 files changed, 67 insertions(+) diff --git a/xen/arch/riscv/cpufeature.c b/xen/arch/riscv/cpufeature.c index 02b68aeaa49f..03e27b037be0 100644 --- a/xen/arch/riscv/cpufeature.c +++ b/xen/arch/riscv/cpufeature.c @@ -137,6 +137,7 @@ const struct riscv_isa_ext_data __initconst riscv_isa_e= xt[] =3D { RISCV_ISA_EXT_DATA(zbb), RISCV_ISA_EXT_DATA(zbs), RISCV_ISA_EXT_DATA(smaia), + RISCV_ISA_EXT_DATA(smstateen), RISCV_ISA_EXT_DATA(ssaia), RISCV_ISA_EXT_DATA(svade), RISCV_ISA_EXT_DATA(svpbmt), diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index e5fda1af4ee9..44387d056546 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -3,6 +3,67 @@ #include #include =20 +#include +#include +#include + +static void vcpu_csr_init(struct vcpu *v) +{ + unsigned long hedeleg, hideleg, hstatus; + + hedeleg =3D 0; + hedeleg |=3D (1U << CAUSE_MISALIGNED_FETCH); + hedeleg |=3D (1U << CAUSE_FETCH_ACCESS); + hedeleg |=3D (1U << CAUSE_ILLEGAL_INSTRUCTION); + hedeleg |=3D (1U << CAUSE_MISALIGNED_LOAD); + hedeleg |=3D (1U << CAUSE_LOAD_ACCESS); + hedeleg |=3D (1U << CAUSE_MISALIGNED_STORE); + hedeleg |=3D (1U << CAUSE_STORE_ACCESS); + hedeleg |=3D (1U << CAUSE_BREAKPOINT); + hedeleg |=3D (1U << CAUSE_USER_ECALL); + hedeleg |=3D (1U << CAUSE_FETCH_PAGE_FAULT); + hedeleg |=3D (1U << CAUSE_LOAD_PAGE_FAULT); + hedeleg |=3D (1U << CAUSE_STORE_PAGE_FAULT); + v->arch.hedeleg =3D hedeleg; + + hstatus =3D HSTATUS_SPV | HSTATUS_SPVP; + v->arch.hstatus =3D hstatus; + + hideleg =3D MIP_VSTIP | MIP_VSEIP | MIP_VSSIP; + v->arch.hideleg =3D 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; + + if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_smstateen) ) + { + /* + * If the hypervisor extension is implemented, the same three bits= are + * defined also in hypervisor CSR hstateen0 but concern only the s= tate + * potentially accessible to a virtual machine executing in privil= ege + * modes VS and VU: + * bit 60 CSRs siselect and sireg (really vsiselect and vsire= g) + * bit 59 CSRs siph and sieh (RV32 only) and stopi (really vs= iph, + * vsieh, and vstopi) + * bit 58 all state of IMSIC guest interrupt files, including= 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 corresponding state= from + * VS or VU-mode raises a virtual instruction exception. + */ + v->arch.hstateen0 =3D SMSTATEEN0_AIA | SMSTATEEN0_IMSIC | SMSTATEE= N0_SVSLCT; + + /* Allow guest to access CSR_ENVCFG */ + v->arch.hstateen0 |=3D SMSTATEEN0_HSENVCFG; + } +} + static void continue_new_vcpu(struct vcpu *prev) { BUG_ON("unimplemented\n"); @@ -30,6 +91,8 @@ int arch_vcpu_create(struct vcpu *v) v->arch.xen_saved_context.sp, v->arch.xen_saved_context.ra, (unsigned long)v->arch.cpu_info); =20 + vcpu_csr_init(v); + /* Idle VCPUs don't need the rest of this setup */ if ( is_idle_vcpu(v) ) return rc; diff --git a/xen/arch/riscv/include/asm/cpufeature.h b/xen/arch/riscv/inclu= de/asm/cpufeature.h index b69616038888..ef02a3e26d2c 100644 --- a/xen/arch/riscv/include/asm/cpufeature.h +++ b/xen/arch/riscv/include/asm/cpufeature.h @@ -36,6 +36,7 @@ enum riscv_isa_ext_id { RISCV_ISA_EXT_zbb, RISCV_ISA_EXT_zbs, RISCV_ISA_EXT_smaia, + RISCV_ISA_EXT_smstateen, RISCV_ISA_EXT_ssaia, RISCV_ISA_EXT_svade, RISCV_ISA_EXT_svpbmt, 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.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595862; cv=none; d=zohomail.com; s=zohoarc; b=WwnmEoZuu2AAT53NWEBaC/OgYNJ9r2OO+1ct9FAyPEuSbZ6m3txZx0n5XP8NMpV8KgwjYSUm2W8JsAmoxw039BdXUHt26HD2UfF3xZOTQniLuss6HDsZSdc1KuNF/p9wRvVYzaGaoH5GgOqW6FoeyOOaegecZePV+INYYFMFPm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595862; 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=g8XzwJhnCm5wKitCTTX5wDHC/h0G6FAP9bDwWltV38M=; b=G4ttweEjRGNsEfRtiQcIlZ0oYq8882RCpY2W8G2bGv74rCI3dPOtsnrmTwr8PcqJeiF2GagVSPwxNW8TEYZjHiiSmNLi2S/Ltcfgbni3Hl982EahASCvoQiwqdnVn2qYqk/hiPGNHDiRSo+SlT8oqYRkzruLLpghI12l21rodhc= 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 176659586247420.485793995618792; Wed, 24 Dec 2025 09:04:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192952.1511996 (Exim 4.92) (envelope-from ) id 1vYSH3-00045z-1g; Wed, 24 Dec 2025 17:03:45 +0000 Received: by outflank-mailman (output) from mailman id 1192952.1511996; Wed, 24 Dec 2025 17:03:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSH2-00045q-TN; Wed, 24 Dec 2025 17:03:44 +0000 Received: by outflank-mailman (input) for mailman id 1192952; Wed, 24 Dec 2025 17:03:43 +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 1vYSH0-0003b7-VP for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:42 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7f4a175e-e0ea-11f0-9cce-f158ae23cfc8; Wed, 24 Dec 2025 18:03:41 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-b7a6e56193cso998928766b.3 for ; Wed, 24 Dec 2025 09:03:41 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:39 -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: 7f4a175e-e0ea-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595820; x=1767200620; 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=g8XzwJhnCm5wKitCTTX5wDHC/h0G6FAP9bDwWltV38M=; b=nfgR1hChQELx+mxttjRdYhOFXOR1RF4K7nrL6wgUmEgNw3EKUYlPwi+XBrl/dnM2ME 4vX0tuxnVVBQKKt465vlcY58VH6SqQByeDwgPS+rpOnCLtAvG9lnEtqysEBa4TJT3Bgo ITKm0bjs1Fc5wmT4IvfHAGI/RBlE5xSKNb/AJaiU+b7LI6+xJGLMb8YB2OG70ouOUklT kl/foLM1hRmEcwYd5ZACcE4/UjuTOLG6P8Vh7MbI73x3OYTzgXbXM2IToIvEglbcF0HY nArl3PzdqYlSeurj9cOZYDKT1cWri2/n32dUfdI2Fe14ZjbBCY0+9BEikKQUy/N/MBlq 1Kew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595820; x=1767200620; 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=g8XzwJhnCm5wKitCTTX5wDHC/h0G6FAP9bDwWltV38M=; b=qyhwnoB/5tayQGys97/Dx6fs/FtQaBEypYUvKOFaLItSlZ7jWfDA7w4jvYovEOoa6b JCB15pg5MNM0nFtoNljLYUrZA4KW329osYZcbLeFIwRC8GxQYqQxE8+75Yj2HNaHyBBM ehIqfmstzCNuTU5WtXgJqaN3FTVMphPecTZucVTiu+olNJIG/8Dc/GYsgREY2/3RDOD9 psjUyEBZJoKkWKYUq+k8FzrnkBZ1VmZJ/A+tejuNEx4gCZWgiYhDECK1J5veYoeHNiQX zxVCYZEy2lbMhFwxgTgYHdH2H7Cvs0s6j3j1slx+7c9jQEavE9zoY8BmInatIQRuw39Z jp7w== X-Gm-Message-State: AOJu0YzhyFnMeeb2NrbUJra8j6baXJNSpGvDJXEGW6Lx39edHfYApBjZ wvpG9LbBYGitFamwHy6pb6aoOtH2vaXXjjoIOxLueurrwTJgWM3UVEqRcksemQ== X-Gm-Gg: AY/fxX6Ipj8/Uoz6RxN6XFizFGQ8OozhgMWIBp6szchNqDkdDdxBkU8MVweYTcoE5cZ bGm1CU6oOhEZxJR9mbdcUGWSSVF4GbfPoRP/S1sGCefuAoYO1IxDHe5kekrJ+TFjlXDFkoYtcPn 3hSKKa3ga9KquoqeJDZwfsR8+8asJrRYLwW8oYrEentZYHLqbkknvmm/B418Y4x+rLzNrmjIM0J Pz0B+aklR90TMgofG2JCdlJGMa2Yz3gu9/wjDH4H1k0h4UIsLAgi1bWoMFG8bUQ7of8dVbKCRwW /wmu/cacys820Pcgjqc1iMVj5/7n4Q3a9Qhy0WrJahWsvFto6RQB81B2Wup63dAoOqfpz7rwCQ3 zj3BVbc9jDGyFU9fXINZZ8zpIL01TKa1snLVpRLf461kH87lFaS4qYwlK97Tb6IZHeFw6/+ga2C JvNOEEedBG4SNW8sRJxGI0xR+Wu/OZrRciZMbLdmlkDZDFpuFzw6EuQdUzGWMPaxBo4A== X-Google-Smtp-Source: AGHT+IH6Bhd0noBuZdsNvUD5oseP8WhloVgyS5FPCVJYVoTkO6Qd/swFoYV/yyKbBks3zpi7Qwzu6g== X-Received: by 2002:a17:907:7e85:b0:b7c:eb19:2094 with SMTP id a640c23a62f3a-b8037257589mr1663597366b.48.1766595820172; Wed, 24 Dec 2025 09:03:40 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 04/15] xen/riscv: introduce vtimer Date: Wed, 24 Dec 2025 18:03:17 +0100 Message-ID: <94ffc70d3050e532290126560355dc548161f466.1766595589.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595863758158500 Content-Type: text/plain; charset="utf-8" Introduce a virtual timer structure along with functions to initialize and destroy the virtual timer. Add a vtimer_expired() function and implement it as a stub, as the timer and tasklet subsystems are not functional at this stage. Call vcpu_vtimer_init() in arch_vcpu_create(). Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/domain.c | 8 ++++-- xen/arch/riscv/include/asm/domain.h | 4 +++ xen/arch/riscv/include/asm/vtimer.h | 25 ++++++++++++++++++ xen/arch/riscv/vtimer.c | 39 +++++++++++++++++++++++++++++ 5 files changed, 75 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 8863d4b15605..5bd180130165 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 44387d056546..dd3c237d163d 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -6,6 +6,7 @@ #include #include #include +#include =20 static void vcpu_csr_init(struct vcpu *v) { @@ -97,11 +98,14 @@ int arch_vcpu_create(struct vcpu *v) if ( is_idle_vcpu(v) ) return rc; =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; diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/a= sm/domain.h index a0ffbbc09c6f..be7ddaff30e7 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; @@ -52,6 +53,9 @@ struct arch_vcpu struct cpu_info *cpu_info; void *stack; =20 + struct vtimer vtimer; + bool vtimer_initialized; + /* CSRs */ register_t hstatus; register_t hedeleg; 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..a2ca704cf0cc --- /dev/null +++ b/xen/arch/riscv/include/asm/vtimer.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * (c) 2023-2024 Vates + */ + +#ifndef ASM__RISCV__VTIMER_H +#define ASM__RISCV__VTIMER_H + +#include + +struct domain; +struct vcpu; +struct xen_arch_domainconfig; + +struct vtimer { + struct vcpu *v; + struct timer timer; +}; + +int vcpu_vtimer_init(struct vcpu *v); +void vcpu_timer_destroy(struct vcpu *v); + +int domain_vtimer_init(struct domain *d, struct xen_arch_domainconfig *con= fig); + +#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..5ba533690bc2 --- /dev/null +++ b/xen/arch/riscv/vtimer.c @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include + +#include + +#include + +int domain_vtimer_init(struct domain *d, struct xen_arch_domainconfig *con= fig) +{ + /* Nothing to do at the moment */ + + return 0; +} + +static void vtimer_expired(void *data) +{ + panic("%s: TBD\n", __func__); +} + +int vcpu_vtimer_init(struct vcpu *v) +{ + struct vtimer *t =3D &v->arch.vtimer; + + t->v =3D v; + init_timer(&t->timer, vtimer_expired, t, v->processor); + + v->arch.vtimer_initialized =3D true; + + return 0; +} + +void vcpu_timer_destroy(struct vcpu *v) +{ + if ( !v->arch.vtimer_initialized ) + return; + + kill_timer(&v->arch.vtimer.timer); +} --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595850; cv=none; d=zohomail.com; s=zohoarc; b=URxZ1ufOsWv1/d/ljtPR2gdpUSsT3Ppzg9w0lhAOpdFfm2pXiY9V13ZiO8/TRjgI1++WeYZSEdryPWa2gOKfd/ezNugXaTpS2lSjrZ3lVO6L6OVZtBqjPwXFGjwwVPYEMZfAd9/rq7oz2NSUbYk7thVAFgvnn6ZzmxYCMha+xrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595850; 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=v3trXYiveaHvhlgyXDqsatKIS2roH4Y0Sc6KIceNuMI=; b=n2V6Utmhm2do90iT7sgHk/BnItl8kV7m+zUP078mu6nAKlEFIaVhkUSE0xpOIc96RrEfdrH4+RkcS4wzTosGEEL+3M44Z9m4328ys9LSw/2IgJzymOhLbWOJgxnZMQwY4i+R0HNBDZC9YLn+RZTzdt3RGOOl/J2Hp8jMUO19AIg= 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 1766595850274635.070225375465; Wed, 24 Dec 2025 09:04:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192951.1511982 (Exim 4.92) (envelope-from ) id 1vYSH1-0003hF-Mo; Wed, 24 Dec 2025 17:03:43 +0000 Received: by outflank-mailman (output) from mailman id 1192951.1511982; Wed, 24 Dec 2025 17:03:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSH1-0003gu-H6; Wed, 24 Dec 2025 17:03:43 +0000 Received: by outflank-mailman (input) for mailman id 1192951; Wed, 24 Dec 2025 17:03:42 +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 1vYSH0-0003CV-Ph for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:42 +0000 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [2a00:1450:4864:20::530]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7fc64ca4-e0ea-11f0-b15c-2bf370ae4941; Wed, 24 Dec 2025 18:03:42 +0100 (CET) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-6418b55f86dso8317203a12.1 for ; Wed, 24 Dec 2025 09:03:42 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:40 -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: 7fc64ca4-e0ea-11f0-b15c-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595821; x=1767200621; 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=v3trXYiveaHvhlgyXDqsatKIS2roH4Y0Sc6KIceNuMI=; b=NuV3PMpskygdAPgT8ca6gM4FGYNEOL3TKCj404/GxHKDeiH6+xIRwXBQonRl2KmNx3 cyn/dK4qp4TM/pGn8xV+Fnj6e58zaKbCmdZBklcW0jPeAff0NSsytKajO2uHM3YEhyMp RFWeAdPLWAkK1amuVZZ0F0X3d1DzSiYQuJJ806f6Cl0EpC2ayISMxMPa1T972+h8J9Yr ANnHmhVPJwnjAEoBGvxqEM5QhWvFEp8uJU2wtsOHoSusE2hG8gJCwuF8EVtiRCit/tfm QklVcf9jT1C1zgL+P+5nZCdqZYJjsz0wQ14/ecYTEA3Hk1GQfUNLotK+DKUy/jN0KgTI L2cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595821; x=1767200621; 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=v3trXYiveaHvhlgyXDqsatKIS2roH4Y0Sc6KIceNuMI=; b=u3h2bllInSCYIRgZujb4p94MrP7v7KRY6oUiQDjKUxL96HC+H4sMBF+pFyeAphI2+i sLTp2zJKW18yWz50zaXAJQQiNTZ5QI7JQorUgAP/tY9Pt4otmNKbY945xOtF7+gkEr42 o10NFUVS6Ggm3bt+CEPXZ8CCZzkIVFHBLavERGiqisYawnu8aMo1PbeY9TeWkDTIbZs/ 6Syz77KgORnATAVP0pESXTCJRrQxQmsdxSNbMAzNzTUgVCFR9m8Hr2f2a6/mNPxbg+DY AKyp/ngEhk1rjilt/sU5G5tCVQG/dopeUIBXP5MfAbLfsGxkWCMOROZ9iqfImz47NXH9 8PyQ== X-Gm-Message-State: AOJu0YwOgzV6Msd1pURVVK1eQIGkjDZ/FHgv40h6cS+6IojoxcJjoHwh sgKKRFdJ6it0loI0MykIGp1CM15nVcscA9luYYC824wQf0BWAXPX4qL3Kaclmg== X-Gm-Gg: AY/fxX7jeHF3KC/p+nekFjV6mGaP/+PjxB/aPJFwYJlQlfYHqioZ9WhGQGJXo22LAo0 lbzH6AWrew0BlvDRHBsj6R5sApqqnw/Nsf2fbukGuKqx8Vd5QDfNHd88mP17cz5HyM5o61sK9w5 pQjVdJdCdOfdL9oi6oeX65o/OC607sGn8N0hQS7KPh8ZabPxZ+40yVNp39tIVHfMeY3tFBMMA8z HzxIVf2InEF1CGRG61I6lWvLoIccG6WF6BiJJF5EE4sWwNNAICOTLbCq9wtzuopTigoQp6/zPT1 JRQuh0KoigQFqbQP2HJhpEB+XCW0jM+VhV+vV5M9DwkwGBLtxvTpKNavZo4RfuALpVegzDu7+Gc U6tsJHvLAGvEXFjbOvskEaiI8u4GtWOG4mOgfpSI1pXkSNj7YoUYNJKqUvT06Y7y5iNBYwBOO5D 2UWztLxc1MO0XaBP+oVaTjGHAtcEAPl1yY+UYpnz6nBz2bfscf3vcvITA= X-Google-Smtp-Source: AGHT+IF9OfLAnUg/4nt8QKZLGFjhUX1TmmbLlZPfFQKnsGxPFkAGTeLHlwNnhCdhFUm6gHPgOXbSRA== X-Received: by 2002:a17:907:1de2:b0:b80:4117:b6b3 with SMTP id a640c23a62f3a-b804117f48bmr1194562666b.10.1766595821194; Wed, 24 Dec 2025 09:03:41 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 05/15] xen/riscv: implement stub for smp_send_event_check_mask() Date: Wed, 24 Dec 2025 18:03:18 +0100 Message-ID: <837c863f5995cc4371e82b481211b053656ec7e7.1766595589.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595852016158500 Content-Type: text/plain; charset="utf-8" Since SMP is not yet supported, it is acceptable to implement smp_send_event_check_mask() as a stub. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/smp.c | 8 ++++++++ xen/arch/riscv/stubs.c | 5 ----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/xen/arch/riscv/smp.c b/xen/arch/riscv/smp.c index 4ca6a4e89200..e727fdb09612 100644 --- a/xen/arch/riscv/smp.c +++ b/xen/arch/riscv/smp.c @@ -1,3 +1,4 @@ +#include #include =20 /* @@ -13,3 +14,10 @@ struct pcpu_info pcpu_info[NR_CPUS] =3D { [0 ... NR_CPUS - 1] =3D { .processor_id =3D NR_CPUS, }}; + +void smp_send_event_check_mask(const cpumask_t *mask) +{ +#if CONFIG_NR_CPUS > 1 +# error "smp_send_event_check_mask() unimplemented" +#endif +} diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index eab826e8c3ae..6ebb5139de69 100644 --- a/xen/arch/riscv/stubs.c +++ b/xen/arch/riscv/stubs.c @@ -65,11 +65,6 @@ int arch_monitor_domctl_event(struct domain *d, =20 /* smp.c */ =20 -void smp_send_event_check_mask(const cpumask_t *mask) -{ - BUG_ON("unimplemented"); -} - void smp_send_call_function_mask(const cpumask_t *mask) { BUG_ON("unimplemented"); --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595855; cv=none; d=zohomail.com; s=zohoarc; b=QSjtrBjFzdCaNDfoux/b7Cd7Bjy1a3QO3nCQsWZ4ytvFQYqvxI73VQy8aDenbRDNVjOzHWUit7R0f9NL8vfjR84cXp6E1uEs14F5ZYSclN31mCWSYSjEJFcI/L1HbBA0i3LXdg1pSrSkUMKqoV9QWCf+ufeE8+XUOUNzFCVFiQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595855; 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=RsMdYupDzApAqnlVn5Mcs/WEIvYP7U3Z1iGkgA4AkDY=; b=Xov3G59WEU8J2zHeCTKhdleN7yfoVjAqhMw8scJUPlz+Wnjuh/Cwmsu5OJsv9TO3n1Jh1NAlOTmLipEkAujS5Y9oELJvr0TiHSLw0K0kv8GkD0bq8ufzGxNltaXXV1ueI2BoqYTCie/tjlbRlXnKlyZA5+CIkJgmjBDizFLkdUc= 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 1766595855897688.6552387101677; Wed, 24 Dec 2025 09:04:15 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192953.1512002 (Exim 4.92) (envelope-from ) id 1vYSH3-00049T-ED; Wed, 24 Dec 2025 17:03:45 +0000 Received: by outflank-mailman (output) from mailman id 1192953.1512002; Wed, 24 Dec 2025 17:03:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSH3-00049E-7a; Wed, 24 Dec 2025 17:03:45 +0000 Received: by outflank-mailman (input) for mailman id 1192953; Wed, 24 Dec 2025 17:03:44 +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 1vYSH2-0003b7-If for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:44 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8054301f-e0ea-11f0-9cce-f158ae23cfc8; Wed, 24 Dec 2025 18:03:43 +0100 (CET) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-b8052725de4so484933166b.0 for ; Wed, 24 Dec 2025 09:03:43 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:41 -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: 8054301f-e0ea-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595822; x=1767200622; 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=RsMdYupDzApAqnlVn5Mcs/WEIvYP7U3Z1iGkgA4AkDY=; b=LxT+L1hnxXMUYl2UXND0Yuf2TQIt7iQtlqORZDFl2bzt0WMyM73E3+Uqfa5c0eMFAt bntnmVg2Xmzhzjj3Q+mYAJtNRd6hIapoXcNnKDbn4M2U4V1SXHeP9XTazGTe1h8HfjsA M68/j17SmoRhcPl2o17cR4dcuEd8gOLu4vKG6xgKC6Hdvui5xai11pPsGWX7i6LFVRdZ FqY6sedZ21VJqtALSbHvPclLYCqsTHvugd3I9lZgfuFHBYou/jNmJo6SAelhqFs5vfJY PPrLM0FehTK42KcHhfKIbeM6Gzz334fDPoalTJmGb8s2kXLgMJ6UxsuPoN666AHwcvQD 7OkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595822; x=1767200622; 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=RsMdYupDzApAqnlVn5Mcs/WEIvYP7U3Z1iGkgA4AkDY=; b=R6Qg9ja1bcK5iQ6xsS8JZGRoy5yLsy9dwS9abjLnhcrFb9W3cWMMC+u/xiiLJLk7bg k0wIzUgp5dRUoE1WGXmvwrHq7oaa5yxs3zJM9Ncb0ruJwUwXeSfGpVl1hVQYtq8oa9VM LFIwtXxLXO8M5mtPx0QA2E6w3RLm9zBku/PU34DrVbXULEM1ZGOWbWhk9HZB99B4X5k0 UcYrQfToxsd5u9VdvB6ohb84ywtavyw1q++gxxUhiajLZ3PaiHCV7cUfETMSdtl3mzFW CN+eP1rGUJD5KKhPYahVjUlg5zZsaNmaqu/sSVMXrndS946pvedht6IUKjtlh4RqS+I3 /qNQ== X-Gm-Message-State: AOJu0Yy/euLGjNUm8WudLJUB+hzPbmAD3gWpg3N0UWWQ/Sd1zye07WL2 OeTYgKXa5+b9gij+8YgI32U2XlvrdcsIErQSa9APIENgVitubV6vWTSNa0jxhw== X-Gm-Gg: AY/fxX7YFw1MjlYOvcp6RvyVfeeSy6XgmrvFTo1pGHI/6AoClv2tPYL54lK/HFVzJPQ Pch4NiuHlmLhDAkv/oYWjBbImZYla6AH8VIEUtBDtYG1oOEkDjHOQ9S1lsSDQS23+ffILHsKcq6 F8oEfyYNVm5VqYARBnFVjOrkN1BLE4+GXfyheiQGO4Hp0ieLqxGrILpMCE+v5nEXRkM+WPC1ueL j/yFcwhj9CprztD/mNP1EXDxTGjWjUA9KZRGs261C+tAo39V7XQFmJO6myG7HNGS/4rzieFWnd5 oCbBm9keyj/KXbIWhxAvUkg5j3bO6wOo/vBsVTIUs+ni2O7tyERYeRN2PWPVzptB2SpmKlJuexR nr+l2ged2GLOrRU3hKwFrJVpD67E8Mv6oFq6OpafJ2jhe/RCijacrSa6o7EKGwsULIModrjW9jT n7q0Rr2qFYL6wypdtRGkuWkc7L6AC5JV8J8JpwMSC+sXaxMMtQMLx8BXU= X-Google-Smtp-Source: AGHT+IHhUMpUxd3Xsuvj4VpMElwnJhkzHeXZnV3OSkbjZoCKDj/+fCc9yIGuUZtowk1PFuuqdElJhQ== X-Received: by 2002:a17:907:948d:b0:b7a:1bde:1224 with SMTP id a640c23a62f3a-b80371e921fmr1846678166b.65.1766595822095; Wed, 24 Dec 2025 09:03:42 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 06/15] xen/riscv: introduce vcpu_kick() implementation Date: Wed, 24 Dec 2025 18:03:19 +0100 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595857667158500 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. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- xen/arch/riscv/domain.c | 14 ++++++++++++++ xen/arch/riscv/stubs.c | 5 ----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index dd3c237d163d..164ab14a5209 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -1,7 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include #include #include +#include =20 #include #include @@ -121,3 +123,15 @@ void arch_vcpu_destroy(struct vcpu *v) { free_xenheap_pages(v->arch.stack, STACK_ORDER); } + +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)); + } +} diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index 6ebb5139de69..68ee859ca1a8 100644 --- a/xen/arch/riscv/stubs.c +++ b/xen/arch/riscv/stubs.c @@ -213,11 +213,6 @@ void vcpu_block_unless_event_pending(struct vcpu *v) BUG_ON("unimplemented"); } =20 -void vcpu_kick(struct vcpu *v) -{ - BUG_ON("unimplemented"); -} - struct vcpu *alloc_vcpu_struct(const struct domain *d) { BUG_ON("unimplemented"); --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595857; cv=none; d=zohomail.com; s=zohoarc; b=CoAmlIhZDKS4iBYdngSixWzfXqWjF6k7qyL0QNBl32w5LWFPJbYBt6jrBUGkNXTHh9ovTYRvaGnMG25KLKAoYnkCeYyRcfSg9g7EWcC6yMk/lHFu/eIs6mgeWDvmue0wm/FSCP2zKr4ECFtWFchtGXwX9Zt3fYRFNxTxLW1nQPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595857; 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=eVSU+W1QGWlyg8JQ8PYuBMuNclIYpGmrVspxyegORmI=; b=j0cYyrPntQTeYx+3vNEb9WrEjqNbGa0s6XSpe8Iw4Rj56euE33dvelX4L9pm6QMU8oLHZSSIR8IxwjzPSS0AfCS7Qa9VbB4osJy2O+P1oV6wtny2gFMazSKyb2GlHAvwudOry3VrdmUuoS+yA+nCYBkvpmjMziGD3C5HyTg3Atk= 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 1766595857561926.4113528566232; Wed, 24 Dec 2025 09:04:17 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192954.1512016 (Exim 4.92) (envelope-from ) id 1vYSH4-0004We-Lt; Wed, 24 Dec 2025 17:03:46 +0000 Received: by outflank-mailman (output) from mailman id 1192954.1512016; Wed, 24 Dec 2025 17:03:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSH4-0004Vk-H1; Wed, 24 Dec 2025 17:03:46 +0000 Received: by outflank-mailman (input) for mailman id 1192954; Wed, 24 Dec 2025 17:03:45 +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 1vYSH3-0003b7-K0 for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:45 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 80ea9404-e0ea-11f0-9cce-f158ae23cfc8; Wed, 24 Dec 2025 18:03:44 +0100 (CET) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-b73a9592fb8so1149477966b.1 for ; Wed, 24 Dec 2025 09:03:44 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:42 -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: 80ea9404-e0ea-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595823; x=1767200623; 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=eVSU+W1QGWlyg8JQ8PYuBMuNclIYpGmrVspxyegORmI=; b=ZBAC5fYFgAiZeyasBl4AMnNhfyiqULx860sfQYCDYuZKoX5O7YFjTEFmtNTvEx/4qL bfOgjqbUGD5iskG0I9z9pJhk4Rujtp6F4Qgf4sT9392Q+E63HZpFczUDijQbssiBiTc+ tpKyZuoLoosJQS2G739KfGtaHgaWS8xzxCktWSgW/w6ldU+LZWl/QCh8NafPJPADZ4sv s7ZXXnstL48FnasR0egQqE5rM08eb99chyTXZPNBX/vCncDUEFAZJWiXXvrTEk0IHN9h czrmjf3J47/z/9M+veX9QdtbQf73NCl1e74HSBWJwdO9/YSo6cO1/1XOD+Momx9sf6xI Xm7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595823; x=1767200623; 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=eVSU+W1QGWlyg8JQ8PYuBMuNclIYpGmrVspxyegORmI=; b=b9dk8hNrAFbXTSEyV5GpJrxh0CCXZEJ576COyZyClNqAu9TFPfDvKOJ2cy1PdhJhDP qaoXBcHsD+CVp8N59jAEM0qUoWjydLqqmnSmQtjAXLmzof27yx5FLnDvHn81udWI0aiD XFAA0Mdjh8ZS5SoIpKnoa2oOLwh/JvcXSTkbI2fA/zHlGYT0LJO2HYdukdnLEWaWD/UE JDwUBiaKNBG7UXAnbzmjcUYrJDKNMov6MkCG+Jtvn32PYnCZbZzPHObOdeOTkrHM1+jF p85hgr/Yw1cwSveGnRx88bUul+anb9Ls4xw/eIsdseTYeihxigJcAOxNxY6ZQcRptqZk rJBg== X-Gm-Message-State: AOJu0YxzMeHElkjWfjn6iDLA1enbCkFCgSZ56thqBvikWCdRD1Zweo26 V0s0hlPB0vAoIPCJA4b2MqnecN0zQcRndEjkA5XNUyS/rXtoHt1JNsXgOLA9QA== X-Gm-Gg: AY/fxX5jrn5FkK+jkSzjxQhtbnTZ76eTGLE3TSZn0EmGcGZ5e6nyxr3K1noI8oUkHZH r8brMcV+8/M0wmdlermHGkyZ9j8hi+LKsnvw003Xzv9uh3ZGXPAVNIh8kW/xacqT0fnF3Q/4Jsr mxV5mrGaANxwtHb3RAKxSrOK/qmZC7bXcSaW+WE5T575WU4ckbqm1p+X3SI41+FZWQ5oaB6R7Ye K0++DNAS6WimOrnTW/mBaJTAGxCHPO7WVmFr9dSmUx3Aa6Wgkgjakskvodjwjvl89ajR03J88tT ejundnrBQCEvv02DjnmZqLno+EyTGvJ24dGjsDJ6QJ2hHcTMIojcM9PGey++3jkrMAigjVdQ8+Z eTgZPSTcJf+rOUHMmFVIA1RpuPdB2SxSaWquANoVxY0dG1+VfievMWBZB7i4+gLbcKt0jzy9HZZ nR8Fmv3nyYziAE5FTk/WlT0Oh2VW0LB+5IpqVQkPUGek/7DAQU3nl8evA= X-Google-Smtp-Source: AGHT+IHyvwi6tzwoa0da4D5yRiLL+x7c5L6uyL4HDN/1K0/a4HJYGqOGf1921C5u1CXXdfwvsTy1xg== X-Received: by 2002:a17:906:aa16:b0:b72:dcda:fe5a with SMTP id a640c23a62f3a-b802040097fmr1699255866b.5.1766595822996; Wed, 24 Dec 2025 09:03:42 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 07/15] xen/riscv: introduce tracking of pending vCPU interrupts, part 1 Date: Wed, 24 Dec 2025 18:03:20 +0100 Message-ID: X-Mailer: git-send-email 2.52.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: 1766595857713158500 This patch is based on Linux kernel 6.16.0. Introduce a lockless mechanism for tracking pending vCPU interrupts using atomic bit operations. The design follows a multi-producer, single-consumer model where the consumer is the vCPU itself. Two bitmaps are added: - irqs_pending =E2=80=94 represents interrupts currently pending - irqs_pending_mask =E2=80=94 represents bits that have changed in irqs_pe= nding Introduce vcpu_(un)set_interrupt() to mark an interrupt in irqs_pending{_ma= sk} bitmap(s) to notify vCPU that it has or no an interrupt. Other parts (such as vcpu_has_interrupts(), vcpu_flush_interrupts() and vcpu_sync_interrupts()) of a lockless mechanism for tracking pending vCPU interuupts are going to be introduced in a separate patch. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/domain.c | 47 +++++++++++++++++++++ xen/arch/riscv/include/asm/domain.h | 19 +++++++++ xen/arch/riscv/include/asm/riscv_encoding.h | 1 + 3 files changed, 67 insertions(+) diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index 164ab14a5209..8a010ae5b47e 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -5,9 +5,11 @@ #include #include =20 +#include #include #include #include +#include #include =20 static void vcpu_csr_init(struct vcpu *v) @@ -100,6 +102,9 @@ int arch_vcpu_create(struct vcpu *v) if ( is_idle_vcpu(v) ) return rc; =20 + bitmap_zero(v->arch.irqs_pending, RISCV_VCPU_NR_IRQS); + bitmap_zero(v->arch.irqs_pending_mask, RISCV_VCPU_NR_IRQS); + if ( (rc =3D vcpu_vtimer_init(v)) ) goto fail; =20 @@ -135,3 +140,45 @@ void vcpu_kick(struct vcpu *v) smp_send_event_check_mask(cpumask_of(v->processor)); } } + +int vcpu_set_interrupt(struct vcpu *v, const unsigned int irq) +{ + /* + * We only allow VS-mode software, timer, and external + * interrupts when irq is one of the local interrupts + * defined by RISC-V privilege specification. + */ + if ( irq < IRQ_LOCAL_MAX && + irq !=3D IRQ_VS_SOFT && + irq !=3D IRQ_VS_TIMER && + irq !=3D IRQ_VS_EXT ) + return -EINVAL; + + set_bit(irq, v->arch.irqs_pending); + smp_mb__before_atomic(); + set_bit(irq, v->arch.irqs_pending_mask); + + vcpu_kick(v); + + return 0; +} + +int vcpu_unset_interrupt(struct vcpu *v, const unsigned int irq) +{ + /* + * We only allow VS-mode software, timer, external + * interrupts when irq is one of the local interrupts + * defined by RISC-V privilege specification. + */ + if ( irq < IRQ_LOCAL_MAX && + irq !=3D IRQ_VS_SOFT && + irq !=3D IRQ_VS_TIMER && + irq !=3D IRQ_VS_EXT ) + return -EINVAL; + + clear_bit(irq, v->arch.irqs_pending); + smp_mb__before_atomic(); + set_bit(irq, v->arch.irqs_pending_mask); + + return 0; +} diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/a= sm/domain.h index be7ddaff30e7..a7538e0dc966 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -85,6 +85,22 @@ struct arch_vcpu register_t vstval; register_t vsatp; register_t vsepc; + + /* + * 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 64 + DECLARE_BITMAP(irqs_pending, RISCV_VCPU_NR_IRQS); + DECLARE_BITMAP(irqs_pending_mask, RISCV_VCPU_NR_IRQS); } __cacheline_aligned; =20 struct paging_domain { @@ -123,6 +139,9 @@ 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, const unsigned int irq); +int vcpu_unset_interrupt(struct vcpu *v, const unsigned int irq); + #endif /* ASM__RISCV__DOMAIN_H */ =20 /* diff --git a/xen/arch/riscv/include/asm/riscv_encoding.h b/xen/arch/riscv/i= nclude/asm/riscv_encoding.h index dd15731a86fa..32d25f2d3e94 100644 --- a/xen/arch/riscv/include/asm/riscv_encoding.h +++ b/xen/arch/riscv/include/asm/riscv_encoding.h @@ -91,6 +91,7 @@ #define IRQ_M_EXT 11 #define IRQ_S_GEXT 12 #define IRQ_PMU_OVF 13 +#define IRQ_LOCAL_MAX (IRQ_PMU_OVF + 1) =20 #define MIP_SSIP (_UL(1) << IRQ_S_SOFT) #define MIP_VSSIP (_UL(1) << IRQ_VS_SOFT) --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595855; cv=none; d=zohomail.com; s=zohoarc; b=Jolz+eEKpviXEdBVImah2xlRaku3QyQVbqFlKW4qvH2dio/XqlFbXSanfQUc4Tcohd6kwPCJAJn/jteZ7g0/Zqtyv6SaGCMV8RUnJMOBmwSsqm7UWD+eiRA+9jqtpPQ6cXW9zFU+0OTpUwmecij3U8QhiJK4p6Ig4IMrUrbORqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595855; 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=f81w3dP1tK2eL4eFxpXsxUA2ohrjxt2N+AHHpB9O6MY=; b=KvGXzhKjR6F0JBm75xnxLVgmlYsdr2R3Z8Cjv60kFaFh9gZQVoTpdLPD6LJNJ2c+1KrTzR+F1lOnDJpBXSwJMjWeqV/eKdtk7G/MEfEzXcIsGLqF0QbX1nsxrKvaNwgphBPg9MaBN2WvUfgExegC097KQmM66vX3x7+QOL7aNPI= 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 1766595855193952.0005599445304; Wed, 24 Dec 2025 09:04:15 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192956.1512032 (Exim 4.92) (envelope-from ) id 1vYSH6-0004sv-E4; Wed, 24 Dec 2025 17:03:48 +0000 Received: by outflank-mailman (output) from mailman id 1192956.1512032; Wed, 24 Dec 2025 17:03:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSH6-0004rx-4j; Wed, 24 Dec 2025 17:03:48 +0000 Received: by outflank-mailman (input) for mailman id 1192956; Wed, 24 Dec 2025 17:03:46 +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 1vYSH4-0003b7-Bs for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:46 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8162f76f-e0ea-11f0-9cce-f158ae23cfc8; Wed, 24 Dec 2025 18:03:44 +0100 (CET) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-b7cee045187so1086233066b.0 for ; Wed, 24 Dec 2025 09:03:44 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:43 -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: 8162f76f-e0ea-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595824; x=1767200624; 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=f81w3dP1tK2eL4eFxpXsxUA2ohrjxt2N+AHHpB9O6MY=; b=cixfmFkV76J2i6aUf83Gci9BXp7acnnehZOyNLl2lZLptxlmMx5UFw9uybJy/uOxS3 9WOtavKThU0/fcbkQv5BWDhI8AKfVGtz2RbLC/mmkUd1u0o0EP/7W1kpAF6FR+5DxgZ4 cE9/1OmNMF9jtD/0cwhzxo++KbkhgoqfxSFzVZQGj/2Q7wGRA+aQO6lJl067yTcRHnFW kEL/v/1Eba/IquCukZo1VfWvXhp0hJoS1xEiZ8H74B8Lb+Wl6AXzXpj9CY9ssGBSgbzV nWNpBzIlMN1RGg2Xuh+0Tiy0rWYqs0uJxDeOyROvfOV6U7xP2VT5NdSU0GlDzTpOKj7h 9yDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595824; x=1767200624; 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=f81w3dP1tK2eL4eFxpXsxUA2ohrjxt2N+AHHpB9O6MY=; b=i0cgsjigt5BH8xl/S7IEAyNLXaccp/VLNIAbNEr9dGnPgo59tBAt/ei9Uny/0fZQwB AUm4l+fmDjaMFP51J/X35bWOnlw2aeDQIAcUSU0eOFM2LU5Bx76/DMJ2oTGJ1X+O8k7d 7FZ7TVvPQ+Ebs33+uAQciP+kWpWt/RG71ojfkORpoJrbxjD59ZSU81iB4m5FdCyT3Ga7 OxLW4GyZXlqARyx/V30xvZKxuEChBQSmsV9zITIEvCgevcMxdbK3DUtOZjLXuJ4/guEm +Ti0XcR9E91DbPqQheuKVT9xTKQYwpb8xdTD3/OtKuY9JGLc84jGSrWC+6ACx3Azllm3 kCPA== X-Gm-Message-State: AOJu0Yzu5/WfQkeNCgNITqpN4+piC+skAYLeEfTWcXPL77O8mqU1Lk0G zVRPv+BzaDl8Mmxc58CO2uLPRMJdhaf/oVhbXhP7ZHgEJiCVLSBKpY+1AcpPDQ== X-Gm-Gg: AY/fxX5TeXcrfT0SqvSSe1b+hXs5Cy7curRO2Oxu4OHM67C1FtpUOZDv4gfoeOZ7dfc EYziGZlRFmofKVD9IpPJpW+Iyi108WsroAMc6xp54bK9oLxGJsGPeqNBsTYF5qvI7ToAGTEequX ArXabQ/MaAsRVpC6N/Y17gFGBMJkEkKWjPE+GDSJI00D4LRUFGgNmokrNQtSamg5uxELOANdESs qvbvsP9JGcY8nVCAtKCRAD+ZTgBaU0AfxVILj5HaaS0fTnrRLqpM0VSzrRckMu2yISh6/naI01w esJPRlJ+4Mo9tRKw8SLoSjOXqNvXX8B2tdOtknEwJp2sb21uRpBUXkcyGRWj6BpDWkY0J9rSYgP duDrcZiGXEoOHEbLCogdfc6Vj/v7wZpsKmZrzmhnsGjebikkLXjmIkguFplgTD5YpPDLDZ4ewuD 9tZbRbkluX4bZpZutCxAmiHdaBDNflsMOJBrBVqA/Ur7jLklX9O+nqHM0= X-Google-Smtp-Source: AGHT+IHshSx3l5OrJNFlQ2SSgcsfwt3lta9Ueb5q3FYlqr00Fpc0Dn1/nt2xc9qJJ5HAxNygBYvj1w== X-Received: by 2002:a17:907:7e85:b0:b3a:8070:e269 with SMTP id a640c23a62f3a-b8035649310mr2198873866b.14.1766595823899; Wed, 24 Dec 2025 09:03:43 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 08/15] xen/riscv: introduce vtimer_set_timer() and vtimer_expired() Date: Wed, 24 Dec 2025 18:03:21 +0100 Message-ID: <8cd3efa488b3da2a6751c92d20bbfeb87b3ba39a.1766595589.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.52.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: 1766595855710158500 Introduce vtimer_set_timer() to program a vCPU=E2=80=99s virtual timer base= d on guest-provided tick values. The function handles clearing pending timer interrupts, converting ticks to nanoseconds, and correctly treating (uint64_t)-1 as a request to disable the timer per the RISC-V SBI specification. Additionally, update vtimer_expired() to inject IRQ_VS_TIMER into the target vCPU instead of panicking, enabling basic virtual timer operation. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/vtimer.h | 2 ++ xen/arch/riscv/vtimer.c | 30 ++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/xen/arch/riscv/include/asm/vtimer.h b/xen/arch/riscv/include/a= sm/vtimer.h index a2ca704cf0cc..2cacaf74b83b 100644 --- a/xen/arch/riscv/include/asm/vtimer.h +++ b/xen/arch/riscv/include/asm/vtimer.h @@ -22,4 +22,6 @@ void vcpu_timer_destroy(struct vcpu *v); =20 int domain_vtimer_init(struct domain *d, struct xen_arch_domainconfig *con= fig); =20 +void vtimer_set_timer(struct vtimer *t, const uint64_t ticks); + #endif /* ASM__RISCV__VTIMER_H */ diff --git a/xen/arch/riscv/vtimer.c b/xen/arch/riscv/vtimer.c index 5ba533690bc2..99a0c5986f1d 100644 --- a/xen/arch/riscv/vtimer.c +++ b/xen/arch/riscv/vtimer.c @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include #include +#include =20 #include =20 @@ -15,7 +17,9 @@ int domain_vtimer_init(struct domain *d, struct xen_arch_= domainconfig *config) =20 static void vtimer_expired(void *data) { - panic("%s: TBD\n", __func__); + struct vtimer *t =3D data; + + vcpu_set_interrupt(t->v, IRQ_VS_TIMER); } =20 int vcpu_vtimer_init(struct vcpu *v) @@ -37,3 +41,27 @@ void vcpu_timer_destroy(struct vcpu *v) =20 kill_timer(&v->arch.vtimer.timer); } + +void vtimer_set_timer(struct vtimer *t, const uint64_t ticks) +{ + s_time_t expires =3D ticks_to_ns(ticks - boot_clock_cycles); + + vcpu_unset_interrupt(t->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)~0ULL) ) + { + stop_timer(&t->timer); + + return; + } + + set_timer(&t->timer, expires); +} --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595854; cv=none; d=zohomail.com; s=zohoarc; b=PHRLBdOOO+8viRznvP3fkoKpTqlf6tbgJAdrwc4nKz99LTBWUbmE5x526EGBnvLyaEy1FA6ubsEVGX3PlZVYpvW6bn2vTQhXG6sfxQOqURHtH21DBJeHoCidFmsv3rZAbbhNVaaUeGID3zC+SRvpaWZjR0UE6FPhOnkNjIojJHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595854; 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=MGJ+8PA+B3BZDqfQOwxBtkdsNJonGtyAMvb81pE0IsY=; b=S6Um0Kz75Ewfv+GbVevdYgDsPljYOH3a/qAjmZFY9Ta1k11I/4BxH2amYGjApPAf3ZBMYNBwJQuoFLokvc3ioUwfMrnq0tXL2H787JneWD0W8F+FGWcBxH8dahjtkGDYn14Wyia7hzpKEJqNR6PbGsVmK/bcMLBiyWoX6rA1sws= 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 1766595854243121.0756358611917; Wed, 24 Dec 2025 09:04:14 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192957.1512037 (Exim 4.92) (envelope-from ) id 1vYSH6-000530-UT; Wed, 24 Dec 2025 17:03:48 +0000 Received: by outflank-mailman (output) from mailman id 1192957.1512037; Wed, 24 Dec 2025 17:03:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSH6-00050i-OX; Wed, 24 Dec 2025 17:03:48 +0000 Received: by outflank-mailman (input) for mailman id 1192957; Wed, 24 Dec 2025 17:03:47 +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 1vYSH5-0003b7-5H for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:47 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 81f799f9-e0ea-11f0-9cce-f158ae23cfc8; Wed, 24 Dec 2025 18:03:45 +0100 (CET) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-b734fcbf1e3so1217320766b.3 for ; Wed, 24 Dec 2025 09:03:45 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:44 -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: 81f799f9-e0ea-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595825; x=1767200625; 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=MGJ+8PA+B3BZDqfQOwxBtkdsNJonGtyAMvb81pE0IsY=; b=dD3IgTGK28E1oOIT4mnmx9bJdTBah48Zr5x/6Lw2WpQODtSfq622R/iiU66V64aDlh 4csU1v/vJBxzzQ7adyMtsrJPcLuum/EaENybG/dmzBRQjqNVyYoZOMfBZb32q/mIsrnB a6o/mDRoS/6eZob0dmh8uBj9tuQmfprOjy+1OGPFVaGwZ6Vo/4xtbxUMCFi9jbTSREUN 59EkXWDhBJyioegZD8O1Otn0+xI9zAndei9wwxwFvCFfchJelIHQfCilATDBwr5sKvmA lF2V1a3K/HRTFwqRZahLgzpYH5zRvkVfF/1yv3iTC3ua34GLvtdIEF3VXQigUetvam09 AmNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595825; x=1767200625; 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=MGJ+8PA+B3BZDqfQOwxBtkdsNJonGtyAMvb81pE0IsY=; b=xQoGptxTYagrKW9NUF34jHWsdxhyd6GJOFi6WmEAfZcjb/m1mAmyQVHkrTsdmlZoEh UfUXQ/GTv23ccenJmjlPnnR8koGtEranhyCDiOpzFJLVa05NMsh0rh1iF9rOhQe4unSB 6WCD6GPlQA5gp2YqAq1ZPLRLatfbVTKAmXA9XG/adPUVDqPFvKKszmKltf8+Fv1a3UtD 2wVBcB8pTw2ZsRH+2+vlJqOY+rnBzdsgHB/EQ8yOK66fsfAjVaqhzQPqNBDTlfrxlUpf jr4pPSJnZRlvnHePH0UDN8NNpHgS/hDxRiPHFB8x8SPQv7pRDMW9Ub0r7X0Indu4Fall qj0A== X-Gm-Message-State: AOJu0YxVxK0+cE2li83v/UHVGQa79rpJ2BLCYA7VyrRHjpLcMexmx1Qv SE/HcYAuvl2tnzhS6Zwy+kRx4vBMYklJJ3QKQY1+TZKA+4rnH9vzxVtPLN2ftQ== X-Gm-Gg: AY/fxX4wTUnBG0wIIOYe4mepk3YL6NADegxvSZLoHNmk+3s2g3k9KAyswBEgGhoaw2K XidNgJZ1WQwkjFjLot8lt+7p4G3xEmK4qo/iOH5smGUk8Zateq8HHC9GeDysxJebyhokZpIORnt As4hPDFhM5jvdjRNBCS3fB8TNOYIEHXiQ2o3a3nUe6Tr6WH8eAr0uA2mZnNPmciUuinvr1XfIgI 6I2beg0qLeOaGwWJzT4BwCYGjYywCdg8G3D7e+N2yWDGrE7yRaTaixbs2xs4XwtxPVhCqUPcHrf EDZvOcRJhPnnx/RR+Pv6tJkOXPzSgaMO/OVauirgwJuM8nA0TSfxU/vtLxNSteulHME6MV7ICrz N7UTSLiuDtZFY0MDtn5kPfd9mszHGcVfKoWBNsWu32dIrDW0zF4fEi77f/GpmRkEb/vSSbTQjyL J4V0i2UNLEHgdn3n64zQ6aQQ29tv/mYjlUQVy1dy8UFl7PTy+zM9ivEvk= X-Google-Smtp-Source: AGHT+IE6Rng/74BQOORFuFqqd25NLbcHLdjnMNrygxPv5l6Eq0mWe3vHJVxozddH9FrS50pBgVXS9Q== X-Received: by 2002:a17:907:8686:b0:b76:8163:f1f8 with SMTP id a640c23a62f3a-b80371d6725mr1938532166b.53.1766595824765; Wed, 24 Dec 2025 09:03:44 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 09/15] xen/riscv: add vtimer_{save,restore}() Date: Wed, 24 Dec 2025 18:03:22 +0100 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595855701158500 Content-Type: text/plain; charset="utf-8" Add implementations of vtimer_save() and vtimer_restore(). At the moment, vrtimer_save() does nothing as SSTC, which provided virtualization-aware timer, isn't supported yet, so emulated (SBI-based) timer is used. vtimer uses internal Xen timer: initialize it on the pcpu the vcpu is running on, rather than the processor that it's creating the vcpu. On vcpu restore migrate (when vtimer_restore() is going to be called) the vtimer to the pcpu the vcpu is running on. Signed-off-by: Oleksii Kurochko --- 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 2cacaf74b83b..e0f94f7c31c7 100644 --- a/xen/arch/riscv/include/asm/vtimer.h +++ b/xen/arch/riscv/include/asm/vtimer.h @@ -24,4 +24,7 @@ int domain_vtimer_init(struct domain *d, struct xen_arch_= domainconfig *config); =20 void vtimer_set_timer(struct vtimer *t, const uint64_t ticks); =20 +void vtimer_save(struct vcpu *v); +void vtimer_restore(struct vcpu *v); + #endif /* ASM__RISCV__VTIMER_H */ diff --git a/xen/arch/riscv/vtimer.c b/xen/arch/riscv/vtimer.c index 99a0c5986f1d..4256fe9a2bb0 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 #include @@ -65,3 +66,17 @@ void vtimer_set_timer(struct vtimer *t, const uint64_t t= icks) =20 set_timer(&t->timer, expires); } + +void vtimer_save(struct vcpu *p) +{ + ASSERT(!is_idle_vcpu(p)); + + /* Nothing to do at the moment as SSTC isn't supported now. */ +} + +void vtimer_restore(struct vcpu *n) +{ + ASSERT(!is_idle_vcpu(n)); + + migrate_timer(&n->arch.vtimer.timer, n->processor); +} --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766596075; cv=none; d=zohomail.com; s=zohoarc; b=aUkXu9Ej2TO1Xw44bZJqw9k8eru0kyWgatDCVPBRsgY+ynC4IRKhm0mB4RCXrp5LctWh3siOQT22MLwCAISwWdN2RtoepLx6fDbQnTu3Ux8k1dd7ugP6tpxYsyZ9/R/VIcNOMS9aGMmYuabU7yjd087/NArIxxLiEK4mfYDTcwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766596075; 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=QwTK78uer5FqwaU5f51ewDsBN5tAldzPPMkL2zu2Q7s=; b=l3J+BB8dfr6MgX51y0wkZMkssanCxLPUwZfqMR2cZRU85m3nOZcLrXuzM01/U/56o5uWxhZI4k72btqwrQHfjFhVIbyC0+wraXT+a1a8G7dXOifls+aJdMqk+/P66F6EynifhJhcBywCWAOL8HJ9gQaScyJ6ECQ77JVWm2RtKuE= 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 1766596075551906.1652223888009; Wed, 24 Dec 2025 09:07:55 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1193083.1512105 (Exim 4.92) (envelope-from ) id 1vYSKo-00036i-V8; Wed, 24 Dec 2025 17:07:38 +0000 Received: by outflank-mailman (output) from mailman id 1193083.1512105; Wed, 24 Dec 2025 17:07:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSKo-00036b-QU; Wed, 24 Dec 2025 17:07:38 +0000 Received: by outflank-mailman (input) for mailman id 1193083; Wed, 24 Dec 2025 17:07:37 +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 1vYSHB-0003b7-1D for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:53 +0000 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [2a00:1450:4864:20::529]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 852d0b02-e0ea-11f0-9cce-f158ae23cfc8; Wed, 24 Dec 2025 18:03:51 +0100 (CET) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-64b61f82b5fso8046046a12.0 for ; Wed, 24 Dec 2025 09:03:51 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:45 -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: 852d0b02-e0ea-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595830; x=1767200630; 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=QwTK78uer5FqwaU5f51ewDsBN5tAldzPPMkL2zu2Q7s=; b=hXvsCXcI4svtdYfylJXCsw4dx8MxbJd7aWco5vwlCob+Lwtu2tK8/C1AyGIn704hzB F9HtV6k91wVpOEjtdTmdPXtfGB5z990AMFbQTrCsZ4twhxOnoqbZ7oSuJuL9GAQNcJR7 S6okmXKSUvOo4wxERaP1hxGk7dgVi9P4ZM7t5s6LVNVgfeyK9yX/+f4yy8+qaaSrsS3H uCqszC5mCh6QuwWtAzgRGxWxK2IX2LwcbaD0aL95KAhCV5tKnjg4jOn/SReJjdIX+j6h qv+dXiyNtCJIhRV3eBP2xGjP5SrI+5gIEH0pJ5QU4WT0dULK7wDLBW0+8OXDCbI46mt1 7Agg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595830; x=1767200630; 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=QwTK78uer5FqwaU5f51ewDsBN5tAldzPPMkL2zu2Q7s=; b=Tu6rWkoxnMrLwF6chMe65tpwIEuAO46YMpfj5XyfGBEyM8/5uhNAIjhlnvczUtejSm TqA1HqdxWb15qwQoOQe4yeVLkTGXb/oETGZNY94ukhxZiuQTX6f/nYUkn/tj3CPLQXjS 0927dTWd3gOixz8xGJkrZkhMtLSDue7GttrJ2ILARXueBTzCqUWJ4FP6CX7mx+dlwniX HkKYHpqCj5vCNkWOTzv0bcQK4LpiiTvNqEd1gefJWNgkAZodlEQeTzesdD4l+4z9FpuI DQLNdiX8UfdDT8YmlhkZQrzZ42aDdnn6QMhI2HJt/1xQifrKb3Jo36IwLNRT8KkFBQgO 5lMg== X-Gm-Message-State: AOJu0YyOOq+OqxuEtbvkr+NNFWXYoJ+R8gHFcRxZ08jF4tzwSzkazrHF W6JYK2jQ0jyq1CvYeKaFAfXG12sgfwoZsTkpBP61FlLS59q2Jwugczf4pehksA== X-Gm-Gg: AY/fxX48F5hCg1CoVoFwIAUCNhNmpZIMGwzMuiB/2yQFJvL0XJ6YRCfvdMgRJVTT2gi arLaLfDhmUjkrtRfnzTB19uirqX2xB56Vm3QN/gkC4MSsoNxtT2YM+m7SlxyW+x4XD9ID5LXkw/ TOGQFLAU6OHhbR5ww5xdFjgFqYBTW2GA29sR0ggrBwYmqO6uz+5rfRTgC/GvBi+NeV7rIDM3CU6 ahrW67gSRD7aJIHIRLJaou9WpOBggHNCM2zOwLmJykw3Yf5nPmvspAyAEgvh8ORepRJm1/mu83B TJgjx5DgYHYKBUSPiWCJf5k8uRvKC7MadhjvWj8E9vvHOoBarouH0CMK+1Qppw0+gbeX3jAO2Jd o5e5YyOOjdwuO36ZW+XP3zWR0Mfd8pGRf7nb/VyRnSkFntR6FPowdJl6AupIVSMH+WLtUTdGmzb K98jFN+7N+QDbEvTxcwiDfQ5ereDWlIOeG6FJVqTrpdazUwIQ1+izA7N8p7TD5UzYAHQ== X-Google-Smtp-Source: AGHT+IGl54jmOAYUGkIE1+LHb8Ib0Ru38nQPIsZR8jHbOJogShCm59AuodegHYJUA176Df1F0Piu+A== X-Received: by 2002:a17:907:9801:b0:b73:6838:802c with SMTP id a640c23a62f3a-b80371d8c9bmr1801488066b.42.1766595825667; Wed, 24 Dec 2025 09:03:45 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 10/15] xen/riscv: implement SBI legacy SET_TIMER support for guests Date: Wed, 24 Dec 2025 18:03:23 +0100 Message-ID: X-Mailer: git-send-email 2.52.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: 1766596076694158500 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 --- 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 ca869942d693..7eb3a1f119d8 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.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595857; cv=none; d=zohomail.com; s=zohoarc; b=eNUCgFG1jG40JtNJjutHqE76bhGLhFxk4lpjVGBn4HlXNclGtMZzoDqaotkf1i6h3TK2VCyzliJaHntTqL+Iz7z99c5kB6VmVHJD9Hl8i5HlL5lsVrRJLWKC8/9TtBxDUFqqFkY92w/oE1XpzooeV3MHwkzMzwa/MlNxyQW6cnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595857; 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=2oxTmuSNbGknJOIWam5SQOKhN8ri960Ne582GEFVsMM=; b=DqPwxcRMTWOq8H7dLRsLI0Qf3pcQRkjhtlikJ3Mn9K9rV5yhJPbr/oEqczsPnDLJ2mqmUlSL9Y09CN/Lp4ReqtoCzOOy8tsGiJPvthKD1wX8dHbaxfK4QK6SNcZlDKpGXxttiPBL6mEPu9/71UB0hulibUyTOb5pYhv+0Fpuaao= 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 176659585714263.04564899994307; Wed, 24 Dec 2025 09:04:17 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192958.1512045 (Exim 4.92) (envelope-from ) id 1vYSH7-00058o-Gi; Wed, 24 Dec 2025 17:03:49 +0000 Received: by outflank-mailman (output) from mailman id 1192958.1512045; Wed, 24 Dec 2025 17:03:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSH7-00057M-5y; Wed, 24 Dec 2025 17:03:49 +0000 Received: by outflank-mailman (input) for mailman id 1192958; Wed, 24 Dec 2025 17:03:48 +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 1vYSH5-0003CV-TU for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:47 +0000 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [2a00:1450:4864:20::530]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 82f9be44-e0ea-11f0-b15c-2bf370ae4941; Wed, 24 Dec 2025 18:03:47 +0100 (CET) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-64b9230f564so6920102a12.1 for ; Wed, 24 Dec 2025 09:03:47 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:46 -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: 82f9be44-e0ea-11f0-b15c-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595827; x=1767200627; 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=2oxTmuSNbGknJOIWam5SQOKhN8ri960Ne582GEFVsMM=; b=WBFp+MejlcxPEu5iX2a9/1QxrXitFgaQp8+v4VYhsB7mfsrAoqLUn8nc4k8+mNybNz n5FHjL31C3CxKJd04/jZDjWtcAtsCHtAITFdB8DdmAu95yRB/SV9YI+/4ieTXC3UBqw8 I64ng9JDLrOZ/sNVwyHGaGwOzlCi6Dts56azHM7dqo6/SWWsNfAHjZOmzkOMGlpBsbNs LPu0s1r8vAwkJxTvH2G5wm9wd4QKHqZLFXEjdEMrewP3exh0Eh0AiGc13gCoLE/oNMPZ Q9ZRZ7ZrrvNf8Ls2DJS+5DcL2K9NQhMQMGRta+91UwZsYKbaFmitZSGQaJ6JLt29Ki0x 3kmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595827; x=1767200627; 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=2oxTmuSNbGknJOIWam5SQOKhN8ri960Ne582GEFVsMM=; b=ItFOWWw8JXEny6GuA10t7c41PMBoz8WTfzG5iLKKpjMbCZ3io1i1IB9bvj+6sX3Oik EZp6rxxJWQ6W+Yr+0chSYph9p5TZxuE/nvEQD8Pyy8zTMWMPC0f6VCHdMykUXZIZZ3ZA P50Wepkfw+nfWf1GPMewNpV6hItA6F8x1mPLFuYLyCvfxBt21Fum31TsHqzhv04xOVe6 UrvoOmx8EoERIHp4VA7+gBQprRSdb31lj8ebA7dhJrLxfr1M0EShUBHNiA5SYkEBLQRV o2q4f/2AwWrvGT5pTd6Mjz7/thIgEljiu4wu5lfLRPlNq84A3iUxTV4RSA0hbFfktKXG CoNw== X-Gm-Message-State: AOJu0Yw3DufBGAFO9KtPhqeg51MBtO6xZx1w0eqB3dxhrcPHBxnMHSbr TSSz4Qh29T9p+eUuDXKW51QZOTEyKDR1jhEljVR5UoDwp3mdp8OQiw649Bw0BQ== X-Gm-Gg: AY/fxX4YCO8du3VeLAPdjJHIKMQHf/Z3YGUQNFy4jmMu9g+TYy9sfnnTd9ScM1oKl8N zIB/V+24PwMDxTYcAxTdUa1qmxDhyObGPUqLKt8NFrrdQ1Hx5/VB9wNSnN4ZEi7VUn1HWJgCT46 aKMXe43sN6CRElNUH+b4boJwLrtj35n2zx+/RCD1SY3cPRSXfW6MNgmgQlJ3Wo5+/9FU7LwsI30 /pKfmPToJTLO9MFMHs7xcQaTswaiSdKo3B/aj+wt/VFvZbG7DUdZ+UUUo/bT+WslD9IT/8QT1Mo mEI6CM9Fsyjz850w+uJcsiN4GNpBSZGCTcPtPU4hMlIXCHaTjxrcXCgtV3wx6pLn4CkcPhCQeqn 0rNAVzeZSESBgGu+FaR7wGx1mtSxWnFJNfwqCCAqwnOB8hLOZLCRievnbfQpis6caUcqwai444q DKortep9dfdHu2kwbbig3yKxpF3FPMCrzWi4oIbyTPwPLQ/tSK0LYzd5FRU+kURqA4oQ== X-Google-Smtp-Source: AGHT+IF9n4wrdQHHFlIxEhxL5KnGCIoX4DKXTBGq6kQ9H7BVz9NiSLos6Vc2q4neRXUgjTMfN2mSTg== X-Received: by 2002:a17:907:608d:b0:b76:f57a:b0a7 with SMTP id a640c23a62f3a-b803705129emr2171318066b.31.1766595826555; Wed, 24 Dec 2025 09:03:46 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 11/15] xen/riscv: introduce ns_to_ticks() Date: Wed, 24 Dec 2025 18:03:24 +0100 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595857648158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/time.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xen/arch/riscv/include/asm/time.h b/xen/arch/riscv/include/asm= /time.h index 63bdd471ccac..3d013a3ace0f 100644 --- a/xen/arch/riscv/include/asm/time.h +++ b/xen/arch/riscv/include/asm/time.h @@ -29,6 +29,11 @@ static inline s_time_t ticks_to_ns(uint64_t ticks) return muldiv64(ticks, MILLISECS(1), cpu_khz); } =20 +static inline uint64_t ns_to_ticks(s_time_t ns) +{ + return muldiv64(ns, cpu_khz, MILLISECS(1)); +} + void preinit_xen_time(void); =20 #endif /* ASM__RISCV__TIME_H */ --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595856; cv=none; d=zohomail.com; s=zohoarc; b=afh1GLZFTkEt7WEK5TQBr6fvdDU1jKbD0I1upNGk+r21DtA1/MC1zIZXbFN7d3OmpNwk5CGQZwd/KxNAvfQc3G0fxjPQ6QAH/jhdPy6c/ftJgBjPZ6Ps4U1J593ooYtR4c/apBV3VrVVqPayRK2DVQkqul5zRQzr3oO9R3dE5vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595856; 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=+6n/yOP3bwyBec0cz6YcBSWP9PQeZ3Kxu2XaTVIzNOk=; b=brrwTaDkmFDEZmJsXgzqkUEnNDkfA7Dyx2jF++aJqIxkKgmO56OaFJW3Vgn3dfpy7+HVWleJP6pNEgqJgNwaClkb+oHzk6ngYq+Iwm19GCb5fxiC5W591ISbaWQKJLoq1Rprj1H7VQOMzhyRuUmDBdE1E/C443bm3k4TxqS/I+M= 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 1766595856520121.5568281039125; Wed, 24 Dec 2025 09:04:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192959.1512066 (Exim 4.92) (envelope-from ) id 1vYSHA-0005r1-0K; Wed, 24 Dec 2025 17:03:52 +0000 Received: by outflank-mailman (output) from mailman id 1192959.1512066; Wed, 24 Dec 2025 17:03:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSH9-0005pY-NR; Wed, 24 Dec 2025 17:03:51 +0000 Received: by outflank-mailman (input) for mailman id 1192959; Wed, 24 Dec 2025 17:03:49 +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 1vYSH7-0003CV-35 for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:49 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 839eed93-e0ea-11f0-b15c-2bf370ae4941; Wed, 24 Dec 2025 18:03:48 +0100 (CET) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-b7ffa5d1b80so761541766b.0 for ; Wed, 24 Dec 2025 09:03:48 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:47 -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: 839eed93-e0ea-11f0-b15c-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595828; x=1767200628; 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=+6n/yOP3bwyBec0cz6YcBSWP9PQeZ3Kxu2XaTVIzNOk=; b=RuDeQIWdrf9Wl6S/zUNA8ovCOt08MJiHa4Xe0IfBjlm1xAk3e1U5PPqjplZUQJMidT M+ApdGS24i7IDYAEME/EXL2uiHYM7g5ITxjPuf0pEcQsCWMYlT8jI0DEFdWOW8gr188v g2cDvOnXzriWRjRCQLH3JZ4r7SiBlZwfz1+kx1r/9aLg+ccYMMX1FJ948CXU7PVG09yP DTSvWvRg4gu0KjpocIkq/jDYE2Kju1M/MgQPv6m8N9bYOAUt67dmCTiaed0eJRzenKeB IomP8ZYz7w5NRC94IlURo5vCgZiHynePNLcodv2BGiCLyV1v9ZVgLhWwKWpdmpLAmRR7 IkmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595828; x=1767200628; 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=+6n/yOP3bwyBec0cz6YcBSWP9PQeZ3Kxu2XaTVIzNOk=; b=Xi4mwjrbhRU7QB86rDTiFYygg2uAUal8oR6MBBn7aaQ1IDR8V0pkTkeCcz06UQW9FQ 02WRQWo5N6pY89KryYU0DxRofG/kOYOB1XYJEfoeNbLBuUVSaarj1cOSeGop8jXlwzEd 8NLnBkd+nlv8zMneW2f+l0fozvspRp8PPCrHhs3j15nCCVUhM2Yfxv/TqagzRKqpyEhm R512dPcPEjhKECNxX2XAMB+ZiWHap3DhyW8BoVlHMWBxZMS5k5nNUAYanq9NLoWdeYRx v1tDo48tTXAq7Yku/9Yh/4eBSeg3hh//tayZpjbDaM6WzxqZSmhimRiRoKmPpLkpxCJK I6Mg== X-Gm-Message-State: AOJu0Yxr8U5teyWTQ6O5KFrDdgu7/cuBxwHNy+frWo774J9kDbvsnFBF Qeds/W+GpdpuaMY5nEDJSQQAIdRSVwndtw2uvsv1uAaoAfQ9Gzo9MwohRi8aAQ== X-Gm-Gg: AY/fxX65YyluJbOV6Mr1wzL7g1K4jJz23G+Yyq8llB1pa2SdxIJDlPlQDR530U/6XLq Aqtfpga9cx9XwKRARWE53SGdWBFs8rEDCOX4I+3hPNG9w+lgvwMHWSJFE5aKOOTPnwSNVc8fn9c 8Sgox9ZSDEHsVd+l9DewT36aL2ZR4Lknxd0zzrkglVuNPIKcvCvwzpnvA42ypzfmrsjBPiR5lma VKNPjSsEwbBKrmgKcjiAgCXOTbTd4ASv3U/VtmNSbAiYQFg12PpMZOs7eEEBZqokNVhXL3UrkKv joycJALXb+ZCcsFR4mwvi2E6Cx9mBN2epdnR9j08BHDsJCkejNB4l6xlpOPW6ekTwjfaBiiD2lg TeKB4zrE2n+Xb8nXZOM41vxMFxhGlQJE/EZqy5/ZC9PVtpZB4ZvU8xCPjXWDTQbWINAIu1wCLr1 cco+9uuActqFACYmste9FXIY8sH2zY3R5uldtUWD0sGQu7x42Eky3tepo= X-Google-Smtp-Source: AGHT+IGr4zgf4fLfUd2DDKV1cqCs5XI4c7sJYGYVApGkKJiqD3dWds42+WeKTJopx3ZyanuXcdWGLw== X-Received: by 2002:a17:907:7eaa:b0:b73:885b:7554 with SMTP id a640c23a62f3a-b80371d5059mr1936670666b.45.1766595827506; Wed, 24 Dec 2025 09:03:47 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 12/15] xen/riscv: introduce sbi_set_timer() Date: Wed, 24 Dec 2025 18:03:25 +0100 Message-ID: <84cf8fb2331614c6d0cc6e9030571f42bfc6d928.1766595589.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595857706158500 Content-Type: text/plain; charset="utf-8" Introduce pointer to function which points to a specific sbi_set_timer() implementation. It is done in this way as different OpenSBI version can have different Extenion ID and/or funcion ID for TIME extension. sbi_set_time() programs the clock for next event after stime_value time. This function also clears the pending timer interrupt bit. Introduce extension ID and SBI function ID for TIME extension. Implement only sbi_set_timer_v02() as there is not to much sense to support earlier version and, at the moment, Xen supports only v02. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/sbi.h | 17 +++++++++++++++++ xen/arch/riscv/sbi.c | 26 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/xen/arch/riscv/include/asm/sbi.h b/xen/arch/riscv/include/asm/= sbi.h index a88d3d57127a..c54dc7642ff1 100644 --- a/xen/arch/riscv/include/asm/sbi.h +++ b/xen/arch/riscv/include/asm/sbi.h @@ -33,6 +33,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 @@ -65,6 +66,9 @@ =20 #define SBI_SPEC_VERSION_DEFAULT 0x1 =20 +/* SBI function IDs for TIME extension */ +#define SBI_EXT_TIME_SET_TIMER 0x0 + struct sbiret { long error; long value; @@ -138,6 +142,19 @@ 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 after stime_value time. This function= also + * clears the pending timer interrupt bit. + * 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. + * + * This SBI call returns 0 upon success or an implementation specific nega= tive + * error code. + */ +extern int (*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..206ea3462c50 100644 --- a/xen/arch/riscv/sbi.c +++ b/xen/arch/riscv/sbi.c @@ -249,6 +249,26 @@ 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; + +#ifdef CONFIG_RISCV_64 + ret =3D sbi_ecall(SBI_EXT_TIME, SBI_EXT_TIME_SET_TIMER, stime_value, 0, + 0, 0, 0, 0); +#else + ret =3D sbi_ecall(SBI_EXT_TIME, SBI_EXT_TIME_SET_TIMER, stime_value, + stime_value >> 32, 0, 0, 0, 0); +#endif + + if ( ret.error ) + return sbi_err_map_xen_errno(ret.error); + else + return 0; +} + +int (* __ro_after_init sbi_set_timer)(uint64_t stime_value); + int sbi_remote_sfence_vma(const cpumask_t *cpu_mask, vaddr_t start, size_t size) { @@ -326,6 +346,12 @@ int __init sbi_init(void) sbi_rfence =3D sbi_rfence_v02; printk("SBI v0.2 RFENCE extension detected\n"); } + + if ( sbi_probe_extension(SBI_EXT_TIME) > 0 ) + { + sbi_set_timer =3D sbi_set_timer_v02; + printk("SBI v0.2 TIME extension detected\n"); + } } else panic("Ooops. SBI spec version 0.1 detected. Need to add support"); --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595853; cv=none; d=zohomail.com; s=zohoarc; b=TAVvyd4vwPIcWieJgyvYplqbr3JBayAvxa8knZrVhNJRt2996esK9HSOLZbRFp4KU5HguC5aD2/JFMW8vYRSt1wfvDi1ttH0Bz4fuZydgDXFr0JPyyRpWXdrNyIOzIUjEtRLCpX4tEsWhYa76fZBEMVMXtfyGXHJeQlIsMZXRYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595853; 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=LTO1cOoieIDYOdGun+r3UsYomgD550c5mWk/kyaU2a4=; b=W/raj6fHn4xJgfw4l2qUs9QtgPEuNVy+DdI1H82mgD2AN2ITFG6AP5XaDHTk/5/rUiJF7/2HQILi1bROpMF5yslVuzng601Kc/jyiHncECRha/KUexVpCM7Ublc6czkheD32wjXGtp6AHJRi+/GAgVvkp4OKFEh1brtkd+IxrTo= 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 1766595853541202.07488805422724; Wed, 24 Dec 2025 09:04:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192962.1512073 (Exim 4.92) (envelope-from ) id 1vYSHB-0006BI-JZ; Wed, 24 Dec 2025 17:03:53 +0000 Received: by outflank-mailman (output) from mailman id 1192962.1512073; Wed, 24 Dec 2025 17:03:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSHB-0006Aq-Dq; Wed, 24 Dec 2025 17:03:53 +0000 Received: by outflank-mailman (input) for mailman id 1192962; Wed, 24 Dec 2025 17:03:51 +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 1vYSH9-0003b7-CD for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:51 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 843d05c1-e0ea-11f0-9cce-f158ae23cfc8; Wed, 24 Dec 2025 18:03:49 +0100 (CET) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-b8052725de4so484940166b.0 for ; Wed, 24 Dec 2025 09:03:49 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:48 -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: 843d05c1-e0ea-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595829; x=1767200629; 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=LTO1cOoieIDYOdGun+r3UsYomgD550c5mWk/kyaU2a4=; b=QjCWp3CdV+DoLKh/ULA4Nmql8c3AMT7xvflbHKZf60687J2Ega7TvOjFuXRVhBKwvu 2dZ84oBhqRcBHVy1GhW3JdmgTQaent9xmWjWwJl71BOJg3V6SFYUvH98RB8PoomSBAeH CUD46v/aZ0jHiuoSS2iNIEB6otlck6DZb/bhQLW+5mdk2Pu4Fs2plpkguwkxGL8pS1qo pmHXKicH3paHkRNKTdJKTAf7PR8Uq/WDJ6z9yw2UkV5vjjKiygdY59evkePoD99s5BGg QUJmng3j6zmZ1noZzJBhGJgrjn2lkpcrP33OXrCmdOCr8xjeupvptoY9yP3m5iX4NBh2 C5SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595829; x=1767200629; 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=LTO1cOoieIDYOdGun+r3UsYomgD550c5mWk/kyaU2a4=; b=bcMUCwDg8n8Js++biMNE6oN6K7aVx42hwHK/LVsTn47uD9nIXRv8mmDLvPqqfmUw+l xIOtNtkYS2kKRmGSwc7HG2PGEHVbUoW83V7Aqyod2aI09ncCmX5a6eDb169ZhQP0lhz/ eKrCDnFDaThXVu3ULyvdMODed2itnvxnSoXEuaQgfwLxqWYUJ3TfnCb+y/K3qR37j9wi WEP+n+nmF2Tq8NsZLWxITP8c1zM6tqEy93PIjG98Z3rtrmsdnO/dbqP3RVbXarbn5Bk/ 8twfJma1DEhiPmxbf+JB/AyVFRSe2EepBkenZm9alIclOnsLnQxe+/Z4asdBjMBIActO lGoA== X-Gm-Message-State: AOJu0YyI5TZK2KszL/rgE46jH0ZaPrzH3Xh1dEn73aKQaSccwJPbL+N1 8h60/ZZ2mmCsZqKSo1ea5zts/Dl+lgzfFkGvmso7XZomYCm0f833PHdDmhWUaw== X-Gm-Gg: AY/fxX6kbyjuQG5LpDUXIxkpN8NJ91MYC5tNglgulrLik8eHG4NhZgvZDAs9YQSR0i/ H3ARay/VEUP1gBBLJijxGKLbqbKkglwnxbNwkNXbNgtO8btkN9+NNnA2a5YJh6ys+ZG3mzqjsja v0og+dMrWoSaUKGUZSThV9ojQBIvvlGKCqlVn2vdMpa7i4oTtmh/Uedk5FIG7Ea7X5RE0Fu4KN1 4RvlnfsBMUx1Jk12Wt0ekblPYkjOYnughCN3V70fZ9X/hbNFX0pyolBlVKOIXT+M2SxJ3axXmYn 55CeXXbLFs+/8ansT6YChmBnCGLWx9w2KJ3PRJEtlJ+0pnr8dm4+TADBFNeO9jy3ksIiZZHzQ4T q8VMZNKvJLqRuloninkeXDyaDmnohHe2ADa9Xmjq58pYD+jLqYBBYu5EaVRw5o+s0Cojw8u3vte zQBq6pwCUlBuk4ie3KQT4bRtEXw6/hLkLWFdPfUcP+bua16KArMzDAHfM= X-Google-Smtp-Source: AGHT+IHKRJ3z0OvQOS9JRD6aJDuls3Iyrs4+KvWrvJ864awhMFP6aCzaj6a9Ntxog0vGp55AnKTR8g== X-Received: by 2002:a17:907:96a7:b0:b73:8e7d:4fa3 with SMTP id a640c23a62f3a-b8037051234mr2000256366b.32.1766595828640; Wed, 24 Dec 2025 09:03:48 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 13/15] xen/riscv: implement reprogram_timer() using SBI Date: Wed, 24 Dec 2025 18:03:26 +0100 Message-ID: <43249171def325c49541ebdac141fe99d159b60f.1766595589.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595853685158500 Content-Type: text/plain; charset="utf-8" Enable Xen to handle timer reprogramming on RISC-V using standard SBI calls. Add a RISC-V implementation of reprogram_timer() to replace the stub: - Re-enable the function previously stubbed in stubs.c. - Use sbi_set_timer() to program the timer for the given timeout. - Disable the timer when timeout =3D=3D 0 by clearing the SIE.STIE bit. - Calculate the deadline based on the current boot clock cycle count and timer ticks. - Ensure correct behavior when the deadline is already passed. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/stubs.c | 5 ----- xen/arch/riscv/time.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index 68ee859ca1a8..d120274af2fe 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 e962f8518d78..53ba1cfb4a99 100644 --- a/xen/arch/riscv/time.c +++ b/xen/arch/riscv/time.c @@ -4,8 +4,12 @@ #include #include #include +#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 @@ -39,6 +43,33 @@ 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 timers */ + 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; + + /* Enable timer */ + csr_set(CSR_SIE, BIT(IRQ_S_TIMER, UL)); + + if ( (rc =3D sbi_set_timer(deadline)) ) + panic("%s: timer wasn't set because: %d\n", __func__, rc); + + return 1; +} + void __init preinit_xen_time(void) { if ( acpi_disabled ) --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595866; cv=none; d=zohomail.com; s=zohoarc; b=C1Brw2r7SSDZHAdqwQIJxUiMEt7ga5keBd+Cgct5W6Ag/BTfoB95rXOZ4JPlFomMymVpTGj2EpwLpnTSRTk0vcJvdC+iIgbfGT3tkR86F5/YrdfQAftEtR6uOqp1eaSbV8ZlMkR8fzczY+0UtRI1SdQ67ZQef/r/S0UvJsjbXp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595866; 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=xHV6F5htLdht8yZyJ/VwtJxiGcps1XdDoDnEGPAzWMU=; b=V6XCdSCu3DBhzxg28FgMOlqPU0aAb4ZBr/Zaw3FLxiM1PyNervY/FuFQNHszxTQNLzpxugkD973zuvTm86ntgF/aH8I0n6RWWI2zWeMA2M0mkwnJq1P6yve9FDaPPWWhR8w1/dtlwrEjHhr37jRtII9GLvjjoGWxhc0CMEuJm5E= 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 1766595866129933.1127910408997; Wed, 24 Dec 2025 09:04:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192964.1512085 (Exim 4.92) (envelope-from ) id 1vYSHC-0006Tm-UV; Wed, 24 Dec 2025 17:03:54 +0000 Received: by outflank-mailman (output) from mailman id 1192964.1512085; Wed, 24 Dec 2025 17:03:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSHC-0006TO-O8; Wed, 24 Dec 2025 17:03:54 +0000 Received: by outflank-mailman (input) for mailman id 1192964; Wed, 24 Dec 2025 17:03:52 +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 1vYSHA-0003b7-BD for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:52 +0000 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [2a00:1450:4864:20::535]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 84fad15a-e0ea-11f0-9cce-f158ae23cfc8; Wed, 24 Dec 2025 18:03:50 +0100 (CET) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-64b7a38f07eso7666681a12.0 for ; Wed, 24 Dec 2025 09:03:50 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:49 -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: 84fad15a-e0ea-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595830; x=1767200630; 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=xHV6F5htLdht8yZyJ/VwtJxiGcps1XdDoDnEGPAzWMU=; b=VYo6zE9bFqe4p5SdBZZ5wLqzpeT98++7+dfo3SZStcT0P5PnWsoegw0dxpZwtmLGW+ 275CsL0O5VIdPqYHt4DKMRW/LFDBepqg+Rz9ZQvbP3FWI/d+CydD33IcHwtYfrFBeRsb hODY3nOlkLT2ES5/wDbSz8NqZjhwoGJH8XYSNRSDkUCdKJcTcYNxsydczEwKUa2dKvFy oK0KEWfzE28cowcAkYWLUqRP5L++VhpZl8iOOPhyTE2jtBJB+Oz26Z7prT6S3kUaYrm/ tMlt4iQ/BTzqA5L0Hk6Q5/jMvlZITDxA0jJW3lC6Qknb8OB9InCdZm5GgPUIW7pPBpNa NRXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595830; x=1767200630; 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=xHV6F5htLdht8yZyJ/VwtJxiGcps1XdDoDnEGPAzWMU=; b=Yu9e0h6S3P8n/tW0dDW2UHuH8j0RsqEw6Q8dSlisjpojbFN0B/MXI0VE3qLNdrxdK/ bT1UJnzGS2zi7lGI8Yt2uCgeYbwT3+mjhhbo/o5HAt0yDF5Ut84Am8qd65SlqGrzQOQ1 bfjU+4t3dEwHPO4M0GP1xox3YDH29NhXpgs0CpHEpzonlxfRNM6uFBwGuupfpF31BmPU hrVNxsF1oYO1/nnH9+yVH6GcjpibtUKBGveS1wYJg1UlJSjPnOwhitajI1+OPYUt3Tag SGMcHkkbmgrXjiP7Y7Mw51m3HafCywqpONbwkpUigmbgGQiFjgko4takBC+NfZ0hZ9jq n3jA== X-Gm-Message-State: AOJu0YyYDs1iC65wRuuWMD1OBTox8qGp2fd6xRpn3H2/73XSRmvgxtrR tvUHyEM3Z9HAqUuVBLhnmTwgfI5nyimkwAzc8EUsugaF98lZY5ZN3Sspy7mKzg== X-Gm-Gg: AY/fxX4mLv7aa6IXJlYQO2RF1df4gNxn8ROYo+YJajzEcF2iPSQYANAbI1z3FPOUSvS c30uPqdwt4atMeCRuTYI22RnmABCu1bJo/C38/0ksqxKA4FQdgf+2Q3f/CI38pySwyrksiv6i3/ hqKxElESUK76OHDftPuSBo9/KqZUzF5chPCAXTe0kyYWD0N+/yUor9uhT56xGenU/bcR+xRAyzg mjX0BILplc96V8FkgXMTtavCxVrNS6aZC1ksaNVYUd6vmVqvw26Khy7UJA3QycSZUDcyoAxcnm8 Y06hTmF5g6LvkRqKPsajVx/gaLAs7F4XRd4cle56qGq7O63NicKtz94Nz792WhvGrJ3oAst9TFM nisH4aRNyF+GoBDgfCviShEKHWPT9pyG2qYTubnLRXNj2uo1XpJDotOTBzMFoWvKWyqtmCegKsP 5NEM5Yj616T1+GvSHt2u+nXFA2yO/v+w1CsEauGaMH/Vd+yzbTUzOsjJo= X-Google-Smtp-Source: AGHT+IGCPZmbf6qTvckKYI4m1PncXD0B+3c5MgjqTyQZjgApVhhOZGr5y4+53c6unhHJQPTgfm0J4Q== X-Received: by 2002:a17:907:97c5:b0:b6d:3fc9:e60c with SMTP id a640c23a62f3a-b8036f10dc8mr1977178266b.20.1766595829888; Wed, 24 Dec 2025 09:03:49 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 14/15] xen/riscv: handle hypervisor timer interrupts Date: Wed, 24 Dec 2025 18:03:27 +0100 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595867711158500 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 --- 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 e9c967786312..5fd12b1b21c3 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 #include #include @@ -108,6 +109,15 @@ static void do_unexpected_trap(const struct cpu_user_r= egs *regs) die(); } =20 +static void timer_interrupt(unsigned long cause) +{ + /* 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; @@ -148,6 +158,10 @@ void do_trap(struct cpu_user_regs *cpu_regs) intc_handle_external_irqs(cpu_regs); break; =20 + case IRQ_S_TIMER: + timer_interrupt(cause); + break; + default: break; } --=20 2.52.0 From nobody Thu Jan 8 12:32:50 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; 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=1766595855; cv=none; d=zohomail.com; s=zohoarc; b=CWO86YEVq9mR+xLbEhsKvtOJJNhTsZuVdkHegb2bFFLjYE16LIAu5ZUXuQS/N98K9wYOeHDrFgzW1ihdbFcXA1WeAPyo/9SJCsSbcTUkAlN4mIXAeKBjBcVOqVrmJqetiIWluMu1f6/PajxFY60AzQbpIDqesukgIbQT53dp84M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766595855; 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=R6hiHqwl+Z7Yh4uAVa4kDT1XiFyPodQcTQAl+wvwf0w=; b=C0lLZVAZMKuSlSxsVGDps+lPB9GFi5paUMzz0s/8mALdajUkFOtVToMGplyopzJ5+AW/w36N2BqhbHypk60bTV9tSOQFKQKB1wZGYRoqwpg8pJGgXcY1r2qetYyBDuYPbFANI5UOfe1YTb7a+hsWslA4WH2fwrByhBYKIAn5yvE= 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 1766595855904887.9364701329691; Wed, 24 Dec 2025 09:04:15 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1192965.1512090 (Exim 4.92) (envelope-from ) id 1vYSHD-0006aG-Gy; Wed, 24 Dec 2025 17:03:55 +0000 Received: by outflank-mailman (output) from mailman id 1192965.1512090; Wed, 24 Dec 2025 17:03:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vYSHD-0006ZK-6R; Wed, 24 Dec 2025 17:03:55 +0000 Received: by outflank-mailman (input) for mailman id 1192965; Wed, 24 Dec 2025 17:03:52 +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 1vYSHA-0003CV-P6 for xen-devel@lists.xenproject.org; Wed, 24 Dec 2025 17:03:52 +0000 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [2a00:1450:4864:20::52a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 85788b4e-e0ea-11f0-b15c-2bf370ae4941; Wed, 24 Dec 2025 18:03:51 +0100 (CET) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-64b8123c333so8864650a12.3 for ; Wed, 24 Dec 2025 09:03:51 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ab7f7bsm1798927766b.18.2025.12.24.09.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 09:03:50 -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: 85788b4e-e0ea-11f0-b15c-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766595831; x=1767200631; 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=R6hiHqwl+Z7Yh4uAVa4kDT1XiFyPodQcTQAl+wvwf0w=; b=XMALNBWcjzpRY9YOG2Vq53gnTeLAkbsnjDDqnc8OX9fy4TS7ewbiIou6BRaVcWHGor LnzI9weig+GZ8evxyotaZwrQ9PmCGhtptWul0MYTp1oV/PCYecw/b8pZd89SUfCUo/4a eRqUE+34U+ogkGkFJEcPE5A/QS7BOz1zZakNKrjuCI6klsxcDSJ+mNlFuXaOlNIV8LJB 5lY5skjnlavdjvsjNwmPzh6rUiJA0sso6p0kxTHfece16DkFJiM/70UNdWcYBo30g0Y8 MdE7QJoUMWImF2wHttUeuepV7jZfuk8hgQ0+M4Izc/ZCnOD/u8cvqPUCYyyjCxR22Q6o /b0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766595831; x=1767200631; 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=R6hiHqwl+Z7Yh4uAVa4kDT1XiFyPodQcTQAl+wvwf0w=; b=n6vBdwTYOmcoXWG0kPIcRv+f0jJSHS3lsUNkdS5X8F+BruBSSF1MwJTTJgFuuMq9d3 XSATp4Dq4gcdIxcjge5pmqcPFwBh3RXueUWaFLrpesDLV3vqy13ZwW8sseNm4IqphnuM sltECfcTtdwOGBZ3dYX93pwN+K7YQMfn1drUdF9njg1E2mbI81kbyJyGCZZBqpE6Q5cL yau4wu98H6YE5IkLTJqdqZpaSgrRy9uCNM7RoobMfiyp0p35mqtaQw7k50f/CqjPWgz8 5P1eIkzUOXpOyueehpuOLD4YPxK+KB2otEv6sy4HRBbLphZ5GBNyF5ezQJTndYX2HCjR 6GQg== X-Gm-Message-State: AOJu0YytEL9I6dhZPg53FIBVKb4y7oIMi0Pmy5gGw9GoeWgNL+KYQXpq ci0bvmQocoR+hvFhPZyrm7amaGHs1pim488dVfFjHMgP/TR4z+r3FzgqeAGkVw== X-Gm-Gg: AY/fxX7/9Ilnyr0mn+M51tMYOvZpJwg5vGvT9VJd+tM/yir9J/NyBSU1/TkQe4sL0D4 Y/fUSQBQmeeBQvWVxSVFA1Ajd9CO63k2Ednq+hL/XxE1QQe4wI8RQEbHkPPQDWssn6D1Wg4Y6gw VSlhdj9niqKbTLp+FGcKfrDysM+ieYDQXWKEBMmk9z7SdtFs7lbbPgQ5h+sA7nANeAXMUJk+y+x 1ODiFM1EDieMRqutsFZWuX3W0ERjKbINu6qS1geeXQg/IXeILZ+Wig7yWmixd5L0WnsRCxpTyK6 BejOd1dBPYsa8Zn8fZ7Pi6GyM9wa5DUDSOUWh78QYXOQQ4P0om5EtIY5Sp2GmwRqEO5fA2b0oy0 xIkVYPrmHVXglR/dGdByY5MsSHfWIcQtCQUxRH2A7nmJTsPD3mw+w0syMDsVnJ2D29JEfTVCUXp fZ2nBgTmsCzy4bOyuNB/bOd+pNV50DW8MnRPO0nWAbFJQaBUVS1S1XKLo= X-Google-Smtp-Source: AGHT+IFZDDoqLAbYXkPFbUkXKiCs+Oiox6J1OyndpU35+7MxaU1dUMcYECbzYLhVMAVG5FUxsi2txw== X-Received: by 2002:a17:907:1c27:b0:b75:7b39:847a with SMTP id a640c23a62f3a-b80372228e5mr2019898966b.60.1766595830803; Wed, 24 Dec 2025 09:03:50 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 15/15] xen/riscv: init tasklet subsystem Date: Wed, 24 Dec 2025 18:03:28 +0100 Message-ID: <7fd154cda45466ca4bd425bc05d191caccc7d96d.1766595589.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1766595857687158500 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(). After introducing sync_local_execstate(), the following linker issue occurs: riscv64-linux-gnu-ld: prelink.o: in function `bitmap_and': /build/xen/./include/xen/bitmap.h:147: undefined reference to `sync_vcpu_execstate' riscv64-linux-gnu-ld: ./.xen-syms.0: hidden symbol `sync_vcpu_execstate' isn't defined riscv64-linux-gnu-ld: final link failed: bad value Therefore, an implementation of sync_vcpu_execstate() is provided, based on the Arm code. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/domain.c | 23 +++++++++++++++++++++++ xen/arch/riscv/setup.c | 3 +++ xen/arch/riscv/stubs.c | 10 ---------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c index 8a010ae5b47e..574a5a34a389 100644 --- a/xen/arch/riscv/domain.c +++ b/xen/arch/riscv/domain.c @@ -141,6 +141,29 @@ 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) +{ + /* + * We don't support lazy switching. + * + * However the context may have been saved from a remote pCPU so we + * need a barrier to ensure it is observed before continuing. + * + * Per vcpu_context_saved(), the context can be observed when + * v->is_running is false (the caller should check it before calling + * this function). + * + * Note this is a full barrier to also prevent update of the context + * to happen before it was observed. + */ + smp_mb(); +} + int vcpu_set_interrupt(struct vcpu *v, const unsigned int irq) { /* diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 9b4835960d20..e8dbd55ce79e 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(); diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index d120274af2fe..2b3eb01bf03c 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.52.0