From patchwork Tue Dec 5 17:45:07 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: 13480518 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 7A9DBC4167B for ; Tue, 5 Dec 2023 17:45:37 +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=cutkEPUTMooGbS swNf1ArsdYDazNkyIhXFwvYJWgs8G2GtuOjNW6dOKuKa+hqyTJO+rltflet8xGrQwGWi/9O9hf5QY g3cUnuWjAuY2UY83kULQudYo8vFdGcduV4ldgW5IGhvLmyz8q8G7JmongLwixlXsKSgbY3UD485te MMbTEw7oVm9iEJTxJaDPKuAtCk2HNzizXAGcP2dwQ9IQMVD978Dsn2ncOUFhWNOuCfd6Vc6PFzcKO ZGbkJPLrqaMX2hp0c7PVOTG+KeYVsfMIAqnF6AMR5clTrtSXWYArTCt78dfohVirnKYJ3PXxkjPBh 8ZmxPNGfv2MevF4HTkRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAZUA-0083qO-0J; Tue, 05 Dec 2023 17:45:30 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAZU8-0083pI-0z for linux-riscv@lists.infradead.org; Tue, 05 Dec 2023 17:45:29 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1d048c171d6so41231545ad.1 for ; Tue, 05 Dec 2023 09:45:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1701798326; x=1702403126; 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=gvnJd6ZNWz5J3AtgKLVBQ5LOL528Z6ovGGer8rgbyfvwCoXQDr6mPO2QWzacadibCB 29C49N+IUN1nnVjq9eL97i4UIMlhAz0dqXxcXJ6aRIjlFaFKuLmleH+SOBC1uaAg6CN4 CgQpU+n4T+QVrq6Bgof5RpDCpGNFrjJoj6Na/pj9PNNz+8z1oRvK9itY2HiSC3kkHM50 MW6bwzot1J9AQ2YlmJot4VAw3H4k1c+PVQTlBEFRJJkVqHnuCPJbGQd45PIcI+9zuqfR NDoSmsD2OUbHaPW+rlYQRtYExSBXJ/AfdqxlbDmkNjoijV9GNgZQnyYvCyA12FH1ThxG 6cUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701798326; x=1702403126; 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=oWaYFLJFWKpIU6aLNKe6v6HGGSelOpBOIc5FHlMORVOuOmHsQuwCJ2aU97QHjzXf7+ aGPx7xCj9XYvQQ0MNz+QCm20Buexzb/dbemVbKjutH8JV3G8hb88JHE77SFaZQnNebcj +nnXm3Y0KCv7XWxxwFo709RXBbv+dhpfLH0MrPMsk6h3/9Vj02u1d68CVdisbt3HCB7L SXBpAJXUh0brtcHw2dRSIYCjiRvPidG8W1CMOc7OhYARMfTsBj45hVj/zFDP9REY6nIp tDgC2DHgp/mqWiKiYGU+a37rd06AO/3PsZB6C/62104Jx5MM9XQPRSFUi1ZiasIoP5Tx uQNg== X-Gm-Message-State: AOJu0YyLr9bOpnh2FD8vmcJuxFbV/ohmv/eH/8kAqz/sYSSE6pSFgZG+ hukvM3EjGy+WonFfGF4FKzEwzA== X-Google-Smtp-Source: AGHT+IF7Y/RolGBXnpDHkOsMt/rkm/fe03CCbMCd5KOY+xnFrO9TY+7df1EdMH6EfJJh7i6FHHqd2Q== X-Received: by 2002:a17:902:e804:b0:1d0:98db:6fd4 with SMTP id u4-20020a170902e80400b001d098db6fd4mr4578699plg.56.1701798326243; Tue, 05 Dec 2023 09:45:26 -0800 (PST) Received: from grind.. ([152.234.124.8]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b001c74df14e6fsm10465705pll.284.2023.12.05.09.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 09:45:25 -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 v3 1/3] RISC-V: KVM: set 'vlenb' in kvm_riscv_vcpu_alloc_vector_context() Date: Tue, 5 Dec 2023 14:45:07 -0300 Message-ID: <20231205174509.2238870-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205174509.2238870-1-dbarboza@ventanamicro.com> References: <20231205174509.2238870-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_094528_342836_1FD906DE X-CRM114-Status: UNSURE ( 7.21 ) 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 17:45: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: 13480520 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 68599C4167B for ; Tue, 5 Dec 2023 17:45:42 +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=QU+Ymf+LXwreCG oTrzS8rjFHBUOpG9/qQpNBMHTJhr3vgzpGdXjhXKLZahEsmcUsk9kuIegtwjFddhZXwjs7VvOPw/Q 78x1jyMQ1Tp3qsoSQ76XMLRdssLtrMWWYLe0+vrKa2GXCxom9SCIuApmiP5PSa/9c7/yOxJ22Nw92 OQ6jMRbGvfJ9xyzfxjDwPBlXzuFfgmbJVmEcfkdTJ/CAH103a4ghLrYRJ7wlY/5goZfnyJs7ja2YQ t41t7MGZ7jeD9k04mRgHXYg3L4giXV3VjdWI7s82weLw22g/znoTeiDxezaZhtvk9QpedyUtQieZa WW1suiYQgGN1Mg6H8GaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAZUG-0083t4-2T; Tue, 05 Dec 2023 17:45:36 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAZUD-0083qa-29 for linux-riscv@lists.infradead.org; Tue, 05 Dec 2023 17:45:34 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d0897e99e0so18830845ad.3 for ; Tue, 05 Dec 2023 09:45:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1701798330; x=1702403130; 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=bTz8WS9TxCIHHb7rBT6XjWp+aftHxpdT6kNpGrkSC7IQAIgCvUIv6MVihdwZeDlobl eSHkjtUGDSLKIcf7MTt7AI5S6OfP9JBlBuJUo7NXvZumJHekd7OjLgd0f8wtIClVKENz JNxkY6nOQfXcaxYuoLNJj6hU/6IjRVdthUqIPqU8BOVjRz2ks88kCp9Yanwh/X8z5KsB uss+B2JgOjdFanh+xK/8EVwyAnPKF/l7/DV0lrvjlBAFD3E310UQ4k38HynPUGkb5DUj tRp0+JvUTTgfSjPmVY1N1ggINrF+N86+P+TdVeqEsosJZeSk+ihkMMJ20fxfKuDzVd90 16LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701798330; x=1702403130; 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=SrakYdX8M/XSBQO1FT9UVchg59XEWzBjVhWpwA0gcHsBuBldS9fJqZjdYqkH0zEthE tBFwcscnp3mTpF2wQIEH/Gq7WtBp/I+rFixKmA2oOn6f+Kb2OMNjpu7hlcH7coN0K4+D sr6LLsaitznXdEhYNqbjffiF0bs5yFOnYN2FVx/VJKPGsFjuYUStOXagIul4CeCIv/n6 LtEKs5jPDGcft/r5CBF+QgNG2az9MLfzTT4WPrgdG0UL9P9UPNBRjnTE+6CMjZdOO/im dQP8GtsyvbJ1Xegsygw7usKFrjchm6xcGOmw215/KyyVMNC/HYTLkb5vt9ogjvexoH5D peEA== X-Gm-Message-State: AOJu0YxcadFXIkH5NB+ltfHHNH7PxRvX8oXpH66deSQtxlDdRHMotXnS SVRtK6pJu4SOmb8TNdaolCK5qA== X-Google-Smtp-Source: AGHT+IF1UZLtbstXiLGAqb3dZPBrPK0Kg5I3E3SNIV6kA8JjlJ2QhfhiGUU2Udk2N9DtQEvBJyDFVw== X-Received: by 2002:a17:902:748c:b0:1d0:b033:4a98 with SMTP id h12-20020a170902748c00b001d0b0334a98mr2747236pll.17.1701798329723; Tue, 05 Dec 2023 09:45:29 -0800 (PST) Received: from grind.. ([152.234.124.8]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b001c74df14e6fsm10465705pll.284.2023.12.05.09.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 09:45:29 -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 v3 2/3] RISC-V: KVM: add 'vlenb' Vector CSR Date: Tue, 5 Dec 2023 14:45:08 -0300 Message-ID: <20231205174509.2238870-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205174509.2238870-1-dbarboza@ventanamicro.com> References: <20231205174509.2238870-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_094533_702116_3D5EDB76 X-CRM114-Status: GOOD ( 10.00 ) 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 17:45: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: 13480521 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 CBCE3C10F05 for ; Tue, 5 Dec 2023 17:45:43 +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=EkvhbvBn+0f1oZPypMoa6ehi7Qb5BUBj7eWyQJLIGT0=; b=nYfy0Lz5ZR6ki+ Jr4R/frcn0l0c9YiuNuYqFjAwRBcHX5ZmzwvRnJVBlJQ4ol2Un99l0Mgt/pXdC3yLSV+pDeEYijFu s749bxddpVoZHHhsuw4SdZN0YpnzeX3cHMkXE6aMebccbZbFwg1qJJ6sPkBpvxknxehIfHMs5OmBj nF/d/4oEIIJTG94wIB1sKDGoYPdv4pBjXoK8JdQs1jZXY7FudJIHVpN8YRw+mvV0XwTQrQWNFQk4E mGpS9B8TUubgl6I/TgYVQ8Uyyi3cjwzjvkZxXkh62u6rp3ZOzFMFDAJQvtbSBzSkfwnsy1Rh8Q8eX K2Kjjoks3+enjo17o3yA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAZUI-0083u4-1K; Tue, 05 Dec 2023 17:45:38 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAZUG-0083rZ-0u for linux-riscv@lists.infradead.org; Tue, 05 Dec 2023 17:45:37 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1d0b0334ffcso19055485ad.1 for ; Tue, 05 Dec 2023 09:45:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1701798333; x=1702403133; 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=Xh660VR+cynL5ByMmnyvYALQkVg9X3nzQmC84j+D7MQ=; b=YdtGdQ4UizM9e7fAeOXbilUP/Y1Hhe5IE8c4hbCWjhLHEVUWwACVmngViYcdE546GA sTLvZx+DFey7xooVrP0VxAbjM7EjAZ889QRMcdD10siabQ44tCY11BmWCDuoih3imqEK gk0bt3iAww6i3oQ4RlTaKmd5qHZ2/UBYDHZrREsuEctzg6tAuiFvZQFOTvbhDDJFrwVP UfaDEaXJSXt/FtJMH9+UB2Tvld1nf78UxmdXlELoBt2rzage/Ut7R7WfAO3D5boCyyto ffZyDdh46cPubPU+BvbetmZSqWZItBGRDXeypo9lr/q9gai1efuzqSBKDpJlLIV8ftTV 8E1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701798333; x=1702403133; 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=Xh660VR+cynL5ByMmnyvYALQkVg9X3nzQmC84j+D7MQ=; b=QuW76ZoUld6TkZvYBE43oSARAJtET4FZlpjjJ3QdFMfHZ8FfR03ydbB1EA/d4zVIp+ FfPbiCzHoRiRAnWRwIbvliqYQCMty6qTOnZ1kdSDrqkLx6EEi9Cf7Mk+3PMsUNdxCmk5 EG43Qmx/nPsGdcVkCHiSP+moraL4jVoHfug9tSk0x1EDGi4LnI3dhSPfzGoKziwkqEBz nestNYK3SR/VKbZNjSEYNCTRic69q5GDe8T//1xM3J2X+KFwVcCzfqf8MIO22JLajPun MkRzHNk6Z9vcTQXPQp/2j55xeNyOHaHHPWK1f4rcnJfh7LdE7shyzwB66zOy3Gn27Nh9 e1YQ== X-Gm-Message-State: AOJu0YzeevVPsw2GXftE6YQfixMy8L+XsdeX2jvE3yAVThQHG8NnTbIr TnZHfiY9rssyiXnUJHnX/5WhYw== X-Google-Smtp-Source: AGHT+IHmxq3UYJ5ZQx5exhCrZrdLX5Q8e34CNi9nSp70tBpb4whX5/If4GYuXq2EXsnqnTsBq5YwzQ== X-Received: by 2002:a17:903:1c7:b0:1d0:9c53:9cca with SMTP id e7-20020a17090301c700b001d09c539ccamr4076817plh.96.1701798333325; Tue, 05 Dec 2023 09:45:33 -0800 (PST) Received: from grind.. ([152.234.124.8]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b001c74df14e6fsm10465705pll.284.2023.12.05.09.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 09:45:32 -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 v3 3/3] RISC-V: KVM: add vector CSRs in KVM_GET_REG_LIST Date: Tue, 5 Dec 2023 14:45:09 -0300 Message-ID: <20231205174509.2238870-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205174509.2238870-1-dbarboza@ventanamicro.com> References: <20231205174509.2238870-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_094536_319064_FDB9EFD4 X-CRM114-Status: GOOD ( 14.06 ) 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 | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c index f8c9fa0c03c5..2eb4980295ae 100644 --- a/arch/riscv/kvm/vcpu_onereg.c +++ b/arch/riscv/kvm/vcpu_onereg.c @@ -986,6 +986,55 @@ 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 and 32 vector regs */ + return 37; +} + +static int copy_vector_reg_indices(const struct kvm_vcpu *vcpu, + u64 __user *uindices) +{ + const struct kvm_cpu_context *cntx = &vcpu->arch.guest_context; + int n = num_vector_regs(vcpu); + u64 reg, size; + int i; + + if (n == 0) + return 0; + + /* copy vstart, vl, vtype, vcsr and vlenb */ + size = IS_ENABLED(CONFIG_32BIT) ? KVM_REG_SIZE_U32 : KVM_REG_SIZE_U64; + for (i = 0; i < 5; i++) { + reg = KVM_REG_RISCV | size | KVM_REG_RISCV_VECTOR | i; + + if (uindices) { + if (put_user(reg, uindices)) + return -EFAULT; + uindices++; + } + } + + /* vector_regs have a variable 'vlenb' size */ + size = __builtin_ctzl(cntx->vector.vlenb); + size <<= KVM_REG_SIZE_SHIFT; + for (i = 0; i < 32; i++) { + reg = KVM_REG_RISCV | KVM_REG_RISCV_VECTOR | size | + KVM_REG_RISCV_VECTOR_REG(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 +1050,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 +1095,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;