From nobody Mon Feb 9 10:50:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1770037122; cv=none; d=zohomail.com; s=zohoarc; b=loKKbXs1oIccb5uuFON5wOYDd6019qMEUvv/MctWVw3x5iZYOwfOVNLfJxzP/CFNWCRcZCvv8OoNROkrRrx4BBUgo7CSlBSzRhfsQjYEVHYpQqfuBnsCUblFQAhzInTq/UkrLpNxesicyrLYb1VHzHmIehAy+ZROdvz5ijgCV50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770037122; 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=SCI6k1gY6hOQ2mQg++ELmk05/We6ArMoGY0m7U5btes=; b=Pg+nSqpJkjvAoCi8bqiMF0uAjfDurbZse4vTSAG8Bl3Qmc2z5XTsQJ37KE+vyEIYN1WMtdcbolaeWjkv+RFWkO88eWaSKhysuKNiEsEKGEAITflFSP2h2EJSwGcfgdFrkKFoRtvQkxk3FjztguAZTk8nJqP2A/mNkmOZ9KR5WgU= 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 1770037122172460.2966674200959; Mon, 2 Feb 2026 04:58:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1218574.1527411 (Exim 4.92) (envelope-from ) id 1vmtVW-000665-W8; Mon, 02 Feb 2026 12:58:22 +0000 Received: by outflank-mailman (output) from mailman id 1218574.1527411; Mon, 02 Feb 2026 12:58:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vmtVW-00065y-TS; Mon, 02 Feb 2026 12:58:22 +0000 Received: by outflank-mailman (input) for mailman id 1218574; Mon, 02 Feb 2026 12:58:22 +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 1vmtVW-00064e-AI for xen-devel@lists.xenproject.org; Mon, 02 Feb 2026 12:58:22 +0000 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [2a00:1450:4864:20::331]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d4897cc4-0036-11f1-b161-2bf370ae4941; Mon, 02 Feb 2026 13:58:12 +0100 (CET) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-480706554beso48047475e9.1 for ; Mon, 02 Feb 2026 04:58:12 -0800 (PST) Received: from fedora (user-109-243-67-101.play-internet.pl. [109.243.67.101]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-482dbd0f043sm107954345e9.7.2026.02.02.04.58.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Feb 2026 04:58:10 -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: d4897cc4-0036-11f1-b161-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770037091; x=1770641891; 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=SCI6k1gY6hOQ2mQg++ELmk05/We6ArMoGY0m7U5btes=; b=eVEIF2XKupOCYe1HF/FW+Ml5yT7nZQg28EDXtYJ4ZXqVIMuQwmrKBjiCiV2NCGjJK/ Jj4cdqRb8694nY2IQV5KTIHuDG7ehBfaAX3Qc8dcRi12y/zVII107HMvqOikkAj4EMp6 ejntekFx3AaTFLeRu1bBno+/xQAxPa7qs3Uav1uOcchlPAP+ybcxc9nX0pR95wUYPx0u oqmkeAusWfZxT/cOpePNSgfSgW+WrockMQTYct5qn+BmPPuLE/jS6UOASpi77O0JN8EK 23kwe95sC/gBOfpy0yR96PbJtSgG0TqqqjTf2i2ixiU0U+LrmXPGnC0NWKcoXMwiXHN2 hsFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770037091; x=1770641891; 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=SCI6k1gY6hOQ2mQg++ELmk05/We6ArMoGY0m7U5btes=; b=ADw+COdCO+Z0iOLzRib+j3/UKMclRB30cCUy0+29xfD/8fhnzg9BZgi6W5DNbbD70e aXf7I1izP3fpuZP3G67kziWvSjhIp0Rs46YFrHSVH7tbQ52TAdw9CJmLTDhUGw2QQpx3 23Y2cVO8g+igN+5EupTFGlreFFWQoXwAGefaQkBkoW30ec4AWxVi370nrGn3FLTQdo1J nUIRPqoN8+0W3AF1MfcmM1hif7E2VT84VBLt7UjS4jHkq3JxMi28+IY5Kbm51zRXIr6q EiUHA3Pmxzkt7PyklN+qsRcYXwpuQPMbKDNTbrgKL6yjvQArBvi6CwiKu1ooh+d815iY RC2g== X-Gm-Message-State: AOJu0YwszNlIvAUwQhspEnZDpbj+fKxw8jTB20WUCewGozKyymUAjSQ5 CFaTmMKVKHrN02wxNvXm4ZKOsxnpDTgT7EWUVzKjz/gmwruxtdcO4bHdUqHPKA== X-Gm-Gg: AZuq6aLzBIm8thjnNuwAT3iXBKddFeGgrEiiG7ALolS23QfxOwK8BlxUWWwv8w9utSz yB1RA8KT/Tb910mZtIh/VwAPYITplH2quM8zOyaQRg9gLgMCHfd9mSSirBZXYLJ7clNZDnfF7h7 edlLq1Av5NHDAuLc2QDeHLVGDGhVcejZC9yo8rckIYqarUHFb2j8sDXwD/cLTLYtWzBl/leJHl4 9R2C3f/GXFIsrovcoOW/1VbDZix8/IzA3F4VfV6m6Ahxd0cudsJSAPwiDeGd3Plbwl0HKp5ZqdU 1mTXz+o90D1v79nfN/sQZpay2sCefhOvlT9WdvGelF60ElWMCzFsA2cd3fzCa3T6f1EQw2jDo1G Rw9EYZgma3OV3RIIu2iSQ5fin4Y1RyKOCbpHvn3eY2sy+j/MOO1NotmIArqRrWqFZRAeNHli328 9GlnslKymE9AkJaU3DIz7l8r/AGm5b9vWCfqd9RJuy/jJDObwvp8wu7g== X-Received: by 2002:a05:600c:1d1b:b0:46e:59bd:f7d3 with SMTP id 5b1f17b1804b1-482db4939d8mr145289775e9.20.1770037091020; Mon, 02 Feb 2026 04:58:11 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Oleksii Kurochko , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 1/3] xen/riscv: introduce struct arch_vcpu Date: Mon, 2 Feb 2026 13:57:57 +0100 Message-ID: <98214488c67fac866ba519c368aef697da2d2bb6.1770036584.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: 1770037123210154100 Introdce struct arch_vcpu to hold RISC-V vCPU-specific state. The structure contains: - Guest-visible CSR state, used to save and restore vCPU execution state across context switches. hstatus isn't added here as it is already part of cpu_user_regs struct. - Callee-saved registers used to preserve Xen=E2=80=99s own execution con= text when switching between vCPU stacks. It is going to be used in the following way (pseudocode): context_switch(prev_vcpu, next_vcpu): ... /* Switch from previous stack to the next stack. */ __context_switch(prev_vcpu, next_vcpu); ... schedule_tail(prev_vcpu): Save and restore vCPU's CSRs. The Xen-saved context allows __context_switch() to switch execution from the previous vCPU=E2=80=99s stack to the next vCPU=E2=80=99s stack and= later resume execution on the original stack when switching back. During vCPU creation, the Xen-saved context is going to be initialized with: - SP pointing to the newly allocated vCPU stack - RA pointing to a helper that performs final vCPU setup before transferring control to the guest After the first execution of __context_switch(), RA naturally points to the instruction following the call site, and the remaining callee-saved registers contain the Xen register state at the time of the switch. Signed-off-by: Oleksii Kurochko --- Changes in V3: - Drop gp from struct {...} xen_saved_context as it ought to be stable acc= ross Xen so there is no need to be saved/restored and, also, it shouldn't be preserved across calls according to RISC-V ABI. - Update the comment above struct {...} xen_saved_context to make it more clear. - Drop CSRs and VCSRS comments in arch_vcpu as it is clear what kind of CSR it is based on the name. - Drop __cacheline_aligned for struct arch_vcpu as proper measurements can= 't be made now so it is hard to prove that the attribute really boost performance. --- Changes in v2: - Drop hstatus from struct arch_vcpu as it is stored in struct cpu_user_re= gs which will be stored on top of vCPU's stack. - Drop the comment above ra in xen_saved_context struct as it is potential= ly misleading. --- xen/arch/riscv/include/asm/domain.h | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/a= sm/domain.h index 316e7c6c8448..cca39effc1ba 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -24,6 +24,55 @@ struct arch_vcpu_io { =20 struct arch_vcpu { struct vcpu_vmid vmid; + + /* + * Callee saved registers for Xen's state used to switch from + * prev's stack to the next's stack during context switch. + */ + 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 ra; + } xen_saved_context; + + 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 + + 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; }; =20 struct paging_domain { --=20 2.52.0