From: Adalbert Lazar Subject: [RFC PATCH 06/19] kvm: Add kvm_vm_shutdown() Date: Fri, 16 Jun 2017 16:43:35 +0300 Message-ID: <20170616134348.17725-7-alazar@bitdefender.com> References: <20170616134348.17725-1-alazar@bitdefender.com> Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , alazar@bitdefender.com, mdontu@bitdefender.com To: kvm@vger.kernel.org Return-path: Received: from mx02.bbu.dsd.mx.bitdefender.com ([91.199.104.133]:49032 "EHLO mx02.buh.bitdefender.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753594AbdFPNml (ORCPT ); Fri, 16 Jun 2017 09:42:41 -0400 In-Reply-To: <20170616134348.17725-1-alazar@bitdefender.com> Sender: kvm-owner@vger.kernel.org List-ID: From: Mihai Dontu This function is used by the introspection subsystem to shutdown a specific VM. Signed-off-by: Mihai Dontu --- include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 545964ed6a63..2f00b5c64632 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -555,6 +555,7 @@ void kvm_exit(void); void kvm_enum(int (*enum_cb) (const struct kvm *kvm, void *param), void *param); struct kvm *kvm_from_uuid(const uuid_le *uuid); +void kvm_vm_shutdown(struct kvm *kvm); void kvm_get_kvm(struct kvm *kvm); void kvm_put_kvm(struct kvm *kvm); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 31bcdc92f1ea..52d92fcf39ff 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4084,3 +4084,30 @@ struct kvm *kvm_from_uuid(const uuid_le *uuid) spin_unlock(&kvm_lock); return found; } + +static int kvm_vcpu_kill(int sig, struct kvm_vcpu *vcpu) +{ + int err = -ESRCH; + struct pid *pid; + struct siginfo siginfo[1] = { }; + + rcu_read_lock(); + pid = rcu_dereference(vcpu->pid); + if (pid) + err = kill_pid_info(sig, siginfo, pid); + rcu_read_unlock(); + + return err; +} + +void kvm_vm_shutdown(struct kvm *kvm) +{ + int i; + struct kvm_vcpu *vcpu; + + mutex_lock(&kvm->lock); + kvm_for_each_vcpu(i, vcpu, kvm) { + kvm_vcpu_kill(SIGTERM, vcpu); + } + mutex_unlock(&kvm->lock); +} -- 2.12.2