From: Peter Dinda Date: Tue, 14 Jan 2014 00:04:02 +0000 (-0600) Subject: Error checking fixes, minor bug in keyed stream, minor bug in checkpoint X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=0b2115047303e779be8578e9802cfa55d1767c7b Error checking fixes, minor bug in keyed stream, minor bug in checkpoint All allocations now zeroed by default --- diff --git a/linux_module/buddy.c b/linux_module/buddy.c index 43247b6..26a7021 100644 --- a/linux_module/buddy.c +++ b/linux_module/buddy.c @@ -155,7 +155,7 @@ int buddy_add_pool(struct buddy_memzone * zone, mp = palacios_alloc_extended(sizeof(struct buddy_mempool), GFP_KERNEL, zone->node_id); - if (IS_ERR(mp)) { + if (!mp) { ERROR("Could not allocate mempool\n"); return -1; } @@ -174,6 +174,13 @@ int buddy_add_pool(struct buddy_memzone * zone, BITS_TO_LONGS(mp->num_blocks) * sizeof(long), GFP_KERNEL, zone->node_id ); + if (!(mp->tag_bits)) { + ERROR("Could not allocate tag_bits\n"); + palacios_free(mp); + return -1; + } + + /* Initially mark all minimum-sized blocks as allocated */ bitmap_zero(mp->tag_bits, mp->num_blocks); diff --git a/linux_module/iface-code-inject.c b/linux_module/iface-code-inject.c index db74648..1add908 100644 --- a/linux_module/iface-code-inject.c +++ b/linux_module/iface-code-inject.c @@ -55,7 +55,7 @@ static int vm_tophalf_inject (struct v3_guest * guest, unsigned int cmd, unsigne struct top_half_data * top; top = palacios_alloc(sizeof(struct top_half_data)); - if (IS_ERR(top)) { + if (!top) { ERROR("Palacios Error: could not allocate space for top half data\n"); return -EFAULT; } @@ -81,7 +81,7 @@ static int vm_tophalf_inject (struct v3_guest * guest, unsigned int cmd, unsigne DEBUG("Palacios: Allocating %lu B of kernel memory for ELF binary data...\n", top->elf_size); top->elf_data = palacios_alloc(top->elf_size); - if (IS_ERR(top->elf_data)) { + if (!(top->elf_data)) { ERROR("Palacios Error: could not allocate space for binary image\n"); palacios_free(top); return -EFAULT; diff --git a/linux_module/iface-env-inject.c b/linux_module/iface-env-inject.c index 44daab5..115d867 100644 --- a/linux_module/iface-env-inject.c +++ b/linux_module/iface-env-inject.c @@ -59,7 +59,7 @@ static int vm_env_inject (struct v3_guest * guest, unsigned int cmd, unsigned lo } env = palacios_alloc(sizeof(struct env_data)); - if (IS_ERR(env)) { + if (!env) { ERROR("Palacios Error: could not allocate space for environment data\n"); return -EFAULT; } @@ -73,7 +73,7 @@ static int vm_env_inject (struct v3_guest * guest, unsigned int cmd, unsigned lo //DEBUG("Palacios: Allocating space for %u env var string ptrs...\n", env->num_strings); env->strings = palacios_alloc(env->num_strings*sizeof(char*)); - if (IS_ERR(env->strings)) { + if (!(env->strings)) { ERROR("Palacios Error: could not allocate space for env var strings\n"); return -EFAULT; } @@ -87,7 +87,7 @@ static int vm_env_inject (struct v3_guest * guest, unsigned int cmd, unsigned lo for (i = 0; i < env->num_strings; i++) { char * tmp = palacios_alloc(MAX_STRING_LEN); - if (IS_ERR(tmp)) { + if (!(tmp)) { ERROR("Palacios Error: could not allocate space for env var string #%d\n", i); return -EFAULT; } diff --git a/linux_module/iface-file.c b/linux_module/iface-file.c index b446916..78c4e0b 100644 --- a/linux_module/iface-file.c +++ b/linux_module/iface-file.c @@ -161,7 +161,7 @@ static int palacios_file_mkdir(const char * pathname, unsigned short perms, int { dentry = kern_path_create(AT_FDCWD, pathname, &tmp_path, 1); - if (IS_ERR(dentry)) { + if (!dentry || IS_ERR(dentry)) { return 0; } @@ -170,7 +170,7 @@ static int palacios_file_mkdir(const char * pathname, unsigned short perms, int #endif - if (!IS_ERR(dentry)) { + if (!(!dentry || IS_ERR(dentry))) { ret = vfs_mkdir(path_ptr->dentry->d_inode, dentry, perms); } @@ -220,7 +220,7 @@ static void * palacios_file_open(const char * path, int mode, void * private_dat pfile->filp = filp_open(path, pfile->mode, 0); - if (IS_ERR(pfile->filp)) { + if (!pfile->filp || IS_ERR(pfile->filp)) { ERROR("Cannot open file: %s\n", path); palacios_free(pfile); return NULL; diff --git a/linux_module/iface-keyed-stream.c b/linux_module/iface-keyed-stream.c index 0381aa4..dd218d0 100644 --- a/linux_module/iface-keyed-stream.c +++ b/linux_module/iface-keyed-stream.c @@ -726,7 +726,7 @@ static v3_keyed_stream_t open_stream_file(char *url, de = lookup_create(&nd,1); - if (IS_ERR(de)) { + if (!de || IS_ERR(de)) { ERROR("cannot allocate dentry\n"); goto fail_out; } @@ -800,7 +800,7 @@ static v3_keyed_stream_key_t open_key_file(v3_keyed_stream_t stream, strcat(path,"/"); strcat(path,key); - fs = (struct file_stream *) palacios_alloc(sizeof(struct file_stream *)); + fs = (struct file_stream *) palacios_alloc(sizeof(struct file_stream)); if (!fs) { ERROR("cannot allocate file keyed stream for key %s\n",key); @@ -812,7 +812,7 @@ static v3_keyed_stream_key_t open_key_file(v3_keyed_stream_t stream, fs->f = filp_open(path,O_RDWR|O_CREAT|O_LARGEFILE,0600); - if (IS_ERR(fs->f)) { + if (!fs->f || IS_ERR(fs->f)) { ERROR("cannot open relevent file \"%s\" for stream \"file:%s\" and key \"%s\"\n",path,fks->path,key); palacios_free(fs); palacios_free(path); diff --git a/linux_module/inspector.c b/linux_module/inspector.c index 7d3ccf2..56b6fa5 100644 --- a/linux_module/inspector.c +++ b/linux_module/inspector.c @@ -64,7 +64,7 @@ static int inspect_vm(struct v3_guest * guest, unsigned int cmd, unsigned long a guest_dir = debugfs_create_dir(guest->name, v3_dir); - if (IS_ERR(guest_dir)) { + if (!guest_dir || IS_ERR(guest_dir)) { ERROR("Error Creating inspector tree for VM \"%s\"\n", guest->name); return -1; } @@ -79,7 +79,7 @@ static int init_inspector( void ) { v3_dir = debugfs_create_dir("v3vee", NULL); - if (IS_ERR(v3_dir)) { + if (!v3_dir || IS_ERR(v3_dir)) { ERROR("Error creating v3vee debugfs directory\n"); return -1; } diff --git a/linux_module/main.c b/linux_module/main.c index 932b739..34c24f7 100644 --- a/linux_module/main.c +++ b/linux_module/main.c @@ -90,7 +90,7 @@ static long v3_dev_ioctl(struct file * filp, struct v3_guest_img user_image; struct v3_guest * guest = palacios_alloc(sizeof(struct v3_guest)); - if (IS_ERR(guest)) { + if (!(guest)) { ERROR("Palacios: Error allocating Kernel guest_image\n"); return -EFAULT; } @@ -118,7 +118,7 @@ static long v3_dev_ioctl(struct file * filp, DEBUG("Palacios: Allocating kernel memory for guest image (%llu bytes)\n", user_image.size); guest->img = palacios_valloc(guest->img_size); - if (IS_ERR(guest->img)) { + if (!guest->img) { ERROR("Palacios Error: Could not allocate space for guest image\n"); goto out_err1; } @@ -576,7 +576,7 @@ static int __init v3_init(void) { v3_class = class_create(THIS_MODULE, "vms"); - if (IS_ERR(v3_class)) { + if (!v3_class || IS_ERR(v3_class)) { ERROR("Failed to register V3 VM device class\n"); ret = PTR_ERR(v3_class); goto failure3; diff --git a/linux_module/palacios-stubs.c b/linux_module/palacios-stubs.c index decae1f..694a212 100644 --- a/linux_module/palacios-stubs.c +++ b/linux_module/palacios-stubs.c @@ -34,10 +34,10 @@ -// The following can be used to track heap bugs -// zero memory after allocation -#define ALLOC_ZERO_MEM 0 -// pad allocations by this many bytes on both ends of block +// The following can be used to track memory bugs +// zero memory after allocation (now applies to valloc and page alloc as well) +#define ALLOC_ZERO_MEM 1 +// pad allocations by this many bytes on both ends of block (heap only) #define ALLOC_PAD 0 @@ -191,6 +191,10 @@ void *palacios_allocate_pages(int num_pages, unsigned int alignment, int node_id pg_allocs += num_pages; +#if ALLOC_ZERO_MEM + memset(__va(pg_addr),0,num_pages*4096); +#endif + MEMCHECK_ALLOC_PAGES(pg_addr,num_pages*4096); return pg_addr; @@ -233,7 +237,7 @@ palacios_alloc_extended(unsigned int size, unsigned int flags, int node) { addr = kmalloc_node(size+2*ALLOC_PAD, flags, node); } - if (!addr) { + if (!addr || IS_ERR(addr)) { ERROR("ALERT ALERT kmalloc has FAILED FAILED FAILED\n"); return NULL; } @@ -261,13 +265,17 @@ palacios_valloc(unsigned int size) addr = vmalloc(size); - if (!addr) { + if (!addr || IS_ERR(addr)) { ERROR("ALERT ALERT vmalloc has FAILED FAILED FAILED\n"); return NULL; } vmallocs++; +#if ALLOC_ZERO_MEM + memset(addr,0,size); +#endif + MEMCHECK_VMALLOC(addr,size); return addr; @@ -446,7 +454,7 @@ palacios_start_thread_on_cpu(int cpu_id, thread = kthread_create( lnx_thread_target, thread_info, thread_info->name ); - if (IS_ERR(thread)) { + if (!thread || IS_ERR(thread)) { WARNING("Palacios error creating thread: %s\n", thread_info->name); palacios_free(thread_info); return NULL; diff --git a/palacios/src/palacios/vmm_checkpoint.c b/palacios/src/palacios/vmm_checkpoint.c index 7a564e6..d96cbee 100644 --- a/palacios/src/palacios/vmm_checkpoint.c +++ b/palacios/src/palacios/vmm_checkpoint.c @@ -715,6 +715,11 @@ static int load_header(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { ctx = v3_chkpt_open_ctx(chkpt, "header"); + if (!ctx) { + PrintError(vm, VCORE_NONE, "Cannot open context to load header\n"); + return -1; + } + switch (v3_mach_type) { case V3_SVM_CPU: case V3_SVM_REV3_CPU: { diff --git a/palacios/src/palacios/vmm_util.c b/palacios/src/palacios/vmm_util.c index 678a42b..e6fd1fb 100644 --- a/palacios/src/palacios/vmm_util.c +++ b/palacios/src/palacios/vmm_util.c @@ -24,8 +24,11 @@ void v3_dump_mem(uint8_t * start, int n) { int i, j; char buf[128]; - + if (!start) { + return; + } + for (i = 0; i < n; i += 16) { snprintf(buf, 128, "%p ", (void *)(start + i)); for (j = i; (j < (i + 16)) && (j < n); j++) {