Skip to content

Commit

Permalink
Tender, binding: Fix build failures
Browse files Browse the repository at this point in the history
  • Loading branch information
niks3089 committed Nov 16, 2018
1 parent daf79fb commit 09498ac
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 34 deletions.
17 changes: 0 additions & 17 deletions bindings/hvt/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,12 @@
#include "sinfo.h"
#include "reader.h"
#include "writer.h"
#include "bindings.h"

struct muchannel *tx_channel;
struct muchannel *rx_channel;
struct muchannel_reader net_rdr;
bool shm_enabled = false;

static inline solo5_result_t shm_to_solo5_result(int shm_result)
{
switch(shm_result) {
case SHM_NET_OK:
case SHM_NET_XON:
return SOLO5_R_OK;
case SHM_NET_AGAIN:
case SHM_NET_EPOCH_CHANGED:
return SOLO5_R_AGAIN;
default:
break;
}
return SOLO5_R_EUNSPEC;
}

solo5_result_t solo5_net_queue(const uint8_t *buf, size_t size)
{
int ret;
Expand Down Expand Up @@ -99,7 +83,6 @@ solo5_result_t solo5_net_read(uint8_t *buf, size_t size, size_t *read_size)
rd.ret = 0;

hvt_do_hypercall(HVT_HYPERCALL_NETREAD, &rd);

*read_size = rd.len;
return (rd.ret == 0) ? SOLO5_R_OK : SOLO5_R_AGAIN;
}
Expand Down
5 changes: 3 additions & 2 deletions bindings/muen/muen-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ static uint8_t mac_addr[6];

solo5_result_t solo5_net_write(const uint8_t *buf, size_t size)
{
return shm_net_write(net_out, buf, size);
return shm_to_solo5_result(shm_net_write(net_out, buf, size));
}

solo5_result_t solo5_net_read(uint8_t *buf, size_t size, size_t *read_size)
{
return shm_net_read(net_in, &net_rdr, buf, size, read_size);
return shm_to_solo5_result(shm_net_read(net_in, &net_rdr, buf,
size, read_size));
}

bool muen_net_pending_data()
Expand Down
16 changes: 16 additions & 0 deletions bindings/muen/shm_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "channel.h"
#include "reader.h"
#include "solo5.h"

#define PACKET_SIZE 1514
#define MUENNET_PROTO 0x7ade5c549b08e814ULL
Expand All @@ -37,6 +38,21 @@ typedef enum {
SHM_NET_EINVAL
} shm_net_result_t;

static inline solo5_result_t shm_to_solo5_result(int shm_result)
{
switch(shm_result) {
case SHM_NET_OK:
case SHM_NET_XON:
return SOLO5_R_OK;
case SHM_NET_AGAIN:
case SHM_NET_EPOCH_CHANGED:
return SOLO5_R_AGAIN;
default:
break;
}
return SOLO5_R_EUNSPEC;
}

