From patchwork Thu Jun 8 07:03:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 9773993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CAA3060393 for ; Thu, 8 Jun 2017 07:06:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA08E25D9E for ; Thu, 8 Jun 2017 07:06:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AECA528533; Thu, 8 Jun 2017 07:06:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E80B5283BD for ; Thu, 8 Jun 2017 07:06:46 +0000 (UTC) Received: from localhost ([::1]:47798 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIrWn-0001Hl-VB for patchwork-qemu-devel@patchwork.kernel.org; Thu, 08 Jun 2017 03:06:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIrUW-0000Tx-Kn for qemu-devel@nongnu.org; Thu, 08 Jun 2017 03:04:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIrUV-0007eI-GQ for qemu-devel@nongnu.org; Thu, 08 Jun 2017 03:04:24 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:36461) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIrUQ-0007cf-TY; Thu, 08 Jun 2017 03:04:19 -0400 Received: by mail-pf0-x243.google.com with SMTP id y7so4101046pfd.3; Thu, 08 Jun 2017 00:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y5mSRlc8qgYxTPwBKYlMBzae+1tmyo59kKPFwSWIOig=; b=aedPPuADpdR/qh2mAZ9IrAlQEo2kHdSG+2U5IwBFBHNtsmLa0NaWEt+guRtxfEg7qv eL39ishOAi844ak+SZbIOLFWvJz0YR0kj9zAINAfbnKWAbVkgl5i/useJttMmSPp4MND xqGPptcTMDwYnBJvf+khrhk4JEtPyo+Bo/y7Evlth+nEiNb899PaVTENNdBja2HMGSu2 oYd4pwClAzTx0Sb/Cp63MUouj6wxJDZ1AlQTy6K4yV1dLZRNlWf3W2Ue32IiZmsb6SvY lBccig9MQvaafSRG8LDyZOeQTiK0t/ZXUtOo0DH8KxDATjRbVriTUqLwOAG4iw/CvGho 9G/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=y5mSRlc8qgYxTPwBKYlMBzae+1tmyo59kKPFwSWIOig=; b=TRgXhMMr+ckVqK4hzA+DtfMONob/gq2tHYHaoYVGbzVs/HXGbgIAmFp5ADEvHnjTxw 1nHu3wAf4HeNi7XxmVrVy14BFSLMtCEQ90TlgWDgnKWXVvjUOqQYeDUrLZwG8Or5cem2 gxVYfmqHV5PRfZhozbPYptkAGXLzph8HFXqK486DpX35nC0I/yWOisY2Zpmj4ajRrkl6 d4onJTawimV2vbJufqR005g6cI0zE7tCs2w9vVcHJpdaDLoqsIBwR33DD2tXOll9Y31W /UlFx/L3vVF1yJ9JnJEPJMo0lb5j461kVlzk2nQa6wI4cSjOczS27bhILH/pFFPOBT1X TZFQ== X-Gm-Message-State: AODbwcBt8RAGxNbACUH128akUDMnSpyK6gQZ7JhyL4tZG5TsnW43CXvf 8YJTKLq6OOLYcJyT X-Received: by 10.84.231.130 with SMTP id g2mr33310825plk.2.1496905457949; Thu, 08 Jun 2017 00:04:17 -0700 (PDT) Received: from surajjs1.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id p76sm8568188pfl.24.2017.06.08.00.04.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jun 2017 00:04:17 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Thu, 8 Jun 2017 17:03:49 +1000 Message-Id: <20170608070351.1434-4-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170608070351.1434-1-sjitindarsingh@gmail.com> References: <20170608070351.1434-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH 3/5] target/ppc: Implement migration support for large decrementer 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: agraf@suse.de, qemu-devel@nongnu.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Implement support to migrate a guest which is using the large decrementer. We need to save the decrementer width to the migration stream. On incoming migration we then need to check that the hypervisor is capable of letting the guest use the large decrementer and that the decrementer width is the same on the receiving side. Since there is no way to tell the guest when the width of the decrementer changes we have to terminate if the decrementer width is not what the guest expects. If we can use the large decrementer then we have to tell the hypervisor to enable it. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/spapr.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + 2 files changed, 64 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 5d10366..6ba869a 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1420,6 +1420,45 @@ static bool spapr_vga_init(PCIBus *pci_bus, Error **errp) } } +static int spapr_import_large_decr_bits(sPAPRMachineState *spapr) +{ + /* + * If the guest uses the large decrementer then this hypervisor must also + * support it and have the exact same width. We must also enable the large + * decrementer because we have no way to tell the guest to stop using it. + */ + if (spapr->large_decr_bits) { + uint32_t dec_bits = 32; + PowerPCCPU *cpu = POWERPC_CPU(first_cpu); + CPUState *cs = CPU(cpu); + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs); + + if (kvm_enabled()) { + if (!kvmppc_has_cap_large_decr()) { + error_report("Host doesn't support large decrementer and guest requires it"); + return -EINVAL; + } + dec_bits = kvmppc_get_dec_bits(); + } else { + dec_bits = pcc->large_decr_bits; + } + + if (spapr->large_decr_bits != dec_bits) { + error_report("Host large decrementer size [%u] doesn't match what guest expects [%u]", + dec_bits, spapr->large_decr_bits); + return -EINVAL; + } + + if (kvm_enabled()) { + CPU_FOREACH(cs) { + kvmppc_configure_large_decrementer(cs, true); + } + } + } + + return 0; +} + static int spapr_post_load(void *opaque, int version_id) { sPAPRMachineState *spapr = (sPAPRMachineState *)opaque; @@ -1439,8 +1478,13 @@ static int spapr_post_load(void *opaque, int version_id) * value into the RTC device */ if (version_id < 3) { err = spapr_rtc_import_offset(&spapr->rtc, spapr->rtc_offset); + if (err) { + return err; + } } + err = spapr_import_large_decr_bits(spapr); + return err; } @@ -1529,6 +1573,24 @@ static const VMStateDescription vmstate_spapr_patb_entry = { }, }; +static bool spapr_large_decr_entry_needed(void *opaque) +{ + sPAPRMachineState *spapr = opaque; + + return !!spapr->large_decr_bits; +} + +static const VMStateDescription vmstate_spapr_large_decr_entry = { + .name = "spapr_large_decr_entry", + .version_id = 1, + .minimum_version_id = 1, + .needed = spapr_large_decr_entry_needed, + .fields = (VMStateField[]) { + VMSTATE_UINT32(large_decr_bits, sPAPRMachineState), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_spapr = { .name = "spapr", .version_id = 3, @@ -1547,6 +1609,7 @@ static const VMStateDescription vmstate_spapr = { .subsections = (const VMStateDescription*[]) { &vmstate_spapr_ov5_cas, &vmstate_spapr_patb_entry, + &vmstate_spapr_large_decr_entry, NULL } }; diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 98fb78b..4ba9b89 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -91,6 +91,7 @@ struct sPAPRMachineState { sPAPROptionVector *ov5_cas; /* negotiated (via CAS) option vectors */ bool cas_reboot; bool cas_legacy_guest_workaround; + uint32_t large_decr_bits; /* Large decrementer width (0 -> not in use) */ Notifier epow_notifier; QTAILQ_HEAD(, sPAPREventLogEntry) pending_events;