Skip to content

Commit 63a9b0b

Browse files
committed
Merge tag 'kvm-riscv-6.19-1' of https://github.com/kvm-riscv/linux into HEAD
KVM/riscv changes for 6.19 - SBI MPXY support for KVM guest - New KVM_EXIT_FAIL_ENTRY_NO_VSFILE for the case when in-kernel AIA virtualization fails to allocate IMSIC VS-file - Support enabling dirty log gradually in small chunks - Fix guest page fault within HLV* instructions - Flush VS-stage TLB after VCPU migration for Andes cores
2 parents 8040280 + 3239c52 commit 63a9b0b

File tree

21 files changed

+138
-94
lines changed

21 files changed

+138
-94
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8028,7 +8028,7 @@ will be initialized to 1 when created. This also improves performance because
80288028
dirty logging can be enabled gradually in small chunks on the first call
80298029
to KVM_CLEAR_DIRTY_LOG. KVM_DIRTY_LOG_INITIALLY_SET depends on
80308030
KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (it is also only available on
8031-
x86 and arm64 for now).
8031+
x86, arm64 and riscv for now).
80328032

80338033
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 was previously available under the name
80348034
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT, but the implementation had bugs that make

arch/riscv/include/asm/kvm_host.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
BIT(IRQ_VS_TIMER) | \
6060
BIT(IRQ_VS_EXT))
6161

62+
#define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
63+
KVM_DIRTY_LOG_INITIALLY_SET)
64+
6265
struct kvm_vm_stat {
6366
struct kvm_vm_stat_generic generic;
6467
};
@@ -327,4 +330,7 @@ bool kvm_riscv_vcpu_stopped(struct kvm_vcpu *vcpu);
327330

328331
void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu);
329332

333+
/* Flags representing implementation specific details */
334+
DECLARE_STATIC_KEY_FALSE(kvm_riscv_vsstage_tlb_no_gpa);
335+
330336
#endif /* __RISCV_KVM_HOST_H__ */

arch/riscv/include/asm/kvm_tlb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void kvm_riscv_local_hfence_vvma_gva(unsigned long vmid,
4949
unsigned long gva, unsigned long gvsz,
5050
unsigned long order);
5151
void kvm_riscv_local_hfence_vvma_all(unsigned long vmid);
52+
void kvm_riscv_local_tlb_sanitize(struct kvm_vcpu *vcpu);
5253

5354
void kvm_riscv_tlb_flush_process(struct kvm_vcpu *vcpu);
5455

arch/riscv/include/asm/kvm_vcpu_sbi.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ struct kvm_vcpu_sbi_extension {
6969
unsigned long reg_size, const void *reg_val);
7070
};
7171

72-
void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run);
72+
int kvm_riscv_vcpu_sbi_forward_handler(struct kvm_vcpu *vcpu,
73+
struct kvm_run *run,
74+
struct kvm_vcpu_sbi_return *retdata);
7375
void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
7476
struct kvm_run *run,
7577
u32 type, u64 flags);
@@ -105,6 +107,7 @@ extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_dbcn;
105107
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_susp;
106108
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta;
107109
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_fwft;
110+
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_mpxy;
108111
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental;
109112
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor;
110113

arch/riscv/include/asm/kvm_vmid.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ unsigned long kvm_riscv_gstage_vmid_bits(void);
2222
int kvm_riscv_gstage_vmid_init(struct kvm *kvm);
2323
bool kvm_riscv_gstage_vmid_ver_changed(struct kvm_vmid *vmid);
2424
void kvm_riscv_gstage_vmid_update(struct kvm_vcpu *vcpu);
25-
void kvm_riscv_gstage_vmid_sanitize(struct kvm_vcpu *vcpu);
2625

2726
#endif

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define KVM_INTERRUPT_SET -1U
2424
#define KVM_INTERRUPT_UNSET -2U
2525

26+
#define KVM_EXIT_FAIL_ENTRY_NO_VSFILE (1ULL << 0)
27+
2628
/* for KVM_GET_REGS and KVM_SET_REGS */
2729
struct kvm_regs {
2830
};
@@ -211,6 +213,7 @@ enum KVM_RISCV_SBI_EXT_ID {
211213
KVM_RISCV_SBI_EXT_STA,
212214
KVM_RISCV_SBI_EXT_SUSP,
213215
KVM_RISCV_SBI_EXT_FWFT,
216+
KVM_RISCV_SBI_EXT_MPXY,
214217
KVM_RISCV_SBI_EXT_MAX,
215218
};
216219

arch/riscv/kvm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ kvm-y += vcpu_onereg.o
2727
kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_pmu.o
2828
kvm-y += vcpu_sbi.o
2929
kvm-y += vcpu_sbi_base.o
30+
kvm-y += vcpu_sbi_forward.o
3031
kvm-y += vcpu_sbi_fwft.o
3132
kvm-y += vcpu_sbi_hsm.o
3233
kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_sbi_pmu.o

arch/riscv/kvm/aia_imsic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ int kvm_riscv_vcpu_aia_imsic_update(struct kvm_vcpu *vcpu)
814814
/* For HW acceleration mode, we can't continue */
815815
if (kvm->arch.aia.mode == KVM_DEV_RISCV_AIA_MODE_HWACCEL) {
816816
run->fail_entry.hardware_entry_failure_reason =
817-
CSR_HSTATUS;
817+
KVM_EXIT_FAIL_ENTRY_NO_VSFILE;
818818
run->fail_entry.cpu = vcpu->cpu;
819819
run->exit_reason = KVM_EXIT_FAIL_ENTRY;
820820
return 0;

arch/riscv/kvm/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
#include <asm/kvm_nacl.h>
1616
#include <asm/sbi.h>
1717

18+
DEFINE_STATIC_KEY_FALSE(kvm_riscv_vsstage_tlb_no_gpa);
19+
20+
static void kvm_riscv_setup_vendor_features(void)
21+
{
22+
/* Andes AX66: split two-stage TLBs */
23+
if (riscv_cached_mvendorid(0) == ANDES_VENDOR_ID &&
24+
(riscv_cached_marchid(0) & 0xFFFF) == 0x8A66) {
25+
static_branch_enable(&kvm_riscv_vsstage_tlb_no_gpa);
26+
kvm_info("VS-stage TLB does not cache guest physical address and VMID\n");
27+
}
28+
}
29+
1830
long kvm_arch_dev_ioctl(struct file *filp,
1931
unsigned int ioctl, unsigned long arg)
2032
{
@@ -160,6 +172,8 @@ static int __init riscv_kvm_init(void)
160172
kvm_info("AIA available with %d guest external interrupts\n",
161173
kvm_riscv_aia_nr_hgei);
162174

175+
kvm_riscv_setup_vendor_features();
176+
163177
kvm_register_perf_callbacks(NULL);
164178

165179
rc = kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);

arch/riscv/kvm/mmu.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
161161
* allocated dirty_bitmap[], dirty pages will be tracked while
162162
* the memory slot is write protected.
163163
*/
164-
if (change != KVM_MR_DELETE && new->flags & KVM_MEM_LOG_DIRTY_PAGES)
164+
if (change != KVM_MR_DELETE && new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
165+
if (kvm_dirty_log_manual_protect_and_init_set(kvm))
166+
return;
165167
mmu_wp_memory_region(kvm, new->id);
168+
}
166169
}
167170

168171
int kvm_arch_prepare_memory_region(struct kvm *kvm,

0 commit comments

Comments
 (0)