From: Alexander Graf <agraf@suse.de>
To: qemu-ppc@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 19/33] spapr_nvram: Enable migration
Date: Tue, 4 Nov 2014 20:26:37 +0100 [thread overview]
Message-ID: <1415129211-9740-20-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1415129211-9740-1-git-send-email-agraf@suse.de>
From: Alexey Kardashevskiy <aik@ozlabs.ru>
The only case when sPAPR NVRAM migrates now is if is backed by a file and
copy-storage migration is performed. In other cases NVRAM does not
migrate regardless whether it is backed by a file or not.
This enables shadow copy of NVRAM in RAM which is read from a file
(if used) and used for reads. Writes to NVRAM are mirrored to the file.
This defines a VMSTATE descriptor for NVRAM device so the memory copy
of NVRAM can migrate and be flushed to a backing file on the destination
if one is specified.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
hw/nvram/spapr_nvram.c | 81 +++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 64 insertions(+), 17 deletions(-)
diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
index 10b5b2e..35dc6d5 100644
--- a/hw/nvram/spapr_nvram.c
+++ b/hw/nvram/spapr_nvram.c
@@ -52,7 +52,6 @@ static void rtas_nvram_fetch(PowerPCCPU *cpu, sPAPREnvironment *spapr,
{
sPAPRNVRAM *nvram = spapr->nvram;
hwaddr offset, buffer, len;
- int alen;
void *membuf;
if ((nargs != 3) || (nret != 2)) {
@@ -77,19 +76,14 @@ static void rtas_nvram_fetch(PowerPCCPU *cpu, sPAPREnvironment *spapr,
return;
}
- membuf = cpu_physical_memory_map(buffer, &len, 1);
- if (nvram->blk) {
- alen = blk_pread(nvram->blk, offset, membuf, len);
- } else {
- assert(nvram->buf);
+ assert(nvram->buf);
- memcpy(membuf, nvram->buf + offset, len);
- alen = len;
- }
+ membuf = cpu_physical_memory_map(buffer, &len, 1);
+ memcpy(membuf, nvram->buf + offset, len);
cpu_physical_memory_unmap(membuf, len, 1, len);
- rtas_st(rets, 0, (alen < len) ? RTAS_OUT_HW_ERROR : RTAS_OUT_SUCCESS);
- rtas_st(rets, 1, (alen < 0) ? 0 : alen);
+ rtas_st(rets, 0, RTAS_OUT_SUCCESS);
+ rtas_st(rets, 1, len);
}
static void rtas_nvram_store(PowerPCCPU *cpu, sPAPREnvironment *spapr,
@@ -123,14 +117,15 @@ static void rtas_nvram_store(PowerPCCPU *cpu, sPAPREnvironment *spapr,
}
membuf = cpu_physical_memory_map(buffer, &len, 0);
+
+ alen = len;
if (nvram->blk) {
alen = blk_pwrite(nvram->blk, offset, membuf, len);
- } else {
- assert(nvram->buf);
-
- memcpy(nvram->buf + offset, membuf, len);
- alen = len;
}
+
+ assert(nvram->buf);
+ memcpy(nvram->buf + offset, membuf, len);
+
cpu_physical_memory_unmap(membuf, len, 0, len);
rtas_st(rets, 0, (alen < len) ? RTAS_OUT_HW_ERROR : RTAS_OUT_SUCCESS);
@@ -145,15 +140,24 @@ static int spapr_nvram_init(VIOsPAPRDevice *dev)
nvram->size = blk_getlength(nvram->blk);
} else {
nvram->size = DEFAULT_NVRAM_SIZE;
- nvram->buf = g_malloc0(nvram->size);
}
+ nvram->buf = g_malloc0(nvram->size);
+
if ((nvram->size < MIN_NVRAM_SIZE) || (nvram->size > MAX_NVRAM_SIZE)) {
fprintf(stderr, "spapr-nvram must be between %d and %d bytes in size\n",
MIN_NVRAM_SIZE, MAX_NVRAM_SIZE);
return -1;
}
+ if (nvram->blk) {
+ int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);
+
+ if (alen != nvram->size) {
+ return -1;
+ }
+ }
+
spapr_rtas_register(RTAS_NVRAM_FETCH, "nvram-fetch", rtas_nvram_fetch);
spapr_rtas_register(RTAS_NVRAM_STORE, "nvram-store", rtas_nvram_store);
@@ -167,6 +171,48 @@ static int spapr_nvram_devnode(VIOsPAPRDevice *dev, void *fdt, int node_off)
return fdt_setprop_cell(fdt, node_off, "#bytes", nvram->size);
}
+static int spapr_nvram_pre_load(void *opaque)
+{
+ sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(opaque);
+
+ g_free(nvram->buf);
+ nvram->buf = NULL;
+ nvram->size = 0;
+
+ return 0;
+}
+
+static int spapr_nvram_post_load(void *opaque, int version_id)
+{
+ sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(opaque);
+
+ if (nvram->blk) {
+ int alen = blk_pwrite(nvram->blk, 0, nvram->buf, nvram->size);
+
+ if (alen < 0) {
+ return alen;
+ }
+ if (alen != nvram->size) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static const VMStateDescription vmstate_spapr_nvram = {
+ .name = "spapr_nvram",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .pre_load = spapr_nvram_pre_load,
+ .post_load = spapr_nvram_post_load,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT32(size, sPAPRNVRAM),
+ VMSTATE_VBUFFER_ALLOC_UINT32(buf, sPAPRNVRAM, 1, NULL, 0, size),
+ VMSTATE_END_OF_LIST()
+ },
+};
+
static Property spapr_nvram_properties[] = {
DEFINE_SPAPR_PROPERTIES(sPAPRNVRAM, sdev),
DEFINE_PROP_DRIVE("drive", sPAPRNVRAM, blk),
@@ -185,6 +231,7 @@ static void spapr_nvram_class_init(ObjectClass *klass, void *data)
k->dt_compatible = "qemu,spapr-nvram";
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
dc->props = spapr_nvram_properties;
+ dc->vmsd = &vmstate_spapr_nvram;
}
static const TypeInfo spapr_nvram_type_info = {
--
1.8.1.4
next prev parent reply other threads:[~2014-11-04 19:27 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-04 19:26 [Qemu-devel] [PULL 2.2 00/33] ppc patch queue 2014-11-04 for 2.2 Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 01/33] ppc: fix monitor access to CR Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 02/33] ppc: use CRF_* in int_helper.c Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 03/33] ppc: fix result of DLMZB when no zero bytes are found Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 04/33] ppc: rename gen_set_cr6_from_fpscr Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 05/33] ppc: compute mask from BI using right shift Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 06/33] target-ppc: Fix kvmppc_set_compat to use negotiated cpu-version Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 07/33] target-ppc: Implement IVOR[59] By Default for Book E Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 08/33] target-ppc: virtex-ml507 machine type should depend on CONFIG_XILINX Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 09/33] spapr: Cleanup machine naming conventions, and prepare for 2.2 release Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 10/33] PPC: openpic_kvm: Only map first occurence in address space Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 11/33] target-ppc : Allow fc[tf]id[*] mnemonics for non TARGET_PPC64 Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 12/33] target-ppc : Add new processor type 440x5wDFPU Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 13/33] hw/pci/ppc4xx_pci.c: Remove unused pci4xx_cfgaddr_read/write/ops Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 14/33] target-ppc: Use macros in opcodes table handling code Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 15/33] target-ppc: Fix an invalid free in opcode " Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 16/33] PPC: Add MPC8XXX gpio controller Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 17/33] PPC: E500: Instantiate MPC8XXX gpio controller on virt machine Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 18/33] PPC: E500: Hook up power off GPIO to GPIO controller Alexander Graf
2014-11-04 19:26 ` Alexander Graf [this message]
2014-11-04 19:26 ` [Qemu-devel] [PULL 20/33] target-ppc: kvm: Fix memory overflow issue about strncat() Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 21/33] ppc: do not look at the MMU index to detect PR/HV mode Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 22/33] hw/ppc/spapr_pci.c: Avoid functions not in glib 2.12 (g_hash_table_iter_*) Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 23/33] sysbus: Add dynamic sysbus device search Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 24/33] sysbus: Make devices spawnable via -device Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 25/33] sysbus: Expose IRQ enumeration helpers Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 26/33] sysbus: Expose MMIO enumeration helper Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 27/33] sysbus: Add new platform bus helper device Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 28/33] PPC: e500: Support dynamically spawned sysbus devices Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 29/33] e500: Add support for eTSEC in device tree Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 30/33] target-ppc: simplify AES emulation Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 31/33] target-ppc: Fix Altivec Shifts Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 32/33] target-ppc: Fix vcmpbfp. Unordered Case Alexander Graf
2014-11-04 19:26 ` [Qemu-devel] [PULL 33/33] target-ppc: Fix Altivec Round Opcodes Alexander Graf
2014-11-04 21:34 ` [Qemu-devel] [PULL 2.2 00/33] ppc patch queue 2014-11-04 for 2.2 Peter Maydell
2014-11-05 12:48 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415129211-9740-20-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=aik@ozlabs.ru \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).