aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2018-04-26 19:22:09 +0100
committerPeter Maydell <peter.maydell@linaro.org>2018-04-26 19:22:09 +0100
commitca92651697bdb2f15b36d347a498fbc31f4a4893 (patch)
tree553bfe798e7a391371ffee3f53a637d8bfcddfd7 /hw
parentb8846a4d6352b2a1d2012f8b3b9115640524aeda (diff)
parent8bbe05d77360b73c1834808023016a778ccf55ca (diff)
downloadqemu-ca92651697bdb2f15b36d347a498fbc31f4a4893.zip
qemu-ca92651697bdb2f15b36d347a498fbc31f4a4893.tar.gz
qemu-ca92651697bdb2f15b36d347a498fbc31f4a4893.tar.bz2
Merge remote-tracking branch 'remotes/iwj/tags/for-upstream.depriv-2' into staging
xen: xen-domid-restrict improvements # gpg: Signature made Thu 26 Apr 2018 19:11:22 BST # gpg: using RSA key E3E3392348B50D39 # gpg: Good signature from "Ian Jackson (new general purpose key) <ijackson@chiark.greenend.org.uk>" # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 559A E46C 2D6B 6D32 65E7 CBA1 E3E3 3923 48B5 0D39 * remotes/iwj/tags/for-upstream.depriv-2: configure: do_compiler: Dump some extra info under bash os-posix: cleanup: Replace perror with error_report os-posix: cleanup: Replace fprintf with error_report in remaining call sites xen: Expect xenstore write to fail when restricted xen: Remove now-obsolete xen_xc_domain_add_to_physmap xen: Use newly added dmops for mapping VGA memory os-posix: Provide new -runas <uid>:<gid> facility os-posix: cleanup: Replace fprintfs with error_report in change_process_uid xen: destroy_hvm_domain: Try xendevicemodel_shutdown xen: move xc_interface compatibility fallback further up the file xen: destroy_hvm_domain: Move reason into a variable xen: defer call to xen_restrict until just before os_setup_post xen: restrict: use xentoolcore_restrict_all xen: link against xentoolcore AccelClass: Introduce accel_setup_post checkpatch: Add xendevicemodel_handle to the list of types Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r--hw/i386/xen/xen-hvm.c75
-rw-r--r--hw/xen/xen-common.c21
2 files changed, 62 insertions, 34 deletions
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index f24b7d4..caa563b 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -347,7 +347,7 @@ static int xen_add_to_physmap(XenIOState *state,
MemoryRegion *mr,
hwaddr offset_within_region)
{
- unsigned long i = 0;
+ unsigned long nr_pages;
int rc = 0;
XenPhysmap *physmap = NULL;
hwaddr pfn, start_gpfn;
@@ -396,22 +396,26 @@ go_physmap:
pfn = phys_offset >> TARGET_PAGE_BITS;
start_gpfn = start_addr >> TARGET_PAGE_BITS;
- for (i = 0; i < size >> TARGET_PAGE_BITS; i++) {
- unsigned long idx = pfn + i;
- xen_pfn_t gpfn = start_gpfn + i;
-
- rc = xen_xc_domain_add_to_physmap(xen_xc, xen_domid, XENMAPSPACE_gmfn, idx, gpfn);
- if (rc) {
- DPRINTF("add_to_physmap MFN %"PRI_xen_pfn" to PFN %"
- PRI_xen_pfn" failed: %d (errno: %d)\n", idx, gpfn, rc, errno);
- return -rc;
- }
+ nr_pages = size >> TARGET_PAGE_BITS;
+ rc = xendevicemodel_relocate_memory(xen_dmod, xen_domid, nr_pages, pfn,
+ start_gpfn);
+ if (rc) {
+ int saved_errno = errno;
+
+ error_report("relocate_memory %lu pages from GFN %"HWADDR_PRIx
+ " to GFN %"HWADDR_PRIx" failed: %s",
+ nr_pages, pfn, start_gpfn, strerror(saved_errno));
+ errno = saved_errno;
+ return -1;
}
- xc_domain_pin_memory_cacheattr(xen_xc, xen_domid,
+ rc = xendevicemodel_pin_memory_cacheattr(xen_dmod, xen_domid,
start_addr >> TARGET_PAGE_BITS,
(start_addr + size - 1) >> TARGET_PAGE_BITS,
XEN_DOMCTL_MEM_CACHEATTR_WB);
+ if (rc) {
+ error_report("pin_memory_cacheattr failed: %s", strerror(errno));
+ }
return xen_save_physmap(state, physmap);
}
@@ -419,7 +423,6 @@ static int xen_remove_from_physmap(XenIOState *state,
hwaddr start_addr,
ram_addr_t size)
{
- unsigned long i = 0;
int rc = 0;
XenPhysmap *physmap = NULL;
hwaddr phys_offset = 0;
@@ -438,16 +441,17 @@ static int xen_remove_from_physmap(XenIOState *state,
size >>= TARGET_PAGE_BITS;
start_addr >>= TARGET_PAGE_BITS;
phys_offset >>= TARGET_PAGE_BITS;
- for (i = 0; i < size; i++) {
- xen_pfn_t idx = start_addr + i;
- xen_pfn_t gpfn = phys_offset + i;
-
- rc = xen_xc_domain_add_to_physmap(xen_xc, xen_domid, XENMAPSPACE_gmfn, idx, gpfn);
- if (rc) {
- fprintf(stderr, "add_to_physmap MFN %"PRI_xen_pfn" to PFN %"
- PRI_xen_pfn" failed: %d (errno: %d)\n", idx, gpfn, rc, errno);
- return -rc;
- }
+ rc = xendevicemodel_relocate_memory(xen_dmod, xen_domid, size, start_addr,
+ phys_offset);
+ if (rc) {
+ int saved_errno = errno;
+
+ error_report("relocate_memory "RAM_ADDR_FMT" pages"
+ " from GFN %"HWADDR_PRIx
+ " to GFN %"HWADDR_PRIx" failed: %s",
+ size, start_addr, phys_offset, strerror(saved_errno));
+ errno = saved_errno;
+ return -1;
}
QLIST_REMOVE(physmap, list);
@@ -1254,14 +1258,6 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
goto err;
}
- if (xen_domid_restrict) {
- rc = xen_restrict(xen_domid);
- if (rc < 0) {
- error_report("failed to restrict: error %d", errno);
- goto err;
- }
- }
-
xen_create_ioreq_server(xen_domid, &state->ioservid);
state->exit.notify = xen_exit_notifier;
@@ -1394,13 +1390,26 @@ void destroy_hvm_domain(bool reboot)
{
xc_interface *xc_handle;
int sts;
+ int rc;
+
+ unsigned int reason = reboot ? SHUTDOWN_reboot : SHUTDOWN_poweroff;
+
+ if (xen_dmod) {
+ rc = xendevicemodel_shutdown(xen_dmod, xen_domid, reason);
+ if (!rc) {
+ return;
+ }
+ if (errno != ENOTTY /* old Xen */) {
+ perror("xendevicemodel_shutdown failed");
+ }
+ /* well, try the old thing then */
+ }
xc_handle = xc_interface_open(0, 0, 0);
if (xc_handle == NULL) {
fprintf(stderr, "Cannot acquire xenctrl handle\n");
} else {
- sts = xc_domain_shutdown(xc_handle, xen_domid,
- reboot ? SHUTDOWN_reboot : SHUTDOWN_poweroff);
+ sts = xc_domain_shutdown(xc_handle, xen_domid, reason);
if (sts != 0) {
fprintf(stderr, "xc_domain_shutdown failed to issue %s, "
"sts %d, %s\n", reboot ? "reboot" : "poweroff",
diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c
index 83099dd..6ec14c7 100644
--- a/hw/xen/xen-common.c
+++ b/hw/xen/xen-common.c
@@ -101,7 +101,12 @@ static void xenstore_record_dm_state(struct xs_handle *xs, const char *state)
}
snprintf(path, sizeof (path), "device-model/%u/state", xen_domid);
- if (!xs_write(xs, XBT_NULL, path, state, strlen(state))) {
+ /*
+ * This call may fail when running restricted so don't make it fatal in
+ * that case. Toolstacks should instead use QMP to listen for state changes.
+ */
+ if (!xs_write(xs, XBT_NULL, path, state, strlen(state)) &&
+ !xen_domid_restrict) {
error_report("error recording dm state");
exit(1);
}
@@ -117,6 +122,19 @@ static void xen_change_state_handler(void *opaque, int running,
}
}
+static void xen_setup_post(MachineState *ms, AccelState *accel)
+{
+ int rc;
+
+ if (xen_domid_restrict) {
+ rc = xen_restrict(xen_domid);
+ if (rc < 0) {
+ perror("xen: failed to restrict");
+ exit(1);
+ }
+ }
+}
+
static int xen_init(MachineState *ms)
{
xen_xc = xc_interface_open(0, 0, 0);
@@ -165,6 +183,7 @@ static void xen_accel_class_init(ObjectClass *oc, void *data)
AccelClass *ac = ACCEL_CLASS(oc);
ac->name = "Xen";
ac->init_machine = xen_init;
+ ac->setup_post = xen_setup_post;
ac->allowed = &xen_allowed;
ac->global_props = xen_compat_props;
}