KVM RISC-V fixes for ONE_REG interface
Subsystems (4)
v2 cover KVM RISC-V fixes for ONE_REG interface
This series includes few assorted fixes for KVM RISC-V ONE_REG interface and KVM_GET_REG_LIST API.
These patches can also be found in riscv_kvm_onereg_fixes_v2 branch at:
https://github.com/avpatel/linux.git
Changes since v1:
- Addressed Drew's comments in PATCH4
Anup Patel (4):
RISC-V: KVM: Fix KVM_GET_REG_LIST API for ISA_EXT registers
RISC-V: KVM: Fix riscv_vcpu_get_isa_ext_single() for missing
extensions
KVM: riscv: selftests: Fix ISA_EXT register handling in get-reg-list
KVM: riscv: selftests: Selectively filter-out AIA registers
arch/riscv/kvm/vcpu_onereg.c | 7 ++- .../selftests/kvm/riscv/get-reg-list.c | 58 ++++++++++++++----- 2 files changed, 47 insertions(+), 18 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/4 RISC-V: KVM: Fix KVM_GET_REG_LIST API for ISA_EXT registers
The ISA_EXT registers to enabled/disable ISA extensions for VCPU are always available when underlying host has the corresponding ISA extension. The copy_isa_ext_reg_indices() called by the KVM_GET_REG_LIST API does not align with this expectation so let's fix it.
--- arch/riscv/kvm/vcpu_onereg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kvm/vcpu_onereg.c +1 -1
@@ -842,7 +842,7 @@ static int copy_isa_ext_reg_indices(const struct kvm_vcpu *vcpu,u64 reg =KVM_REG_RISCV | size |KVM_REG_RISCV_ISA_EXT | i; isa_ext = kvm_isa_ext_arr[i]; -if (!__riscv_isa_extension_available (vcpu->arch.isa, isa_ext)) +if (!__riscv_isa_extension_available (NULL , isa_ext))continue ;if (uindices) {
Signature · 1 line
2.34.1
PATCH v2 2/4 RISC-V: KVM: Fix riscv_vcpu_get_isa_ext_single() for missing extensions
In reply to Anup PatelThe riscv_vcpu_get_isa_ext_single() should fail with -ENOENT error when corresponding ISA extension is not available on the host.
--- arch/riscv/kvm/vcpu_onereg.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/riscv/kvm/vcpu_onereg.c +4 -1
@@ -460,8 +460,11 @@ static int riscv_vcpu_get_isa_ext_single(struct kvm_vcpu *vcpu, reg_num >= ARRAY_SIZE(kvm_isa_ext_arr))return -ENOENT ; - *reg_val =0 ; host_isa_ext = kvm_isa_ext_arr[reg_num]; +if (!__riscv_isa_extension_available (NULL , host_isa_ext)) +return -ENOENT ; + + *reg_val =0 ;if (__riscv_isa_extension_available (vcpu->arch.isa, host_isa_ext)) *reg_val =1 ;/* Mark the given extension as available */
Signature · 1 line
2.34.1
PATCH v2 3/4 KVM: riscv: selftests: Fix ISA_EXT register handling in get-reg-list
In reply to Anup PatelSame set of ISA_EXT registers are not present on all host because ISA_EXT registers are visible to the KVM user space based on the ISA extensions available on the host. Also, disabling an ISA extension using corresponding ISA_EXT register does not affect the visibility of the ISA_EXT register itself.
Based on the above, we should filter-out all ISA_EXT registers.
--- .../selftests/kvm/riscv/get-reg-list.c | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-)
tools/testing/selftests/kvm/riscv/get-reg-list.c +21 -14
@@ -14,17 +14,33 @@bool filter_reg (__u64 reg) { +switch (reg & ~REG_MASK ) {/* -* Some ISA extensions are optional and not present on all host, -* but they can't be disabled through ISA_EXT registers when present. -* So, to make life easy, just filtering out these kind of registers. +* Same set of ISA_EXT registers are not present on all host because +* ISA_EXT registers are visible to the KVM user space based on the +* ISA extensions available on the host. Also, disabling an ISA +* extension using corresponding ISA_EXT register does not affect +* the visibility of the ISA_EXT register itself. +* +* Based on above, we should filter-out all ISA_EXT registers. */ -switch (reg & ~REG_MASK ) { +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_A : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_C : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_D : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_F : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_H : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_I : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_M : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_SVPBMT :case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_SSTC :case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_SVINVAL :case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_ZIHINTPAUSE : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_ZICBOM : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_ZICBOZ :case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_ZBB :case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_SSAIA : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_V : +case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_SVNAPOT :case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_ZBA :case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_ZBS :case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_ZICNTR :
@@ -50,12 +66,7 @@ static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext)unsigned long value; ret =__vcpu_get_reg (vcpu,RISCV_ISA_EXT_REG (ext), &value); -if (ret) { -printf ("Failed to get ext %d" , ext); -return false; - } - -return !!value; +return (ret) ? false : !!value; }void finalize_vcpu (struct kvm_vcpu *vcpu,struct vcpu_reg_list *c)
@@ -506,10 +517,6 @@ static __u64 base_regs[] = {KVM_REG_RISCV |KVM_REG_SIZE_U64 |KVM_REG_RISCV_TIMER |KVM_REG_RISCV_TIMER_REG (time),KVM_REG_RISCV |KVM_REG_SIZE_U64 |KVM_REG_RISCV_TIMER |KVM_REG_RISCV_TIMER_REG (compare),KVM_REG_RISCV |KVM_REG_SIZE_U64 |KVM_REG_RISCV_TIMER |KVM_REG_RISCV_TIMER_REG (state), -KVM_REG_RISCV |KVM_REG_SIZE_ULONG |KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_A , -KVM_REG_RISCV |KVM_REG_SIZE_ULONG |KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_C , -KVM_REG_RISCV |KVM_REG_SIZE_ULONG |KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_I , -KVM_REG_RISCV |KVM_REG_SIZE_ULONG |KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_M ,KVM_REG_RISCV |KVM_REG_SIZE_ULONG |KVM_REG_RISCV_SBI_EXT |KVM_REG_RISCV_SBI_SINGLE |KVM_RISCV_SBI_EXT_V01 ,KVM_REG_RISCV |KVM_REG_SIZE_ULONG |KVM_REG_RISCV_SBI_EXT |KVM_REG_RISCV_SBI_SINGLE |KVM_RISCV_SBI_EXT_TIME , KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_IPI,
Signature · 1 line
2.34.1
PATCH v2 4/4 KVM: riscv: selftests: Selectively filter-out AIA registers
In reply to Anup PatelCurrently the AIA ONE_REG registers are reported by get-reg-list as new registers for various vcpu_reg_list configs whenever Ssaia is available on the host because Ssaia extension can only be disabled by Smstateen extension which is not always available.
To tackle this, we should filter-out AIA ONE_REG registers only when Ssaia can't be disabled for a VCPU.
--- .../selftests/kvm/riscv/get-reg-list.c | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/riscv/get-reg-list.c +21 -2
@@ -12,6 +12,8 @@#define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK) +static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX ]; +bool filter_reg (__u64 reg) {switch (reg & ~REG_MASK ) {
@@ -48,6 +50,15 @@ bool filter_reg(__u64 reg)case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_ZIFENCEI :case KVM_REG_RISCV_ISA_EXT |KVM_RISCV_ISA_EXT_ZIHPM :return true; +/* AIA registers are always available when Ssaia can't be disabled */ +case KVM_REG_RISCV_CSR |KVM_REG_RISCV_CSR_AIA |KVM_REG_RISCV_CSR_AIA_REG (siselect): +case KVM_REG_RISCV_CSR |KVM_REG_RISCV_CSR_AIA |KVM_REG_RISCV_CSR_AIA_REG (iprio1): +case KVM_REG_RISCV_CSR |KVM_REG_RISCV_CSR_AIA |KVM_REG_RISCV_CSR_AIA_REG (iprio2): +case KVM_REG_RISCV_CSR |KVM_REG_RISCV_CSR_AIA |KVM_REG_RISCV_CSR_AIA_REG (sieh): +case KVM_REG_RISCV_CSR |KVM_REG_RISCV_CSR_AIA |KVM_REG_RISCV_CSR_AIA_REG (siph): +case KVM_REG_RISCV_CSR |KVM_REG_RISCV_CSR_AIA |KVM_REG_RISCV_CSR_AIA_REG (iprio1h): +case KVM_REG_RISCV_CSR |KVM_REG_RISCV_CSR_AIA |KVM_REG_RISCV_CSR_AIA_REG (iprio2h): +return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA ];default :break ; }
@@ -71,14 +82,22 @@ static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext)void finalize_vcpu (struct kvm_vcpu *vcpu,struct vcpu_reg_list *c) { +unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX ] = {0 };struct vcpu_reg_sublist *s; +int rc; + +for (int i =0 ; i <KVM_RISCV_ISA_EXT_MAX ; i++) +__vcpu_get_reg (vcpu,RISCV_ISA_EXT_REG (i), &isa_ext_state[i]);/* * Disable all extensions which were enabled by default * if they were available in the risc-v host. */ -for (int i =0 ; i <KVM_RISCV_ISA_EXT_MAX ; i++) -__vcpu_set_reg (vcpu,RISCV_ISA_EXT_REG (i),0 ); +for (int i =0 ; i <KVM_RISCV_ISA_EXT_MAX ; i++) { + rc =__vcpu_set_reg (vcpu,RISCV_ISA_EXT_REG (i),0 ); +if (rc && isa_ext_state[i]) + isa_ext_cant_disable[i] = true; + }for_each_sublist (c, s) {if (!s->feature)
Signature · 1 line
2.34.1
Re: [PATCH v2 4/4] KVM: riscv: selftests: Selectively filter-out AIA registers
Quoted 11 lines · Anup Patel
Currently the AIA
ONE_REGregisters are reported by get-reg-list as new registers for variousvcpu_reg_listconfigs whenever Ssaia is available on the host because Ssaia extension can only be disabled by Smstateen extension which is not always available.To tackle this, we should filter-out AIA
ONE_REGregisters only when Ssaia can't be disabled for a VCPU.Fixes 477069398ed6 ("KVM: riscv: selftests: Add get-reg-list test")Signed-off-by Anup Patel <[email protected]>Reviewed-by Atish Patra <[email protected]>
I guess you missed my reply to myself where I corrected my analysis and gave an r-b. Anyway, here it is again, and thanks for fixing up the nits.
Thanks,
drew
Quoted 10 lines · On Wed, Sep 20, 2023 at 9:16?PM Anup Patel <[email protected]> wrote:
This series includes few assorted fixes for KVM RISC-V
ONE_REGinterface andKVM_GET_REG_LISTAPI.These patches can also be found in
riscv_kvm_onereg_fixes_v2branch at:
https://github.com/avpatel/linux.gitChanges since v1:
- Addressed Drew's comments in PATCH4
Quoted 6 lines
Anup Patel (4):
RISC-V: KVM: FixKVM_GET_REG_LISTAPI forISA_EXTregisters
RISC-V: KVM: Fixriscv_vcpu_get_isa_ext_single()for missing
extensions
KVM: riscv: selftests: FixISA_EXTregister handling in get-reg-list
KVM: riscv: selftests: Selectively filter-out AIA registers
Queued this series for 6.6-rcX fixes
Thanks,
Anup
Quoted 8 lines
arch/riscv/kvm/vcpu_onereg.c | 7 ++- .../selftests/kvm/riscv/get-reg-list.c | 58 ++++++++++++++----- 2 files changed, 47 insertions(+), 18 deletions(-)--
2.34.1