From patchwork Wed May 9 11:16:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 910760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40gv3T0nCBz9s3Z for ; Wed, 9 May 2018 21:17:55 +1000 (AEST) Received: from localhost ([::1]:55742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGN6W-0001er-CG for incoming@patchwork.ozlabs.org; Wed, 09 May 2018 07:17:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGN62-0001Z9-2l for qemu-devel@nongnu.org; Wed, 09 May 2018 07:17:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGN5x-00057U-Qo for qemu-devel@nongnu.org; Wed, 09 May 2018 07:17:22 -0400 Received: from 4.mo2.mail-out.ovh.net ([87.98.172.75]:45939) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fGN5x-0004o4-KU for qemu-devel@nongnu.org; Wed, 09 May 2018 07:17:17 -0400 Received: from player799.ha.ovh.net (unknown [10.109.120.80]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 319E1131E87 for ; Wed, 9 May 2018 13:17:08 +0200 (CEST) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player799.ha.ovh.net (Postfix) with ESMTPA id 44EE25200DE; Wed, 9 May 2018 13:17:02 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 09 May 2018 13:16:56 +0200 Message-ID: <152586461606.636636.16396178012223646393.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 X-Ovh-Tracer-Id: 15614824335587252636 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrudehgdegtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.98.172.75 Subject: [Qemu-devel] [PATCH] target/ppc: migrate VPA related state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Mackerras , qemu-ppc@nongnu.org, Michael Roth , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" QEMU implements the "Shared Processor LPAR" (SPLPAR) option, which allows the hypervisor to time-slice a physical processor into multiple virtual processor. The intent is to allow more guests to run, and to optimize processor utilization. The guest OS can cede idle VCPUs, so that their processing capacity may be used by other VCPUs, with the H_CEDE hcall. The guest OS can also optimize spinlocks, by confering the time-slice of a spinning VCPU to the spinlock holder if it's currently notrunning, with the H_CONFER hcall. Both hcalls depend on a "Virtual Processor Area" (VPA) to be registered by the guest OS, generally during early boot. Other per-VCPU areas can be registerer: the "SLB Shadow Buffer" which allows a more efficient dispatching of VCPUs, and the "Dispatch Trace Log Buffer" (DTL) which is used to compute time stolen by the hypervisor. Both DTL and SLB Shadow areas depend on the VPA to be registered. The VPA/SLB Shadow/DTL are state that QEMU should migrate, but this doesn't happen, for no apparent reason other than it was just never coded. This causes the features listed above to stop working after migration, and it breaks the logic of the H_REGISTER_VPA hcall in the destination. This patch fixes it for newer machine types (ie, version > 2.12) by adding a "cpu/vpa" subsection to the CPU migration stream. It ensures backward migration to existing QEMU versions. Since DTL and SLB Shadow are optional and both depend on VPA, they get their own subsections "cpu/vpa/slb_shadow" and "cpu/vpa/dtl" hanging from the "cpu/vpa" subsection. Signed-off-by: Greg Kurz --- target/ppc/machine.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/target/ppc/machine.c b/target/ppc/machine.c index ba1b9e531f97..b0d4040b37f9 100644 --- a/target/ppc/machine.c +++ b/target/ppc/machine.c @@ -677,6 +677,67 @@ static const VMStateDescription vmstate_compat = { } }; +static bool slb_shadow_needed(void *opaque) +{ + PowerPCCPU *cpu = opaque; + + return cpu->env.slb_shadow_addr != 0; +} + +static const VMStateDescription vmstate_slb_shadow = { + .name = "cpu/vpa/slb_shadow", + .version_id = 1, + .minimum_version_id = 1, + .needed = slb_shadow_needed, + .fields = (VMStateField[]) { + VMSTATE_UINT64(env.slb_shadow_addr, PowerPCCPU), + VMSTATE_UINT64(env.slb_shadow_size, PowerPCCPU), + VMSTATE_END_OF_LIST() + } +}; + +static bool dtl_needed(void *opaque) +{ + PowerPCCPU *cpu = opaque; + + return cpu->env.dtl_addr != 0; +} + +static const VMStateDescription vmstate_dtl = { + .name = "cpu/vpa/dtl", + .version_id = 1, + .minimum_version_id = 1, + .needed = dtl_needed, + .fields = (VMStateField[]) { + VMSTATE_UINT64(env.dtl_addr, PowerPCCPU), + VMSTATE_UINT64(env.dtl_size, PowerPCCPU), + VMSTATE_END_OF_LIST() + } +}; + +static bool vpa_needed(void *opaque) +{ + PowerPCCPU *cpu = opaque; + + return !cpu->pre_2_13_migration && cpu->env.vpa_addr != 0; +} + +static const VMStateDescription vmstate_vpa = { + .name = "cpu/vpa", + .version_id = 1, + .minimum_version_id = 1, + .needed = vpa_needed, + .fields = (VMStateField[]) { + VMSTATE_UINT64(env.vpa_addr, PowerPCCPU), + VMSTATE_END_OF_LIST() + }, + .subsections = (const VMStateDescription * []) { + &vmstate_slb_shadow, + &vmstate_dtl, + NULL + } +}; + const VMStateDescription vmstate_ppc_cpu = { .name = "cpu", .version_id = 5, @@ -731,6 +792,7 @@ const VMStateDescription vmstate_ppc_cpu = { &vmstate_tlbemb, &vmstate_tlbmas, &vmstate_compat, + &vmstate_vpa, NULL } };