From patchwork Sun Apr 30 23:14:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 9706261 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 9DE22602CA for ; Sun, 30 Apr 2017 23:21:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B6EB25E13 for ; Sun, 30 Apr 2017 23:21:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DD822623C; Sun, 30 Apr 2017 23:21:09 +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 E4AD125E13 for ; Sun, 30 Apr 2017 23:21:08 +0000 (UTC) Received: from localhost ([::1]:46203 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4y9L-0005lk-Uk for patchwork-qemu-devel@patchwork.kernel.org; Sun, 30 Apr 2017 19:21:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4y3e-00028v-H1 for qemu-devel@nongnu.org; Sun, 30 Apr 2017 19:15:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4y3d-0006hY-FP for qemu-devel@nongnu.org; Sun, 30 Apr 2017 19:15:14 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:33578) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d4y3d-0006hC-9V for qemu-devel@nongnu.org; Sun, 30 Apr 2017 19:15:13 -0400 Received: by mail-pf0-x241.google.com with SMTP id b23so9853348pfc.0 for ; Sun, 30 Apr 2017 16:15:13 -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 :in-reply-to:references; bh=aLPISuS5eSd812PwiN7tjAxR9Wk2P1U1KxqUk+A/dp4=; b=ubSfrKMNAJcb5FA6BrxmYXlfPQCIBFgC5shiKzPHnpmSVGZyR/Wd+BymDrpCsX40ci zQZt+2qaqHkbLKshzoB5u4T4G5cuJbjpZ+t/W3xbzuXo/MUaspzHg1o1XkohZN/4JeDK D3PJKhrmhUCm/cnPNHUGNHidpRiZrudNCQSaW4qF17Gs3QHZn3bKcE+1khEYgE64RDQl niwbNn2YSg6NPvewKzK1wOILCu4dEI8pr5F6pU1jMsQ9nO6DemFP0F874wGBoggPUy87 PO10+T4EHr6SjG4d6xZMUbjsAlqkuUgYcxnZntegC+IKiklhB9p1ka1QCLUdBuumLY8e mDsA== 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:in-reply-to:references; bh=aLPISuS5eSd812PwiN7tjAxR9Wk2P1U1KxqUk+A/dp4=; b=Df3K9hgRDhVGvxtqQFYMvhjT6XfVmoMrH41gBgx8isp+Ugd8YVtXHZZEV9S9MS8PhE eSxx5DtS8hPkqB0J5XaIayU5UXxcXg6dfz/nJOAzjg/yA4VH89KobDR5nR/D67BtSQWu AZeSzQP5LWBaktwN/24FwNSNfoNQ6ODESf00iNdR+N9TYId8evNtmiQUVP9KyCzxbsUe D4wKfw6fG8OMp6ywYea7oXPVSL9eiIbBOR/Ppw36Vh2AW2IFoJNN+NtpDx2WRgPYU98e VfZaUew40fVJQGTvFd0GRZZatzTsiceMq4fFf2uKYUv1XUyQkW05LYnIVrNlaGGrLfAf ECeg== X-Gm-Message-State: AN3rC/4RWb/UypLQU3knewu5MF3AAtYfEe+f10leVqWRzb5sv+uwX42V A8JUCSFY4+pi+w== X-Received: by 10.84.254.67 with SMTP id a3mr30333639pln.185.1493594112570; Sun, 30 Apr 2017 16:15:12 -0700 (PDT) Received: from localhost (z209.124-44-183.ppp.wakwak.ne.jp. [124.44.183.209]) by smtp.gmail.com with ESMTPSA id n7sm22031030pfn.0.2017.04.30.16.15.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 30 Apr 2017 16:15:12 -0700 (PDT) From: Stafford Horne To: peter.maydell@linaro.org Date: Mon, 1 May 2017 08:14:23 +0900 Message-Id: <76adf807304af127f81f0c11f29b610b059f3497.1493593744.git.shorne@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PULL 09/11] target/openrisc: Implement full vmstate serialization 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: Stafford Horne , QEMU Development Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Previously serialization did not persist the tlb, timer, pic and other key state items. This meant snapshotting and restoring a running os would crash. After adding these I am able to take snapshots of a running linux os and restore at a later time. I am currently not trying to maintain capatibility with older versions as I do not believe this really worked before or anyone used it. Signed-off-by: Stafford Horne --- target/openrisc/machine.c | 73 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/target/openrisc/machine.c b/target/openrisc/machine.c index 2bf71c3..a82be62 100644 --- a/target/openrisc/machine.c +++ b/target/openrisc/machine.c @@ -24,6 +24,63 @@ #include "hw/boards.h" #include "migration/cpu.h" +static int env_post_load(void *opaque, int version_id) +{ + CPUOpenRISCState *env = opaque; + + /* Restore MMU handlers */ + if (env->sr & SR_DME) { + env->tlb->cpu_openrisc_map_address_data = + &cpu_openrisc_get_phys_data; + } else { + env->tlb->cpu_openrisc_map_address_data = + &cpu_openrisc_get_phys_nommu; + } + + if (env->sr & SR_IME) { + env->tlb->cpu_openrisc_map_address_code = + &cpu_openrisc_get_phys_code; + } else { + env->tlb->cpu_openrisc_map_address_code = + &cpu_openrisc_get_phys_nommu; + } + + + return 0; +} + +static const VMStateDescription vmstate_tlb_entry = { + .name = "tlb_entry", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINTTL(mr, OpenRISCTLBEntry), + VMSTATE_UINTTL(tr, OpenRISCTLBEntry), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_cpu_tlb = { + .name = "cpu_tlb", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_STRUCT_2DARRAY(itlb, CPUOpenRISCTLBContext, + ITLB_WAYS, ITLB_SIZE, 0, + vmstate_tlb_entry, OpenRISCTLBEntry), + VMSTATE_STRUCT_2DARRAY(dtlb, CPUOpenRISCTLBContext, + DTLB_WAYS, DTLB_SIZE, 0, + vmstate_tlb_entry, OpenRISCTLBEntry), + VMSTATE_END_OF_LIST() + } +}; + +#define VMSTATE_CPU_TLB(_f, _s) \ + VMSTATE_STRUCT_POINTER(_f, _s, vmstate_cpu_tlb, CPUOpenRISCTLBContext) + + static int get_sr(QEMUFile *f, void *opaque, size_t size, VMStateField *field) { CPUOpenRISCState *env = opaque; @@ -47,8 +104,9 @@ static const VMStateInfo vmstate_sr = { static const VMStateDescription vmstate_env = { .name = "env", - .version_id = 5, - .minimum_version_id = 5, + .version_id = 6, + .minimum_version_id = 6, + .post_load = env_post_load, .fields = (VMStateField[]) { VMSTATE_UINTTL_2DARRAY(shadow_gpr, CPUOpenRISCState, 16, 32), VMSTATE_UINTTL(pc, CPUOpenRISCState), @@ -79,9 +137,20 @@ static const VMStateDescription vmstate_env = { VMSTATE_UINT32(cpucfgr, CPUOpenRISCState), VMSTATE_UINT32(dmmucfgr, CPUOpenRISCState), VMSTATE_UINT32(immucfgr, CPUOpenRISCState), + VMSTATE_UINT32(evbar, CPUOpenRISCState), VMSTATE_UINT32(esr, CPUOpenRISCState), VMSTATE_UINT32(fpcsr, CPUOpenRISCState), VMSTATE_UINT64(mac, CPUOpenRISCState), + + VMSTATE_CPU_TLB(tlb, CPUOpenRISCState), + + VMSTATE_TIMER_PTR(timer, CPUOpenRISCState), + VMSTATE_UINT32(ttmr, CPUOpenRISCState), + VMSTATE_UINT32(ttcr, CPUOpenRISCState), + + VMSTATE_UINT32(picmr, CPUOpenRISCState), + VMSTATE_UINT32(picsr, CPUOpenRISCState), + VMSTATE_END_OF_LIST() } };