From patchwork Fri Aug 11 18:24:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13351314 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B186C41513 for ; Fri, 11 Aug 2023 18:26:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUWpD-0002MR-2y; Fri, 11 Aug 2023 14:25:27 -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 1qUWpB-0002Kf-W8 for qemu-devel@nongnu.org; Fri, 11 Aug 2023 14:25:26 -0400 Received: from mail-vk1-xa30.google.com ([2607:f8b0:4864:20::a30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUWpA-0003oQ-1f for qemu-devel@nongnu.org; Fri, 11 Aug 2023 14:25:25 -0400 Received: by mail-vk1-xa30.google.com with SMTP id 71dfb90a1353d-48746a002f8so828062e0c.1 for ; Fri, 11 Aug 2023 11:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691778305; x=1692383105; 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=1F7SrSpIXNlKh5W9vshZuEadPvion/6uR1Y68b6CsiE=; b=nXoe5ERThCaQB6Z1anFuYR+pr+yxmf9BZSj1viPU0vvgalrxOaZgr3M4M4V5SUaCvc qtCeVZYB1xJvfODFp7ZEJqUu754N+1zyq7NqQEHSgvhQvJlxMkyeM9Ak8PyUiygWRGx9 CTL3u9zSh4Rj58+DQdeAfsCntTCTYJLEgGoH+TBmLR+/u+NR/XmoimWIB82ewni9O+Ah zc3sbJWqIc8cEpqUNWb+ggWm+DTtqKzLBY6Gasxbp7JtBQjoLgQjtEw4mLcxv29RGIeJ DwfmZ0cLLEn+m2c4in/68p7nUFW44xgH5uL2ey+fIJFeFoGQHHJjl7+Vo6+AysMWsvBz 4BZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691778305; x=1692383105; 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=1F7SrSpIXNlKh5W9vshZuEadPvion/6uR1Y68b6CsiE=; b=MTyesCS6LWZe4a8BEkkh3+JO7KK2gRTj44Fn4bToleoHemQ+Tv/Aby8wPro5tWsDQ1 4HyzjfHcoiX4d/zzre8qMABhrOztKddBW9RENjP/Qq4jWdOJpDJGsELMRJgKSFxtxaqg thateUQzynAkEMc97yrciIVUQXr9esPX1PSbJnBKrxRz1HCkPCGeTaLmMTwVa6tjFwUM vYs16jT5BH7KeLj6dx1eI1wmYo+5LwcyPI8m/9FPZ6Q+4PR9tNYNvSySuQmXK7DrKH1R N0CGCqeFwXhpPxxQrW65gTVVu43Rd3mspH8qtYfatYB71bEBTdFnXdOEUD01syrdSpVa Foiw== X-Gm-Message-State: AOJu0YxmuBxnIRGqigqCSByYY0K6tEjvQfy1vQ7FLsarI7UlkE1yvLm5 9fgkB9gBOXjIImQR433/WOygWhkEfxoAEcgS X-Google-Smtp-Source: AGHT+IF/JGj7BhmkTUdf5BbP+lx7xLzXRcF3qmZybFAK+wPBUDFm6VNJjLVE547SUlmYZhsP8OPt+g== X-Received: by 2002:a05:6102:282f:b0:446:f573:3ec6 with SMTP id ba15-20020a056102282f00b00446f5733ec6mr2322801vsb.9.1691778305464; Fri, 11 Aug 2023 11:25:05 -0700 (PDT) Received: from localhost.localdomain ([146.70.187.10]) by smtp.gmail.com with ESMTPSA id g30-20020ab016de000000b007876731f2dbsm638234uaf.22.2023.08.11.11.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 11:25:05 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Daniel Henrique Barboza , Alistair Francis , Andrew Jones Subject: [PULL 1/2] target/riscv/kvm.c: fix mvendorid size in vcpu_set_machine_ids() Date: Fri, 11 Aug 2023 14:24:44 -0400 Message-ID: <20230811182445.1185140-2-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230811182445.1185140-1-alistair.francis@wdc.com> References: <20230811182445.1185140-1-alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::a30; envelope-from=alistair23@gmail.com; helo=mail-vk1-xa30.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Daniel Henrique Barboza cpu->cfg.mvendorid is a 32 bit field and kvm_set_one_reg() always write a target_ulong val, i.e. a 64 bit field in a 64 bit host. Given that we're passing a pointer to the mvendorid field, the reg is reading 64 bits starting from mvendorid and going 32 bits in the next field, marchid. Here's an example: $ ./qemu-system-riscv64 -machine virt,accel=kvm -m 2G -smp 1 \ -cpu rv64,marchid=0xab,mvendorid=0xcd,mimpid=0xef(...) (inside the guest) # cat /proc/cpuinfo processor : 0 hart : 0 isa : rv64imafdc_zicbom_zicboz_zihintpause_zbb_sstc mmu : sv57 mvendorid : 0xab000000cd marchid : 0xab mimpid : 0xef 'mvendorid' was written as a combination of 0xab (the value from the adjacent field, marchid) and its intended value 0xcd. Fix it by assigning cpu->cfg.mvendorid to a target_ulong var 'reg' and use it as input for kvm_set_one_reg(). Here's the result with this patch applied and using the same QEMU command line: # cat /proc/cpuinfo processor : 0 hart : 0 isa : rv64imafdc_zicbom_zicboz_zihintpause_zbb_sstc mmu : sv57 mvendorid : 0xcd marchid : 0xab mimpid : 0xef This bug affects only the generic (rv64) CPUs when running with KVM in a 64 bit env since the 'host' CPU does not allow the machine IDs to be changed via command line. Fixes: 1fb5a622f7 ("target/riscv: handle mvendorid/marchid/mimpid for KVM CPUs") Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis Reviewed-by: Andrew Jones Message-ID: <20230802180058.281385-1-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- target/riscv/kvm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 9d8a8982f9..b1fd2233c0 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -852,12 +852,19 @@ void kvm_arch_init_irq_routing(KVMState *s) static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs) { CPURISCVState *env = &cpu->env; + target_ulong reg; 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); + /* + * cfg.mvendorid is an uint32 but a target_ulong will + * be written. Assign it to a target_ulong var to avoid + * writing pieces of other cpu->cfg fields in the reg. + */ + reg = cpu->cfg.mvendorid; + ret = kvm_set_one_reg(cs, id, ®); if (ret != 0) { return ret; } From patchwork Fri Aug 11 18:24:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13351316 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06286C001DE for ; Fri, 11 Aug 2023 18:26:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUWpE-0002No-UC; Fri, 11 Aug 2023 14:25: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 1qUWpD-0002Mj-AK for qemu-devel@nongnu.org; Fri, 11 Aug 2023 14:25:27 -0400 Received: from mail-ua1-x92a.google.com ([2607:f8b0:4864:20::92a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUWpA-0003oX-DF for qemu-devel@nongnu.org; Fri, 11 Aug 2023 14:25:27 -0400 Received: by mail-ua1-x92a.google.com with SMTP id a1e0cc1a2514c-79d8edd6d99so750703241.3 for ; Fri, 11 Aug 2023 11:25:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691778306; x=1692383106; 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=xNoSfbOUSMZ0uPLpFeXZj/thZpSQpdkJJbUVXjq2Rnk=; b=dMGlE8xjtJiwfTcstFOh5yu/NaOSNFCr6HqmuQ8Ji506BpNzleuksSmudLTtgCMzaQ oUp8fZXytYHYGK7Z6PmLVDV7eiQa7iEor32zuPl0/eZSGLDNBkzftA7P5U0ykpmWUhaY Gf71NtsIzQBFLGLQ/h/pqMg6rZxGjvum+fpDtE9OTTLKvLFEuSjpTsKHCxyhusT5cLmy 785Eqv3CDQ40HUWSg1s/cp1ztlM6ptTxkwAI4E0HcmaJVRCpqHT1/b6kw9codWPw25YN Q35mmtAsNhoGmyP8M5YzwyGwW8lLYoEJrdY6V2Ff6CjtmwIUsPLLWJG9/RmrsWyPYZa3 alkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691778306; x=1692383106; 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=xNoSfbOUSMZ0uPLpFeXZj/thZpSQpdkJJbUVXjq2Rnk=; b=j+C/kmIqC93dTFqZIFVzyU+kEs3w3CfZ3XQgVTf5m6UkYSXtrDHiEvHDzS+RSRw42P vaEBkJuybBb68bv8iUqFcqEcimVU2h6uMuLG633khqsN8pK0/vLEg4Kola3a0J3obpXK b7qhLZp2Ya/Nt3oNnpN4xZG5nkigbPYDffl5Axx2s+CLr5v1DQNTwUCRGXD3RMfzAvqc N8WLKHHcY5C+nDuUp6aYaZQ9u9DsTyxhCnGJoZbaj597PgaPheqxBr4W+5Cytjrwe9Cr Eu8EDIhz/Jeg8eFPkwrw3ICEFtcfWOdYLQN3Rcpr0w/7KgPfZB+PO6Z31I9EOr2Ii/20 vL/g== X-Gm-Message-State: AOJu0YxdtWo2BzFLpb6EpxOXpdwDDBjWOM7IQGJw3kgoOE562Pqd1KNp KW6AOYL3+XvJeltiimciZMs+3IDP53dzm5bN X-Google-Smtp-Source: AGHT+IEhu7LvbA82YYvDcAG6gHk4ENkcqJ1Kkz/QqOEwQS8Y+hscXPJJ6+hBSwC6Eildlp9Vh+rqDA== X-Received: by 2002:a67:f80d:0:b0:443:6deb:2b4 with SMTP id l13-20020a67f80d000000b004436deb02b4mr2738910vso.2.1691778306537; Fri, 11 Aug 2023 11:25:06 -0700 (PDT) Received: from localhost.localdomain ([146.70.187.10]) by smtp.gmail.com with ESMTPSA id g30-20020ab016de000000b007876731f2dbsm638234uaf.22.2023.08.11.11.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 11:25:06 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Daniel Henrique Barboza , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Alistair Francis Subject: [PULL 2/2] hw/riscv/virt.c: change 'aclint' TCG check Date: Fri, 11 Aug 2023 14:24:45 -0400 Message-ID: <20230811182445.1185140-3-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230811182445.1185140-1-alistair.francis@wdc.com> References: <20230811182445.1185140-1-alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::92a; envelope-from=alistair23@gmail.com; helo=mail-ua1-x92a.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Daniel Henrique Barboza The 'aclint' property is being conditioned with tcg acceleration in virt_machine_class_init(). But acceleration code starts later than the class init of the board, meaning that tcg_enabled() will be always be false during class_init(), and the option is never being declared even when declaring TCG accel: $ ./build/qemu-system-riscv64 -M virt,accel=tcg,aclint=on qemu-system-riscv64: Property 'virt-machine.aclint' not found Fix it by moving the check from class_init() to machine_init(). Tune the description to mention that the option is TCG only. Cc: Philippe Mathieu-Daudé Fixes: c0716c81b ("hw/riscv/virt: Restrict ACLINT to TCG") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1823 Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20230811160224.440697-2-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- hw/riscv/virt.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index d90286dc46..99c4e6314b 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1350,6 +1350,11 @@ static void virt_machine_init(MachineState *machine) exit(1); } + if (!tcg_enabled() && s->have_aclint) { + error_report("'aclint' is only available with TCG acceleration"); + exit(1); + } + /* Initialize sockets */ mmio_irqchip = virtio_irqchip = pcie_irqchip = NULL; for (i = 0; i < socket_count; i++) { @@ -1683,13 +1688,14 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS); #endif - if (tcg_enabled()) { - object_class_property_add_bool(oc, "aclint", virt_get_aclint, - virt_set_aclint); - object_class_property_set_description(oc, "aclint", - "Set on/off to enable/disable " - "emulating ACLINT devices"); - } + + object_class_property_add_bool(oc, "aclint", virt_get_aclint, + virt_set_aclint); + object_class_property_set_description(oc, "aclint", + "(TCG only) Set on/off to " + "enable/disable emulating " + "ACLINT devices"); + object_class_property_add_str(oc, "aia", virt_get_aia, virt_set_aia); object_class_property_set_description(oc, "aia",