* [PATCH 01/21] xen: reinstate previously unused XENMEM_remove_from_physmap hypercall
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 02/21] xen: allow global VIRQ handlers to be delegated to other domains Daniel De Graaf
` (20 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf, Alex Zeffertt
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
This patch reinstates the XENMEM_remove_from_physmap hypercall
which was removed in 19041:ee62aaafff46 because it was not used.
However, is now needed in order to support xenstored stub domains.
The xenstored stub domain is not priviliged like dom0 and so cannot
unilaterally map the xenbus page of other guests into it's address
space. Therefore, before creating a domU the domain builder needs to
seed its grant table with a grant ref allowing the xenstored stub
domain to access the new domU's xenbus page.
At present domU's do not start with their grant table mapped.
Instead it gets mapped when the guest requests a grant table from
the hypervisor.
In order to seed the grant table, the domain builder first needs to
map it into dom0 address space. But the hypercall to do this
requires a gpfn (guest pfn), which is an mfn for PV guest, but a pfn
for HVM guests. Therfore, in order to seed the grant table of an
HVM guest, dom0 needs to *temporarily* map it into the guest's
"physical" address space.
Hence the need to reinstate the XENMEM_remove_from_physmap hypercall.
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
xen/common/compat/memory.c | 14 ++++++++++++++
xen/common/memory.c | 37 +++++++++++++++++++++++++++++++++++++
xen/include/asm-ia64/mm.h | 1 +
xen/include/public/memory.h | 16 ++++++++++++++++
xen/include/xlat.lst | 1 +
xen/include/xsm/xsm.h | 6 ++++++
xen/xsm/dummy.c | 6 ++++++
xen/xsm/flask/hooks.c | 6 ++++++
8 files changed, 87 insertions(+), 0 deletions(-)
diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c
index 2402984..e7257cc 100644
--- a/xen/common/compat/memory.c
+++ b/xen/common/compat/memory.c
@@ -25,6 +25,7 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE(void) compat)
XEN_GUEST_HANDLE(void) hnd;
struct xen_memory_reservation *rsrv;
struct xen_memory_exchange *xchg;
+ struct xen_remove_from_physmap *xrfp;
} nat;
union {
struct compat_memory_reservation rsrv;
@@ -179,6 +180,18 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE(void) compat)
nat.hnd = compat;
break;
+ case XENMEM_remove_from_physmap:
+ {
+ struct compat_remove_from_physmap cmp;
+
+ if ( copy_from_guest(&cmp, compat, 1) )
+ return -EFAULT;
+
+ XLAT_remove_from_physmap(nat.xrfp, &cmp);
+
+ break;
+ }
+
default:
return compat_arch_memory_op(cmd, compat);
}
@@ -284,6 +297,7 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE(void) compat)
case XENMEM_current_reservation:
case XENMEM_maximum_reservation:
case XENMEM_maximum_gpfn:
+ case XENMEM_remove_from_physmap:
break;
default:
diff --git a/xen/common/memory.c b/xen/common/memory.c
index c796137..60b9e17 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -659,6 +659,43 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE(void) arg)
break;
+ case XENMEM_remove_from_physmap:
+ {
+ struct xen_remove_from_physmap xrfp;
+ unsigned long mfn;
+ struct domain *d;
+
+ if ( copy_from_guest(&xrfp, arg, 1) )
+ return -EFAULT;
+
+ rc = rcu_lock_target_domain_by_id(xrfp.domid, &d);
+ if ( rc != 0 )
+ return rc;
+
+ if ( xsm_remove_from_physmap(current->domain, d) )
+ {
+ rcu_unlock_domain(d);
+ return -EPERM;
+ }
+
+ domain_lock(d);
+
+ mfn = get_gfn_untyped(d, xrfp.gpfn);
+
+ if ( mfn_valid(mfn) )
+ guest_physmap_remove_page(d, xrfp.gpfn, mfn, PAGE_ORDER_4K);
+ else
+ rc = -ENOENT;
+
+ put_gfn(d, xrfp.gpfn);
+
+ domain_unlock(d);
+
+ rcu_unlock_domain(d);
+
+ break;
+ }
+
default:
rc = arch_memory_op(op, arg);
break;
diff --git a/xen/include/asm-ia64/mm.h b/xen/include/asm-ia64/mm.h
index d09c363..a2bfc02 100644
--- a/xen/include/asm-ia64/mm.h
+++ b/xen/include/asm-ia64/mm.h
@@ -550,6 +550,7 @@ extern u64 translate_domain_pte(u64 pteval, u64 address, u64 itir__,
#define gmfn_to_mfn(_d, gpfn) \
gmfn_to_mfn_foreign((_d), (gpfn))
+#define get_gfn_untyped(d, gpfn) gmfn_to_mfn(d, gpfn)
#define put_gfn(d, g) ((void)0)
#define __gpfn_invalid(_d, gpfn) \
diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h
index c5b78a8..308deff 100644
--- a/xen/include/public/memory.h
+++ b/xen/include/public/memory.h
@@ -229,6 +229,22 @@ struct xen_add_to_physmap {
typedef struct xen_add_to_physmap xen_add_to_physmap_t;
DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
+/*
+ * Unmaps the page appearing at a particular GPFN from the specified guest's
+ * pseudophysical address space.
+ * arg == addr of xen_remove_from_physmap_t.
+ */
+#define XENMEM_remove_from_physmap 15
+struct xen_remove_from_physmap {
+ /* Which domain to change the mapping for. */
+ domid_t domid;
+
+ /* GPFN of the current mapping of the page. */
+ xen_pfn_t gpfn;
+};
+typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
+DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);
+
/*** REMOVED ***/
/*#define XENMEM_translate_gpfn_list 8*/
diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index 3d92175..5f94380 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -59,6 +59,7 @@
! memory_map memory.h
! memory_reservation memory.h
! pod_target memory.h
+! remove_from_physmap memory.h
? physdev_eoi physdev.h
? physdev_get_free_pirq physdev.h
? physdev_irq physdev.h
diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h
index df6cec2..566c808 100644
--- a/xen/include/xsm/xsm.h
+++ b/xen/include/xsm/xsm.h
@@ -169,6 +169,7 @@ struct xsm_operations {
int (*update_va_mapping) (struct domain *d, struct domain *f,
l1_pgentry_t pte);
int (*add_to_physmap) (struct domain *d1, struct domain *d2);
+ int (*remove_from_physmap) (struct domain *d1, struct domain *d2);
int (*sendtrigger) (struct domain *d);
int (*bind_pt_irq) (struct domain *d, struct xen_domctl_bind_pt_irq *bind);
int (*unbind_pt_irq) (struct domain *d);
@@ -738,6 +739,11 @@ static inline int xsm_add_to_physmap(struct domain *d1, struct domain *d2)
return xsm_call(add_to_physmap(d1, d2));
}
+static inline int xsm_remove_from_physmap(struct domain *d1, struct domain *d2)
+{
+ return xsm_call(remove_from_physmap(d1, d2));
+}
+
static inline int xsm_sendtrigger(struct domain *d)
{
return xsm_call(sendtrigger(d));
diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c
index 4bbfbff..65daa4e 100644
--- a/xen/xsm/dummy.c
+++ b/xen/xsm/dummy.c
@@ -529,6 +529,11 @@ static int dummy_add_to_physmap (struct domain *d1, struct domain *d2)
return 0;
}
+static int dummy_remove_from_physmap (struct domain *d1, struct domain *d2)
+{
+ return 0;
+}
+
static int dummy_sendtrigger (struct domain *d)
{
return 0;
@@ -690,6 +695,7 @@ void xsm_fixup_ops (struct xsm_operations *ops)
set_to_dummy_if_null(ops, mmu_machphys_update);
set_to_dummy_if_null(ops, update_va_mapping);
set_to_dummy_if_null(ops, add_to_physmap);
+ set_to_dummy_if_null(ops, remove_from_physmap);
set_to_dummy_if_null(ops, sendtrigger);
set_to_dummy_if_null(ops, bind_pt_irq);
set_to_dummy_if_null(ops, pin_mem_cacheattr);
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index 0d35767..a2020a9 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -1283,6 +1283,11 @@ static int flask_add_to_physmap(struct domain *d1, struct domain *d2)
return domain_has_perm(d1, d2, SECCLASS_MMU, MMU__PHYSMAP);
}
+static int flask_remove_from_physmap(struct domain *d1, struct domain *d2)
+{
+ return domain_has_perm(d1, d2, SECCLASS_MMU, MMU__PHYSMAP);
+}
+
static int flask_sendtrigger(struct domain *d)
{
return domain_has_perm(current->domain, d, SECCLASS_DOMAIN, DOMAIN__TRIGGER);
@@ -1550,6 +1555,7 @@ static struct xsm_operations flask_ops = {
.mmu_machphys_update = flask_mmu_machphys_update,
.update_va_mapping = flask_update_va_mapping,
.add_to_physmap = flask_add_to_physmap,
+ .remove_from_physmap = flask_remove_from_physmap,
.sendtrigger = flask_sendtrigger,
.get_device_group = flask_get_device_group,
.test_assign_device = flask_test_assign_device,
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 02/21] xen: allow global VIRQ handlers to be delegated to other domains
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
2012-01-20 20:47 ` [PATCH 01/21] xen: reinstate previously unused XENMEM_remove_from_physmap hypercall Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 03/21] xen: change virq parameters from int to uint32_t Daniel De Graaf
` (19 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf, Alex Zeffertt, Diego Ongaro
This patch sends global VIRQs to a domain designated as the VIRQ handler
instead of sending all global VIRQ events to dom0. This is required in
order to run xenstored in a stubdom, because VIRQ_DOM_EXC must be sent
to xenstored for domain destruction to work properly.
This patch was inspired by the xenstored stubdomain patch series sent to
xen-devel by Alex Zeffertt in 2009.
Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
tools/flask/policy/policy/flask/access_vectors | 1 +
tools/libxc/xc_domain.c | 10 ++++
tools/libxc/xenctrl.h | 9 +++
xen/arch/x86/cpu/mcheck/amd_nonfatal.c | 2 +-
xen/arch/x86/cpu/mcheck/mce.c | 2 +-
xen/arch/x86/cpu/mcheck/mce_intel.c | 6 +-
xen/arch/x86/cpu/mcheck/non-fatal.c | 2 +-
xen/common/cpu.c | 4 +-
xen/common/domain.c | 8 ++--
xen/common/domctl.c | 17 ++++++
xen/common/event_channel.c | 66 +++++++++++++++++++++++-
xen/common/trace.c | 2 +-
xen/drivers/char/console.c | 4 +-
xen/include/public/domctl.h | 8 +++
xen/include/xen/event.h | 12 +++-
xen/include/xsm/xsm.h | 6 ++
xen/xsm/dummy.c | 6 ++
xen/xsm/flask/hooks.c | 6 ++
xen/xsm/flask/include/av_perm_to_string.h | 1 +
xen/xsm/flask/include/av_permissions.h | 1 +
20 files changed, 154 insertions(+), 19 deletions(-)
diff --git a/tools/flask/policy/policy/flask/access_vectors b/tools/flask/policy/policy/flask/access_vectors
index 644f2e1..5901911 100644
--- a/tools/flask/policy/policy/flask/access_vectors
+++ b/tools/flask/policy/policy/flask/access_vectors
@@ -85,6 +85,7 @@ class domain
getpodtarget
setpodtarget
set_misc_info
+ set_virq_handler
}
class hvm
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index ab019b8..d98e68b 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -1504,6 +1504,16 @@ int xc_domain_set_access_required(xc_interface *xch,
return do_domctl(xch, &domctl);
}
+int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq)
+{
+ DECLARE_DOMCTL;
+
+ domctl.cmd = XEN_DOMCTL_set_virq_handler;
+ domctl.domain = domid;
+ domctl.u.set_virq_handler.virq = virq;
+ return do_domctl(xch, &domctl);
+}
+
/*
* Local variables:
* mode: C
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index 8b34769..8f3426f 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -747,6 +747,15 @@ int xc_domain_p2m_audit(xc_interface *xch,
int xc_domain_set_access_required(xc_interface *xch,
uint32_t domid,
unsigned int required);
+/**
+ * This function sets the handler of global VIRQs sent by the hypervisor
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id which will handle the VIRQ
+ * @parm virq the virq number (VIRQ_*)
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq);
/*
* CPUPOOL MANAGEMENT FUNCTIONS
diff --git a/xen/arch/x86/cpu/mcheck/amd_nonfatal.c b/xen/arch/x86/cpu/mcheck/amd_nonfatal.c
index 50288bd..9222098 100644
--- a/xen/arch/x86/cpu/mcheck/amd_nonfatal.c
+++ b/xen/arch/x86/cpu/mcheck/amd_nonfatal.c
@@ -100,7 +100,7 @@ static void mce_amd_checkregs(void *info)
if (dom0_vmce_enabled()) {
mctelem_commit(mctc);
- send_guest_global_virq(dom0, VIRQ_MCA);
+ send_global_virq(VIRQ_MCA);
} else if (++dumpcount >= 10) {
x86_mcinfo_dump((struct mc_info *)mctelem_dataptr(mctc));
mctelem_dismiss(mctc);
diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c
index b592041..c4e4477 100644
--- a/xen/arch/x86/cpu/mcheck/mce.c
+++ b/xen/arch/x86/cpu/mcheck/mce.c
@@ -594,7 +594,7 @@ void mcheck_cmn_handler(struct cpu_user_regs *regs, long error_code,
if (dom0_vmce_enabled()) {
if (mctc != NULL)
mctelem_commit(mctc);
- send_guest_global_virq(dom0, VIRQ_MCA);
+ send_global_virq(VIRQ_MCA);
} else {
x86_mcinfo_dump(mci);
if (mctc != NULL)
diff --git a/xen/arch/x86/cpu/mcheck/mce_intel.c b/xen/arch/x86/cpu/mcheck/mce_intel.c
index 0986025..0894080 100644
--- a/xen/arch/x86/cpu/mcheck/mce_intel.c
+++ b/xen/arch/x86/cpu/mcheck/mce_intel.c
@@ -354,7 +354,7 @@ static void mce_softirq(void)
/* Step2: Send Log to DOM0 through vIRQ */
if (dom0_vmce_enabled()) {
mce_printk(MCE_VERBOSE, "MCE: send MCE# to DOM0 through virq\n");
- send_guest_global_virq(dom0, VIRQ_MCA);
+ send_global_virq(VIRQ_MCA);
}
}
@@ -1085,7 +1085,7 @@ static void cmci_discover(void)
if (bs.errcnt && mctc != NULL) {
if (dom0_vmce_enabled()) {
mctelem_commit(mctc);
- send_guest_global_virq(dom0, VIRQ_MCA);
+ send_global_virq(VIRQ_MCA);
} else {
x86_mcinfo_dump(mctelem_dataptr(mctc));
mctelem_dismiss(mctc);
@@ -1205,7 +1205,7 @@ fastcall void smp_cmci_interrupt(struct cpu_user_regs *regs)
if (dom0_vmce_enabled()) {
mctelem_commit(mctc);
mce_printk(MCE_VERBOSE, "CMCI: send CMCI to DOM0 through virq\n");
- send_guest_global_virq(dom0, VIRQ_MCA);
+ send_global_virq(VIRQ_MCA);
} else {
x86_mcinfo_dump(mctelem_dataptr(mctc));
mctelem_dismiss(mctc);
diff --git a/xen/arch/x86/cpu/mcheck/non-fatal.c b/xen/arch/x86/cpu/mcheck/non-fatal.c
index c57688f..1dded9b 100644
--- a/xen/arch/x86/cpu/mcheck/non-fatal.c
+++ b/xen/arch/x86/cpu/mcheck/non-fatal.c
@@ -55,7 +55,7 @@ static void mce_checkregs (void *info)
if (dom0_vmce_enabled()) {
mctelem_commit(mctc);
- send_guest_global_virq(dom0, VIRQ_MCA);
+ send_global_virq(VIRQ_MCA);
} else if (++dumpcount >= 10) {
x86_mcinfo_dump((struct mc_info *)mctelem_dataptr(mctc));
mctelem_dismiss(mctc);
diff --git a/xen/common/cpu.c b/xen/common/cpu.c
index 79abdb7..630881e 100644
--- a/xen/common/cpu.c
+++ b/xen/common/cpu.c
@@ -108,7 +108,7 @@ int cpu_down(unsigned int cpu)
notifier_rc = notifier_call_chain(&cpu_chain, CPU_DEAD, hcpu, NULL);
BUG_ON(notifier_rc != NOTIFY_DONE);
- send_guest_global_virq(dom0, VIRQ_PCPU_STATE);
+ send_global_virq(VIRQ_PCPU_STATE);
cpu_hotplug_done();
return 0;
@@ -148,7 +148,7 @@ int cpu_up(unsigned int cpu)
notifier_rc = notifier_call_chain(&cpu_chain, CPU_ONLINE, hcpu, NULL);
BUG_ON(notifier_rc != NOTIFY_DONE);
- send_guest_global_virq(dom0, VIRQ_PCPU_STATE);
+ send_global_virq(VIRQ_PCPU_STATE);
cpu_hotplug_done();
return 0;
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 52a63ef..f1a7ede 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -116,7 +116,7 @@ static void __domain_finalise_shutdown(struct domain *d)
if ( (d->shutdown_code == SHUTDOWN_suspend) && d->suspend_evtchn )
evtchn_send(d, d->suspend_evtchn);
else
- send_guest_global_virq(dom0, VIRQ_DOM_EXC);
+ send_global_virq(VIRQ_DOM_EXC);
}
static void vcpu_check_shutdown(struct vcpu *v)
@@ -492,7 +492,7 @@ int domain_kill(struct domain *d)
}
d->is_dying = DOMDYING_dead;
put_domain(d);
- send_guest_global_virq(dom0, VIRQ_DOM_EXC);
+ send_global_virq(VIRQ_DOM_EXC);
/* fallthrough */
case DOMDYING_dead:
break;
@@ -633,7 +633,7 @@ void domain_pause_for_debugger(void)
for_each_vcpu ( d, v )
vcpu_sleep_nosync(v);
- send_guest_global_virq(dom0, VIRQ_DEBUGGER);
+ send_global_virq(VIRQ_DEBUGGER);
}
/* Complete domain destroy after RCU readers are not holding old references. */
@@ -690,7 +690,7 @@ static void complete_domain_destroy(struct rcu_head *head)
free_cpumask_var(d->domain_dirty_cpumask);
free_domain_struct(d);
- send_guest_global_virq(dom0, VIRQ_DOM_EXC);
+ send_global_virq(VIRQ_DOM_EXC);
}
/* Release resources belonging to task @p. */
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index d6ae09b..97c7d53 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -994,6 +994,23 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domctl_t) u_domctl)
}
break;
+ case XEN_DOMCTL_set_virq_handler:
+ {
+ struct domain *d;
+ uint32_t virq = op->u.set_virq_handler.virq;
+
+ ret = -ESRCH;
+ d = rcu_lock_domain_by_id(op->domain);
+ if ( d != NULL )
+ {
+ ret = xsm_set_virq_handler(d, virq);
+ if ( !ret )
+ ret = set_global_virq_handler(d, virq);
+ rcu_unlock_domain(d);
+ }
+ }
+ break;
+
default:
ret = arch_do_domctl(op, u_domctl);
break;
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 9212042..43bd167 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -689,7 +689,7 @@ void send_guest_vcpu_virq(struct vcpu *v, int virq)
spin_unlock_irqrestore(&v->virq_lock, flags);
}
-void send_guest_global_virq(struct domain *d, int virq)
+static void send_guest_global_virq(struct domain *d, int virq)
{
unsigned long flags;
int port;
@@ -739,6 +739,68 @@ int send_guest_pirq(struct domain *d, const struct pirq *pirq)
return evtchn_set_pending(d->vcpu[chn->notify_vcpu_id], port);
}
+static struct domain *global_virq_handlers[NR_VIRQS] __read_mostly;
+
+static DEFINE_SPINLOCK(global_virq_handlers_lock);
+
+void send_global_virq(uint32_t virq)
+{
+ ASSERT(virq < NR_VIRQS);
+ ASSERT(virq_is_global(virq));
+
+ send_guest_global_virq(global_virq_handlers[virq] ?: dom0, virq);
+}
+
+int set_global_virq_handler(struct domain *d, uint32_t virq)
+{
+ struct domain *old;
+
+ if (virq >= NR_VIRQS)
+ return -EINVAL;
+ if (!virq_is_global(virq))
+ return -EINVAL;
+
+ if (global_virq_handlers[virq] == d)
+ return 0;
+
+ if (unlikely(!get_domain(d)))
+ return -EINVAL;
+
+ spin_lock(&global_virq_handlers_lock);
+ old = global_virq_handlers[virq];
+ global_virq_handlers[virq] = d;
+ spin_unlock(&global_virq_handlers_lock);
+
+ if (old != NULL)
+ put_domain(old);
+
+ return 0;
+}
+
+static void clear_global_virq_handlers(struct domain *d)
+{
+ uint32_t virq;
+ int put_count = 0;
+
+ spin_lock(&global_virq_handlers_lock);
+
+ for (virq = 0; virq < NR_VIRQS; virq++)
+ {
+ if (global_virq_handlers[virq] == d)
+ {
+ global_virq_handlers[virq] = NULL;
+ put_count++;
+ }
+ }
+
+ spin_unlock(&global_virq_handlers_lock);
+
+ while (put_count)
+ {
+ put_domain(d);
+ put_count--;
+ }
+}
static long evtchn_status(evtchn_status_t *status)
{
@@ -1160,6 +1222,8 @@ void evtchn_destroy(struct domain *d)
d->evtchn[i] = NULL;
}
spin_unlock(&d->event_lock);
+
+ clear_global_virq_handlers(d);
}
diff --git a/xen/common/trace.c b/xen/common/trace.c
index 5772f24..58cbf39 100644
--- a/xen/common/trace.c
+++ b/xen/common/trace.c
@@ -661,7 +661,7 @@ static inline void insert_lost_records(struct t_buf *buf)
*/
static void trace_notify_dom0(unsigned long unused)
{
- send_guest_global_virq(dom0, VIRQ_TBUF);
+ send_global_virq(VIRQ_TBUF);
}
static DECLARE_SOFTIRQ_TASKLET(trace_notify_dom0_tasklet,
trace_notify_dom0, 0);
diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index 8a4c684..79b266f 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -287,7 +287,7 @@ static void __serial_rx(char c, struct cpu_user_regs *regs)
if ( (serial_rx_prod-serial_rx_cons) != SERIAL_RX_SIZE )
serial_rx_ring[SERIAL_RX_MASK(serial_rx_prod++)] = c;
/* Always notify the guest: prevents receive path from getting stuck. */
- send_guest_global_virq(dom0, VIRQ_CONSOLE);
+ send_global_virq(VIRQ_CONSOLE);
}
static void serial_rx(char c, struct cpu_user_regs *regs)
@@ -314,7 +314,7 @@ static void serial_rx(char c, struct cpu_user_regs *regs)
static void notify_dom0_con_ring(unsigned long unused)
{
- send_guest_global_virq(dom0, VIRQ_CON_RING);
+ send_global_virq(VIRQ_CON_RING);
}
static DECLARE_SOFTIRQ_TASKLET(notify_dom0_con_ring_tasklet,
notify_dom0_con_ring, 0);
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index c7640aa..75be370 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -813,6 +813,12 @@ struct xen_domctl_audit_p2m {
typedef struct xen_domctl_audit_p2m xen_domctl_audit_p2m_t;
DEFINE_XEN_GUEST_HANDLE(xen_domctl_audit_p2m_t);
+struct xen_domctl_set_virq_handler {
+ uint32_t virq; /* IN */
+};
+typedef struct xen_domctl_set_virq_handler xen_domctl_set_virq_handler_t;
+DEFINE_XEN_GUEST_HANDLE(xen_domctl_set_virq_handler_t);
+
#if defined(__i386__) || defined(__x86_64__)
/* XEN_DOMCTL_setvcpuextstate */
/* XEN_DOMCTL_getvcpuextstate */
@@ -912,6 +918,7 @@ struct xen_domctl {
#define XEN_DOMCTL_getvcpuextstate 63
#define XEN_DOMCTL_set_access_required 64
#define XEN_DOMCTL_audit_p2m 65
+#define XEN_DOMCTL_set_virq_handler 66
#define XEN_DOMCTL_gdbsx_guestmemio 1000
#define XEN_DOMCTL_gdbsx_pausevcpu 1001
#define XEN_DOMCTL_gdbsx_unpausevcpu 1002
@@ -966,6 +973,7 @@ struct xen_domctl {
#endif
struct xen_domctl_set_access_required access_required;
struct xen_domctl_audit_p2m audit_p2m;
+ struct xen_domctl_set_virq_handler set_virq_handler;
struct xen_domctl_gdbsx_memio gdbsx_guest_memio;
struct xen_domctl_gdbsx_pauseunp_vcpu gdbsx_pauseunp_vcpu;
struct xen_domctl_gdbsx_domstatus gdbsx_domstatus;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 232d50e..40b8a7a 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -23,11 +23,17 @@
void send_guest_vcpu_virq(struct vcpu *v, int virq);
/*
- * send_guest_global_virq: Notify guest via a global VIRQ.
- * @d: Domain to which virtual IRQ should be sent
+ * send_global_virq: Notify the domain handling a global VIRQ.
* @virq: Virtual IRQ number (VIRQ_*)
*/
-void send_guest_global_virq(struct domain *d, int virq);
+void send_global_virq(uint32_t virq);
+
+/*
+ * sent_global_virq_handler: Set a global VIRQ handler.
+ * @d: New target domain for this VIRQ
+ * @virq: Virtual IRQ number (VIRQ_*), must be global
+ */
+int set_global_virq_handler(struct domain *d, uint32_t virq);
/*
* send_guest_pirq:
diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h
index 566c808..e3cae60 100644
--- a/xen/include/xsm/xsm.h
+++ b/xen/include/xsm/xsm.h
@@ -64,6 +64,7 @@ struct xsm_operations {
int (*domain_settime) (struct domain *d);
int (*set_target) (struct domain *d, struct domain *e);
int (*domctl) (struct domain *d, int cmd);
+ int (*set_virq_handler) (struct domain *d, uint32_t virq);
int (*tbufcontrol) (void);
int (*readconsole) (uint32_t clear);
int (*sched_id) (void);
@@ -265,6 +266,11 @@ static inline int xsm_domctl (struct domain *d, int cmd)
return xsm_call(domctl(d, cmd));
}
+static inline int xsm_set_virq_handler (struct domain *d, uint32_t virq)
+{
+ return xsm_call(set_virq_handler(d, virq));
+}
+
static inline int xsm_tbufcontrol (void)
{
return xsm_call(tbufcontrol());
diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c
index 65daa4e..acf9c8a 100644
--- a/xen/xsm/dummy.c
+++ b/xen/xsm/dummy.c
@@ -94,6 +94,11 @@ static int dummy_domctl(struct domain *d, int cmd)
return 0;
}
+static int dummy_set_virq_handler(struct domain *d, uint32_t virq)
+{
+ return 0;
+}
+
static int dummy_tbufcontrol (void)
{
return 0;
@@ -596,6 +601,7 @@ void xsm_fixup_ops (struct xsm_operations *ops)
set_to_dummy_if_null(ops, domain_settime);
set_to_dummy_if_null(ops, set_target);
set_to_dummy_if_null(ops, domctl);
+ set_to_dummy_if_null(ops, set_virq_handler);
set_to_dummy_if_null(ops, tbufcontrol);
set_to_dummy_if_null(ops, readconsole);
set_to_dummy_if_null(ops, sched_id);
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index a2020a9..543dc77 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -597,6 +597,11 @@ static int flask_domctl(struct domain *d, int cmd)
return domain_has_perm(current->domain, d, SECCLASS_DOMAIN, DOMAIN__SET_MISC_INFO);
}
+static int flask_set_virq_handler(struct domain *d, uint32_t virq)
+{
+ return domain_has_perm(current->domain, d, SECCLASS_DOMAIN, DOMAIN__SET_VIRQ_HANDLER);
+}
+
static int flask_tbufcontrol(void)
{
return domain_has_xen(current->domain, XEN__TBUFCONTROL);
@@ -1460,6 +1465,7 @@ static struct xsm_operations flask_ops = {
.domain_settime = flask_domain_settime,
.set_target = flask_set_target,
.domctl = flask_domctl,
+ .set_virq_handler = flask_set_virq_handler,
.tbufcontrol = flask_tbufcontrol,
.readconsole = flask_readconsole,
.sched_id = flask_sched_id,
diff --git a/xen/xsm/flask/include/av_perm_to_string.h b/xen/xsm/flask/include/av_perm_to_string.h
index 85cbffc..17a1c36 100644
--- a/xen/xsm/flask/include/av_perm_to_string.h
+++ b/xen/xsm/flask/include/av_perm_to_string.h
@@ -60,6 +60,7 @@
S_(SECCLASS_DOMAIN, DOMAIN__GETPODTARGET, "getpodtarget")
S_(SECCLASS_DOMAIN, DOMAIN__SETPODTARGET, "setpodtarget")
S_(SECCLASS_DOMAIN, DOMAIN__SET_MISC_INFO, "set_misc_info")
+ S_(SECCLASS_DOMAIN, DOMAIN__SET_VIRQ_HANDLER, "set_virq_handler")
S_(SECCLASS_HVM, HVM__SETHVMC, "sethvmc")
S_(SECCLASS_HVM, HVM__GETHVMC, "gethvmc")
S_(SECCLASS_HVM, HVM__SETPARAM, "setparam")
diff --git a/xen/xsm/flask/include/av_permissions.h b/xen/xsm/flask/include/av_permissions.h
index 9e55a86..42eaf81 100644
--- a/xen/xsm/flask/include/av_permissions.h
+++ b/xen/xsm/flask/include/av_permissions.h
@@ -61,6 +61,7 @@
#define DOMAIN__GETPODTARGET 0x10000000UL
#define DOMAIN__SETPODTARGET 0x20000000UL
#define DOMAIN__SET_MISC_INFO 0x40000000UL
+#define DOMAIN__SET_VIRQ_HANDLER 0x80000000UL
#define HVM__SETHVMC 0x00000001UL
#define HVM__GETHVMC 0x00000002UL
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 03/21] xen: change virq parameters from int to uint32_t
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
2012-01-20 20:47 ` [PATCH 01/21] xen: reinstate previously unused XENMEM_remove_from_physmap hypercall Daniel De Graaf
2012-01-20 20:47 ` [PATCH 02/21] xen: allow global VIRQ handlers to be delegated to other domains Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 04/21] xen: use XSM instead of IS_PRIV for getdomaininfo Daniel De Graaf
` (18 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
xen/common/event_channel.c | 10 +++++-----
xen/include/asm-ia64/event.h | 2 +-
xen/include/asm-x86/event.h | 2 +-
xen/include/xen/event.h | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 43bd167..f784254 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -104,11 +104,11 @@ static uint8_t get_xen_consumer(xen_event_channel_notification_t fn)
static int evtchn_set_pending(struct vcpu *v, int port);
-static int virq_is_global(int virq)
+static int virq_is_global(uint32_t virq)
{
int rc;
- ASSERT((virq >= 0) && (virq < NR_VIRQS));
+ ASSERT(virq < NR_VIRQS);
switch ( virq )
{
@@ -665,12 +665,12 @@ static int evtchn_set_pending(struct vcpu *v, int port)
return 0;
}
-int guest_enabled_event(struct vcpu *v, int virq)
+int guest_enabled_event(struct vcpu *v, uint32_t virq)
{
return ((v != NULL) && (v->virq_to_evtchn[virq] != 0));
}
-void send_guest_vcpu_virq(struct vcpu *v, int virq)
+void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
{
unsigned long flags;
int port;
@@ -689,7 +689,7 @@ void send_guest_vcpu_virq(struct vcpu *v, int virq)
spin_unlock_irqrestore(&v->virq_lock, flags);
}
-static void send_guest_global_virq(struct domain *d, int virq)
+static void send_guest_global_virq(struct domain *d, uint32_t virq)
{
unsigned long flags;
int port;
diff --git a/xen/include/asm-ia64/event.h b/xen/include/asm-ia64/event.h
index c99babd..4463cb3 100644
--- a/xen/include/asm-ia64/event.h
+++ b/xen/include/asm-ia64/event.h
@@ -63,7 +63,7 @@ static inline void local_event_delivery_enable(void)
current->vcpu_info->evtchn_upcall_mask = 0;
}
-static inline int arch_virq_is_global(int virq)
+static inline int arch_virq_is_global(uint32_t virq)
{
int rc;
diff --git a/xen/include/asm-x86/event.h b/xen/include/asm-x86/event.h
index 606ec6d..06057c7 100644
--- a/xen/include/asm-x86/event.h
+++ b/xen/include/asm-x86/event.h
@@ -39,7 +39,7 @@ static inline void local_event_delivery_enable(void)
}
/* No arch specific virq definition now. Default to global. */
-static inline int arch_virq_is_global(int virq)
+static inline int arch_virq_is_global(uint32_t virq)
{
return 1;
}
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 40b8a7a..22fc6a3 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -20,7 +20,7 @@
* @v: VCPU to which virtual IRQ should be sent
* @virq: Virtual IRQ number (VIRQ_*)
*/
-void send_guest_vcpu_virq(struct vcpu *v, int virq);
+void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq);
/*
* send_global_virq: Notify the domain handling a global VIRQ.
@@ -65,7 +65,7 @@ void free_xen_event_channel(
struct vcpu *local_vcpu, int port);
/* Query if event channel is in use by the guest */
-int guest_enabled_event(struct vcpu *v, int virq);
+int guest_enabled_event(struct vcpu *v, uint32_t virq);
/* Notify remote end of a Xen-attached event channel.*/
void notify_via_xen_event_channel(struct domain *ld, int lport);
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 04/21] xen: use XSM instead of IS_PRIV for getdomaininfo
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (2 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 03/21] xen: change virq parameters from int to uint32_t Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 05/21] xen: Preserve reserved grant entries when switching versions Daniel De Graaf
` (17 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
The XEN_DOMCTL_getdomaininfo domctl does not allow manipulation of
domains, only basic information such as size and state, so its use
does not fully justify making a domain privileged. XSM modules can also
provide fine-grained control over what domains are visible to domains
that call getdomaininfo.
If XSM is disabled (either at compile time or by using the dummy XSM
module) then there is no change in behavior: only IS_PRIV domains can
use this domctl. If enabled, the XSM module controls access.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
xen/common/domctl.c | 4 ++++
xen/xsm/dummy.c | 2 ++
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 97c7d53..e1bbc9a 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -263,6 +263,10 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domctl_t) u_domctl)
return -EPERM;
break;
}
+#ifdef XSM_ENABLE
+ case XEN_DOMCTL_getdomaininfo:
+ break;
+#endif
default:
if ( !IS_PRIV(current->domain) )
return -EPERM;
diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c
index acf9c8a..d99f886 100644
--- a/xen/xsm/dummy.c
+++ b/xen/xsm/dummy.c
@@ -66,6 +66,8 @@ static int dummy_scheduler (struct domain *d)
static int dummy_getdomaininfo (struct domain *d)
{
+ if ( !IS_PRIV(current->domain) )
+ return -EPERM;
return 0;
}
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 05/21] xen: Preserve reserved grant entries when switching versions
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (3 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 04/21] xen: use XSM instead of IS_PRIV for getdomaininfo Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 06/21] tools/libxl: pull xenstore/console domids from xenstore Daniel De Graaf
` (16 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
In order for the toolstack to use reserved grant table entries, the
grant table for a guest must be initialized prior to the guest's boot.
When the guest switches grant table versions (necessary if the guest is
using v2 grant tables, or on kexec if switching grant versions), these
initial grants will be cleared. Instead of clearing them, preserve
the grants across the type change.
Attempting to preserve v2-only features such as sub-page grants will
produce a warning and invalidate the resulting v1 grant entry.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
xen/common/grant_table.c | 48 +++++++++++++++++++++++++++++++++----
xen/include/public/grant_table.h | 7 +++++
2 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index 34a49db..dd9f904 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -2110,6 +2110,7 @@ gnttab_set_version(XEN_GUEST_HANDLE(gnttab_set_version_t uop))
struct domain *d = current->domain;
struct grant_table *gt = d->grant_table;
struct active_grant_entry *act;
+ grant_entry_v1_t reserved_entries[GNTTAB_NR_RESERVED_ENTRIES];
long res;
int i;
@@ -2130,7 +2131,7 @@ gnttab_set_version(XEN_GUEST_HANDLE(gnttab_set_version_t uop))
/* (You need to change the version number for e.g. kexec.) */
if ( gt->gt_version != 0 )
{
- for ( i = 0; i < nr_grant_entries(gt); i++ )
+ for ( i = GNTTAB_NR_RESERVED_ENTRIES; i < nr_grant_entries(gt); i++ )
{
act = &active_entry(gt, i);
if ( act->pin != 0 )
@@ -2155,15 +2156,50 @@ gnttab_set_version(XEN_GUEST_HANDLE(gnttab_set_version_t uop))
goto out_unlock;
}
+ /* Preserve the first 8 entries (toolstack reserved grants) */
+ if (gt->gt_version == 1)
+ {
+ memcpy(reserved_entries, gt->shared_v1[0], sizeof(reserved_entries));
+ }
+ else if (gt->gt_version == 2)
+ {
+ for ( i = 0; i < GNTTAB_NR_RESERVED_ENTRIES && i < nr_grant_entries(gt); i++ )
+ {
+ reserved_entries[i].flags = shared_entry_v2(gt, i).hdr.flags;
+ reserved_entries[i].domid = shared_entry_v2(gt, i).hdr.domid;
+ reserved_entries[i].frame = shared_entry_v2(gt, i).full_page.frame;
+ reserved_entries[i].flags |= status_entry(gt, i);
+ if ((reserved_entries[i].flags & GTF_type_mask) > GTF_permit_access)
+ {
+ gdprintk(XENLOG_INFO, "d%d: bad flags %x in grant %d when switching grant version\n",
+ d->domain_id, reserved_entries[i].flags, i);
+ reserved_entries[i].flags = GTF_invalid;
+ }
+ }
+ }
+
if ( op.version < 2 && gt->gt_version == 2 )
gnttab_unpopulate_status_frames(d, gt);
- if ( op.version != gt->gt_version )
+ /* Make sure there's no crud left over in the table from the
+ old version. */
+ for ( i = 0; i < nr_grant_frames(gt); i++ )
+ memset(gt->shared_raw[i], 0, PAGE_SIZE);
+
+ /* Restore the first 8 entries (toolstack reserved grants) */
+ if (gt->gt_version != 0 && op.version == 1)
{
- /* Make sure there's no crud left over in the table from the
- old version. */
- for ( i = 0; i < nr_grant_frames(gt); i++ )
- memset(gt->shared_raw[i], 0, PAGE_SIZE);
+ memcpy(gt->shared_v1[0], reserved_entries, sizeof(reserved_entries));
+ }
+ else if (gt->gt_version != 0 && op.version == 2)
+ {
+ for ( i = 0; i < GNTTAB_NR_RESERVED_ENTRIES; i++ )
+ {
+ status_entry(gt, i) = reserved_entries[i].flags & (GTF_reading|GTF_writing);
+ shared_entry_v2(gt, i).hdr.flags = reserved_entries[i].flags & ~(GTF_reading|GTF_writing);
+ shared_entry_v2(gt, i).hdr.domid = reserved_entries[i].domid;
+ shared_entry_v2(gt, i).full_page.frame = reserved_entries[i].frame;
+ }
}
gt->gt_version = op.version;
diff --git a/xen/include/public/grant_table.h b/xen/include/public/grant_table.h
index 0bf20bc..5604638 100644
--- a/xen/include/public/grant_table.h
+++ b/xen/include/public/grant_table.h
@@ -117,6 +117,13 @@ struct grant_entry_v1 {
};
typedef struct grant_entry_v1 grant_entry_v1_t;
+/* The first few grant table entries will be preserved across grant table
+ * version changes and may be pre-populated at domain creation by tools.
+ */
+#define GNTTAB_NR_RESERVED_ENTRIES 8
+#define GNTTAB_RESERVED_CONSOLE 0
+#define GNTTAB_RESERVED_XENSTORE 1
+
/*
* Type of grant entry.
* GTF_invalid: This grant entry grants no privileges.
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 06/21] tools/libxl: pull xenstore/console domids from xenstore
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (4 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 05/21] xen: Preserve reserved grant entries when switching versions Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 07/21] lib{xc, xl}: Seed grant tables with xenstore and console grants Daniel De Graaf
` (15 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
Instead of assuming that xenstored and xenconsoled are running in dom0,
pull the domain IDs from xenstore.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
tools/libxl/libxl_dom.c | 14 ++++++++++++--
tools/libxl/libxl_internal.h | 2 ++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 91643a2..3828c62 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -64,6 +64,7 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
{
libxl_ctx *ctx = libxl__gc_owner(gc);
int tsc_mode;
+ char *xs_domid, *con_domid;
xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + LIBXL_MAXMEM_CONSTANT);
if (info->type == LIBXL_DOMAIN_TYPE_PV)
@@ -95,9 +96,18 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
xc_shadow_control(ctx->xch, domid, XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, NULL, 0, &shadow, 0, NULL);
}
- state->store_port = xc_evtchn_alloc_unbound(ctx->xch, domid, 0);
- state->console_port = xc_evtchn_alloc_unbound(ctx->xch, domid, 0);
+ xs_domid = xs_read(ctx->xsh, XBT_NULL, "/tool/xenstored/domid", NULL);
+ state->store_domid = xs_domid ? atoi(xs_domid) : 0;
+ free(xs_domid);
+
+ con_domid = xs_read(ctx->xsh, XBT_NULL, "/tool/xenconsoled/domid", NULL);
+ state->console_domid = con_domid ? atoi(con_domid) : 0;
+ free(con_domid);
+
+ state->store_port = xc_evtchn_alloc_unbound(ctx->xch, domid, state->store_domid);
+ state->console_port = xc_evtchn_alloc_unbound(ctx->xch, domid, state->console_domid);
state->vm_generationid_addr = 0;
+
return 0;
}
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 39e9e05..7e42a50 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -241,9 +241,11 @@ _hidden int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t domid);
libxl__domain_type((gc), (domid)) == LIBXL_DOMAIN_TYPE_##type
typedef struct {
uint32_t store_port;
+ uint32_t store_domid;
unsigned long store_mfn;
uint32_t console_port;
+ uint32_t console_domid;
unsigned long console_mfn;
unsigned long vm_generationid_addr;
} libxl__domain_build_state;
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 07/21] lib{xc, xl}: Seed grant tables with xenstore and console grants
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (5 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 06/21] tools/libxl: pull xenstore/console domids from xenstore Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-23 12:26 ` Ian Campbell
2012-01-20 20:47 ` [PATCH 08/21] mini-os: avoid crash if no console is provided Daniel De Graaf
` (14 subsequent siblings)
21 siblings, 1 reply; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf, Alex Zeffertt, Diego Ongaro
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
This patch claims one reserved grant entry for the console and another
for the xenstore. It modifies the builder to fill in the grant table
entries for the console and the xenstore.
Previous versions of this patch have been sent to xen-devel. See
http://lists.xensource.com/archives/html/xen-devel/2008-07/msg00610.html
http://lists.xensource.com/archives/html/xen-devel/2009-03/msg01491.html
Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
tools/libxc/xc_dom.h | 13 +++
tools/libxc/xc_dom_boot.c | 164 +++++++++++++++++++++++++++++++++++++
tools/libxc/xc_dom_compat_linux.c | 2 +
tools/libxc/xc_domain_restore.c | 19 ++++-
tools/libxc/xenguest.h | 3 +-
tools/libxl/libxl_dom.c | 18 ++++-
tools/xcutils/xc_restore.c | 4 +-
7 files changed, 216 insertions(+), 7 deletions(-)
diff --git a/tools/libxc/xc_dom.h b/tools/libxc/xc_dom.h
index e72f066..6c36403 100644
--- a/tools/libxc/xc_dom.h
+++ b/tools/libxc/xc_dom.h
@@ -106,7 +106,9 @@ struct xc_dom_image {
/* misc xen domain config stuff */
unsigned long flags;
unsigned int console_evtchn;
+ unsigned int console_domid;
unsigned int xenstore_evtchn;
+ unsigned int xenstore_domid;
xen_pfn_t shared_info_mfn;
xc_interface *xch;
@@ -200,6 +202,17 @@ void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
xen_pfn_t count);
int xc_dom_boot_image(struct xc_dom_image *dom);
int xc_dom_compat_check(struct xc_dom_image *dom);
+int xc_dom_gnttab_init(struct xc_dom_image *dom);
+int xc_dom_gnttab_hvm_seed(xc_interface *xch, uint32_t domid,
+ unsigned long console_gmfn,
+ unsigned long xenstore_gmfn,
+ uint32_t console_domid,
+ uint32_t xenstore_domid);
+int xc_dom_gnttab_seed(xc_interface *xch, uint32_t domid,
+ unsigned long console_gmfn,
+ unsigned long xenstore_gmfn,
+ uint32_t console_domid,
+ uint32_t xenstore_domid);
/* --- debugging bits ---------------------------------------------- */
diff --git a/tools/libxc/xc_dom_boot.c b/tools/libxc/xc_dom_boot.c
index 65f60df..1f139db 100644
--- a/tools/libxc/xc_dom_boot.c
+++ b/tools/libxc/xc_dom_boot.c
@@ -34,6 +34,7 @@
#include "xg_private.h"
#include "xc_dom.h"
#include <xen/hvm/params.h>
+#include <xen/grant_table.h>
/* ------------------------------------------------------------------------ */
@@ -275,6 +276,169 @@ int xc_dom_boot_image(struct xc_dom_image *dom)
return rc;
}
+static unsigned long xc_dom_gnttab_setup(xc_interface *xch, uint32_t domid)
+{
+ DECLARE_HYPERCALL;
+ gnttab_setup_table_t setup_table;
+ DECLARE_HYPERCALL_BUFFER(unsigned long, gmfnp);
+ int rc;
+ unsigned long gmfn;
+
+ gmfnp = xc_hypercall_buffer_alloc(xch, gmfnp, sizeof(*gmfnp));
+ if (gmfnp == NULL)
+ return -1;
+
+ setup_table.dom = domid;
+ setup_table.nr_frames = 1;
+ set_xen_guest_handle(setup_table.frame_list, gmfnp);
+ setup_table.status = 0;
+
+ hypercall.op = __HYPERVISOR_grant_table_op;
+ hypercall.arg[0] = GNTTABOP_setup_table;
+ hypercall.arg[1] = (unsigned long) &setup_table;
+ hypercall.arg[2] = 1;
+
+ rc = do_xen_hypercall(xch, &hypercall);
+ gmfn = *gmfnp;
+ xc_hypercall_buffer_free(xch, gmfnp);
+
+ if ( rc != 0 || setup_table.status != GNTST_okay )
+ {
+ xc_dom_panic(xch, XC_INTERNAL_ERROR,
+ "%s: failed to setup domU grant table "
+ "[errno=%d, status=%" PRId16 "]\n",
+ __FUNCTION__, rc != 0 ? errno : 0, setup_table.status);
+ return -1;
+ }
+
+ return gmfn;
+}
+
+int xc_dom_gnttab_seed(xc_interface *xch, uint32_t domid,
+ unsigned long console_gmfn,
+ unsigned long xenstore_gmfn,
+ uint32_t console_domid,
+ uint32_t xenstore_domid)
+{
+
+ unsigned long gnttab_gmfn;
+ grant_entry_v1_t *gnttab;
+
+ gnttab_gmfn = xc_dom_gnttab_setup(xch, domid);
+ if ( gnttab_gmfn == -1 )
+ return -1;
+
+ gnttab = xc_map_foreign_range(xch,
+ domid,
+ PAGE_SIZE,
+ PROT_READ|PROT_WRITE,
+ gnttab_gmfn);
+ if ( gnttab == NULL )
+ {
+ xc_dom_panic(xch, XC_INTERNAL_ERROR,
+ "%s: failed to map domU grant table "
+ "[errno=%d]\n",
+ __FUNCTION__, errno);
+ return -1;
+ }
+
+ if ( domid != console_domid && console_gmfn != -1)
+ {
+ gnttab[GNTTAB_RESERVED_CONSOLE].flags = GTF_permit_access;
+ gnttab[GNTTAB_RESERVED_CONSOLE].domid = console_domid;
+ gnttab[GNTTAB_RESERVED_CONSOLE].frame = console_gmfn;
+ }
+ if ( domid != xenstore_domid && xenstore_gmfn != -1)
+ {
+ gnttab[GNTTAB_RESERVED_XENSTORE].flags = GTF_permit_access;
+ gnttab[GNTTAB_RESERVED_XENSTORE].domid = xenstore_domid;
+ gnttab[GNTTAB_RESERVED_XENSTORE].frame = xenstore_gmfn;
+ }
+
+ if ( munmap(gnttab, PAGE_SIZE) == -1 )
+ {
+ xc_dom_panic(xch, XC_INTERNAL_ERROR,
+ "%s: failed to unmap domU grant table "
+ "[errno=%d]\n",
+ __FUNCTION__, errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+int xc_dom_gnttab_hvm_seed(xc_interface *xch, uint32_t domid,
+ unsigned long console_gpfn,
+ unsigned long xenstore_gpfn,
+ uint32_t console_domid,
+ uint32_t xenstore_domid)
+{
+#define SCRATCH_PFN_GNTTAB 0xFFFFE
+
+ int rc;
+ struct xen_add_to_physmap xatp = {
+ .domid = domid,
+ .space = XENMAPSPACE_grant_table,
+ .idx = 0, /* TODO: what's this? */
+ .gpfn = SCRATCH_PFN_GNTTAB
+ };
+ struct xen_remove_from_physmap xrfp = {
+ .domid = domid,
+ .gpfn = SCRATCH_PFN_GNTTAB
+ };
+
+ rc = do_memory_op(xch, XENMEM_add_to_physmap, &xatp, sizeof(xatp));
+ if ( rc != 0 )
+ {
+ xc_dom_panic(xch, XC_INTERNAL_ERROR,
+ "%s: failed to add gnttab to physmap "
+ "[errno=%d]\n",
+ __FUNCTION__, errno);
+ return -1;
+ }
+
+ rc = xc_dom_gnttab_seed(xch, domid,
+ console_gpfn, xenstore_gpfn,
+ console_domid, xenstore_domid);
+ if (rc != 0)
+ {
+ xc_dom_panic(xch, XC_INTERNAL_ERROR,
+ "%s: failed to seed gnttab entries\n",
+ __FUNCTION__);
+ (void) do_memory_op(xch, XENMEM_remove_from_physmap, &xrfp, sizeof(xrfp));
+ return -1;
+ }
+
+ rc = do_memory_op(xch, XENMEM_remove_from_physmap, &xrfp, sizeof(xrfp));
+ if (rc != 0)
+ {
+ xc_dom_panic(xch, XC_INTERNAL_ERROR,
+ "%s: failed to remove gnttab from physmap "
+ "[errno=%d]\n",
+ __FUNCTION__, errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+int xc_dom_gnttab_init(struct xc_dom_image *dom)
+{
+ unsigned long console_gmfn;
+ unsigned long xenstore_gmfn;
+ int autotranslated;
+
+ autotranslated = xc_dom_feature_translated(dom);
+ console_gmfn = autotranslated ?
+ dom->console_pfn : xc_dom_p2m_host(dom, dom->console_pfn);
+ xenstore_gmfn = autotranslated ?
+ dom->xenstore_pfn : xc_dom_p2m_host(dom, dom->xenstore_pfn);
+
+ return xc_dom_gnttab_seed(dom->xch, dom->guest_domid,
+ console_gmfn, xenstore_gmfn,
+ dom->console_domid, dom->xenstore_domid);
+}
+
/*
* Local variables:
* mode: C
diff --git a/tools/libxc/xc_dom_compat_linux.c b/tools/libxc/xc_dom_compat_linux.c
index 0e78842..2183a3b 100644
--- a/tools/libxc/xc_dom_compat_linux.c
+++ b/tools/libxc/xc_dom_compat_linux.c
@@ -62,6 +62,8 @@ static int xc_linux_build_internal(struct xc_dom_image *dom,
goto out;
if ( (rc = xc_dom_boot_image(dom)) != 0 )
goto out;
+ if ( (rc = xc_dom_gnttab_init(dom)) != 0)
+ goto out;
*console_mfn = xc_dom_p2m_host(dom, dom->console_pfn);
*store_mfn = xc_dom_p2m_host(dom, dom->xenstore_pfn);
diff --git a/tools/libxc/xc_domain_restore.c b/tools/libxc/xc_domain_restore.c
index 3fda6f8..8bee684 100644
--- a/tools/libxc/xc_domain_restore.c
+++ b/tools/libxc/xc_domain_restore.c
@@ -1259,7 +1259,8 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
unsigned int store_evtchn, unsigned long *store_mfn,
- unsigned int console_evtchn, unsigned long *console_mfn,
+ uint32_t store_domid, unsigned int console_evtchn,
+ unsigned long *console_mfn, uint32_t console_domid,
unsigned int hvm, unsigned int pae, int superpages,
int no_incr_generationid,
unsigned long *vm_generationid_addr)
@@ -2018,6 +2019,14 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
memcpy(ctx->live_p2m, ctx->p2m, dinfo->p2m_size * sizeof(xen_pfn_t));
munmap(ctx->live_p2m, P2M_FL_ENTRIES * PAGE_SIZE);
+ rc = xc_dom_gnttab_seed(xch, dom, *console_mfn, *store_mfn,
+ console_domid, store_domid);
+ if (rc != 0)
+ {
+ ERROR("error seeding grant table");
+ goto out;
+ }
+
DPRINTF("Domain ready to be built.\n");
rc = 0;
goto out;
@@ -2076,6 +2085,14 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
goto out;
}
+ rc = xc_dom_gnttab_hvm_seed(xch, dom, *console_mfn, *store_mfn,
+ console_domid, store_domid);
+ if (rc != 0)
+ {
+ ERROR("error seeding grant table");
+ goto out;
+ }
+
/* HVM success! */
rc = 0;
diff --git a/tools/libxc/xenguest.h b/tools/libxc/xenguest.h
index 6026370..3bd5549 100644
--- a/tools/libxc/xenguest.h
+++ b/tools/libxc/xenguest.h
@@ -79,7 +79,8 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
*/
int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
unsigned int store_evtchn, unsigned long *store_mfn,
- unsigned int console_evtchn, unsigned long *console_mfn,
+ uint32_t store_domid, unsigned int console_evtchn,
+ unsigned long *console_mfn, uint32_t console_domid,
unsigned int hvm, unsigned int pae, int superpages,
int no_incr_generationid,
unsigned long *vm_generationid_addr);
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 3828c62..28646e0 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -224,7 +224,9 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
dom->flags = flags;
dom->console_evtchn = state->console_port;
+ dom->console_domid = state->console_domid;
dom->xenstore_evtchn = state->store_port;
+ dom->xenstore_domid = state->store_domid;
if ( (ret = xc_dom_boot_xen_init(dom, ctx->xch, domid)) != 0 ) {
LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_boot_xen_init failed");
@@ -250,6 +252,10 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_boot_image failed");
goto out;
}
+ if ( (ret = xc_dom_gnttab_init(dom)) != 0 ) {
+ LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_gnttab_init failed");
+ goto out;
+ }
state->console_mfn = xc_dom_p2m_host(dom, dom->console_pfn);
state->store_mfn = xc_dom_p2m_host(dom, dom->xenstore_pfn);
@@ -263,7 +269,8 @@ out:
static int hvm_build_set_params(xc_interface *handle, uint32_t domid,
libxl_domain_build_info *info,
int store_evtchn, unsigned long *store_mfn,
- int console_evtchn, unsigned long *console_mfn)
+ int console_evtchn, unsigned long *console_mfn,
+ uint32_t store_domid, uint32_t console_domid)
{
struct hvm_info_table *va_hvm;
uint8_t *va_map, sum;
@@ -296,6 +303,8 @@ static int hvm_build_set_params(xc_interface *handle, uint32_t domid,
xc_set_hvm_param(handle, domid, HVM_PARAM_NESTEDHVM, info->u.hvm.nested_hvm);
xc_set_hvm_param(handle, domid, HVM_PARAM_STORE_EVTCHN, store_evtchn);
xc_set_hvm_param(handle, domid, HVM_PARAM_CONSOLE_EVTCHN, console_evtchn);
+
+ xc_dom_gnttab_hvm_seed(handle, domid, *console_mfn, *store_mfn, console_domid, store_domid);
return 0;
}
@@ -349,7 +358,9 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
goto out;
}
ret = hvm_build_set_params(ctx->xch, domid, info, state->store_port,
- &state->store_mfn, state->console_port, &state->console_mfn);
+ &state->store_mfn, state->console_port,
+ &state->console_mfn, state->store_domid,
+ state->console_domid);
if (ret) {
LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, ret, "hvm build set params failed");
goto out;
@@ -387,7 +398,8 @@ int libxl__domain_restore_common(libxl__gc *gc, uint32_t domid,
}
rc = xc_domain_restore(ctx->xch, fd, domid,
state->store_port, &state->store_mfn,
- state->console_port, &state->console_mfn,
+ state->store_domid, state->console_port,
+ &state->console_mfn, state->console_domid,
hvm, pae, superpages, no_incr_generationid,
&state->vm_generationid_addr);
if ( rc ) {
diff --git a/tools/xcutils/xc_restore.c b/tools/xcutils/xc_restore.c
index 63d53a8..e41a133 100644
--- a/tools/xcutils/xc_restore.c
+++ b/tools/xcutils/xc_restore.c
@@ -45,8 +45,8 @@ main(int argc, char **argv)
else
superpages = !!hvm;
- ret = xc_domain_restore(xch, io_fd, domid, store_evtchn, &store_mfn,
- console_evtchn, &console_mfn, hvm, pae, superpages,
+ ret = xc_domain_restore(xch, io_fd, domid, store_evtchn, &store_mfn, 0,
+ console_evtchn, &console_mfn, 0, hvm, pae, superpages,
0, NULL);
if ( ret == 0 )
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 07/21] lib{xc, xl}: Seed grant tables with xenstore and console grants
2012-01-20 20:47 ` [PATCH 07/21] lib{xc, xl}: Seed grant tables with xenstore and console grants Daniel De Graaf
@ 2012-01-23 12:26 ` Ian Campbell
0 siblings, 0 replies; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 12:26 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: Alex Zeffertt, xen-devel, Keir Fraser, Diego Ongaro
> @@ -275,6 +276,169 @@ int xc_dom_boot_image(struct xc_dom_image *dom)
> return rc;
> }
>
> +static unsigned long xc_dom_gnttab_setup(xc_interface *xch, uint32_t domid)
> +{
> + DECLARE_HYPERCALL;
> + gnttab_setup_table_t setup_table;
This memory needs to be a hypercall buffer. The easiest way to achieve
this would be to use xc_gnttab_op() which will bounce it for you.
> + DECLARE_HYPERCALL_BUFFER(unsigned long, gmfnp);
> + int rc;
> + unsigned long gmfn;
> +
> + gmfnp = xc_hypercall_buffer_alloc(xch, gmfnp, sizeof(*gmfnp));
> + if (gmfnp == NULL)
> + return -1;
> +
> + setup_table.dom = domid;
> + setup_table.nr_frames = 1;
> + set_xen_guest_handle(setup_table.frame_list, gmfnp);
> + setup_table.status = 0;
> +
> + hypercall.op = __HYPERVISOR_grant_table_op;
> + hypercall.arg[0] = GNTTABOP_setup_table;
> + hypercall.arg[1] = (unsigned long) &setup_table;
> + hypercall.arg[2] = 1;
> +
> + rc = do_xen_hypercall(xch, &hypercall);
> + gmfn = *gmfnp;
> + xc_hypercall_buffer_free(xch, gmfnp);
> +
> + if ( rc != 0 || setup_table.status != GNTST_okay )
> + {
> + xc_dom_panic(xch, XC_INTERNAL_ERROR,
> + "%s: failed to setup domU grant table "
> + "[errno=%d, status=%" PRId16 "]\n",
> + __FUNCTION__, rc != 0 ? errno : 0, setup_table.status);
> + return -1;
> + }
> +
> + return gmfn;
> +}
[...]
> +int xc_dom_gnttab_hvm_seed(xc_interface *xch, uint32_t domid,
> + unsigned long console_gpfn,
> + unsigned long xenstore_gpfn,
> + uint32_t console_domid,
> + uint32_t xenstore_domid)
> +{
> +#define SCRATCH_PFN_GNTTAB 0xFFFFE
Do we need to reserve this address? Even if not should we do so anyway?
Certainly I think hiding it away in this file is a bit too secret...
hvmloader reserves from hvm_info->reserved_mem_pgstart to the 4GB limit
in the guest's e820. reserved_mem_pgstart starts at special_pfn(0) and
is reduced by mem_alloc in hvmloader.
#define NR_SPECIAL_PAGES 5
#define special_pfn(x) (0xff000u - NR_SPECIAL_PAGES + (x))
So we end up reserving from 0xFEFFB000 to the end. So we are at least
hiding this address from the guest, so that's ok, but I think we need to
document this somewhere -- I'm just not sure where we can put it -- Keir
any ideas?
There's a list of SPECIALPAGE_* in xc_hvm_build but that's not exactly
the height of discoverable either.
> +
> + int rc;
> + struct xen_add_to_physmap xatp = {
> + .domid = domid,
> + .space = XENMAPSPACE_grant_table,
> + .idx = 0, /* TODO: what's this? */
"Index into source mapping space". Since you want the first page of the
grant table 0 seems to be correct.
Ian.
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH 08/21] mini-os: avoid crash if no console is provided
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (6 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 07/21] lib{xc, xl}: Seed grant tables with xenstore and console grants Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 09/21] mini-os: remove per-fd evtchn limit Daniel De Graaf
` (13 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
| 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
--git a/extras/mini-os/console/xencons_ring.c b/extras/mini-os/console/xencons_ring.c
index 22fd618..af0afed 100644
--- a/extras/mini-os/console/xencons_ring.c
+++ b/extras/mini-os/console/xencons_ring.c
@@ -25,7 +25,10 @@ static inline void notify_daemon(struct consfront_dev *dev)
static inline struct xencons_interface *xencons_interface(void)
{
- return mfn_to_virt(start_info.console.domU.mfn);
+ if (start_info.console.domU.evtchn)
+ return mfn_to_virt(start_info.console.domU.mfn);
+ else
+ return NULL;
}
int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len)
@@ -38,6 +41,8 @@ int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, uns
intf = xencons_interface();
else
intf = dev->ring;
+ if (!intf)
+ return sent;
cons = intf->out_cons;
prod = intf->out_prod;
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 09/21] mini-os: remove per-fd evtchn limit
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (7 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 08/21] mini-os: avoid crash if no console is provided Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 10/21] mini-os: create app-specific configuration Daniel De Graaf
` (12 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf, Alex Zeffertt, Diego Ongaro
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
This changes the minios evtchn implementation to use a list instead of
an array which ahis allows it to grow as necessary to support any number
of ports, only limited by Xen (NR_EVS is 1024, should be enough for now).
Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
| 16 +++---
tools/libxc/xc_minios.c | 139 ++++++++++++++++++++++--------------------
2 files changed, 81 insertions(+), 74 deletions(-)
--git a/extras/mini-os/include/lib.h b/extras/mini-os/include/lib.h
index bd3eeaf..12070c3 100644
--- a/extras/mini-os/include/lib.h
+++ b/extras/mini-os/include/lib.h
@@ -53,6 +53,7 @@
#include <xen/xen.h>
#include <xen/event_channel.h>
#include "gntmap.h"
+#include "list.h"
#ifdef HAVE_LIBC
#include <stdio.h>
@@ -143,7 +144,12 @@ enum fd_type {
FTYPE_SAVEFILE,
};
-#define MAX_EVTCHN_PORTS 16
+struct evtchn_port_info {
+ struct minios_list_head list;
+ evtchn_port_t port;
+ unsigned long pending;
+ int bound;
+};
extern struct file {
enum fd_type type;
@@ -158,13 +164,7 @@ extern struct file {
off_t offset;
} file;
struct {
- /* To each event channel FD is associated a series of ports which
- * wakes select for this FD. */
- struct {
- evtchn_port_t port;
- unsigned long pending;
- int bound;
- } ports[MAX_EVTCHN_PORTS];
+ struct minios_list_head ports;
} evtchn;
struct gntmap gntmap;
struct {
diff --git a/tools/libxc/xc_minios.c b/tools/libxc/xc_minios.c
index 8bbfd18..29cce63 100644
--- a/tools/libxc/xc_minios.c
+++ b/tools/libxc/xc_minios.c
@@ -210,15 +210,34 @@ static struct xc_osdep_ops minios_privcmd_ops = {
},
};
+
+/* XXX Note: This is not threadsafe */
+static struct evtchn_port_info* port_alloc(int fd) {
+ struct evtchn_port_info *port_info;
+ port_info = malloc(sizeof(struct evtchn_port_info));
+ if (port_info == NULL)
+ return NULL;
+ port_info->pending = 0;
+ port_info->port = -1;
+ port_info->bound = 0;
+
+ minios_list_add(&port_info->list, &files[fd].evtchn.ports);
+ return port_info;
+}
+
+static void port_dealloc(struct evtchn_port_info *port_info) {
+ if (port_info->bound)
+ unbind_evtchn(port_info->port);
+ minios_list_del(&port_info->list);
+ free(port_info);
+}
+
static xc_osdep_handle minios_evtchn_open(xc_evtchn *xce)
{
- int fd = alloc_fd(FTYPE_EVTCHN), i;
+ int fd = alloc_fd(FTYPE_EVTCHN);
if ( fd == -1 )
return XC_OSDEP_OPEN_ERROR;
- for (i = 0; i < MAX_EVTCHN_PORTS; i++) {
- files[fd].evtchn.ports[i].port = -1;
- files[fd].evtchn.ports[i].bound = 0;
- }
+ MINIOS_INIT_LIST_HEAD(&files[fd].evtchn.ports);
printf("evtchn_open() -> %d\n", fd);
return (xc_osdep_handle)fd;
}
@@ -231,10 +250,10 @@ static int minios_evtchn_close(xc_evtchn *xce, xc_osdep_handle h)
void minios_evtchn_close_fd(int fd)
{
- int i;
- for (i = 0; i < MAX_EVTCHN_PORTS; i++)
- if (files[fd].evtchn.ports[i].bound)
- unbind_evtchn(files[fd].evtchn.ports[i].port);
+ struct evtchn_port_info *port_info, *tmp;
+ minios_list_for_each_entry_safe(port_info, tmp, &files[fd].evtchn.ports, list)
+ port_dealloc(port_info);
+
files[fd].type = FTYPE_NONE;
}
@@ -256,35 +275,21 @@ static int minios_evtchn_notify(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t
return ret;
}
-/* XXX Note: This is not threadsafe */
-static int port_alloc(int fd) {
- int i;
- for (i= 0; i < MAX_EVTCHN_PORTS; i++)
- if (files[fd].evtchn.ports[i].port == -1)
- break;
- if (i == MAX_EVTCHN_PORTS) {
- printf("Too many ports in xc handle\n");
- errno = EMFILE;
- return -1;
- }
- files[fd].evtchn.ports[i].pending = 0;
- return i;
-}
-
static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
{
int fd = (int)(intptr_t)data;
- int i;
+ struct evtchn_port_info *port_info;
assert(files[fd].type == FTYPE_EVTCHN);
mask_evtchn(port);
- for (i= 0; i < MAX_EVTCHN_PORTS; i++)
- if (files[fd].evtchn.ports[i].port == port)
- break;
- if (i == MAX_EVTCHN_PORTS) {
- printk("Unknown port for handle %d\n", fd);
- return;
+ minios_list_for_each_entry(port_info, &files[fd].evtchn.ports, list) {
+ if (port_info->port == port)
+ goto found;
}
- files[fd].evtchn.ports[i].pending = 1;
+ printk("Unknown port for handle %d\n", fd);
+ return;
+
+ found:
+ port_info->pending = 1;
files[fd].read = 1;
wake_up(&event_queue);
}
@@ -292,12 +297,13 @@ static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
static evtchn_port_or_error_t minios_evtchn_bind_unbound_port(xc_evtchn *xce, xc_osdep_handle h, int domid)
{
int fd = (int)h;
- int ret, i;
+ struct evtchn_port_info *port_info;
+ int ret;
evtchn_port_t port;
assert(get_current() == main_thread);
- i = port_alloc(fd);
- if (i == -1)
+ port_info = port_alloc(fd);
+ if (port_info == NULL)
return -1;
printf("xc_evtchn_bind_unbound_port(%d)", domid);
@@ -305,11 +311,12 @@ static evtchn_port_or_error_t minios_evtchn_bind_unbound_port(xc_evtchn *xce, xc
printf(" = %d\n", ret);
if (ret < 0) {
+ port_dealloc(port_info);
errno = -ret;
return -1;
}
- files[fd].evtchn.ports[i].bound = 1;
- files[fd].evtchn.ports[i].port = port;
+ port_info->bound = 1;
+ port_info->port = port;
unmask_evtchn(port);
return port;
}
@@ -318,12 +325,13 @@ static evtchn_port_or_error_t minios_evtchn_bind_interdomain(xc_evtchn *xce, xc_
evtchn_port_t remote_port)
{
int fd = (int)h;
+ struct evtchn_port_info *port_info;
evtchn_port_t local_port;
- int ret, i;
+ int ret;
assert(get_current() == main_thread);
- i = port_alloc(fd);
- if (i == -1)
+ port_info = port_alloc(fd);
+ if (port_info == NULL)
return -1;
printf("xc_evtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port);
@@ -331,11 +339,12 @@ static evtchn_port_or_error_t minios_evtchn_bind_interdomain(xc_evtchn *xce, xc_
printf(" = %d\n", ret);
if (ret < 0) {
+ port_dealloc(port_info);
errno = -ret;
return -1;
}
- files[fd].evtchn.ports[i].bound = 1;
- files[fd].evtchn.ports[i].port = local_port;
+ port_info->bound = 1;
+ port_info->port = local_port;
unmask_evtchn(local_port);
return local_port;
}
@@ -343,42 +352,40 @@ static evtchn_port_or_error_t minios_evtchn_bind_interdomain(xc_evtchn *xce, xc_
static int minios_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port)
{
int fd = (int)h;
- int i;
- for (i = 0; i < MAX_EVTCHN_PORTS; i++)
- if (files[fd].evtchn.ports[i].port == port) {
- files[fd].evtchn.ports[i].port = -1;
- break;
- }
- if (i == MAX_EVTCHN_PORTS) {
- printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", port, fd);
- errno = -EINVAL;
- return -1;
+ struct evtchn_port_info *port_info;
+
+ minios_list_for_each_entry(port_info, &files[fd].evtchn.ports, list) {
+ if (port_info->port == port) {
+ port_dealloc(port_info);
+ return 0;
+ }
}
- files[fd].evtchn.ports[i].bound = 0;
- unbind_evtchn(port);
- return 0;
+ printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", port, fd);
+ errno = -EINVAL;
+ return -1;
}
static evtchn_port_or_error_t minios_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq)
{
int fd = (int)h;
+ struct evtchn_port_info *port_info;
evtchn_port_t port;
- int i;
assert(get_current() == main_thread);
- i = port_alloc(fd);
- if (i == -1)
+ port_info = port_alloc(fd);
+ if (port_info == NULL)
return -1;
printf("xc_evtchn_bind_virq(%d)", virq);
port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)fd);
if (port < 0) {
+ port_dealloc(port_info);
errno = -port;
return -1;
}
- files[fd].evtchn.ports[i].bound = 1;
- files[fd].evtchn.ports[i].port = port;
+ port_info->bound = 1;
+ port_info->port = port;
unmask_evtchn(port);
return port;
}
@@ -386,18 +393,18 @@ static evtchn_port_or_error_t minios_evtchn_bind_virq(xc_evtchn *xce, xc_osdep_h
static evtchn_port_or_error_t minios_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h)
{
int fd = (int)h;
- int i;
+ struct evtchn_port_info *port_info;
unsigned long flags;
evtchn_port_t ret = -1;
local_irq_save(flags);
files[fd].read = 0;
- for (i = 0; i < MAX_EVTCHN_PORTS; i++) {
- evtchn_port_t port = files[fd].evtchn.ports[i].port;
- if (port != -1 && files[fd].evtchn.ports[i].pending) {
+
+ minios_list_for_each_entry(port_info, &files[fd].evtchn.ports, list) {
+ if (port_info->port != -1 && port_info->pending) {
if (ret == -1) {
- ret = port;
- files[fd].evtchn.ports[i].pending = 0;
+ ret = port_info->port;
+ port_info->pending = 0;
} else {
files[fd].read = 1;
break;
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 10/21] mini-os: create app-specific configuration
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (8 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 09/21] mini-os: remove per-fd evtchn limit Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-23 12:41 ` Ian Campbell
2012-01-20 20:47 ` [PATCH 11/21] mini-os: make frontends and xenbus optional Daniel De Graaf
` (11 subsequent siblings)
21 siblings, 1 reply; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
Instead of using CONFIG_QEMU and CONFIG_GRUB to enable or disable minios
code, create CONFIG_ items for features and use application-specific
configuration files to enable or disable the features.
The configuration flags are currently added to the compiler command
line; as the number of flags grows this may need to move to a header.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
| 15 +++++++++------
| 11 +++++++++++
| 2 ++
| 1 +
| 28 ++++++++++++++++++++++++++++
extras/mini-os/main.c | 16 ++++++++--------
| 4 ++--
stubdom/Makefile | 8 ++++----
8 files changed, 65 insertions(+), 20 deletions(-)
create mode 100644 extras/mini-os/apps/common.mk
create mode 100644 extras/mini-os/apps/grub.mk
create mode 100644 extras/mini-os/apps/ioemu.mk
create mode 100644 extras/mini-os/files.mk
--git a/extras/mini-os/Makefile b/extras/mini-os/Makefile
index c2ee062..af7d0d4 100644
--- a/extras/mini-os/Makefile
+++ b/extras/mini-os/Makefile
@@ -8,7 +8,12 @@ export XEN_ROOT = $(CURDIR)/../..
include $(XEN_ROOT)/Config.mk
OBJ_DIR ?= $(CURDIR)
-ifneq ($(stubdom),y)
+ifeq ($(stubdom),y)
+-include apps/$(MINIOS_APP).mk
+include apps/common.mk
+EXTRA_DEPS += $(wildcard $(CURDIR)/apps/$(MINIOS_APP).mk)
+EXTRA_DEPS += $(CURDIR)/apps/common.mk
+else
include Config.mk
endif
@@ -34,13 +39,11 @@ TARGET := mini-os
# Subdirectories common to mini-os
SUBDIRS := lib xenbus console
+include files.mk
+
# The common mini-os objects to build.
APP_OBJS :=
-OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard *.c))
-OBJS += $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard lib/*.c))
-OBJS += $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard xenbus/*.c))
-OBJS += $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard console/*.c))
-
+OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(src-y))
.PHONY: default
default: $(OBJ_DIR)/$(TARGET)
--git a/extras/mini-os/apps/common.mk b/extras/mini-os/apps/common.mk
new file mode 100644
index 0000000..12b686d
--- /dev/null
+++ b/extras/mini-os/apps/common.mk
@@ -0,0 +1,11 @@
+# Defaults
+CONFIG_START_NETWORK ?= y
+CONFIG_SPARSE_BSS ?= y
+
+# Export items as compiler directives
+flags-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK
+flags-$(CONFIG_SPARSE_BSS) += -DCONFIG_SPARSE_BSS
+flags-$(CONFIG_QEMU_XS_ARGS) += -DCONFIG_QEMU_XS_ARGS
+
+DEF_CFLAGS += $(flags-y)
+
--git a/extras/mini-os/apps/grub.mk b/extras/mini-os/apps/grub.mk
new file mode 100644
index 0000000..40cfa68
--- /dev/null
+++ b/extras/mini-os/apps/grub.mk
@@ -0,0 +1,2 @@
+CONFIG_START_NETWORK=n
+CONFIG_SPARSE_BSS=n
--git a/extras/mini-os/apps/ioemu.mk b/extras/mini-os/apps/ioemu.mk
new file mode 100644
index 0000000..7ea1d2f
--- /dev/null
+++ b/extras/mini-os/apps/ioemu.mk
@@ -0,0 +1 @@
+CONFIG_QEMU_XS_ARGS=y
--git a/extras/mini-os/files.mk b/extras/mini-os/files.mk
new file mode 100644
index 0000000..5c1c6ef
--- /dev/null
+++ b/extras/mini-os/files.mk
@@ -0,0 +1,28 @@
+src-y += blkfront.c
+src-y += daytime.c
+src-y += events.c
+src-y += fbfront.c
+src-y += gntmap.c
+src-y += gnttab.c
+src-y += hypervisor.c
+src-y += kernel.c
+src-y += lock.c
+src-y += main.c
+src-y += mm.c
+src-y += netfront.c
+src-y += pcifront.c
+src-y += sched.c
+
+src-y += lib/ctype.c
+src-y += lib/math.c
+src-y += lib/printf.c
+src-y += lib/stack_chk_fail.c
+src-y += lib/string.c
+src-y += lib/sys.c
+src-y += lib/xmalloc.c
+src-y += lib/xs.c
+
+src-y += xenbus/xenbus.c
+
+src-y += console/console.c
+src-y += console/xencons_ring.c
diff --git a/extras/mini-os/main.c b/extras/mini-os/main.c
index b95b889..aeda548 100644
--- a/extras/mini-os/main.c
+++ b/extras/mini-os/main.c
@@ -43,13 +43,13 @@ extern char __app_bss_start, __app_bss_end;
static void call_main(void *p)
{
char *c, quote;
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QEMU_XS_ARGS
char *domargs, *msg;
#endif
int argc;
char **argv;
char *envp[] = { NULL };
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QEMU_XS_ARGS
char *vm;
char path[128];
int domid;
@@ -60,15 +60,15 @@ static void call_main(void *p)
* crashing. */
//sleep(1);
-#ifndef CONFIG_GRUB
+#ifdef CONFIG_SPARSE_BSS
sparse((unsigned long) &__app_bss_start, &__app_bss_end - &__app_bss_start);
-#if defined(HAVE_LWIP) && !defined(CONFIG_QEMU)
- start_networking();
#endif
+#if defined(HAVE_LWIP) && defined(CONFIG_START_NETWORK)
+ start_networking();
#endif
create_thread("pcifront", pcifront_watches, NULL);
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QEMU_XS_ARGS
/* Fetch argc, argv from XenStore */
domid = xenbus_read_integer("target");
if (domid == -1) {
@@ -132,7 +132,7 @@ static void call_main(void *p)
#define PARSE_ARGS_STORE(ARGS) PARSE_ARGS(ARGS, argv[argc++] = c, memmove(c, c + 1, strlen(c + 1) + 1), *c++ = 0)
PARSE_ARGS_COUNT((char*)start_info.cmd_line);
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QEMU_XS_ARGS
PARSE_ARGS_COUNT(domargs);
#endif
@@ -141,7 +141,7 @@ static void call_main(void *p)
argc = 1;
PARSE_ARGS_STORE((char*)start_info.cmd_line)
-#ifdef CONFIG_QEMU
+#ifdef CONFIG_QEMU_XS_ARGS
PARSE_ARGS_STORE(domargs)
#endif
--git a/extras/mini-os/minios.mk b/extras/mini-os/minios.mk
index 698648a..48ed768 100644
--- a/extras/mini-os/minios.mk
+++ b/extras/mini-os/minios.mk
@@ -39,8 +39,8 @@ LDFLAGS := $(DEF_LDFLAGS) $(ARCH_LDFLAGS)
# Special build dependencies.
# Rebuild all after touching this/these file(s)
-EXTRA_DEPS = $(MINI-OS_ROOT)/minios.mk \
- $(MINI-OS_ROOT)/$(TARGET_ARCH_DIR)/arch.mk
+EXTRA_DEPS += $(MINI-OS_ROOT)/minios.mk
+EXTRA_DEPS += $(MINI-OS_ROOT)/$(TARGET_ARCH_DIR)/arch.mk
# Find all header files for checking dependencies.
HDRS := $(wildcard $(MINI-OS_ROOT)/include/*.h)
diff --git a/stubdom/Makefile b/stubdom/Makefile
index 3705059..7989f31 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -341,19 +341,19 @@ grub: grub-upstream $(CROSS_ROOT)
.PHONY: ioemu-stubdom
ioemu-stubdom: APP_OBJS=$(CURDIR)/ioemu/i386-stubdom/qemu.a $(CURDIR)/ioemu/i386-stubdom/libqemu.a $(CURDIR)/ioemu/libqemu_common.a
ioemu-stubdom: mini-os-$(XEN_TARGET_ARCH)-ioemu lwip-$(XEN_TARGET_ARCH) libxc ioemu
- DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_QEMU $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(APP_OBJS)"
+ DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_APP=ioemu $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(APP_OBJS)"
.PHONY: caml-stubdom
caml-stubdom: mini-os-$(XEN_TARGET_ARCH)-caml lwip-$(XEN_TARGET_ARCH) libxc cross-ocaml caml
- DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_CAML $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(CURDIR)/caml/main-caml.o $(CURDIR)/caml/caml.o $(CAMLLIB)/libasmrun.a"
+ DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_APP=caml $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(CURDIR)/caml/main-caml.o $(CURDIR)/caml/caml.o $(CAMLLIB)/libasmrun.a"
.PHONY: c-stubdom
c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxc c
- DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_C $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS=$(CURDIR)/c/main.a
+ DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_APP=c $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS=$(CURDIR)/c/main.a
.PHONY: pv-grub
pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxc grub
- DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_GRUB $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub-$(XEN_TARGET_ARCH)/main.a
+ DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_APP=grub $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub-$(XEN_TARGET_ARCH)/main.a
#########
# install
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 10/21] mini-os: create app-specific configuration
2012-01-20 20:47 ` [PATCH 10/21] mini-os: create app-specific configuration Daniel De Graaf
@ 2012-01-23 12:41 ` Ian Campbell
2012-01-23 16:05 ` Daniel De Graaf
0 siblings, 1 reply; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 12:41 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: xen-devel
On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
> Instead of using CONFIG_QEMU and CONFIG_GRUB to enable or disable minios
> code, create CONFIG_ items for features and use application-specific
> configuration files to enable or disable the features.
>
> The configuration flags are currently added to the compiler command
> line; as the number of flags grows this may need to move to a header.
>
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> ---
> extras/mini-os/Makefile | 15 +++++++++------
> extras/mini-os/apps/common.mk | 11 +++++++++++
> extras/mini-os/apps/grub.mk | 2 ++
> extras/mini-os/apps/ioemu.mk | 1 +
I think these should go under stubdom/xxx. You can simply pass in
MINIOS_CONFIG as an absolute path and included it
ifneq($(MINIOS_CONFIG),) instead of the ifeq($(stubdom),y) change you
made.
> extras/mini-os/files.mk | 28 ++++++++++++++++++++++++++++
> extras/mini-os/main.c | 16 ++++++++--------
> extras/mini-os/minios.mk | 4 ++--
> stubdom/Makefile | 8 ++++----
> 8 files changed, 65 insertions(+), 20 deletions(-)
> create mode 100644 extras/mini-os/apps/common.mk
> create mode 100644 extras/mini-os/apps/grub.mk
> create mode 100644 extras/mini-os/apps/ioemu.mk
> create mode 100644 extras/mini-os/files.mk
>
> diff --git a/extras/mini-os/Makefile b/extras/mini-os/Makefile
> index c2ee062..af7d0d4 100644
> --- a/extras/mini-os/Makefile
> +++ b/extras/mini-os/Makefile
> @@ -8,7 +8,12 @@ export XEN_ROOT = $(CURDIR)/../..
> include $(XEN_ROOT)/Config.mk
> OBJ_DIR ?= $(CURDIR)
>
> -ifneq ($(stubdom),y)
> +ifeq ($(stubdom),y)
> +-include apps/$(MINIOS_APP).mk
If you do as I suggest above this can become an unconditional include.
> +include apps/common.mk
Probably the app-specific mk should include this if it wants it, or just
inline in each app config since I think the contents being common is
more a coincidence than anything else.
> +EXTRA_DEPS += $(wildcard $(CURDIR)/apps/$(MINIOS_APP).mk)
> +EXTRA_DEPS += $(CURDIR)/apps/common.mk
> +else
> include Config.mk
> endif
>
> @@ -34,13 +39,11 @@ TARGET := mini-os
> # Subdirectories common to mini-os
> SUBDIRS := lib xenbus console
>
> +include files.mk
I don't think moving this out of line is necessary, the pattern in moast
of our makefiles is to have the obj-(YN) stuff inline in the Makefiles.
> +
> # The common mini-os objects to build.
> APP_OBJS :=
> -OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard *.c))
> -OBJS += $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard lib/*.c))
> -OBJS += $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard xenbus/*.c))
> -OBJS += $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard console/*.c))
> -
> +OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(src-y))
>
> .PHONY: default
> default: $(OBJ_DIR)/$(TARGET)
> diff --git a/extras/mini-os/apps/common.mk b/extras/mini-os/apps/common.mk
> new file mode 100644
> index 0000000..12b686d
> --- /dev/null
> +++ b/extras/mini-os/apps/common.mk
> @@ -0,0 +1,11 @@
> +# Defaults
> +CONFIG_START_NETWORK ?= y
> +CONFIG_SPARSE_BSS ?= y
> +
> +# Export items as compiler directives
> +flags-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK
> +flags-$(CONFIG_SPARSE_BSS) += -DCONFIG_SPARSE_BSS
> +flags-$(CONFIG_QEMU_XS_ARGS) += -DCONFIG_QEMU_XS_ARGS
> +
> +DEF_CFLAGS += $(flags-y)
I'd be inclined to put the CFLAGS stuff in the main makefile. It's not
really "config" as such but part of the config system scaffolding.
[...]
> diff --git a/extras/mini-os/main.c b/extras/mini-os/main.c
> index b95b889..aeda548 100644
> --- a/extras/mini-os/main.c
> +++ b/extras/mini-os/main.c
> @@ -43,13 +43,13 @@ extern char __app_bss_start, __app_bss_end;
> static void call_main(void *p)
> {
> char *c, quote;
> -#ifdef CONFIG_QEMU
> +#ifdef CONFIG_QEMU_XS_ARGS
> char *domargs, *msg;
> #endif
> int argc;
> char **argv;
> char *envp[] = { NULL };
> -#ifdef CONFIG_QEMU
> +#ifdef CONFIG_QEMU_XS_ARGS
If you allow for the "%s/image/dmargs" (not shown in the patch context)
to come from a CONFIG_MUMBLE then this is no longer QEMU specific.
> char *vm;
> char path[128];
> int domid;
> @@ -60,15 +60,15 @@ static void call_main(void *p)
> * crashing. */
> //sleep(1);
>
> -#ifndef CONFIG_GRUB
> +#ifdef CONFIG_SPARSE_BSS
> sparse((unsigned long) &__app_bss_start, &__app_bss_end - &__app_bss_start);
> -#if defined(HAVE_LWIP) && !defined(CONFIG_QEMU)
> - start_networking();
> #endif
> +#if defined(HAVE_LWIP) && defined(CONFIG_START_NETWORK)
In grub.mk (which I've already trimmed, oops) you have
CONFIG_START_NETWORK=n
which will pass that half of the test, which isn't what I think you
wanted.
I've just noticed the same with the SPARSE_BSS option. Oh, and common.mk
actually ends up unconditionally setting some vars too (using ?=).
I think a Linux style "# CONFIG_FOO is not set" would be better if you
think it is necessary to explicitly list options we are not enabling.
Ian.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 10/21] mini-os: create app-specific configuration
2012-01-23 12:41 ` Ian Campbell
@ 2012-01-23 16:05 ` Daniel De Graaf
2012-01-23 16:23 ` Ian Campbell
0 siblings, 1 reply; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-23 16:05 UTC (permalink / raw)
To: Ian Campbell; +Cc: xen-devel
On 01/23/2012 07:41 AM, Ian Campbell wrote:
> On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
>> Instead of using CONFIG_QEMU and CONFIG_GRUB to enable or disable minios
>> code, create CONFIG_ items for features and use application-specific
>> configuration files to enable or disable the features.
>>
>> The configuration flags are currently added to the compiler command
>> line; as the number of flags grows this may need to move to a header.
>>
>> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
>> ---
>> extras/mini-os/Makefile | 15 +++++++++------
>> extras/mini-os/apps/common.mk | 11 +++++++++++
>> extras/mini-os/apps/grub.mk | 2 ++
>> extras/mini-os/apps/ioemu.mk | 1 +
>
> I think these should go under stubdom/xxx. You can simply pass in
> MINIOS_CONFIG as an absolute path and included it
> ifneq($(MINIOS_CONFIG),) instead of the ifeq($(stubdom),y) change you
> made.
>
That location also looks nicer, but it will make it more likely that some
config file will be missed if the defaults are updated. Shouldn't be too
much of a problem, though - we only have 5 stubdom configs at the moment.
>
>> extras/mini-os/files.mk | 28 ++++++++++++++++++++++++++++
>> extras/mini-os/main.c | 16 ++++++++--------
>> extras/mini-os/minios.mk | 4 ++--
>> stubdom/Makefile | 8 ++++----
>> 8 files changed, 65 insertions(+), 20 deletions(-)
>> create mode 100644 extras/mini-os/apps/common.mk
>> create mode 100644 extras/mini-os/apps/grub.mk
>> create mode 100644 extras/mini-os/apps/ioemu.mk
>> create mode 100644 extras/mini-os/files.mk
>>
>> diff --git a/extras/mini-os/Makefile b/extras/mini-os/Makefile
>> index c2ee062..af7d0d4 100644
>> --- a/extras/mini-os/Makefile
>> +++ b/extras/mini-os/Makefile
>> @@ -8,7 +8,12 @@ export XEN_ROOT = $(CURDIR)/../..
>> include $(XEN_ROOT)/Config.mk
>> OBJ_DIR ?= $(CURDIR)
>>
>> -ifneq ($(stubdom),y)
>> +ifeq ($(stubdom),y)
>> +-include apps/$(MINIOS_APP).mk
>
> If you do as I suggest above this can become an unconditional include.
>
>> +include apps/common.mk
>
> Probably the app-specific mk should include this if it wants it, or just
> inline in each app config since I think the contents being common is
> more a coincidence than anything else.
>
>> +EXTRA_DEPS += $(wildcard $(CURDIR)/apps/$(MINIOS_APP).mk)
>> +EXTRA_DEPS += $(CURDIR)/apps/common.mk
>> +else
>> include Config.mk
>> endif
>>
>> @@ -34,13 +39,11 @@ TARGET := mini-os
>> # Subdirectories common to mini-os
>> SUBDIRS := lib xenbus console
>>
>> +include files.mk
>
> I don't think moving this out of line is necessary, the pattern in moast
> of our makefiles is to have the obj-(YN) stuff inline in the Makefiles.
OK, I wasn't sure how this Makefile was intended split up (it has some logic
in minios.mk that seemed related).
>> +
>> # The common mini-os objects to build.
>> APP_OBJS :=
>> -OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard *.c))
>> -OBJS += $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard lib/*.c))
>> -OBJS += $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard xenbus/*.c))
>> -OBJS += $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard console/*.c))
>> -
>> +OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(src-y))
>>
>> .PHONY: default
>> default: $(OBJ_DIR)/$(TARGET)
>> diff --git a/extras/mini-os/apps/common.mk b/extras/mini-os/apps/common.mk
>> new file mode 100644
>> index 0000000..12b686d
>> --- /dev/null
>> +++ b/extras/mini-os/apps/common.mk
>> @@ -0,0 +1,11 @@
>> +# Defaults
>> +CONFIG_START_NETWORK ?= y
>> +CONFIG_SPARSE_BSS ?= y
>> +
>> +# Export items as compiler directives
>> +flags-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK
>> +flags-$(CONFIG_SPARSE_BSS) += -DCONFIG_SPARSE_BSS
>> +flags-$(CONFIG_QEMU_XS_ARGS) += -DCONFIG_QEMU_XS_ARGS
>> +
>> +DEF_CFLAGS += $(flags-y)
>
> I'd be inclined to put the CFLAGS stuff in the main makefile. It's not
> really "config" as such but part of the config system scaffolding.
Doing this would mostly eliminate common.mk - which sounds fine.
> [...]
>> diff --git a/extras/mini-os/main.c b/extras/mini-os/main.c
>> index b95b889..aeda548 100644
>> --- a/extras/mini-os/main.c
>> +++ b/extras/mini-os/main.c
>> @@ -43,13 +43,13 @@ extern char __app_bss_start, __app_bss_end;
>> static void call_main(void *p)
>> {
>> char *c, quote;
>> -#ifdef CONFIG_QEMU
>> +#ifdef CONFIG_QEMU_XS_ARGS
>> char *domargs, *msg;
>> #endif
>> int argc;
>> char **argv;
>> char *envp[] = { NULL };
>> -#ifdef CONFIG_QEMU
>> +#ifdef CONFIG_QEMU_XS_ARGS
>
> If you allow for the "%s/image/dmargs" (not shown in the patch context)
> to come from a CONFIG_MUMBLE then this is no longer QEMU specific.
It's still mostly ioemu-specific, since we start by looking up a target
domain ID, convert it to a VM path, and then look for a path under there.
Making only the final path of /vm/UUID/image/dmargs configurable doesn't
sound as useful for a general case, and making the intermediate steps
configurable would be a mess.
>> char *vm;
>> char path[128];
>> int domid;
>> @@ -60,15 +60,15 @@ static void call_main(void *p)
>> * crashing. */
>> //sleep(1);
>>
>> -#ifndef CONFIG_GRUB
>> +#ifdef CONFIG_SPARSE_BSS
>> sparse((unsigned long) &__app_bss_start, &__app_bss_end - &__app_bss_start);
>> -#if defined(HAVE_LWIP) && !defined(CONFIG_QEMU)
>> - start_networking();
>> #endif
>> +#if defined(HAVE_LWIP) && defined(CONFIG_START_NETWORK)
>
> In grub.mk (which I've already trimmed, oops) you have
> CONFIG_START_NETWORK=n
> which will pass that half of the test, which isn't what I think you
> wanted.
>
> I've just noticed the same with the SPARSE_BSS option. Oh, and common.mk
> actually ends up unconditionally setting some vars too (using ?=).
>
> I think a Linux style "# CONFIG_FOO is not set" would be better if you
> think it is necessary to explicitly list options we are not enabling.
>
> Ian.
Actually, =n will result in the C symbol being undefined; the Makefile symbol
can't be undefined or the ?= used to set defaults will override it.
The other way I thought of doing it is to discard the defaults and add them to
each stubdom's configuration, but this seemed more prone to getting out of sync
when adding new configuration items.
--
Daniel De Graaf
National Security Agency
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 10/21] mini-os: create app-specific configuration
2012-01-23 16:05 ` Daniel De Graaf
@ 2012-01-23 16:23 ` Ian Campbell
0 siblings, 0 replies; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 16:23 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: xen-devel
On Mon, 2012-01-23 at 16:05 +0000, Daniel De Graaf wrote:
> On 01/23/2012 07:41 AM, Ian Campbell wrote:
> > On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
> >> Instead of using CONFIG_QEMU and CONFIG_GRUB to enable or disable minios
> >> code, create CONFIG_ items for features and use application-specific
> >> configuration files to enable or disable the features.
> >>
> >> The configuration flags are currently added to the compiler command
> >> line; as the number of flags grows this may need to move to a header.
> >>
> >> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> >> ---
> >> extras/mini-os/Makefile | 15 +++++++++------
> >> extras/mini-os/apps/common.mk | 11 +++++++++++
> >> extras/mini-os/apps/grub.mk | 2 ++
> >> extras/mini-os/apps/ioemu.mk | 1 +
> >
> > I think these should go under stubdom/xxx. You can simply pass in
> > MINIOS_CONFIG as an absolute path and included it
> > ifneq($(MINIOS_CONFIG),) instead of the ifeq($(stubdom),y) change you
> > made.
> >
>
> That location also looks nicer, but it will make it more likely that some
> config file will be missed if the defaults are updated. Shouldn't be too
> much of a problem, though - we only have 5 stubdom configs at the moment.
Perhaps a comment directing people to look in stubdoms/... too?
> >> @@ -34,13 +39,11 @@ TARGET := mini-os
> >> # Subdirectories common to mini-os
> >> SUBDIRS := lib xenbus console
> >>
> >> +include files.mk
> >
> > I don't think moving this out of line is necessary, the pattern in moast
> > of our makefiles is to have the obj-(YN) stuff inline in the Makefiles.
>
> OK, I wasn't sure how this Makefile was intended split up (it has some logic
> in minios.mk that seemed related).
minios.mk looks like general rules for building bits of mini-os itself,
it's included from submakefiles too (we'd normally call that Rules.mk
these days).
> > [...]
> >> diff --git a/extras/mini-os/main.c b/extras/mini-os/main.c
> >> index b95b889..aeda548 100644
> >> --- a/extras/mini-os/main.c
> >> +++ b/extras/mini-os/main.c
> >> @@ -43,13 +43,13 @@ extern char __app_bss_start, __app_bss_end;
> >> static void call_main(void *p)
> >> {
> >> char *c, quote;
> >> -#ifdef CONFIG_QEMU
> >> +#ifdef CONFIG_QEMU_XS_ARGS
> >> char *domargs, *msg;
> >> #endif
> >> int argc;
> >> char **argv;
> >> char *envp[] = { NULL };
> >> -#ifdef CONFIG_QEMU
> >> +#ifdef CONFIG_QEMU_XS_ARGS
> >
> > If you allow for the "%s/image/dmargs" (not shown in the patch context)
> > to come from a CONFIG_MUMBLE then this is no longer QEMU specific.
>
> It's still mostly ioemu-specific, since we start by looking up a target
> domain ID, convert it to a VM path, and then look for a path under there.
> Making only the final path of /vm/UUID/image/dmargs configurable doesn't
> sound as useful for a general case, and making the intermediate steps
> configurable would be a mess.
Oh, I hadn't realised it was reading from the target VM and not the stub
VM -- as you say that does make it somewhat more convoluted.
Maybe just refactoring into a function of it's own would help. I was
going to suggest CONFIG_HAS_ARGS_PARSER surrounding a call to
parse_the_args which was supplied from under stubdoms but I don't see
anywhere convenient to put it.
[...]
> Actually, =n will result in the C symbol being undefined; the Makefile symbol
> can't be undefined or the ?= used to set defaults will override it.
Oh right, this is the CPP symbol not the make one which is done with
CFLAGS-$(XXX) += -D$(XXX) -- so that does indeed work.
> The other way I thought of doing it is to discard the defaults and add them to
> each stubdom's configuration, but this seemed more prone to getting out of sync
> when adding new configuration items.
Sure.
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH 11/21] mini-os: make frontends and xenbus optional
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (9 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 10/21] mini-os: create app-specific configuration Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-23 12:51 ` Ian Campbell
2012-01-23 13:29 ` Ian Campbell
2012-01-20 20:47 ` [PATCH 12/21] mini-os: fix list.h include guard name Daniel De Graaf
` (10 subsequent siblings)
21 siblings, 2 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
This adds compile-time logic to disable certain frontends in mini-os:
- pcifront is disabled by default, enabled for ioemu
- blkfront, netfront, fbfront, and kbdfront are enabled by default
- xenbus is required for any frontend, and is enabled by default
If all frontends and xenbus are disabled, mini-os will run without
needing to communicate with xenstore, making it suitable to run the
xenstore daemon.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
| 5 +++-
| 11 +++++++++
| 1 +
| 15 ++++++++++--
| 12 +++++-----
| 2 +
| 40 +++++++++++++++++++++++++++++++-
| 28 +++++++++++++++++++++++
extras/mini-os/main.c | 6 +++-
9 files changed, 106 insertions(+), 14 deletions(-)
--git a/extras/mini-os/Makefile b/extras/mini-os/Makefile
index af7d0d4..7419211 100644
--- a/extras/mini-os/Makefile
+++ b/extras/mini-os/Makefile
@@ -70,7 +70,10 @@ ifeq ($(lwip),y)
LWC := $(shell find $(LWIPDIR)/ -type f -name '*.c')
LWC := $(filter-out %6.c %ip6_addr.c %ethernetif.c, $(LWC))
LWO := $(patsubst %.c,%.o,$(LWC))
-LWO += $(addprefix $(OBJ_DIR)/,lwip-arch.o lwip-net.o)
+LWO += $(OBJ_DIR)/lwip-arch.o
+ifeq ($(CONFIG_NETFRONT),y)
+LWO += $(OBJ_DIR)/lwip-net.o
+endif
$(OBJ_DIR)/lwip.a: $(LWO)
$(RM) $@
--git a/extras/mini-os/apps/common.mk b/extras/mini-os/apps/common.mk
index 12b686d..1fd4c9f 100644
--- a/extras/mini-os/apps/common.mk
+++ b/extras/mini-os/apps/common.mk
@@ -1,11 +1,22 @@
# Defaults
CONFIG_START_NETWORK ?= y
CONFIG_SPARSE_BSS ?= y
+CONFIG_BLKFRONT ?= y
+CONFIG_NETFRONT ?= y
+CONFIG_FBFRONT ?= y
+CONFIG_KBDFRONT ?= y
+CONFIG_XENBUS ?= y
# Export items as compiler directives
flags-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK
flags-$(CONFIG_SPARSE_BSS) += -DCONFIG_SPARSE_BSS
flags-$(CONFIG_QEMU_XS_ARGS) += -DCONFIG_QEMU_XS_ARGS
+flags-$(CONFIG_PCIFRONT) += -DCONFIG_PCIFRONT
+flags-$(CONFIG_BLKFRONT) += -DCONFIG_BLKFRONT
+flags-$(CONFIG_NETFRONT) += -DCONFIG_NETFRONT
+flags-$(CONFIG_KBDFRONT) += -DCONFIG_KBDFRONT
+flags-$(CONFIG_FBFRONT) += -DCONFIG_FBFRONT
+flags-$(CONFIG_XENBUS) += -DCONFIG_XENBUS
DEF_CFLAGS += $(flags-y)
--git a/extras/mini-os/apps/ioemu.mk b/extras/mini-os/apps/ioemu.mk
index 7ea1d2f..e3a96da 100644
--- a/extras/mini-os/apps/ioemu.mk
+++ b/extras/mini-os/apps/ioemu.mk
@@ -1 +1,2 @@
CONFIG_QEMU_XS_ARGS=y
+CONFIG_PCIFRONT=y
--git a/extras/mini-os/console/xencons_ring.c b/extras/mini-os/console/xencons_ring.c
index af0afed..c3eba35 100644
--- a/extras/mini-os/console/xencons_ring.c
+++ b/extras/mini-os/console/xencons_ring.c
@@ -189,6 +189,7 @@ struct consfront_dev *xencons_ring_init(void)
void free_consfront(struct consfront_dev *dev)
{
+#ifdef CONFIG_XENBUS
char* err = NULL;
XenbusState state;
@@ -217,6 +218,7 @@ void free_consfront(struct consfront_dev *dev)
close:
if (err) free(err);
xenbus_unwatch_path_token(XBT_NIL, path, path);
+#endif
mask_evtchn(dev->evtchn);
unbind_evtchn(dev->evtchn);
@@ -231,16 +233,18 @@ close:
struct consfront_dev *init_consfront(char *_nodename)
{
+ struct consfront_dev *dev;
+ char nodename[256];
+ static int consfrontends = 3;
+#ifdef CONFIG_XENBUS
xenbus_transaction_t xbt;
char* err;
char* message=NULL;
int retry=0;
char* msg = NULL;
- char nodename[256];
char path[256];
- static int consfrontends = 3;
- struct consfront_dev *dev;
int res;
+#endif
if (!_nodename)
snprintf(nodename, sizeof(nodename), "device/console/%d", consfrontends);
@@ -257,6 +261,7 @@ struct consfront_dev *init_consfront(char *_nodename)
dev->fd = -1;
#endif
+#ifdef CONFIG_XENBUS
snprintf(path, sizeof(path), "%s/backend-id", nodename);
if ((res = xenbus_read_integer(path)) < 0)
return NULL;
@@ -351,17 +356,21 @@ done:
goto error;
}
}
+#endif
+
unmask_evtchn(dev->evtchn);
printk("**************************\n");
return dev;
+#ifdef CONFIG_XENBUS
error:
free(msg);
free(err);
free_consfront(dev);
return NULL;
+#endif
}
void xencons_resume(void)
--git a/extras/mini-os/files.mk b/extras/mini-os/files.mk
index 5c1c6ef..be37a8b 100644
--- a/extras/mini-os/files.mk
+++ b/extras/mini-os/files.mk
@@ -1,7 +1,7 @@
-src-y += blkfront.c
+src-$(CONFIG_BLKFRONT) += blkfront.c
src-y += daytime.c
src-y += events.c
-src-y += fbfront.c
+src-$(CONFIG_FBFRONT) += fbfront.c
src-y += gntmap.c
src-y += gnttab.c
src-y += hypervisor.c
@@ -9,8 +9,8 @@ src-y += kernel.c
src-y += lock.c
src-y += main.c
src-y += mm.c
-src-y += netfront.c
-src-y += pcifront.c
+src-$(CONFIG_NETFRONT) += netfront.c
+src-$(CONFIG_PCIFRONT) += pcifront.c
src-y += sched.c
src-y += lib/ctype.c
@@ -20,9 +20,9 @@ src-y += lib/stack_chk_fail.c
src-y += lib/string.c
src-y += lib/sys.c
src-y += lib/xmalloc.c
-src-y += lib/xs.c
+src-$(CONFIG_XENBUS) += lib/xs.c
-src-y += xenbus/xenbus.c
+src-$(CONFIG_XENBUS) += xenbus/xenbus.c
src-y += console/console.c
src-y += console/xencons_ring.c
--git a/extras/mini-os/include/lib.h b/extras/mini-os/include/lib.h
index 12070c3..9c69440 100644
--- a/extras/mini-os/include/lib.h
+++ b/extras/mini-os/include/lib.h
@@ -182,11 +182,13 @@ extern struct file {
struct {
struct consfront_dev *dev;
} cons;
+#ifdef CONFIG_XENBUS
struct {
/* To each xenbus FD is associated a queue of watch events for this
* FD. */
xenbus_event_queue events;
} xenbus;
+#endif
};
int read; /* maybe available for read */
} files[];
--git a/extras/mini-os/kernel.c b/extras/mini-os/kernel.c
index 2875bf1..9e490d5 100644
--- a/extras/mini-os/kernel.c
+++ b/extras/mini-os/kernel.c
@@ -46,8 +46,6 @@
#include <xen/features.h>
#include <xen/version.h>
-static struct netfront_dev *net_dev;
-
uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32];
void setup_xen_features(void)
@@ -86,11 +84,16 @@ static void periodic_thread(void *p)
}
}
+#ifdef CONFIG_NETFRONT
+static struct netfront_dev *net_dev;
+
static void netfront_thread(void *p)
{
net_dev = init_netfront(NULL, NULL, NULL, NULL);
}
+#endif
+#ifdef CONFIG_BLKFRONT
static struct blkfront_dev *blk_dev;
static struct blkfront_info blk_info;
static uint64_t blk_size_read;
@@ -255,6 +258,9 @@ static void blkfront_thread(void *p)
#endif
}
}
+#endif
+
+#ifdef CONFIG_FBFRONT
#define WIDTH 800
#define HEIGHT 600
@@ -347,6 +353,9 @@ static void refresh_cursor(int new_x, int new_y)
fbfront_drawhoriz(new_x + 1, new_x + 8, new_y, 0xffffffff);
fbfront_update(fb_dev, new_x, new_y, 9, 9);
}
+#endif
+
+#ifdef CONFIG_KBDFRONT
static struct kbdfront_dev *kbd_dev;
static void kbdfront_thread(void *p)
@@ -431,7 +440,9 @@ static void kbdfront_thread(void *p)
schedule();
}
}
+#endif
+#ifdef CONFIG_PCIFRONT
static struct pcifront_dev *pci_dev;
static void print_pcidev(unsigned int domain, unsigned int bus, unsigned int slot, unsigned int fun)
@@ -455,6 +466,7 @@ static void pcifront_thread(void *p)
printk("PCI devices:\n");
pcifront_scan(pci_dev, print_pcidev);
}
+#endif
/* This should be overridden by the application we are linked against. */
__attribute__((weak)) int app_main(start_info_t *si)
@@ -462,11 +474,21 @@ __attribute__((weak)) int app_main(start_info_t *si)
printk("Dummy main: start_info=%p\n", si);
create_thread("xenbus_tester", xenbus_tester, si);
create_thread("periodic_thread", periodic_thread, si);
+#ifdef CONFIG_NETFRONT
create_thread("netfront", netfront_thread, si);
+#endif
+#ifdef CONFIG_BLKFRONT
create_thread("blkfront", blkfront_thread, si);
+#endif
+#ifdef CONFIG_FBFRONT
create_thread("fbfront", fbfront_thread, si);
+#endif
+#ifdef CONFIG_KBDFRONT
create_thread("kbdfront", kbdfront_thread, si);
+#endif
+#ifdef CONFIG_PCIFRONT
create_thread("pcifront", pcifront_thread, si);
+#endif
return 0;
}
@@ -522,8 +544,10 @@ void start_kernel(start_info_t *si)
/* Init scheduler. */
init_sched();
+#ifdef CONFIG_XENBUS
/* Init XenBus */
init_xenbus();
+#endif
/* Call (possibly overridden) app_main() */
app_main(&start_info);
@@ -534,20 +558,30 @@ void start_kernel(start_info_t *si)
void stop_kernel(void)
{
+#ifdef CONFIG_NETFRONT
if (net_dev)
shutdown_netfront(net_dev);
+#endif
+#ifdef CONFIG_BLKFRONT
if (blk_dev)
shutdown_blkfront(blk_dev);
+#endif
+#ifdef CONFIG_FBFRONT
if (fb_dev)
shutdown_fbfront(fb_dev);
+#endif
+#ifdef CONFIG_KBDFRONT
if (kbd_dev)
shutdown_kbdfront(kbd_dev);
+#endif
+#ifdef CONFIG_PCIFRONT
if (pci_dev)
shutdown_pcifront(pci_dev);
+#endif
/* TODO: fs import */
@@ -560,8 +594,10 @@ void stop_kernel(void)
fini_console(NULL);
/* TODO: record new ring mfn & event in start_info */
+#ifdef CONFIG_XENBUS
/* Reset XenBus */
fini_xenbus();
+#endif
/* Reset timers */
fini_time();
--git a/extras/mini-os/lib/sys.c b/extras/mini-os/lib/sys.c
index b7b3aff..14e7780 100644
--- a/extras/mini-os/lib/sys.c
+++ b/extras/mini-os/lib/sys.c
@@ -241,6 +241,7 @@ int read(int fd, void *buf, size_t nbytes)
case FTYPE_SOCKET:
return lwip_read(files[fd].socket.fd, buf, nbytes);
#endif
+#ifdef CONFIG_NETFRONT
case FTYPE_TAP: {
ssize_t ret;
ret = netfront_receive(files[fd].tap.dev, buf, nbytes);
@@ -250,6 +251,8 @@ int read(int fd, void *buf, size_t nbytes)
}
return ret;
}
+#endif
+#ifdef CONFIG_KBDFRONT
case FTYPE_KBD: {
int ret, n;
n = nbytes / sizeof(union xenkbd_in_event);
@@ -260,6 +263,8 @@ int read(int fd, void *buf, size_t nbytes)
}
return ret * sizeof(union xenkbd_in_event);
}
+#endif
+#ifdef CONFIG_FBFRONT
case FTYPE_FB: {
int ret, n;
n = nbytes / sizeof(union xenfb_in_event);
@@ -270,6 +275,7 @@ int read(int fd, void *buf, size_t nbytes)
}
return ret * sizeof(union xenfb_in_event);
}
+#endif
default:
break;
}
@@ -297,9 +303,11 @@ int write(int fd, const void *buf, size_t nbytes)
case FTYPE_SOCKET:
return lwip_write(files[fd].socket.fd, (void*) buf, nbytes);
#endif
+#ifdef CONFIG_NETFRONT
case FTYPE_TAP:
netfront_xmit(files[fd].tap.dev, (void*) buf, nbytes);
return nbytes;
+#endif
default:
break;
}
@@ -326,9 +334,11 @@ int close(int fd)
default:
files[fd].type = FTYPE_NONE;
return 0;
+#ifdef CONFIG_XENBUS
case FTYPE_XENBUS:
xs_daemon_close((void*)(intptr_t) fd);
return 0;
+#endif
#ifdef HAVE_LWIP
case FTYPE_SOCKET: {
int res = lwip_close(files[fd].socket.fd);
@@ -345,22 +355,30 @@ int close(int fd)
case FTYPE_GNTMAP:
minios_gnttab_close_fd(fd);
return 0;
+#ifdef CONFIG_NETFRONT
case FTYPE_TAP:
shutdown_netfront(files[fd].tap.dev);
files[fd].type = FTYPE_NONE;
return 0;
+#endif
+#ifdef CONFIG_BLKFRONT
case FTYPE_BLK:
shutdown_blkfront(files[fd].blk.dev);
files[fd].type = FTYPE_NONE;
return 0;
+#endif
+#ifdef CONFIG_KBDFRONT
case FTYPE_KBD:
shutdown_kbdfront(files[fd].kbd.dev);
files[fd].type = FTYPE_NONE;
return 0;
+#endif
+#ifdef CONFIG_FBFRONT
case FTYPE_FB:
shutdown_fbfront(files[fd].fb.dev);
files[fd].type = FTYPE_NONE;
return 0;
+#endif
case FTYPE_SAVEFILE:
case FTYPE_CONSOLE:
fini_console(files[fd].cons.dev);
@@ -611,6 +629,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exce
n++;
FD_CLR(i, exceptfds);
break;
+#ifdef CONFIG_XENBUS
case FTYPE_XENBUS:
if (FD_ISSET(i, readfds)) {
if (files[i].xenbus.events)
@@ -621,6 +640,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exce
FD_CLR(i, writefds);
FD_CLR(i, exceptfds);
break;
+#endif
case FTYPE_EVTCHN:
case FTYPE_TAP:
case FTYPE_BLK:
@@ -727,11 +747,19 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
/* Tell people we're going to sleep before looking at what they are
* saying, hence letting them wake us if events happen between here and
* schedule() */
+#ifdef CONFIG_NETFRONT
add_waiter(w1, netfront_queue);
+#endif
add_waiter(w2, event_queue);
+#ifdef CONFIG_BLKFRONT
add_waiter(w3, blkfront_queue);
+#endif
+#ifdef CONFIG_XENBUS
add_waiter(w4, xenbus_watch_queue);
+#endif
+#ifdef CONFIG_KBDFRONT
add_waiter(w5, kbdfront_queue);
+#endif
add_waiter(w6, console_queue);
if (readfds)
diff --git a/extras/mini-os/main.c b/extras/mini-os/main.c
index aeda548..73eb6fb 100644
--- a/extras/mini-os/main.c
+++ b/extras/mini-os/main.c
@@ -63,10 +63,12 @@ static void call_main(void *p)
#ifdef CONFIG_SPARSE_BSS
sparse((unsigned long) &__app_bss_start, &__app_bss_end - &__app_bss_start);
#endif
-#if defined(HAVE_LWIP) && defined(CONFIG_START_NETWORK)
+#if defined(HAVE_LWIP) && defined(CONFIG_START_NETWORK) && defined(CONFIG_NETFRONT)
start_networking();
#endif
+#ifdef CONFIG_PCIFRONT
create_thread("pcifront", pcifront_watches, NULL);
+#endif
#ifdef CONFIG_QEMU_XS_ARGS
/* Fetch argc, argv from XenStore */
@@ -169,7 +171,7 @@ void _exit(int ret)
close_all_files();
__libc_fini_array();
printk("main returned %d\n", ret);
-#ifdef HAVE_LWIP
+#if defined(HAVE_LWIP) && defined(CONFIG_NETFRONT)
stop_networking();
#endif
stop_kernel();
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 11/21] mini-os: make frontends and xenbus optional
2012-01-20 20:47 ` [PATCH 11/21] mini-os: make frontends and xenbus optional Daniel De Graaf
@ 2012-01-23 12:51 ` Ian Campbell
2012-01-23 16:21 ` Daniel De Graaf
2012-01-23 13:29 ` Ian Campbell
1 sibling, 1 reply; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 12:51 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: xen-devel
On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
> This adds compile-time logic to disable certain frontends in mini-os:
> - pcifront is disabled by default, enabled for ioemu
> - blkfront, netfront, fbfront, and kbdfront are enabled by default
> - xenbus is required for any frontend, and is enabled by default
>
> If all frontends and xenbus are disabled, mini-os will run without
> needing to communicate with xenstore, making it suitable to run the
> xenstore daemon.
>
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> ---
> extras/mini-os/Makefile | 5 +++-
> extras/mini-os/apps/common.mk | 11 +++++++++
> extras/mini-os/apps/ioemu.mk | 1 +
> extras/mini-os/console/xencons_ring.c | 15 ++++++++++--
> extras/mini-os/files.mk | 12 +++++-----
> extras/mini-os/include/lib.h | 2 +
> extras/mini-os/kernel.c | 40 +++++++++++++++++++++++++++++++-
> extras/mini-os/lib/sys.c | 28 +++++++++++++++++++++++
> extras/mini-os/main.c | 6 +++-
> 9 files changed, 106 insertions(+), 14 deletions(-)
>
> diff --git a/extras/mini-os/Makefile b/extras/mini-os/Makefile
> index af7d0d4..7419211 100644
> --- a/extras/mini-os/Makefile
> +++ b/extras/mini-os/Makefile
> @@ -70,7 +70,10 @@ ifeq ($(lwip),y)
> LWC := $(shell find $(LWIPDIR)/ -type f -name '*.c')
> LWC := $(filter-out %6.c %ip6_addr.c %ethernetif.c, $(LWC))
> LWO := $(patsubst %.c,%.o,$(LWC))
> -LWO += $(addprefix $(OBJ_DIR)/,lwip-arch.o lwip-net.o)
> +LWO += $(OBJ_DIR)/lwip-arch.o
> +ifeq ($(CONFIG_NETFRONT),y)
> +LWO += $(OBJ_DIR)/lwip-net.o
> +endif
Without lwip-net.o is there any point in having the rest of LWO? Or does
the linker optimise it all away anyway?
[...]
> diff --git a/extras/mini-os/console/xencons_ring.c b/extras/mini-os/console/xencons_ring.c
> index af0afed..c3eba35 100644
> --- a/extras/mini-os/console/xencons_ring.c
> +++ b/extras/mini-os/console/xencons_ring.c
> @@ -189,6 +189,7 @@ struct consfront_dev *xencons_ring_init(void)
>
> void free_consfront(struct consfront_dev *dev)
> {
> +#ifdef CONFIG_XENBUS
> char* err = NULL;
> XenbusState state;
>
> @@ -217,6 +218,7 @@ void free_consfront(struct consfront_dev *dev)
> close:
> if (err) free(err);
> xenbus_unwatch_path_token(XBT_NIL, path, path);
> +#endif
>
> mask_evtchn(dev->evtchn);
> unbind_evtchn(dev->evtchn);
> @@ -231,16 +233,18 @@ close:
>
> struct consfront_dev *init_consfront(char *_nodename)
> {
> + struct consfront_dev *dev;
> + char nodename[256];
> + static int consfrontends = 3;
> +#ifdef CONFIG_XENBUS
> xenbus_transaction_t xbt;
> char* err;
> char* message=NULL;
> int retry=0;
> char* msg = NULL;
> - char nodename[256];
> char path[256];
> - static int consfrontends = 3;
> - struct consfront_dev *dev;
> int res;
> +#endif
>
> if (!_nodename)
> snprintf(nodename, sizeof(nodename), "device/console/%d", consfrontends);
> @@ -257,6 +261,7 @@ struct consfront_dev *init_consfront(char *_nodename)
> dev->fd = -1;
> #endif
>
> +#ifdef CONFIG_XENBUS
> snprintf(path, sizeof(path), "%s/backend-id", nodename);
> if ((res = xenbus_read_integer(path)) < 0)
> return NULL;
> @@ -351,17 +356,21 @@ done:
> goto error;
> }
> }
> +#endif
Haven't you ifdef'd out everything which would have set dev->evtchn?
I'm not sure that the CONFIG_XENBUS is worthwhile, at least at the
moment, and it seems to add an awful lot of ifdefery.
[...]
> diff --git a/extras/mini-os/kernel.c b/extras/mini-os/kernel.c
> index 2875bf1..9e490d5 100644
> --- a/extras/mini-os/kernel.c
> +++ b/extras/mini-os/kernel.c
> [...]
> @@ -462,11 +474,21 @@ __attribute__((weak)) int app_main(start_info_t *si)
> printk("Dummy main: start_info=%p\n", si);
> create_thread("xenbus_tester", xenbus_tester, si);
> create_thread("periodic_thread", periodic_thread, si);
> +#ifdef CONFIG_NETFRONT
> create_thread("netfront", netfront_thread, si);
> +#endif
Better to define init_FOOfront for each of these and have it be a nop in
the ifndef case and avoid the ifdefs in the code itself.
Likewise the ifdef's in the teardown. Ideally the actual meat in the
ifdef cases would be moved into the files you aren't compiling (e.g.
netfront_thread goes into netfront.c) and only the stubs remain in some
header somewhere.
Ian.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 11/21] mini-os: make frontends and xenbus optional
2012-01-23 12:51 ` Ian Campbell
@ 2012-01-23 16:21 ` Daniel De Graaf
2012-01-23 16:24 ` Ian Campbell
0 siblings, 1 reply; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-23 16:21 UTC (permalink / raw)
To: Ian Campbell; +Cc: xen-devel
On 01/23/2012 07:51 AM, Ian Campbell wrote:
> On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
>> This adds compile-time logic to disable certain frontends in mini-os:
>> - pcifront is disabled by default, enabled for ioemu
>> - blkfront, netfront, fbfront, and kbdfront are enabled by default
>> - xenbus is required for any frontend, and is enabled by default
>>
>> If all frontends and xenbus are disabled, mini-os will run without
>> needing to communicate with xenstore, making it suitable to run the
>> xenstore daemon.
>>
>> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
>> ---
>> extras/mini-os/Makefile | 5 +++-
>> extras/mini-os/apps/common.mk | 11 +++++++++
>> extras/mini-os/apps/ioemu.mk | 1 +
>> extras/mini-os/console/xencons_ring.c | 15 ++++++++++--
>> extras/mini-os/files.mk | 12 +++++-----
>> extras/mini-os/include/lib.h | 2 +
>> extras/mini-os/kernel.c | 40 +++++++++++++++++++++++++++++++-
>> extras/mini-os/lib/sys.c | 28 +++++++++++++++++++++++
>> extras/mini-os/main.c | 6 +++-
>> 9 files changed, 106 insertions(+), 14 deletions(-)
>>
>> diff --git a/extras/mini-os/Makefile b/extras/mini-os/Makefile
>> index af7d0d4..7419211 100644
>> --- a/extras/mini-os/Makefile
>> +++ b/extras/mini-os/Makefile
>> @@ -70,7 +70,10 @@ ifeq ($(lwip),y)
>> LWC := $(shell find $(LWIPDIR)/ -type f -name '*.c')
>> LWC := $(filter-out %6.c %ip6_addr.c %ethernetif.c, $(LWC))
>> LWO := $(patsubst %.c,%.o,$(LWC))
>> -LWO += $(addprefix $(OBJ_DIR)/,lwip-arch.o lwip-net.o)
>> +LWO += $(OBJ_DIR)/lwip-arch.o
>> +ifeq ($(CONFIG_NETFRONT),y)
>> +LWO += $(OBJ_DIR)/lwip-net.o
>> +endif
>
> Without lwip-net.o is there any point in having the rest of LWO? Or does
> the linker optimise it all away anyway?
>
Some of the other parts of LWO may be useful on their own, depending on the
application run under minios. The xenstored configuration disables all of
LWO, so this doesn't matter there; the vTPM stub domains (from patches sent
by Matthew Fioravante in March 2011) do use parts of LWO without needing
netfront support, which prompted this configuration test.
> [...]
>
>> diff --git a/extras/mini-os/console/xencons_ring.c b/extras/mini-os/console/xencons_ring.c
>> index af0afed..c3eba35 100644
>> --- a/extras/mini-os/console/xencons_ring.c
>> +++ b/extras/mini-os/console/xencons_ring.c
>> @@ -189,6 +189,7 @@ struct consfront_dev *xencons_ring_init(void)
>>
>> void free_consfront(struct consfront_dev *dev)
>> {
>> +#ifdef CONFIG_XENBUS
>> char* err = NULL;
>> XenbusState state;
>>
>> @@ -217,6 +218,7 @@ void free_consfront(struct consfront_dev *dev)
>> close:
>> if (err) free(err);
>> xenbus_unwatch_path_token(XBT_NIL, path, path);
>> +#endif
>>
>> mask_evtchn(dev->evtchn);
>> unbind_evtchn(dev->evtchn);
>> @@ -231,16 +233,18 @@ close:
>>
>> struct consfront_dev *init_consfront(char *_nodename)
>> {
>> + struct consfront_dev *dev;
>> + char nodename[256];
>> + static int consfrontends = 3;
>> +#ifdef CONFIG_XENBUS
>> xenbus_transaction_t xbt;
>> char* err;
>> char* message=NULL;
>> int retry=0;
>> char* msg = NULL;
>> - char nodename[256];
>> char path[256];
>> - static int consfrontends = 3;
>> - struct consfront_dev *dev;
>> int res;
>> +#endif
>>
>> if (!_nodename)
>> snprintf(nodename, sizeof(nodename), "device/console/%d", consfrontends);
>> @@ -257,6 +261,7 @@ struct consfront_dev *init_consfront(char *_nodename)
>> dev->fd = -1;
>> #endif
>>
>> +#ifdef CONFIG_XENBUS
>> snprintf(path, sizeof(path), "%s/backend-id", nodename);
>> if ((res = xenbus_read_integer(path)) < 0)
>> return NULL;
>> @@ -351,17 +356,21 @@ done:
>> goto error;
>> }
>> }
>> +#endif
>
> Haven't you ifdef'd out everything which would have set dev->evtchn?
Hmm, I might have. Will address it in the cleanup from the second mail.
>
> I'm not sure that the CONFIG_XENBUS is worthwhile, at least at the
> moment, and it seems to add an awful lot of ifdefery.
>
> [...]
>> diff --git a/extras/mini-os/kernel.c b/extras/mini-os/kernel.c
>> index 2875bf1..9e490d5 100644
>> --- a/extras/mini-os/kernel.c
>> +++ b/extras/mini-os/kernel.c
>> [...]
>> @@ -462,11 +474,21 @@ __attribute__((weak)) int app_main(start_info_t *si)
>> printk("Dummy main: start_info=%p\n", si);
>> create_thread("xenbus_tester", xenbus_tester, si);
>> create_thread("periodic_thread", periodic_thread, si);
>> +#ifdef CONFIG_NETFRONT
>> create_thread("netfront", netfront_thread, si);
>> +#endif
>
> Better to define init_FOOfront for each of these and have it be a nop in
> the ifndef case and avoid the ifdefs in the code itself.
>
> Likewise the ifdef's in the teardown. Ideally the actual meat in the
> ifdef cases would be moved into the files you aren't compiling (e.g.
> netfront_thread goes into netfront.c) and only the stubs remain in some
> header somewhere.
>
> Ian.
>
The majority of kernel.c seems to be test code intended to be overridden
by the application; see the comment above app_main:
/* This should be overridden by the application we are linked against. */
__attribute__((weak)) int app_main(start_info_t *si)
As such, maybe all of this code should be moved out of kernel.c and into
test.c, and have a better noop app_main in kernel.c.
--
Daniel De Graaf
National Security Agency
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 11/21] mini-os: make frontends and xenbus optional
2012-01-23 16:21 ` Daniel De Graaf
@ 2012-01-23 16:24 ` Ian Campbell
0 siblings, 0 replies; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 16:24 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: xen-devel
On Mon, 2012-01-23 at 16:21 +0000, Daniel De Graaf wrote:
> On 01/23/2012 07:51 AM, Ian Campbell wrote:
> > Better to define init_FOOfront for each of these and have it be a nop in
> > the ifndef case and avoid the ifdefs in the code itself.
> >
> > Likewise the ifdef's in the teardown. Ideally the actual meat in the
> > ifdef cases would be moved into the files you aren't compiling (e.g.
> > netfront_thread goes into netfront.c) and only the stubs remain in some
> > header somewhere.
> >
> > Ian.
> >
>
> The majority of kernel.c seems to be test code intended to be overridden
> by the application; see the comment above app_main:
>
> /* This should be overridden by the application we are linked against. */
> __attribute__((weak)) int app_main(start_info_t *si)
>
> As such, maybe all of this code should be moved out of kernel.c and into
> test.c, and have a better noop app_main in kernel.c.
That sounds reasonable to me.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 11/21] mini-os: make frontends and xenbus optional
2012-01-20 20:47 ` [PATCH 11/21] mini-os: make frontends and xenbus optional Daniel De Graaf
2012-01-23 12:51 ` Ian Campbell
@ 2012-01-23 13:29 ` Ian Campbell
2012-01-23 16:21 ` Daniel De Graaf
1 sibling, 1 reply; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 13:29 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: xen-devel
On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
> This adds compile-time logic to disable certain frontends in mini-os:
> - pcifront is disabled by default, enabled for ioemu
> - blkfront, netfront, fbfront, and kbdfront are enabled by default
> - xenbus is required for any frontend, and is enabled by default
>
> If all frontends and xenbus are disabled, mini-os will run without
> needing to communicate with xenstore, making it suitable to run the
> xenstore daemon.
I should've read this properly first time, then it wouldn't have taken
me until 17/21 to figure it out.
I think would be worthwhile to refactor the xenstore driver "extra"
consoles from the single console provided via start info and to make the
former a configurable option in line with the other front end drivers.
That would, I think, tidy up the changes to xencons_ring. I think
free_consfront and init_consfront only apply to the extra console case
so the ifdefs you add within them would instead surround the whole
functions (or even consfront.o if you decide that works).
Ian.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 11/21] mini-os: make frontends and xenbus optional
2012-01-23 13:29 ` Ian Campbell
@ 2012-01-23 16:21 ` Daniel De Graaf
0 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-23 16:21 UTC (permalink / raw)
To: Ian Campbell; +Cc: xen-devel
On 01/23/2012 08:29 AM, Ian Campbell wrote:
> On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
>> This adds compile-time logic to disable certain frontends in mini-os:
>> - pcifront is disabled by default, enabled for ioemu
>> - blkfront, netfront, fbfront, and kbdfront are enabled by default
>> - xenbus is required for any frontend, and is enabled by default
>>
>> If all frontends and xenbus are disabled, mini-os will run without
>> needing to communicate with xenstore, making it suitable to run the
>> xenstore daemon.
>
> I should've read this properly first time, then it wouldn't have taken
> me until 17/21 to figure it out.
>
> I think would be worthwhile to refactor the xenstore driver "extra"
> consoles from the single console provided via start info and to make the
> former a configurable option in line with the other front end drivers.
> That would, I think, tidy up the changes to xencons_ring. I think
> free_consfront and init_consfront only apply to the extra console case
> so the ifdefs you add within them would instead surround the whole
> functions (or even consfront.o if you decide that works).
>
> Ian.
>
Ah, I hadn't noticed that minios supported multiple consoles; that
explains a lot of the xenstore dependencies here. In that case, I think
it'd be useful to add CONFIG_CONSFRONT to allow dropping that support
(possibly refactoring into multiple files).
--
Daniel De Graaf
National Security Agency
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH 12/21] mini-os: fix list.h include guard name
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (10 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 11/21] mini-os: make frontends and xenbus optional Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 13/21] xenstored: use grant references instead of map_foreign_range Daniel De Graaf
` (9 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
The symbol _LINUX_LIST_H collides with other header files.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
| 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
--git a/extras/mini-os/include/list.h b/extras/mini-os/include/list.h
index a60ae23..4e6a2ac 100644
--- a/extras/mini-os/include/list.h
+++ b/extras/mini-os/include/list.h
@@ -1,5 +1,5 @@
-#ifndef _LINUX_LIST_H
-#define _LINUX_LIST_H
+#ifndef _MINIOS_LIST_H
+#define _MINIOS_LIST_H
/*
* Simple doubly linked list implementation.
@@ -186,5 +186,5 @@ static __inline__ void minios_list_splice(struct minios_list_head *list, struct
n = minios_list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = minios_list_entry(n->member.next, typeof(*n), member))
-#endif /* _LINUX_LIST_H */
+#endif /* _MINIOS_LIST_H */
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 13/21] xenstored: use grant references instead of map_foreign_range
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (11 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 12/21] mini-os: fix list.h include guard name Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-23 13:06 ` Ian Campbell
2012-01-20 20:47 ` [PATCH 14/21] xenstored: add NO_SOCKETS compilation option Daniel De Graaf
` (8 subsequent siblings)
21 siblings, 1 reply; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf, Alex Zeffertt, Diego Ongaro
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
make xenstored use grantref rather than map_foreign_range (which can
only be used by privileged domains)
This patch modifies the xenstore daemon to use xc_gnttab_map_grant_ref
instead of xc_map_foreign_range where available.
Previous versions of this patch have been sent to xen-devel. See
http://lists.xensource.com/archives/html/xen-devel/2008-07/msg00610.html
http://lists.xensource.com/archives/html/xen-devel/2009-03/msg01492.html
Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
tools/xenstore/xenstored_domain.c | 52 ++++++++++++++++++++++++++++++++----
1 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index 443af82..661d955 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -32,8 +32,10 @@
#include "xenstored_watch.h"
#include <xenctrl.h>
+#include <xen/grant_table.h>
static xc_interface **xc_handle;
+static xc_gnttab **xcg_handle;
static evtchn_port_t virq_port;
xc_evtchn *xce_handle = NULL;
@@ -163,6 +165,26 @@ static int readchn(struct connection *conn, void *data, unsigned int len)
return len;
}
+static void *map_interface(domid_t domid, unsigned long mfn)
+{
+ if (*xcg_handle >= 0) {
+ /* this is the preferred method */
+ return xc_gnttab_map_grant_ref(*xcg_handle, domid,
+ GNTTAB_RESERVED_XENSTORE, PROT_READ|PROT_WRITE);
+ } else {
+ return xc_map_foreign_range(*xc_handle, domid,
+ getpagesize(), PROT_READ|PROT_WRITE, mfn);
+ }
+}
+
+static void unmap_interface(void *interface)
+{
+ if (*xcg_handle >= 0)
+ xc_gnttab_munmap(*xcg_handle, interface, 1);
+ else
+ munmap(interface, getpagesize());
+}
+
static int destroy_domain(void *_domain)
{
struct domain *domain = _domain;
@@ -174,8 +196,12 @@ static int destroy_domain(void *_domain)
eprintf("> Unbinding port %i failed!\n", domain->port);
}
- if (domain->interface)
- munmap(domain->interface, getpagesize());
+ if (domain->interface) {
+ if (domain->domid == 0)
+ munmap(domain->interface, getpagesize());
+ else
+ unmap_interface(domain->interface);
+ }
fire_watches(NULL, "@releaseDomain", false);
@@ -344,9 +370,7 @@ void do_introduce(struct connection *conn, struct buffered_data *in)
domain = find_domain_by_domid(domid);
if (domain == NULL) {
- interface = xc_map_foreign_range(
- *xc_handle, domid,
- getpagesize(), PROT_READ|PROT_WRITE, mfn);
+ interface = map_interface(domid, mfn);
if (!interface) {
send_error(conn, errno);
return;
@@ -354,7 +378,7 @@ void do_introduce(struct connection *conn, struct buffered_data *in)
/* Hang domain off "in" until we're finished. */
domain = new_domain(in, domid, port);
if (!domain) {
- munmap(interface, getpagesize());
+ unmap_interface(interface);
send_error(conn, errno);
return;
}
@@ -552,6 +576,12 @@ static int close_xc_handle(void *_handle)
return 0;
}
+static int close_xcg_handle(void *_handle)
+{
+ xc_gnttab_close(*(xc_gnttab **)_handle);
+ return 0;
+}
+
/* Returns the implicit path of a connection (only domains have this) */
const char *get_implicit_path(const struct connection *conn)
{
@@ -603,6 +633,16 @@ void domain_init(void)
talloc_set_destructor(xc_handle, close_xc_handle);
+ xcg_handle = talloc(talloc_autofree_context(), xc_gnttab*);
+ if (!xcg_handle)
+ barf_perror("Failed to allocate domain gnttab handle");
+
+ *xcg_handle = xc_gnttab_open(NULL, 0);
+ if (*xcg_handle < 0)
+ xprintf("WARNING: Failed to open connection to gnttab\n");
+ else
+ talloc_set_destructor(xcg_handle, close_xcg_handle);
+
xce_handle = xc_evtchn_open(NULL, 0);
if (xce_handle == NULL)
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 13/21] xenstored: use grant references instead of map_foreign_range
2012-01-20 20:47 ` [PATCH 13/21] xenstored: use grant references instead of map_foreign_range Daniel De Graaf
@ 2012-01-23 13:06 ` Ian Campbell
0 siblings, 0 replies; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 13:06 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: Alex Zeffertt, xen-devel, Diego Ongaro
On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
> From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
>
> make xenstored use grantref rather than map_foreign_range (which can
> only be used by privileged domains)
>
> This patch modifies the xenstore daemon to use xc_gnttab_map_grant_ref
> instead of xc_map_foreign_range where available.
>
> Previous versions of this patch have been sent to xen-devel. See
> http://lists.xensource.com/archives/html/xen-devel/2008-07/msg00610.html
> http://lists.xensource.com/archives/html/xen-devel/2009-03/msg01492.html
>
> Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
> Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
> ---
> tools/xenstore/xenstored_domain.c | 52 ++++++++++++++++++++++++++++++++----
> 1 files changed, 46 insertions(+), 6 deletions(-)
>
> diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
> index 443af82..661d955 100644
> --- a/tools/xenstore/xenstored_domain.c
> +++ b/tools/xenstore/xenstored_domain.c
> @@ -32,8 +32,10 @@
> #include "xenstored_watch.h"
>
> #include <xenctrl.h>
> +#include <xen/grant_table.h>
>
> static xc_interface **xc_handle;
> +static xc_gnttab **xcg_handle;
> static evtchn_port_t virq_port;
>
> xc_evtchn *xce_handle = NULL;
> @@ -163,6 +165,26 @@ static int readchn(struct connection *conn, void *data, unsigned int len)
> return len;
> }
>
> +static void *map_interface(domid_t domid, unsigned long mfn)
> +{
> + if (*xcg_handle >= 0) {
> + /* this is the preferred method */
> + return xc_gnttab_map_grant_ref(*xcg_handle, domid,
> + GNTTAB_RESERVED_XENSTORE, PROT_READ|PROT_WRITE);
> + } else {
> + return xc_map_foreign_range(*xc_handle, domid,
> + getpagesize(), PROT_READ|PROT_WRITE, mfn);
> + }
> +}
> +
> +static void unmap_interface(void *interface)
> +{
> + if (*xcg_handle >= 0)
> + xc_gnttab_munmap(*xcg_handle, interface, 1);
> + else
> + munmap(interface, getpagesize());
> +}
> +
> static int destroy_domain(void *_domain)
> {
> struct domain *domain = _domain;
> @@ -174,8 +196,12 @@ static int destroy_domain(void *_domain)
> eprintf("> Unbinding port %i failed!\n", domain->port);
> }
>
> - if (domain->interface)
> - munmap(domain->interface, getpagesize());
> + if (domain->interface) {
> + if (domain->domid == 0)
> + munmap(domain->interface, getpagesize());
> + else
> + unmap_interface(domain->interface);
> + }
>
> fire_watches(NULL, "@releaseDomain", false);
>
> @@ -344,9 +370,7 @@ void do_introduce(struct connection *conn, struct buffered_data *in)
> domain = find_domain_by_domid(domid);
>
> if (domain == NULL) {
> - interface = xc_map_foreign_range(
> - *xc_handle, domid,
> - getpagesize(), PROT_READ|PROT_WRITE, mfn);
> + interface = map_interface(domid, mfn);
> if (!interface) {
> send_error(conn, errno);
> return;
> @@ -354,7 +378,7 @@ void do_introduce(struct connection *conn, struct buffered_data *in)
> /* Hang domain off "in" until we're finished. */
> domain = new_domain(in, domid, port);
> if (!domain) {
> - munmap(interface, getpagesize());
> + unmap_interface(interface);
> send_error(conn, errno);
> return;
> }
> @@ -552,6 +576,12 @@ static int close_xc_handle(void *_handle)
> return 0;
> }
>
> +static int close_xcg_handle(void *_handle)
> +{
> + xc_gnttab_close(*(xc_gnttab **)_handle);
> + return 0;
> +}
> +
> /* Returns the implicit path of a connection (only domains have this) */
> const char *get_implicit_path(const struct connection *conn)
> {
> @@ -603,6 +633,16 @@ void domain_init(void)
>
> talloc_set_destructor(xc_handle, close_xc_handle);
>
> + xcg_handle = talloc(talloc_autofree_context(), xc_gnttab*);
> + if (!xcg_handle)
> + barf_perror("Failed to allocate domain gnttab handle");
> +
> + *xcg_handle = xc_gnttab_open(NULL, 0);
> + if (*xcg_handle < 0)
> + xprintf("WARNING: Failed to open connection to gnttab\n");
> + else
> + talloc_set_destructor(xcg_handle, close_xcg_handle);
> +
> xce_handle = xc_evtchn_open(NULL, 0);
>
> if (xce_handle == NULL)
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH 14/21] xenstored: add NO_SOCKETS compilation option
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (12 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 13/21] xenstored: use grant references instead of map_foreign_range Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-23 10:33 ` Stefano Stabellini
2012-01-20 20:47 ` [PATCH 15/21] xenstored: support for tdb_copy with TDB_INTERNAL Daniel De Graaf
` (7 subsequent siblings)
21 siblings, 1 reply; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf, Alex Zeffertt, Diego Ongaro
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
option for compiling xenstored without unix sockets to support running on mini-OS
Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
tools/xenstore/xenstored_core.c | 22 +++++++++++++++++++++-
tools/xenstore/xs.c | 2 ++
tools/xenstore/xs_lib.c | 4 ++++
3 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 9e6c2c7..631bfe4 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -19,9 +19,11 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/socket.h>
#include <sys/select.h>
+#ifndef NO_SOCKETS
+#include <sys/socket.h>
#include <sys/un.h>
+#endif
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
@@ -320,8 +322,10 @@ static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock,
FD_ZERO(inset);
FD_ZERO(outset);
+#ifndef NO_SOCKETS
set_fd(sock, inset, &max);
set_fd(ro_sock, inset, &max);
+#endif
set_fd(reopen_log_pipe[0], inset, &max);
if (xce_handle != NULL)
@@ -343,12 +347,14 @@ static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock,
return max;
}
+#ifndef NO_SOCKETS
static int destroy_fd(void *_fd)
{
int *fd = _fd;
close(*fd);
return 0;
}
+#endif
/* Is child a subnode of parent, or equal? */
bool is_child(const char *child, const char *parent)
@@ -1352,6 +1358,7 @@ struct connection *new_connection(connwritefn_t *write, connreadfn_t *read)
return new;
}
+#ifndef NO_SOCKETS
static int writefd(struct connection *conn, const void *data, unsigned int len)
{
int rc;
@@ -1406,6 +1413,7 @@ static void accept_connection(int sock, bool canwrite)
} else
close(fd);
}
+#endif
#define TDB_FLAGS 0
@@ -1753,7 +1761,11 @@ extern void dump_conn(struct connection *conn);
int main(int argc, char *argv[])
{
int opt, *sock, *ro_sock, max;
+#ifdef NO_SOCKETS
+ int minus_one = -1;
+#else
struct sockaddr_un addr;
+#endif
fd_set inset, outset;
bool dofork = true;
bool outputpid = false;
@@ -1837,6 +1849,9 @@ int main(int argc, char *argv[])
if (!dofork)
talloc_enable_leak_report_full();
+#ifdef NO_SOCKETS
+ sock = ro_sock = &minus_one;
+#else
/* Create sockets for them to listen to. */
sock = talloc(talloc_autofree_context(), int);
*sock = socket(PF_UNIX, SOCK_STREAM, 0);
@@ -1848,10 +1863,12 @@ int main(int argc, char *argv[])
barf_perror("Could not create socket");
talloc_set_destructor(sock, destroy_fd);
talloc_set_destructor(ro_sock, destroy_fd);
+#endif
/* Don't kill us with SIGPIPE. */
signal(SIGPIPE, SIG_IGN);
+#ifndef NO_SOCKETS
/* FIXME: Be more sophisticated, don't mug running daemon. */
unlink(xs_daemon_socket());
unlink(xs_daemon_socket_ro());
@@ -1871,6 +1888,7 @@ int main(int argc, char *argv[])
if (listen(*sock, 1) != 0
|| listen(*ro_sock, 1) != 0)
barf_perror("Could not listen on sockets");
+#endif
if (pipe(reopen_log_pipe)) {
barf_perror("pipe");
@@ -1931,11 +1949,13 @@ int main(int argc, char *argv[])
reopen_log();
}
+#ifndef NO_SOCKETS
if (FD_ISSET(*sock, &inset))
accept_connection(*sock, true);
if (FD_ISSET(*ro_sock, &inset))
accept_connection(*ro_sock, false);
+#endif
if (evtchn_fd != -1 && FD_ISSET(evtchn_fd, &inset))
handle_event();
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index 0a01675..60f2cee 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -271,10 +271,12 @@ struct xs_handle *xs_open(unsigned long flags)
{
struct xs_handle *xsh = NULL;
+#ifndef NO_SOCKETS
if (flags & XS_OPEN_READONLY)
xsh = get_handle(xs_daemon_socket_ro());
else
xsh = get_handle(xs_daemon_socket());
+#endif
if (!xsh && !(flags & XS_OPEN_SOCKETONLY))
xsh = get_handle(xs_domain_dev());
diff --git a/tools/xenstore/xs_lib.c b/tools/xenstore/xs_lib.c
index 03a9ee4..af3db6b 100644
--- a/tools/xenstore/xs_lib.c
+++ b/tools/xenstore/xs_lib.c
@@ -39,6 +39,7 @@ const char *xs_daemon_rundir(void)
return (s ? s : "/var/run/xenstored");
}
+#ifndef NO_SOCKETS
static const char *xs_daemon_path(void)
{
static char buf[PATH_MAX];
@@ -50,6 +51,7 @@ static const char *xs_daemon_path(void)
return NULL;
return buf;
}
+#endif
const char *xs_daemon_tdb(void)
{
@@ -58,6 +60,7 @@ const char *xs_daemon_tdb(void)
return buf;
}
+#ifndef NO_SOCKETS
const char *xs_daemon_socket(void)
{
return xs_daemon_path();
@@ -73,6 +76,7 @@ const char *xs_daemon_socket_ro(void)
return NULL;
return buf;
}
+#endif
const char *xs_domain_dev(void)
{
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 14/21] xenstored: add NO_SOCKETS compilation option
2012-01-20 20:47 ` [PATCH 14/21] xenstored: add NO_SOCKETS compilation option Daniel De Graaf
@ 2012-01-23 10:33 ` Stefano Stabellini
2012-01-23 13:12 ` Ian Campbell
0 siblings, 1 reply; 41+ messages in thread
From: Stefano Stabellini @ 2012-01-23 10:33 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: Alex Zeffertt, xen-devel, Diego Ongaro
On Fri, 20 Jan 2012, Daniel De Graaf wrote:
> From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
>
> option for compiling xenstored without unix sockets to support running on mini-OS
The amount of ifdef's introduced by this patch is not ideal.
Do you think is possible to refactor the code to use structures with
function pointers, with a registration mechanism, so that in the dom0
case you would end up with two structs (one for each kind of
connections), while you would have only one on mini-OS?
We could have an initialize, a destroy and an accept_connection
functions.
> Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
> Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> Acked-by: Ian Campbell <ian.campbell@citrix.com>
> ---
> tools/xenstore/xenstored_core.c | 22 +++++++++++++++++++++-
> tools/xenstore/xs.c | 2 ++
> tools/xenstore/xs_lib.c | 4 ++++
> 3 files changed, 27 insertions(+), 1 deletions(-)
>
> diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
> index 9e6c2c7..631bfe4 100644
> --- a/tools/xenstore/xenstored_core.c
> +++ b/tools/xenstore/xenstored_core.c
> @@ -19,9 +19,11 @@
>
> #include <sys/types.h>
> #include <sys/stat.h>
> -#include <sys/socket.h>
> #include <sys/select.h>
> +#ifndef NO_SOCKETS
> +#include <sys/socket.h>
> #include <sys/un.h>
> +#endif
> #include <sys/time.h>
> #include <time.h>
> #include <unistd.h>
> @@ -320,8 +322,10 @@ static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock,
> FD_ZERO(inset);
> FD_ZERO(outset);
>
> +#ifndef NO_SOCKETS
> set_fd(sock, inset, &max);
> set_fd(ro_sock, inset, &max);
> +#endif
> set_fd(reopen_log_pipe[0], inset, &max);
>
> if (xce_handle != NULL)
> @@ -343,12 +347,14 @@ static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock,
> return max;
> }
>
> +#ifndef NO_SOCKETS
> static int destroy_fd(void *_fd)
> {
> int *fd = _fd;
> close(*fd);
> return 0;
> }
> +#endif
>
> /* Is child a subnode of parent, or equal? */
> bool is_child(const char *child, const char *parent)
> @@ -1352,6 +1358,7 @@ struct connection *new_connection(connwritefn_t *write, connreadfn_t *read)
> return new;
> }
>
> +#ifndef NO_SOCKETS
> static int writefd(struct connection *conn, const void *data, unsigned int len)
> {
> int rc;
> @@ -1406,6 +1413,7 @@ static void accept_connection(int sock, bool canwrite)
> } else
> close(fd);
> }
> +#endif
>
> #define TDB_FLAGS 0
>
> @@ -1753,7 +1761,11 @@ extern void dump_conn(struct connection *conn);
> int main(int argc, char *argv[])
> {
> int opt, *sock, *ro_sock, max;
> +#ifdef NO_SOCKETS
> + int minus_one = -1;
> +#else
> struct sockaddr_un addr;
> +#endif
> fd_set inset, outset;
> bool dofork = true;
> bool outputpid = false;
> @@ -1837,6 +1849,9 @@ int main(int argc, char *argv[])
> if (!dofork)
> talloc_enable_leak_report_full();
>
> +#ifdef NO_SOCKETS
> + sock = ro_sock = &minus_one;
> +#else
> /* Create sockets for them to listen to. */
> sock = talloc(talloc_autofree_context(), int);
> *sock = socket(PF_UNIX, SOCK_STREAM, 0);
> @@ -1848,10 +1863,12 @@ int main(int argc, char *argv[])
> barf_perror("Could not create socket");
> talloc_set_destructor(sock, destroy_fd);
> talloc_set_destructor(ro_sock, destroy_fd);
> +#endif
>
> /* Don't kill us with SIGPIPE. */
> signal(SIGPIPE, SIG_IGN);
>
> +#ifndef NO_SOCKETS
> /* FIXME: Be more sophisticated, don't mug running daemon. */
> unlink(xs_daemon_socket());
> unlink(xs_daemon_socket_ro());
> @@ -1871,6 +1888,7 @@ int main(int argc, char *argv[])
> if (listen(*sock, 1) != 0
> || listen(*ro_sock, 1) != 0)
> barf_perror("Could not listen on sockets");
> +#endif
>
> if (pipe(reopen_log_pipe)) {
> barf_perror("pipe");
> @@ -1931,11 +1949,13 @@ int main(int argc, char *argv[])
> reopen_log();
> }
>
> +#ifndef NO_SOCKETS
> if (FD_ISSET(*sock, &inset))
> accept_connection(*sock, true);
>
> if (FD_ISSET(*ro_sock, &inset))
> accept_connection(*ro_sock, false);
> +#endif
>
> if (evtchn_fd != -1 && FD_ISSET(evtchn_fd, &inset))
> handle_event();
> diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
> index 0a01675..60f2cee 100644
> --- a/tools/xenstore/xs.c
> +++ b/tools/xenstore/xs.c
> @@ -271,10 +271,12 @@ struct xs_handle *xs_open(unsigned long flags)
> {
> struct xs_handle *xsh = NULL;
>
> +#ifndef NO_SOCKETS
> if (flags & XS_OPEN_READONLY)
> xsh = get_handle(xs_daemon_socket_ro());
> else
> xsh = get_handle(xs_daemon_socket());
> +#endif
>
> if (!xsh && !(flags & XS_OPEN_SOCKETONLY))
> xsh = get_handle(xs_domain_dev());
> diff --git a/tools/xenstore/xs_lib.c b/tools/xenstore/xs_lib.c
> index 03a9ee4..af3db6b 100644
> --- a/tools/xenstore/xs_lib.c
> +++ b/tools/xenstore/xs_lib.c
> @@ -39,6 +39,7 @@ const char *xs_daemon_rundir(void)
> return (s ? s : "/var/run/xenstored");
> }
>
> +#ifndef NO_SOCKETS
> static const char *xs_daemon_path(void)
> {
> static char buf[PATH_MAX];
> @@ -50,6 +51,7 @@ static const char *xs_daemon_path(void)
> return NULL;
> return buf;
> }
> +#endif
>
> const char *xs_daemon_tdb(void)
> {
> @@ -58,6 +60,7 @@ const char *xs_daemon_tdb(void)
> return buf;
> }
>
> +#ifndef NO_SOCKETS
> const char *xs_daemon_socket(void)
> {
> return xs_daemon_path();
> @@ -73,6 +76,7 @@ const char *xs_daemon_socket_ro(void)
> return NULL;
> return buf;
> }
> +#endif
>
> const char *xs_domain_dev(void)
> {
> --
> 1.7.7.5
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 14/21] xenstored: add NO_SOCKETS compilation option
2012-01-23 10:33 ` Stefano Stabellini
@ 2012-01-23 13:12 ` Ian Campbell
0 siblings, 0 replies; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 13:12 UTC (permalink / raw)
To: Stefano Stabellini
Cc: Daniel De Graaf, Alex Zeffertt, xen-devel, Diego Ongaro
On Mon, 2012-01-23 at 10:33 +0000, Stefano Stabellini wrote:
> On Fri, 20 Jan 2012, Daniel De Graaf wrote:
> > From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
> >
> > option for compiling xenstored without unix sockets to support running on mini-OS
>
> The amount of ifdef's introduced by this patch is not ideal.
>
> Do you think is possible to refactor the code to use structures with
> function pointers, with a registration mechanism, so that in the dom0
> case you would end up with two structs (one for each kind of
> connections), while you would have only one on mini-OS?
>
> We could have an initialize, a destroy and an accept_connection
> functions.
I suggested earlier that sprinkling checks for fd == -1 around instead
of ifdefs might end up more palatable -- e.g. for the changes in
initialize_set, destroy_fd, write_fd, the FD_ISSET test etc. Factoring
the setup code from main() into a function which can have an ifdef
nopped case would help too.
> > Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
> > Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
> > Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> > Acked-by: Ian Campbell <ian.campbell@citrix.com>
[...]
> > diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
> > index 0a01675..60f2cee 100644
> > --- a/tools/xenstore/xs.c
> > +++ b/tools/xenstore/xs.c
> > @@ -271,10 +271,12 @@ struct xs_handle *xs_open(unsigned long flags)
> > {
> > struct xs_handle *xsh = NULL;
> >
> > +#ifndef NO_SOCKETS
> > if (flags & XS_OPEN_READONLY)
> > xsh = get_handle(xs_daemon_socket_ro());
> > else
> > xsh = get_handle(xs_daemon_socket());
> > +#endif
I think tools/xenstore/xs.c is only used by the client library -- does
this change actual cause anything to happen?
[...]
> > +#ifndef NO_SOCKETS
> > const char *xs_daemon_socket(void)
> > {
> > return xs_daemon_path();
> > @@ -73,6 +76,7 @@ const char *xs_daemon_socket_ro(void)
> > return NULL;
> > return buf;
> > }
> > +#endif
If this returned NULL in the NO_SOCKETS case that might also help.
Ian.
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH 15/21] xenstored: support for tdb_copy with TDB_INTERNAL
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (13 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 14/21] xenstored: add NO_SOCKETS compilation option Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-23 13:14 ` Ian Campbell
2012-01-20 20:47 ` [PATCH 16/21] xenstored: support running in minios stubdom Daniel De Graaf
` (6 subsequent siblings)
21 siblings, 1 reply; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf, Alex Zeffertt, Diego Ongaro
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
The tdb_copy function should honor the TDB_INTERNAL flag for in-memory
databases; this is required to run in mini-os which does not use a
filesystem.
Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
tools/xenstore/tdb.c | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/tools/xenstore/tdb.c b/tools/xenstore/tdb.c
index 63205e1..3ecd3fc 100644
--- a/tools/xenstore/tdb.c
+++ b/tools/xenstore/tdb.c
@@ -2103,6 +2103,41 @@ TDB_CONTEXT *tdb_copy(TDB_CONTEXT *tdb, const char *outfile)
int fd, saved_errno;
TDB_CONTEXT *copy;
+ if (tdb->flags & TDB_INTERNAL) {
+ struct tdb_header *copydb;
+
+ copy = talloc_zero(outfile, TDB_CONTEXT);
+ if (copy == NULL) {
+ errno = ENOMEM;
+ goto intfail;
+ }
+ memcpy(copy, tdb, sizeof(TDB_CONTEXT));
+
+ if (copy->name || copy->locked || copy->device || copy->inode) {
+ fprintf(stderr, "tdb_copy assumption(s) failed\n");
+ goto intfail;
+ }
+
+ copydb = talloc_zero_size(copy, copy->map_size);
+ if (copydb == NULL) {
+ errno = ENOMEM;
+ goto intfail;
+ }
+ memcpy(copydb, copy->map_ptr, copy->map_size);
+ copy->map_ptr = (char*) copydb;
+
+ if (tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0) == -1)
+ goto intfail;
+
+ copy->next = tdbs;
+ tdbs = copy;
+
+ return copy;
+intfail:
+ talloc_free(copy);
+ return NULL;
+ }
+
fd = open(outfile, O_TRUNC|O_CREAT|O_WRONLY, 0640);
if (fd < 0)
return NULL;
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 15/21] xenstored: support for tdb_copy with TDB_INTERNAL
2012-01-20 20:47 ` [PATCH 15/21] xenstored: support for tdb_copy with TDB_INTERNAL Daniel De Graaf
@ 2012-01-23 13:14 ` Ian Campbell
0 siblings, 0 replies; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 13:14 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: Alex Zeffertt, xen-devel, Diego Ongaro
On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
> From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
>
> The tdb_copy function should honor the TDB_INTERNAL flag for in-memory
> databases; this is required to run in mini-os which does not use a
> filesystem.
>
> Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
> Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH 16/21] xenstored: support running in minios stubdom
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (14 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 15/21] xenstored: support for tdb_copy with TDB_INTERNAL Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-23 10:39 ` Stefano Stabellini
2012-01-20 20:47 ` [PATCH 17/21] stubdom: enable xenstored build Daniel De Graaf
` (5 subsequent siblings)
21 siblings, 1 reply; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf, Alex Zeffertt, Diego Ongaro
A previous versions of this patch has been sent to xen-devel. See
http://lists.xensource.com/archives/html/xen-devel/2009-03/msg01655.html
Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
tools/xenstore/Makefile | 9 +++++-
tools/xenstore/tdb.c | 6 ++--
tools/xenstore/utils.h | 2 +
tools/xenstore/xenstored_core.c | 47 ++++++++++++++++++++++++++++++-
tools/xenstore/xenstored_domain.c | 11 +++++++
tools/xenstore/xenstored_transaction.c | 2 +
6 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 4facb62..3a061d6 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -28,6 +28,10 @@ endif
ALL_TARGETS = libxenstore.so libxenstore.a clients xs_tdb_dump xenstored
+ifdef CONFIG_STUBDOM
+CFLAGS += -DNO_SOCKETS=1 -DNO_LOCAL_XENBUS=1 -DNO_SYSLOG=1 -DNO_REOPEN_LOG=1
+endif
+
.PHONY: all
all: $(ALL_TARGETS)
@@ -45,10 +49,13 @@ xenstored_probes.o: xenstored_solaris.o
CFLAGS += -DHAVE_DTRACE=1
endif
-
+
xenstored: $(XENSTORED_OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
+xenstored.a: $(XENSTORED_OBJS)
+ $(AR) cr $@ $^
+
$(CLIENTS): xenstore
ln -f xenstore $@
diff --git a/tools/xenstore/tdb.c b/tools/xenstore/tdb.c
index 3ecd3fc..cb66ea7 100644
--- a/tools/xenstore/tdb.c
+++ b/tools/xenstore/tdb.c
@@ -1334,7 +1334,7 @@ static int tdb_next_lock(TDB_CONTEXT *tdb, struct tdb_traverse_lock *tlock,
/* Iterate through chain */
while( tlock->off) {
- tdb_off current;
+ tdb_off mycurrent;
if (rec_read(tdb, tlock->off, rec) == -1)
goto fail;
@@ -1352,10 +1352,10 @@ static int tdb_next_lock(TDB_CONTEXT *tdb, struct tdb_traverse_lock *tlock,
}
/* Try to clean dead ones from old traverses */
- current = tlock->off;
+ mycurrent = tlock->off;
tlock->off = rec->next;
if (!tdb->read_only &&
- do_delete(tdb, current, rec) != 0)
+ do_delete(tdb, mycurrent, rec) != 0)
goto fail;
}
tdb_unlock(tdb, tlock->hash, F_WRLCK);
diff --git a/tools/xenstore/utils.h b/tools/xenstore/utils.h
index f378343..2effd17 100644
--- a/tools/xenstore/utils.h
+++ b/tools/xenstore/utils.h
@@ -19,7 +19,9 @@ static inline bool strends(const char *a, const char *b)
return streq(a + strlen(a) - strlen(b), b);
}
+#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
void barf(const char *fmt, ...) __attribute__((noreturn));
void barf_perror(const char *fmt, ...) __attribute__((noreturn));
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 631bfe4..66ca555 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -32,7 +32,9 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
+#ifndef NO_SYSLOG
#include <syslog.h>
+#endif
#include <string.h>
#include <errno.h>
#include <dirent.h>
@@ -61,13 +63,24 @@ LIST_HEAD(connections);
static int tracefd = -1;
static bool recovery = true;
static bool remove_local = true;
+#ifndef NO_REOPEN_LOG
static int reopen_log_pipe[2];
+#endif
static char *tracefile = NULL;
static TDB_CONTEXT *tdb_ctx;
static void corrupt(struct connection *conn, const char *fmt, ...);
static void check_store(void);
+#ifdef __MINIOS__
+#define lockf(...) (-ENOSYS)
+#endif
+
+#ifdef NO_SYSLOG
+#define openlog(...) ((void) 0)
+#define syslog(...) ((void) 0)
+#endif
+
#define log(...) \
do { \
char *s = talloc_asprintf(NULL, __VA_ARGS__); \
@@ -92,8 +105,10 @@ TDB_CONTEXT *tdb_context(struct connection *conn)
bool replace_tdb(const char *newname, TDB_CONTEXT *newtdb)
{
+#ifndef __MINIOS__
if (rename(newname, xs_daemon_tdb()) != 0)
return false;
+#endif
tdb_close(tdb_ctx);
tdb_ctx = talloc_steal(talloc_autofree_context(), newtdb);
return true;
@@ -195,6 +210,11 @@ void trace_destroy(const void *data, const char *type)
trace("DESTROY %s %p\n", type, data);
}
+#ifdef NO_REOPEN_LOG
+static void reopen_log(void)
+{
+}
+#else
/**
* Signal handler for SIGHUP, which requests that the trace log is reopened
* (in the main loop). A single byte is written to reopen_log_pipe, to awaken
@@ -222,7 +242,7 @@ static void reopen_log(void)
trace("\n***\n");
}
}
-
+#endif
static bool write_messages(struct connection *conn)
{
@@ -326,7 +346,9 @@ static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock,
set_fd(sock, inset, &max);
set_fd(ro_sock, inset, &max);
#endif
+#ifndef NO_REOPEN_LOG
set_fd(reopen_log_pipe[0], inset, &max);
+#endif
if (xce_handle != NULL)
set_fd(xc_evtchn_fd(xce_handle), inset, &max);
@@ -1415,7 +1437,11 @@ static void accept_connection(int sock, bool canwrite)
}
#endif
+#ifdef __MINIOS__
+#define TDB_FLAGS TDB_INTERNAL|TDB_NOLOCK
+#else
#define TDB_FLAGS 0
+#endif
/* We create initial nodes manually. */
static void manual_node(const char *name, const char *child)
@@ -1440,7 +1466,11 @@ static void setup_structure(void)
{
char *tdbname;
tdbname = talloc_strdup(talloc_autofree_context(), xs_daemon_tdb());
+#ifdef __MINIOS__
+ tdb_ctx = NULL;
+#else
tdb_ctx = tdb_open(tdbname, 0, TDB_FLAGS, O_RDWR, 0);
+#endif
if (tdb_ctx) {
/* XXX When we make xenstored able to restart, this will have
@@ -1666,6 +1696,7 @@ static void corrupt(struct connection *conn, const char *fmt, ...)
}
+#ifndef __MINIOS__
static void write_pidfile(const char *pidfile)
{
char buf[100];
@@ -1712,7 +1743,7 @@ static void daemonize(void)
/* Discard our parent's old-fashioned umask prejudices. */
umask(0);
}
-
+#endif
static void usage(void)
{
@@ -1823,6 +1854,7 @@ int main(int argc, char *argv[])
reopen_log();
+#ifndef __MINIOS__
/* make sure xenstored directory exists */
if (mkdir(xs_daemon_rundir(), 0755)) {
if (errno != EEXIST) {
@@ -1844,6 +1876,7 @@ int main(int argc, char *argv[])
}
if (pidfile)
write_pidfile(pidfile);
+#endif
/* Talloc leak reports go to stderr, which is closed if we fork. */
if (!dofork)
@@ -1890,9 +1923,11 @@ int main(int argc, char *argv[])
barf_perror("Could not listen on sockets");
#endif
+#ifndef NO_REOPEN_LOG
if (pipe(reopen_log_pipe)) {
barf_perror("pipe");
}
+#endif
/* Setup the database */
setup_structure();
@@ -1909,6 +1944,7 @@ int main(int argc, char *argv[])
fflush(stdout);
}
+#ifndef __MINIOS__
/* redirect to /dev/null now we're ready to accept connections */
if (dofork) {
int devnull = open("/dev/null", O_RDWR);
@@ -1920,8 +1956,11 @@ int main(int argc, char *argv[])
close(devnull);
xprintf = trace;
}
+#endif
+#ifndef NO_REOPEN_LOG
signal(SIGHUP, trigger_reopen_log);
+#endif
if (xce_handle != NULL)
evtchn_fd = xc_evtchn_fd(xce_handle);
@@ -1929,8 +1968,10 @@ int main(int argc, char *argv[])
/* Get ready to listen to the tools. */
max = initialize_set(&inset, &outset, *sock, *ro_sock, &timeout);
+#ifndef __MINIOS__
/* Tell the kernel we're up and running. */
xenbus_notify_running();
+#endif
/* Main loop. */
for (;;) {
@@ -1942,12 +1983,14 @@ int main(int argc, char *argv[])
barf_perror("Select failed");
}
+#ifndef NO_REOPEN_LOG
if (FD_ISSET(reopen_log_pipe[0], &inset)) {
char c;
if (read(reopen_log_pipe[0], &c, 1) != 1)
barf_perror("read failed");
reopen_log();
}
+#endif
#ifndef NO_SOCKETS
if (FD_ISSET(*sock, &inset))
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index 661d955..435f76a 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -197,10 +197,14 @@ static int destroy_domain(void *_domain)
}
if (domain->interface) {
+#ifdef __MINIOS__
+ unmap_interface(domain->interface);
+#else
if (domain->domid == 0)
munmap(domain->interface, getpagesize());
else
unmap_interface(domain->interface);
+#endif
}
fire_watches(NULL, "@releaseDomain", false);
@@ -595,6 +599,12 @@ void restore_existing_connections(void)
{
}
+#ifdef __MINIOS__
+static int dom0_init(void)
+{
+ return 0;
+}
+#else
static int dom0_init(void)
{
evtchn_port_t port;
@@ -618,6 +628,7 @@ static int dom0_init(void)
return 0;
}
+#endif
void domain_init(void)
{
diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xenstored_transaction.c
index 380c691..c59acfb 100644
--- a/tools/xenstore/xenstored_transaction.c
+++ b/tools/xenstore/xenstored_transaction.c
@@ -120,7 +120,9 @@ static int destroy_transaction(void *_transaction)
trace_destroy(trans, "transaction");
if (trans->tdb)
tdb_close(trans->tdb);
+#ifndef __MINIOS__
unlink(trans->tdb_name);
+#endif
return 0;
}
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 16/21] xenstored: support running in minios stubdom
2012-01-20 20:47 ` [PATCH 16/21] xenstored: support running in minios stubdom Daniel De Graaf
@ 2012-01-23 10:39 ` Stefano Stabellini
0 siblings, 0 replies; 41+ messages in thread
From: Stefano Stabellini @ 2012-01-23 10:39 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: Alex Zeffertt, xen-devel, Diego Ongaro
On Fri, 20 Jan 2012, Daniel De Graaf wrote:
> A previous versions of this patch has been sent to xen-devel. See
> http://lists.xensource.com/archives/html/xen-devel/2009-03/msg01655.html
>
> Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
> Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> ---
> diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
> index 631bfe4..66ca555 100644
> --- a/tools/xenstore/xenstored_core.c
> +++ b/tools/xenstore/xenstored_core.c
> @@ -32,7 +32,9 @@
> #include <stdio.h>
> #include <stdarg.h>
> #include <stdlib.h>
> +#ifndef NO_SYSLOG
> #include <syslog.h>
> +#endif
> #include <string.h>
> #include <errno.h>
> #include <dirent.h>
> @@ -61,13 +63,24 @@ LIST_HEAD(connections);
> static int tracefd = -1;
> static bool recovery = true;
> static bool remove_local = true;
> +#ifndef NO_REOPEN_LOG
> static int reopen_log_pipe[2];
> +#endif
> static char *tracefile = NULL;
> static TDB_CONTEXT *tdb_ctx;
>
> static void corrupt(struct connection *conn, const char *fmt, ...);
> static void check_store(void);
>
> +#ifdef __MINIOS__
> +#define lockf(...) (-ENOSYS)
> +#endif
maybe it's better to change lockf in extras/mini-os/lib/sys.c from
unsupported_function_crash to unsupported_function_log
> +#ifdef NO_SYSLOG
> +#define openlog(...) ((void) 0)
> +#define syslog(...) ((void) 0)
> +#endif
these ones are actually supposed to work, going through minios' first
console
> #define log(...) \
> do { \
> char *s = talloc_asprintf(NULL, __VA_ARGS__); \
> @@ -92,8 +105,10 @@ TDB_CONTEXT *tdb_context(struct connection *conn)
>
> bool replace_tdb(const char *newname, TDB_CONTEXT *newtdb)
> {
> +#ifndef __MINIOS__
> if (rename(newname, xs_daemon_tdb()) != 0)
> return false;
> +#endif
> tdb_close(tdb_ctx);
> tdb_ctx = talloc_steal(talloc_autofree_context(), newtdb);
> return true;
> @@ -195,6 +210,11 @@ void trace_destroy(const void *data, const char *type)
> trace("DESTROY %s %p\n", type, data);
> }
>
> +#ifdef NO_REOPEN_LOG
> +static void reopen_log(void)
> +{
> +}
> +#else
> /**
> * Signal handler for SIGHUP, which requests that the trace log is reopened
> * (in the main loop). A single byte is written to reopen_log_pipe, to awaken
> @@ -222,7 +242,7 @@ static void reopen_log(void)
> trace("\n***\n");
> }
> }
> -
> +#endif
>
> static bool write_messages(struct connection *conn)
> {
> @@ -326,7 +346,9 @@ static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock,
> set_fd(sock, inset, &max);
> set_fd(ro_sock, inset, &max);
> #endif
> +#ifndef NO_REOPEN_LOG
> set_fd(reopen_log_pipe[0], inset, &max);
> +#endif
>
> if (xce_handle != NULL)
> set_fd(xc_evtchn_fd(xce_handle), inset, &max);
> @@ -1415,7 +1437,11 @@ static void accept_connection(int sock, bool canwrite)
> }
> #endif
>
> +#ifdef __MINIOS__
> +#define TDB_FLAGS TDB_INTERNAL|TDB_NOLOCK
> +#else
> #define TDB_FLAGS 0
> +#endif
>
> /* We create initial nodes manually. */
> static void manual_node(const char *name, const char *child)
> @@ -1440,7 +1466,11 @@ static void setup_structure(void)
> {
> char *tdbname;
> tdbname = talloc_strdup(talloc_autofree_context(), xs_daemon_tdb());
> +#ifdef __MINIOS__
> + tdb_ctx = NULL;
> +#else
> tdb_ctx = tdb_open(tdbname, 0, TDB_FLAGS, O_RDWR, 0);
> +#endif
>
> if (tdb_ctx) {
> /* XXX When we make xenstored able to restart, this will have
> @@ -1666,6 +1696,7 @@ static void corrupt(struct connection *conn, const char *fmt, ...)
> }
>
>
> +#ifndef __MINIOS__
> static void write_pidfile(const char *pidfile)
> {
> char buf[100];
> @@ -1712,7 +1743,7 @@ static void daemonize(void)
> /* Discard our parent's old-fashioned umask prejudices. */
> umask(0);
> }
> -
> +#endif
>
> static void usage(void)
> {
> @@ -1823,6 +1854,7 @@ int main(int argc, char *argv[])
>
> reopen_log();
>
> +#ifndef __MINIOS__
> /* make sure xenstored directory exists */
> if (mkdir(xs_daemon_rundir(), 0755)) {
> if (errno != EEXIST) {
> @@ -1844,6 +1876,7 @@ int main(int argc, char *argv[])
> }
> if (pidfile)
> write_pidfile(pidfile);
> +#endif
>
> /* Talloc leak reports go to stderr, which is closed if we fork. */
> if (!dofork)
> @@ -1890,9 +1923,11 @@ int main(int argc, char *argv[])
> barf_perror("Could not listen on sockets");
> #endif
>
> +#ifndef NO_REOPEN_LOG
> if (pipe(reopen_log_pipe)) {
> barf_perror("pipe");
> }
> +#endif
>
> /* Setup the database */
> setup_structure();
> @@ -1909,6 +1944,7 @@ int main(int argc, char *argv[])
> fflush(stdout);
> }
>
> +#ifndef __MINIOS__
> /* redirect to /dev/null now we're ready to accept connections */
> if (dofork) {
> int devnull = open("/dev/null", O_RDWR);
> @@ -1920,8 +1956,11 @@ int main(int argc, char *argv[])
> close(devnull);
> xprintf = trace;
> }
> +#endif
>
> +#ifndef NO_REOPEN_LOG
> signal(SIGHUP, trigger_reopen_log);
> +#endif
>
> if (xce_handle != NULL)
> evtchn_fd = xc_evtchn_fd(xce_handle);
> @@ -1929,8 +1968,10 @@ int main(int argc, char *argv[])
> /* Get ready to listen to the tools. */
> max = initialize_set(&inset, &outset, *sock, *ro_sock, &timeout);
>
> +#ifndef __MINIOS__
> /* Tell the kernel we're up and running. */
> xenbus_notify_running();
> +#endif
>
> /* Main loop. */
> for (;;) {
> @@ -1942,12 +1983,14 @@ int main(int argc, char *argv[])
> barf_perror("Select failed");
> }
>
> +#ifndef NO_REOPEN_LOG
> if (FD_ISSET(reopen_log_pipe[0], &inset)) {
> char c;
> if (read(reopen_log_pipe[0], &c, 1) != 1)
> barf_perror("read failed");
> reopen_log();
> }
> +#endif
>
> #ifndef NO_SOCKETS
> if (FD_ISSET(*sock, &inset))
> diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
> index 661d955..435f76a 100644
> --- a/tools/xenstore/xenstored_domain.c
> +++ b/tools/xenstore/xenstored_domain.c
> @@ -197,10 +197,14 @@ static int destroy_domain(void *_domain)
> }
>
> if (domain->interface) {
> +#ifdef __MINIOS__
> + unmap_interface(domain->interface);
> +#else
> if (domain->domid == 0)
> munmap(domain->interface, getpagesize());
> else
> unmap_interface(domain->interface);
> +#endif
> }
>
> fire_watches(NULL, "@releaseDomain", false);
> @@ -595,6 +599,12 @@ void restore_existing_connections(void)
> {
> }
>
> +#ifdef __MINIOS__
> +static int dom0_init(void)
> +{
> + return 0;
> +}
> +#else
> static int dom0_init(void)
> {
> evtchn_port_t port;
> @@ -618,6 +628,7 @@ static int dom0_init(void)
>
> return 0;
> }
> +#endif
>
> void domain_init(void)
> {
> diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xenstored_transaction.c
> index 380c691..c59acfb 100644
> --- a/tools/xenstore/xenstored_transaction.c
> +++ b/tools/xenstore/xenstored_transaction.c
> @@ -120,7 +120,9 @@ static int destroy_transaction(void *_transaction)
> trace_destroy(trans, "transaction");
> if (trans->tdb)
> tdb_close(trans->tdb);
> +#ifndef __MINIOS__
> unlink(trans->tdb_name);
> +#endif
> return 0;
> }
>
maybe we could reduce the amount of ifdef's using the same struct of
function pointers idea?
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH 17/21] stubdom: enable xenstored build
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (15 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 16/21] xenstored: support running in minios stubdom Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-23 13:17 ` Ian Campbell
2012-01-20 20:47 ` [PATCH 18/21] xenstored: add --event parameter for bootstrapping Daniel De Graaf
` (4 subsequent siblings)
21 siblings, 1 reply; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
| 8 ++++++++
stubdom/Makefile | 29 ++++++++++++++++++++++++++---
2 files changed, 34 insertions(+), 3 deletions(-)
create mode 100644 extras/mini-os/apps/xenstore.mk
--git a/extras/mini-os/apps/xenstore.mk b/extras/mini-os/apps/xenstore.mk
new file mode 100644
index 0000000..26ff9a6
--- /dev/null
+++ b/extras/mini-os/apps/xenstore.mk
@@ -0,0 +1,8 @@
+CONFIG_BLKFRONT=n
+CONFIG_NETFRONT=n
+CONFIG_FBFRONT=n
+CONFIG_KBDFRONT=n
+CONFIG_XENBUS=n
+
+lwip=n
+DEF_CPPFLAGS := $(filter-out -DHAVE_LWIP,$(DEF_CPPFLAGS))
diff --git a/stubdom/Makefile b/stubdom/Makefile
index 7989f31..0718e50 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -74,14 +74,14 @@ TARGET_CPPFLAGS += -I$(XEN_ROOT)/xen/include
TARGET_LDFLAGS += -nostdlib -L$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib
-TARGETS=ioemu c caml grub
+TARGETS=ioemu c caml grub xenstore
CROSS_MAKE := $(MAKE) DESTDIR=
.PHONY: all
all: build
ifeq ($(STUBDOM_SUPPORTED),1)
-build: genpath ioemu-stubdom c-stubdom pv-grub
+build: genpath ioemu-stubdom c-stubdom pv-grub xenstore-stubdom
else
build: genpath
endif
@@ -262,6 +262,11 @@ mk-headers-$(XEN_TARGET_ARCH): ioemu/linkfarm.stamp
ln -sf $(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/*.c . && \
ln -sf $(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/*.h . && \
ln -sf $(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/Makefile . )
+ mkdir -p xenstore
+ [ -h xenstore/Makefile ] || ( cd xenstore && \
+ ln -sf $(XEN_ROOT)/tools/xenstore/*.c . && \
+ ln -sf $(XEN_ROOT)/tools/xenstore/*.h . && \
+ ln -sf $(XEN_ROOT)/tools/xenstore/Makefile . )
$(CROSS_MAKE) -C $(MINI_OS) links
touch mk-headers-$(XEN_TARGET_ARCH)
@@ -334,6 +339,14 @@ grub: grub-upstream $(CROSS_ROOT)
mkdir -p grub-$(XEN_TARGET_ARCH)
CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(CROSS_MAKE) -C $@ OBJ_DIR=$(CURDIR)/grub-$(XEN_TARGET_ARCH)
+##########
+# xenstore
+##########
+
+.PHONY: xenstore
+xenstore: $(CROSS_ROOT)
+ CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(CROSS_MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip xenstored.a CONFIG_STUBDOM=y
+
########
# minios
########
@@ -355,12 +368,16 @@ c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxc c
pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxc grub
DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_APP=grub $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub-$(XEN_TARGET_ARCH)/main.a
+.PHONY: xenstore-stubdom
+xenstore-stubdom: mini-os-$(XEN_TARGET_ARCH)-xenstore libxc xenstore
+ DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_APP=xenstore $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS=$(CURDIR)/xenstore/xenstored.a
+
#########
# install
#########
ifeq ($(STUBDOM_SUPPORTED),1)
-install: genpath install-readme install-ioemu install-grub
+install: genpath install-readme install-ioemu install-grub install-xenstore
else
install: genpath
endif
@@ -379,6 +396,10 @@ install-grub: pv-grub
$(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
$(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-grub/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/pv-grub-$(XEN_TARGET_ARCH).gz"
+install-xenstore: xenstore-stubdom
+ $(INSTALL_DIR) "$(DESTDIR)/usr/lib/xen/boot"
+ $(INSTALL_PROG) mini-os-$(XEN_TARGET_ARCH)-xenstore/mini-os.gz "$(DESTDIR)/usr/lib/xen/boot/xenstore-stubdom.gz"
+
#######
# clean
#######
@@ -390,12 +411,14 @@ clean:
rm -fr mini-os-$(XEN_TARGET_ARCH)-c
rm -fr mini-os-$(XEN_TARGET_ARCH)-caml
rm -fr mini-os-$(XEN_TARGET_ARCH)-grub
+ rm -fr mini-os-$(XEN_TARGET_ARCH)-xenstore
$(CROSS_MAKE) -C caml clean
$(CROSS_MAKE) -C c clean
rm -fr grub-$(XEN_TARGET_ARCH)
rm -f $(STUBDOMPATH)
[ ! -d libxc-$(XEN_TARGET_ARCH) ] || $(CROSS_MAKE) -C libxc-$(XEN_TARGET_ARCH) clean
-[ ! -d ioemu ] || $(CROSS_MAKE) -C ioemu clean
+ -[ ! -d xenstore ] || $(CROSS_MAKE) -C xenstore clean
# clean the cross-compilation result
.PHONY: crossclean
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 17/21] stubdom: enable xenstored build
2012-01-20 20:47 ` [PATCH 17/21] stubdom: enable xenstored build Daniel De Graaf
@ 2012-01-23 13:17 ` Ian Campbell
0 siblings, 0 replies; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 13:17 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: xen-devel
On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> ---
> extras/mini-os/apps/xenstore.mk | 8 ++++++++
> stubdom/Makefile | 29 ++++++++++++++++++++++++++---
> 2 files changed, 34 insertions(+), 3 deletions(-)
> create mode 100644 extras/mini-os/apps/xenstore.mk
>
> diff --git a/extras/mini-os/apps/xenstore.mk b/extras/mini-os/apps/xenstore.mk
> new file mode 100644
> index 0000000..26ff9a6
> --- /dev/null
> +++ b/extras/mini-os/apps/xenstore.mk
> @@ -0,0 +1,8 @@
> +CONFIG_BLKFRONT=n
> +CONFIG_NETFRONT=n
> +CONFIG_FBFRONT=n
> +CONFIG_KBDFRONT=n
> +CONFIG_XENBUS=n
I see now why you added this possibility.
> +
> +lwip=n
> +DEF_CPPFLAGS := $(filter-out -DHAVE_LWIP,$(DEF_CPPFLAGS))
> diff --git a/stubdom/Makefile b/stubdom/Makefile
> index 7989f31..0718e50 100644
> --- a/stubdom/Makefile
> +++ b/stubdom/Makefile
> @@ -74,14 +74,14 @@ TARGET_CPPFLAGS += -I$(XEN_ROOT)/xen/include
>
> TARGET_LDFLAGS += -nostdlib -L$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib
>
> -TARGETS=ioemu c caml grub
> +TARGETS=ioemu c caml grub xenstore
>
> CROSS_MAKE := $(MAKE) DESTDIR=
>
> .PHONY: all
> all: build
> ifeq ($(STUBDOM_SUPPORTED),1)
> -build: genpath ioemu-stubdom c-stubdom pv-grub
> +build: genpath ioemu-stubdom c-stubdom pv-grub xenstore-stubdom
> else
> build: genpath
> endif
> @@ -262,6 +262,11 @@ mk-headers-$(XEN_TARGET_ARCH): ioemu/linkfarm.stamp
> ln -sf $(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/*.c . && \
> ln -sf $(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/*.h . && \
> ln -sf $(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/Makefile . )
> + mkdir -p xenstore
> + [ -h xenstore/Makefile ] || ( cd xenstore && \
> + ln -sf $(XEN_ROOT)/tools/xenstore/*.c . && \
> + ln -sf $(XEN_ROOT)/tools/xenstore/*.h . && \
> + ln -sf $(XEN_ROOT)/tools/xenstore/Makefile . )
> $(CROSS_MAKE) -C $(MINI_OS) links
> touch mk-headers-$(XEN_TARGET_ARCH)
>
> @@ -334,6 +339,14 @@ grub: grub-upstream $(CROSS_ROOT)
> mkdir -p grub-$(XEN_TARGET_ARCH)
> CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(CROSS_MAKE) -C $@ OBJ_DIR=$(CURDIR)/grub-$(XEN_TARGET_ARCH)
>
> +##########
> +# xenstore
> +##########
> +
> +.PHONY: xenstore
> +xenstore: $(CROSS_ROOT)
> + CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(CROSS_MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip xenstored.a CONFIG_STUBDOM=y
> +
> ########
> # minios
> ########
> @@ -355,12 +368,16 @@ c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxc c
> pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxc grub
> DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_APP=grub $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub-$(XEN_TARGET_ARCH)/main.a
>
> +.PHONY: xenstore-stubdom
> +xenstore-stubdom: mini-os-$(XEN_TARGET_ARCH)-xenstore libxc xenstore
> + DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_APP=xenstore $(CROSS_MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS=$(CURDIR)/xenstore/xenstored.a
> +
> #########
> # install
> #########
>
> ifeq ($(STUBDOM_SUPPORTED),1)
> -install: genpath install-readme install-ioemu install-grub
> +install: genpath install-readme install-ioemu install-grub install-xenstore
> else
> install: genpath
> endif
> @@ -379,6 +396,10 @@ install-grub: pv-grub
> $(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
> $(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-grub/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/pv-grub-$(XEN_TARGET_ARCH).gz"
>
> +install-xenstore: xenstore-stubdom
> + $(INSTALL_DIR) "$(DESTDIR)/usr/lib/xen/boot"
> + $(INSTALL_PROG) mini-os-$(XEN_TARGET_ARCH)-xenstore/mini-os.gz "$(DESTDIR)/usr/lib/xen/boot/xenstore-stubdom.gz"
> +
> #######
> # clean
> #######
> @@ -390,12 +411,14 @@ clean:
> rm -fr mini-os-$(XEN_TARGET_ARCH)-c
> rm -fr mini-os-$(XEN_TARGET_ARCH)-caml
> rm -fr mini-os-$(XEN_TARGET_ARCH)-grub
> + rm -fr mini-os-$(XEN_TARGET_ARCH)-xenstore
> $(CROSS_MAKE) -C caml clean
> $(CROSS_MAKE) -C c clean
> rm -fr grub-$(XEN_TARGET_ARCH)
> rm -f $(STUBDOMPATH)
> [ ! -d libxc-$(XEN_TARGET_ARCH) ] || $(CROSS_MAKE) -C libxc-$(XEN_TARGET_ARCH) clean
> -[ ! -d ioemu ] || $(CROSS_MAKE) -C ioemu clean
> + -[ ! -d xenstore ] || $(CROSS_MAKE) -C xenstore clean
>
> # clean the cross-compilation result
> .PHONY: crossclean
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH 18/21] xenstored: add --event parameter for bootstrapping
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (16 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 17/21] stubdom: enable xenstored build Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 19/21] xenstored: use domain_is_unprivileged instead of checking conn->id Daniel De Graaf
` (3 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
When xenstored is run in a minios domain, it needs a bootstrap
connection to dom0 so that additional domain introduce messages can be
sent to it.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
tools/xenstore/xenstored_core.c | 5 +++++
tools/xenstore/xenstored_core.h | 1 +
tools/xenstore/xenstored_domain.c | 11 +++++++++++
3 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 66ca555..aad0298 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -1775,6 +1775,7 @@ static struct option options[] = {
{ "no-domain-init", 0, NULL, 'D' },
{ "entry-nb", 1, NULL, 'E' },
{ "pid-file", 1, NULL, 'F' },
+ { "event", 1, NULL, 'e' },
{ "help", 0, NULL, 'H' },
{ "no-fork", 0, NULL, 'N' },
{ "output-pid", 0, NULL, 'P' },
@@ -1788,6 +1789,7 @@ static struct option options[] = {
{ NULL, 0, NULL, 0 } };
extern void dump_conn(struct connection *conn);
+int dom0_event = 0;
int main(int argc, char *argv[])
{
@@ -1847,6 +1849,9 @@ int main(int argc, char *argv[])
case 'W':
quota_nb_watch_per_domain = strtol(optarg, NULL, 10);
break;
+ case 'e':
+ dom0_event = strtol(optarg, NULL, 10);
+ break;
}
}
if (optind != argc)
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index c487089..d3040ba 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -168,6 +168,7 @@ void trace(const char *fmt, ...);
void dtrace_io(const struct connection *conn, const struct buffered_data *data, int out);
extern int event_fd;
+extern int dom0_event;
/* Map the kernel's xenstore page. */
void *xenbus_map(void);
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index 435f76a..6a0dbc2 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -602,6 +602,17 @@ void restore_existing_connections(void)
#ifdef __MINIOS__
static int dom0_init(void)
{
+ struct domain *domain;
+ int domid = 0;
+ evtchn_port_t port = dom0_event;
+
+ domain = new_domain(NULL, domid, port);
+ domain->interface = xc_gnttab_map_grant_ref(*xcg_handle, domid,
+ GNTTAB_RESERVED_XENSTORE, PROT_READ|PROT_WRITE);
+ talloc_steal(domain->conn, domain);
+
+ xc_evtchn_notify(xce_handle, domain->port);
+
return 0;
}
#else
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 19/21] xenstored: use domain_is_unprivileged instead of checking conn->id
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (17 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 18/21] xenstored: add --event parameter for bootstrapping Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 20/21] xenstored: add --priv-domid parameter Daniel De Graaf
` (2 subsequent siblings)
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
This centralizes all the permission checking for privileged domains in
preparation for allowing domains other than dom0 to be privileged.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
tools/xenstore/xenstored_core.c | 6 +++---
tools/xenstore/xenstored_domain.c | 8 ++++----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index aad0298..4897c97 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -492,7 +492,7 @@ static enum xs_perm_type perm_for_conn(struct connection *conn,
mask &= ~XS_PERM_WRITE;
/* Owners and tools get it all... */
- if (!conn->id || perms[0].id == conn->id
+ if (!domain_is_unprivileged(conn) || perms[0].id == conn->id
|| (conn->target && perms[0].id == conn->target->id))
return (XS_PERM_READ|XS_PERM_WRITE|XS_PERM_OWNER) & mask;
@@ -830,11 +830,11 @@ static struct node *construct_node(struct connection *conn, const char *name)
node->tdb = tdb_context(conn);
node->name = talloc_strdup(node, name);
- /* Inherit permissions, except domains own what they create */
+ /* Inherit permissions, except unprivileged domains own what they create */
node->num_perms = parent->num_perms;
node->perms = talloc_memdup(node, parent->perms,
node->num_perms * sizeof(node->perms[0]));
- if (conn && conn->id)
+ if (domain_is_unprivileged(conn))
node->perms[0].id = conn->id;
/* No children, no data */
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index 6a0dbc2..d89528f 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -356,7 +356,7 @@ void do_introduce(struct connection *conn, struct buffered_data *in)
return;
}
- if (conn->id != 0 || !conn->can_write) {
+ if (domain_is_unprivileged(conn) || !conn->can_write) {
send_error(conn, EACCES);
return;
}
@@ -420,7 +420,7 @@ void do_set_target(struct connection *conn, struct buffered_data *in)
return;
}
- if (conn->id != 0 || !conn->can_write) {
+ if (domain_is_unprivileged(conn) || !conn->can_write) {
send_error(conn, EACCES);
return;
}
@@ -472,7 +472,7 @@ void do_release(struct connection *conn, const char *domid_str)
return;
}
- if (conn->id != 0) {
+ if (domain_is_unprivileged(conn)) {
send_error(conn, EACCES);
return;
}
@@ -509,7 +509,7 @@ void do_resume(struct connection *conn, const char *domid_str)
return;
}
- if (conn->id != 0) {
+ if (domain_is_unprivileged(conn)) {
send_error(conn, EACCES);
return;
}
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 20/21] xenstored: add --priv-domid parameter
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (18 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 19/21] xenstored: use domain_is_unprivileged instead of checking conn->id Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-20 20:47 ` [PATCH 21/21] xenstored: Add stub domain builder Daniel De Graaf
2012-01-20 20:47 ` [PATCH] xenbus: Add support for xenbus backend in stub domain Daniel De Graaf
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
This parameter identifies an alternative service domain which has
superuser access to the xenstore database, which is currently required
to set up a new domain's xenstore entries.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
tools/xenstore/xenstored_core.c | 5 +++++
tools/xenstore/xenstored_core.h | 1 +
tools/xenstore/xenstored_domain.c | 2 +-
3 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 4897c97..7ad6db8 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -1778,6 +1778,7 @@ static struct option options[] = {
{ "event", 1, NULL, 'e' },
{ "help", 0, NULL, 'H' },
{ "no-fork", 0, NULL, 'N' },
+ { "priv-domid", 1, NULL, 'p' },
{ "output-pid", 0, NULL, 'P' },
{ "entry-size", 1, NULL, 'S' },
{ "trace-file", 1, NULL, 'T' },
@@ -1790,6 +1791,7 @@ static struct option options[] = {
extern void dump_conn(struct connection *conn);
int dom0_event = 0;
+int priv_domid = 0;
int main(int argc, char *argv[])
{
@@ -1852,6 +1854,9 @@ int main(int argc, char *argv[])
case 'e':
dom0_event = strtol(optarg, NULL, 10);
break;
+ case 'p':
+ priv_domid = strtol(optarg, NULL, 10);
+ break;
}
}
if (optind != argc)
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index d3040ba..03e2e48 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -169,6 +169,7 @@ void dtrace_io(const struct connection *conn, const struct buffered_data *data,
extern int event_fd;
extern int dom0_event;
+extern int priv_domid;
/* Map the kernel's xenstore page. */
void *xenbus_map(void);
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index d89528f..8c215fb 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -261,7 +261,7 @@ bool domain_can_read(struct connection *conn)
bool domain_is_unprivileged(struct connection *conn)
{
- return (conn && conn->domain && conn->domain->domid != 0);
+ return (conn && conn->domain && conn->domain->domid != 0 && conn->domain->domid != priv_domid);
}
bool domain_can_write(struct connection *conn)
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 21/21] xenstored: Add stub domain builder
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (19 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 20/21] xenstored: add --priv-domid parameter Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
2012-01-23 13:52 ` Ian Campbell
2012-01-20 20:47 ` [PATCH] xenbus: Add support for xenbus backend in stub domain Daniel De Graaf
21 siblings, 1 reply; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
tools/include/xen-sys/Linux/xenbus_dev.h | 44 ++++++++++++++
tools/xenstore/Makefile | 9 ++-
tools/xenstore/init-xenstore-domain.c | 94 ++++++++++++++++++++++++++++++
3 files changed, 145 insertions(+), 2 deletions(-)
create mode 100644 tools/include/xen-sys/Linux/xenbus_dev.h
create mode 100644 tools/xenstore/init-xenstore-domain.c
diff --git a/tools/include/xen-sys/Linux/xenbus_dev.h b/tools/include/xen-sys/Linux/xenbus_dev.h
new file mode 100644
index 0000000..bbee8c6
--- /dev/null
+++ b/tools/include/xen-sys/Linux/xenbus_dev.h
@@ -0,0 +1,44 @@
+/******************************************************************************
+ * evtchn.h
+ *
+ * Interface to /dev/xen/xenbus_backend.
+ *
+ * Copyright (c) 2011 Bastian Blank <waldi@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation; or, when distributed
+ * separately from the Linux kernel or incorporated into other
+ * software packages, subject to the following license:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __LINUX_XEN_XENBUS_DEV_H__
+#define __LINUX_XEN_XENBUS_DEV_H__
+
+#include <linux/ioctl.h>
+
+#define IOCTL_XENBUS_BACKEND_EVTCHN \
+ _IOC(_IOC_NONE, 'B', 0, 0)
+
+#define IOCTL_XENBUS_BACKEND_SETUP \
+ _IOC(_IOC_NONE, 'B', 1, 0)
+
+#endif /* __LINUX_XEN_XENBUS_DEV_H__ */
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 3a061d6..9b411a5 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -26,7 +26,7 @@ LIBXENSTORE := libxenstore.a
xenstore xenstore-control: CFLAGS += -static
endif
-ALL_TARGETS = libxenstore.so libxenstore.a clients xs_tdb_dump xenstored
+ALL_TARGETS = libxenstore.so libxenstore.a clients xs_tdb_dump xenstored init-xenstore-domain
ifdef CONFIG_STUBDOM
CFLAGS += -DNO_SOCKETS=1 -DNO_LOCAL_XENBUS=1 -DNO_SYSLOG=1 -DNO_REOPEN_LOG=1
@@ -50,6 +50,11 @@ xenstored_probes.o: xenstored_solaris.o
CFLAGS += -DHAVE_DTRACE=1
endif
+init-xenstore-domain.o: CFLAGS += $(CFLAGS_libxenguest)
+
+init-xenstore-domain: init-xenstore-domain.o $(LIBXENSTORE)
+ $(CC) $(LDFLAGS) $^ $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) -o $@ $(APPEND_LDFLAGS)
+
xenstored: $(XENSTORED_OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
@@ -85,7 +90,7 @@ libxenstore.a: xs.o xs_lib.o
clean:
rm -f *.a *.o *.opic *.so* xenstored_probes.h
rm -f xenstored xs_random xs_stress xs_crashme
- rm -f xs_tdb_dump xenstore-control
+ rm -f xs_tdb_dump xenstore-control init-xenstore-domain
rm -f xenstore $(CLIENTS)
$(RM) $(DEPS)
diff --git a/tools/xenstore/init-xenstore-domain.c b/tools/xenstore/init-xenstore-domain.c
new file mode 100644
index 0000000..f6c31d0
--- /dev/null
+++ b/tools/xenstore/init-xenstore-domain.c
@@ -0,0 +1,94 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <xenctrl.h>
+#include <xc_dom.h>
+#include <xs.h>
+#include <xen/sys/xenbus_dev.h>
+
+static uint32_t domid = -1;
+
+static int build(xc_interface *xch, char** argv)
+{
+ char cmdline[512];
+ uint32_t ssid;
+ xen_domain_handle_t handle = { 0 };
+ int rv;
+ int xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
+ struct xc_dom_image *dom;
+ int maxmem = atoi(argv[2]);
+ int limit_kb = (maxmem + 1)*1024;
+
+ rv = xc_flask_context_to_sid(xch, argv[3], strlen(argv[3]), &ssid);
+ if (rv) return rv;
+ rv = xc_domain_create(xch, ssid, handle, 0, &domid);
+ if (rv) return rv;
+ rv = xc_domain_max_vcpus(xch, domid, 1);
+ if (rv) return rv;
+ rv = xc_domain_setmaxmem(xch, domid, limit_kb);
+ if (rv) return rv;
+ rv = xc_domain_set_memmap_limit(xch, domid, limit_kb);
+ if (rv) return rv;
+
+ rv = ioctl(xs_fd, IOCTL_XENBUS_BACKEND_SETUP, domid);
+ if (rv < 0) return rv;
+ snprintf(cmdline, 512, "--event %d", rv);
+
+ dom = xc_dom_allocate(xch, cmdline, NULL);
+ rv = xc_dom_kernel_file(dom, argv[1]);
+ if (rv) return rv;
+ rv = xc_dom_boot_xen_init(dom, xch, domid);
+ if (rv) return rv;
+ rv = xc_dom_parse_image(dom);
+ if (rv) return rv;
+ rv = xc_dom_mem_init(dom, maxmem);
+ if (rv) return rv;
+ rv = xc_dom_boot_mem_init(dom);
+ if (rv) return rv;
+ rv = xc_dom_build_image(dom);
+ if (rv) return rv;
+ rv = xc_dom_boot_image(dom);
+ if (rv) return rv;
+
+ xc_dom_release(dom);
+
+ rv = xc_domain_set_virq_handler(xch, domid, VIRQ_DOM_EXC);
+ if (rv) return rv;
+ rv = xc_domain_unpause(xch, domid);
+ if (rv) return rv;
+
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ xc_interface *xch;
+ struct xs_handle *xsh;
+ char buf[16];
+ int rv;
+
+ if (argc != 4) {
+ printf("Use: %s <xenstore-kernel> <memory_mb> <flask-label>\n", argv[0]);
+ return 2;
+ }
+
+ xch = xc_interface_open(NULL, NULL, 0);
+ if (!xch) return 1;
+
+ rv = build(xch, argv);
+
+ xc_interface_close(xch);
+
+ if (rv) return 1;
+
+ xsh = xs_open(0);
+ rv = snprintf(buf, 16, "%d", domid);
+ xs_write(xsh, XBT_NULL, "/tool/xenstored/domid", buf, rv);
+ xs_daemon_close(xsh);
+
+ return 0;
+}
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 21/21] xenstored: Add stub domain builder
2012-01-20 20:47 ` [PATCH 21/21] xenstored: Add stub domain builder Daniel De Graaf
@ 2012-01-23 13:52 ` Ian Campbell
2012-01-23 14:26 ` Stefano Stabellini
0 siblings, 1 reply; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 13:52 UTC (permalink / raw)
To: Daniel De Graaf; +Cc: xen-devel
On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
> +int main(int argc, char** argv)
> +{
> + xc_interface *xch;
> + struct xs_handle *xsh;
> + char buf[16];
> + int rv;
> +
> + if (argc != 4) {
> + printf("Use: %s <xenstore-kernel> <memory_mb> <flask-label>\n", argv[0]);
> + return 2;
> + }
> +
> + xch = xc_interface_open(NULL, NULL, 0);
> + if (!xch) return 1;
> +
> + rv = build(xch, argv);
> +
> + xc_interface_close(xch);
> +
> + if (rv) return 1;
Did you consider forking a daemon at this point to sit and drain the
domains console ring into a log file? (instead of/as well as your patch
08/21).
The following bit would remain in the existing process so there would be
no risk of deadlock AFAICT.
> +
> + xsh = xs_open(0);
> + rv = snprintf(buf, 16, "%d", domid);
> + xs_write(xsh, XBT_NULL, "/tool/xenstored/domid", buf, rv);
> + xs_daemon_close(xsh);
> +
> + return 0;
> +}
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 21/21] xenstored: Add stub domain builder
2012-01-23 13:52 ` Ian Campbell
@ 2012-01-23 14:26 ` Stefano Stabellini
2012-01-23 14:31 ` Ian Campbell
0 siblings, 1 reply; 41+ messages in thread
From: Stefano Stabellini @ 2012-01-23 14:26 UTC (permalink / raw)
To: Ian Campbell; +Cc: Daniel De Graaf, xen-devel
On Mon, 23 Jan 2012, Ian Campbell wrote:
> On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
> > +int main(int argc, char** argv)
> > +{
> > + xc_interface *xch;
> > + struct xs_handle *xsh;
> > + char buf[16];
> > + int rv;
> > +
> > + if (argc != 4) {
> > + printf("Use: %s <xenstore-kernel> <memory_mb> <flask-label>\n", argv[0]);
> > + return 2;
> > + }
> > +
> > + xch = xc_interface_open(NULL, NULL, 0);
> > + if (!xch) return 1;
> > +
> > + rv = build(xch, argv);
> > +
> > + xc_interface_close(xch);
> > +
> > + if (rv) return 1;
>
> Did you consider forking a daemon at this point to sit and drain the
> domains console ring into a log file? (instead of/as well as your patch
> 08/21).
I don't know if there are any benefits in basing this stub domain builder
on libxl but if it was based on libxl you could just add a pv console
device with consback = LIBXL_CONSOLE_BACKEND_IOEMU and then set output =
"file:/path/to/file", and you would have your logging going to that
file.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 21/21] xenstored: Add stub domain builder
2012-01-23 14:26 ` Stefano Stabellini
@ 2012-01-23 14:31 ` Ian Campbell
0 siblings, 0 replies; 41+ messages in thread
From: Ian Campbell @ 2012-01-23 14:31 UTC (permalink / raw)
To: Stefano Stabellini; +Cc: Daniel De Graaf, xen-devel
On Mon, 2012-01-23 at 14:26 +0000, Stefano Stabellini wrote:
> On Mon, 23 Jan 2012, Ian Campbell wrote:
> > On Fri, 2012-01-20 at 20:47 +0000, Daniel De Graaf wrote:
> > > +int main(int argc, char** argv)
> > > +{
> > > + xc_interface *xch;
> > > + struct xs_handle *xsh;
> > > + char buf[16];
> > > + int rv;
> > > +
> > > + if (argc != 4) {
> > > + printf("Use: %s <xenstore-kernel> <memory_mb> <flask-label>\n", argv[0]);
> > > + return 2;
> > > + }
> > > +
> > > + xch = xc_interface_open(NULL, NULL, 0);
> > > + if (!xch) return 1;
> > > +
> > > + rv = build(xch, argv);
> > > +
> > > + xc_interface_close(xch);
> > > +
> > > + if (rv) return 1;
> >
> > Did you consider forking a daemon at this point to sit and drain the
> > domains console ring into a log file? (instead of/as well as your patch
> > 08/21).
>
> I don't know if there are any benefits in basing this stub domain builder
> on libxl but if it was based on libxl you could just add a pv console
> device with consback = LIBXL_CONSOLE_BACKEND_IOEMU and then set output =
> "file:/path/to/file", and you would have your logging going to that
> file.
This builder cannot use xenstore and therefore cannot use xenconsoled
(which would block waiting for xenstored) either.
Ian.
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH] xenbus: Add support for xenbus backend in stub domain
2012-01-20 20:47 [PATCH v3 00/21] Xenstore stub domain Daniel De Graaf
` (20 preceding siblings ...)
2012-01-20 20:47 ` [PATCH 21/21] xenstored: Add stub domain builder Daniel De Graaf
@ 2012-01-20 20:47 ` Daniel De Graaf
21 siblings, 0 replies; 41+ messages in thread
From: Daniel De Graaf @ 2012-01-20 20:47 UTC (permalink / raw)
To: xen-devel; +Cc: Daniel De Graaf
This adds an ioctl to the /dev/xen/xenbus_backend device allowing the
xenbus backend to be started after the kernel has booted. This is
intended to allow dom0 to start another domain to run xenstore.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
drivers/xen/xenbus/xenbus_comms.c | 6 ++++
drivers/xen/xenbus/xenbus_comms.h | 1 +
drivers/xen/xenbus/xenbus_dev_backend.c | 51 +++++++++++++++++++++++++++++++
include/xen/grant_table.h | 2 +
include/xen/xenbus_dev.h | 3 ++
5 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/drivers/xen/xenbus/xenbus_comms.c b/drivers/xen/xenbus/xenbus_comms.c
index 2eff7a6..52fe7ad 100644
--- a/drivers/xen/xenbus/xenbus_comms.c
+++ b/drivers/xen/xenbus/xenbus_comms.c
@@ -234,3 +234,9 @@ int xb_init_comms(void)
return 0;
}
+
+void xb_deinit_comms(void)
+{
+ unbind_from_irqhandler(xenbus_irq, &xb_waitq);
+ xenbus_irq = 0;
+}
diff --git a/drivers/xen/xenbus/xenbus_comms.h b/drivers/xen/xenbus/xenbus_comms.h
index 6e42800..c8abd3b 100644
--- a/drivers/xen/xenbus/xenbus_comms.h
+++ b/drivers/xen/xenbus/xenbus_comms.h
@@ -35,6 +35,7 @@
int xs_init(void);
int xb_init_comms(void);
+void xb_deinit_comms(void);
/* Low level routines. */
int xb_write(const void *data, unsigned len);
diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c
index 3d3be78..be738c4 100644
--- a/drivers/xen/xenbus/xenbus_dev_backend.c
+++ b/drivers/xen/xenbus/xenbus_dev_backend.c
@@ -8,7 +8,11 @@
#include <xen/xen.h>
#include <xen/page.h>
+#include <xen/xenbus.h>
#include <xen/xenbus_dev.h>
+#include <xen/grant_table.h>
+#include <xen/events.h>
+#include <asm/xen/hypervisor.h>
#include "xenbus_comms.h"
@@ -22,6 +26,50 @@ static int xenbus_backend_open(struct inode *inode, struct file *filp)
return nonseekable_open(inode, filp);
}
+static long xenbus_alloc(domid_t domid)
+{
+ struct evtchn_alloc_unbound arg;
+ int err = -EEXIST;
+
+ xs_suspend();
+
+ /* If xenstored_ready is nonzero, that means we have already talked to
+ * xenstore and set up watches. These watches will be restored by
+ * xs_resume, but that requires communication over the port established
+ * below that is not visible to anyone until the ioctl returns.
+ *
+ * This can be resolved by splitting the ioctl into two parts
+ * (postponing the resume until xenstored is active) but this is
+ * unnecessarily complex for the intended use where xenstored is only
+ * started once - so return -EEXIST if it's already running.
+ */
+ if (xenstored_ready)
+ goto out_err;
+
+ gnttab_grant_foreign_access_ref(GNTTAB_RESERVED_XENSTORE, domid,
+ virt_to_mfn(xen_store_interface), 0 /* writable */);
+
+ arg.dom = DOMID_SELF;
+ arg.remote_dom = domid;
+
+ err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &arg);
+ if (err)
+ goto out_err;
+
+ if (xen_store_evtchn > 0)
+ xb_deinit_comms();
+
+ xen_store_evtchn = arg.port;
+
+ xs_resume();
+
+ return arg.port;
+
+ out_err:
+ xs_suspend_cancel();
+ return err;
+}
+
static long xenbus_backend_ioctl(struct file *file, unsigned int cmd, unsigned long data)
{
if (!capable(CAP_SYS_ADMIN))
@@ -33,6 +81,9 @@ static long xenbus_backend_ioctl(struct file *file, unsigned int cmd, unsigned l
return xen_store_evtchn;
return -ENODEV;
+ case IOCTL_XENBUS_BACKEND_SETUP:
+ return xenbus_alloc(data);
+
default:
return -ENOTTY;
}
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 15f8a00..11e27c3 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -46,6 +46,8 @@
#include <xen/features.h>
+#define GNTTAB_RESERVED_XENSTORE 1
+
/* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
#define NR_GRANT_FRAMES 4
diff --git a/include/xen/xenbus_dev.h b/include/xen/xenbus_dev.h
index ac5f0fe..bbee8c6 100644
--- a/include/xen/xenbus_dev.h
+++ b/include/xen/xenbus_dev.h
@@ -38,4 +38,7 @@
#define IOCTL_XENBUS_BACKEND_EVTCHN \
_IOC(_IOC_NONE, 'B', 0, 0)
+#define IOCTL_XENBUS_BACKEND_SETUP \
+ _IOC(_IOC_NONE, 'B', 1, 0)
+
#endif /* __LINUX_XEN_XENBUS_DEV_H__ */
--
1.7.7.5
^ permalink raw reply related [flat|nested] 41+ messages in thread