From patchwork Tue May 30 19:46:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787937 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=nbbOZJSq; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2xb3GzRz20Q5 for ; Wed, 31 May 2023 05:48:01 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45Im-0006Sn-VB; Tue, 30 May 2023 15:46:40 -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 1q45Il-0006RA-34 for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:39 -0400 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45Ij-0004F9-GV for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:38 -0400 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-19f6211d4e1so1849016fac.1 for ; Tue, 30 May 2023 12:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685475996; x=1688067996; 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=QS1DGxToErlST7DIPVOrtAe0U4ury3VVrsLqKkjgUmA=; b=nbbOZJSq0xLiNLRIK/EEnwTLSUJ+rz+ZkjI8g5numGuCnlCHsp+SNeYttB2OMf1ZWY x5/CuRNkz5gfieGqRnqV9g5YFCTN3HhOVXEsG1Bp4kBT7q/IfvdzvHZJKtJko6HUB2Dd xG8xYYv82yOu99mXCNHXj1qUeiNKtyWgdjynLIXEgIKg/TOetXdPnr4Sx4MkDI102QHU 84++znJOndBv5Yh1XcmhZoeVNc/j4YScZiCN+QZQq1I4/UzZHbBtlU4atNjytcNGJtE5 UDFhehEKZdURoDxIMuyE3vk0Igg+d3w0EhvMn36yVZNWtPttQFEFzi9vKNwY53FndERc ftkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685475996; x=1688067996; 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=QS1DGxToErlST7DIPVOrtAe0U4ury3VVrsLqKkjgUmA=; b=E2NDOJvdbDfmhYY/dPig8ejob9FUhoJj/6KNUqY4LdpLD+qm2rmtTvARuXsSWA+Bnf vHdlP0kHrJe9R5R5xTEiQLxFnSID/97nd+fqB+4LC1gyMfgqYfunR/SVyS2Jjt3v8H1C Daqcmfx53nJXX5aVFjQa9NLP4j+2dBvBpBr3NXdmQPjKXCf2N5aHPrYe7JrgibUiqAjy cjbnI5gmf9pv0i9psivCMq1hcaZL+5JV4nwcDnnyZdgYIoycQWNofg8ZMfRlSPUcr/H4 IJmYgLE71NiSDZDBoShoeGrgkytsWZlVFRhU/5i08/diI+3Hv74MAG9fGmSmF22ZV+7w Seqw== X-Gm-Message-State: AC+VfDyBTBFjKMdjtadesuO6Mn2RPDiFv3E2EkZIC37Pvxc2x0NTX3u+ QtYJprG5gV8i58ISYrussnaR7mzug1RI405EX0k= X-Google-Smtp-Source: ACHHUZ4r0WWYtsm5Bl52e9SbsZ/Vt+3ACC3A8dNkTmlqcZBTdpTMv4iJ4V2Jjabi7//3qQnjHBF8nQ== X-Received: by 2002:a05:6870:a2d5:b0:19e:ae04:95ae with SMTP id w21-20020a056870a2d500b0019eae0495aemr1870683oak.40.1685475996014; Tue, 30 May 2023 12:46:36 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:46:35 -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, Daniel Henrique Barboza Subject: [PATCH 01/16] target/riscv: skip features setup for KVM CPUs Date: Tue, 30 May 2023 16:46:08 -0300 Message-Id: <20230530194623.272652-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2a; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x2a.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org As it is today it's not possible to use '-cpu host' if the RISC-V host has RVH enabled. This is the resulting error: $ sudo ./qemu/build/qemu-system-riscv64 \ -machine virt,accel=kvm -m 2G -smp 1 \ -nographic -snapshot -kernel ./guest_imgs/Image \ -initrd ./guest_imgs/rootfs_kvm_riscv64.img \ -append "earlycon=sbi root=/dev/ram rw" \ -cpu host qemu-system-riscv64: H extension requires priv spec 1.12.0 This happens because we're checking for priv spec for all CPUs, and since we're not setting env->priv_ver for the 'host' CPU, it's being default to zero (i.e. PRIV_SPEC_1_10_0). In reality env->priv_ver does not make sense when running with the KVM 'host' CPU. It's used to gate certain CSRs/extensions during translation to make them unavailable if the hart declares an older spec version. It doesn't have any other use. E.g. OpenSBI version 1.2 retrieves the spec checking if the CSR_MCOUNTEREN, CSR_MCOUNTINHIBIT and CSR_MENVCFG CSRs are available [1]. 'priv_ver' is just one example. We're doing a lot of feature validation and setup during riscv_cpu_realize() that it doesn't apply KVM CPUs. Validating the feature set for those CPUs is a KVM problem that should be handled in KVM specific code. The new riscv_cpu_realize_features() helper contains all validation logic that are not applicable to KVM CPUs. riscv_cpu_realize() verifies if we're dealing with a KVM CPU and, if not, execute the new helper to proceed with the usual realize() logic for all other CPUs. [1] lib/sbi/sbi_hart.c, hart_detect_features() Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Reviewed-by: Andrew Jones --- target/riscv/cpu.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 938c7bd87b..72f5433776 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -331,6 +331,15 @@ static void set_satp_mode_default_map(RISCVCPU *cpu) } #endif +static bool riscv_running_KVM(void) +{ +#ifndef CONFIG_USER_ONLY + return kvm_enabled(); +#else + return false; +#endif +} + static void riscv_any_cpu_init(Object *obj) { RISCVCPU *cpu = RISCV_CPU(obj); @@ -1295,20 +1304,12 @@ static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) } } -static void riscv_cpu_realize(DeviceState *dev, Error **errp) +static void riscv_cpu_realize_features(DeviceState *dev, Error **errp) { - CPUState *cs = CPU(dev); RISCVCPU *cpu = RISCV_CPU(dev); CPURISCVState *env = &cpu->env; - RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev); Error *local_err = NULL; - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } - riscv_cpu_validate_misa_mxl(cpu, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); @@ -1354,6 +1355,28 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } #endif +} + +static void riscv_cpu_realize(DeviceState *dev, Error **errp) +{ + CPUState *cs = CPU(dev); + RISCVCPU *cpu = RISCV_CPU(dev); + RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev); + Error *local_err = NULL; + + cpu_exec_realizefn(cs, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } + + if (!riscv_running_KVM()) { + riscv_cpu_realize_features(dev, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } + } riscv_cpu_finalize_features(cpu, &local_err); if (local_err != NULL) { From patchwork Tue May 30 19:46:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787939 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=F6iey4xN; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2xr0Cmbz20Q4 for ; Wed, 31 May 2023 05:48:16 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45Ip-0006Uj-Lh; Tue, 30 May 2023 15:46:43 -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 1q45In-0006Ty-Vt for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:41 -0400 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45Im-0004Fj-E9 for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:41 -0400 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-19f7f41d9dcso1643953fac.2 for ; Tue, 30 May 2023 12:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685475999; x=1688067999; 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=TtJS64pZP8Myq3aHHVtCKuG+G8XVLuM7yaFoUAKFiIg=; b=F6iey4xNUKNa0z8T1UGiqJkETmPugmnjuo8iKQjCarmc8dM983WsKqHGwQWoqzvRoj OutY7qiBk8EmhsoiQLWWxnxQIQd0NXb2MACooBTPfIiAx4/yy8DIhGka5rPZWiKDyeiL pM+hejkujXhtsulekyrgCntfx5xyXdLeKNKHGsZaP1ErngCEACJMMB+IX1uRB6bREDxp Stem3vT6reh6CFZ5Bb+dtFhUKzMeN0lkuKwu4fjnfKgyK6cznfd8yhoICH0fs2ISGnXT LZdRwTe/esGz5zXKGy1cNGGrxWJKsLdqCm3DXohiwt9KZs4uT2bwarKN1JJ9vVv4zhWJ QUfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685475999; x=1688067999; 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=TtJS64pZP8Myq3aHHVtCKuG+G8XVLuM7yaFoUAKFiIg=; b=OFAWjrRxkzID5AqfM87H72Yb6pRfq8wTiEAFwL6Er/ncKsxGwHDIFPgVuxVOboXs/I O/RH3VZPALwMARwAdV3EOPnX0omv0WHE8sdrBGvTN5fTYEkr9NK15tzRarMIFtV8S593 AFguyqTZxo2G0w/FYbwPHId1cSfKJkH8ufPyGcsnDUWVe1PNxrm68YZWuy+Aiuxo/4qI N/WF6hpugy64slXJ9tOcuCFG4STdAQqzqV07lFIdomHXz4o7p9P7m3ws2OFrAv2LFe2g 0hlG/g+BqVF/0YG5oOZmcQIkpHVi+hOuk9kwPDWdWi0XE6lVPiBMrxa80u+eum+/ddI2 uf9Q== X-Gm-Message-State: AC+VfDxFLweLpfJFUjM1+xeyQ3Reg1KEDq9qGLwY9rYTgPJ9FFCBKGhR FcEFZRjerswh6lkyP/2fXL98ST6DDw8suK7x8Ak= X-Google-Smtp-Source: ACHHUZ7Na67M5A9vtLlovDqnH8GofqEl+Jo8BQqS2kiFd3QlJIEAOOOzGEDvnqOmL7Ne5sNoWY3hHg== X-Received: by 2002:a05:6870:32c2:b0:19f:5d99:fc75 with SMTP id r2-20020a05687032c200b0019f5d99fc75mr1530927oac.2.1685475999144; Tue, 30 May 2023 12:46:39 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:46:38 -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, Daniel Henrique Barboza Subject: [PATCH 02/16] hw/riscv/virt.c: skip 'mmu-type' FDT if satp mode not set Date: Tue, 30 May 2023 16:46:09 -0300 Message-Id: <20230530194623.272652-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2a; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x2a.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The absence of a satp mode in riscv_host_cpu_init() is causing the following error: $ sudo ./qemu/build/qemu-system-riscv64 -machine virt,accel=kvm \ -m 2G -smp 1 -nographic -snapshot \ -kernel ./guest_imgs/Image \ -initrd ./guest_imgs/rootfs_kvm_riscv64.img \ -append "earlycon=sbi root=/dev/ram rw" \ -cpu host ** ERROR:../target/riscv/cpu.c:320:satp_mode_str: code should not be reached Bail out! ERROR:../target/riscv/cpu.c:320:satp_mode_str: code should not be reached Aborted The error is triggered from create_fdt_socket_cpus() in hw/riscv/virt.c. It's trying to get satp_mode_str for a NULL cpu->cfg.satp_mode.map. For this KVM 'cpu' we would need to inherit the satp supported modes from the RISC-V host. At this moment this is not possible because the KVM driver does not support it. And even when it does we can't just let this broken for every other older kernel. Skip the 'mmu-type' FDT node if there's no satp_mode set. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 4e3efbee16..8aa907e81f 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -243,13 +243,13 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, s->soc[socket].hartid_base + cpu); qemu_fdt_add_subnode(ms->fdt, cpu_name); - satp_mode_max = satp_mode_max_from_map( - s->soc[socket].harts[cpu].cfg.satp_mode.map); - sv_name = g_strdup_printf("riscv,%s", - satp_mode_str(satp_mode_max, is_32_bit)); - qemu_fdt_setprop_string(ms->fdt, cpu_name, "mmu-type", sv_name); - g_free(sv_name); - + if (cpu_ptr->cfg.satp_mode.supported != 0) { + satp_mode_max = satp_mode_max_from_map(cpu_ptr->cfg.satp_mode.map); + sv_name = g_strdup_printf("riscv,%s", + satp_mode_str(satp_mode_max, is_32_bit)); + qemu_fdt_setprop_string(ms->fdt, cpu_name, "mmu-type", sv_name); + g_free(sv_name); + } name = riscv_isa_string(cpu_ptr); qemu_fdt_setprop_string(ms->fdt, cpu_name, "riscv,isa", name); From patchwork Tue May 30 19:46:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787945 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=pRvDRNbt; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2yr0qZ0z20Q4 for ; Wed, 31 May 2023 05:49:08 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45Ir-0006VK-KD; Tue, 30 May 2023 15:46:45 -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 1q45Ir-0006V9-4Q for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:45 -0400 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45Ip-0004G7-IQ for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:44 -0400 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-19a308a045aso2262003fac.0 for ; Tue, 30 May 2023 12:46:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476002; x=1688068002; 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=I4/mqWkXzyOSAPWFPm2dUxbXJBqNOFYv851p+8rCBTo=; b=pRvDRNbtbLCP5k7Rg3E8rpvX0kkiwD9B58bS59yCsavUbUSlYCS1J2jL0UfapzUKi/ DgonOL8X+4iFl4bMvLrtCdBa3QuhL0073vcGj1obgZfqn1AvxxhJa5H09BmjWdScYBTu sMkj8N58HgkFeIuPagWyz0C3kxivZ92ahedkN9ngiedBd3x5F33hM7LcAXf/b/WD8G7Y PXQvfAAfZ1FMQEhc8UXxXiYcK4mCX4ELEW5+nkxPFanlPhzwLuKi55Tl7de7LAUUVX16 SP5IpD/yAhfTJ5Nc8EQc5AfA7bMnaFpVrwV4uO61n01a3Cw+CiWjEvvX4XtaLwMwEBz0 SxIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476002; x=1688068002; 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=I4/mqWkXzyOSAPWFPm2dUxbXJBqNOFYv851p+8rCBTo=; b=LE5rNep1Awbm/39U0roIF9suQ8dH9g0/aDVWlg6XT8VgxrnhQKJjwY6/PveKX5jmvw wIPTa8fND6ncRKJ2ku+UP2iW2dkBJpn9+9hwisyoYyVrRnjdN+teHDwokZHkmo2h+Ohy Tsf2McUitOcXridAxAivQ1sCQnyfL9UpCO6FcvysVKWLhuD5FiIDcYxTFQTpYkxMltZT ZGxexGqAOpKgpPSk0Je60UUsDD+lekchdbg1FvVlWB1rMWbFOKBYvuHSDeEe5I0G9M2u CFbOaHcoyVor98x+gmBzTf7XvCn/dgM1daNLoZ5HbgI2ewljkM/X2nG+gJu9KL6u/Xpp jEAQ== X-Gm-Message-State: AC+VfDx82xDAT/Tp4Vku/FHic/Dn+Pn0anEGQLnWDgzKlYocMgnyswYz 2x+YVRe0rQ5aCSvvGjxdC4H41fE0m8/kzfaoJbc= X-Google-Smtp-Source: ACHHUZ5VYxf4vI88JF0CBIRACGCOzLby6BMmNC6Z/yk/K6+HWSmvmt8XuFrxYGIG7wIwTNpbiJApfQ== X-Received: by 2002:a05:6870:c803:b0:192:cb3d:c069 with SMTP id ee3-20020a056870c80300b00192cb3dc069mr1246884oab.2.1685476002102; Tue, 30 May 2023 12:46:42 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:46:41 -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, Daniel Henrique Barboza Subject: [PATCH 03/16] target/riscv/cpu.c: restrict 'mvendorid' value Date: Tue, 30 May 2023 16:46:10 -0300 Message-Id: <20230530194623.272652-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2b; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x2b.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We're going to change the handling of mvendorid/marchid/mimpid by the KVM driver. Since these are always present in all CPUs let's put the same validation for everyone. It doesn't make sense to allow 'mvendorid' to be different than it is already set in named (vendor) CPUs. Generic (dynamic) CPUs can have any 'mvendorid' they want. Change 'mvendorid' to be a class property created via 'object_class_property_add', instead of using the DEFINE_PROP_UINT32() macro. This allow us to define a custom setter for it that will verify, for named CPUs, if mvendorid is different than it is already set by the CPU. This is the error thrown for the 'veyron-v1' CPU if 'mvendorid' is set to an invalid value: $ qemu-system-riscv64 -M virt -nographic -cpu veyron-v1,mvendorid=2 qemu-system-riscv64: can't apply global veyron-v1-riscv-cpu.mvendorid=2: Unable to change veyron-v1-riscv-cpu mvendorid (0x61f) Signed-off-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones --- target/riscv/cpu.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 72f5433776..bcd69bb032 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1723,7 +1723,6 @@ static void riscv_cpu_add_user_properties(Object *obj) static Property riscv_cpu_properties[] = { DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true), - DEFINE_PROP_UINT32("mvendorid", RISCVCPU, cfg.mvendorid, 0), DEFINE_PROP_UINT64("marchid", RISCVCPU, cfg.marchid, RISCV_CPU_MARCHID), DEFINE_PROP_UINT64("mimpid", RISCVCPU, cfg.mimpid, RISCV_CPU_MIMPID), @@ -1810,6 +1809,32 @@ static const struct TCGCPUOps riscv_tcg_ops = { #endif /* !CONFIG_USER_ONLY */ }; +static bool riscv_cpu_is_dynamic(Object *cpu_obj) +{ + return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; +} + +static void cpu_set_mvendorid(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + bool dynamic_cpu = riscv_cpu_is_dynamic(obj); + RISCVCPU *cpu = RISCV_CPU(obj); + uint32_t prev_val = cpu->cfg.mvendorid; + uint32_t value; + + if (!visit_type_uint32(v, name, &value, errp)) { + return; + } + + if (!dynamic_cpu && prev_val != value) { + error_setg(errp, "Unable to change %s mvendorid (0x%x)", + object_get_typename(obj), prev_val); + return; + } + + cpu->cfg.mvendorid = value; +} + static void riscv_cpu_class_init(ObjectClass *c, void *data) { RISCVCPUClass *mcc = RISCV_CPU_CLASS(c); @@ -1841,6 +1866,10 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; cc->tcg_ops = &riscv_tcg_ops; + object_class_property_add(c, "mvendorid", "uint32", NULL, + cpu_set_mvendorid, + NULL, NULL); + device_class_set_props(dc, riscv_cpu_properties); } From patchwork Tue May 30 19:46:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787946 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=GixwYjui; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2ys63gJz20Q4 for ; Wed, 31 May 2023 05:49:09 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45Iv-0006Wh-NJ; Tue, 30 May 2023 15:46:49 -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 1q45It-0006Vw-Sn for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:47 -0400 Received: from mail-oa1-x33.google.com ([2001:4860:4864:20::33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45Is-0004GR-CG for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:47 -0400 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-19f45faedfbso2513354fac.0 for ; Tue, 30 May 2023 12:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476005; x=1688068005; 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=v0QgfmmOTQ2l/zD/WXht/LWS0Z7ownvCJ8eez0uwFsI=; b=GixwYjuiNoxXAZYmdnS7x+OTU39Bn6VYOzeoDUkelxXfxxxmHJEMA29Y0VIDcALOCy PNHliPfhbkXyHj9/Gcz5iYcaXkjGnnVzm7zbit1UTnELepH4A6DsYm4NouRMbzzr2f2H FNENap3bYWj+LnXG/fiixJ/tcVKvZ+h8HwwzakEMcWKQ3OdjgcchfBCqQRKkvYNP/sJt 0RLQ32JzLZ6WW+iuWayYPFSQue7VH7ZlXAEuncvd0nn10VmCklfYBg4roKRV4aJAUdXR 6VfvLmYSbRIKlban/DppVkRGNo5/ONU293WF1tTNjMzgr8LIPZ0incq3TuHkcF0phCfF rr9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476005; x=1688068005; 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=v0QgfmmOTQ2l/zD/WXht/LWS0Z7ownvCJ8eez0uwFsI=; b=Qx4gXw/mNSX/ZHi9jwTfNgs4omBPA4uxo2JpKMRcPUkKb65+zwgFd1uZJiEhIK7zFL c2uIBE7+fkJdnXOa9O/Z8pLr4R8cPfSvH+VndVxich5Nh+MvUTOGdvbxJI+prbB9laEl PBEfWjdNBK9qiU5rNCbSDti8Dv4Z22pXp1tYswZjJEA3+08EB/lkyaGxYlUW+wFDvllU ml0TR+RAuxLqiwfiuiuSNnP3i90TBdXdVa/T9QNtlidGfV4puazCBcPTnj1OrH3VLvRM d/P/+Bdx303i8FKWh7xDMKp2mj59213CXklEDBVHFIHoAoA3tudghKDZAJLoXLX/rqWR wgAQ== X-Gm-Message-State: AC+VfDwavrQtbvN9EM0qxL3lOe6GuW/xmzmI2Mxtb4/ZwRUM5C7uE3PT 6tfxrcOTnadrJ0j0ilUruaKp0N3kcfr6ITHqLdk= X-Google-Smtp-Source: ACHHUZ68gt95iYDqZZtS/8qDTX4CCN4ERpOljBoCOerLM8H0UVIdjmD0z3+kVB4M75vMlnDdx/YhfQ== X-Received: by 2002:a05:6870:e884:b0:19f:3567:a0b5 with SMTP id q4-20020a056870e88400b0019f3567a0b5mr1973103oan.34.1685476005140; Tue, 30 May 2023 12:46:45 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:46:44 -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, Daniel Henrique Barboza Subject: [PATCH 04/16] target/riscv/cpu.c: restrict 'mimpid' value Date: Tue, 30 May 2023 16:46:11 -0300 Message-Id: <20230530194623.272652-5-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::33; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x33.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Following the same logic used with 'mvendorid' let's also restrict 'mimpid' for named CPUs. Generic CPUs keep setting the value freely. Note that we're getting rid of the default RISCV_CPU_MARCHID value. The reason is that this is not a good default since it's dynamic, changing with with every QEMU version, regardless of whether the actual implementation of the CPU changed from one QEMU version to the other. Named CPU should set it to a meaningful value instead and generic CPUs can set whatever they want. This is the error thrown for an invalid 'mimpid' value for the veyron-v1 CPU: $ ./qemu-system-riscv64 -M virt -nographic -cpu veyron-v1,mimpid=2 qemu-system-riscv64: can't apply global veyron-v1-riscv-cpu.mimpid=2: Unable to change veyron-v1-riscv-cpu mimpid (0x111) Signed-off-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones --- target/riscv/cpu.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index bcd69bb032..ed3b33343c 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -42,7 +42,6 @@ #define RISCV_CPU_MARCHID ((QEMU_VERSION_MAJOR << 16) | \ (QEMU_VERSION_MINOR << 8) | \ (QEMU_VERSION_MICRO)) -#define RISCV_CPU_MIMPID RISCV_CPU_MARCHID static const char riscv_single_letter_exts[] = "IEMAFDQCPVH"; @@ -1724,7 +1723,6 @@ static Property riscv_cpu_properties[] = { DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true), DEFINE_PROP_UINT64("marchid", RISCVCPU, cfg.marchid, RISCV_CPU_MARCHID), - DEFINE_PROP_UINT64("mimpid", RISCVCPU, cfg.mimpid, RISCV_CPU_MIMPID), #ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC), @@ -1835,6 +1833,27 @@ static void cpu_set_mvendorid(Object *obj, Visitor *v, const char *name, cpu->cfg.mvendorid = value; } +static void cpu_set_mimpid(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + bool dynamic_cpu = riscv_cpu_is_dynamic(obj); + RISCVCPU *cpu = RISCV_CPU(obj); + uint64_t prev_val = cpu->cfg.mimpid; + uint64_t value; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + + if (!dynamic_cpu && prev_val != value) { + error_setg(errp, "Unable to change %s mimpid (0x%lx)", + object_get_typename(obj), prev_val); + return; + } + + cpu->cfg.mimpid = value; +} + static void riscv_cpu_class_init(ObjectClass *c, void *data) { RISCVCPUClass *mcc = RISCV_CPU_CLASS(c); @@ -1870,6 +1889,10 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cpu_set_mvendorid, NULL, NULL); + object_class_property_add(c, "mimpid", "uint64", NULL, + cpu_set_mimpid, + NULL, NULL); + device_class_set_props(dc, riscv_cpu_properties); } From patchwork Tue May 30 19:46:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787944 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=o8Kniyxc; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2yj4hgsz20Q4 for ; Wed, 31 May 2023 05:49:01 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45Iy-0006XP-Oe; Tue, 30 May 2023 15:46:52 -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 1q45Ix-0006Wz-EY for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:51 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45Iv-0004Gs-PY for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:51 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-392116ae103so3125713b6e.0 for ; Tue, 30 May 2023 12:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476008; x=1688068008; 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=ZHcIFF+On7XVAkK1In1iARALt5xOx5eVMu85enqtbhk=; b=o8KniyxcZo4x+nYoJrc0ZuToTqePJwhmxAZY1UiEKRwiTFtCh9yjR0a6sg8rJqxLVK 0lLOgYzXJw1mO8tUsa3kmoqHBQf3lzcDA/zImoHi4/zO2QJHJgoPtEsrSQwXTzZiN6hP gI4UMTbNOEcLkMl67SJTM3ycUCYBjDealCg3pm08GEUH3Zy5mvBl85KfoV8XAquMbKtw XPeqMiljLVKiQZSQAZDOS2lwU1LSwRynTaqhmfD6TtF8Mdx0iOjyuFFLCo/DXExv6KVq HDBfVVLkV8zY12Z2Y72s660HJ9uHMYZdX8tk20XSHLSDTKDyo1P+kcukHmSm4p5Lo7+T C9WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476008; x=1688068008; 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=ZHcIFF+On7XVAkK1In1iARALt5xOx5eVMu85enqtbhk=; b=e99M4B9/nWex5D6bIIncyjjCnYYIZBiuJ8LVfTtVgiiA8b0uIgOIiZo5EBaQgxhf39 AjNvmNh00ZVeItEaVcRgHYWgqybgDBjPsWQl+lq83BsEgTMiee/ZXNqqoS48XrouGu0+ nS/jdrg+glao33BX3Zx0kC02asCLPk4EclpD8185ZaZSWC1r9hmgYlNNpcJAVxKTTaDi HkJ8tnTx9u0U6NsneRQdeK3rsHYAkk9tWPzRsFHzlV4Soj1Bxt0/V0Pv3XbzN8OGF/Yi 5RstnWHVGlInlvDKqlDTKzt/SAW16DnP7P991fea0a/sf7N6+5MMCh/cGQF1QZHDxO7W PW+g== X-Gm-Message-State: AC+VfDwbHhE0n9lwSMH8YEy/ajDGHPBPyo2Y7v2dEP8qh7uezNplWl1k 6Ac8uVJbMbhSPlT1vqIdHmJhRDev/MO7LLenuZY= X-Google-Smtp-Source: ACHHUZ7I8Z8ziaTxI94QWIJDw9k3pXBKa0X0XlZrLtPd9t8uq24Z3Wm1pnEERwM/VjFp2TG/fWhyuw== X-Received: by 2002:a05:6808:1453:b0:398:55f:6a50 with SMTP id x19-20020a056808145300b00398055f6a50mr2020040oiv.10.1685476008144; Tue, 30 May 2023 12:46:48 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:46:47 -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, Daniel Henrique Barboza Subject: [PATCH 05/16] target/riscv/cpu.c: restrict 'marchid' value Date: Tue, 30 May 2023 16:46:12 -0300 Message-Id: <20230530194623.272652-6-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x234.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 'marchid' shouldn't be set to a different value as previously set for named CPUs. For all other CPUs it shouldn't be freely set either - the spec requires that 'marchid' can't have the MSB (most significant bit) set and every other bit set to zero, i.e. 0x80000000 is an invalid 'marchid' value for 32 bit CPUs. As with 'mimpid', setting a default value based on the current QEMU version is not a good idea because it implies that the CPU implementation changes from one QEMU version to the other. Named CPUs should set 'marchid' to a meaningful value instead, and generic CPUs can set to any valid value. For the 'veyron-v1' CPU this is the error thrown if 'marchid' is set to a different val: $ ./build/qemu-system-riscv64 -M virt -nographic -cpu veyron-v1,marchid=0x80000000 qemu-system-riscv64: can't apply global veyron-v1-riscv-cpu.marchid=0x80000000: Unable to change veyron-v1-riscv-cpu marchid (0x8000000000010000) And, for generics CPUs, this is the error when trying to set to an invalid val: $ ./build/qemu-system-riscv64 -M virt -nographic -cpu rv64,marchid=0x8000000000000000 qemu-system-riscv64: can't apply global rv64-riscv-cpu.marchid=0x8000000000000000: Unable to set marchid with MSB (64) bit set and the remaining bits zero Signed-off-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones --- target/riscv/cpu.c | 53 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index ed3b33343c..d6e23bfd83 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -38,11 +38,6 @@ #include "tcg/tcg.h" /* RISC-V CPU definitions */ - -#define RISCV_CPU_MARCHID ((QEMU_VERSION_MAJOR << 16) | \ - (QEMU_VERSION_MINOR << 8) | \ - (QEMU_VERSION_MICRO)) - static const char riscv_single_letter_exts[] = "IEMAFDQCPVH"; struct isa_ext_data { @@ -1722,8 +1717,6 @@ static void riscv_cpu_add_user_properties(Object *obj) static Property riscv_cpu_properties[] = { DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true), - DEFINE_PROP_UINT64("marchid", RISCVCPU, cfg.marchid, RISCV_CPU_MARCHID), - #ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC), #endif @@ -1854,6 +1847,48 @@ static void cpu_set_mimpid(Object *obj, Visitor *v, const char *name, cpu->cfg.mimpid = value; } +static void cpu_set_marchid(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + bool dynamic_cpu = riscv_cpu_is_dynamic(obj); + RISCVCPU *cpu = RISCV_CPU(obj); + uint64_t prev_val = cpu->cfg.marchid; + uint64_t value, invalid_val; + uint32_t mxlen = 0; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + + if (!dynamic_cpu && prev_val != value) { + error_setg(errp, "Unable to change %s marchid (0x%lx)", + object_get_typename(obj), prev_val); + return; + } + + switch (riscv_cpu_mxl(&cpu->env)) { + case MXL_RV32: + mxlen = 32; + break; + case MXL_RV64: + case MXL_RV128: + mxlen = 64; + break; + default: + g_assert_not_reached(); + } + + invalid_val = 1LL << (mxlen - 1); + + if (value == invalid_val) { + error_setg(errp, "Unable to set marchid with MSB (%u) bit set " + "and the remaining bits zero", mxlen); + return; + } + + cpu->cfg.marchid = value; +} + static void riscv_cpu_class_init(ObjectClass *c, void *data) { RISCVCPUClass *mcc = RISCV_CPU_CLASS(c); @@ -1893,6 +1928,10 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cpu_set_mimpid, NULL, NULL); + object_class_property_add(c, "marchid", "uint64", NULL, + cpu_set_marchid, + NULL, NULL); + device_class_set_props(dc, riscv_cpu_properties); } From patchwork Tue May 30 19:46:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=UXPLkHHR; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2zs6KKpz20Q4 for ; Wed, 31 May 2023 05:50:01 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45J6-0006bu-WA; Tue, 30 May 2023 15:47:01 -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 1q45J2-0006Zh-5R for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:56 -0400 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45Iy-0004HN-OC for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:55 -0400 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-39817f3e08eso1638510b6e.1 for ; Tue, 30 May 2023 12:46:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476011; x=1688068011; 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=PQfvEU6D8rfX7EQRs/z2WyDaYmnYIefS7PvmuSNGDek=; b=UXPLkHHRtdO3pom0TSUeVlzJkSU6DJTyBiRbVN7HMlF6xyxnDB1EehU0BEuigYf90J wCcUlq11BFVp4pEcq44zLbafgoy9a+SNZpvPO5tCt66K+XMWO/YN00BaOmDNg92rkzaa k7k1QRB6R6ucfp0bM2Uhtu05mLEDjONYesymhLye8D9clZrAovGIM7eTs1o0LpGCdiav AKa4NvasEV1aP0eGxkkKod2O9PHQ1lztZEuOcn3rnPfZM7uHukfQyeLiGDq5k1pahMSH padlTzoK2I58TyiSoQSsdyS67mPesMAOE9eopCuB/amGl2n4TxqaUWight/uqzT++6gC YQLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476011; x=1688068011; 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=PQfvEU6D8rfX7EQRs/z2WyDaYmnYIefS7PvmuSNGDek=; b=j13RXhCeK8FrYdUwnzHG5TXzpZSC/I0pwGZAebpC/gvcJzNU5PxmeouO7lDxiUHozd M9r7jYO5zpIg1uA8XYxaEBJuOceUTnEmL9qb3DdVdGbWFSu6FGESoDwNqBB9m4bi6ORz Lifp2C7C3CrjoGX4ZP1uDgdp5ZbHssgpzrlov0nleD4keDYBW+cc647W6Q+bB0Fy7Fch N9Rvo2IzdThJk8Wy9oNV7tNVL3Yj2n7fpREDy0b6p6xl3HD2ozIzp3ILrmAwWw+ZKdOS ogdDXvk09angiv7CcXGIfry7/EyIjhltEqzaYaVeRFGZXMEnHmqL/xn+c91VBr0AkQrm Bs8A== X-Gm-Message-State: AC+VfDxHLUmOk+tm1Zs047UcQlRrpOQa/Y1yOGKlzsVgJlqG8mDwb9Rc NQ9e4CRF6S9WZzxVeZIJMyUXX0ZkTsjTISes98E= X-Google-Smtp-Source: ACHHUZ5gF0cMgz0O0PJqSzJ/O3dHLQEOd9Kfo2y0jZZOsgPG4UK8VFZzdqb7hr+W2DrOs+Md4dJ0gA== X-Received: by 2002:a54:4e01:0:b0:398:2b60:dbf7 with SMTP id a1-20020a544e01000000b003982b60dbf7mr1456681oiy.17.1685476011393; Tue, 30 May 2023 12:46:51 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:46:50 -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, Daniel Henrique Barboza , Andrew Jones Subject: [PATCH 06/16] target/riscv: use KVM scratch CPUs to init KVM properties Date: Tue, 30 May 2023 16:46:13 -0300 Message-Id: <20230530194623.272652-7-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::233; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x233.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Certain validations, such as the validations done for the machine IDs (mvendorid/marchid/mimpid), are done before starting the CPU. Non-dynamic (named) CPUs tries to match user input with a preset default. As it is today we can't prefetch a KVM default for these cases because we're only able to read/write KVM regs after the vcpu is spinning. Our target/arm friends use a concept called "scratch CPU", which consists of creating a vcpu for doing queries and validations and so on, which is discarded shortly after use [1]. This is a suitable solution for what we need so let's implement it in target/riscv as well. kvm_riscv_init_machine_ids() will be used to do any pre-launch setup for KVM CPUs, via riscv_cpu_add_user_properties(). The function will create a KVM scratch CPU, fetch KVM regs that work as default values for user properties, and then discard the scratch CPU afterwards. We're starting by initializing 'mvendorid'. This concept will be used to init other KVM specific properties in the next patches as well. [1] target/arm/kvm.c, kvm_arm_create_scratch_host_vcpu() Suggested-by: Andrew Jones Signed-off-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones Acked-by: Alistair Francis --- target/riscv/cpu.c | 4 ++ target/riscv/kvm.c | 85 ++++++++++++++++++++++++++++++++++++++++ target/riscv/kvm_riscv.h | 1 + 3 files changed, 90 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d6e23bfd83..749d8bf5eb 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1703,6 +1703,10 @@ static void riscv_cpu_add_user_properties(Object *obj) Property *prop; DeviceState *dev = DEVICE(obj); + if (riscv_running_KVM()) { + kvm_riscv_init_user_properties(obj); + } + riscv_cpu_add_misa_properties(obj); for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 0f932a5b96..37f0f70794 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -309,6 +309,91 @@ static void kvm_riscv_put_regs_timer(CPUState *cs) env->kvm_timer_dirty = false; } +typedef struct KVMScratchCPU { + int kvmfd; + int vmfd; + int cpufd; +} KVMScratchCPU; + +/* + * Heavily inspired by kvm_arm_create_scratch_host_vcpu() + * from target/arm/kvm.c. + */ +static bool kvm_riscv_create_scratch_vcpu(KVMScratchCPU *scratch) +{ + int kvmfd = -1, vmfd = -1, cpufd = -1; + + kvmfd = qemu_open_old("/dev/kvm", O_RDWR); + if (kvmfd < 0) { + goto err; + } + do { + vmfd = ioctl(kvmfd, KVM_CREATE_VM, 0); + } while (vmfd == -1 && errno == EINTR); + if (vmfd < 0) { + goto err; + } + cpufd = ioctl(vmfd, KVM_CREATE_VCPU, 0); + if (cpufd < 0) { + goto err; + } + + scratch->kvmfd = kvmfd; + scratch->vmfd = vmfd; + scratch->cpufd = cpufd; + + return true; + + err: + if (cpufd >= 0) { + close(cpufd); + } + if (vmfd >= 0) { + close(vmfd); + } + if (kvmfd >= 0) { + close(kvmfd); + } + + return false; +} + +static void kvm_riscv_destroy_scratch_vcpu(KVMScratchCPU *scratch) +{ + close(scratch->cpufd); + close(scratch->vmfd); + close(scratch->kvmfd); +} + +static void kvm_riscv_init_machine_ids(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) +{ + CPURISCVState *env = &cpu->env; + struct kvm_one_reg reg; + int ret; + + reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, + KVM_REG_RISCV_CONFIG_REG(mvendorid)); + reg.addr = (uint64_t)&cpu->cfg.mvendorid; + ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, ®); + if (ret != 0) { + error_report("Unable to retrieve mvendorid from host, error %d", ret); + } +} + +void kvm_riscv_init_user_properties(Object *cpu_obj) +{ + RISCVCPU *cpu = RISCV_CPU(cpu_obj); + KVMScratchCPU kvmcpu; + + if (!kvm_riscv_create_scratch_vcpu(&kvmcpu)) { + return; + } + + kvm_riscv_init_machine_ids(cpu, &kvmcpu); + + kvm_riscv_destroy_scratch_vcpu(&kvmcpu); +} + const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_LAST_INFO }; diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h index ed281bdce0..e3ba935808 100644 --- a/target/riscv/kvm_riscv.h +++ b/target/riscv/kvm_riscv.h @@ -19,6 +19,7 @@ #ifndef QEMU_KVM_RISCV_H #define QEMU_KVM_RISCV_H +void kvm_riscv_init_user_properties(Object *cpu_obj); void kvm_riscv_reset_vcpu(RISCVCPU *cpu); void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level); From patchwork Tue May 30 19:46:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787941 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=nYqB3w91; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2yQ4ZF7z20Q4 for ; Wed, 31 May 2023 05:48:46 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45J5-0006aw-Nn; Tue, 30 May 2023 15:46: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 1q45J4-0006Zy-4w for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:58 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45J1-0004Ix-L6 for qemu-devel@nongnu.org; Tue, 30 May 2023 15:46:57 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-397f3aec11aso132646b6e.1 for ; Tue, 30 May 2023 12:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476014; x=1688068014; 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=RRT+44VDoy+4v36rTa7zi9SGRXRzolaKQZeKAAn0Q/E=; b=nYqB3w91d2ThcUoM0FCQ87uqY908IMWIZUFVa0cAGbuyW5foor589rSy85QspsxDWQ w09mN+V3mCRCV7G+MqkPWRA0Wp3Sqy7ps4aYbvrd66YL97oqSs2Ej8gH5Rf1TVgxyO+W H8lKw96LpCgqudtivAyfzERjPd/qllP83Dn5CSXfJG2+QLj4RKbOhV31ncKr4WnHYjRE GQYi3hV+K6O0XH3jSk3CEmTZB0UnsZE3Ke84nnI6YaWsXQCDptgWzHdzsYf5KaDar7qs Mo4hpBvPhnDXOKEXp4XUxtqOYAc6Xw2Z5wBqCG+cxeyIhPopk6ZlbfwetsUGwv4NBPSi 6Unw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476014; x=1688068014; 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=RRT+44VDoy+4v36rTa7zi9SGRXRzolaKQZeKAAn0Q/E=; b=l3uJTjJP6/cegSzBFjcR4iMrBKy5yW4JBRbDhmOAF4UHkSAQlbdf7Ylo5A2wSkinBU U/h106ryDNDkrZgLWLc9ZkuqQMQNv8YR2gqpo8fqv+bqE3a2L57v5F3wYhWOg7awuHpC YyT/utART8Hdp0ZMjo+95cdJewI8jbkCG8aAGjkiu45MIkusdQUtn6ple+zgfMlXUhUM IGRQMHkhRgLFj/X8LYqwVrHyLaREJUnKwLfgqKUvhRU9X1HEeMvXiTPCgkM6tzBUuigs 8zNpdkNwPtk0FHVYdOcGsPFKLSYpGmlmeRHETBiFttiGAdu/LSVw86P8XqTwuU72wM/5 o1Nw== X-Gm-Message-State: AC+VfDzBWKZsvKouQzT5AKmOXgu3ehszJIdkzzvwdRHGmvtcgEWjJ5qh 681c8Q9thEjLd9SqpGiVypC/Th/y8XTGlQXk+X4= X-Google-Smtp-Source: ACHHUZ6bSCx0/MSV2LTrw4X9l2NzaC817de0O+RVwDKAZaHBfjCDYL4hFmz+GqXyxUgkuu+IlC0jNA== X-Received: by 2002:a05:6808:3022:b0:393:fe54:9a01 with SMTP id ay34-20020a056808302200b00393fe549a01mr1789194oib.11.1685476014272; Tue, 30 May 2023 12:46:54 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:46:54 -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, Daniel Henrique Barboza Subject: [PATCH 07/16] target/riscv: read marchid/mimpid in kvm_riscv_init_machine_ids() Date: Tue, 30 May 2023 16:46:14 -0300 Message-Id: <20230530194623.272652-8-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22b.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Allow 'marchid' and 'mimpid' to also be initialized in kvm_riscv_init_machine_ids(). After this change, the handling of mvendorid/marchid/mimpid for the 'host' CPU type will be equal to what we already have for TCG named CPUs, i.e. the user is not able to set these values to a different val than the one that is already preset. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones Acked-by: Alistair Francis --- target/riscv/kvm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 37f0f70794..cd2974c663 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -378,6 +378,22 @@ static void kvm_riscv_init_machine_ids(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) if (ret != 0) { error_report("Unable to retrieve mvendorid from host, error %d", ret); } + + reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, + KVM_REG_RISCV_CONFIG_REG(marchid)); + reg.addr = (uint64_t)&cpu->cfg.marchid; + ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, ®); + if (ret != 0) { + error_report("Unable to retrieve marchid from host, error %d", ret); + } + + reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, + KVM_REG_RISCV_CONFIG_REG(mimpid)); + reg.addr = (uint64_t)&cpu->cfg.mimpid; + ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, ®); + if (ret != 0) { + error_report("Unable to retrieve mimpid from host, error %d", ret); + } } void kvm_riscv_init_user_properties(Object *cpu_obj) From patchwork Tue May 30 19:46:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787936 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=NRDgC6hk; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2xc3RmBz20WQ for ; Wed, 31 May 2023 05:48:04 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45J9-0006ci-DD; Tue, 30 May 2023 15:47:03 -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 1q45J6-0006bM-Dr for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:00 -0400 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45J4-0004Ja-S2 for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:00 -0400 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6af6b6837acso3567807a34.1 for ; Tue, 30 May 2023 12:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476017; x=1688068017; 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=S2MGPPJ0plm+6/+zmeg7JR1jnjsVFqkpNJ2x5NNUP5s=; b=NRDgC6hkXxRpNuJ2foitjcc+pVW/gYFlIq5YpOb9AvwUipGts7YiVlhs43evRlPV7T YFcJcnDaVpVmt54Ap1+bYh2okWzAhxU0hlEmBXYpo3DYySDmfjDy4n4SK+Kjf3CDAEwn 244WUBczcaURbZmXp+8kQS1GulvfFYH67TIa2DKgiEMIb5M1cE/dimD0I7tKZxDez/R6 g2sOrRQ57rPXays3OmE47dUXh3WWIoZB7SGtCdJdH/MTNF33Ei81sPtE8DkZ4uslzi6V Tj+dWr6Z5TA1paRKBOwPtd0SeIy+DlfwoXI/4Ji4A26+K9HNPtmRc3SBiKCaSdB3yHVi L1Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476017; x=1688068017; 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=S2MGPPJ0plm+6/+zmeg7JR1jnjsVFqkpNJ2x5NNUP5s=; b=JoW6suQ/n9zwTmF5asr4srRCWIVMYuJzj95i2z7WVh8PproZwHF3AYX1yvKlm7mEtW gE9SBR8dP/Z7q1WvYznM20+gzNKB5fDmbIZiitn/tOx0hl3w4pEj4aIRsqJJiGFPW/nI jTDjqew6sWs1hCm/6bFXM3+M6BSmY2+LclD0ym8Y3QFQnfERZIseT+R+k7zLw9OpDFFU iVknVcoxyxGc/Z66VJAoXKT9kF0yQIbDJwOP1ToHmxgbkfF23pN0ySZDj2SKhcRKA+yx XRwclxmhCTaFhGDVecRD6SfgDsjR/5G7IRuCWP5dN87TgZVjsHdq55wbng2p6ziEKSpy dXfQ== X-Gm-Message-State: AC+VfDx+WNO8a+YeKWQOVgjxIQ+KdECwcli0BLUif3VLoBs89wkaxynX mmgU9FS7TsLDiPOHza+TWYtFJNSpo1xFMxXbNFs= X-Google-Smtp-Source: ACHHUZ6+Rj7+Xt3dFq5nX0m+eJSIRWGE799WN6FkXG26KnI9ItxifADX0WxNg7J67/M4J16Xn7lVWw== X-Received: by 2002:a05:6808:f12:b0:398:6452:5bed with SMTP id m18-20020a0568080f1200b0039864525bedmr2201719oiw.20.1685476017402; Tue, 30 May 2023 12:46:57 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:46:57 -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, Daniel Henrique Barboza Subject: [PATCH 08/16] target/riscv: handle mvendorid/marchid/mimpid for KVM CPUs Date: Tue, 30 May 2023 16:46:15 -0300 Message-Id: <20230530194623.272652-9-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::32f; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x32f.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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; } From patchwork Tue May 30 19:46:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787935 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=Fvd8wmmB; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2xb34Wpz20Q4 for ; Wed, 31 May 2023 05:48:01 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45JJ-0006if-Ba; Tue, 30 May 2023 15:47:14 -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 1q45JD-0006gs-6Y for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:07 -0400 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45J9-0004K9-6o for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:05 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6af6df7f93aso3610912a34.0 for ; Tue, 30 May 2023 12:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476020; x=1688068020; 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=7BFCfo0HGKkFmJVQPVF5IuVIhGV9LkXg0Cc3rc8YZxU=; b=Fvd8wmmBh00SXwtpotNyqRLzClEBCCbuJTIdsGiSsmAuaZ7Sez5Kb7h7QOKa72rfOI j0OV/Wbm6azuzqYkQnylGeXnvuukuzZ/G2IV2PVWWJJWL8pmKCxTXj4CR4dneih41hl5 olxnaFlOzwQhm0k+vi4geZ9SS6ResQitUVV6Nl03ngm/n/L78+Uahgq/BLPMEWMkCvfa uItC6xlsv4fD4Xf5BopYN1QAXsjn31PjpV06x9XRg0RAc5c0SnBxkSrm1HSZAUrva8cV yl/6yuqLYeN5zvdA/WHDdXWo3F1OpJnvAp2JnQfjQwgtTJAGY24g4y3kQkELSpn5fTkp AmPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476020; x=1688068020; 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=7BFCfo0HGKkFmJVQPVF5IuVIhGV9LkXg0Cc3rc8YZxU=; b=X4EjwZ2PX0SDdTvhHR2j98SzIH4/HcfOPt/+gh8ZutDfTP/RBLN+fVB3oszD2dY4AH 340BmQ4c3bQN6o5g1gndWQtt9N2EbjjmRRcghXYm324fJh+JS9xnB0RcpdKWsByXC3Z5 L+p4/MscQujIf9r1/KuUPtTrgGDlvvwEkfJisLxUIg5Xnmt6QhxLYnHy8BC0f9xOUSFk ZMzXEETpbrkdZeMEGc3ELyw9ujcZgu7J2EQ1+5Y0A+jNz3BRzcgr2f55Le75Tubq3uzK SvQlyuMHMcH5Mq04yL1kIsOj7+nTqVVHsfWF4GoI/bWkUEJJgxkOHym1W08JaXFee4OI LHsQ== X-Gm-Message-State: AC+VfDw/zhzQszqIHqrz6Kd/aziBJNybAStulzxZa6tMoUwaZm3MRG+v E3tO8FbZ22jYJb9aCCFKgvTJuop/62oaf4l+l+U= X-Google-Smtp-Source: ACHHUZ5AvSdCraD0tvOKJAvJH2UO4eEQyAaq3uUvCK7To+O/ciYTSFsOcxI4X+I/sAFssxhcUxaplA== X-Received: by 2002:a05:6870:d503:b0:19a:7bd0:e260 with SMTP id b3-20020a056870d50300b0019a7bd0e260mr1939718oan.0.1685476020451; Tue, 30 May 2023 12:47:00 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:47:00 -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, Daniel Henrique Barboza Subject: [PATCH 09/16] linux-headers: Update to v6.4-rc1 Date: Tue, 30 May 2023 16:46:16 -0300 Message-Id: <20230530194623.272652-10-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::331; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x331.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Update to commit ac9a78681b92 ("Linux 6.4-rc1"). Signed-off-by: Daniel Henrique Barboza --- include/standard-headers/linux/const.h | 2 +- include/standard-headers/linux/virtio_blk.h | 18 +++---- .../standard-headers/linux/virtio_config.h | 6 +++ include/standard-headers/linux/virtio_net.h | 1 + linux-headers/asm-arm64/kvm.h | 33 ++++++++++++ linux-headers/asm-riscv/kvm.h | 53 ++++++++++++++++++- linux-headers/asm-riscv/unistd.h | 9 ++++ linux-headers/asm-s390/unistd_32.h | 1 + linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 3 ++ linux-headers/linux/const.h | 2 +- linux-headers/linux/kvm.h | 12 +++-- linux-headers/linux/psp-sev.h | 7 +++ linux-headers/linux/userfaultfd.h | 17 +++++- 14 files changed, 149 insertions(+), 16 deletions(-) diff --git a/include/standard-headers/linux/const.h b/include/standard-headers/linux/const.h index 5e48987251..1eb84b5087 100644 --- a/include/standard-headers/linux/const.h +++ b/include/standard-headers/linux/const.h @@ -28,7 +28,7 @@ #define _BITUL(x) (_UL(1) << (x)) #define _BITULL(x) (_ULL(1) << (x)) -#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) +#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1) #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) diff --git a/include/standard-headers/linux/virtio_blk.h b/include/standard-headers/linux/virtio_blk.h index 7155b1a470..d7be3cf5e4 100644 --- a/include/standard-headers/linux/virtio_blk.h +++ b/include/standard-headers/linux/virtio_blk.h @@ -138,11 +138,11 @@ struct virtio_blk_config { /* Zoned block device characteristics (if VIRTIO_BLK_F_ZONED) */ struct virtio_blk_zoned_characteristics { - uint32_t zone_sectors; - uint32_t max_open_zones; - uint32_t max_active_zones; - uint32_t max_append_sectors; - uint32_t write_granularity; + __virtio32 zone_sectors; + __virtio32 max_open_zones; + __virtio32 max_active_zones; + __virtio32 max_append_sectors; + __virtio32 write_granularity; uint8_t model; uint8_t unused2[3]; } zoned; @@ -239,11 +239,11 @@ struct virtio_blk_outhdr { */ struct virtio_blk_zone_descriptor { /* Zone capacity */ - uint64_t z_cap; + __virtio64 z_cap; /* The starting sector of the zone */ - uint64_t z_start; + __virtio64 z_start; /* Zone write pointer position in sectors */ - uint64_t z_wp; + __virtio64 z_wp; /* Zone type */ uint8_t z_type; /* Zone state */ @@ -252,7 +252,7 @@ struct virtio_blk_zone_descriptor { }; struct virtio_blk_zone_report { - uint64_t nr_zones; + __virtio64 nr_zones; uint8_t reserved[56]; struct virtio_blk_zone_descriptor zones[]; }; diff --git a/include/standard-headers/linux/virtio_config.h b/include/standard-headers/linux/virtio_config.h index 965ee6ae23..8a7d0dc8b0 100644 --- a/include/standard-headers/linux/virtio_config.h +++ b/include/standard-headers/linux/virtio_config.h @@ -97,6 +97,12 @@ */ #define VIRTIO_F_SR_IOV 37 +/* + * This feature indicates that the driver passes extra data (besides + * identifying the virtqueue) in its device notifications. + */ +#define VIRTIO_F_NOTIFICATION_DATA 38 + /* * This feature indicates that the driver can reset a queue individually. */ diff --git a/include/standard-headers/linux/virtio_net.h b/include/standard-headers/linux/virtio_net.h index c0e797067a..2325485f2c 100644 --- a/include/standard-headers/linux/virtio_net.h +++ b/include/standard-headers/linux/virtio_net.h @@ -61,6 +61,7 @@ #define VIRTIO_NET_F_GUEST_USO6 55 /* Guest can handle USOv6 in. */ #define VIRTIO_NET_F_HOST_USO 56 /* Host can handle USO in. */ #define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ +#define VIRTIO_NET_F_GUEST_HDRLEN 59 /* Guest provides the exact hdr_len value. */ #define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ #define VIRTIO_NET_F_RSC_EXT 61 /* extended coalescing info */ #define VIRTIO_NET_F_STANDBY 62 /* Act as standby for another device diff --git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h index d7e7bb885e..38e5957526 100644 --- a/linux-headers/asm-arm64/kvm.h +++ b/linux-headers/asm-arm64/kvm.h @@ -198,6 +198,15 @@ struct kvm_arm_copy_mte_tags { __u64 reserved[2]; }; +/* + * Counter/Timer offset structure. Describe the virtual/physical offset. + * To be used with KVM_ARM_SET_COUNTER_OFFSET. + */ +struct kvm_arm_counter_offset { + __u64 counter_offset; + __u64 reserved; +}; + #define KVM_ARM_TAGS_TO_GUEST 0 #define KVM_ARM_TAGS_FROM_GUEST 1 @@ -363,6 +372,10 @@ enum { KVM_REG_ARM_VENDOR_HYP_BIT_PTP = 1, }; +/* Device Control API on vm fd */ +#define KVM_ARM_VM_SMCCC_CTRL 0 +#define KVM_ARM_VM_SMCCC_FILTER 0 + /* Device Control API: ARM VGIC */ #define KVM_DEV_ARM_VGIC_GRP_ADDR 0 #define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1 @@ -402,6 +415,8 @@ enum { #define KVM_ARM_VCPU_TIMER_CTRL 1 #define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0 #define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1 +#define KVM_ARM_VCPU_TIMER_IRQ_HVTIMER 2 +#define KVM_ARM_VCPU_TIMER_IRQ_HPTIMER 3 #define KVM_ARM_VCPU_PVTIME_CTRL 2 #define KVM_ARM_VCPU_PVTIME_IPA 0 @@ -458,6 +473,24 @@ enum { /* run->fail_entry.hardware_entry_failure_reason codes. */ #define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED (1ULL << 0) +enum kvm_smccc_filter_action { + KVM_SMCCC_FILTER_HANDLE = 0, + KVM_SMCCC_FILTER_DENY, + KVM_SMCCC_FILTER_FWD_TO_USER, + +}; + +struct kvm_smccc_filter { + __u32 base; + __u32 nr_functions; + __u8 action; + __u8 pad[15]; +}; + +/* arm64-specific KVM_EXIT_HYPERCALL flags */ +#define KVM_HYPERCALL_EXIT_SMC (1U << 0) +#define KVM_HYPERCALL_EXIT_16BIT (1U << 1) + #endif #endif /* __ARM_KVM_H__ */ diff --git a/linux-headers/asm-riscv/kvm.h b/linux-headers/asm-riscv/kvm.h index 92af6f3f05..f92790c948 100644 --- a/linux-headers/asm-riscv/kvm.h +++ b/linux-headers/asm-riscv/kvm.h @@ -12,6 +12,7 @@ #ifndef __ASSEMBLY__ #include +#include #include #define __KVM_HAVE_READONLY_MEM @@ -52,6 +53,7 @@ struct kvm_riscv_config { unsigned long mvendorid; unsigned long marchid; unsigned long mimpid; + unsigned long zicboz_block_size; }; /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ @@ -64,7 +66,7 @@ struct kvm_riscv_core { #define KVM_RISCV_MODE_S 1 #define KVM_RISCV_MODE_U 0 -/* CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ +/* General CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ struct kvm_riscv_csr { unsigned long sstatus; unsigned long sie; @@ -78,6 +80,17 @@ struct kvm_riscv_csr { unsigned long scounteren; }; +/* AIA CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ +struct kvm_riscv_aia_csr { + unsigned long siselect; + unsigned long iprio1; + unsigned long iprio2; + unsigned long sieh; + unsigned long siph; + unsigned long iprio1h; + unsigned long iprio2h; +}; + /* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ struct kvm_riscv_timer { __u64 frequency; @@ -105,9 +118,29 @@ enum KVM_RISCV_ISA_EXT_ID { KVM_RISCV_ISA_EXT_SVINVAL, KVM_RISCV_ISA_EXT_ZIHINTPAUSE, KVM_RISCV_ISA_EXT_ZICBOM, + KVM_RISCV_ISA_EXT_ZICBOZ, + KVM_RISCV_ISA_EXT_ZBB, + KVM_RISCV_ISA_EXT_SSAIA, KVM_RISCV_ISA_EXT_MAX, }; +/* + * SBI extension IDs specific to KVM. This is not the same as the SBI + * extension IDs defined by the RISC-V SBI specification. + */ +enum KVM_RISCV_SBI_EXT_ID { + KVM_RISCV_SBI_EXT_V01 = 0, + KVM_RISCV_SBI_EXT_TIME, + KVM_RISCV_SBI_EXT_IPI, + KVM_RISCV_SBI_EXT_RFENCE, + KVM_RISCV_SBI_EXT_SRST, + KVM_RISCV_SBI_EXT_HSM, + KVM_RISCV_SBI_EXT_PMU, + KVM_RISCV_SBI_EXT_EXPERIMENTAL, + KVM_RISCV_SBI_EXT_VENDOR, + KVM_RISCV_SBI_EXT_MAX, +}; + /* Possible states for kvm_riscv_timer */ #define KVM_RISCV_TIMER_STATE_OFF 0 #define KVM_RISCV_TIMER_STATE_ON 1 @@ -118,6 +151,8 @@ enum KVM_RISCV_ISA_EXT_ID { /* If you need to interpret the index values, here is the key: */ #define KVM_REG_RISCV_TYPE_MASK 0x00000000FF000000 #define KVM_REG_RISCV_TYPE_SHIFT 24 +#define KVM_REG_RISCV_SUBTYPE_MASK 0x0000000000FF0000 +#define KVM_REG_RISCV_SUBTYPE_SHIFT 16 /* Config registers are mapped as type 1 */ #define KVM_REG_RISCV_CONFIG (0x01 << KVM_REG_RISCV_TYPE_SHIFT) @@ -131,8 +166,12 @@ enum KVM_RISCV_ISA_EXT_ID { /* Control and status registers are mapped as type 3 */ #define KVM_REG_RISCV_CSR (0x03 << KVM_REG_RISCV_TYPE_SHIFT) +#define KVM_REG_RISCV_CSR_GENERAL (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_CSR_AIA (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT) #define KVM_REG_RISCV_CSR_REG(name) \ (offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long)) +#define KVM_REG_RISCV_CSR_AIA_REG(name) \ + (offsetof(struct kvm_riscv_aia_csr, name) / sizeof(unsigned long)) /* Timer registers are mapped as type 4 */ #define KVM_REG_RISCV_TIMER (0x04 << KVM_REG_RISCV_TYPE_SHIFT) @@ -152,6 +191,18 @@ enum KVM_RISCV_ISA_EXT_ID { /* ISA Extension registers are mapped as type 7 */ #define KVM_REG_RISCV_ISA_EXT (0x07 << KVM_REG_RISCV_TYPE_SHIFT) +/* SBI extension registers are mapped as type 8 */ +#define KVM_REG_RISCV_SBI_EXT (0x08 << KVM_REG_RISCV_TYPE_SHIFT) +#define KVM_REG_RISCV_SBI_SINGLE (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_SBI_MULTI_EN (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_SBI_MULTI_DIS (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_SBI_MULTI_REG(__ext_id) \ + ((__ext_id) / __BITS_PER_LONG) +#define KVM_REG_RISCV_SBI_MULTI_MASK(__ext_id) \ + (1UL << ((__ext_id) % __BITS_PER_LONG)) +#define KVM_REG_RISCV_SBI_MULTI_REG_LAST \ + KVM_REG_RISCV_SBI_MULTI_REG(KVM_RISCV_SBI_EXT_MAX - 1) + #endif #endif /* __LINUX_KVM_RISCV_H */ diff --git a/linux-headers/asm-riscv/unistd.h b/linux-headers/asm-riscv/unistd.h index 73d7cdd2ec..950ab3fd44 100644 --- a/linux-headers/asm-riscv/unistd.h +++ b/linux-headers/asm-riscv/unistd.h @@ -43,3 +43,12 @@ #define __NR_riscv_flush_icache (__NR_arch_specific_syscall + 15) #endif __SYSCALL(__NR_riscv_flush_icache, sys_riscv_flush_icache) + +/* + * Allows userspace to query the kernel for CPU architecture and + * microarchitecture details across a given set of CPUs. + */ +#ifndef __NR_riscv_hwprobe +#define __NR_riscv_hwprobe (__NR_arch_specific_syscall + 14) +#endif +__SYSCALL(__NR_riscv_hwprobe, sys_riscv_hwprobe) diff --git a/linux-headers/asm-s390/unistd_32.h b/linux-headers/asm-s390/unistd_32.h index 8e644d65f5..800f3adb20 100644 --- a/linux-headers/asm-s390/unistd_32.h +++ b/linux-headers/asm-s390/unistd_32.h @@ -419,6 +419,7 @@ #define __NR_landlock_create_ruleset 444 #define __NR_landlock_add_rule 445 #define __NR_landlock_restrict_self 446 +#define __NR_memfd_secret 447 #define __NR_process_mrelease 448 #define __NR_futex_waitv 449 #define __NR_set_mempolicy_home_node 450 diff --git a/linux-headers/asm-s390/unistd_64.h b/linux-headers/asm-s390/unistd_64.h index 51da542fec..399a605901 100644 --- a/linux-headers/asm-s390/unistd_64.h +++ b/linux-headers/asm-s390/unistd_64.h @@ -367,6 +367,7 @@ #define __NR_landlock_create_ruleset 444 #define __NR_landlock_add_rule 445 #define __NR_landlock_restrict_self 446 +#define __NR_memfd_secret 447 #define __NR_process_mrelease 448 #define __NR_futex_waitv 449 #define __NR_set_mempolicy_home_node 450 diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index 2937e7bf69..2b3a8f7bd2 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -557,4 +557,7 @@ struct kvm_pmu_event_filter { #define KVM_VCPU_TSC_CTRL 0 /* control group for the timestamp counter (TSC) */ #define KVM_VCPU_TSC_OFFSET 0 /* attribute for the TSC offset */ +/* x86-specific KVM_EXIT_HYPERCALL flags. */ +#define KVM_EXIT_HYPERCALL_LONG_MODE BIT(0) + #endif /* _ASM_X86_KVM_H */ diff --git a/linux-headers/linux/const.h b/linux-headers/linux/const.h index 5e48987251..1eb84b5087 100644 --- a/linux-headers/linux/const.h +++ b/linux-headers/linux/const.h @@ -28,7 +28,7 @@ #define _BITUL(x) (_UL(1) << (x)) #define _BITULL(x) (_ULL(1) << (x)) -#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) +#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1) #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 599de3c6e3..65b145b317 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -341,8 +341,11 @@ struct kvm_run { __u64 nr; __u64 args[6]; __u64 ret; - __u32 longmode; - __u32 pad; + + union { + __u32 longmode; + __u64 flags; + }; } hypercall; /* KVM_EXIT_TPR_ACCESS */ struct { @@ -1182,6 +1185,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224 #define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225 #define KVM_CAP_PMU_EVENT_MASKED_EVENTS 226 +#define KVM_CAP_COUNTER_OFFSET 227 #ifdef KVM_CAP_IRQ_ROUTING @@ -1449,7 +1453,7 @@ struct kvm_vfio_spapr_tce { #define KVM_CREATE_VCPU _IO(KVMIO, 0x41) #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log) #define KVM_SET_NR_MMU_PAGES _IO(KVMIO, 0x44) -#define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45) +#define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45) /* deprecated */ #define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46, \ struct kvm_userspace_memory_region) #define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47) @@ -1541,6 +1545,8 @@ struct kvm_s390_ucas_mapping { #define KVM_SET_PMU_EVENT_FILTER _IOW(KVMIO, 0xb2, struct kvm_pmu_event_filter) #define KVM_PPC_SVM_OFF _IO(KVMIO, 0xb3) #define KVM_ARM_MTE_COPY_TAGS _IOR(KVMIO, 0xb4, struct kvm_arm_copy_mte_tags) +/* Available with KVM_CAP_COUNTER_OFFSET */ +#define KVM_ARM_SET_COUNTER_OFFSET _IOW(KVMIO, 0xb5, struct kvm_arm_counter_offset) /* ioctl for vm fd */ #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device) diff --git a/linux-headers/linux/psp-sev.h b/linux-headers/linux/psp-sev.h index 51d8b3940e..12ccb70099 100644 --- a/linux-headers/linux/psp-sev.h +++ b/linux-headers/linux/psp-sev.h @@ -36,6 +36,13 @@ enum { * SEV Firmware status code */ typedef enum { + /* + * This error code is not in the SEV spec. Its purpose is to convey that + * there was an error that prevented the SEV firmware from being called. + * The SEV API error codes are 16 bits, so the -1 value will not overlap + * with possible values from the specification. + */ + SEV_RET_NO_FW_CALL = -1, SEV_RET_SUCCESS = 0, SEV_RET_INVALID_PLATFORM_STATE, SEV_RET_INVALID_GUEST_STATE, diff --git a/linux-headers/linux/userfaultfd.h b/linux-headers/linux/userfaultfd.h index ba5d0df52f..14e402263a 100644 --- a/linux-headers/linux/userfaultfd.h +++ b/linux-headers/linux/userfaultfd.h @@ -38,7 +38,8 @@ UFFD_FEATURE_MINOR_HUGETLBFS | \ UFFD_FEATURE_MINOR_SHMEM | \ UFFD_FEATURE_EXACT_ADDRESS | \ - UFFD_FEATURE_WP_HUGETLBFS_SHMEM) + UFFD_FEATURE_WP_HUGETLBFS_SHMEM | \ + UFFD_FEATURE_WP_UNPOPULATED) #define UFFD_API_IOCTLS \ ((__u64)1 << _UFFDIO_REGISTER | \ (__u64)1 << _UFFDIO_UNREGISTER | \ @@ -203,6 +204,12 @@ struct uffdio_api { * * UFFD_FEATURE_WP_HUGETLBFS_SHMEM indicates that userfaultfd * write-protection mode is supported on both shmem and hugetlbfs. + * + * UFFD_FEATURE_WP_UNPOPULATED indicates that userfaultfd + * write-protection mode will always apply to unpopulated pages + * (i.e. empty ptes). This will be the default behavior for shmem + * & hugetlbfs, so this flag only affects anonymous memory behavior + * when userfault write-protection mode is registered. */ #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0) #define UFFD_FEATURE_EVENT_FORK (1<<1) @@ -217,6 +224,7 @@ struct uffdio_api { #define UFFD_FEATURE_MINOR_SHMEM (1<<10) #define UFFD_FEATURE_EXACT_ADDRESS (1<<11) #define UFFD_FEATURE_WP_HUGETLBFS_SHMEM (1<<12) +#define UFFD_FEATURE_WP_UNPOPULATED (1<<13) __u64 features; __u64 ioctls; @@ -297,6 +305,13 @@ struct uffdio_writeprotect { struct uffdio_continue { struct uffdio_range range; #define UFFDIO_CONTINUE_MODE_DONTWAKE ((__u64)1<<0) + /* + * UFFDIO_CONTINUE_MODE_WP will map the page write protected on + * the fly. UFFDIO_CONTINUE_MODE_WP is available only if the + * write protected ioctl is implemented for the range + * according to the uffdio_register.ioctls. + */ +#define UFFDIO_CONTINUE_MODE_WP ((__u64)1<<1) __u64 mode; /* From patchwork Tue May 30 19:46:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787940 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=nRT6+kyg; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2xx4MM1z20Q4 for ; Wed, 31 May 2023 05:48:21 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45JQ-0006lP-L8; Tue, 30 May 2023 15:47:20 -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 1q45JH-0006iO-D4 for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:13 -0400 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45JB-0004Eb-1n for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:09 -0400 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-19e82ae057eso3466238fac.3 for ; Tue, 30 May 2023 12:47:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476023; x=1688068023; 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=1GiLv/mMyR/lX2Ul3OkR5/DnIxMohqsEw/laPeSH3Mc=; b=nRT6+kygW28WSwgalx5l9U0ePI1GiEuj0iU4CkAvB3YWP00uOlJcElcOj0haGZWEr8 EPr81mNclK9GCCrprj5se7llewy94pRpFw+IZFuNSlrp3LapQNukSgMf0bEzh47yyvHM V9ZXa7X1SWEAjTNx87v6LgKVE5j01VUn+ECO+ib6xZhIrBzSssMPuGz2psaQJfLCX1c9 jBhLeiX4E+FSMM6bkXVBT8nKusJib3NCs3nz0P98AZhgQ+6DJ5OMjzQ1WsKZ5ghaUXaG tMQGiYva2GBPtwL82U3it94tNO3m3UbqI5GOuYVeiI1jqWwBkODA1H2ezTsSDExFBpAl dGtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476023; x=1688068023; 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=1GiLv/mMyR/lX2Ul3OkR5/DnIxMohqsEw/laPeSH3Mc=; b=hJwn7NIqTkzHme1TfHbESDQWahYP62YcENQM35FvVyY3HbEK0jYQNE6Ny08i2PlO8R IvoxOraJwn2Fl40rVbfX4eEq+Whe43cRRNUsix7oXG65+V8z7Wmaywb0MjTdRX9JyeWy 2xYleh8DvTJCOXFWYGhgEnAvwrkXEVnk4u7p49zJlCZjNQ6mcMrhKht8pqFX3leYWLAK 0cEneQNmQEXMXFffDqzoohA5cNY4E8ScDPXZ230+NRYX4apNKlA2/fo9k27HM3ZsW1Hp /0DFrGkcx5/OrgKTGSzQGw+UXoIEFx9N3FSIS0Ebh+y++8PIb/GJNTOsCBES9MbP6QLR FfTQ== X-Gm-Message-State: AC+VfDwvOo0IIs7W6HjbhIiiDSXWHD9a2dHR9TiC/lbVukSvE/9QUb4Q e4J8yqL1qxzv4/s+Nzjn/9imc2Af+NCASZ9o2F8= X-Google-Smtp-Source: ACHHUZ5nHCOUByyc8r3ZRvEkuliBP6IIsiQyhND37tJiDQ7oXmgRGtEJleY8tSC1dLBQzRD27igG8w== X-Received: by 2002:a05:6870:e393:b0:19e:e6e8:46f9 with SMTP id x19-20020a056870e39300b0019ee6e846f9mr2706429oad.30.1685476023535; Tue, 30 May 2023 12:47:03 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:47:03 -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, Daniel Henrique Barboza Subject: [PATCH 10/16] target/riscv/kvm.c: init 'misa_ext_mask' with scratch CPU Date: Tue, 30 May 2023 16:46:17 -0300 Message-Id: <20230530194623.272652-11-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2e; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x2e.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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) } } +static void kvm_riscv_init_misa_ext_mask(RISCVCPU *cpu, + KVMScratchCPU *kvmcpu) +{ + CPURISCVState *env = &cpu->env; + struct kvm_one_reg reg; + int ret; + + reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, + KVM_REG_RISCV_CONFIG_REG(isa)); + reg.addr = (uint64_t)&env->misa_ext_mask; + ret = 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 = env->misa_ext_mask; +} + void kvm_riscv_init_user_properties(Object *cpu_obj) { RISCVCPU *cpu = RISCV_CPU(cpu_obj); @@ -406,6 +428,7 @@ void kvm_riscv_init_user_properties(Object *cpu_obj) } kvm_riscv_init_machine_ids(cpu, &kvmcpu); + kvm_riscv_init_misa_ext_mask(cpu, &kvmcpu); kvm_riscv_destroy_scratch_vcpu(&kvmcpu); } @@ -525,21 +548,10 @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs) int kvm_arch_init_vcpu(CPUState *cs) { int ret = 0; - target_ulong isa; RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - uint64_t id; qemu_add_vm_change_state_handler(kvm_riscv_vm_state_change, cs); - id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, - KVM_REG_RISCV_CONFIG_REG(isa)); - ret = kvm_get_one_reg(cs, id, &isa); - if (ret) { - return ret; - } - env->misa_ext = isa; - if (!object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) { ret = kvm_vcpu_set_machine_ids(cpu, cs); } From patchwork Tue May 30 19:46:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787938 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=BZcI+1dx; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2xn46Ttz20Q4 for ; Wed, 31 May 2023 05:48:13 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45JQ-0006l7-Fv; Tue, 30 May 2023 15:47:20 -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 1q45JK-0006jH-Fw for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:15 -0400 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45JD-0004Kl-Tn for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:11 -0400 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-397f3aec11aso132788b6e.1 for ; Tue, 30 May 2023 12:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476026; x=1688068026; 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=zfn9DXWjJJSb8D6yvpocR+9bA7dcxVV7ukkokFVRYdw=; b=BZcI+1dxIExOHUUGLYGVrMlfrpIOPkQhk8Vy4+LgCuLsPeoGmFXvkUgbhqNY5YyqdC +I8VjtKia7se/AnDPKtG2fS9Kkg4GHw6FFMMlTQq4BcmT235echRJQMm9BU9hPPaNBkO 9QIXtF88NqBZTdPpPsBXI5le0gjyoGIRI1rr4TvOTO3gyt5PNw8i+lWUoE8b3oJVRMwc cKZeXKqBWjqHNWMMHATlIoLtjnVJYdzX5GhN6XKK9LYKAHRH0XlTg3Jx0zaMLupz5MQh BXG8ZD2SX44IVRlKltg6ORTkS2HstK0SdSw6s0X+c55KZCjfgR8Tq62OtQU6lT8DIEF5 NViQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476026; x=1688068026; 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=zfn9DXWjJJSb8D6yvpocR+9bA7dcxVV7ukkokFVRYdw=; b=cPQvq2DuXxe25oolisQ3obmEa+uVntoZ3Aus4NMWOlbUAzgVNTnzB0sGli/60uOStc F1ad0uNSLLEJfzO4+XZ89u4lcGdR69657Nj6QaPcn139QliHJaoRW27Ykd3hEMarTZOh xkYJzt8px82iVOM4s2nqa9/qlpw0Lkac2PftGxg/+7TM9X0a96U3nm8sAcgXSKyadqFv GRdHI896iOjCyIzIILQbJVG5nbeN+jrcZysme5vNZpwD7Xhhok+XodBIwYIWYkYs+Z8/ 8OuMMjwwLa7u4I2jwCzfVTMcEKyNcNquV6QgyPk3JmokHgBFd2VNNxAmhQA8AlcMjcNu DcIg== X-Gm-Message-State: AC+VfDzTBU7aisGvZ/DhXkmA4rVt2++EV0wqyWpIUtZq8mw0p+1pKXH9 mLK8iaain3K/qzrHqXSUwqLvszZ16i+oQTqMNzg= X-Google-Smtp-Source: ACHHUZ4JKynjpDOYWOV3zjRWemFw70NWpPyw4wSxzQUyRgA+gQyZ5GktvVA0cOnTe/F/S7qzKQVr2w== X-Received: by 2002:a05:6808:218c:b0:398:4289:8cc5 with SMTP id be12-20020a056808218c00b0039842898cc5mr2098743oib.20.1685476026454; Tue, 30 May 2023 12:47:06 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:47:06 -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, Daniel Henrique Barboza Subject: [PATCH 11/16] target/riscv: add KVM specific MISA properties Date: Tue, 30 May 2023 16:46:18 -0300 Message-Id: <20230530194623.272652-12-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22d; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22d.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Using all TCG user properties in KVM is tricky. First because KVM supports only a small subset of what TCG provides, so most of the cpu->cfg flags do nothing for KVM. Second, and more important, we don't have a way of telling if any given value is an user input or not. For TCG this has a small impact since we just validating everything and error out if needed. But for KVM it would be good to know if a given value was set by the user or if it's a value already provided by KVM. Otherwise we don't know how to handle failed kvm_set_one_regs() when writing the configurations back. These characteristics make it overly complicated to use the same user facing flags for both KVM and TCG. A simpler approach is to create KVM specific properties that have specialized logic, forking KVM and TCG use cases for those cases only. Fully separating KVM/TCG properties is unneeded at this point - in fact we want the user experience to be as equal as possible, regardless of the acceleration chosen. We'll start this fork with the MISA properties, adding the MISA bits that the KVM driver currently supports. The KVM version of RISCVCPUMisaExtConfig and kvm_misa_ext_cfgs[] are inspired by the existing RISCVCPUMisaExtConfig and misa_ext_cfgs[] from target/riscv/cpu.c. For KVM we're adding an extra oomph in RISCVCPUMisaExtConfig with the 'user_set' boolean. This flag will be set when the user set an option that's different than what is already configured in the host, requiring KVM intervention to write the regs back during kvm_arch_init_vcpu(). There is no need to duplicate more code than necessary, so we're going to use the existing kvm_riscv_init_user_properties() to add the KVM specific properties. Any code that is adding a TCG user prop is then changed slightly to verify first if there's a KVM prop with the same name already added. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 10 ++++++ target/riscv/kvm.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 749d8bf5eb..3c348049a3 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1587,6 +1587,11 @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) { const RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i]; + /* Check if KVM didn't create the property already */ + if (object_property_find(cpu_obj, misa_cfg->name)) { + continue; + } + object_property_add(cpu_obj, misa_cfg->name, "bool", cpu_get_misa_ext_cfg, cpu_set_misa_ext_cfg, @@ -1710,6 +1715,11 @@ static void riscv_cpu_add_user_properties(Object *obj) riscv_cpu_add_misa_properties(obj); for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { + /* Check if KVM didn't create the property already */ + if (object_property_find(obj, prop->name)) { + continue; + } + qdev_property_add_static(dev, prop); } diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 4d0808cb9a..6afd56cda5 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -22,8 +22,10 @@ #include #include "qemu/timer.h" +#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" +#include "qapi/visitor.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" #include "sysemu/kvm_int.h" @@ -105,6 +107,81 @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, } \ } while (0) +typedef struct RISCVCPUMisaExtConfig { + const char *name; + const char *description; + target_ulong misa_bit; + int kvm_reg_id; + bool user_set; +} RISCVCPUMisaExtConfig; + +/* KVM ISA extensions */ +static RISCVCPUMisaExtConfig kvm_misa_ext_cfgs[] = { + {.name = "a", .description = "Atomic instructions", + .misa_bit = RVA, .kvm_reg_id = KVM_RISCV_ISA_EXT_A}, + {.name = "c", .description = "Compressed instructions", + .misa_bit = RVC, .kvm_reg_id = KVM_RISCV_ISA_EXT_C}, + {.name = "d", .description = "Double-precision float point", + .misa_bit = RVD, .kvm_reg_id = KVM_RISCV_ISA_EXT_D}, + {.name = "f", .description = "Single-precision float point", + .misa_bit = RVF, .kvm_reg_id = KVM_RISCV_ISA_EXT_F}, + {.name = "h", .description = "Hypervisor", + .misa_bit = RVH, .kvm_reg_id = KVM_RISCV_ISA_EXT_H}, + {.name = "i", .description = "Base integer instruction set", + .misa_bit = RVI, .kvm_reg_id = KVM_RISCV_ISA_EXT_I}, + {.name = "m", .description = "Integer multiplication and division", + .misa_bit = RVM, .kvm_reg_id = KVM_RISCV_ISA_EXT_M}, +}; + +static void kvm_cpu_set_misa_ext_cfg(Object *obj, Visitor *v, + const char *name, + void *opaque, Error **errp) +{ + RISCVCPUMisaExtConfig *misa_ext_cfg = opaque; + target_ulong misa_bit = misa_ext_cfg->misa_bit; + RISCVCPU *cpu = RISCV_CPU(obj); + CPURISCVState *env = &cpu->env; + bool value, host_bit; + + if (!visit_type_bool(v, name, &value, errp)) { + return; + } + + host_bit = env->misa_ext_mask & misa_bit; + + if (value == host_bit) { + return; + } + + if (!value) { + misa_ext_cfg->user_set = true; + return; + } + + /* + * Forbid users to enable extensions that aren't + * available in the hart. + */ + error_setg(errp, "Enabling MISA bit '%s' is not allowed: it's not " + "enabled in the host", misa_ext_cfg->name); +} + +static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(kvm_misa_ext_cfgs); i++) { + RISCVCPUMisaExtConfig *misa_cfg = &kvm_misa_ext_cfgs[i]; + + object_property_add(cpu_obj, misa_cfg->name, "bool", + NULL, + kvm_cpu_set_misa_ext_cfg, + NULL, misa_cfg); + object_property_set_description(cpu_obj, misa_cfg->name, + misa_cfg->description); + } +} + static int kvm_riscv_get_regs_core(CPUState *cs) { int ret = 0; @@ -427,6 +504,7 @@ void kvm_riscv_init_user_properties(Object *cpu_obj) return; } + kvm_riscv_add_cpu_user_properties(cpu_obj); kvm_riscv_init_machine_ids(cpu, &kvmcpu); kvm_riscv_init_misa_ext_mask(cpu, &kvmcpu); From patchwork Tue May 30 19:46:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=U+s8u7dz; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2yg4P99z20Q4 for ; Wed, 31 May 2023 05:48:59 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45JR-0006mr-EX; Tue, 30 May 2023 15:47:21 -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 1q45JK-0006jI-Fy for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:15 -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 1q45JH-0004L2-80 for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:12 -0400 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-19a13476ffeso3821996fac.0 for ; Tue, 30 May 2023 12:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476030; x=1688068030; 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=cd9JOx+5sZlBShuxbAm/YknaytC2WuApRr7KjE0e3dw=; b=U+s8u7dzwJHe3/qDV4ql8xRxSpcb9bgQ0vfvh8ionCECTwOlnvohWTITpBEsxPPjR9 KpZYGKsDQtMWljAJT66GWK8ERBuTg3oAR3f3RUmNL/qT6SBscJyng13K7txVTegISsMZ wtK9uaUE8J+RGqprY2EPMpJ+SzOsCluvQDD4H1yZ98DsabLsp9dRWut+zr3yrnb8EZVS 56cAiJiz9P1v6G919q2PiLwhtybgmDRp9adaxODZ8lqxwJq5fuR+BYhwuhrz9ftEr1J7 ufD/EVTXp8o8Ba4a2MadgtpnjuDgeqcI+NIYwaNpk2kbQmcr4JrgQMiMhxCAIbY2PE4Z niRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476030; x=1688068030; 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=cd9JOx+5sZlBShuxbAm/YknaytC2WuApRr7KjE0e3dw=; b=cj0KF7m2Me/yKEHe2LXmWw1M4hAanE7AF21konOUb0l1OvspBt5tXPwkPD/aOeo0dP 8rklD3H1vMGsxDF5SSua5aKkbK0kBAAlbW8FdGdk+7z73r6EphEWk42o7FNz8zJu7qOF XmR4Nc9a0aZQrpd/RyWkm5GDr1zI1O4DQGI/bAUG+Tozr2fVMOlffPus4uQZdBl9Smmz SbJ0/R5f+nbsOnEgPnQdQpo317+a1RnXNWsAj9GbiC0uZdLIkkyiGvK1q0qMIteWiBJb DcO4QpKAJec7fWxZtqBHuqNxEvDEYRgYH41XgoaLcK5ObrKsMCAW7FWKXMN0Ujp8us0w A4mQ== X-Gm-Message-State: AC+VfDx5zz04g27T9aeQq/m+w7MDGHto2XWPlHaBQE3BOhk9QsgzbLIo ubJyX4I1OEiDJQSmnfMMJQzzb+ocPVN42wLqfhI= X-Google-Smtp-Source: ACHHUZ74J/dintgtnuTEUvXiFquyGTVNCezfqGVB/mRu1nZFK9OgWhpHQw6M/aMbtZ/kW2kyxeM5Fw== X-Received: by 2002:a05:6871:8e06:b0:19f:698f:56a1 with SMTP id zp6-20020a0568718e0600b0019f698f56a1mr1514796oab.15.1685476029729; Tue, 30 May 2023 12:47:09 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.47.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:47:09 -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, Daniel Henrique Barboza Subject: [PATCH 12/16] target/riscv/kvm.c: update KVM MISA bits Date: Tue, 30 May 2023 16:46:19 -0300 Message-Id: <20230530194623.272652-13-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Our design philosophy with KVM properties can be resumed in two main decisions based on KVM interface availability and what the user wants to do: - if the user disables an extension that the host KVM module doesn't know about (i.e. it doesn't implement the kvm_get_one_reg() interface), keep booting the CPU. This will avoid users having to deal with issues with older KVM versions while disabling features they don't care; - for any other case we're going to error out immediately. If the user wants to enable a feature that KVM doesn't know about this a problem that is worth aborting - the user must know that the feature wasn't enabled in the hart. Likewise, if KVM knows about the extension, the user wants to enable/disable it, and we fail to do it so, that's also a problem we can't shrug it off. For MISA bits we're going to be a little more conservative: we won't even try enabling bits that aren't already available in the host. The ioctl() is so likely to fail that's not worth trying. This check is already done in the previous patch, in kvm_cpu_set_misa_ext_cfg(), thus we don't need to worry about it now. In kvm_riscv_update_cpu_misa_ext() we'll go through every potential user option and do as follows: - if the user didn't set the property or set to the same value of the host, do nothing; - Disable the given extension in KVM. If it fails we need to verify the error code. -EINVAL indicates that KVM doesn't know about the reg, so re-enable the extension in env->misa_ext and keep booting. If it fails for any other reason we're going to exit out. Signed-off-by: Daniel Henrique Barboza --- target/riscv/kvm.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 6afd56cda5..bb1dafe263 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -166,6 +166,42 @@ static void kvm_cpu_set_misa_ext_cfg(Object *obj, Visitor *v, "enabled in the host", misa_ext_cfg->name); } +static void kvm_riscv_update_cpu_misa_ext(RISCVCPU *cpu, CPUState *cs) +{ + CPURISCVState *env = &cpu->env; + uint64_t id, reg; + int i, ret; + + for (i = 0; i < ARRAY_SIZE(kvm_misa_ext_cfgs); i++) { + RISCVCPUMisaExtConfig *misa_cfg = &kvm_misa_ext_cfgs[i]; + + if (!misa_cfg->user_set) { + continue; + } + + /* If we're here we're going to disable the MISA bit */ + reg = 0; + id = kvm_riscv_reg_id(env, KVM_REG_RISCV_ISA_EXT, + misa_cfg->kvm_reg_id); + ret = kvm_set_one_reg(cs, id, ®); + if (ret != 0) { + if (ret == -EINVAL) { + /* + * KVM doesn't know how to handle this bit. Since + * it's an extension that the user wants to disable, + * do not error out. + */ + continue; + } else { + error_report("Unable to set KVM reg %s, error %d", + misa_cfg->name, ret); + exit(EXIT_FAILURE); + } + } + env->misa_ext &= ~misa_cfg->misa_bit; + } +} + static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) { int i; @@ -632,8 +668,13 @@ int kvm_arch_init_vcpu(CPUState *cs) if (!object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) { ret = kvm_vcpu_set_machine_ids(cpu, cs); + if (ret != 0) { + return ret; + } } + kvm_riscv_update_cpu_misa_ext(cpu, cs); + return ret; } From patchwork Tue May 30 19:46:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787933 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=lFccBwVk; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2xb3YBHz20Tw for ; Wed, 31 May 2023 05:48:02 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45JT-0006pA-PH; Tue, 30 May 2023 15:47:23 -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 1q45JP-0006kV-Nt for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:19 -0400 Received: from mail-oo1-xc2a.google.com ([2607:f8b0:4864:20::c2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45JL-0004Lm-8S for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:18 -0400 Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-557c7ffea48so1924765eaf.1 for ; Tue, 30 May 2023 12:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476033; x=1688068033; 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=vXyrX/hWg5SdONVi7pUjZJLGr6l31mwjZu1Biy0qrQU=; b=lFccBwVkUHRytZGtblPCdsYVYTkK8Z9CNp7oauRS4ei60GzmpZOmfNhv5t6yKAyBnL bKkQXDgoitiGNT4lb2xFBQIcowMV53XF0KsipYFq19LTaPLoA/B+lVt/smVVD9WKGSwT wPYaFLOXH7l8S3m3gWJFsRzkO20MjMuREO+jjjpCLsXlg2RQ/wSeZ9XJpEhc3g7GBn+F n3d3eR30PixIdVAwRvDKqM1M0RuDbvmHtZqzmCsySpK3NS6+Rk1u3yAz+SsIz2VK7drM 5DcaOmSirZbFBedWg74/jnfTaKNKwOv5B3NH7enAR/DeYz6MU7gMOUUjcf6Q8o47gVqe cK6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476033; x=1688068033; 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=vXyrX/hWg5SdONVi7pUjZJLGr6l31mwjZu1Biy0qrQU=; b=Ox5v5tth3EkKgUcKODCGyKZMiGKjAml8b9exUcI4KumdQnb7ZwHtesD2+MCJq+URH/ UsTCkBewXtb61rPs7/OjgcGM2Dr4WIE+cs+CaVz+kHDtUfH57etLY0fbtV0/9neDfrrm 7pwECx5oJ8fwTxveVNa54nSbBuA/qk8+X13e/B3f8qAuzq3F8F/WT4lNucofoZowLqqo MIZuG/nVwLyytArQjv4KkZsuWoNxmmmVbXX7YRpdjrOK1yogBpBgH3Y8eSIqTs+yGIgn KkrBRJZWRd2guBwrnE46IUr6S73cKHAIRTYV5IsjNbOyF3r6QOPZ33+PLZ/5WhYWMgs2 qfpw== X-Gm-Message-State: AC+VfDyDSwMtCiAHQ+VCHsMfgHzzeMj//W0BS0qL5KV0+yi8lrwIwKqV OAfa0y48BUtc5Ap9y+BZqW1a06RpK8qVFg0dDJs= X-Google-Smtp-Source: ACHHUZ41Ft/IGKNjSq/VjiuKwfHkybXxm52zjEvTcOJzx9UcLCHlgtnMs4KG+FT71mFwIckOpx5DNA== X-Received: by 2002:a05:6808:1a93:b0:398:29f4:366d with SMTP id bm19-20020a0568081a9300b0039829f4366dmr1618956oib.5.1685476032787; Tue, 30 May 2023 12:47:12 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:47:12 -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, Daniel Henrique Barboza Subject: [PATCH 13/16] target/riscv/kvm.c: add multi-letter extension KVM properties Date: Tue, 30 May 2023 16:46:20 -0300 Message-Id: <20230530194623.272652-14-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2a; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc2a.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Let's add KVM user properties for the multi-letter extensions that KVM currently supports: zicbom, zicboz, zihintpause, zbb, ssaia, sstc, svinval and svpbmt. As with the recently added MISA properties we're also going to add a 'user_set' flag in each of them. The flag will be set only if the user chose an option that's different from the host and will require extra handling from the KVM driver. However, multi-letter CPUs have more cases to cover than MISA extensions, so we're adding an extra 'supported' flag as well. This flag will reflect if a given extension is supported by KVM, i.e. KVM knows how to handle it. This is determined during KVM extension discovery in kvm_riscv_init_multiext_cfg(), where we test for EINVAL errors. Any other error different from EINVAL will cause an abort. The 'supported' flag will then be used later on to give an exception for users that are disabling multi-letter extensions that are unknown to KVM. Signed-off-by: Daniel Henrique Barboza --- target/riscv/kvm.c | 136 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index bb1dafe263..b4193a10d8 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -202,6 +202,99 @@ static void kvm_riscv_update_cpu_misa_ext(RISCVCPU *cpu, CPUState *cs) } } +typedef struct RISCVCPUMultiExtConfig { + const char *name; + int kvm_reg_id; + int cpu_cfg_offset; + bool supported; + bool user_set; +} RISCVCPUMultiExtConfig; + +#define CPUCFG(_prop) offsetof(struct RISCVCPUConfig, _prop) + +/* + * KVM ISA Multi-letter extensions. We care about the order + * since it'll be used to create the ISA string later on. + * We follow the same ordering rules of isa_edata_arr[] + * from target/riscv/cpu.c. + */ +static RISCVCPUMultiExtConfig kvm_multi_ext_cfgs[] = { + {.name = "zicbom", .kvm_reg_id = KVM_RISCV_ISA_EXT_ZICBOM, + .cpu_cfg_offset = CPUCFG(ext_icbom)}, + {.name = "zicboz", .kvm_reg_id = KVM_RISCV_ISA_EXT_ZICBOZ, + .cpu_cfg_offset = CPUCFG(ext_icboz)}, + {.name = "zihintpause", .kvm_reg_id = KVM_RISCV_ISA_EXT_ZIHINTPAUSE, + .cpu_cfg_offset = CPUCFG(ext_zihintpause)}, + {.name = "zbb", .kvm_reg_id = KVM_RISCV_ISA_EXT_ZBB, + .cpu_cfg_offset = CPUCFG(ext_zbb)}, + {.name = "ssaia", .kvm_reg_id = KVM_RISCV_ISA_EXT_SSAIA, + .cpu_cfg_offset = CPUCFG(ext_ssaia)}, + {.name = "sstc", .kvm_reg_id = KVM_RISCV_ISA_EXT_SSTC, + .cpu_cfg_offset = CPUCFG(ext_sstc)}, + {.name = "svinval", .kvm_reg_id = KVM_RISCV_ISA_EXT_SVINVAL, + .cpu_cfg_offset = CPUCFG(ext_svinval)}, + {.name = "svpbmt", .kvm_reg_id = KVM_RISCV_ISA_EXT_SVPBMT, + .cpu_cfg_offset = CPUCFG(ext_svpbmt)}, +}; + +static void kvm_cpu_cfg_set(RISCVCPU *cpu, RISCVCPUMultiExtConfig *multi_ext, + uint32_t val) +{ + int cpu_cfg_offset = multi_ext->cpu_cfg_offset; + bool *ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset; + + *ext_enabled = val; +} + +static uint32_t kvm_cpu_cfg_get(RISCVCPU *cpu, + RISCVCPUMultiExtConfig *multi_ext) +{ + int cpu_cfg_offset = multi_ext->cpu_cfg_offset; + bool *ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset; + + return *ext_enabled; +} + +static void kvm_cpu_set_multi_ext_cfg(Object *obj, Visitor *v, + const char *name, + void *opaque, Error **errp) +{ + RISCVCPUMultiExtConfig *multi_ext_cfg = opaque; + RISCVCPU *cpu = RISCV_CPU(obj); + bool value, host_val; + + if (!visit_type_bool(v, name, &value, errp)) { + return; + } + + host_val = kvm_cpu_cfg_get(cpu, multi_ext_cfg); + + /* + * Ignore if the user is setting the same value + * as the host. + */ + if (value == host_val) { + return; + } + + if (!multi_ext_cfg->supported) { + /* + * Error out if the user is trying to enable an + * extension that KVM doesn't support. Ignore + * option otherwise. + */ + if (value) { + error_setg(errp, "KVM does not support disabling extension %s", + multi_ext_cfg->name); + } + + return; + } + + multi_ext_cfg->user_set = true; + kvm_cpu_cfg_set(cpu, multi_ext_cfg, value); +} + static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) { int i; @@ -216,6 +309,15 @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) object_property_set_description(cpu_obj, misa_cfg->name, misa_cfg->description); } + + for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) { + RISCVCPUMultiExtConfig *multi_cfg = &kvm_multi_ext_cfgs[i]; + + object_property_add(cpu_obj, multi_cfg->name, "bool", + NULL, + kvm_cpu_set_multi_ext_cfg, + NULL, multi_cfg); + } } static int kvm_riscv_get_regs_core(CPUState *cs) @@ -531,6 +633,39 @@ static void kvm_riscv_init_misa_ext_mask(RISCVCPU *cpu, env->misa_ext = env->misa_ext_mask; } +static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) +{ + CPURISCVState *env = &cpu->env; + uint64_t val; + int i, ret; + + for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) { + RISCVCPUMultiExtConfig *multi_ext_cfg = &kvm_multi_ext_cfgs[i]; + struct kvm_one_reg reg; + + reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_ISA_EXT, + multi_ext_cfg->kvm_reg_id); + reg.addr = (uint64_t)&val; + ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, ®); + if (ret != 0) { + if (ret == -EINVAL) { + /* Silently default to 'false' if KVM does not support it. */ + multi_ext_cfg->supported = false; + val = false; + } else { + error_report("Unable to read ISA_EXT KVM register %s, " + "error %d", multi_ext_cfg->name, ret); + kvm_riscv_destroy_scratch_vcpu(kvmcpu); + exit(EXIT_FAILURE); + } + } else { + multi_ext_cfg->supported = true; + } + + kvm_cpu_cfg_set(cpu, multi_ext_cfg, val); + } +} + void kvm_riscv_init_user_properties(Object *cpu_obj) { RISCVCPU *cpu = RISCV_CPU(cpu_obj); @@ -543,6 +678,7 @@ void kvm_riscv_init_user_properties(Object *cpu_obj) kvm_riscv_add_cpu_user_properties(cpu_obj); kvm_riscv_init_machine_ids(cpu, &kvmcpu); kvm_riscv_init_misa_ext_mask(cpu, &kvmcpu); + kvm_riscv_init_multiext_cfg(cpu, &kvmcpu); kvm_riscv_destroy_scratch_vcpu(&kvmcpu); } From patchwork Tue May 30 19:46:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787948 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=VJN/Hh9q; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2z45yFsz20Q4 for ; Wed, 31 May 2023 05:49:20 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45JU-0006pe-BC; Tue, 30 May 2023 15:47:24 -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 1q45JQ-0006lb-LR for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:20 -0400 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45JN-0004M6-85 for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:20 -0400 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-19f62a4924eso1906236fac.1 for ; Tue, 30 May 2023 12:47:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476036; x=1688068036; 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=epKnUxMJfnjeboDrxMeafODKr32ZaDiCpV2zHkEuotc=; b=VJN/Hh9q14yxoxG4OGTtIkYSlc+3VXsIVqR5eX6T/q07V4XO0mPfAK0b1NzjBq5xCf +iEf04eFjAIihPfdInAyuSUSs3wCJKuAE7RTC0sb94W3jtF85a9nm2QZkyea8icgWTeb ddd0egsfvhJpP5w0N+kjbIzsMBWQN3gFAbMsdaMm4UlqnwLH+l+oVuNqJOl0lnhYS8o4 xqWvvhC4yTrDUAROKbM89T2PExkH250Nt4JBH0KuoFqm/EOecILL/5Tkt/d8mG7kG5bC Hz8I5xfsC7Qjv0sw3pcKrnGysY8gwvpNxdrjFt721N+OoPFIscUl20YCWZM72x+jlFsY Skmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476036; x=1688068036; 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=epKnUxMJfnjeboDrxMeafODKr32ZaDiCpV2zHkEuotc=; b=WmtAJpM9G4eNSItCFA/yG6//NHQkA0yDlCwZXLUIXxXhc9L4fllM8xn3kH/udmQn/U iRcxquzkNSS0vppFjlysQyUomBTSWwe/ehkt/3mvlrXEMVZI7Gw43Mg3UoFN+tOTdwuG si9CYXUKuPu2PahB4U63Tf1QNJ04mh32hloFUg755M5MVgu51fWJLgkFyR/TwkwATh1T JwyzijpQq727Ajdh8BzLSjZRvrG9I7CGZNKPkeynZsSrJqYewG2+R3wH+jWI4HjrC1jl M46ojM1mPhC4Fa6cEh5mkwExSW2s1AKBXEYEp28N9sGNH+XfFAM6hGkiM/MtIjl/uSQN ZN8w== X-Gm-Message-State: AC+VfDzj3kEZ9FlUxNr6q4ns+QivpiNAHSsmr5c/sSl3Yrb/KIjWYwT7 QoqPCJckQ0E7hOTJZjknytfI8ZATBxfYRvb+XQo= X-Google-Smtp-Source: ACHHUZ7eGpAlmgmJQ0P9rQe10t5vM/aj6uYj3G3OmVfmL5H25zzINNMlG+k0v5uibkLcleTFK63/rw== X-Received: by 2002:a05:6870:a2d5:b0:19a:48bc:cc9d with SMTP id w21-20020a056870a2d500b0019a48bccc9dmr1351868oak.41.1685476035871; Tue, 30 May 2023 12:47:15 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:47:15 -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, Daniel Henrique Barboza Subject: [PATCH 14/16] target/riscv: adapt 'riscv_isa_string' for KVM Date: Tue, 30 May 2023 16:46:21 -0300 Message-Id: <20230530194623.272652-15-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2a; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x2a.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org KVM is not using the same attributes as TCG, i.e. it doesn't use isa_edata_arr[]. Add a new kvm_riscv_isa_string_ext() helper that does basically the same thing, but using KVM internals instead. The decision to add this helper target/riscv/kvm.c is to foster the separation between KVM and TCG logic, while still using riscv_isa_string_ext() from target/riscv/cpu.c to retrieve the string to not overcomplicate things. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 5 +++++ target/riscv/kvm.c | 19 +++++++++++++++++++ target/riscv/kvm_riscv.h | 2 ++ 3 files changed, 26 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 3c348049a3..ec1d0c621a 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1956,6 +1956,11 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, char *new = *isa_str; int i; + if (riscv_running_KVM()) { + kvm_riscv_isa_string_ext(cpu, isa_str, max_str_len); + return; + } + for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) { if (cpu->env.priv_ver >= isa_edata_arr[i].min_version && isa_ext_is_enabled(cpu, &isa_edata_arr[i])) { diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index b4193a10d8..675e18df3b 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -320,6 +320,25 @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) } } +void kvm_riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, + int max_str_len) +{ + char *old = *isa_str; + char *new = *isa_str; + int i; + + for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) { + RISCVCPUMultiExtConfig *multi_ext_cfg = &kvm_multi_ext_cfgs[i]; + if (kvm_cpu_cfg_get(cpu, multi_ext_cfg)) { + new = g_strconcat(old, "_", multi_ext_cfg->name, NULL); + g_free(old); + old = new; + } + } + + *isa_str = new; +} + static int kvm_riscv_get_regs_core(CPUState *cs) { int ret = 0; diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h index e3ba935808..1a12efa8db 100644 --- a/target/riscv/kvm_riscv.h +++ b/target/riscv/kvm_riscv.h @@ -20,6 +20,8 @@ #define QEMU_KVM_RISCV_H void kvm_riscv_init_user_properties(Object *cpu_obj); +void kvm_riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, + int max_str_len); void kvm_riscv_reset_vcpu(RISCVCPU *cpu); void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level); From patchwork Tue May 30 19:46:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787942 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=RBaHcB00; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2yS5kcRz20Q4 for ; Wed, 31 May 2023 05:48:48 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45JV-0006q5-1i; Tue, 30 May 2023 15:47:25 -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 1q45JT-0006oX-3R for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:23 -0400 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45JQ-0004MY-Jc for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:22 -0400 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-19f68a583a7so129051fac.1 for ; Tue, 30 May 2023 12:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476039; x=1688068039; 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=Jj5q0gQim03Dfqbjx8y7Y2DfBrJ6GzehbS4t//l5qDk=; b=RBaHcB00oSSrGMF73jKqjuY3+u93pcqrkaxzPh9tgO5Ic6Vge2dRrckVoJRAvKm8c9 2z0EXMBhUoQekjjYV870pos5+ACd2KwKIkZ9MzttHlLRbfQTSChJtLu63UdFwNF2pmhs Ovr+qfMzvB4HepLvpS6/SraNDcxZif96YekGZ+QQ4bKm67dfWqCO8bkuYeXlOszRub0E ak5xafRoxRt4t2wE0ciAWvhefi49rUHsaKJj4d5KAKjcg5gqSCt6dTM3WAzf8Rd/eLDR sZ97jOyTTXCgG6/+mFeZxTRDSEI9vKJ2rAoA9ScrmWHA1oi+bDzxnR+v0P7rNqW09zCJ a8zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476039; x=1688068039; 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=Jj5q0gQim03Dfqbjx8y7Y2DfBrJ6GzehbS4t//l5qDk=; b=P2Iq0YorRYlgGiX0VT0Mdr21IFqSZ6uPcwyDvBbrN6zNi18mVZZFqOJhiEElGJxEty 8eQCr8IzpfGYbRrC+BOPes4OPcaMXkqDrvrqpU/bGzaRVoxjtiGLwpmdu1r8w6A2hwxq Sag5eYRjUN+p7DDwuvrppfHIBAE2lkokUof2rJD4W83DpkJXNRrYxZ7qOf0nBRNuZq8O dGHoUphFYrcokSFO2excxgWG868xUnu2l/iOlkPmODKQVZU18qqyLpMvLIcBP4DX/JJO 3ET4R7bHiY3nlhSfhbEgaPObpgVsuyA5zBasw1paUUUT+3MalZ6FEXTeYNlUyxGXBt5g eKbA== X-Gm-Message-State: AC+VfDy8kEDHbG7EAeTvqRC6feX/g8m77nN4NBPMWHqsxwlJ0AzrIsoO TriPa0wsXso6kCyc/9ejlklt+o3LTyPT+9XsuwM= X-Google-Smtp-Source: ACHHUZ5/HpF2/L0F++kDsE3DvqKTw9PUCyLwDn9cl/Uxi3/Jyh9qi1z6i08ZscOpVwmISIJheffWbA== X-Received: by 2002:a05:6870:219c:b0:192:b704:cf2a with SMTP id l28-20020a056870219c00b00192b704cf2amr1959880oae.25.1685476039223; Tue, 30 May 2023 12:47:19 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:47:18 -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, Daniel Henrique Barboza Subject: [PATCH 15/16] target/riscv: update multi-letter extension KVM properties Date: Tue, 30 May 2023 16:46:22 -0300 Message-Id: <20230530194623.272652-16-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::30; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x30.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We're now ready to update the multi-letter extensions status for KVM. kvm_riscv_update_cpu_cfg_isa_ext() is called called during vcpu creation time to verify which user options changes host defaults (via the 'user_set' flag) and tries to write them back to KVM. Failure to commit a change to KVM is only ignored in case KVM doesn't know about the extension (-EINVAL error code) and the user wanted to disable the given extension. Otherwise we're going to abort the boot process. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones --- target/riscv/kvm.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 675e18df3b..92b99fe261 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -295,6 +295,32 @@ static void kvm_cpu_set_multi_ext_cfg(Object *obj, Visitor *v, kvm_cpu_cfg_set(cpu, multi_ext_cfg, value); } +static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) +{ + CPURISCVState *env = &cpu->env; + uint64_t id, reg; + int i, ret; + + for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) { + RISCVCPUMultiExtConfig *multi_ext_cfg = &kvm_multi_ext_cfgs[i]; + + if (!multi_ext_cfg->user_set) { + continue; + } + + id = kvm_riscv_reg_id(env, KVM_REG_RISCV_ISA_EXT, + multi_ext_cfg->kvm_reg_id); + reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg); + ret = kvm_set_one_reg(cs, id, ®); + if (ret != 0) { + error_report("Unable to %s extension %s in KVM, error %d", + reg ? "enable" : "disable", + multi_ext_cfg->name, ret); + exit(EXIT_FAILURE); + } + } +} + static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) { int i; @@ -829,6 +855,7 @@ int kvm_arch_init_vcpu(CPUState *cs) } kvm_riscv_update_cpu_misa_ext(cpu, cs); + kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs); return ret; } From patchwork Tue May 30 19:46:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1787947 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=UJsF939T; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW2z15byGz20Q4 for ; Wed, 31 May 2023 05:49:17 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q45JY-0006ri-5Y; Tue, 30 May 2023 15:47:28 -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 1q45JV-0006qW-EY for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:25 -0400 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q45JT-0004N4-I6 for qemu-devel@nongnu.org; Tue, 30 May 2023 15:47:25 -0400 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-19edebe85adso4360481fac.2 for ; Tue, 30 May 2023 12:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685476042; x=1688068042; 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=CrhzqizdTgnzqcguCNLILoS86odAFap96xtuLIlGjBs=; b=UJsF939TQoL/2clPmqmFLo8VziDSc1NGQD+siLVsM82DEI/4bd20XNn+vABDO9lKWw /VxYaisBeckJS4RcxmYIJJc9XHMWQtZGIagYJOPWIIDtfwnqDzaareM19yNwPzdrEUOW F5NfLqkI3M3ank8Ky/177ZP96vxiiYNLgp5yVbKk2IJ54VNfxYXWNGjFaK12OLAReDE2 CObKHT/LrTZKpkbBOwuqwpSQt3s1vJxAmQf6DyvuiixHC9RHLiNKdDfU2LWHXTitYBFZ 1eWXCyQujImW9KWi1WqPQx2P3TwoHjKkmVqAPMGXghTQJI4/bYfHEKTrtINLwq16YieM L0WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685476042; x=1688068042; 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=CrhzqizdTgnzqcguCNLILoS86odAFap96xtuLIlGjBs=; b=kTqPzu78APwEHbeHV7Yz4i9JLT1fWGo2bQmEDf9CU5V2Uy1o4lI2L+zpDZ2j5R12ZX TsR77PSrNiWUtE5pBwy1ZB1STmV50l/jwjVDQs2detnYOA+a5Z6gYxeJklfZPnc4TViA sVPCk7wqEahvD/X5IFVhLDoAPJA1z7rf6lEvA+b2ur4ByI6XwxIwnIHdjyLmlz5HvLPy dICSq0hyeZetLxekN1Xid/4MjgeWrbFfaxLaJ8OO7PCwCC8XO58N3fFn4kdk+uSHTc4b 3mm7mIaZ0U6FyUNt79a7z3r9k7lSv6oYAZnqckPDjWSW/5/LXE4QkBs5nEeQfGFg0ixd KPmg== X-Gm-Message-State: AC+VfDyqeBbfwp/sN+wtAm2qWE0PIhlg2n6xHBbJZqWuAWqM6zVEsHsq DBaBJKLTcWVcZHr4UlBhZOEqeczO4PfvON2g8MA= X-Google-Smtp-Source: ACHHUZ5ONwqJ+gVY3AxB551xaCjyVjsFHr5BE8pmRrcI60ZEW1z0XwQdMWDXDNSqBEmJUuNHybFtUQ== X-Received: by 2002:a05:6871:4044:b0:172:2d00:99f7 with SMTP id ky4-20020a056871404400b001722d0099f7mr2093104oab.20.1685476042287; Tue, 30 May 2023 12:47:22 -0700 (PDT) Received: from grind.dc1.ventanamicro.com (200-162-225-121.static-corp.ajato.com.br. [200.162.225.121]) by smtp.gmail.com with ESMTPSA id j3-20020a056870a48300b0019fa8728b05sm342214oal.39.2023.05.30.12.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 12:47:21 -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, Daniel Henrique Barboza Subject: [PATCH 16/16] target/riscv/kvm.c: read/write (cbom|cboz)_blocksize in KVM Date: Tue, 30 May 2023 16:46:23 -0300 Message-Id: <20230530194623.272652-17-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530194623.272652-1-dbarboza@ventanamicro.com> References: <20230530194623.272652-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::30; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x30.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If we don't set a proper cbom_blocksize|cboz_blocksize in the FDT the Linux Kernel will fail to detect the availability of the CBOM/CBOZ extensions, regardless of the contents of the 'riscv,isa' DT prop. The FDT is being written using the cpu->cfg.cbom|z_blocksize attributes, so let's use them. We'll also expose them as user flags like it is already done with TCG. However, in contrast with what happens with TCG, the user is not able to set any value that is different from the 'host' value. And KVM can be harsh dealing with it: a ENOTSUPP can be thrown for the mere attempt of executing kvm_set_one_reg() for these 2 regs. We'll read the 'host' value and use it to set these values, regardless of user choice. If the user happened to chose a different value, error out. We'll also error out if we failed to read the block sizes. Signed-off-by: Daniel Henrique Barboza --- target/riscv/kvm.c | 94 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 92b99fe261..7789d835e5 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -241,8 +241,16 @@ static void kvm_cpu_cfg_set(RISCVCPU *cpu, RISCVCPUMultiExtConfig *multi_ext, uint32_t val) { int cpu_cfg_offset = multi_ext->cpu_cfg_offset; - bool *ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset; + uint16_t *blocksize; + bool *ext_enabled; + if (strstr(multi_ext->name, "blocksize")) { + blocksize = (void *)&cpu->cfg + cpu_cfg_offset; + *blocksize = val; + return; + } + + ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset; *ext_enabled = val; } @@ -250,8 +258,15 @@ static uint32_t kvm_cpu_cfg_get(RISCVCPU *cpu, RISCVCPUMultiExtConfig *multi_ext) { int cpu_cfg_offset = multi_ext->cpu_cfg_offset; - bool *ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset; + uint16_t *blocksize; + bool *ext_enabled; + if (strstr(multi_ext->name, "blocksize")) { + blocksize = (void *)&cpu->cfg + cpu_cfg_offset; + return *blocksize; + } + + ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset; return *ext_enabled; } @@ -295,6 +310,33 @@ static void kvm_cpu_set_multi_ext_cfg(Object *obj, Visitor *v, kvm_cpu_cfg_set(cpu, multi_ext_cfg, value); } +/* + * We'll avoid extra complexity by always assuming this + * array order with cbom first. + */ +static RISCVCPUMultiExtConfig kvm_cbomz_blksize_cfgs[] = { + {.name = "cbom_blocksize", .cpu_cfg_offset = CPUCFG(cbom_blocksize), + .kvm_reg_id = KVM_REG_RISCV_CONFIG_REG(zicbom_block_size)}, + {.name = "cboz_blocksize", .cpu_cfg_offset = CPUCFG(cboz_blocksize), + .kvm_reg_id = KVM_REG_RISCV_CONFIG_REG(zicboz_block_size)}, +}; + +static void kvm_cpu_set_cbomz_blksize(Object *obj, Visitor *v, + const char *name, + void *opaque, Error **errp) +{ + RISCVCPUMultiExtConfig *cbomz_size_cfg = opaque; + RISCVCPU *cpu = RISCV_CPU(obj); + uint16_t value; + + if (!visit_type_uint16(v, name, &value, errp)) { + return; + } + + cbomz_size_cfg->user_set = true; + kvm_cpu_cfg_set(cpu, cbomz_size_cfg, value); +} + static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) { CPURISCVState *env = &cpu->env; @@ -321,6 +363,45 @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) } } +static void kvm_riscv_finalize_features(RISCVCPU *cpu, CPUState *cs) +{ + CPURISCVState *env = &cpu->env; + uint64_t id, reg; + int i, ret; + + for (i = 0; i < ARRAY_SIZE(kvm_cbomz_blksize_cfgs); i++) { + RISCVCPUMultiExtConfig *cbomz_cfg = &kvm_cbomz_blksize_cfgs[i]; + uint64_t host_val; + + if ((i == 0 && !cpu->cfg.ext_icbom) || + (i == 1 && !cpu->cfg.ext_icboz)) { + continue; + } + + id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, + cbomz_cfg->kvm_reg_id); + + ret = kvm_get_one_reg(cs, id, &host_val); + if (ret != 0) { + error_report("Unable to read KVM reg val %s, error %d", + cbomz_cfg->name, ret); + exit(EXIT_FAILURE); + } + + if (cbomz_cfg->user_set) { + reg = kvm_cpu_cfg_get(cpu, cbomz_cfg); + if (reg != host_val) { + error_report("Unable to set %s to a different value than " + "the host (%lu)", + cbomz_cfg->name, host_val); + exit(EXIT_FAILURE); + } + } + + kvm_cpu_cfg_set(cpu, cbomz_cfg, host_val); + } +} + static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) { int i; @@ -344,6 +425,14 @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) kvm_cpu_set_multi_ext_cfg, NULL, multi_cfg); } + + for (i = 0; i < ARRAY_SIZE(kvm_cbomz_blksize_cfgs); i++) { + RISCVCPUMultiExtConfig *cbomz_size_cfg = &kvm_cbomz_blksize_cfgs[i]; + + object_property_add(cpu_obj, cbomz_size_cfg->name, "uint16", + NULL, kvm_cpu_set_cbomz_blksize, + NULL, cbomz_size_cfg); + } } void kvm_riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, @@ -856,6 +945,7 @@ int kvm_arch_init_vcpu(CPUState *cs) kvm_riscv_update_cpu_misa_ext(cpu, cs); kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs); + kvm_riscv_finalize_features(cpu, cs); return ret; }