summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneel <neel@FreeBSD.org>2014-05-13 16:40:27 +0000
committerneel <neel@FreeBSD.org>2014-05-13 16:40:27 +0000
commitf14c076ec7c8287b78e1359e537ee6d6e2adb9ea (patch)
tree8dd38e30d588937f075d090074ca872066ef16f7
parent681730d4b1912a06a4378919ec36145765be0c92 (diff)
downloadFreeBSD-src-f14c076ec7c8287b78e1359e537ee6d6e2adb9ea.zip
FreeBSD-src-f14c076ec7c8287b78e1359e537ee6d6e2adb9ea.tar.gz
Don't include the guest memory segments in the bhyve(8) process core dump.
This has not added a lot of value when debugging bhyve issues while greatly increasing the time and space required to store the core file. Passing the "-C" option to bhyve(8) will change the default and dump guest memory in the core dump. Requested by: grehan Reviewed by: grehan
-rw-r--r--lib/libvmmapi/vmmapi.c18
-rw-r--r--lib/libvmmapi/vmmapi.h3
-rw-r--r--usr.sbin/bhyve/bhyve.84
-rw-r--r--usr.sbin/bhyve/bhyverun.c11
4 files changed, 30 insertions, 6 deletions
diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c
index 4a7f852..b853ae7 100644
--- a/lib/libvmmapi/vmmapi.c
+++ b/lib/libvmmapi/vmmapi.c
@@ -57,6 +57,7 @@ struct vmctx {
int fd;
uint32_t lowmem_limit;
enum vm_mmap_style vms;
+ int memflags;
size_t lowmem;
char *lowmem_addr;
size_t highmem;
@@ -101,6 +102,7 @@ vm_open(const char *name)
assert(vm != NULL);
vm->fd = -1;
+ vm->memflags = 0;
vm->lowmem_limit = 3 * GB;
vm->name = (char *)(vm + 1);
strcpy(vm->name, name);
@@ -180,10 +182,17 @@ vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit)
ctx->lowmem_limit = limit;
}
+void
+vm_set_memflags(struct vmctx *ctx, int flags)
+{
+
+ ctx->memflags = flags;
+}
+
static int
setup_memory_segment(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char **addr)
{
- int error;
+ int error, mmap_flags;
struct vm_memory_segment seg;
/*
@@ -195,8 +204,11 @@ setup_memory_segment(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char **addr)
seg.len = len;
error = ioctl(ctx->fd, VM_MAP_MEMORY, &seg);
if (error == 0 && addr != NULL) {
- *addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED,
- ctx->fd, gpa);
+ mmap_flags = MAP_SHARED;
+ if ((ctx->memflags & VM_MEM_F_INCORE) == 0)
+ mmap_flags |= MAP_NOCORE;
+ *addr = mmap(NULL, len, PROT_READ | PROT_WRITE, mmap_flags,
+ ctx->fd, gpa);
}
return (error);
}
diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h
index 2a2ca6b..c1a4b35 100644
--- a/lib/libvmmapi/vmmapi.h
+++ b/lib/libvmmapi/vmmapi.h
@@ -42,6 +42,8 @@ enum vm_mmap_style {
VM_MMAP_SPARSE, /* mappings created on-demand */
};
+#define VM_MEM_F_INCORE 0x01 /* include guest memory in core file */
+
int vm_create(const char *name);
struct vmctx *vm_open(const char *name);
void vm_destroy(struct vmctx *ctx);
@@ -53,6 +55,7 @@ void *vm_map_gpa(struct vmctx *ctx, vm_paddr_t gaddr, size_t len);
int vm_get_gpa_pmap(struct vmctx *, uint64_t gpa, uint64_t *pte, int *num);
uint32_t vm_get_lowmem_limit(struct vmctx *ctx);
void vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit);
+void vm_set_memflags(struct vmctx *ctx, int flags);
int vm_set_desc(struct vmctx *ctx, int vcpu, int reg,
uint64_t base, uint32_t limit, uint32_t access);
int vm_get_desc(struct vmctx *ctx, int vcpu, int reg,
diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8
index aa97a67..23eaadc 100644
--- a/usr.sbin/bhyve/bhyve.8
+++ b/usr.sbin/bhyve/bhyve.8
@@ -32,7 +32,7 @@
.Nd "run a guest operating system inside a virtual machine"
.Sh SYNOPSIS
.Nm
-.Op Fl aehwxAHPW
+.Op Fl aehwxACHPW
.Op Fl c Ar numcpus
.Op Fl g Ar gdbport
.Op Fl p Ar vcpu:hostcpu
@@ -70,6 +70,8 @@ guests.
.It Fl c Ar numcpus
Number of guest virtual CPUs.
The default is 1 and the maximum is 16.
+.It Fl C
+Include guest memory in core file.
.It Fl H
Yield the virtual CPU thread when a HLT instruction is detected.
If this option is not specified, virtual CPUs will use 100% of a host CPU.
diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
index f4a9111..b2354c9 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -134,6 +134,7 @@ usage(int code)
" -A: create an ACPI table\n"
" -g: gdb port\n"
" -c: # cpus (default 1)\n"
+ " -C: include guest memory in core file\n"
" -p: pin 'vcpu' to 'hostcpu'\n"
" -H: vmexit from the guest on hlt\n"
" -P: vmexit from the guest on pause\n"
@@ -642,19 +643,20 @@ int
main(int argc, char *argv[])
{
int c, error, gdb_port, err, bvmcons;
- int max_vcpus, mptgen;
+ int dump_guest_memory, max_vcpus, mptgen;
struct vmctx *ctx;
uint64_t rip;
size_t memsize;
bvmcons = 0;
+ dump_guest_memory = 0;
progname = basename(argv[0]);
gdb_port = 0;
guest_ncpus = 1;
memsize = 256 * MB;
mptgen = 1;
- while ((c = getopt(argc, argv, "abehwxAHIPWYp:g:c:s:m:l:U:")) != -1) {
+ while ((c = getopt(argc, argv, "abehwxACHIPWYp:g:c:s:m:l:U:")) != -1) {
switch (c) {
case 'a':
x2apic_mode = 0;
@@ -674,6 +676,9 @@ main(int argc, char *argv[])
case 'c':
guest_ncpus = atoi(optarg);
break;
+ case 'C':
+ dump_guest_memory = 1;
+ break;
case 'g':
gdb_port = atoi(optarg);
break;
@@ -755,6 +760,8 @@ main(int argc, char *argv[])
fbsdrun_set_capabilities(ctx, BSP);
+ if (dump_guest_memory)
+ vm_set_memflags(ctx, VM_MEM_F_INCORE);
err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL);
if (err) {
fprintf(stderr, "Unable to setup memory (%d)\n", err);
OpenPOWER on IntegriCloud