Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6102E68165 for ; Tue, 17 Feb 2026 11:29:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1234868.1537976 (Exim 4.92) (envelope-from ) id 1vsJGD-0008KB-So; Tue, 17 Feb 2026 11:28:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1234868.1537976; Tue, 17 Feb 2026 11:28:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vsJGD-0008K4-Pd; Tue, 17 Feb 2026 11:28:57 +0000 Received: by outflank-mailman (input) for mailman id 1234868; Tue, 17 Feb 2026 11:28:57 +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 1vsJGD-0008Jy-CI for xen-devel@lists.xenproject.org; Tue, 17 Feb 2026 11:28:57 +0000 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [2a00:1450:4864:20::42b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d84d4777-0bf3-11f1-b164-2bf370ae4941; Tue, 17 Feb 2026 12:28:56 +0100 (CET) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-43767807da6so2909325f8f.2 for ; Tue, 17 Feb 2026 03:28:56 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48371a10cacsm176333415e9.4.2026.02.17.03.28.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Feb 2026 03:28:54 -0800 (PST) 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: d84d4777-0bf3-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1771327735; x=1771932535; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=AZwUkpipSK3w4UtqHK19BjXJ6/3zF0qpUaX3liVbzlk=; b=Oi8HSOP2NcTqtX8b4YBRyZVTAWQaOPoSvk1A/leZ9tJnB/GH4CxMmIsX0Dm8KpjUBR hdWuTtSm/anuoShh8PwkKgvZRpjVkv521nl8vhow/9FgHqVhvjHDm9P/qWBrkcDw9IxL SuuWq9lOuSpI+44CGRBDNMDFZWQabZskqcfEwGwf8hn/Af0brfrFCELwS2Mij6+qiDbd XZZBzQ9i6YAdNeoax9VQ09W5xLRWmvP6LwjmHZo0cMfFFiTtn4365CrWDHPwhwoLpbq4 3A+m9VHWMy/i045JTFmFydDzcoiBUP9jYhYYoTzsIkL5g0xG0NWlB45io+E2WJ86tyCp Eesg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771327735; x=1771932535; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AZwUkpipSK3w4UtqHK19BjXJ6/3zF0qpUaX3liVbzlk=; b=N/HbqLf1ppoQvnDGNry7aPqJByqgME7qwe9t+k/bDDNEGarDGEQPHTV6bzvbTT+XZg 2l9uLHtK7xWpoD/p/V5aB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907:b0:477:73e9:dc17 with SMTP id 5b1f17b1804b1-48373a79afbmr244401975e9.35.1771327735226; Tue, 17 Feb 2026 03:28:55 -0800 (PST) Message-ID: <06208b1b-9107-4ae6-acbf-c69659354da4@suse.com> Date: Tue, 17 Feb 2026 12:28:53 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 01/16] xen/riscv: implement arch_vcpu_{create,destroy}() To: Oleksii Kurochko Cc: Romain Caritey , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , xen-devel@lists.xenproject.org References: <42534cb6aabf25cf551a13ae1288045e1ac08f9e.1770999383.git.oleksii.kurochko@gmail.com> Content-Language: en-US From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <42534cb6aabf25cf551a13ae1288045e1ac08f9e.1770999383.git.oleksii.kurochko@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 13.02.2026 17:28, Oleksii Kurochko wrote: > 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. > > Add calle-saved registers to struct arch_vcpu which are used to preserve > Xen’s own execution context 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’s stack to the next vCPU’s 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. > > 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. > The prev argument is going to be set by RISC-V ABI (prev will be stored in > a0) when __context_swtich() will be introduced and called from > context_switch(). > > Update the STACK_SIZE definition and introduce STACK_ORDER (to align with > other architectures) for allocating the vCPU stack. Yet you don't really need STACK_ORDER, as you use vzalloc() (unlike in particular Arm, but also x86). If there's no expected other use of the constant, I'd suggest to omit it, to avoid the false impression that RISC-V is like (again in particular) Arm in regards to how the stack is being allocated. > --- /dev/null > +++ b/xen/arch/riscv/domain.c > @@ -0,0 +1,58 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include > +#include > +#include > +#include > + > +static void continue_new_vcpu(struct vcpu *prev) > +{ > + BUG_ON("unimplemented\n"); > +} > + > +static void __init __maybe_unused build_assertions(void) > +{ > + /* > + * Enforce the requirement documented in struct cpu_info that > + * guest_cpu_user_regs must be the first field. > + */ > + BUILD_BUG_ON(offsetof(struct cpu_info, guest_cpu_user_regs) != 0); > +} Nit: Generally we have this kind of function at the bottom of source files. > +int arch_vcpu_create(struct vcpu *v) > +{ > + int rc = 0; > + void *stack = vzalloc(STACK_SIZE); > + > + if ( !stack ) > + return -ENOMEM; > + > + v->arch.cpu_info = stack + STACK_SIZE - sizeof(struct cpu_info); Perhaps better sizeof(*v->arch.cpu_info), to connect lhs and rhs? > + v->arch.xen_saved_context.sp = (register_t)v->arch.cpu_info; > + v->arch.xen_saved_context.ra = (register_t)continue_new_vcpu; > + > + /* Idle VCPUs don't need the rest of this setup */ > + if ( is_idle_vcpu(v) ) > + return rc; I'd suggest "return 0" here to make clear it's a success path. Then possible uses of "rc" earlier in the function also won't affect this. With all of the adjustments (happy to carry out while committing, as long as you agree) Acked-by: Jan Beulich Jan