From patchwork Fri Sep 5 16:13:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 36870 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8E8A7202A1 for ; Fri, 5 Sep 2014 16:17:27 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id fp1sf68469504pdb.9 for ; Fri, 05 Sep 2014 09:17:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=C4z1BTzpdZB0WYJDMGiOcCzzbIUHV3/wYz0kTNdbzF8=; b=ES29RnqbfDDJwfgk50fdWvnEpv1HgjDn9/0JC6d/gTapjI9FinhrDQsHuL+Dn0b9c5 oI0ll/046z4PQNt//ZdnEVsMEBSGtqSUaOxjG7b2DR8gLgU4A4b0ypaVnoSqg3f+24Lz /jEqo7CGyCgUvmeC9Pubi/I4wrFmpxniOLryRJcp13h7KE8qoGkNNEEi5uLOMnLDjkxO T7t3zSgSMdlqcre2m4ET0nxpnGft6Q+QIRNdqHURUrlZ+tcuBNGNxkmKRgfxMjNLL8hW qSfvTphMTYX9CRMHCjrGdgLNtTDVEtH/l3a/ZmwVxdXTzanQgcBviPUN034W4J7hxg8a zAYw== X-Gm-Message-State: ALoCoQmf0rddYKr1sQBm+RpDWJNJGquSqGMXTqOT3OpyA+5cL80JIZHS/K89f+cW4/gKqRTATnt4 X-Received: by 10.66.249.197 with SMTP id yw5mr7189489pac.34.1409933846893; Fri, 05 Sep 2014 09:17:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.88.6 with SMTP id s6ls802284qgd.22.gmail; Fri, 05 Sep 2014 09:17:26 -0700 (PDT) X-Received: by 10.52.28.40 with SMTP id y8mr1350671vdg.60.1409933846540; Fri, 05 Sep 2014 09:17:26 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id sq9si1655559vdb.90.2014.09.05.09.17.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 09:17:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hq11so12382751vcb.22 for ; Fri, 05 Sep 2014 09:17:26 -0700 (PDT) X-Received: by 10.52.120.51 with SMTP id kz19mr1549021vdb.95.1409933846391; Fri, 05 Sep 2014 09:17:26 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp106401vcb; Fri, 5 Sep 2014 09:17:26 -0700 (PDT) X-Received: by 10.224.60.193 with SMTP id q1mr20423298qah.12.1409933845760; Fri, 05 Sep 2014 09:17:25 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t4si2230031qaj.16.2014.09.05.09.17.25 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 05 Sep 2014 09:17:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:58865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPwCT-0008Qo-7q for patch@linaro.org; Fri, 05 Sep 2014 12:17:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPw9O-0003eD-CG for qemu-devel@nongnu.org; Fri, 05 Sep 2014 12:14:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPw9I-0005nr-8A for qemu-devel@nongnu.org; Fri, 05 Sep 2014 12:14:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26109) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPw9H-0005nW-Uo for qemu-devel@nongnu.org; Fri, 05 Sep 2014 12:14:08 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s85GE51a006913 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 5 Sep 2014 12:14:05 -0400 Received: from localhost (ovpn-112-65.ams2.redhat.com [10.36.112.65]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s85GE4I6026656; Fri, 5 Sep 2014 12:14:05 -0400 From: Stefan Hajnoczi To: Date: Fri, 5 Sep 2014 17:13:31 +0100 Message-Id: <1409933634-11331-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1409933634-11331-1-git-send-email-stefanha@redhat.com> References: <1409933634-11331-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Laszlo Ersek , Stefan Hajnoczi Subject: [Qemu-devel] [PULL 03/26] pflash_cfi01: write flash contents to bdrv on incoming migration 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Laszlo Ersek A drive that backs a pflash device is special: - it is very small, - its entire contents are kept in a RAMBlock at all times, covering the guest-phys address range that provides the guest's view of the emulated flash chip. The pflash device model keeps the drive (the host-side file) and the guest-visible flash contents in sync. When migrating the guest, the guest-visible flash contents (the RAMBlock) is migrated by default, but on the target host, the drive (the host-side file) remains in full sync with the RAMBlock only if: - the source and target hosts share the storage underlying the pflash drive, - or the migration requests full or incremental block migration too, which then covers all drives. Due to the special nature of pflash drives, the following scenario makes sense as well: - no full nor incremental block migration, covering all drives, alongside the base migration (justified eg. by shared storage for "normal" (big) drives), - non-shared storage for pflash drives. In this case, currently only those portions of the flash drive are updated on the target disk that the guest reprograms while running on the target host. In order to restore accord, dump the entire flash contents to the bdrv in a post_load() callback. - The read-only check follows the other call-sites of pflash_update(); - both "pfl->ro" and pflash_update() reflect / consider the case when "pfl->bs" is NULL; - the total size of the flash device is calculated as in pflash_cfi01_realize(). When using shared storage, or requesting full or incremental block migration along with the normal migration, the patch should incur a harmless rewrite from the target side. It is assumed that, on the target host, RAM is loaded ahead of the call to pflash_post_load(). Suggested-by: Paolo Bonzini Signed-off-by: Laszlo Ersek Signed-off-by: Stefan Hajnoczi --- hw/block/pflash_cfi01.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index fddef39..593fbc5 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -94,10 +94,13 @@ struct pflash_t { void *storage; }; +static int pflash_post_load(void *opaque, int version_id); + static const VMStateDescription vmstate_pflash = { .name = "pflash_cfi01", .version_id = 1, .minimum_version_id = 1, + .post_load = pflash_post_load, .fields = (VMStateField[]) { VMSTATE_UINT8(wcycle, pflash_t), VMSTATE_UINT8(cmd, pflash_t), @@ -982,3 +985,14 @@ MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl) { return &fl->mem; } + +static int pflash_post_load(void *opaque, int version_id) +{ + pflash_t *pfl = opaque; + + if (!pfl->ro) { + DPRINTF("%s: updating bdrv for %s\n", __func__, pfl->name); + pflash_update(pfl, 0, pfl->sector_len * pfl->nb_blocs); + } + return 0; +}