From patchwork Thu Jul 6 17:37:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1804445 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Z5Agh7QL; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=a/wMiLR/; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QxkKJ51Cwz20ZQ for ; Fri, 7 Jul 2023 03:38:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8Pat+ibvs2NI4IYWdewhJ0ZjxOjsD0qzA4O6UM6Ucgg=; b=Z5Agh7QLMHy2ng 0ceJKGQhsulYVEdJQQ+Ztm2lUO4Edami0AOUT0w0NlvFOml9Nm6gTaY1I0tFPhpluZThTG7PF1kFU i2VPh2EwZ9kr1ePFY2fDsJXFoSA3Ofl9+aFuaxbCakVP3w/Q1X8ZfmzEujDVg17X/mPYgZMQMExJM vVE1okvb3Y3W9C20vHJfA0PR9j1eJ/OKav/PBVMBi50IXX0ENzkZa4l5NN5Ga7X53JwNPfhmfW+i6 FXGtdGEMTA81UxhH1Bl4IyO7ciLlP/Rc0gfyT7RHp8tozGi0++wao3dx9fwbSycdK0hZ54B9akdDR M1YQKs56EpgQbdIb95hA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHSwC-002Iqg-38; Thu, 06 Jul 2023 17:38:40 +0000 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qHSw9-002Iov-2f for kvm-riscv@lists.infradead.org; Thu, 06 Jul 2023 17:38:39 +0000 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-76c64da0e46so34289139f.0 for ; Thu, 06 Jul 2023 10:38:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688665116; x=1691257116; 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=I4RvkKA5HMlJ9jiuvmt347v/0/0kHBcwrduLKYcFeXM=; b=a/wMiLR/Fj10x0KocTj8ukW8achJVs0fD21O8+oelLoE1eJAqX/bnE7SjMbhi2xfW6 OlRQMdnmIEvTfbOr/UNp6X9FF6dZ6bX0j6/HD5U8IzoZcBlNSX1i+vP/qrEL6G5Yu1wZ 1VNNOXceekZUs/DNt1DWVDxUTZowuXM2FfUTCGLwHzet0s1LAs3ZLn0CBr9rOdLq+Zgn 34zW05zHOyD8MP7CKxwljz3pBYxSIbOzxz0XyjKwoJm9zRKdfMTw5OhTqPVCOESj+WPh aw1XexQ3AdkMKAUC6/9bmBhi43OGo0mlD/G3FHHQDk1Nj799dagrd7Gp6kUxOWff/Fu3 IGiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688665116; x=1691257116; 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=I4RvkKA5HMlJ9jiuvmt347v/0/0kHBcwrduLKYcFeXM=; b=P3neFELXpUyfh/9cgzF/GAq7IdgifjGwMvWvohBWTifm9SbR6z7EyDf5jtdET26eik 8Yl/BVjAkyL0hNZ+7XF9ifg4G3Kl5WnBSRN6L8TBlWqKFka6x/WTHcUG0tm18B3oBdk9 rcpPYDFl8JG3z09vEUisW6XteL2IAIjIqItItFcMACVKTGPgPyJeh8FyUrCZL65odVIt vXl0KJj/6bHyo+3I48uBD0IV1/ilYSXtG+i4i6mVLPsJIvUwjNh6T8I7bDPhstn2+VLn hsTORyIhge5GEk83qzsuwtcxYX2NcrHWHNwi/ZILS73INoVfF94vLcvakqS51gmuDFrv jG8g== X-Gm-Message-State: ABy/qLbERwMbwuRcRLFvz7Mz+gCF0bNWKjJfrQKvlXWgnixehbe9vKz1 NMgQrZiBCNK+wm42OGljJu0uag== X-Google-Smtp-Source: APBJJlHPi63G4ghKH2j2yUusZJg9UQGqLOCn/QM9/Ch6a2hDUV8cfzA7Y7DbI7AAWZEVbGqbBJ9oPg== X-Received: by 2002:a92:c6cf:0:b0:345:ab58:5afd with SMTP id v15-20020a92c6cf000000b00345ab585afdmr2752499ilm.16.1688665116617; Thu, 06 Jul 2023 10:38:36 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id q8-20020a0566380ec800b0042b70c5d242sm633528jas.116.2023.07.06.10.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 10:38:36 -0700 (PDT) From: Anup Patel To: Will Deacon , julien.thierry.kdev@gmail.com, maz@kernel.org Cc: Paolo Bonzini , Atish Patra , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Anup Patel Subject: [kvmtool PATCH v3 2/8] riscv: Allow setting custom mvendorid, marchid, and mimpid Date: Thu, 6 Jul 2023 23:07:58 +0530 Message-Id: <20230706173804.1237348-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706173804.1237348-1-apatel@ventanamicro.com> References: <20230706173804.1237348-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230706_103837_860955_6A5E208B X-CRM114-Status: GOOD ( 11.63 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: We add command-line parameter to set custom mvendorid, marchid, and mimpid so that users can show fake CPU type to Guest/VM which does not match underlying Host CPU. Signed-off-by: Anup Patel --- riscv/include/kvm/kvm-config-arch.h | 12 ++++++++++++ riscv/kvm-cpu.c | 26 +++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 delet [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:d30 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We add command-line parameter to set custom mvendorid, marchid, and mimpid so that users can show fake CPU type to Guest/VM which does not match underlying Host CPU. Signed-off-by: Anup Patel --- riscv/include/kvm/kvm-config-arch.h | 12 ++++++++++++ riscv/kvm-cpu.c | 26 +++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h index 188125c..e64e3ca 100644 --- a/riscv/include/kvm/kvm-config-arch.h +++ b/riscv/include/kvm/kvm-config-arch.h @@ -5,6 +5,9 @@ struct kvm_config_arch { const char *dump_dtb_filename; + u64 custom_mvendorid; + u64 custom_marchid; + u64 custom_mimpid; bool ext_disabled[KVM_RISCV_ISA_EXT_MAX]; }; @@ -12,6 +15,15 @@ struct kvm_config_arch { pfx, \ OPT_STRING('\0', "dump-dtb", &(cfg)->dump_dtb_filename, \ ".dtb file", "Dump generated .dtb to specified file"),\ + OPT_U64('\0', "custom-mvendorid", \ + &(cfg)->custom_mvendorid, \ + "Show custom mvendorid to Guest VCPU"), \ + OPT_U64('\0', "custom-marchid", \ + &(cfg)->custom_marchid, \ + "Show custom marchid to Guest VCPU"), \ + OPT_U64('\0', "custom-mimpid", \ + &(cfg)->custom_mimpid, \ + "Show custom mimpid to Guest VCPU"), \ OPT_BOOLEAN('\0', "disable-sstc", \ &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSTC], \ "Disable Sstc Extension"), \ diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c index f98bd7a..89122b4 100644 --- a/riscv/kvm-cpu.c +++ b/riscv/kvm-cpu.c @@ -22,7 +22,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) { struct kvm_cpu *vcpu; u64 timebase = 0; - unsigned long isa = 0; + unsigned long isa = 0, id = 0; int coalesced_offset, mmap_size; struct kvm_one_reg reg; @@ -64,6 +64,30 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) die("KVM_SET_ONE_REG failed (config.isa)"); + if (kvm->cfg.arch.custom_mvendorid) { + id = kvm->cfg.arch.custom_mvendorid; + reg.id = RISCV_CONFIG_REG(mvendorid); + reg.addr = (unsigned long)&id; + if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) + die("KVM_SET_ONE_REG failed (config.mvendorid)"); + } + + if (kvm->cfg.arch.custom_marchid) { + id = kvm->cfg.arch.custom_marchid; + reg.id = RISCV_CONFIG_REG(marchid); + reg.addr = (unsigned long)&id; + if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) + die("KVM_SET_ONE_REG failed (config.marchid)"); + } + + if (kvm->cfg.arch.custom_mimpid) { + id = kvm->cfg.arch.custom_mimpid; + reg.id = RISCV_CONFIG_REG(mimpid); + reg.addr = (unsigned long)&id; + if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) + die("KVM_SET_ONE_REG failed (config.mimpid)"); + } + /* Populate the vcpu structure. */ vcpu->kvm = kvm; vcpu->cpu_id = cpu_id;