From patchwork Mon Dec 4 18:29:02 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: 13478931 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 F1AF6C4167B for ; Mon, 4 Dec 2023 18:29: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=8VPHvlRH2OrWpDWxMvljQTa4qeo/TEX8nQIPF+7Ag4Y=; b=xYrEx9H8z1DqIb zKOUrbriOaiOSf0C46VqaVIal1R8a6ym7uz5h/lhUv4xNoMD0Hs6eIBQEaZeMlb9DxMI1o6h5kYPb uL8zE7WQW0RRe2Hwymr5JFnXFTWVsakJbVvIy/z2/JivPlZmiShWIJom8+EP90RVAFPOmsd/cClFp KFLTAKxJpctAo1+A0/6yFqK1OzCH6jSVcsnylnlGQdxlAw/WlU348saXAZtiyLoxQDfakAuhIZ1Tr ljJkLqqzb7hPR6LFD/aGUm2I6eNUSRkWIuNBXxa3IFLNriNWMlgeIb1YZD+nPw3WS5M54TLn9W8nO NTJUzumub0jY7UCpqI/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rADh0-005JMz-0e; Mon, 04 Dec 2023 18:29:18 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rADgw-005JLV-1u for linux-riscv@lists.infradead.org; Mon, 04 Dec 2023 18:29:16 +0000 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-5be30d543c4so1580320a12.2 for ; Mon, 04 Dec 2023 10:29:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1701714553; x=1702319353; 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=J5z1/nK+IZsn50nQV4NUWp93rXJtUh/NxQyek3nk5YfizDScu+nesAgStA99nMhV6b 9HqH3nEFDFcnvzOjtVv+zTv2rYyb5Ob6W5Yhf6JJYpQEbzdKYnFp3LO574uLyDfYpuZ/ xgEQhXLFjBNC6rJ7IDeLQWn5tODWMftcP6gxk6aIJcPUOwaR2WJffBGZxmvfYnacIW/G NmWj0RTtSv+4CJZn6OxEnUReT4CCZCdoH/5FciWH7bJPpHc5hACuRmUyexXfn/RbREZx jpnT9u1WpLSwr7AFqG9rfpWUbz+SzXA0RAu9ZqdslL0NL1lZWH3se2O7tdtRV9Vi5P5o zDsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701714553; x=1702319353; 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=hmoZkRPeuc+zbF0EIwVX+z7SvrGVUYx37PLuw6AAeheQYYm84zTo1vSvoWthtb2tVV N9NlcWuBd+kyF346Q1Jns2JFSkcPCdym3QKP5G2QNoCVmwkKRWKR+NIwgPmkwLHNpFYO BL1AJ5ifLkcoPuw+PzN5RfuMojGPyy6UGe5RsGkfa64D5REErKcGS7GWDUtBa4bO3J6Z O1yL0Q9ax113+Gk4rYhaBusinaOBhsXbRyVDCWNv8QJDsPieacOfEY31lfJ7iHnST/cb 3ZCo0yRWYjhTwGJrmkeZGW128stD7rXl61zNNEBJOYtc9StjlnVHHZXqjpkw1Uf7L9/N w8Cg== X-Gm-Message-State: AOJu0YwRcy8ZNnFu5D+t4VJKWcsla03yXiipYTSP+BdWj3R6U+O0uVDF cPAOOXKkwlPXxWDIKoKbfkkayQ== X-Google-Smtp-Source: AGHT+IE7Ek+QAO98xYFQUhE2+KsLzefRKGzxvQR6MjetLHTqt5mcn71POBm0SK15aUZ0cAx/t3xcWg== X-Received: by 2002:a05:6a20:e123:b0:18b:fde7:71ac with SMTP id kr35-20020a056a20e12300b0018bfde771acmr3150854pzb.60.1701714553529; Mon, 04 Dec 2023 10:29:13 -0800 (PST) Received: from grind.. (200-206-229-234.dsl.telesp.net.br. [200.206.229.234]) by smtp.gmail.com with ESMTPSA id it19-20020a056a00459300b006cdce7c69d9sm1806224pfb.91.2023.12.04.10.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 10:29:13 -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 1/3] RISC-V: KVM: set 'vlenb' in kvm_riscv_vcpu_alloc_vector_context() Date: Mon, 4 Dec 2023 15:29:02 -0300 Message-ID: <20231204182905.2163676-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231204182905.2163676-1-dbarboza@ventanamicro.com> References: <20231204182905.2163676-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231204_102914_628006_596DB8F1 X-CRM114-Status: UNSURE ( 7.38 ) 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 Mon Dec 4 18:29:03 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: 13478928 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 0327AC4167B for ; Mon, 4 Dec 2023 18:29:28 +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=E/2GcklVCN+pEK IBo2Uk+9Q04jbojUzk0QfrEa0XE198FYZmJTanaZ9j1jkj1bTVSZWsq1tALp0zDGbH6ucJ6YKIHh0 XmY9ohSBGS1ilzXcuYJyX6R7GoKdCrYiNGjDZb0z+Ymvl0BHfL0fLI75tSsDp8/h3LJjJ8oY3Xv57 bc6vhql9kPqHMwtzi7jokk6a2qW3UW+9uKeW0gV0WUr/bfOcIepXEaDY/MFikp+UBlvq1bBPL7d/S QYITj2ZZpbbJ9yQ3WxuUjoWnRZ8sgblgs7kibVmVNthOukqJGm7IwDpaF1aUegHsrR6i26hmbYDO5 F7rXVxSt/aDfaV9AuJ7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rADh2-005JNw-0W; Mon, 04 Dec 2023 18:29:20 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rADgz-005JMO-0u for linux-riscv@lists.infradead.org; Mon, 04 Dec 2023 18:29:18 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6ce2ff70619so933796b3a.2 for ; Mon, 04 Dec 2023 10:29:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1701714556; x=1702319356; 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=UsoId6VgN25ziZh7HDV5LfgfzEis50+WkAHaFCe/84tdf6jUqG/7PywCtpAgvlqKrd hDQcvzCySFj61quEOTvW7EWdmESu135W02RcqSEZuldlzuXamkjdg0urrQ8H7TMdjL48 1qbbTEzuUID0zmfZPCo53Izfskn09PYIVZkBdlYkg0XcnVeZtjhj66RKakQl98rc9xGW duEtYLvdtf5JQFb7wM6aCtTsoL+O6RVQ1Dtm2+6B7PJXhwIRKUmumReFmBcm5uhSxXTN p3ve7e1KXzwvp4iOfKx8s41C3dBIzO3DS2ca3KbjhW2k7Sx8JAey1TjsMtv/TfSdjA3A K/0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701714556; x=1702319356; 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=abYuM+6gSm9y9vzyxhcvFfR2FZcut5uzjCP2+FWqzqxEnIVvjl2KQsv2v1X58FTFgq SefqQv0MuDBUWexL40gBH6Kp2RHgOpo8zMj91AY6UyMQ3AN4HJQ1HMQJ2W8+L7DiIq9P xLrIx4FX5QhLwEUFkKw9k58SQWaeTJMxaI0syShJU8sTOfnkP6hLHPI68jajSxaTkx4v hqjtfzpCiMa6njpTAJiKp0ytwdcN+wJT8gpyLhAyS1OQX7ovDp1LypTP9A9ru80bltCD Jrouwg/uhevyXBH1VB3fzYgKe2PJACPIYeyHA/9jEaSMC9VK0+0uO5JqXQpcM84F8xGA Uzug== X-Gm-Message-State: AOJu0YwyzvhQlXVXIt1zVc68S655MbrnFn+F2cnmYCx1hjDzq/T2Mr0a uyO3Q3nKZuRGle39EbN8UCbs9A== X-Google-Smtp-Source: AGHT+IG6Wyqv2WvJP1zaZXMUuQtyu1/S6bopl2FuO6DN7j/U4MqqE9hCWwoYJQU65ZQ+sT3VU7DtaA== X-Received: by 2002:a05:6a20:daa7:b0:186:555e:bc80 with SMTP id iy39-20020a056a20daa700b00186555ebc80mr1933829pzb.25.1701714556270; Mon, 04 Dec 2023 10:29:16 -0800 (PST) Received: from grind.. (200-206-229-234.dsl.telesp.net.br. [200.206.229.234]) by smtp.gmail.com with ESMTPSA id it19-20020a056a00459300b006cdce7c69d9sm1806224pfb.91.2023.12.04.10.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 10:29:15 -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 2/3] RISC-V: KVM: add 'vlenb' Vector CSR Date: Mon, 4 Dec 2023 15:29:03 -0300 Message-ID: <20231204182905.2163676-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231204182905.2163676-1-dbarboza@ventanamicro.com> References: <20231204182905.2163676-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231204_102917_533922_9CFEFFC4 X-CRM114-Status: GOOD ( 10.27 ) 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 Mon Dec 4 18:29:04 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: 13478930 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 3F4F4C10DC1 for ; Mon, 4 Dec 2023 18:29:30 +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=gD15Ry/VjV4Qn6es9l1c3ytoApkH2sZlO4FBbH/+1IU=; b=SNGWO4pSnJAqJS MeFVuu3Xf3PyRJsLhuMAyvVuyCBIujbt7sQPveZZFFa9CvtDyCqxvEPIOtMlPlfVVDtcysWU6XKdS QZiDJ9wfd7BYDM4cDwYPCxAaBUkADbkkiAkDvAgV8Gy16dsLhnu3FVS9UZ3BWzg8Qc6jOwM8vdO38 vvN4bQP9vPkM6SoB59ORP8sxCQL4r29XKU+I1lkVgBX718o82eMbb/vzaxjGYPYbGFZAe65abej3y 4MqshNLE594DhfbLaNb8gP/YGSPigPeZp3DWsqJK8mYhpsSGxIEu5qTKHfbed1Mp2b40LL9mlVTsB 1rDGnm3Rl9HQGQ4HOALw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rADh5-005JPw-20; Mon, 04 Dec 2023 18:29:23 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rADh2-005JNl-1H for linux-riscv@lists.infradead.org; Mon, 04 Dec 2023 18:29:21 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6cdd214bce1so5078607b3a.3 for ; Mon, 04 Dec 2023 10:29:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1701714559; x=1702319359; 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=mGBD600RHtXFtkPU4SOmbidKDzxeJ3jBcLp4jGcjDdY=; b=hgPrX1EyehTmTdvTmmPI/WCLHPOdqjbFd/4f9h2mnYXWT4ziFSXXFBFFDhsnoM/8bz Ub8DOnevaYYdDj2MM0GOb3YRogECRK96kL235ARGNAgHl33y5v3R/XR5zjhtbYMUExWD 2PwmM8XHfU3Kc7RhjS3Eg6DZXUm6rRFiVQRu6OlMDdaRQr0yVA2i0TrK0HlYJHxDjpPp dQRMIPZFQ1DRSxvxRSU8cs674sNj9TanR9js4a8XHKc8OH0gsIXABO8YCsq2prqFiH2c 6adbiJwEJu5ucP3fiR6XQ8kMJ3lagn1XKlZ5AHBPJATxKmqnA7Y6Dwbe4VffvMDrVlLq CISA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701714559; x=1702319359; 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=mGBD600RHtXFtkPU4SOmbidKDzxeJ3jBcLp4jGcjDdY=; b=ZP7owT8cbPVb+H8kA42dEArVDzaTWCx2twSDJxLVCAFtVtmGPAkxMn2gtlMuPk7wT/ B0XTHXP8Af64S2EWrbGczSJs5gPklFp57m4+nPWMJ6ep3GU+wN3Z8j8QHnJ0GntkaD+8 maErPil8JZuFy2dyT9XMCwUIX7aqlEkZBdO/3pM1XqxeFN9zW4OPzErzBUKCQBShhFaT KldglJ9qcOfQQ30fyUdJJl4I92ixpm6YXfAAc4ZWPAjWMmcb6TvYq0pheE1czsK8NLWF A5fwVxfWdKlp+unruQ+X4HRUCHwl7UYHGj/5VK8x2Ghauat7dyQ8/IuZWRqgTDh8f58J SW3A== X-Gm-Message-State: AOJu0YyHSnAIjOLg7B1V0W/muUVK607vs4jp/tbdyM9myCadpIH0Hb6j RkxJcqNDmb5MtcMNGxMOp2tJdA== X-Google-Smtp-Source: AGHT+IESIwZmOWM6eeY2+i7bqfBNcq8SQrottFDB8R8T+zVBCK33v9JZ4EZonX0hxRihd6tmXKie+w== X-Received: by 2002:a05:6a00:2d0d:b0:6be:314c:16cb with SMTP id fa13-20020a056a002d0d00b006be314c16cbmr4797997pfb.10.1701714559101; Mon, 04 Dec 2023 10:29:19 -0800 (PST) Received: from grind.. (200-206-229-234.dsl.telesp.net.br. [200.206.229.234]) by smtp.gmail.com with ESMTPSA id it19-20020a056a00459300b006cdce7c69d9sm1806224pfb.91.2023.12.04.10.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 10:29:18 -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 3/3] RISC-V: KVM: add vector CSRs in KVM_GET_REG_LIST Date: Mon, 4 Dec 2023 15:29:04 -0300 Message-ID: <20231204182905.2163676-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231204182905.2163676-1-dbarboza@ventanamicro.com> References: <20231204182905.2163676-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231204_102920_436444_A7EDF451 X-CRM114-Status: GOOD ( 12.09 ) 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 | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c index f8c9fa0c03c5..1c91615f47cc 100644 --- a/arch/riscv/kvm/vcpu_onereg.c +++ b/arch/riscv/kvm/vcpu_onereg.c @@ -986,6 +986,37 @@ 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) +{ + const struct kvm_cpu_context *cntx = &vcpu->arch.guest_context; + + 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 +1032,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 +1077,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;