From patchwork Thu Apr 9 16:31:55 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Haskins X-Patchwork-Id: 25791 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id B3D97DE1E2 for ; Fri, 10 Apr 2009 02:30:25 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935437AbZDIQ3y (ORCPT ); Thu, 9 Apr 2009 12:29:54 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S935533AbZDIQ3t (ORCPT ); Thu, 9 Apr 2009 12:29:49 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:58844 "EHLO victor.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935521AbZDIQ3q (ORCPT ); Thu, 9 Apr 2009 12:29:46 -0400 Received: from dev.haskins.net (prv-ext-foundry1.gns.novell.com [137.65.251.240]) by victor.provo.novell.com with ESMTP (TLS encrypted); Thu, 09 Apr 2009 10:29:41 -0600 Received: from dev.haskins.net (localhost [127.0.0.1]) by dev.haskins.net (Postfix) with ESMTP id 365954641FA; Thu, 9 Apr 2009 12:31:55 -0400 (EDT) From: Gregory Haskins Subject: [RFC PATCH v2 14/19] kvm: add a reset capability To: linux-kernel@vger.kernel.org Cc: agraf@suse.de, pmullaney@novell.com, pmorreale@novell.com, anthony@codemonkey.ws, rusty@rustcorp.com.au, netdev@vger.kernel.org, kvm@vger.kernel.org, avi@redhat.com, bhutchings@solarflare.com, andi@firstfloor.org, gregkh@suse.de, herber@gondor.apana.org.au, chrisw@sous-sol.org, shemminger@vyatta.com Date: Thu, 09 Apr 2009 12:31:55 -0400 Message-ID: <20090409163155.32740.50340.stgit@dev.haskins.net> In-Reply-To: <20090409155200.32740.19358.stgit@dev.haskins.net> References: <20090409155200.32740.19358.stgit@dev.haskins.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org We need a way to detect if a VM is reset later in the series, so lets add a capability for userspace to signal a VM reset down to the kernel. Signed-off-by: Gregory Haskins --- arch/x86/kvm/x86.c | 1 + include/linux/kvm.h | 2 ++ include/linux/kvm_host.h | 6 ++++++ virt/kvm/kvm_main.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 758b7a1..9b0a649 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -971,6 +971,7 @@ int kvm_dev_ioctl_check_extension(long ext) case KVM_CAP_NOP_IO_DELAY: case KVM_CAP_MP_STATE: case KVM_CAP_SYNC_MMU: + case KVM_CAP_RESET: r = 1; break; case KVM_CAP_COALESCED_MMIO: diff --git a/include/linux/kvm.h b/include/linux/kvm.h index 0424326..7ffd8f5 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -396,6 +396,7 @@ struct kvm_trace_rec { #ifdef __KVM_HAVE_USER_NMI #define KVM_CAP_USER_NMI 22 #endif +#define KVM_CAP_RESET 23 /* * ioctls for VM fds @@ -429,6 +430,7 @@ struct kvm_trace_rec { struct kvm_assigned_pci_dev) #define KVM_ASSIGN_IRQ _IOR(KVMIO, 0x70, \ struct kvm_assigned_irq) +#define KVM_RESET _IO(KVMIO, 0x67) /* * ioctls for vcpu fds diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index bf6f703..506eca1 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -132,6 +133,8 @@ struct kvm { unsigned long mmu_notifier_seq; long mmu_notifier_count; #endif + + struct raw_notifier_head reset_notifier; /* triggers when VM reboots */ }; /* The guest did something we don't support. */ @@ -158,6 +161,9 @@ void kvm_exit(void); void kvm_get_kvm(struct kvm *kvm); void kvm_put_kvm(struct kvm *kvm); +int kvm_reset_notifier_register(struct kvm *kvm, struct notifier_block *nb); +int kvm_reset_notifier_unregister(struct kvm *kvm, struct notifier_block *nb); + #define HPA_MSB ((sizeof(hpa_t) * 8) - 1) #define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB) static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; } diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 29a667c..fca2d25 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -868,6 +868,8 @@ static struct kvm *kvm_create_vm(void) #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET kvm_coalesced_mmio_init(kvm); #endif + RAW_INIT_NOTIFIER_HEAD(&kvm->reset_notifier); + out: return kvm; } @@ -1485,6 +1487,35 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn) } } +static void kvm_notify_reset(struct kvm *kvm) +{ + mutex_lock(&kvm->lock); + raw_notifier_call_chain(&kvm->reset_notifier, 0, kvm); + mutex_unlock(&kvm->lock); +} + +int kvm_reset_notifier_register(struct kvm *kvm, struct notifier_block *nb) +{ + int ret; + + mutex_lock(&kvm->lock); + ret = raw_notifier_chain_register(&kvm->reset_notifier, nb); + mutex_unlock(&kvm->lock); + + return ret; +} + +int kvm_reset_notifier_unregister(struct kvm *kvm, struct notifier_block *nb) +{ + int ret; + + mutex_lock(&kvm->lock); + ret = raw_notifier_chain_unregister(&kvm->reset_notifier, nb); + mutex_unlock(&kvm->lock); + + return ret; +} + /* * The vCPU has executed a HLT instruction with in-kernel mode enabled. */ @@ -1929,6 +1960,11 @@ static long kvm_vm_ioctl(struct file *filp, break; } #endif + case KVM_RESET: { + kvm_notify_reset(kvm); + r = 0; + break; + } default: r = kvm_arch_vm_ioctl(filp, ioctl, arg); }