From: Lei Xia Date: Thu, 19 May 2011 21:41:45 +0000 (-0500) Subject: Fix to VNET bug when vnet_host_hooks is not properly initiated X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=e39ac677ad4eb2c2db111ce08eb6172c61f5001f Fix to VNET bug when vnet_host_hooks is not properly initiated Fix to Virtio NIC Fix to the debug code of VNET --- diff --git a/linux_module/palacios-dev.c b/linux_module/palacios-dev.c index be62f33..231a7f9 100644 --- a/linux_module/palacios-dev.c +++ b/linux_module/palacios-dev.c @@ -292,7 +292,7 @@ static int __init v3_init(void) { #endif #ifdef V3_CONFIG_VNET - palacios_init_vnet(); + palacios_vnet_init(); #endif #ifdef V3_CONFIG_HOST_DEVICE diff --git a/linux_module/palacios-vnet-bridge.c b/linux_module/palacios-vnet-bridge.c index f4a4151..de94d70 100644 --- a/linux_module/palacios-vnet-bridge.c +++ b/linux_module/palacios-vnet-bridge.c @@ -794,7 +794,7 @@ debug_write(struct file * file, const char * buf, size_t size, loff_t * ppos) { printk("Set VNET Debug level to %d\n", level); if(level >= 0){ - vnet_debug = level; + net_debug = level; } return size; @@ -802,7 +802,7 @@ debug_write(struct file * file, const char * buf, size_t size, loff_t * ppos) { static int debug_show(struct seq_file * file, void * v){ - seq_printf(file, "Current VNET Debug Level: %d\n", vnet_debug); + seq_printf(file, "Current VNET Debug Level: %d\n", net_debug); return 0; } @@ -993,10 +993,10 @@ send_to_palacios(unsigned char * buf, memcpy(pkt.header, buf, ETHERNET_HEADER_LEN); pkt.data = buf; - if(vnet_debug >= 2){ + if(net_debug >= 2){ printk("VNET Lnx Bridge: send pkt to VNET core (size: %d, src_id: %d, src_type: %d)\n", pkt.size, pkt.src_id, pkt.src_type); - if(vnet_debug >= 4){ + if(net_debug >= 4){ print_hex_dump(NULL, "pkt_data: ", 0, 20, 20, pkt.data, pkt.size, 0); } } @@ -1014,11 +1014,11 @@ bridge_send_pkt(struct v3_vm_info * vm, void * private_data) { struct vnet_link * link; - if(vnet_debug >= 2){ + if(net_debug >= 2){ printk("VNET Lnx Host Bridge: packet received from VNET Core ... pkt size: %d, link: %d\n", pkt->size, pkt->dst_id); - if(vnet_debug >= 4){ + if(net_debug >= 4){ print_hex_dump(NULL, "pkt_data: ", 0, 20, 20, pkt->data, pkt->size, 0); } } @@ -1159,7 +1159,7 @@ static inline int hash_eq(addr_t key1, addr_t key2) { } -int palacios_init_vnet(void) { +int palacios_init_vnet_bridge(void) { struct v3_vnet_bridge_ops bridge_ops; diff --git a/linux_module/palacios-vnet.c b/linux_module/palacios-vnet.c index 32f6bd6..19a6bca 100644 --- a/linux_module/palacios-vnet.c +++ b/linux_module/palacios-vnet.c @@ -15,6 +15,7 @@ #include #include "palacios-mm.h" +#include "palacios-vnet.h" static void host_print(const char * fmt, ...) { @@ -276,10 +277,11 @@ static struct vnet_host_hooks vnet_host_hooks = { -int vnet_init( void ) { - printk("Host init VNET\n"); - +int palacios_vnet_init( void ) { init_vnet(&vnet_host_hooks); + + palacios_init_vnet_bridge(); + printk("V3 VNET Inited\n"); return 0; } diff --git a/linux_module/palacios-vnet.h b/linux_module/palacios-vnet.h index 010b99a..b3e5450 100644 --- a/linux_module/palacios-vnet.h +++ b/linux_module/palacios-vnet.h @@ -6,7 +6,8 @@ #ifndef __PALACIOS_VNET_BRIDGE_H__ #define __PALACIOS_VNET_BRIDGE_H__ -int palacios_init_vnet(void); +int palacios_vnet_init(void); +int palacios_init_vnet_bridge(void); #endif diff --git a/palacios/include/palacios/vmm_ethernet.h b/palacios/include/palacios/vmm_ethernet.h index ca3034b..1ca3713 100644 --- a/palacios/include/palacios/vmm_ethernet.h +++ b/palacios/include/palacios/vmm_ethernet.h @@ -31,8 +31,9 @@ #define MAX_PACKET_LEN (ETHERNET_HEADER_LEN + MAX_MTU) - -extern int vnet_debug; +#ifdef V3_CONFIG_VNET +extern int net_debug; +#endif #ifdef __V3VEE__ @@ -40,7 +41,7 @@ extern int vnet_debug; #define V3_Net_Print(level, fmt, args...) \ do { \ - if(level <= vnet_debug) { \ + if(level <= net_debug) { \ extern struct v3_os_hooks * os_hooks; \ if ((os_hooks) && (os_hooks)->print) { \ (os_hooks)->print((fmt), ##args); \ diff --git a/palacios/include/vnet/vnet_host.h b/palacios/include/vnet/vnet_host.h index 631d240..3519cf4 100644 --- a/palacios/include/vnet/vnet_host.h +++ b/palacios/include/vnet/vnet_host.h @@ -212,8 +212,8 @@ static inline void vnet_reset_timer(struct vnet_timer * timer, #define Vnet_Print(level, fmt, args...) \ do { \ - extern int vnet_debug; \ - if(level <= vnet_debug) { \ + extern int net_debug; \ + if(level <= net_debug) { \ extern struct vnet_host_hooks * host_hooks; \ if ((host_hooks) && (host_hooks)->print) { \ (host_hooks)->print((fmt), ##args); \ diff --git a/palacios/src/devices/lnx_virtio_nic.c b/palacios/src/devices/lnx_virtio_nic.c index 642b259..3c519aa 100644 --- a/palacios/src/devices/lnx_virtio_nic.c +++ b/palacios/src/devices/lnx_virtio_nic.c @@ -38,6 +38,10 @@ #define PrintDebug(fmt, args...) #endif +#ifndef V3_CONFIG_VNET +static int net_debug = 0; +#endif + #define TX_QUEUE_SIZE 4096 #define RX_QUEUE_SIZE 4096 #define CTRL_QUEUE_SIZE 64 @@ -199,7 +203,7 @@ static int tx_one_pkt(struct guest_info * core, } V3_Net_Print(2, "Virtio-NIC: virtio_tx: size: %d\n", len); - if(vnet_debug >= 4){ + if(net_debug >= 4){ v3_hexdump(buf, len, NULL, 0); } @@ -248,11 +252,15 @@ static inline int get_desc_count(struct virtio_queue * q, int index) { } static inline void enable_cb(struct virtio_queue *queue){ - queue->used->flags &= ~ VRING_NO_NOTIFY_FLAG; + if(queue->used){ + queue->used->flags &= ~ VRING_NO_NOTIFY_FLAG; + } } static inline void disable_cb(struct virtio_queue *queue) { - queue->used->flags |= VRING_NO_NOTIFY_FLAG; + if(queue->used){ + queue->used->flags |= VRING_NO_NOTIFY_FLAG; + } } static int handle_pkt_tx(struct guest_info * core, @@ -561,7 +569,7 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) { unsigned long flags; V3_Net_Print(2, "Virtio-NIC: virtio_rx: size: %d\n", size); - if(vnet_debug >= 4){ + if(net_debug >= 4){ v3_hexdump(buf, size, NULL, 0); } @@ -804,6 +812,7 @@ static int register_dev(struct virtio_dev_state * virtio, return 0; } + #define RATE_UPPER_THRESHOLD 10 /* 10000 pkts per second, around 100Mbits */ #define RATE_LOWER_THRESHOLD 1 #define PROFILE_PERIOD 10000 /*us*/ @@ -815,6 +824,10 @@ static void virtio_nic_timer(struct guest_info * core, uint64_t period_us; static int profile_ms = 0; + if(!net_state->status){ /* VNIC is not in working status */ + return; + } + period_us = (1000*cpu_cycles)/cpu_freq; net_state->past_us += period_us; @@ -890,12 +903,16 @@ static int connect_fn(struct v3_vm_info * info, net_state->timer = v3_add_timer(&(info->cores[0]),&timer_ops,net_state); + PrintError("net_state 0x%p\n", (void *)net_state); + ops->recv = virtio_rx; ops->frontend_data = net_state; memcpy(ops->fnt_mac, virtio->mac, ETH_ALEN); net_state->poll_thread = vnet_start_thread(virtio_tx_flush, (void *)net_state, "Virtio_Poll"); + net_state->status = 1; + return 0; } diff --git a/palacios/src/devices/vnet_nic.c b/palacios/src/devices/vnet_nic.c index 66761d9..ac484a0 100644 --- a/palacios/src/devices/vnet_nic.c +++ b/palacios/src/devices/vnet_nic.c @@ -54,7 +54,7 @@ static int vnet_nic_send(uint8_t * buf, uint32_t len, V3_Net_Print(2, "VNET-NIC: send pkt (size: %d, src_id: %d, src_type: %d)\n", pkt.size, pkt.src_id, pkt.src_type); - if(vnet_debug >= 4){ + if(net_debug >= 4){ v3_hexdump(buf, len, NULL, 0); } diff --git a/palacios/src/vnet/vnet_core.c b/palacios/src/vnet/vnet_core.c index 42c9d3b..38c2f1d 100644 --- a/palacios/src/vnet/vnet_core.c +++ b/palacios/src/vnet/vnet_core.c @@ -29,7 +29,7 @@ #define Vnet_Debug(fmt, args...) #endif -int vnet_debug = 0; +int net_debug = 0; struct eth_hdr { uint8_t dst_mac[ETH_ALEN]; @@ -447,7 +447,7 @@ int vnet_tx_one_pkt(struct v3_vnet_pkt * pkt, void * private_data) { Vnet_Print(2, "VNET/P Core: cpu %d: pkt (size %d, src_id:%d, src_type: %d, dst_id: %d, dst_type: %d)\n", cpu, pkt->size, pkt->src_id, pkt->src_type, pkt->dst_id, pkt->dst_type); - if(vnet_debug >= 4){ + if(net_debug >= 4){ v3_hexdump(pkt->data, pkt->size, NULL, 0); } diff --git a/palacios/src/vnet/vnet_host.c b/palacios/src/vnet/vnet_host.c index 9d3bb31..2121e7f 100644 --- a/palacios/src/vnet/vnet_host.c +++ b/palacios/src/vnet/vnet_host.c @@ -22,31 +22,31 @@ struct vnet_host_hooks * host_hooks; - int vnet_lock_init(vnet_lock_t * lock) { - *lock = (addr_t)(host_hooks->mutex_alloc()); - - if (!(*lock)) { - return -1; + if((host_hooks) && host_hooks->mutex_alloc){ + *lock = (addr_t)(host_hooks->mutex_alloc()); + + if (*lock) { + return 0; + } } - return 0; + return -1; } struct vnet_thread * vnet_start_thread(int (*func)(void *), void *arg, char * name){ - struct vnet_thread * thread; + if((host_hooks) && host_hooks->thread_start){ + struct vnet_thread * thread = Vnet_Malloc(sizeof(struct vnet_thread)); + thread->host_thread = host_hooks->thread_start(func, arg, name); - thread = Vnet_Malloc(sizeof(struct vnet_thread)); - - thread->host_thread = host_hooks->thread_start(func, arg, name); - - if(thread->host_thread == NULL){ + if(thread->host_thread){ + return thread; + } Vnet_Free(thread); - return NULL; } - return thread; + return NULL; } @@ -54,15 +54,13 @@ struct vnet_thread * vnet_start_thread(int (*func)(void *), void *arg, char * na struct vnet_timer * vnet_create_timer(unsigned long interval, void (* timer_fun)(void * priv_data), void * priv_data){ - struct vnet_timer * timer = NULL; - if((host_hooks) && host_hooks->timer_create){ - timer = Vnet_Malloc(sizeof(struct vnet_timer)); - + struct vnet_timer * timer = Vnet_Malloc(sizeof(struct vnet_timer)); timer->host_timer = host_hooks->timer_create(interval, timer_fun, priv_data); + return timer; } - return timer; + return NULL; }