Re: kernel device reset support

Avi Kivity
2007-10-08T10:24:22Z

Dong, Eddie wrote:
> Kernel side patch to introduce a new API for kernel device reset and
> force
> vcpu mp_state to UNINATIALIZED state if it is reset.
> thx,eddie
>
>
>
> +
> +/*
> + * Reset VM.
> + *
> + */
> +int kvm_vm_reset(struct kvm *kvm)
> +{
> + struct kvm_vcpu *vcpu;
> + int i;
> +
> + kvm_reset_devices(kvm);
> + for (i = 0; i < KVM_MAX_VCPUS; i++) {
> + vcpu = kvm->vcpus[i];
> + if (!vcpu)
> + continue;
> + /* active VCPU */
> + if (vcpu->vcpu_id)
> + vcpu->mp_state = VCPU_MP_STATE_UNINITIALIZED;
> + else {
> + vcpu->mp_state = VCPU_MP_STATE_RUNNABLE;
> + kvm_lapic_reset(vcpu);
>

Why is the handling here different?

> + }
> + vcpu->force_to_quit = 1;
> + kvm_vcpu_kick(vcpu);
> + }
> + return 0;
> +}
> +
> static long kvm_vm_ioctl(struct file *filp,
> unsigned int ioctl, unsigned long arg)
> {
> @@ -3163,6 +3200,12 @@ static long kvm_vm_ioctl(struct file *filp,
> else
> goto out;
> break;
> + case KVM_RESET:
> + r = -EFAULT;
>

-EINVAL. Or better accept it always and only reset the vcpu if
!irqchip_in_kernel().

> + if (!irqchip_in_kernel(kvm))
> + goto out;
> + r = kvm_vm_reset(kvm);
> + break;
> case KVM_IRQ_LINE: {
> struct kvm_irq_level irq_event;
>
> diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
> index 3d8e01e..0799aad 100644
> --- a/drivers/kvm/vmx.c
> +++ b/drivers/kvm/vmx.c
> @@ -1860,6 +1860,10 @@ static int handle_external_interrupt(struct
> kvm_vcpu *vcpu,
> struct kvm_run *kvm_run)
> {
> ++vcpu->stat.irq_exits;
> + if (vcpu->force_to_quit) {
> + vcpu->force_to_quit = 0;
> + return -EINTR;
> + }
> return 1;
> }
>

Why is this needed?

Userspace can always force an exit by sending a signal.

--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.