From patchwork Thu Jul 18 10:39:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11048773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6B0013A4 for ; Thu, 18 Jul 2019 10:40:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D63FA22A6F for ; Thu, 18 Jul 2019 10:40:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9AD028521; Thu, 18 Jul 2019 10:40:45 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6B5BC22A6F for ; Thu, 18 Jul 2019 10:40:45 +0000 (UTC) Received: from localhost ([::1]:36182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1ho3q8-0004kE-Du for patchwork-qemu-devel@patchwork.kernel.org; Thu, 18 Jul 2019 06:40:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34875) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1ho3pr-0003eq-Uj for qemu-devel@nongnu.org; Thu, 18 Jul 2019 06:40:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ho3pq-0000gf-Ro for qemu-devel@nongnu.org; Thu, 18 Jul 2019 06:40:27 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:33753) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ho3po-0000dO-A1; Thu, 18 Jul 2019 06:40:24 -0400 Received: by mail-pf1-x42d.google.com with SMTP id g2so12443849pfq.0; Thu, 18 Jul 2019 03:40:24 -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 :mime-version:content-transfer-encoding; bh=jeDfu5EycFvl9XFUWjClydY4i9PbIdp0Dl2n2igY378=; b=du2EdGeBkny+IfgWNzwqYqHutMf9z9h/WVcIjUyH/Mp5Jfz0L68EkTg86Us7OcSlRY +VpfdyTK7tagjno46JRE7+xxNQ6O8NcQeJDs1mDiDFGuixAzqlNq+ttlDaQkmg/uJOfD 1tbTSsXPowJkoexkZCpnGOEvTPf9GOe6uOVxZUVU2wMUBS17SDocB7vbqtQioWAUhK4Z QXCZ7wzMnHZg3mHnRFQkLONMOoO/VSFPKsXW2vwUooAk/R48LJY+8zK8KXc+FYjhmKeV HjU7jE97aB8vYbMFfflPLL7kcarvrE63jH0n0Y37PUEIo1Z0UZ/C4YE4sDR+P9RMOO70 yFNg== 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:mime-version:content-transfer-encoding; bh=jeDfu5EycFvl9XFUWjClydY4i9PbIdp0Dl2n2igY378=; b=sv+gmoA98uDcdK5kopPddBFn7M4JFQe85gx5GtrGXvrWxOnZVg7BCPA2g4L+vPVJLe p/0GDumgfPhhjG5doY8b3XVc4MeRBhJzDOzL1eDCQEtHq21KOz2nBfiZhQiGBRwcRewr Z6HFbAWR2n4miE39bIOWCwWcVubGnZ9I+rV2zW/oHIfBi7XbKkaXPBptP9keQw6lpWQV H9tWk2uqiitrJQGMfapQBINatzKzZvGk5A2FPuxXuEwrp57qN6eXPT4615TsPz3SpQA9 6012Yk+otOq3K1r41jbIcdt7lxPoXcSaJjQe4hISLhLiN1a+AmCAc/iQVd4rGr10Tfzr ky8g== X-Gm-Message-State: APjAAAUEkujgPSCzb+P6dRPlqrcZxnAbYqbgWocR+carVAsBUkkJByC1 KPjdDu81U7RVhj95jFTEqFimighY X-Google-Smtp-Source: APXvYqwUtt17A6CS7/mLYliXRZawQAJ8FObcwBEz14TJr7/wbkmsQhHg1IETvyNszfUtMR6I/spdYw== X-Received: by 2002:a63:9e43:: with SMTP id r3mr21865071pgo.148.1563446423094; Thu, 18 Jul 2019 03:40:23 -0700 (PDT) Received: from bobo.local0.net (61-68-63-89.tpgi.com.au. [61.68.63.89]) by smtp.gmail.com with ESMTPSA id y10sm28243415pfm.66.2019.07.18.03.40.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 03:40:22 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Date: Thu, 18 Jul 2019 20:39:50 +1000 Message-Id: <20190718103951.10027-3-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190718103951.10027-1-npiggin@gmail.com> References: <20190718103951.10027-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::42d Subject: [Qemu-devel] [PATCH 2/3] machine: Add wakeup method to MachineClass X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Nicholas Piggin , Luiz Capitulino , Christian Borntraeger , Gerd Hoffmann , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Waking from suspend is not logically a machine reset on all machines, particularly in the paravirtualized case rather than hardware emulated. The ppc spapr machine for example just invokes hypervisor to suspend, and expects that call to return with the machine in the same state (modulo some possible migration and reconfiguration details). Implement a machine ->wakeup method and use that if it exists. Signed-off-by: Nicholas Piggin --- include/hw/boards.h | 1 + vl.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index a71d1a53a5..915ac3352b 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -180,6 +180,7 @@ struct MachineClass { void (*init)(MachineState *state); void (*reset)(MachineState *state); + void (*wakeup)(MachineState *state); void (*hot_add_cpu)(MachineState *state, const int64_t id, Error **errp); int (*kvm_type)(MachineState *machine, const char *arg); void (*smp_parse)(MachineState *ms, QemuOpts *opts); diff --git a/vl.c b/vl.c index ef3c7ab8b8..b9e9943458 100644 --- a/vl.c +++ b/vl.c @@ -1556,6 +1556,33 @@ void qemu_system_reset(ShutdownCause reason) cpu_synchronize_all_post_reset(); } +/* + * Wake the VM after suspend. + */ +static void qemu_system_wakeup(void) +{ + MachineClass *mc; + + mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL; + + if (mc && mc->wakeup) { + mc->wakeup(current_machine); + } else { + /* + * Fall back to old reset wakeup method. Platforms supporting + * wakeup should be converted over to use ->wakeup and this + * fallback code removed. + */ + cpu_synchronize_all_states(); + if (mc && mc->reset) { + mc->reset(current_machine); + } else { + qemu_devices_reset(); + } + cpu_synchronize_all_post_reset(); + } +} + void qemu_system_guest_panicked(GuestPanicInformation *info) { qemu_log_mask(LOG_GUEST_ERROR, "Guest crashed"); @@ -1764,7 +1791,7 @@ static bool main_loop_should_exit(void) } if (qemu_wakeup_requested()) { pause_all_vcpus(); - qemu_system_reset(SHUTDOWN_CAUSE_NONE); + qemu_system_wakeup(); notifier_list_notify(&wakeup_notifiers, &wakeup_reason); wakeup_reason = QEMU_WAKEUP_REASON_NONE; resume_all_vcpus();