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.gnu.org (lists.gnu.org [209.51.188.17]) (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 2EFA8C0015E for ; Wed, 5 Jul 2023 21:43:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHAEj-0004tX-Iz; Wed, 05 Jul 2023 17:40:33 -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 1qHAEg-0004ry-So for qemu-riscv@nongnu.org; Wed, 05 Jul 2023 17:40:30 -0400 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHAEf-0001jo-8X for qemu-riscv@nongnu.org; Wed, 05 Jul 2023 17:40:30 -0400 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-565f3881cbeso3910708eaf.2 for ; Wed, 05 Jul 2023 14:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688593228; x=1691185228; 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=xIsSwZv0+6HkvL9zAUnCljJ7f9IbfLIHWBAcagEC0B4=; b=eJhWjy/ZHa2ZovU1YCzao0dSZVJx0p8bY2A8UdYSuve4l2rejW16lLDnEuQgVKbXMf gSkEHTfCvugbK8UaBEwfX8h7gXL+OgJVj9i5cCO1YmnAAkdXuKm2q7F1DmxZ0Y9B+Pgx nkhCO4j3BrE7KXcr9ppLXZSaJ2Ev5hHLA4cYli9iQi1Ck1SOwyiZ/YV40WUUiGCLM84G ckP2fye+fHN29/w61+lVtwzMui1friMsuccZ+oLyb3VgWGQVGIsk3siApHRcijj3jFmU y9ACwr9L3dkctDY03nUk92+IxfP77KHfFn+65/Ql1EoF6iBw8RsDELYvM3hRJQi8kSSN H10g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688593228; x=1691185228; 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=xIsSwZv0+6HkvL9zAUnCljJ7f9IbfLIHWBAcagEC0B4=; b=Hn5qSorQ5a/BzW6O4+E7CRcAWXU8GvAry1mz1msRVBG63C1F2wjEQz2y4x5OaD7xc6 gSXDPfThMb42+cfSH1Pu/IXAVVrHPKYBTspHk1oifvjDfU8hLdcVDz+CGOe+2tqqGdna +wOapWtKPNzB6fRL/N6d2qgdR452iGy/yUEy3VgCvSU4GIs1S8K1wSXoCwARl4ul0/RW p//I+TGgsoPiOfSKBuQ0jbqxV34wUpQ1GZ1ohhNzLN2qVerI+AQcJfokBDOx4CXechKp +ihdIVa01ndXU01/7cCRB/w2uk5+BRIZ5dNTkymgIxi2R+GICJNqmr1OaKtx+MDYdjCZ bdBQ== X-Gm-Message-State: ABy/qLaVDonwqCUvpKhPbJUBwzzqc7cvnd5pWztQwSgcpqRJvRwh7fA1 UgpVi/QJkcBOT1risNU3vjfI5g== X-Google-Smtp-Source: APBJJlEik44PPo6su8BGSqaSxNZ+yLxV0DdShklaH9kESaAvYjntFg/wIRplATxB6Do8CRy2Zy8U0g== X-Received: by 2002:a4a:4589:0:b0:565:cf26:5a10 with SMTP id y131-20020a4a4589000000b00565cf265a10mr67804ooa.0.1688593228202; Wed, 05 Jul 2023 14:40:28 -0700 (PDT) Received: from grind.. (201-69-66-110.dial-up.telesp.net.br. [201.69.66.110]) by smtp.gmail.com with ESMTPSA id m1-20020a4add01000000b0056665a16536sm70764oou.30.2023.07.05.14.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 14:40:27 -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 v8 08/20] target/riscv: handle mvendorid/marchid/mimpid for KVM CPUs Date: Wed, 5 Jul 2023 18:39:43 -0300 Message-ID: <20230705213955.429895-9-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230705213955.429895-1-dbarboza@ventanamicro.com> References: <20230705213955.429895-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::c2b; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc2b.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-riscv@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-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org Sender: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org After changing user validation for mvendorid/marchid/mimpid to guarantee that the value is validated on user input time, coupled with the work in fetching KVM default values for them by using a scratch CPU, we're certain that the values in cpu->cfg.(mvendorid|marchid|mimpid) are already good to be written back to KVM. There's no need to write the values back for 'host' type CPUs since the values can't be changed, so let's do that just for generic CPUs. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones Acked-by: Alistair Francis --- target/riscv/kvm.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index cd2974c663..602727cdfd 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -495,6 +495,33 @@ void kvm_arch_init_irq_routing(KVMState *s) { } +static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs) +{ + CPURISCVState *env = &cpu->env; + uint64_t id; + int ret; + + id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, + KVM_REG_RISCV_CONFIG_REG(mvendorid)); + ret = kvm_set_one_reg(cs, id, &cpu->cfg.mvendorid); + if (ret != 0) { + return ret; + } + + id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, + KVM_REG_RISCV_CONFIG_REG(marchid)); + ret = kvm_set_one_reg(cs, id, &cpu->cfg.marchid); + if (ret != 0) { + return ret; + } + + id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, + KVM_REG_RISCV_CONFIG_REG(mimpid)); + ret = kvm_set_one_reg(cs, id, &cpu->cfg.mimpid); + + return ret; +} + int kvm_arch_init_vcpu(CPUState *cs) { int ret = 0; @@ -513,6 +540,10 @@ int kvm_arch_init_vcpu(CPUState *cs) } env->misa_ext = isa; + if (!object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) { + ret = kvm_vcpu_set_machine_ids(cpu, cs); + } + return ret; } -- 2.41.0