Skip to content

Commit 028f54b

Browse files
feat:sync sregs when cpu exit due to KVM_EXIT_SYNC_ARM_V7M_SREGS
Add kvm_cortex_m_vcpu_sync(CPUState *cs) interfaces to sync sregs between kvm cpu env with tcg env. Signed-off-by: chaojixx <[email protected]>
1 parent d891238 commit 028f54b

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

accel/kvm/kvm-all.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
#include "hw/boards.h"
4646

47+
#include "kvm_arm.h"
48+
4749
/* This check must be after config-host.h is included */
4850
#ifdef CONFIG_EVENTFD
4951
#include <sys/eventfd.h>
@@ -2347,6 +2349,12 @@ int kvm_cpu_exec(CPUState *cpu)
23472349
qemu_mutex_unlock_iothread();
23482350
ret = 0;
23492351
break;
2352+
case KVM_EXIT_SYNC_ARM_V7M_SREGS:
2353+
qemu_mutex_lock_iothread();
2354+
kvm_cortex_m_get_regs(cpu);
2355+
qemu_mutex_unlock_iothread();
2356+
ret = 0;
2357+
break;
23502358
default:
23512359
DPRINTF("kvm_arch_handle_exit\n");
23522360
ret = kvm_arch_handle_exit(cpu, run);

linux-headers/linux/kvm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,16 @@ struct kvm_hyperv_exit {
236236
#define KVM_EXIT_IOAPIC_EOI 26
237237
#define KVM_EXIT_HYPERV 27
238238

239+
/* ARM Cortex-m exit codes */
240+
#define KVM_EXIT_SYNC_ARM_V7M_SREGS 40
241+
239242
/* Symbolic execution exit codes */
240243
#define KVM_EXIT_FLUSH_DISK 100
241244
#define KVM_EXIT_SAVE_DEV_STATE 101
242245
#define KVM_EXIT_RESTORE_DEV_STATE 102
243246
#define KVM_EXIT_CLONE_PROCESS 103
244247

248+
245249
/* For KVM_EXIT_INTERNAL_ERROR */
246250
/* Emulate instruction failed. */
247251
#define KVM_INTERNAL_ERROR_EMULATION 1

target/arm/kvm.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ int kvm_cortex_m_vcpu_init(CPUState *cs)
5959
return 0;
6060
}
6161

62+
int kvm_cortex_m_get_regs(CPUState *cs)
63+
{
64+
ARMCPU *cpu = ARM_CPU(cs);
65+
CPUARMState *env=&cpu->env;
66+
67+
struct kvm_m_regs regs;
68+
struct kvm_m_sregs sregs;
69+
70+
kvm_vcpu_ioctl(cs, KVM_GET_M_REGS, &regs);
71+
kvm_vcpu_ioctl(cs, KVM_GET_M_SREGS, &sregs);
72+
memcpy(env->regs,regs.regs,sizeof(regs.regs));
73+
74+
env->v7m.vecbase[0] = sregs.vecbase;
75+
env->v7m.other_sp = sregs.other_sp;
76+
env->v7m.basepri[0] = sregs.basepri;
77+
env->v7m.control[0] = sregs.control;
78+
env->v7m.exception = sregs.exception;
79+
return 0;
80+
}
81+
6282
int kvm_arm_vcpu_init(CPUState *cs)
6383
{
6484
ARMCPU *cpu = ARM_CPU(cs);

target/arm/kvm_arm.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,23 @@
2020
* @env: CPUARMState
2121
*
2222
* Initialize (or reinitialize) the cotex-m VCPU by invoking the
23-
* cotex-m reg write and read ioctl with the CPUARMState
23+
* cotex-m reg write ioctl with the CPUARMState
2424
*
2525
* Returns: 0 if success else < 0 error code
2626
*/
27-
int kvm_cortex_m_vcpu_init(CPUState *cs);
27+
int kvm_cortex_m_vcpu_init(CPUState *cs);
28+
29+
/**
30+
* kvm_cortex_m_vcpu_sync
31+
* @env: CPUARMState
32+
*
33+
* get the cotex-m VCPU regs by invoking the
34+
* cotex-m reg read ioctl with the CPUARMState
35+
*
36+
* Returns: 0 if success else < 0 error code
37+
*/
38+
int kvm_cortex_m_get_regs(CPUState *cs);
39+
2840
/**
2941
* kvm_arm_vcpu_init:
3042
* @cs: CPUState

0 commit comments

Comments
 (0)