From nobody Mon Feb 9 23:15:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1687817365; cv=none; d=zohomail.com; s=zohoarc; b=XqTGWOV7Z5XMhY7CBeGw/6sCv55KRaoZUPSfNJTrOmVtVT5+Pk5blct5MVJukd8jPxcAx5Qkr0P+XkyJJP47+81qwZwGmDroul2xd4rd/x2AkETAw5xavl02XtxL80BdVUEX1EzCxBeEV4Rnd0Q3Vc16vUpi4aZuidmFXxl9WLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687817365; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nvD2DfqdT0yLrhg4B8fLoR2B1muCOTUleRsfoLErt80=; b=KlMJiin6QBgxdvAKXRrcokaTWyJR3VioL3dTVrN/gQJPwY6mjD16TrBGSVnS9PFXazLVzcPIMTuOOfwQ+KttHVJ19t8ayKtQ138DyoKjLUPVMOKJYQDXjackhJhCEEUYT3bog1Xk4E/j6w8h3RlOHohHLLWUF3YqRWyHqEuCya4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168781736586274.17991346426447; Mon, 26 Jun 2023 15:09:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qDuJO-0005A3-1i; Mon, 26 Jun 2023 18:03:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qDuIM-0002R4-1g for qemu-devel@nongnu.org; Mon, 26 Jun 2023 18:02:52 -0400 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qDuIH-0005xj-5n for qemu-devel@nongnu.org; Mon, 26 Jun 2023 18:02:48 -0400 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-1aa291b3fc9so3674916fac.0 for ; Mon, 26 Jun 2023 15:02:44 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (201-69-66-110.dial-up.telesp.net.br. [201.69.66.110]) by smtp.gmail.com with ESMTPSA id m12-20020a056870a10c00b001b03fbfa0c5sm1831419oae.39.2023.06.26.15.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 15:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1687816963; x=1690408963; 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=nvD2DfqdT0yLrhg4B8fLoR2B1muCOTUleRsfoLErt80=; b=UK4/5fWE+G6G0OsSQgs+OKGf8dvxnx0XXp31t2Ij0YLCsoMPU2S4WyGPOJ824nyaCR AZPQ6xwe3gHmtOdQa1ubPqE5M01b0JZ01zwKmPUpvOWaUoOl7VvZgtfnyvhU+S9/bG/X wuFH4ApC3et87iGVlXhnt16ZWaaw8dkymE+LXkqfmSuHLACkiyfEHP5snh6QdMfGG6cJ EM1Zs5uPYgUecuJi728dwz/Vwu256TFUkJAsf2VfglX/jyu4M7pZ0ek6yRasxu38bTh3 WImjdXlE/+3iVSbIB0pcBFNyC5iMqrPAe2qaJOA764Cz/aOH/LdB1l+Sz8YX71Rp6kMu dSLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687816963; x=1690408963; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nvD2DfqdT0yLrhg4B8fLoR2B1muCOTUleRsfoLErt80=; b=dVT8Ez7PFpFaW4uejXtHghHjCJHkwek31A3/m0QN86Z+cbu7Z/+qUPNdiKe3C79T78 z8wgZoi6IJP4O4nYtR4fsQNJEvEm1phUSkuP61f5Fp76HofbAgdMCS6CPEtrbuPILK+7 vOhTD18S1Qm1f6B3182anunmek1oCGqOpZLII9fe4TvvbwqA+tSY2W8K1dI0nXISJ0r4 q8fx18aYi6KZB7wIHwz4yoFXoiGCNJzAll31DMGUZo6Sg62Fz+1shcja5FcZn8KPpAm5 2wR/QFiRiOez0HK43E/58b9zIDvd1kKaGEWYidxCU+RcjZfS1VQbgmzOgD1NsfXAm/Xd g1EA== X-Gm-Message-State: AC+VfDzQGim3vaMLh/cMxgSWMLbfMVGSpfMd4i3urAD+zy4drevhySKa +YwFn6KQnm1M1hpzHGt/P7zJiXjg1nm7U6C2HHE= X-Google-Smtp-Source: ACHHUZ6GoYWCMUefLiL9RVWZsPIr6kgJ8GQkefli15eqevDMqqh7gniK8dOAZ0dpiYJmBWv9kTrU9Q== X-Received: by 2002:a05:6870:32cf:b0:1aa:f3:5b3b with SMTP id r15-20020a05687032cf00b001aa00f35b3bmr36330685oac.17.1687816963405; Mon, 26 Jun 2023 15:02:43 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, ajones@ventanamicro.com, Daniel Henrique Barboza Subject: [PATCH v4 10/19] target/riscv/kvm.c: init 'misa_ext_mask' with scratch CPU Date: Mon, 26 Jun 2023 19:02:00 -0300 Message-ID: <20230626220209.22142-11-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626220209.22142-1-dbarboza@ventanamicro.com> References: <20230626220209.22142-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:4860:4864:20::31; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x31.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1687817367357100010 Content-Type: text/plain; charset="utf-8" At this moment we're retrieving env->misa_ext during kvm_arch_init_cpu(), leaving env->misa_ext_mask behind. We want to set env->misa_ext_mask, and we want to set it as early as possible. The reason is that we're going to use it in the validation process of the KVM MISA properties we're going to add next. Setting it during arch_init_cpu() is too late for user validation. Move the code to a new helper that is going to be called during init() time, via kvm_riscv_init_user_properties(), like we're already doing for the machine ID properties. Set both misa_ext and misa_ext_mask to the same value retrieved by the 'isa' config reg. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones Acked-by: Alistair Francis --- target/riscv/kvm.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 602727cdfd..4d0808cb9a 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -396,6 +396,28 @@ static void kvm_riscv_init_machine_ids(RISCVCPU *cpu, = KVMScratchCPU *kvmcpu) } } =20 +static void kvm_riscv_init_misa_ext_mask(RISCVCPU *cpu, + KVMScratchCPU *kvmcpu) +{ + CPURISCVState *env =3D &cpu->env; + struct kvm_one_reg reg; + int ret; + + reg.id =3D kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, + KVM_REG_RISCV_CONFIG_REG(isa)); + reg.addr =3D (uint64_t)&env->misa_ext_mask; + ret =3D ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, ®); + + if (ret) { + error_report("Unable to fetch ISA register from KVM, " + "error %d", ret); + kvm_riscv_destroy_scratch_vcpu(kvmcpu); + exit(EXIT_FAILURE); + } + + env->misa_ext =3D env->misa_ext_mask; +} + void kvm_riscv_init_user_properties(Object *cpu_obj) { RISCVCPU *cpu =3D RISCV_CPU(cpu_obj); @@ -406,6 +428,7 @@ void kvm_riscv_init_user_properties(Object *cpu_obj) } =20 kvm_riscv_init_machine_ids(cpu, &kvmcpu); + kvm_riscv_init_misa_ext_mask(cpu, &kvmcpu); =20 kvm_riscv_destroy_scratch_vcpu(&kvmcpu); } @@ -525,21 +548,10 @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CP= UState *cs) int kvm_arch_init_vcpu(CPUState *cs) { int ret =3D 0; - target_ulong isa; RISCVCPU *cpu =3D RISCV_CPU(cs); - CPURISCVState *env =3D &cpu->env; - uint64_t id; =20 qemu_add_vm_change_state_handler(kvm_riscv_vm_state_change, cs); =20 - id =3D kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, - KVM_REG_RISCV_CONFIG_REG(isa)); - ret =3D kvm_get_one_reg(cs, id, &isa); - if (ret) { - return ret; - } - env->misa_ext =3D isa; - if (!object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) { ret =3D kvm_vcpu_set_machine_ids(cpu, cs); } --=20 2.41.0