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: 13478911 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="Doeaq1dP" Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160A5D5 for ; Mon, 4 Dec 2023 10:29:14 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5c66bbb3d77so815146a12.0 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=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=Doeaq1dPJxVMgNm1ELPfevgBMEFPj3noVI/Tfy0pjJL1yEuPdpMauvu8Vvlm1x+fhW Jg/QKyAFGWZeGF4D0a/MwIY5mwriANUE4vD+lUzCHCOenRRCmYS6eOl50EP6CKKyQBTw FVzwP4yYykEHAkLAlmap8KbDM8LEzh8Vkrpp3H3xwVfAXaA0iweROLDioCinQMP29JWB 2fsKYGACJl+QfJjTgioZ/sT48jHiqG45vDUza8en651OISKc9eOQxEolsC0XY92IqFMA o5K5kmYSX8dIxxkt1qMglbbDYFSTf6WzPq+SoF5G9BhLUoC9iotdmiMkrJJLQrVXil42 NQYA== 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=AmhyaG4dqgLicMNXlClLUcMJ1e1BtH04cl246iGYdQ8CyAAr8mSUcRYy8z/8wd1ohA fDOuLNWJOhn+D/hqemllTwIWFt7VglTc3kdGbVe6G5xjSeiGFsTGhWStVfSUh3kwpETB QJomSlfS3Xlh/E3p0I4AElzftelONLBlBjFaeyeUHkAsJTcHwUa4ZPPC1/gL5g5tkBdt 8AJHasFLQ6NV3gzyjcu4fhkkkbtk8x/T9ooKLbJiLcdcvxrHcTSDpO5VImLnsRbPPXH7 a8ivXsdL1RE7NStp3Tqll5ACdFQtH+fMczMcPMROW0B3CpKBEAqywoKVA3RJ8yzvN/7p dsRg== X-Gm-Message-State: AOJu0YyfYlMbnE0YUtoRWZC47o2uV5hJdoV6JrkOCnGII2tXZmzwHhoj WrVHnrlgAjMJRtdM45opr+2PEg== 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> 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 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: 13478912 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="Y8v5FiRi" Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E58F6B0 for ; Mon, 4 Dec 2023 10:29:16 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5c6734e0c22so688452a12.0 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=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=Y8v5FiRiLHstq0msZOlqLf8Sl25plGCmGtEsGWsib+DtSVNoCvhs5of/UDX4+tqJcx tOgjGMPj5hRUAxJILcIte+QrCRlue1Rw3BCieflj7Bb6uJtatFoeHdLaG2+pumOgiGzW te5v49Z79q462RpWBrkZmH/8Dqn4ETn4+4oHYEaNL1euMpG6T2cSlJUe0V7qMthp1lTP PvGJc2MKBADD5KHaBDBNMI2tPcxuCcJd1DS0Q/+qgaI9b5F1WKogKQvrJkfF/Sg461UN KKZFcDjUWG+5UtT0pwZksWp4bmEyfB2/vSh9bjPSyPTscDH7y5asI3tyFrd1ekZ1tWEQ 2c7A== 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=sz19pcmHbRpam68zeCXmFScX7L1mID5AxAkJLB1T7yBNJXzr4bFTf0xEm+24/WMzFC UMFPUiv1upmtSTDNqfXmp6Riy1rxHMjbjN24b5ByeRj1VI5neFR/DE1Pot4HJww+8KO5 SqTvDE8YOz+zLAqj5CpNlRT6Zlz1sL5SC/AA48aSV6biUWAHSlvgAj/7yqNJC7nuoQGP eCttxQVsfAY8A98ykogQ4oaN76jjV6PTzyUnE6q7DWjrcMM/28y2FA7d+YWJKSz5B5kd qqV2Dnwq7ExrchmV4wT/PNann1LFbdVR3dTRzxdMotVZjuLFDC3ZGL2+jGLQuJz/UEt4 nNRA== X-Gm-Message-State: AOJu0YxeAK8GwvoVxN5Op9ham+ZUAMMGLb8BeAAx0qnDNsqg1o6iVV8W yG3YkYbEUBJviAaYGaTxX9NzWQ== 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> 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 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: 13478913 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="VZK8D13H" Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A721FB0 for ; Mon, 4 Dec 2023 10:29:19 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6ce3935ffedso2102458b3a.1 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=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=mGBD600RHtXFtkPU4SOmbidKDzxeJ3jBcLp4jGcjDdY=; b=VZK8D13HFVHDoEtqwWG2tsDOa1wVrIclggIjuoiWlByB3xtM0hMEe5DWm68ErjvodA /9u+rXkIrWcjowNu/KX/lGn+fzuZzVPPI7TKsgUTOPtBOUVnFdvjnwlBEiMqSDLRXOPD ldi+a6HpHgXsHdIRwktz/boMMa6fmnI2aSY2OjxStjkNVuWD/lFwa4kK7Fc/JOYxLdgE 65Gk9ZssEj9WX4LLC5KLccfF/bvFMjE0qGvRi5reNGQJa376k3Nc/08ga0xoHL0stCO1 ysnP/X6BK4Hzk8wm+3+ZHssZVgdFio0s1r7S1Wythth84bi+XdayZxEgNp4OV48YFZ3C K/2Q== 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=Swic3vl3Q31JBi7NjRg253lF/kZE+afm1TmaFOzRB8r8NPhHa8JjarYusm2Z0n7en1 W/0JtIWoyBrbSYjLHHT7MYPJz57HE4VN+QQWPBC5Ehquigv25caAxmEtQE7BghVr1Knh r1Wphj3yVf3Cpz+n7yTOSIsZZxGQ2YYY1Y8h4bhvHhjAt+EPVVo4M8h2WSCL4gSOpJlF xI0z95E3yAqthuCPV7V15SEwn8Wo2YwXPHDim4xgkx43wAxtsPCbMpXoK3W0J0/SGICU YsGaV9k/vdUrRwpdBGD9mzp5Oehth6Urk9BPi1TaRx/+RndGovjKUTOIZQxVyVa9Ta8C GErw== X-Gm-Message-State: AOJu0YzvmOfqPtJHgtE31jEkkS+WI8StsoT+BDGUzeNRpZgUoCqJUGFJ d35Hzvt0IKda4yNiTdZ7IzXBEA== 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> 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 | 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;