Skip to content

Commit f4d3165

Browse files
committed
KVM: generalize "bugged" VM to "dead" VM
Generalize KVM_REQ_VM_BUGGED so that it can be called even in cases where it is by design that the VM cannot be operated upon. In this case any KVM_BUG_ON should still warn, so introduce a new flag kvm->vm_dead that is separate from kvm->vm_bugged. Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent b67a4cc commit f4d3165

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9654,7 +9654,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
96549654
}
96559655

96569656
if (kvm_request_pending(vcpu)) {
9657-
if (kvm_check_request(KVM_REQ_VM_BUGGED, vcpu)) {
9657+
if (kvm_check_request(KVM_REQ_VM_DEAD, vcpu)) {
96589658
r = -EIO;
96599659
goto out;
96609660
}

include/linux/kvm_host.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static inline bool is_error_page(struct page *page)
150150
#define KVM_REQ_MMU_RELOAD (1 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
151151
#define KVM_REQ_UNBLOCK 2
152152
#define KVM_REQ_UNHALT 3
153-
#define KVM_REQ_VM_BUGGED (4 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
153+
#define KVM_REQ_VM_DEAD (4 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
154154
#define KVM_REQUEST_ARCH_BASE 8
155155

156156
#define KVM_ARCH_REQ_FLAGS(nr, flags) ({ \
@@ -617,6 +617,7 @@ struct kvm {
617617
unsigned int max_halt_poll_ns;
618618
u32 dirty_ring_size;
619619
bool vm_bugged;
620+
bool vm_dead;
620621

621622
#ifdef CONFIG_HAVE_KVM_PM_NOTIFIER
622623
struct notifier_block pm_notifier;
@@ -650,12 +651,19 @@ struct kvm {
650651
#define vcpu_err(vcpu, fmt, ...) \
651652
kvm_err("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)
652653

654+
static inline void kvm_vm_dead(struct kvm *kvm)
655+
{
656+
kvm->vm_dead = true;
657+
kvm_make_all_cpus_request(kvm, KVM_REQ_VM_DEAD);
658+
}
659+
653660
static inline void kvm_vm_bugged(struct kvm *kvm)
654661
{
655662
kvm->vm_bugged = true;
656-
kvm_make_all_cpus_request(kvm, KVM_REQ_VM_BUGGED);
663+
kvm_vm_dead(kvm);
657664
}
658665

666+
659667
#define KVM_BUG(cond, kvm, fmt...) \
660668
({ \
661669
int __ret = (cond); \

virt/kvm/kvm_main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,7 +3747,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
37473747
struct kvm_fpu *fpu = NULL;
37483748
struct kvm_sregs *kvm_sregs = NULL;
37493749

3750-
if (vcpu->kvm->mm != current->mm || vcpu->kvm->vm_bugged)
3750+
if (vcpu->kvm->mm != current->mm || vcpu->kvm->vm_dead)
37513751
return -EIO;
37523752

37533753
if (unlikely(_IOC_TYPE(ioctl) != KVMIO))
@@ -3957,7 +3957,7 @@ static long kvm_vcpu_compat_ioctl(struct file *filp,
39573957
void __user *argp = compat_ptr(arg);
39583958
int r;
39593959

3960-
if (vcpu->kvm->mm != current->mm || vcpu->kvm->vm_bugged)
3960+
if (vcpu->kvm->mm != current->mm || vcpu->kvm->vm_dead)
39613961
return -EIO;
39623962

39633963
switch (ioctl) {
@@ -4023,7 +4023,7 @@ static long kvm_device_ioctl(struct file *filp, unsigned int ioctl,
40234023
{
40244024
struct kvm_device *dev = filp->private_data;
40254025

4026-
if (dev->kvm->mm != current->mm || dev->kvm->vm_bugged)
4026+
if (dev->kvm->mm != current->mm || dev->kvm->vm_dead)
40274027
return -EIO;
40284028

40294029
switch (ioctl) {
@@ -4345,7 +4345,7 @@ static long kvm_vm_ioctl(struct file *filp,
43454345
void __user *argp = (void __user *)arg;
43464346
int r;
43474347

4348-
if (kvm->mm != current->mm || kvm->vm_bugged)
4348+
if (kvm->mm != current->mm || kvm->vm_dead)
43494349
return -EIO;
43504350
switch (ioctl) {
43514351
case KVM_CREATE_VCPU:
@@ -4556,7 +4556,7 @@ static long kvm_vm_compat_ioctl(struct file *filp,
45564556
struct kvm *kvm = filp->private_data;
45574557
int r;
45584558

4559-
if (kvm->mm != current->mm || kvm->vm_bugged)
4559+
if (kvm->mm != current->mm || kvm->vm_dead)
45604560
return -EIO;
45614561
switch (ioctl) {
45624562
#ifdef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT

0 commit comments

Comments
 (0)