Skip to content

Commit a6250b1

Browse files
committed
RISC-V: KVM: Introduce feature specific reset for SBI FWFT
The SBI FWFT feature values must be reset upon VCPU reset so introduce feature specific reset callback for this purpose. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Nutty Liu <nutty.liu@hotmail.com> Link: https://lore.kernel.org/r/20250823155947.1354229-3-apatel@ventanamicro.com Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 83df1d6 commit a6250b1

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

arch/riscv/kvm/vcpu_sbi_fwft.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ struct kvm_sbi_fwft_feature {
3030
*/
3131
bool (*supported)(struct kvm_vcpu *vcpu);
3232

33+
/**
34+
* @reset: Reset the feature value irrespective whether feature is supported or not
35+
*
36+
* This callback is mandatory
37+
*/
38+
void (*reset)(struct kvm_vcpu *vcpu);
39+
3340
/**
3441
* @set: Set the feature value
3542
*
@@ -75,6 +82,13 @@ static bool kvm_sbi_fwft_misaligned_delegation_supported(struct kvm_vcpu *vcpu)
7582
return misaligned_traps_can_delegate();
7683
}
7784

85+
static void kvm_sbi_fwft_reset_misaligned_delegation(struct kvm_vcpu *vcpu)
86+
{
87+
struct kvm_vcpu_config *cfg = &vcpu->arch.cfg;
88+
89+
cfg->hedeleg &= ~MIS_DELEG;
90+
}
91+
7892
static long kvm_sbi_fwft_set_misaligned_delegation(struct kvm_vcpu *vcpu,
7993
struct kvm_sbi_fwft_config *conf,
8094
unsigned long value)
@@ -124,6 +138,11 @@ static bool kvm_sbi_fwft_pointer_masking_pmlen_supported(struct kvm_vcpu *vcpu)
124138
return fwft->have_vs_pmlen_7 || fwft->have_vs_pmlen_16;
125139
}
126140

141+
static void kvm_sbi_fwft_reset_pointer_masking_pmlen(struct kvm_vcpu *vcpu)
142+
{
143+
vcpu->arch.cfg.henvcfg &= ~ENVCFG_PMM;
144+
}
145+
127146
static long kvm_sbi_fwft_set_pointer_masking_pmlen(struct kvm_vcpu *vcpu,
128147
struct kvm_sbi_fwft_config *conf,
129148
unsigned long value)
@@ -189,13 +208,15 @@ static const struct kvm_sbi_fwft_feature features[] = {
189208
{
190209
.id = SBI_FWFT_MISALIGNED_EXC_DELEG,
191210
.supported = kvm_sbi_fwft_misaligned_delegation_supported,
211+
.reset = kvm_sbi_fwft_reset_misaligned_delegation,
192212
.set = kvm_sbi_fwft_set_misaligned_delegation,
193213
.get = kvm_sbi_fwft_get_misaligned_delegation,
194214
},
195215
#ifndef CONFIG_32BIT
196216
{
197217
.id = SBI_FWFT_POINTER_MASKING_PMLEN,
198218
.supported = kvm_sbi_fwft_pointer_masking_pmlen_supported,
219+
.reset = kvm_sbi_fwft_reset_pointer_masking_pmlen,
199220
.set = kvm_sbi_fwft_set_pointer_masking_pmlen,
200221
.get = kvm_sbi_fwft_get_pointer_masking_pmlen,
201222
},
@@ -330,11 +351,16 @@ static void kvm_sbi_ext_fwft_deinit(struct kvm_vcpu *vcpu)
330351

331352
static void kvm_sbi_ext_fwft_reset(struct kvm_vcpu *vcpu)
332353
{
333-
int i;
334354
struct kvm_sbi_fwft *fwft = vcpu_to_fwft(vcpu);
355+
const struct kvm_sbi_fwft_feature *feature;
356+
int i;
335357

336-
for (i = 0; i < ARRAY_SIZE(features); i++)
358+
for (i = 0; i < ARRAY_SIZE(features); i++) {
337359
fwft->configs[i].flags = 0;
360+
feature = &features[i];
361+
if (feature->reset)
362+
feature->reset(vcpu);
363+
}
338364
}
339365

340366
const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_fwft = {

0 commit comments

Comments
 (0)