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: 13480237 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="J4uy7eJA" Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32E84D48 for ; Tue, 5 Dec 2023 05:50:52 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6cc02e77a9cso5468175b3a.0 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=vger.kernel.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=J4uy7eJAkgHRXlMqjYrZm55vQhViwdQpXKbi3SYOvt3WK+47p9hVeubN3W7/oL9WRz O0ZNiZ2vbHMgKLw66y3ixNIV4kDzJNucmy7e4HzGXlrbdTXTEcRjECMANNgEQaIfqrfl ynpEih9FRvmOLa1d5Pvl59Uy2vyf95UlBfdvAeZZLU7xzwBdWR+f1yV/UFRUgrpjq8qJ kSdnipTOufEx2c+yCkAz9578cxGH2j5rXMuTM+LCezfqpr9D7i48YTOvPTcFGUuzIRGR jqEPfeI7pkUh8thv1y0yImnfKDSJpOgFZFgvlr5ODntB3yonPadhyCVjdsycvw+z9pLs NVjA== 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=nFLdQApIc6w2qQ/V/jVaExl2sPDzYl77WU8xRfFB3EqfSpuGSowi6zmc0eK3QATZY/ lYM+gsdGM2dPSV6ruMqeA1oFJtQCrWGMrd45QYGcuo4IDwWJX/uLWfJ7tEiAieLU6Qk5 NpgR4gtLU1X6CVACdJvNE2Q+xjbnoMTBMwUqk+pL6MR+16jp2OOeLrqXEnBAGOsLBWpu Zv41OOsy8iybM8VwgEKcmwP7tfu/j78Sn5xNzUVQ7VICIRSA1MKorjbM1aR06c61/cN4 ciZ6tWBf36b1UdSGN6VyOaEbek6k8n3+Rx94ADYZM98nprpDQjXLyD+oowyrjvLw5F8b 61wg== X-Gm-Message-State: AOJu0YyP7wtzWdceG1zUjqUFj4owxZAgHKL4G1yqbhPqsxRCbXSzwZsS BxMNunlXfJy1EqQa8/+PibWCOw== 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 '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: 13480238 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="KZAHwjKg" Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38183D5E for ; Tue, 5 Dec 2023 05:50:55 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6ce557298f6so1584565b3a.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=vger.kernel.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=KZAHwjKgp2LBtSTwhRd7QX0pVgCtGW51nd0JVlGasJi9WwHD2uLZhnJN0sYMilXjN4 Uk3/eEIiQyNDZnGBtrJJQ8lkbqMHhy3NYJNza/03ckMtykYipMP3Wg9deRO3rwCEseVg ELEHh/PJ0eii12a0YEaUF3p0wpH2EY7O8WZ899zB9+CnzZFspePuVQliqMcs+QGuZNmx Hbls0rMQWjjeC2ywalB6J0R55nL4UOUyipPYmdo4EvySxP6s6gR2y7zUmNuoZoF7CyNX UsU04BYo1ieiJ1jjJ9Z8jWdDSjpWKos/rO6CODvB2Pqb6LUY+7PXVaDEGa235830hPMH U8gw== 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=hV96VK9MgnCTCHuEwNLkQTln23PTJKpNPzFthPFQjiMM1BbjyjVBo/YjbJll97VXnc QBNvW04PmRp7tY09TlcoOv2G+TFBsQlezVMLE6HqvlDrab3UjvLNSR87ZMo8PqB+ftRa xYNn7aG6hsp71MseKEpKFm25oJS0WTsfE7p1mcAhG+dfUZO8Fm765Pxkp94sE0voPcdJ SCx1FbUKKIVINwxEjgkNbw//yPbTCHXoZuc6nsYds9AQftzdnPnkyH4GBm5mPt1GIPfs +S/D2YElavZv2pgoewmNrDhPEEK6ZN0LZdsmoRXQdrhm/oPvKrz1Pw/DhFcFUbVUK8uB mAag== X-Gm-Message-State: AOJu0YzIEq/ey5mG9u5I2xIZR/osbMz9bU1n54wcD94rzpWfMcqjBp3K 9LzCHswv+sZ4osRgJR9ib+J4Ug== 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13480239 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="OZnWz0e5" Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 647A5D40 for ; Tue, 5 Dec 2023 05:51:23 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6ce72730548so439440b3a.1 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=vger.kernel.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=OZnWz0e5qGsiTQYZse/pxHJ0Oxfwe3lDSL7Cych4sandyDGB/UUU6KDAJMWBgA1eqK eW6IrzxxNMxV77jTST45fofO3Q0HVonUoZvEchFKaKzhlTgF6Ik1Oo2s3uBC0yJWIBfL EAD6ByLMIQ14Hb8y8BoNS39iwlJRtS4DPfDC7LFZeSdal4mkQGPpEZdVu12+jJkc19RV x3WEX9ZT4kosOkR3sw07jPO9UGV+c1beDJ/Zk/yQPYryPIB8qNOcGdKqEQGS4ZRG00v5 pcosLy5M30+gDfqT2Xpd23fg5FBg41b8hLU2ePBoIFVgefVyC62vG4/2b3po0RtvDBtA l0cg== 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=Y/qXieUuOt3UseeJBHvIu3h8ccqSect3xhLEEwaZVduQWPKX7oj5TcTpKk/IJSbhLf jzEnpiRG7/uD6RrGS4k1VpUZiiT3Hw6sJggh+nCHf0FH405Jt2q/cT9/loe6Nz18AFN1 cKgKr84Q9nMBDXEZSj1REHixMDEvbgYp8ApzYj6T+sBbPuDK+leUu+LUaXuDjjxLC8Sl FW1JyCJun3k7RZ+RtN3COqcjpJ89lccmwOCd7WGp+n1zYH6UkJKC28GEH3INYlRRYNc+ EQiPjxv6TtbxRisg8wi4bpZpLTARKGNnYG2LJaPQjULrxwzqJ0QFjiYVWsPpmNn4ZT1p RkoQ== X-Gm-Message-State: AOJu0YyiJVL+76k5qQez7NWdlhFMEHqNrISpqaxmEIfj0oTgvQvJAtCK 3GIJNIFyYaT0YZFA7fzA4DBoXQ== 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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;