shm_net_result_t shm_net_write(struct muchannel *channel,
const uint8_t *buf, size_t size);
shm_net_result_t shm_net_read(struct muchannel *channel,
Expand Down
1 change: 1 addition & 0 deletions tenders/hvt/hvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ int hvt_gdb_add_breakpoint(struct hvt *hvt, gdb_breakpoint_type type,
int hvt_gdb_remove_breakpoint(struct hvt *hvt, gdb_breakpoint_type type,
hvt_gpa_t addr, size_t len);

void hvt_add_pagetables(struct hvt *hvt, size_t mem_size);
/*
* Canonical list of host memory regions mapped as the guest memory
*/
Expand Down
6 changes: 6 additions & 0 deletions tenders/hvt/hvt_freebsd_x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ static void dump_vmx(struct vm_exit *vme)
warnx("\tinst_error\t%d", vme->u.vmx.inst_error);
}

void hvt_add_pagetables(struct hvt *hvt, size_t mem_size)
{
/* Not supported yet */
assert(0);
}

int hvt_vcpu_loop(struct hvt *hvt)
{
struct hvt_b *hvb = hvt->b;
Expand Down
6 changes: 6 additions & 0 deletions tenders/hvt/hvt_kvm_aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ static void aarch64_setup_core_registers(struct hvt *hvt,
err(1, "Set guest reset entry to PC failed!\n");
}

void hvt_add_pagetables(struct hvt *hvt, size_t mem_size)
{
/* Not supported yet */
assert(0);
}

void hvt_vcpu_init(struct hvt *hvt, hvt_gpa_t gpa_ep,
hvt_gpa_t gpa_kend, char **cmdline)
{
Expand Down
5 changes: 5 additions & 0 deletions tenders/hvt/hvt_kvm_x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ static struct kvm_segment sreg_to_kvm(const struct x86_sreg *sreg)
return kvm;
}

void hvt_add_pagetables(struct hvt *hvt, size_t mem_size)
{
hvt_x86_add_pagetables(hvt->mem, hvt->mem_size, mem_size);
}

void hvt_vcpu_init(struct hvt *hvt, hvt_gpa_t gpa_ep,
hvt_gpa_t gpa_kend, char **cmdline)
{
Expand Down
37 changes: 22 additions & 15 deletions tenders/hvt/hvt_module_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>

#include "hvt.h"
#include "hvt_abi.h"
#include "shm_net.h"
#include "writer.h"

#if defined(__linux__)

Expand All @@ -51,11 +55,8 @@
#include <pthread.h>
#include <sys/eventfd.h>
#include <sys/epoll.h>
#include "hvt_abi.h"
#include "hvt_kvm.h"
#include "hvt_cpu_x86_64.h"
#include "shm_net.h"
#include "writer.h"
#define MAXEVENTS 5
static pthread_t tid;

Expand All @@ -78,6 +79,10 @@ static pthread_t tid;
#define MAX_PACKETS_READ 90
static char *netiface;
static int netfd;
static struct hvt_netinfo netinfo;
static int cmdline_mac = 0;
static int use_shm_stream = 0;
#if defined(__linux__)
static int epoll_fd, // The big epoll for the io thread
/* Event fd to notify the kernel that shm has packet to read */
kernel_read_fd,
Expand All @@ -87,17 +92,13 @@ static int epoll_fd, // The big epoll for the io thread
tender_xon_notify_fd,
/* Event fd to notify tender that shm has packet to read */
tender_read_fd;
static struct hvt_netinfo netinfo;
static int cmdline_mac = 0;
static int use_shm_stream = 0;
static uint64_t rx_shm_size = 0x0;
static uint64_t tx_shm_size = 0x0;
struct timespec readtime;
struct timespec writetime;
struct timespec epochtime;
struct muchannel *tx_channel;
struct muchannel *rx_channel;
struct muchannel_reader net_rdr;
#endif

/*
* Attach to an existing TAP interface named 'ifname'.
Expand Down Expand Up @@ -328,6 +329,7 @@ void* io_event_loop()

static void hypercall_shm_info(struct hvt *hv, hvt_gpa_t gpa)
{
#if defined(__linux__)
struct hvt_shm_info *info =
HVT_CHECKED_GPA_P(hv, gpa, sizeof (struct hvt_shm_info));

Expand All @@ -339,6 +341,7 @@ static void hypercall_shm_info(struct hvt *hv, hvt_gpa_t gpa)
info->rx_channel_addr_size = tx_shm_size;
info->shm_enabled = true;
}
#endif
}

static void hypercall_netinfo(struct hvt *hvt, hvt_gpa_t gpa)
Expand Down Expand Up @@ -379,19 +382,23 @@ static void hypercall_netread(struct hvt *hvt, hvt_gpa_t gpa)

static void hypercall_netxon(struct hvt *hv, hvt_gpa_t gpa)
{
#if defined(__linux__)
uint64_t xon = 1;
if (write(tender_xon_notify_fd, &xon, 8)) {
warnx("Failed to xon notify the tender\n");
}
#endif
}

/* Notify tender that there is data to send */
static void hypercall_netnotify(struct hvt *hv, hvt_gpa_t gpa)
{
#if defined(__linux__)
uint64_t read_data = 1;
if (write(tender_read_fd, &read_data, 8)) {
warnx("Failed to notify tender about the data in shm\n");
}
#endif
}

static int handle_cmdarg(char *cmdarg)
Expand Down Expand Up @@ -470,7 +477,7 @@ static int configure_epoll()
return 0;
}

static int configure_shmstream(struct hvt *hv)
static int configure_shmstream(struct hvt *hvt)
{
uint64_t offset = 0x0;
uint8_t *shm_mem;
Expand Down Expand Up @@ -509,19 +516,19 @@ static int configure_shmstream(struct hvt *hv)
total_pagesize += X86_GUEST_PAGE_SIZE;
} while(total_pagesize < total_shm_buf_size);

if ((hv->mem_size + total_shm_buf_size) > (X86_GUEST_PAGE_SIZE * 512)) {
if ((hvt->mem_size + total_shm_buf_size) > (X86_GUEST_PAGE_SIZE * 512)) {
err(1, "guest memory size exceeds the max size %u bytes", X86_GUEST_PAGE_SIZE * 512);
goto err;
}

/* RX ring buffer */
struct kvm_userspace_memory_region rxring_region = {
.slot = HVT_SHMSTREAM_RXRING_BUF_REGION,
.guest_phys_addr = hv->mem_size + offset,
.guest_phys_addr = hvt->mem_size + offset,
.memory_size = (uint64_t)(rx_shm_size),
.userspace_addr = (uint64_t)(shm_mem + offset),
};
ret = ioctl(hv->b->vmfd, KVM_SET_USER_MEMORY_REGION, &rxring_region);
ret = ioctl(hvt->b->vmfd, KVM_SET_USER_MEMORY_REGION, &rxring_region);
if (ret == -1) {
err(1, "KVM: ioctl (SET_USER_MEMORY_REGION) failed: shmstream RX ring buffer");
goto err;
Expand All @@ -532,11 +539,11 @@ static int configure_shmstream(struct hvt *hv)
/* TX ring buffer */
struct kvm_userspace_memory_region txring_region = {
.slot = HVT_SHMSTREAM_TXRING_BUF_REGION,
.guest_phys_addr = hv->mem_size + offset,
.guest_phys_addr = hvt->mem_size + offset,
.memory_size = (uint64_t)(tx_shm_size),
.userspace_addr = (uint64_t)(shm_mem + offset),
};
ret = ioctl(hv->b->vmfd, KVM_SET_USER_MEMORY_REGION, &txring_region);
ret = ioctl(hvt->b->vmfd, KVM_SET_USER_MEMORY_REGION, &txring_region);
if (ret == -1) {
err(1, "KVM: ioctl (SET_USER_MEMORY_REGION) failed: shmstream TX ring buffer");
goto err;
Expand All @@ -551,7 +558,7 @@ static int configure_shmstream(struct hvt *hv)
offset += txring_region.memory_size;

printf("offset = 0x%"PRIx64", total_pagesize = 0x%"PRIx64"\n", offset, total_pagesize);
hvt_x86_add_pagetables(hv->mem, hv->mem_size, total_pagesize);
hvt_add_pagetables(hvt, total_pagesize);
muen_channel_init_reader(&net_rdr, MUENNET_PROTO);
if (use_shm_stream) {
if (pthread_create(&tid, NULL, &io_event_loop, NULL) != 0) {
Expand Down
6 changes: 6 additions & 0 deletions tenders/hvt/hvt_openbsd_x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ static struct vcpu_segment_info sreg_to_vsi(const struct x86_sreg *sreg)
return vsi;
}

void hvt_add_pagetables(struct hvt *hvt, size_t mem_size)
{
/* Not supported yet */
assert(0);
}

void hvt_mem_size(size_t *mem_size) {
hvt_x86_mem_size(mem_size);
}
Expand Down

0 comments on commit 09498ac

Please sign in to comment.