From patchwork Tue Jan 24 14:56:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasilis Liaskovitis X-Patchwork-Id: 137573 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D08FBB6EEA for ; Wed, 25 Jan 2012 01:56:31 +1100 (EST) Received: from localhost ([::1]:46255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RphnO-0007gI-L7 for incoming@patchwork.ozlabs.org; Tue, 24 Jan 2012 09:56:26 -0500 Received: from eggs.gnu.org ([140.186.70.92]:54457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RphnB-0007e5-JF for qemu-devel@nongnu.org; Tue, 24 Jan 2012 09:56:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rphn1-0003v1-H5 for qemu-devel@nongnu.org; Tue, 24 Jan 2012 09:56:13 -0500 Received: from mail-bk0-f45.google.com ([209.85.214.45]:58591) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rphn1-0003ur-C6 for qemu-devel@nongnu.org; Tue, 24 Jan 2012 09:56:03 -0500 Received: by bkbzu17 with SMTP id zu17so1775068bkb.4 for ; Tue, 24 Jan 2012 06:56:02 -0800 (PST) Received: by 10.204.10.73 with SMTP id o9mr4998809bko.99.1327416961859; Tue, 24 Jan 2012 06:56:01 -0800 (PST) Received: from dhcp-192-168-178-175.profitbricks.localdomain (83-221-87-64.dynamic.primacom.net. [83.221.87.64]) by mx.google.com with ESMTPS id ez5sm26381342bkc.15.2012.01.24.06.55.59 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 24 Jan 2012 06:56:01 -0800 (PST) Date: Tue, 24 Jan 2012 15:56:00 +0100 From: Vasilis Liaskovitis To: Jan Kiszka , kernelfans@gmail.com Message-ID: <20120124145600.GA6555@dhcp-192-168-178-175.profitbricks.localdomain> References: <1327399808-31081-1-git-send-email-vasilis.liaskovitis@profitbricks.com> <1327399808-31081-4-git-send-email-vasilis.liaskovitis@profitbricks.com> <4F1E87D9.6000008@siemens.com> MIME-Version: 1.0 In-Reply-To: <4F1E87D9.6000008@siemens.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQmvLdGIeuAY+l7WbarbiXk5J+Yt6uxDwqT++xvYqZFCS+RH7hWMCEKtJfKVfpTyRIaUoUrY Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.45 Cc: "mtosatti@redhat.com" , "kvm@vger.kernel.org" , "gleb@redhat.com" , "seabios@seabios.org" , "qemu-devel@nongnu.org" , "kernelfans@gmail.com" , "kevin@koconnor.net" , "avi@redhat.com" Subject: Re: [Qemu-devel] [PATCH v2 3/4] uq/master: Add CPU eject handling for acpi_piix4 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Tue, Jan 24, 2012 at 11:28:41AM +0100, Jan Kiszka wrote: > On 2012-01-24 11:10, Vasilis Liaskovitis wrote: > > Add stub functions for CPU eject callback. Define cpu_acpi_eject property and > > enable eject callback only for pc-1.1 machine model. > > Just to get the idea: What is the plan and advantage of introducing a > stub first? How much more is required to have some usable feature, even > if its just a friction of the full support? > There's not really an advantage to adding stubs first. The plan depends on the lifecycle patches getting accepted in some form at some point. The code is all out there, and some of it has been reviewed/commented on, but not accepted. kvm needs the following patches: https://lkml.org/lkml/2012/1/6/355 (v7, still in work) http://patchwork.ozlabs.org/patch/127828/ This second patch introduces ioctl KVM_SETSTATE_VCPU, (qemu uses it to signal vcpu destruction to the host) but the review mentions there should be a simpler way. It's unclear to me whether this ioctl is desired or not. userspace qemu/qemu-kvm need some form of these patches http://patchwork.ozlabs.org/patch/127831/ http://patchwork.ozlabs.org/patch/127830/ http://patchwork.ozlabs.org/patch/127833/ http://patchwork.ozlabs.org/patch/127834/ Assuming that the above is further reviewed and accepted, the extra code needed to actually make something useful in the stub functions would be something like the following (with the above ioctl), comments welcome. This code calls kvm function from hw/acpi_piix4.c so it's probably not well abstracted enough for upstream. diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c index 8475aa6..b5fcb4a 100644 --- a/hw/acpi_piix4.c +++ b/hw/acpi_piix4.c @@ -509,6 +509,20 @@ static uint32_t cpuej_read(void *opaque, uint32_t addr) static void cpuej_write(void *opaque, uint32_t addr, uint32_t val) { + PIIX4PMState *s = opaque; + CPUState *env; + int cpu; + int ret; + + cpu = ffs(val); + /* zero means no bit was set, i.e. no CPU ejection happened */ + if (!cpu) + return; + cpu--; + env = cpu_phyid_to_cpu((uint64_t)cpu); + if (s->kvm_enabled && env != NULL) { + kvm_eject_vcpu(env); + } PIIX4_DPRINTF("cpuej write %x <== %d\n", addr, val); } diff --git a/kvm-all.c b/kvm-all.c index 88f1156..d3e53f5 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -193,6 +193,13 @@ static void kvm_reset_vcpu(void *opaque) kvm_arch_reset_vcpu(env); } +static void kvm_eject_vcpu(void *opaque) +{ + CPUState *env = opaque; + + kvm_arch_eject_vcpu(env); +} + int kvm_irqchip_in_kernel(void) { return kvm_state->irqchip_in_kernel; diff --git a/kvm.h b/kvm.h index 40b5ffc..ace28a8 100644 --- a/kvm.h +++ b/kvm.h @@ -125,6 +125,8 @@ int kvm_arch_init_vcpu(CPUState *env); void kvm_arch_reset_vcpu(CPUState *env); +void kvm_arch_eject_vcpu(CPUState *env); + int kvm_arch_on_sigbus_vcpu(CPUState *env, int code, void *addr); int kvm_arch_on_sigbus(int code, void *addr); diff --git a/target-i386/kvm.c b/target-i386/kvm.c index e41de39..f8239c0 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -589,6 +589,21 @@ void kvm_arch_reset_vcpu(CPUState *env) } } +void kvm_arch_eject_vcpu(CPUState *env) +{ + struct kvm_vcpu_state state; + int ret = 0; + + if (env->state == CPU_STATE_ZAPREQ) { + state.vcpu_id = env->cpu_index; + state.state = 1; + ret = kvm_vm_ioctl(env->kvm_state, KVM_SETSTATE_VCPU, &state); + if (ret) + fprintf(stderr, "KVM_SETSTATE_VCPU failed: %s\n", + strerror(ret)); + } +} + static int kvm_get_supported_msrs(KVMState *s) { static int kvm_supported_msrs;