From patchwork Tue Dec 5 13:50:39 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: 13480242 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 7457BC46CA7 for ; Tue, 5 Dec 2023 13:51:00 +0000 (UTC) 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=8VPHvlRH2OrWpDWxMvljQTa4qeo/TEX8nQIPF+7Ag4Y=; b=bqIkOPZZLZBD2R Nia7nJ5ZQefE/kbbCE5p8n+tiubb5LZYHUJpjjnclnuxFxIe2JoHNf3AplseEz27gu52W7IRwhWkS LnhU6mOqDP8dzSeAHSFG6m1ytQL0hXo/1gdDjk6pB153MeGDI8HipuMPl12E5WJEnl44g7+nnovJX GaWxx5vpE6aLLWl+V4UXBMCOR90eV3FmFWUvTt+DLZJpI+TtHEtI9duSfgp8LdwE1ABmKu0DqsWa6 zCvozh7RaATnSf+usJ+yQRawGgEBg/GuaGiguP/YGOv0NjVqoNbVuYXRjQv4C74UtSBPtRmVBaF/g a0v746ir2v664LBtck/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAVp9-007XJ7-1e; Tue, 05 Dec 2023 13:50:55 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAVp7-007XGs-0V for linux-riscv@lists.infradead.org; Tue, 05 Dec 2023 13:50:54 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6ce6dd83945so584617b3a.3 for ; Tue, 05 Dec 2023 05:50:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1701784251; x=1702389051; darn=lists.infradead.org; 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=Kw9lx7rfek+Fyxn9H19uerjKbw2z7hmkxzJlnytvErY=; b=VFIzyNDRNGNv6yLL5sXGz8dps6Fg9Ofv9eA0HkSUqEEmQIGw6mn5MXLO2UshmC41ok BVLE2a2YC4nqLOcGBNYE2e/V/OzIbY8u1ILvTZ9GmbU8oSPQ3buHydCjwlmNwQtSLxFJ lfLjx92rbDl70xRP9lOcl+kAwsQ/s9mtP3z3FJHmZHdQ9hqnRkPF5ehWVvGknuEfIdx7 k9BYpxh6lAADmWlsJw6be+rMnLO3zQzZyu5TwWz5t4/ulpaRzLXei7sKMNMWUdSxoqks 4QdqAzg7t4zqb79AsiZyWw0L+lncvAPZrsJPPoWYkSB7pDI67VGy/myYm3Alk7+SFuTJ 0v0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701784251; x=1702389051; 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=Kw9lx7rfek+Fyxn9H19uerjKbw2z7hmkxzJlnytvErY=; b=GlOlwA+9jODu3ATs4RMvoFbOMXWFKVl4nbwjslmkJftBfgn6aqsbR6JYl3aKTnmNiy EEQMhGwyLUq7xvikgMsh2g885MDXXIb+AfzeYkU17Cn+HbPcy4pB2ORT21/ZMNqDNuUx tHN/BhU6tT5prkfGuvFUsf1lXPodMVxGKYKnNuDbDheyjcQ1QXf6+fs5uJz/LjXp4Pcr lLLo+O02zlhHMnY4wgcejyymTuCYc1MJ4121x0xvWP5TU6L2MqMG4EAHGDXLaKwMdKxS 9Pr/p+J9wmwdSEn5pHskJMxTP8sxjbOXxawZJWG9vXi0jvmvEPhTP67Vl1I++ompo9Z+ OLEg== X-Gm-Message-State: AOJu0YweSL934HSlnCgjW7DVR44jiulGPMTH0ZPxR9KDIogM9R3+uHrL 9D70Zqn2gqGxUUEcx1KwtzOj4g== X-Google-Smtp-Source: AGHT+IE+MGZNocJKukR2PL4jO1pcCHJx5zeZaiZzHpSE59/id3BPfziDyZviksjyycnDyDaRfgGFtQ== X-Received: by 2002:a05:6a00:849:b0:6ce:60d4:234b with SMTP id q9-20020a056a00084900b006ce60d4234bmr1617686pfk.52.1701784251608; Tue, 05 Dec 2023 05:50:51 -0800 (PST) Received: from grind.. (200-206-229-234.dsl.telesp.net.br. [200.206.229.234]) by smtp.gmail.com with ESMTPSA id c22-20020aa78c16000000b006ce77ffcc75sm673641pfd.165.2023.12.05.05.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 05:50:51 -0800 (PST) From: Daniel Henrique Barboza To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: anup@brainfault.org, atishp@atishpatra.org, palmer@dabbelt.com, ajones@ventanamicro.com, Daniel Henrique Barboza Subject: [PATCH v2 1/3] RISC-V: KVM: set 'vlenb' in kvm_riscv_vcpu_alloc_vector_context() Date: Tue, 5 Dec 2023 10:50:39 -0300 Message-ID: <20231205135041.2208004-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205135041.2208004-1-dbarboza@ventanamicro.com> References: <20231205135041.2208004-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231205_055053_191444_E257D820 X-CRM114-Status: UNSURE ( 7.07 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-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: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 'vlenb', added to riscv_v_ext_state by commit c35f3aa34509 ("RISC-V: vector: export VLENB csr in __sc_riscv_v_state"), isn't being initialized in guest_context. If we export 'vlenb' as a KVM CSR, something we want to do in the next patch, it'll always return 0. Set 'vlenb' to riscv_v_size/32. Signed-off-by: Daniel Henrique Barboza --- arch/riscv/kvm/vcpu_vector.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/riscv/kvm/vcpu_vector.c b/arch/riscv/kvm/vcpu_vector.c index b339a2682f25..530e49c588d6 100644 --- a/arch/riscv/kvm/vcpu_vector.c +++ b/arch/riscv/kvm/vcpu_vector.c @@ -76,6 +76,7 @@ int kvm_riscv_vcpu_alloc_vector_context(struct kvm_vcpu *vcpu, cntx->vector.datap = kmalloc(riscv_v_vsize, GFP_KERNEL); if (!cntx->vector.datap) return -ENOMEM; + cntx->vector.vlenb = riscv_v_vsize / 32; vcpu->arch.host_context.vector.datap = kzalloc(riscv_v_vsize, GFP_KERNEL); if (!vcpu->arch.host_context.vector.datap) From patchwork Tue Dec 5 13:50:40 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: 13480243 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 3FB17C07E97 for ; Tue, 5 Dec 2023 13:51:04 +0000 (UTC) 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=8V2ONYWk6BfBa3IkcU0FydOlGd16n/3zhH2oC16ZAjY=; b=BzXkGzHDqE4460 IaJSmpGuFc0nQQcF26FzVOdDbObGYHSF4LecHQZKEDTCwH0d1NCzIO2YVlc+bp4VaRL+vqJEfcsZm rkKV31/iC/AiN1vvijs/ia5RcX5vIY5CEkxDghWJjV1jQD75/zibdQfAhpUowlrGlpfhiHx77BP33 6Un+OVWVXELGtjM2nqFz9onWHxx1HT74XzdqzhfULZD4TY52SJz46El15W1vdu2aKdB2rmJDuNoMn rKWJc3yYcZWqA+UuuwGmMpcxZfZ6n7g+YuHkfpUpbAMHWfUAZYm+UAz9FGlvXJlbdUTqsmPS9NKfU K8Q8uszDs4aW3Yxta0AA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAVpC-007XLX-2G; Tue, 05 Dec 2023 13:50:58 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAVp9-007XIw-27 for linux-riscv@lists.infradead.org; Tue, 05 Dec 2023 13:50:56 +0000 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5c1f8b0c149so2283666a12.3 for ; Tue, 05 Dec 2023 05:50:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1701784254; x=1702389054; darn=lists.infradead.org; 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=xDmx5prnNC5GcsIkGu5R3qOSAEa8hCYanFPPTHn90qw=; b=GntKl2v+Zm+k+zp2q+vN5X0r3Y7Aks9DnKKm8t5Vi9Y1K+b0LLw2VfFYVz8nbDCPPF 97+pAMReI8gJOampodRU/+xIEYfHryhBkfzZtZjXtGhsSMWzZ0zTMkkV8cI2SxlRimA4 DsJNp6GCJY5dCeHCybi/GDsNljWLPW4wI20Fej3uxNkJnh8ptgLMw7YaArWOsilgNGQL cIVXsOZ4rX0EMAjS3rsac0Y9HhlSjDQtWNGpvW5jw0rEP7tdB1UhXOPqJRPWbkNubjjf Rp2zVGIrngx1onw3r//3GB7gaucNSkaxfTQJtjIrF8NfRyhTjNNmwdk0Q+Iefu22CxKU Xw9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701784254; x=1702389054; 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=xDmx5prnNC5GcsIkGu5R3qOSAEa8hCYanFPPTHn90qw=; b=SvVE6uhw7uWAT7R9lssqee2hyK2W1wpLrIHiuYqyJ6aEDAFpmnE1sk0WgLnC2NxgL8 ezeUATJSna27D9OMu+NwJ8wbK1j5s5/xJqGbPqk/6PNfM+c9zCjeeFwl54o5NAP6VKAC SwO3YcnBSaHQKy8zmYv6W+f2VujbKVdJqOtoWpRXWrHoYfRKCtdNZqkfTpg9twuD/5E5 fQsy6eZjrfQkZyg8MkTwkal6nNPqlrGbbM0/b+0098K++SHc8ldftrRJzSUs4oEabQ/N PrRiIB/8Ouhc78ya1IAO/ya8kMKXYYHE090Mnq+tAc5WB7QENAZvz/OQJc/2Z1QNkLbH MTYg== X-Gm-Message-State: AOJu0YxS5yJA40G94/1brE6kc0zij/Q4s56kNfLF+tgTOH7hGdL8VVxp NFRURR7KLvRpFnfOrBFO5fDGmw== X-Google-Smtp-Source: AGHT+IFFofEjDPFCygGTkPI8Pv4OsjhRCek6+h6rFjjhHBJGn6KCZVf8+gVKPxrIKPeuKD+6UPO0Dw== X-Received: by 2002:a05:6a20:3950:b0:18f:1df2:356 with SMTP id r16-20020a056a20395000b0018f1df20356mr3471659pzg.96.1701784254595; Tue, 05 Dec 2023 05:50:54 -0800 (PST) Received: from grind.. (200-206-229-234.dsl.telesp.net.br. [200.206.229.234]) by smtp.gmail.com with ESMTPSA id c22-20020aa78c16000000b006ce77ffcc75sm673641pfd.165.2023.12.05.05.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 05:50:54 -0800 (PST) From: Daniel Henrique Barboza To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: anup@brainfault.org, atishp@atishpatra.org, palmer@dabbelt.com, ajones@ventanamicro.com, Daniel Henrique Barboza Subject: [PATCH v2 2/3] RISC-V: KVM: add 'vlenb' Vector CSR Date: Tue, 5 Dec 2023 10:50:40 -0300 Message-ID: <20231205135041.2208004-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205135041.2208004-1-dbarboza@ventanamicro.com> References: <20231205135041.2208004-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231205_055055_700965_1F832CE8 X-CRM114-Status: UNSURE ( 9.88 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-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: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Userspace requires 'vlenb' to be able to encode it in reg ID. Otherwise it is not possible to retrieve any vector reg since we're returning EINVAL if reg_size isn't vlenb (see kvm_riscv_vcpu_vreg_addr()). Signed-off-by: Daniel Henrique Barboza --- arch/riscv/kvm/vcpu_vector.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/riscv/kvm/vcpu_vector.c b/arch/riscv/kvm/vcpu_vector.c index 530e49c588d6..d92d1348045c 100644 --- a/arch/riscv/kvm/vcpu_vector.c +++ b/arch/riscv/kvm/vcpu_vector.c @@ -116,6 +116,9 @@ static int kvm_riscv_vcpu_vreg_addr(struct kvm_vcpu *vcpu, case KVM_REG_RISCV_VECTOR_CSR_REG(vcsr): *reg_addr = &cntx->vector.vcsr; break; + case KVM_REG_RISCV_VECTOR_CSR_REG(vlenb): + *reg_addr = &cntx->vector.vlenb; + break; case KVM_REG_RISCV_VECTOR_CSR_REG(datap): default: return -ENOENT; @@ -174,6 +177,18 @@ int kvm_riscv_vcpu_set_reg_vector(struct kvm_vcpu *vcpu, if (!riscv_isa_extension_available(isa, v)) return -ENOENT; + if (reg_num == KVM_REG_RISCV_VECTOR_CSR_REG(vlenb)) { + struct kvm_cpu_context *cntx = &vcpu->arch.guest_context; + unsigned long reg_val; + + if (copy_from_user(®_val, uaddr, reg_size)) + return -EFAULT; + if (reg_val != cntx->vector.vlenb) + return -EINVAL; + + return 0; + } + rc = kvm_riscv_vcpu_vreg_addr(vcpu, reg_num, reg_size, ®_addr); if (rc) return rc; From patchwork Tue Dec 5 13:50:41 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: 13480244 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 61BD7C4167B for ; Tue, 5 Dec 2023 13:51:32 +0000 (UTC) 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=wMZmIvNaS6KSYT+cmefrMva6hPesgDGbt7bFZk4vZwY=; b=draW8RlipQ7DbI 3CpCCB5Q4gYkC7vBw3GuywWKzDdUtsgG3C8nJOwK29zNnebDdBEz44Kqs82BT/7z1C9we+0FrJC+d l8lCQ3rRGVDk2eY2pFVNQqyZTkVEMa6UG2ecao5krryI7LTC6G3LitZeYINKcdxpzf7bZRaKjf979 yTgkssGbN3QXJDAlAG43dOeh7kwLlY+SZ0csqfatQ/125Pr3wBHcE0PBr83k7iw7VKMxvE4jTFFtd j0cZKir4rUu2MbsIupdkVtW9hpLjcCTrJwaPSSi6sQobNAT7UiDjuq53EG0bO1QoJ7UfjGmHErNiU uIOtvQez1Fs9i62qebFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAVpf-007XWz-0Q; Tue, 05 Dec 2023 13:51:27 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAVpc-007XW0-1G for linux-riscv@lists.infradead.org; Tue, 05 Dec 2023 13:51:25 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6cb749044a2so5962628b3a.0 for ; Tue, 05 Dec 2023 05:51:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1701784283; x=1702389083; darn=lists.infradead.org; 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=gWIP8Cx7D+GV9Mq+7uijTcrk0Pfg2qHA9s0FvsGVo74=; b=grwZHxW+AlRzPin4c8I9LlCvUm5vVkt7uOyDCCSlxyJVlOO9oHKw7LgMAJhPfLU4Hx rX5k/s8llJWM0Ks3Otx15F0+qTlSlb9ggAGjs1r6VgiHeEy0pgiFrOUe9n0IdXJCGgum 9pakALwnhrxUo69019/HmK1w+tsaH8DrlLuM/r33Vnu7V3k+P5n+5ONjLmFt6f6B9VIq slsAmjKyF6FTZqXKx666f3RSrLW116AjqISQ05DT7Rw5n86rHFJUubqkrvkP/2QTkELg q1JJQsPThsCjERO7U/mikjdd9Dcun0BrJncZUHsURM0geQePsLRDC/v3CfSLSSEsqInA 0rkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701784283; x=1702389083; 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=gWIP8Cx7D+GV9Mq+7uijTcrk0Pfg2qHA9s0FvsGVo74=; b=FO0oL3xL4Vuv15qjqqfRdR8mPeiPP7hGK95FEsL+pfQhBxUj05vTfIIMLYEaEvgg8V ZC/VAkB6Tv2+nfZhOLWsAuS5vlqS7C2VCueizzbq0gus0+mCZYti0ZXdgNMdqZOz7mqh VPnny7hpEHzxR6V/VnFaUE4OIZ0t4lnLV06CzmujxdPdcBAe8fg3taV/Ehws7QLK1z8A mdSAt/XfKHa6Jetj1cJsQfjDbzEuaps/HbBwfzZ+Qz8l1/Kafiy/fBzD86mW/uoSxtk+ FTqT5e8qpzstS6MrmaWDSpi00QPNBBjEJ4gDo4mBniisFOUg+p9k3tWI/J2ZWN2VWGTL tetA== X-Gm-Message-State: AOJu0YwOn7B0ce0s4zli9aKUtQxH7Dw2Zgv860iIyt1L9gpfhOrjnZzm 6u7KpbugCx3qgQwxCknJJ5fcHQ== X-Google-Smtp-Source: AGHT+IFl6VUO3lxE+m7fVq4lH0JgDU9K0sD3DxngsxIxRWrEodduyQcrtEHmBXOHOq/B4vNQoN+evg== X-Received: by 2002:a05:6a20:a113:b0:18f:b899:21dd with SMTP id q19-20020a056a20a11300b0018fb89921ddmr96150pzk.47.1701784257468; Tue, 05 Dec 2023 05:50:57 -0800 (PST) Received: from grind.. (200-206-229-234.dsl.telesp.net.br. [200.206.229.234]) by smtp.gmail.com with ESMTPSA id c22-20020aa78c16000000b006ce77ffcc75sm673641pfd.165.2023.12.05.05.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 05:50:57 -0800 (PST) From: Daniel Henrique Barboza To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: anup@brainfault.org, atishp@atishpatra.org, palmer@dabbelt.com, ajones@ventanamicro.com, Daniel Henrique Barboza Subject: [PATCH v2 3/3] RISC-V: KVM: add vector CSRs in KVM_GET_REG_LIST Date: Tue, 5 Dec 2023 10:50:41 -0300 Message-ID: <20231205135041.2208004-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205135041.2208004-1-dbarboza@ventanamicro.com> References: <20231205135041.2208004-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231205_055124_428190_AF52893F X-CRM114-Status: GOOD ( 11.61 ) X-BeenThere: linux-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: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add all vector CSRs (vstart, vl, vtype, vcsr, vlenb) in get-reg-list. Signed-off-by: Daniel Henrique Barboza --- arch/riscv/kvm/vcpu_onereg.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c index f8c9fa0c03c5..712785a8f22b 100644 --- a/arch/riscv/kvm/vcpu_onereg.c +++ b/arch/riscv/kvm/vcpu_onereg.c @@ -986,6 +986,35 @@ static int copy_sbi_ext_reg_indices(u64 __user *uindices) return num_sbi_ext_regs(); } +static inline unsigned long num_vector_regs(const struct kvm_vcpu *vcpu) +{ + if (!riscv_isa_extension_available(vcpu->arch.isa, v)) + return 0; + + /* vstart, vl, vtype, vcsr, vlenb; */ + return 5; +} + +static int copy_vector_reg_indices(const struct kvm_vcpu *vcpu, + u64 __user *uindices) +{ + int n = num_vector_regs(vcpu); + u64 reg, size; + + for (int i = 0; i < n; i++) { + size = IS_ENABLED(CONFIG_32BIT) ? KVM_REG_SIZE_U32 : KVM_REG_SIZE_U64; + reg = KVM_REG_RISCV | size | KVM_REG_RISCV_VECTOR | i; + + if (uindices) { + if (put_user(reg, uindices)) + return -EFAULT; + uindices++; + } + } + + return n; +} + /* * kvm_riscv_vcpu_num_regs - how many registers do we present via KVM_GET/SET_ONE_REG * @@ -1001,6 +1030,7 @@ unsigned long kvm_riscv_vcpu_num_regs(struct kvm_vcpu *vcpu) res += num_timer_regs(); res += num_fp_f_regs(vcpu); res += num_fp_d_regs(vcpu); + res += num_vector_regs(vcpu); res += num_isa_ext_regs(vcpu); res += num_sbi_ext_regs(); @@ -1045,6 +1075,11 @@ int kvm_riscv_vcpu_copy_reg_indices(struct kvm_vcpu *vcpu, return ret; uindices += ret; + ret = copy_vector_reg_indices(vcpu, uindices); + if (ret < 0) + return ret; + uindices += ret; + ret = copy_isa_ext_reg_indices(vcpu, uindices); if (ret < 0) return ret;