move dump_pt logic to trace_dump.c, enable via aux_buffer
This commit is contained in:
parent
7b9bd18dc3
commit
84f1a1b67b
@ -7,6 +7,7 @@ synchronization.o \
|
|||||||
page_cache.o \
|
page_cache.o \
|
||||||
kvm_nested.o \
|
kvm_nested.o \
|
||||||
debug.o \
|
debug.o \
|
||||||
|
trace_dump.o \
|
||||||
auxiliary_buffer.o \
|
auxiliary_buffer.o \
|
||||||
mmh3.o \
|
mmh3.o \
|
||||||
nested_hypercalls.o \
|
nested_hypercalls.o \
|
||||||
|
@ -25,6 +25,7 @@ along with QEMU-PT. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "nyx/state/state.h"
|
#include "nyx/state/state.h"
|
||||||
#include "nyx/debug.h"
|
#include "nyx/debug.h"
|
||||||
|
#include "nyx/trace_dump.h"
|
||||||
|
|
||||||
/* experimental feature (currently broken)
|
/* experimental feature (currently broken)
|
||||||
* enabled via trace mode
|
* enabled via trace mode
|
||||||
@ -104,6 +105,7 @@ void check_auxiliary_config_buffer(auxilary_buffer_t* auxilary_buffer, auxilary_
|
|||||||
GET_GLOBAL_STATE()->pt_trace_mode_force = true;
|
GET_GLOBAL_STATE()->pt_trace_mode_force = true;
|
||||||
#endif
|
#endif
|
||||||
redqueen_set_trace_mode();
|
redqueen_set_trace_mode();
|
||||||
|
pt_trace_dump_enable(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -113,6 +115,7 @@ void check_auxiliary_config_buffer(auxilary_buffer_t* auxilary_buffer, auxilary_
|
|||||||
GET_GLOBAL_STATE()->pt_trace_mode_force = false;
|
GET_GLOBAL_STATE()->pt_trace_mode_force = false;
|
||||||
#endif
|
#endif
|
||||||
redqueen_unset_trace_mode();
|
redqueen_unset_trace_mode();
|
||||||
|
pt_trace_dump_enable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ along with QEMU-PT. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "nyx/state/state.h"
|
#include "nyx/state/state.h"
|
||||||
#include "nyx/sharedir.h"
|
#include "nyx/sharedir.h"
|
||||||
#include "nyx/helpers.h"
|
#include "nyx/helpers.h"
|
||||||
|
#include "nyx/trace_dump.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@ -278,7 +279,7 @@ static bool verify_workdir_state(nyx_interface_state *s, Error **errp){
|
|||||||
|
|
||||||
if(s->dump_pt_trace){
|
if(s->dump_pt_trace){
|
||||||
assert(asprintf(&tmp, "%s/pt_trace_dump_%d", workdir, id) != -1);
|
assert(asprintf(&tmp, "%s/pt_trace_dump_%d", workdir, id) != -1);
|
||||||
pt_trace_dump_enable(tmp);
|
pt_trace_dump_init(tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
50
nyx/pt.c
50
nyx/pt.c
@ -44,6 +44,7 @@ along with QEMU-PT. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "nyx/state/state.h"
|
#include "nyx/state/state.h"
|
||||||
#include <libxdc.h>
|
#include <libxdc.h>
|
||||||
#include "nyx/helpers.h"
|
#include "nyx/helpers.h"
|
||||||
|
#include "nyx/trace_dump.h"
|
||||||
|
|
||||||
#define PT_BUFFER_MMAP_ADDR 0x3ffff0000000
|
#define PT_BUFFER_MMAP_ADDR 0x3ffff0000000
|
||||||
|
|
||||||
@ -53,55 +54,6 @@ uint32_t last = 0;
|
|||||||
uint32_t alt_bitmap_size = 0;
|
uint32_t alt_bitmap_size = 0;
|
||||||
uint8_t* alt_bitmap = NULL;
|
uint8_t* alt_bitmap = NULL;
|
||||||
|
|
||||||
int pt_trace_dump_fd = 0;
|
|
||||||
char *pt_trace_dump_filename;
|
|
||||||
bool should_dump_pt_trace= false; /* dump PT trace as returned from HW */
|
|
||||||
|
|
||||||
void pt_trace_dump_enable(char* filename)
|
|
||||||
{
|
|
||||||
int test_fd;
|
|
||||||
|
|
||||||
printf("Enable pt trace dump at %s", filename);
|
|
||||||
pt_trace_dump_filename = filename;
|
|
||||||
should_dump_pt_trace = true;
|
|
||||||
|
|
||||||
test_fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0644);
|
|
||||||
if (test_fd < 0)
|
|
||||||
fprintf(stderr, "Error accessing pt_dump output path: %s", strerror(errno));
|
|
||||||
assert(test_fd >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pt_truncate_pt_dump_file(void) {
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (!should_dump_pt_trace)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fd = open(pt_trace_dump_filename, O_CREAT|O_TRUNC|O_WRONLY, 0644);
|
|
||||||
if (fd < 0) {
|
|
||||||
fprintf(stderr, "Error truncating pt_trace_dump: %s\n", strerror(errno));
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pt_write_pt_dump_file(uint8_t *data, size_t bytes)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (!should_dump_pt_trace)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fd = open(pt_trace_dump_filename, O_APPEND|O_WRONLY, 0644);
|
|
||||||
//fd = open(pt_trace_dump_filename, O_CREAT|O_TRUNC|O_WRONLY, 0644);
|
|
||||||
if (fd < 0) {
|
|
||||||
fprintf(stderr, "Error writing pt_trace_dump: %s\n", strerror(errno));
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
assert(bytes == write(fd, data, bytes));
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pt_set(CPUState *cpu, run_on_cpu_data arg){
|
static void pt_set(CPUState *cpu, run_on_cpu_data arg){
|
||||||
asm volatile("" ::: "memory");
|
asm volatile("" ::: "memory");
|
||||||
}
|
}
|
||||||
|
1
nyx/pt.h
1
nyx/pt.h
@ -44,6 +44,5 @@ void pt_post_kvm_run(CPUState *cpu);
|
|||||||
void pt_handle_overflow(CPUState *cpu);
|
void pt_handle_overflow(CPUState *cpu);
|
||||||
void pt_dump(CPUState *cpu, int bytes);
|
void pt_dump(CPUState *cpu, int bytes);
|
||||||
|
|
||||||
void pt_trace_dump_enable(char* filename);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
66
nyx/trace_dump.c
Normal file
66
nyx/trace_dump.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "state/state.h"
|
||||||
|
#include "trace_dump.h"
|
||||||
|
|
||||||
|
/* dump PT trace as returned from HW */
|
||||||
|
|
||||||
|
char *pt_trace_dump_filename;
|
||||||
|
bool pt_dump_initialized = false;
|
||||||
|
bool pt_dump_enabled = false;
|
||||||
|
|
||||||
|
void pt_trace_dump_enable(bool enable){
|
||||||
|
if (pt_dump_initialized)
|
||||||
|
pt_dump_enabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pt_trace_dump_init(char* filename)
|
||||||
|
{
|
||||||
|
int test_fd;
|
||||||
|
|
||||||
|
//fprintf(stderr, "Enable pt trace dump at %s", filename);
|
||||||
|
pt_dump_initialized = true;
|
||||||
|
|
||||||
|
test_fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0644);
|
||||||
|
if (test_fd < 0)
|
||||||
|
fprintf(stderr, "Error accessing pt_dump output path %s: %s", pt_trace_dump_filename, strerror(errno));
|
||||||
|
assert(test_fd >= 0);
|
||||||
|
|
||||||
|
pt_trace_dump_filename = strdup(filename);
|
||||||
|
assert(pt_trace_dump_filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pt_truncate_pt_dump_file(void) {
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (!pt_dump_enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fd = open(pt_trace_dump_filename, O_CREAT|O_TRUNC|O_WRONLY, 0644);
|
||||||
|
if (fd < 0) {
|
||||||
|
fprintf(stderr, "Error truncating %s: %s\n", pt_trace_dump_filename, strerror(errno));
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pt_write_pt_dump_file(uint8_t *data, size_t bytes)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (!pt_dump_enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fd = open(pt_trace_dump_filename, O_APPEND|O_WRONLY, 0644);
|
||||||
|
//fd = open(pt_trace_dump_filename, O_CREAT|O_TRUNC|O_WRONLY, 0644);
|
||||||
|
if (fd < 0) {
|
||||||
|
fprintf(stderr, "Error writing pt_trace_dump to %s: %s\n", pt_trace_dump_filename, strerror(errno));
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
assert(bytes == write(fd, data, bytes));
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
6
nyx/trace_dump.h
Normal file
6
nyx/trace_dump.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void pt_trace_dump_init(char* filename);
|
||||||
|
void pt_trace_dump_enable(bool enable);
|
||||||
|
void pt_write_pt_dump_file(uint8_t *data, size_t bytes);
|
||||||
|
void pt_truncate_pt_dump_file(void);
|
Loading…
x
Reference in New Issue
Block a user