From nobody Fri Dec 19 17:12:01 2025 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1688992844; cv=none; d=zohomail.com; s=zohoarc; b=Pg6hy6yQ4S28jufVKqjALJIuYAEgESkGRaIwAP1xyDxoPBS87jrk9l3zTbKNkDlC4dQqDxLkFC5eKQZc1/Li2NXXGumGBaid+ju1voVBxjyHOpiysLwSB8Tg2bUWUggkLedXE6DCNU82bZmOsSC82QMCJyDDj054gyvPvP7w7dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688992844; 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=WgGOl//rQvyk/BHWp2tBHpvTrsJKIGooEhJoUipcS7s=; b=gtHQT3HDjyxkObOHvqjpKd62OSLAZpdiQPIjjednemU4uTAkiZVsWQsZKyMNZJJaU2Qg53R7QVeNrEUVfPM0iMkxjhcmhT8pXhvGxbR+IEcDiXDrq2qc8X6ey3wGiJy/daIYh2dNT9rbn459eaQennIBUs4BL51eMxrbOVH5/0s= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1688992844347407.92103038090545; Mon, 10 Jul 2023 05:40:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIq6V-0006b4-CU; Mon, 10 Jul 2023 08:34:59 -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 1qIq6Q-0005wz-Cz for qemu-devel@nongnu.org; Mon, 10 Jul 2023 08:34:54 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIq6M-00051H-OL for qemu-devel@nongnu.org; Mon, 10 Jul 2023 08:34:54 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-668711086f4so2802851b3a.1 for ; Mon, 10 Jul 2023 05:34:49 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id i126-20020a639d84000000b0055b44a901absm181559pgd.70.2023.07.10.05.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 05:34:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688992488; x=1691584488; 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=WgGOl//rQvyk/BHWp2tBHpvTrsJKIGooEhJoUipcS7s=; b=Zf6tUXEffmJ7uO6WR3krB/dabvkufw0Jjmza5C5N9E0LlHmHF+QUhyRziYePKyRTpV Rza0eRw6xRpTy6hIFvVt9gsqZECeR51uou6xEpWx9oYDGfeye436s9TbwzFt+rb8kasu kprm4d9Xjvb3LpT3WWrA5S2IboCbq+l3ho5GsilOokhQ+0Boo23+gheCuMGRhkzbqw9M xC87LadxyyXvNkUMCcg0qK+d8bmN6OO1j/WOOL3FEbozG9tf0h/4BxT4SZtjAOopNqNo 3hPBTNG81vve09PnDFzBVBLqQ9tSLnkoWavq9LEdH5BBXqf04fH77yYk2/COE4xJ4t+s /mow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688992488; x=1691584488; 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=WgGOl//rQvyk/BHWp2tBHpvTrsJKIGooEhJoUipcS7s=; b=gj37P6cJh+MTmfLvqWVxi3kZBe8lJvjjG800sfTHtOpTpaPAiZ4Yml3UXjkBPY1gxZ Iau5qpFlc/nwtwzL6/3LbCaSSSbGX0POJAJ4kPJd0ojY7wmMbQ6oWWzrn45+Fmii/I6L OQvd2T67+DWelBWe6EynRg4QDC0VmxSXOvxQfSC1BkMDyydEbfaIkaehxU3v0HC2DsCw 6eIE1DSfW5d6jXg8gBeesb+jFcv01tw4h6Nmx4N2BMwykXOqGqjsZbe9S6vQ8oEAIHwR iaNpgkgjSA7C0O6zUczhy9K+TlPvlkFkXPZQMbKvhXqdPQsZiRaIACXxCT6y4Pm3rAT6 NFpA== X-Gm-Message-State: ABy/qLaQ8E2JLmLOfMAZKJ3i72xRAjOFFm2iNcd3WyMmregmpjXMpMhh zPmAJwmtLk+oJpjiUJYuoni362wOqbpo0A== X-Google-Smtp-Source: APBJJlHqnzlehOULFR7xNlaOcXtgpbAkXVERsb6sRvVNsCtbrC9XD8myQrFEK3a82qKG5tEAQbrtSA== X-Received: by 2002:a05:6a20:3951:b0:12f:acc9:286 with SMTP id r17-20020a056a20395100b0012facc90286mr19396214pzg.17.1688992488276; Mon, 10 Jul 2023 05:34:48 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Daniel Henrique Barboza , Andrew Jones , Alistair Francis Subject: [PULL 43/54] target/riscv/kvm.c: init 'misa_ext_mask' with scratch CPU Date: Mon, 10 Jul 2023 22:31:54 +1000 Message-Id: <20230710123205.2441106-44-alistair.francis@wdc.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230710123205.2441106-1-alistair.francis@wdc.com> References: <20230710123205.2441106-1-alistair.francis@wdc.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=2607:f8b0:4864:20::433; envelope-from=alistair23@gmail.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1688992845302100001 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza 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 Message-Id: <20230706101738.460804-11-dbarboza@ventanamicro.com> Signed-off-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 f264286d51..0d19267010 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.40.1