Skip to content

Commit 97eccf7

Browse files
yong-xuanavpatel
authored andcommitted
RISC-V: KVM: Add Svade and Svadu Extensions Support for Guest/VM
We extend the KVM ISA extension ONE_REG interface to allow VMM tools to detect and enable Svade and Svadu extensions for Guest/VM. Since the henvcfg.ADUE is read-only zero if the menvcfg.ADUE is zero, the Svadu extension is available for Guest/VM and the Svade extension is allowed to disabledonly when arch_has_hw_pte_young() is true. Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> Link: https://lore.kernel.org/r/20240726084931.28924-4-yongxuan.wang@sifive.com Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent b8d4816 commit 97eccf7

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

arch/riscv/include/uapi/asm/kvm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ enum KVM_RISCV_ISA_EXT_ID {
175175
KVM_RISCV_ISA_EXT_ZCF,
176176
KVM_RISCV_ISA_EXT_ZCMOP,
177177
KVM_RISCV_ISA_EXT_ZAWRS,
178+
KVM_RISCV_ISA_EXT_SVADE,
179+
KVM_RISCV_ISA_EXT_SVADU,
178180
KVM_RISCV_ISA_EXT_MAX,
179181
};
180182

arch/riscv/kvm/vcpu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu)
551551
if (riscv_isa_extension_available(isa, ZICBOZ))
552552
cfg->henvcfg |= ENVCFG_CBZE;
553553

554+
if (riscv_isa_extension_available(isa, SVADU) &&
555+
!riscv_isa_extension_available(isa, SVADE))
556+
cfg->henvcfg |= ENVCFG_ADUE;
557+
554558
if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SMSTATEEN)) {
555559
cfg->hstateen0 |= SMSTATEEN0_HSENVCFG;
556560
if (riscv_isa_extension_available(isa, SSAIA))

arch/riscv/kvm/vcpu_onereg.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <asm/cacheflush.h>
1616
#include <asm/cpufeature.h>
1717
#include <asm/kvm_vcpu_vector.h>
18+
#include <asm/pgtable.h>
1819
#include <asm/vector.h>
1920

2021
#define KVM_RISCV_BASE_ISA_MASK GENMASK(25, 0)
@@ -38,6 +39,8 @@ static const unsigned long kvm_isa_ext_arr[] = {
3839
KVM_ISA_EXT_ARR(SSAIA),
3940
KVM_ISA_EXT_ARR(SSCOFPMF),
4041
KVM_ISA_EXT_ARR(SSTC),
42+
KVM_ISA_EXT_ARR(SVADE),
43+
KVM_ISA_EXT_ARR(SVADU),
4144
KVM_ISA_EXT_ARR(SVINVAL),
4245
KVM_ISA_EXT_ARR(SVNAPOT),
4346
KVM_ISA_EXT_ARR(SVPBMT),
@@ -110,6 +113,12 @@ static bool kvm_riscv_vcpu_isa_enable_allowed(unsigned long ext)
110113
case KVM_RISCV_ISA_EXT_SSCOFPMF:
111114
/* Sscofpmf depends on interrupt filtering defined in ssaia */
112115
return __riscv_isa_extension_available(NULL, RISCV_ISA_EXT_SSAIA);
116+
case KVM_RISCV_ISA_EXT_SVADU:
117+
/*
118+
* The henvcfg.ADUE is read-only zero if menvcfg.ADUE is zero.
119+
* Guest OS can use Svadu only when host OS enable Svadu.
120+
*/
121+
return arch_has_hw_pte_young();
113122
case KVM_RISCV_ISA_EXT_V:
114123
return riscv_v_vstate_ctrl_user_allowed();
115124
default:
@@ -181,6 +190,12 @@ static bool kvm_riscv_vcpu_isa_disable_allowed(unsigned long ext)
181190
/* Extensions which can be disabled using Smstateen */
182191
case KVM_RISCV_ISA_EXT_SSAIA:
183192
return riscv_has_extension_unlikely(RISCV_ISA_EXT_SMSTATEEN);
193+
case KVM_RISCV_ISA_EXT_SVADE:
194+
/*
195+
* The henvcfg.ADUE is read-only zero if menvcfg.ADUE is zero.
196+
* Svade is not allowed to disable when the platform use Svade.
197+
*/
198+
return arch_has_hw_pte_young();
184199
default:
185200
break;
186201
}

0 commit comments

Comments
 (0)