Commit d6c9840b authored by Yathindra Naik's avatar Yathindra Naik

Fix a race condition between domain_create and cap_grant.

parent 280f6bc1
......@@ -421,7 +421,15 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info,
rc = ERROR_FAIL;
goto out;
}
#ifdef CONFIG_XENCAP
libxl_capabilities *cap = d_config.cap;
ret = libxl_domain_setcap(ctx, cap, domid);
if (ret) {
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot grant capabilities: %d", ret);
ret = ERROR_FAIL;
goto error_out;
}
#endif
ret = xc_cpupool_movedomain(ctx->xch, info->poolid, *domid);
if (ret < 0) {
LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, ret, "domain move fail");
......@@ -649,6 +657,17 @@ static void initiate_domain_create(libxl__egc *egc,
goto error_out;
}
#if 0
#ifdef CONFIG_XENCAP
libxl_capabilities *cap = d_config.cap;
ret = libxl_domain_setcap(ctx, cap, domid);
if (ret) {
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot grant capabilities: %d", ret);
ret = ERROR_FAIL;
goto error_out;
}
#endif
#endif
dcs->guest_domid = domid;
dcs->dmss.dm.guest_domid = 0; /* means we haven't spawned */
......
......@@ -1998,10 +1998,12 @@ start:
libxl_domain_unpause(ctx, domid);
#ifdef CONFIG_XENCAP
#if 0
libxl_capabilities *cap = d_config.cap;
ret = libxl_domain_setcap(ctx, cap, domid);
if ( ret != 0 )
printf("libxl_domain_setcap failed!\n");
#endif
#endif
ret = domid; /* caller gets success in parent */
......
......@@ -620,18 +620,14 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
void arch_domain_destroy(struct domain *d)
{
unsigned int i;
printk("In arch_domain_destroy()\n");
if ( is_hvm_domain(d) )
hvm_domain_destroy(d);
else
xfree(d->arch.pv_domain.e820);
printk("after hvm_domain_destroy()\n");
free_domain_pirqs(d);
if ( !is_idle_domain(d) )
iommu_domain_destroy(d);
printk("After iommu_domain_destroy()\n");
paging_final_teardown(d);
printk("After ()\n");
for ( i = 0; i < PDPT_L2_ENTRIES; ++i )
{
if ( perdomain_pt_page(d, i) )
......
......@@ -114,7 +114,6 @@ long arch_do_domctl(
page = mfn_to_page(mfn);
printk("Invoking xsm_getpageframeinfo()\n");
ret = xsm_getpageframeinfo(d);
if ( ret )
{
......@@ -377,7 +376,6 @@ long arch_do_domctl(
ret = -EINVAL;
if ( d != NULL )
{
printk("Invoking xsm_getmemlist()\n");
ret = xsm_getmemlist(d);
if ( ret )
{
......@@ -428,7 +426,6 @@ long arch_do_domctl(
if ( unlikely(d == NULL) )
break;
printk("Invoking xsm_hypercall_init()\n");
ret = xsm_hypercall_init(d);
if ( ret )
{
......@@ -468,7 +465,6 @@ long arch_do_domctl(
if ( (d = rcu_lock_domain_by_id(domctl->domain)) == NULL )
break;
printk("Invoking xsm_hvmcontext()\n");
ret = xsm_hvmcontext(d, domctl->cmd);
if ( ret )
goto sethvmcontext_out;
......@@ -589,7 +585,6 @@ long arch_do_domctl(
if ( (d = rcu_lock_domain_by_id(domctl->domain)) == NULL )
break;
printk("Invoking xsm_address_size()\n");
ret = xsm_address_size(d, domctl->cmd);
if ( ret )
{
......@@ -648,7 +643,6 @@ long arch_do_domctl(
if ( (d = rcu_lock_domain_by_id(domctl->domain)) == NULL )
break;
printk("Invoking xsm_machine_address_size()\n");
ret = xsm_machine_address_size(d, domctl->cmd);
if ( ret )
goto set_machine_address_size_out;
......@@ -701,7 +695,6 @@ long arch_do_domctl(
if ( (d = rcu_lock_domain_by_id(domctl->domain)) == NULL )
break;
printk("Invoking xsm_sendtrigger()\n");
ret = xsm_sendtrigger(d);
if ( ret )
goto sendtrigger_out;
......
......@@ -1121,17 +1121,6 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domctl_t) u_domctl)
break;
}
/* create the cap space for the to domain */
if ( (ret = xsm_domain_create(to, 1234)) != 0 )
{
if ( to->cap_space == NULL )
{
TT_ERR("xsm_domain_create failed to create cap_space for to_domain in xc_cap_grant().\n");
rcu_unlock_domain(to);
break;
}
}
type = op->u.cap_grant.type;
list = op->u.cap_grant.list;
size = op->u.cap_grant.size;
......
......@@ -576,7 +576,6 @@ __gnttab_map_grant_ref(
return;
}
printk("Invoking xsm_grant_mapref()\n");
rc = xsm_grant_mapref(ld, rd, op->flags);
if ( rc )
{
......@@ -897,7 +896,6 @@ __gnttab_unmap_common(
return;
}
printk("Invoking xsm_grant_unmapref()\n");
rc = xsm_grant_unmapref(ld, rd);
if ( rc )
{
......@@ -2291,7 +2289,6 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE(gnttab_get_status_frames_t) uop,
op.status = PTR_ERR(d);
goto out1;
}
printk("Invoking xsm_grant_setup()\n");
rc = xsm_grant_setup(current->domain, d);
if ( rc ) {
op.status = GNTST_permission_denied;
......
......@@ -209,7 +209,6 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysctl_t) u_sysctl)
case XEN_SYSCTL_availheap:
{
printk("Invoking xsm_availheap()\n");
ret = xsm_availheap();
if ( ret )
break;
......@@ -335,7 +334,6 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysctl_t) u_sysctl)
case XEN_SYSCTL_scheduler_op:
{
printk("Invoking xsm_sched_op()\n");
ret = xsm_sched_op();
if ( ret )
break;
......
......@@ -61,9 +61,9 @@ int cap_init(void)
{
int ret = 0;
printk("In cap_init()\n");
TT_DBG("In cap_init()\n");
printk(" -cap_share_boot_info_page()\n");
TT_DBG(" -cap_share_boot_info_page()\n");
/* Initialize the boot info page. */
ret = cap_share_boot_info_page();
......@@ -71,7 +71,7 @@ int cap_init(void)
if ( ret == -1 )
return ret; /* Failed */
printk(" -cap_init_hypercalls()\n");
TT_DBG(" -cap_init_hypercalls()\n");
/* Initialize the capabilities for hypercalls */
ret = cap_init_hypercalls();
......@@ -79,7 +79,7 @@ int cap_init(void)
/* TO-DO: Initialize other resources here with
* capabilities.
*/
printk("Leaving cap_init()\n");
TT_DBG("Leaving cap_init()\n");
return ret;
}
......@@ -88,11 +88,11 @@ int cap_share_boot_info_page()
unsigned long order, cap_boot_info_size;
int i, ret = 0;
printk("In cap_share_boot_info_page()\n");
printk(" - get_order_from_bytes()\n");
TT_DBG("In cap_share_boot_info_page()\n");
TT_DBG(" - get_order_from_bytes()\n");
order = get_order_from_bytes(sizeof(struct cap_boot_info));
printk(" - alloc_xenheap_pages()\n");
TT_DBG(" - alloc_xenheap_pages()\n");
/* Allocate page for cap_boot_info */
if ( (CAP_BOOT_INFO = alloc_xenheap_pages(order,0)) == NULL ) {
......@@ -102,7 +102,7 @@ int cap_share_boot_info_page()
cap_boot_info_size = 1 << order;
printk(" - share_xen_page_with_privileged_guests()\n");
TT_DBG(" - share_xen_page_with_privileged_guests()\n");
/* Share cap_boot_info with the hypervisor */
for ( i = 0; i < cap_boot_info_size; ++i )
......@@ -111,7 +111,7 @@ int cap_share_boot_info_page()
virt_to_page(CAP_BOOT_INFO) + i, XENSHARE_readonly);
}
printk("Leaving cap_share_boot_info_page()\n");
TT_DBG("Leaving cap_share_boot_info_page()\n");
cleanup:
#if 0
......@@ -130,7 +130,7 @@ int cap_init_hypercalls()
int i;
init_rand(41);
printk("In cap_init_hypercalls()\n");
TT_DBG("In cap_init_hypercalls()\n");
/* capability is a random number. */
for ( i = 0; i < NUM_HYPERCALLS; ++i )
......@@ -138,7 +138,7 @@ int cap_init_hypercalls()
CAP_BOOT_INFO->cap_hypercalls[i].magic = rand_cmwc();
}
printk("Leaving cap_init_hypercalls()\n");
TT_DBG("Leaving cap_init_hypercalls()\n");
return 0;
}
......@@ -146,7 +146,7 @@ int cap_create(struct domain *d, struct capability *cap)
{
init_rand(41);
printk("In cap_create()\n");
TT_DBG("In cap_create()\n");
cap->magic = rand_cmwc();
return 0;
......@@ -158,7 +158,7 @@ int cap_grant(struct domain *from, struct domain *to, int type, void *list, int
int i, index;
int *ptr = (int*)list;
printk("In cap_grant()\n");
TT_DBG("In cap_grant()\n");
switch(type)
{
......@@ -169,7 +169,7 @@ int cap_grant(struct domain *from, struct domain *to, int type, void *list, int
index = ptr[i];
to->cap_space->cap_hypercalls[index] = from->cap_space->cap_hypercalls[index];
TT_DBG("Granting Capability: Domain %d, Capability: 0x%x",to->domain_id, from->cap_space->cap_hypercalls[index].magic);
TT_DBG("Granting Capability: Domain %d, Capability: 0x%x\n",to->domain_id, from->cap_space->cap_hypercalls[index].magic);
}
break;
}
......@@ -184,8 +184,8 @@ int cap_check(struct domain *d, int type, struct capability *cap)
if ( d->domain_id != 0 )
{
printk("In cap_check()\n");
printk("Checking Capability: Domain %d, Cap_id: 0x%x\n",d->domain_id, cap->magic);
TT_DBG("In cap_check()\n");
TT_DBG("Checking Capability: Domain %d, Cap_id: 0x%x\n",d->domain_id, cap->magic);
}
switch(type)
{
......
......@@ -86,23 +86,8 @@ extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst);
extern int printk_ratelimit(void);
#ifdef CONFIG_XENCAP
#if 0
#define TT_DBG(_f, _a...) do { \
u64 _now, time_diff; \
u32 __low, __high; \
rdtsc(__low, __high); \
_now = NOW(); \
tt_dbg_last_message = _now; \
time_diff = _now - tt_dbg_last_message; \
/*printk("TT_LOG:(XEN:%llu, %s) " _f, _now, __FUNCTION__, ## _a); */ \
printk("TT_LOG:(XEN:%u.%u,%llu,+%llu, %s) " \
_f, __high, __low, _now, time_diff, __FUNCTION__, ## _a); \
} while (0)
#endif /* 0 */
#define TT_DBG(_f, _a...) do { \
/*printk("TT_LOG:(XEN:%llu, %s) " _f, _now, __FUNCTION__, ## _a); */ \
/*console_force_unlock(); */ \
printk("TT_LOG:(cpu(%d): %s) " \
_f, smp_processor_id(), __FUNCTION__, ## _a); \
} while (0)
......
......@@ -11,7 +11,7 @@
#define __XEN_CAP_H__
#include <xen/sched.h>
//#include <stdlib.h>
#include <xen/lib.h>
/* Capability tokens are random numbers for now. This implementation is taken from wikipedia.
* Source: http://en.wikipedia.org/wiki/Multiply-with-carry
......
......@@ -35,7 +35,7 @@ static int cap_domain_create(struct domain *d, u32 ssidref)
if ( dom_cap_space == NULL )
{
printk("dom_cap_space allocation failed in cap_domain_create()!\n");
TT_DBG("dom_cap_space allocation failed in cap_domain_create()!\n");
return -1;
}
dom_cap_space->cap_hypercalls = xmalloc_array(struct capability, NUM_HYPERCALLS);
......@@ -43,11 +43,11 @@ static int cap_domain_create(struct domain *d, u32 ssidref)
if ( dom_cap_space->cap_hypercalls == NULL )
{
xfree(dom_cap_space);
printk("dom_cap_space->cap_hypercalls allocation failed in cap_domain_create()!\n");
TT_DBG("dom_cap_space->cap_hypercalls allocation failed in cap_domain_create()!\n");
return -1;
}
printk("In cap_domain_create\n");
TT_DBG("In cap_domain_create\n");
/* Dom0 is all-powerful. We'll change this later.
......@@ -62,18 +62,18 @@ static int cap_domain_create(struct domain *d, u32 ssidref)
if ( d->domain_id == 0 )
{
printk("Init'ing capabilities for domain %d\n",d->domain_id);
TT_DBG("Init'ing capabilities for domain %d\n",d->domain_id);
dom_cap_space->cap_hypercalls = CAP_BOOT_INFO->cap_hypercalls;
d->cap_space = dom_cap_space;
return rc;
}
printk("Init'ing cap_space for guest domain: %d\n",d->domain_id);
TT_DBG("Init'ing cap_space for guest domain: %d\n",d->domain_id);
/* Guest domain */
d->cap_space = dom_cap_space;
printk("Returning from cap_domain_create\n");
TT_DBG("Returning from cap_domain_create\n");
return rc;
}
......@@ -93,17 +93,17 @@ static int cap_console_io (struct domain *d, int cmd)
* console access
*/
printk("In cap_console_io()\n");
TT_DBG("In cap_console_io()\n");
cap = &(CAP_BOOT_INFO->cap_hypercalls[1]);
if ( (ret = cap_check(d, 1, cap)) == 1 )
{
printk("cap_check success\nLeaving cap_console_io()\n");
TT_DBG("cap_check success\nLeaving cap_console_io()\n");
return 0;
}
else
{
printk("cap_check failed!\nLeaving cap_console_io()\n");
TT_DBG("cap_check failed!\nLeaving cap_console_io()\n");
return 1;
}
......@@ -117,17 +117,17 @@ static int cap_domain_memory_map(struct domain *d)
struct capability *cap;
printk("In cap_domain_memory_map()\n");
TT_DBG("In cap_domain_memory_map()\n");
cap = &(CAP_BOOT_INFO->cap_hypercalls[0]);
if ( (ret = cap_check(d, 1, cap)) == 1 )
{
printk("cap_check success\nLeaving cap_domain_memory_map()\n");
TT_DBG("cap_check success\nLeaving cap_domain_memory_map()\n");
return 0;
}
else
{
printk("cap_check failed!\ncap_domain_memory_map()\n");
TT_DBG("cap_check failed!\ncap_domain_memory_map()\n");
return 1;
}
......@@ -141,19 +141,19 @@ static int cap_memory_pin_page(struct domain *d1, struct domain *d2, struct page
struct capability *cap;
if ( d1->domain_id != 0 )
printk("In cap_memory_pin_page()\n");
TT_DBG("In cap_memory_pin_page()\n");
cap = &(CAP_BOOT_INFO->cap_hypercalls[1]);
if ( (ret = cap_check(d1, 1, cap)) == 1 )
{
if ( d1->domain_id != 0 )
printk("cap_check success\nLeaving cap_memory_pin_page()\n");
TT_DBG("cap_check success\nLeaving cap_memory_pin_page()\n");
return 0;
}
else
{
if ( d1->domain_id != 0 )
printk("cap_check failed!\ncap_memory_pin_page()\n");
TT_DBG("cap_check failed!\ncap_memory_pin_page()\n");
return 1;
}
......@@ -903,14 +903,14 @@ static __init int xsm_cap_init(void)
{
int ret = 0;
printk("Xen-cap: Initializing and registering with XSM.\n");
TT_DBG("Xen-cap: Initializing and registering with XSM.\n");
original_ops = xsm_ops;
if ( register_xsm(&cap_ops) )
printk("xen-cap: Unable to register with XSM.\n");
TT_DBG("xen-cap: Unable to register with XSM.\n");
printk("Leaving xsm_cap_init.\n");
TT_DBG("Leaving xsm_cap_init.\n");
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment