From: David Vrabel <david.vrabel@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: David Vrabel <david.vrabel@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Ian Campbell <ian.campbell@citrix.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH 5/6] libxl: add libxl_vm_generation_id_set()
Date: Tue, 27 May 2014 18:31:48 +0100 [thread overview]
Message-ID: <1401211909-27771-6-git-send-email-david.vrabel@citrix.com> (raw)
In-Reply-To: <1401211909-27771-1-git-send-email-david.vrabel@citrix.com>
Add a function to allow a toolstack to set a domain's VM generation
ID.
Although the specification requires that a ACPI Notify event is raised
if the generation ID is changed, in practice this appears not to be
necessary if the generation ID is changed while the Windows VM is
suspended.
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
tools/libxl/Makefile | 1 +
tools/libxl/libxl.h | 3 ++
tools/libxl/libxl_vm_genid.c | 87 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 91 insertions(+)
create mode 100644 tools/libxl/libxl_vm_genid.c
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 4cfa275..5d0e2ec 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -77,6 +77,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
libxl_json.o libxl_aoutils.o libxl_numa.o \
libxl_save_callout.o _libxl_save_msgs_callout.o \
libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y)
+LIBXL_OBJS += libxl_vm_genid.o
LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
LIBXL_TESTS += timedereg
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index c7aa817..8dfd715 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1163,6 +1163,9 @@ int libxl_flask_getenforce(libxl_ctx *ctx);
int libxl_flask_setenforce(libxl_ctx *ctx, int mode);
int libxl_flask_loadpolicy(libxl_ctx *ctx, void *policy, uint32_t size);
+int libxl_vm_generation_id_set(libxl_ctx *ctx, uint32_t domid,
+ const libxl_uuid *uuid);
+
/* misc */
/* Each of these sets or clears the flag according to whether the
diff --git a/tools/libxl/libxl_vm_genid.c b/tools/libxl/libxl_vm_genid.c
new file mode 100644
index 0000000..1545a97
--- /dev/null
+++ b/tools/libxl/libxl_vm_genid.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2014 Citrix Systems R&D Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+
+#include "libxl_internal.h"
+
+#include <xenctrl.h>
+#include <xen/hvm/params.h>
+
+/*
+ * Set a HVM domain's VM Generation ID.
+ *
+ * Toolstacks should call this after building or restoring the domain,
+ * but before unpausing it.
+ *
+ * For further details, refer to the "Virtual Machine Generation ID"
+ * document from Microsoft.
+ *
+ * http://www.microsoft.com/en-us/download/details.aspx?id=30707
+ */
+int libxl_vm_generation_id_set(libxl_ctx *ctx, uint32_t domid,
+ const libxl_uuid *uuid)
+{
+ GC_INIT(ctx);
+ char *dom_path;
+ char *key;
+ uint64_t genid[2];
+ uint64_t paddr = 0;
+ int rc;
+
+ memcpy(genid, libxl_uuid_bytearray((libxl_uuid *)uuid), 16);
+
+ /*
+ * Set the "platform/generation-id" XenStore key to pass the ID to
+ * hvmloader.
+ */
+ dom_path = libxl__xs_get_dompath(gc, domid);
+ if (!dom_path) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+ key = libxl__sprintf(gc, "%s/platform/generation-id", dom_path);
+ rc = libxl__xs_write(gc, XBT_NULL, key, "%"PRIu64 ":%" PRIu64,
+ genid[0], genid[1]);
+ if (rc < 0)
+ goto out;
+
+ /*
+ * Update the ID in guest memory (if available).
+ */
+ xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_VM_GENERATION_ID_ADDR, &paddr);
+ if (paddr) {
+ void *vaddr;
+
+ vaddr = xc_map_foreign_range(ctx->xch, domid, XC_PAGE_SIZE,
+ PROT_READ | PROT_WRITE,
+ paddr >> XC_PAGE_SHIFT);
+ if (vaddr == NULL) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+ memcpy(vaddr + (paddr & ~XC_PAGE_MASK), genid, 2 * sizeof(*genid));
+ munmap(vaddr, XC_PAGE_SIZE);
+
+ /*
+ * FIXME: Inject ACPI Notify event.
+ */
+ }
+
+ rc = 0;
+
+ out:
+ GC_FREE;
+ return rc;
+}
--
1.7.10.4
next prev parent reply other threads:[~2014-05-27 17:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-27 17:31 [PATCHv2 0/6] tools: rework VM Generation ID David Vrabel
2014-05-27 17:31 ` [PATCH 1/6] docs: update docs for the ~/platform/generation-id key David Vrabel
2014-05-28 14:44 ` Ian Campbell
2014-05-28 14:51 ` Andrew Cooper
2014-05-28 14:58 ` Ian Campbell
2014-05-27 17:31 ` [PATCH 2/6] hvm: add HVM_PARAM_VM_GENERATION_ID_ADDR David Vrabel
2014-05-27 17:31 ` [PATCH 3/6] tools/hvmloader: add helper functions to get/set HVM params David Vrabel
2014-05-27 17:31 ` [PATCH 4/6] libxc, libxl, hvmloader: strip out outdated VM generation ID implementation David Vrabel
2014-05-28 14:50 ` Ian Campbell
2014-06-02 9:23 ` David Vrabel
2014-05-27 17:31 ` David Vrabel [this message]
2014-05-28 14:56 ` [PATCH 5/6] libxl: add libxl_vm_generation_id_set() Ian Campbell
2014-06-02 9:25 ` David Vrabel
2014-05-27 17:31 ` [PATCH 6/6] xl: generate a new random VM generation ID if requested David Vrabel
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=1401211909-27771-6-git-send-email-david.vrabel@citrix.com \
--to=david.vrabel@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xenproject.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).