[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 1/2] hw/xen: detect when running inside stubdomain
From: |
Marek Marczykowski-Górecki |
Subject: |
[PATCH v2 1/2] hw/xen: detect when running inside stubdomain |
Date: |
Tue, 5 Mar 2024 20:12:29 +0100 |
Introduce global xen_is_stubdomain variable when qemu is running inside
a stubdomain instead of dom0. This will be relevant for subsequent
patches, as few things like accessing PCI config space need to be done
differently.
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
Changes in v2:
- use sigend int for domid to match xenstore_read_int() types, domid is
in a signed range anyway
- fix code style
---
hw/xen/xen-legacy-backend.c | 16 ++++++++++++++++
include/hw/xen/xen.h | 1 +
system/globals.c | 1 +
3 files changed, 18 insertions(+)
diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c
index 124dd5f3d6..6bd4e6eb2f 100644
--- a/hw/xen/xen-legacy-backend.c
+++ b/hw/xen/xen-legacy-backend.c
@@ -603,6 +603,20 @@ static void xen_set_dynamic_sysbus(void)
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_XENSYSDEV);
}
+static bool xen_check_stubdomain(void)
+{
+ char *dm_path = g_strdup_printf("/local/domain/%d/image", xen_domid);
+ int32_t dm_domid;
+ bool is_stubdom = false;
+
+ if (!xenstore_read_int(dm_path, "device-model-domid", &dm_domid)) {
+ is_stubdom = dm_domid != 0;
+ }
+
+ g_free(dm_path);
+ return is_stubdom;
+}
+
void xen_be_init(void)
{
xenstore = qemu_xen_xs_open();
@@ -616,6 +630,8 @@ void xen_be_init(void)
exit(1);
}
+ xen_is_stubdomain = xen_check_stubdomain();
+
xen_sysdev = qdev_new(TYPE_XENSYSDEV);
sysbus_realize_and_unref(SYS_BUS_DEVICE(xen_sysdev), &error_fatal);
xen_sysbus = qbus_new(TYPE_XENSYSBUS, xen_sysdev, "xen-sysbus");
diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h
index 37ecc91fc3..ecb89ecfc1 100644
--- a/include/hw/xen/xen.h
+++ b/include/hw/xen/xen.h
@@ -36,6 +36,7 @@ enum xen_mode {
extern uint32_t xen_domid;
extern enum xen_mode xen_mode;
extern bool xen_domid_restrict;
+extern bool xen_is_stubdomain;
int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
int xen_set_pci_link_route(uint8_t link, uint8_t irq);
diff --git a/system/globals.c b/system/globals.c
index b6d4e72530..ac27d88bd4 100644
--- a/system/globals.c
+++ b/system/globals.c
@@ -62,6 +62,7 @@ bool qemu_uuid_set;
uint32_t xen_domid;
enum xen_mode xen_mode = XEN_DISABLED;
bool xen_domid_restrict;
+bool xen_is_stubdomain;
struct evtchn_backend_ops *xen_evtchn_ops;
struct gnttab_backend_ops *xen_gnttab_ops;
struct foreignmem_backend_ops *xen_foreignmem_ops;
--
2.43.0
- [PATCH v2 1/2] hw/xen: detect when running inside stubdomain,
Marek Marczykowski-Górecki <=