[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3 12/16] Add dump of HVM_SAVE_CODE(VMPORT) to xen-hvmctx.
It also does some validation of the compressed data. Currently expects that all guest info are printable strings. Signed-off-by: Don Slutz <dslutz@xxxxxxxxxxx> --- tools/misc/xen-hvmctx.c | 229 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) diff --git a/tools/misc/xen-hvmctx.c b/tools/misc/xen-hvmctx.c index 5a69245..d076091 100644 --- a/tools/misc/xen-hvmctx.c +++ b/tools/misc/xen-hvmctx.c @@ -399,6 +399,225 @@ static void dump_tsc_adjust(void) printf(" TSC_ADJUST: tsc_adjust %" PRIx64 "\n", p.tsc_adjust); } +static void dump_vmport(int vmport_size) +{ + int i; + HVM_SAVE_TYPE(VMPORT) *vp; + int64_t vmport_guestsize; + uint32_t vmport_used_guestinfo; + uint32_t vmport_used_guestinfo_jumbo; + uint8_t pb[vmport_size]; + char *p; + int chans_size; + + READ(pb); + vp = (void *)&pb; + + p = vp->u.packed.packed_data; + + vmport_guestsize = vp->used_guestsize; + chans_size = vmport_size - vmport_guestsize - (p - (char *)pb); + if ( chans_size < 0 ) + { + fprintf(stderr, "*** VMPORT: bogus chans_size=%d should be >= 0\n" + " vmport_size=%d vmport_guestsize=%d fixed_size=%ld\n", + chans_size, vmport_size, (int)vmport_guestsize, + p - (char *)pb); + chans_size = 0; + } + + printf(" VMPORT: ping_time %" PRIu64 "\n", vp->ping_time); + printf(" VMPORT: open_cookie %" PRIx32 "\n", vp->open_cookie); + for ( i = 0; i < VMPORT_MAX_CHANS; i++ ) + { + int j; + vmport_channel_control_t *vc = &vp->u.packed.chan_ctl[i].chan; + vmport_bucket_control_t *jb = &vp->u.packed.chan_ctl[i].jumbo; + + printf(" VMPORT: chan[%d] chan_id %d\n", i, vc->chan_id); + printf(" VMPORT: chan[%d] active_time %" PRIx64 "\n", + i, vc->active_time); + printf(" VMPORT: chan[%d] proto_num %" PRIx32 "\n", + i, vc->proto_num); + printf(" VMPORT: chan[%d] recv_read %d\n", i, vc->recv_read); + printf(" VMPORT: chan[%d] recv_write %d\n", i, vc->recv_write); + printf(" VMPORT: chan[%d] jumbo %d\n", i, vc->jumbo); + printf(" VMPORT: chan[%d] send_len %d\n", i, vc->send_len); + if ( vc->send_len > VMPORT_MAX_SEND_BUF * 4 ) + { + printf("--- VMPORT: trucated send_len=%d > %d\n", + vc->send_len, VMPORT_MAX_SEND_BUF * 4); + vc->send_len = VMPORT_MAX_SEND_BUF * 4; + } + if ( vc->send_len > chans_size ) + { + fprintf(stderr, "*** VMPORT: bogus send_len=%d > %d\n", + vc->send_len, chans_size); + if ( chans_size >= 0 ) + vc->send_len = chans_size; + else + vc->send_len = 0; + } + p += vc->send_len; + chans_size -= vc->send_len; + for ( j = 0; j < VMPORT_MAX_BKTS; j++ ) + { + vmport_bucket_control_t *b = &vp->u.packed.chan_ctl[i].recv[j]; + + printf(" VMPORT: chan[%d] bucket[%d] recv_len %d\n", + i, j, b->recv_len); + if ( b->recv_len > VMPORT_MAX_RECV_BUF * 4 ) + { + printf("--- VMPORT: trucated recv_len=%d > %d\n", + b->recv_len, VMPORT_MAX_RECV_BUF * 4); + b->recv_len = VMPORT_MAX_RECV_BUF * 4; + } + if ( b->recv_len > chans_size ) + { + fprintf(stderr, "*** VMPORT: bogus recv_len=%d > %d\n", + b->recv_len, chans_size); + if ( chans_size >= 0 ) + b->recv_len = chans_size; + else + b->recv_len = 0; + } + p += b->recv_len; + chans_size -= b->recv_len; + } + printf(" VMPORT: chan[%d] jumbo_bkt recv_len %d\n", i, jb->recv_len); + if ( jb->recv_len > VMPORT_MAX_RECV_JUMBO_BUF * 4 ) + { + printf("--- VMPORT: trucated recv_len=%d > %d\n", + jb->recv_len, VMPORT_MAX_RECV_JUMBO_BUF * 4); + jb->recv_len = VMPORT_MAX_RECV_JUMBO_BUF * 4; + } + if ( jb->recv_len > chans_size ) + { + fprintf(stderr, "*** VMPORT: bogus recv_len=%d > %d\n", + jb->recv_len, chans_size); + if ( chans_size >= 0 ) + jb->recv_len = chans_size; + else + jb->recv_len = 0; + } + p += jb->recv_len; + chans_size -= jb->recv_len; + } + + if ( chans_size != 0 ) + fprintf(stderr, "*** VMPORT: bogus chans_size=%d should be 0\n", + chans_size); + + vmport_used_guestinfo = vp->used_guestinfo; + vmport_used_guestinfo_jumbo = vp->used_guestinfo_jumbo; + + if ( vmport_used_guestinfo == 0 ) + printf(" VMPORT: no small data\n"); + for ( i = 0; i < vmport_used_guestinfo; i++ ) + { + if ( vmport_guestsize > 0 ) + { + uint8_t key_len = (uint8_t)(*p++); + uint8_t val_len = (uint8_t)(*p++); + if ( key_len ) + { + char key[VMPORT_MAX_KEY_LEN + 1]; + char val[VMPORT_MAX_VAL_LEN + 1]; + + if ( key_len > VMPORT_MAX_KEY_LEN ) + { + fprintf(stderr, + "*** VMPORT: bogus key_len=%d > %d for guestinfo[%d]\n", + key_len, VMPORT_MAX_KEY_LEN, i); + key_len = VMPORT_MAX_KEY_LEN; + } + memcpy(key, p, key_len); + p += key_len; + key[key_len] = '\0'; + if ( val_len > VMPORT_MAX_VAL_LEN ) + { + fprintf(stderr, + "*** VMPORT: bogus val_len=%d > %d for guestinfo[%d]\n", + val_len, VMPORT_MAX_VAL_LEN, i); + val_len = VMPORT_MAX_VAL_LEN; + } + memcpy(val, p, val_len); + p += val_len; + val[val_len] = '\0'; + vmport_guestsize -= 2 + key_len + val_len; + printf(" VMPORT: guestinfo[%d](%s) = \"%s\"\n", + i, key, val); + } + else + { + fprintf(stderr, + "*** VMPORT: bogus len for guestinfo[%d]\n", + i); + vmport_guestsize -= 2; + } + if ( vmport_guestsize < 0 ) + printf(" VMPORT: data length skew at guestinfo[%d]\n" + " remaining datasize=%ld\n", + i, vmport_guestsize); + } + } + + if ( vmport_guestsize == 0 ) + printf(" VMPORT: no jumbo data\n"); + for ( i = 0; i < vmport_used_guestinfo_jumbo; i++ ) + { + if ( vmport_guestsize > 0 ) + { + uint8_t key_len = (uint8_t)(*p++); + uint16_t val_len; + + memcpy(&val_len, p, 2); + p += 2; + if ( key_len ) + { + char key[VMPORT_MAX_KEY_LEN + 1]; + char val[VMPORT_MAX_VAL_JUMBO_LEN + 1]; + + if ( key_len > VMPORT_MAX_KEY_LEN ) + { + fprintf(stderr, + "*** VMPORT: bogus key_len=%d > %d for guestinfo[%d]\n", + key_len, VMPORT_MAX_KEY_LEN, i); + key_len = VMPORT_MAX_KEY_LEN; + } + memcpy(key, p, key_len); + p += key_len; + key[key_len] = '\0'; + if ( val_len > VMPORT_MAX_VAL_JUMBO_LEN ) + { + fprintf(stderr, + "*** VMPORT: bogus val_len=%d > %d for guestinfo[%d]\n", + val_len, VMPORT_MAX_VAL_JUMBO_LEN, i); + val_len = VMPORT_MAX_VAL_JUMBO_LEN; + } + memcpy(val, p, val_len); + p += val_len; + val[val_len] = '\0'; + vmport_guestsize -= 2 + key_len + val_len; + printf(" VMPORT: guestinfo_jumbo[%d](%s) = \"%s\"\n", + i, key, val); + } + else + { + printf(" VMPORT: bogus len for guestinfo_jumbo[%d]\n", i); + vmport_guestsize -= 2; + } + if ( vmport_guestsize < 0 ) + printf(" VMPORT: data length skew at guestinfo_jumbo[%d]\n" + " remaining datasize=%ld\n", i, + vmport_guestsize); + } + } + + if ( !vmport_guestsize ) + printf(" VMPORT: %ld bytes leftover data\n", vmport_guestsize); +} + int main(int argc, char **argv) { int entry, domid; @@ -467,6 +686,7 @@ int main(int argc, char **argv) case HVM_SAVE_CODE(VIRIDIAN_VCPU): dump_viridian_vcpu(); break; case HVM_SAVE_CODE(VMCE_VCPU): dump_vmce_vcpu(); break; case HVM_SAVE_CODE(TSC_ADJUST): dump_tsc_adjust(); break; + case HVM_SAVE_CODE(VMPORT): dump_vmport(desc.length); break; case HVM_SAVE_CODE(END): break; default: printf(" ** Don't understand type %u: skipping\n", @@ -477,3 +697,12 @@ int main(int argc, char **argv) return 0; } + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ -- 1.8.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |