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 9B297EB5954 for ; Wed, 11 Feb 2026 09:53:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1227145.1533483 (Exim 4.92) (envelope-from ) id 1vq6uB-0002qq-KT; Wed, 11 Feb 2026 09:53:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1227145.1533483; Wed, 11 Feb 2026 09:53:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vq6uB-0002qj-Fi; Wed, 11 Feb 2026 09:53:07 +0000 Received: by outflank-mailman (input) for mailman id 1227145; Wed, 11 Feb 2026 09:53:05 +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 1vq6u9-0002qb-Rs for xen-devel@lists.xenproject.org; Wed, 11 Feb 2026 09:53:05 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 752318d1-072f-11f1-9ccf-f158ae23cfc8; Wed, 11 Feb 2026 10:53:03 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-47ee3a63300so20652565e9.2 for ; Wed, 11 Feb 2026 01:53:03 -0800 (PST) Received: from [192.168.1.6] (user-109-243-67-101.play-internet.pl. [109.243.67.101]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4835d99497asm43207475e9.6.2026.02.11.01.53.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Feb 2026 01:53:02 -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: 752318d1-072f-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770803583; x=1771408383; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=93Gt2K4loBSrYHf5eCVNMdfs11JBUXF7r8yCMW6LFvo=; b=fuo6Z77Ho3O/DOw68cL/Sx03AaQCgRXYTUrXxsULncVK3Is3OLK1vhJ77YehYGaNKn MxoGAqlsj69Ro8mAgV8b/VAQyfeUoj5KDdfnBn+IRTftrraHkb4kkUsB0Csg/sbExExG Pk37t8cbYZ5xC/pGvu3oXUyOEJoIshX0ok0P8c6+wMIdsrytz4g29L/bw2CjYLzD5UiC kVldm4Coeu2Upbz9FB6+tzSjMQkmReTGQfK/3Ne/MtSlFWtgtCFC45TqGWCeeEjQk+LX 4Eij9Ivc5POxq0GtYVBkNklYIz8ELYQhky81zDY4xR7rM0xIpO3ar8kjoI6RvC/TKGf/ RtVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770803583; x=1771408383; h=content-transfer-encoding:in-reply-to: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=93Gt2K4loBSrYHf5eCVNMdfs11JBUXF7r8yCMW6LFvo=; b=otKfKFH0ZAM7bBsmslnEijQ7BsoURS2KChKT784Z2yomz5avXKUalJRAJDg3KWdqTk +NwIdmwuZ0UYS8+V6UhzBxjopP9y2vr4qIb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:483:4a95:66da with SMTP id 5b1f17b1804b1-4834a956702mr102820995e9.13.1770803582984; Wed, 11 Feb 2026 01:53:02 -0800 (PST) Message-ID: Date: Wed, 11 Feb 2026 10:53:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 04/16] xen/riscv: implement vcpu_csr_init() To: Jan Beulich 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: <212accf20032cc9cbe6c33752fa45de1c1284e3c.1770650552.git.oleksii.kurochko@gmail.com> Content-Language: en-US From: Oleksii Kurochko In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/11/26 10:44 AM, Jan Beulich wrote: > On 09.02.2026 17:52, Oleksii Kurochko wrote: >> --- a/xen/arch/riscv/domain.c >> +++ b/xen/arch/riscv/domain.c >> @@ -5,6 +5,72 @@ >> #include >> #include >> >> +#include >> +#include >> +#include >> +#include >> + >> +#define HEDELEG_DEFAULT (BIT(CAUSE_MISALIGNED_FETCH, U) | \ >> + BIT(CAUSE_FETCH_ACCESS, U) | \ >> + BIT(CAUSE_ILLEGAL_INSTRUCTION, U) | \ >> + BIT(CAUSE_BREAKPOINT, U) | \ >> + BIT(CAUSE_MISALIGNED_LOAD, U) | \ >> + BIT(CAUSE_LOAD_ACCESS, U) | \ >> + BIT(CAUSE_MISALIGNED_STORE, U) | \ >> + BIT(CAUSE_STORE_ACCESS, U) | \ >> + BIT(CAUSE_USER_ECALL, U) | \ >> + BIT(CAUSE_FETCH_PAGE_FAULT, U) | \ >> + BIT(CAUSE_LOAD_PAGE_FAULT, U) | \ >> + BIT(CAUSE_STORE_PAGE_FAULT, U)) >> + >> +#define HIDELEG_DEFAULT (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP) >> + >> +static void vcpu_csr_init(struct vcpu *v) >> +{ >> + register_t hstateen0; > There not being an initializer here, ... > >> + v->arch.hedeleg = HEDELEG_DEFAULT & csr_masks.hedeleg; >> + >> + vcpu_guest_cpu_user_regs(v)->hstatus = HSTATUS_SPV | HSTATUS_SPVP; >> + >> + v->arch.hideleg = HIDELEG_DEFAULT & csr_masks.hideleg; >> + >> + /* >> + * VS should access only the time counter directly. >> + * Everything else should trap. >> + */ >> + v->arch.hcounteren = HCOUNTEREN_TM; >> + >> + if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_svpbmt) ) >> + v->arch.henvcfg = ENVCFG_PBMTE & csr_masks.henvcfg; >> + >> + if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_smstateen) ) >> + { >> + if (riscv_isa_extension_available(NULL, RISCV_ISA_EXT_ssaia)) > (Nit: Style.) > >> + /* >> + * If the hypervisor extension is implemented, the same three >> + * bitsare defined also in hypervisor CSR hstateen0 but concern > (Nit: "bits are") > >> + * only the state potentially accessible to a virtual machine >> + * executing in privilege modes VS and VU: >> + * bit 60 CSRs siselect and sireg (really vsiselect and >> + * vsireg) >> + * bit 59 CSRs siph and sieh (RV32 only) and stopi (really >> + * vsiph, vsieh, and vstopi) >> + * bit 58 all state of IMSIC guest interrupt files, 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. >> + */ >> + hstateen0 = SMSTATEEN0_AIA | SMSTATEEN0_IMSIC | SMSTATEEN0_SVSLCT; >> + >> + /* Allow guest to access CSR_ENVCFG */ >> + hstateen0 |= SMSTATEEN0_HSENVCFG; > ... doesn't the compiler complain about the use of a possibly uninitialized > variable? The variable also wants to move to the more narrow scope. Hmm, for some reason it doesn't. Anyway, I agree that it would be better to move it to a narrower scope, since `hstateen0` exists only when RISCV_ISA_EXT_smstateen is supported. > >> @@ -32,6 +98,8 @@ int arch_vcpu_create(struct vcpu *v) >> v->arch.xen_saved_context.sp = (register_t)v->arch.cpu_info; >> v->arch.xen_saved_context.ra = (register_t)continue_new_vcpu; >> >> + vcpu_csr_init(v); >> + >> /* Idle VCPUs don't need the rest of this setup */ >> if ( is_idle_vcpu(v) ) >> return rc; > Do idle vCPU-s really need to have vcpu_csr_init() called for them? Agree, there is no any sense. I will move the call of vcpu_csr_init() after is_idle_vcpu() check. Thanks. ~ Oleksii