Skip to content

Commit 521052c

Browse files
consume latest hooklift goodies
Signed-off-by: António Meireles <antonio.meireles@reformi.st>
1 parent a8bac3c commit 521052c

File tree

14 files changed

+192
-76
lines changed

14 files changed

+192
-76
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
cmd/xhyve/imgs/stable*
22
cmd/xhyve/xhyve
33
vendor
4+
xhyve

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ build:
55

66
clone-xhyve:
77
-git clone https://github.com/xhyve-xyz/xhyve.git vendor/xhyve
8+
# cherry-picked from https://github.com/c4milo/xhyve/commit/53b63a8819f35a123fb67f2ce5dba21f34cf97b9
9+
# "Makes user message less verbose when using autopty"
10+
-cd vendor/xhyve; curl -Ls https://github.com/c4milo/xhyve/commit/53b63a8819f35a123fb67f2ce5dba21f34cf97b9.patch | patch -N -p1
11+
# cherry-picked from https://github.com/mist64/xhyve/pull/81
12+
# Fix non-deterministic delays when accessing a vcpu in "running" or "sleeping" state.
13+
-cd vendor/xhyve; curl -Ls https://patch-diff.githubusercontent.com/raw/mist64/xhyve/pull/81.patch | patch -N -p1
814

915
sync: clone-xhyve apply-patch
1016
find . \( -name \*.orig -o -name \*.rej \) -delete

include/xhyve/uart_emul.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ struct uart_softc *uart_init(uart_intr_func_t intr_assert,
3939
int uart_legacy_alloc(int unit, int *ioaddr, int *irq);
4040
uint8_t uart_read(struct uart_softc *sc, int offset);
4141
void uart_write(struct uart_softc *sc, int offset, uint8_t value);
42-
int uart_set_backend(struct uart_softc *sc, const char *opt);
42+
int uart_set_backend(struct uart_softc *sc, const char *backend, const char *devname);
43+
44+
extern void go_set_pty_name(char *name);

include/xhyve/vmm/vmm.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,18 @@ struct vm_object;
6262
struct vm_guest_paging;
6363
struct pmap;
6464

65+
struct vm_eventinfo {
66+
void *rptr; /* rendezvous cookie */
67+
int *sptr; /* suspend cookie */
68+
int *iptr; /* reqidle cookie */
69+
};
70+
6571
typedef int (*vmm_init_func_t)(void);
6672
typedef int (*vmm_cleanup_func_t)(void);
6773
typedef void *(*vmi_vm_init_func_t)(struct vm *vm);
6874
typedef int (*vmi_vcpu_init_func_t)(void *vmi, int vcpu);
6975
typedef int (*vmi_run_func_t)(void *vmi, int vcpu, register_t rip,
70-
void *rendezvous_cookie, void *suspend_cookie);
76+
struct vm_eventinfo *info);
7177
typedef void (*vmi_vm_cleanup_func_t)(void *vmi);
7278
typedef void (*vmi_vcpu_cleanup_func_t)(void *vmi, int vcpu);
7379
typedef int (*vmi_get_register_t)(void *vmi, int vcpu, int num,
@@ -145,6 +151,7 @@ int vm_activate_cpu(struct vm *vm, int vcpu);
145151
struct vm_exit *vm_exitinfo(struct vm *vm, int vcpuid);
146152
void vm_exit_suspended(struct vm *vm, int vcpuid, uint64_t rip);
147153
void vm_exit_rendezvous(struct vm *vm, int vcpuid, uint64_t rip);
154+
void vm_exit_reqidle(struct vm *vm, int vcpuid, uint64_t rip);
148155

149156
/*
150157
* Rendezvous all vcpus specified in 'dest' and execute 'func(arg)'.
@@ -167,17 +174,21 @@ cpuset_t vm_active_cpus(struct vm *vm);
167174
cpuset_t vm_suspended_cpus(struct vm *vm);
168175

169176
static __inline int
170-
vcpu_rendezvous_pending(void *rendezvous_cookie)
177+
vcpu_rendezvous_pending(struct vm_eventinfo *info)
171178
{
172-
173-
return (*(uintptr_t *)rendezvous_cookie != 0);
179+
return (*((uintptr_t *)(info->rptr)) != 0);
174180
}
175181

176182
static __inline int
177-
vcpu_suspended(void *suspend_cookie)
183+
vcpu_suspended(struct vm_eventinfo *info)
178184
{
185+
return (*info->sptr);
186+
}
179187

180-
return (*(int *)suspend_cookie);
188+
static __inline int
189+
vcpu_reqidle(struct vm_eventinfo *info)
190+
{
191+
return (*info->iptr);
181192
}
182193

183194
enum vcpu_state {
@@ -256,7 +267,7 @@ struct vm_copyinfo {
256267
/*
257268
* Set up 'copyinfo[]' to copy to/from guest linear address space starting
258269
* at 'gla' and 'len' bytes long. The 'prot' should be set to PROT_READ for
259-
* a copyin or PROT_WRITE for a copyout.
270+
* a copyin or PROT_WRITE for a copyout.
260271
*
261272
* retval is_fault Intepretation
262273
* 0 0 Success

include/xhyve/vmm/vmm_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ enum vm_exitcode {
143143
VM_EXITCODE_INOUT,
144144
VM_EXITCODE_VMX,
145145
VM_EXITCODE_BOGUS,
146+
VM_EXITCODE_REQIDLE,
146147
VM_EXITCODE_RDMSR,
147148
VM_EXITCODE_WRMSR,
148149
VM_EXITCODE_HLT,

include/xhyve/vmm/vmm_ktr.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,32 @@ struct vm;
4141
extern const char *vm_name(struct vm *vm);
4242

4343
#define VCPU_CTR0(vm, vcpuid, format) \
44-
vmmtrace("vm %s[%d]: " format "\n", vm_name((vm)), (vcpuid))
44+
vmmtrace("vm %s[%d]: " format "\r\n", vm_name((vm)), (vcpuid))
4545

4646
#define VCPU_CTR1(vm, vcpuid, format, p1) \
47-
vmmtrace("vm %s[%d]: " format "\n", vm_name((vm)), (vcpuid), (p1))
47+
vmmtrace("vm %s[%d]: " format "\r\n", vm_name((vm)), (vcpuid), (p1))
4848

4949
#define VCPU_CTR2(vm, vcpuid, format, p1, p2) \
50-
vmmtrace("vm %s[%d]: " format "\n", vm_name((vm)), (vcpuid), (p1), (p2))
50+
vmmtrace("vm %s[%d]: " format "\r\n", vm_name((vm)), (vcpuid), (p1), (p2))
5151

5252
#define VCPU_CTR3(vm, vcpuid, format, p1, p2, p3) \
53-
vmmtrace("vm %s[%d]: " format "\n", vm_name((vm)), (vcpuid), (p1), (p2), (p3))
53+
vmmtrace("vm %s[%d]: " format "\r\n", vm_name((vm)), (vcpuid), (p1), (p2), (p3))
5454

5555
#define VCPU_CTR4(vm, vcpuid, format, p1, p2, p3, p4) \
56-
vmmtrace("vm %s[%d]: " format "\n", vm_name((vm)), (vcpuid), \
56+
vmmtrace("vm %s[%d]: " format "\r\n", vm_name((vm)), (vcpuid), \
5757
(p1), (p2), (p3), (p4))
5858

5959
#define VM_CTR0(vm, format) \
60-
vmmtrace("vm %s: " format "\n", vm_name((vm)))
60+
vmmtrace("vm %s: " format "\r\n", vm_name((vm)))
6161

6262
#define VM_CTR1(vm, format, p1) \
63-
vmmtrace("vm %s: " format "\n", vm_name((vm)), (p1))
63+
vmmtrace("vm %s: " format "\r\n", vm_name((vm)), (p1))
6464

6565
#define VM_CTR2(vm, format, p1, p2) \
66-
vmmtrace("vm %s: " format "\n", vm_name((vm)), (p1), (p2))
66+
vmmtrace("vm %s: " format "\r\n", vm_name((vm)), (p1), (p2))
6767

6868
#define VM_CTR3(vm, format, p1, p2, p3) \
69-
vmmtrace("vm %s: " format "\n", vm_name((vm)), (p1), (p2), (p3))
69+
vmmtrace("vm %s: " format "\r\n", vm_name((vm)), (p1), (p2), (p3))
7070

7171
#define VM_CTR4(vm, format, p1, p2, p3, p4) \
72-
vmmtrace("vm %s: " format "\n", vm_name((vm)), (p1), (p2), (p3), (p4))
72+
vmmtrace("vm %s: " format "\r\n", vm_name((vm)), (p1), (p2), (p3), (p4))

include/xhyve/vmm/vmm_stat.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ vmm_stat_array_incr(struct vm *vm, int vcpu, struct vmm_stat_type *vst,
101101
{
102102
#ifdef XHYVE_CONFIG_STATS
103103
uint64_t *stats;
104-
104+
105105
stats = vcpu_stats(vm, vcpu);
106106

107107
if (vst->index >= 0 && statidx < vst->nelems)
@@ -121,7 +121,7 @@ vmm_stat_array_set(struct vm *vm, int vcpu, struct vmm_stat_type *vst,
121121
{
122122
#ifdef XHYVE_CONFIG_STATS
123123
uint64_t *stats;
124-
124+
125125
stats = vcpu_stats(vm, vcpu);
126126

127127
if (vst->index >= 0 && statidx < vst->nelems)
@@ -134,7 +134,7 @@ vmm_stat_array_set(struct vm *vm, int vcpu, struct vmm_stat_type *vst,
134134
(void) val;
135135
#endif
136136
}
137-
137+
138138
static void __inline
139139
vmm_stat_incr(struct vm *vm, int vcpu, struct vmm_stat_type *vst, uint64_t x)
140140
{
@@ -183,3 +183,4 @@ VMM_STAT_DECLARE(VMEXIT_ASTPENDING);
183183
VMM_STAT_DECLARE(VMEXIT_USERSPACE);
184184
VMM_STAT_DECLARE(VMEXIT_RENDEZVOUS);
185185
VMM_STAT_DECLARE(VMEXIT_EXCEPTION);
186+
VMM_STAT_DECLARE(VMEXIT_REQIDLE);

pci_lpc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static struct pci_devinst *lpc_bridge;
6363
static struct lpc_uart_softc {
6464
struct uart_softc *uart_softc;
6565
const char *opts;
66+
const char *name;
6667
int iobase;
6768
int irq;
6869
int enabled;
@@ -89,6 +90,7 @@ lpc_device_parse(const char *opts)
8990
for (unit = 0; unit < LPC_UART_NUM; unit++) {
9091
if (strcasecmp(lpcdev, lpc_uart_names[unit]) == 0) {
9192
lpc_uart_softc[unit].opts = str;
93+
lpc_uart_softc[unit].name = lpc_uart_names[unit];
9294
error = 0;
9395
goto done;
9496
}
@@ -115,7 +117,7 @@ lpc_uart_intr_assert(void *arg)
115117
static void
116118
lpc_uart_intr_deassert(UNUSED void *arg)
117119
{
118-
/*
120+
/*
119121
* The COM devices on the LPC bus generate edge triggered interrupts,
120122
* so nothing more to do here.
121123
*/
@@ -158,32 +160,30 @@ lpc_init(void)
158160
{
159161
struct lpc_uart_softc *sc;
160162
struct inout_port iop;
161-
const char *name;
162163
int unit, error;
163164

164165
/* COM1 and COM2 */
165166
for (unit = 0; unit < LPC_UART_NUM; unit++) {
166167
sc = &lpc_uart_softc[unit];
167-
name = lpc_uart_names[unit];
168168

169169
if (uart_legacy_alloc(unit, &sc->iobase, &sc->irq) != 0) {
170170
fprintf(stderr, "Unable to allocate resources for "
171-
"LPC device %s\n", name);
171+
"LPC device %s\n", sc->name);
172172
return (-1);
173173
}
174174
pci_irq_reserve(sc->irq);
175175

176176
sc->uart_softc = uart_init(lpc_uart_intr_assert,
177177
lpc_uart_intr_deassert, sc);
178178

179-
if (uart_set_backend(sc->uart_softc, sc->opts) != 0) {
179+
if (uart_set_backend(sc->uart_softc, sc->opts, sc->name) != 0) {
180180
fprintf(stderr, "Unable to initialize backend '%s' "
181-
"for LPC device %s\n", sc->opts, name);
181+
"for LPC device %s\n", sc->opts, sc->name);
182182
return (-1);
183183
}
184184

185185
bzero(&iop, sizeof(struct inout_port));
186-
iop.name = name;
186+
iop.name = sc->name;
187187
iop.port = sc->iobase;
188188
iop.size = UART_IO_BAR_SIZE;
189189
iop.flags = IOPORT_F_INOUT;

pci_uart.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static int
8686
pci_uart_init(struct pci_devinst *pi, char *opts)
8787
{
8888
struct uart_softc *sc;
89+
char *name;
8990

9091
pci_emul_alloc_bar(pi, 0, PCIBAR_IO, UART_IO_BAR_SIZE);
9192
pci_lintr_request(pi);
@@ -98,12 +99,14 @@ pci_uart_init(struct pci_devinst *pi, char *opts)
9899
sc = uart_init(pci_uart_intr_assert, pci_uart_intr_deassert, pi);
99100
pi->pi_arg = sc;
100101

101-
if (uart_set_backend(sc, opts) != 0) {
102-
fprintf(stderr, "Unable to initialize backend '%s' for "
103-
"pci uart at %d:%d\n", opts, pi->pi_slot, pi->pi_func);
102+
asprintf(&name, "pci uart at %d:%d", pi->pi_slot, pi->pi_func);
103+
if (uart_set_backend(sc, opts, name) != 0) {
104+
fprintf(stderr, "Unable to initialize backend '%s' for %s\n", opts, name);
105+
free(name);
104106
return (-1);
105107
}
106108

109+
free(name);
107110
return (0);
108111
}
109112

uart_emul.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,14 @@ uart_init(uart_intr_func_t intr_assert, uart_intr_func_t intr_deassert,
611611
}
612612

613613
static int
614-
uart_tty_backend(struct uart_softc *sc, const char *opts)
614+
uart_tty_backend(struct uart_softc *sc, const char *backend)
615615
{
616616
int fd;
617617
int retval;
618618

619619
retval = -1;
620620

621-
fd = open(opts, O_RDWR | O_NONBLOCK);
621+
fd = open(backend, O_RDWR | O_NONBLOCK);
622622
if (fd > 0 && isatty(fd)) {
623623
sc->tty.fd = fd;
624624
sc->tty.opened = true;
@@ -629,23 +629,23 @@ uart_tty_backend(struct uart_softc *sc, const char *opts)
629629
}
630630

631631
int
632-
uart_set_backend(struct uart_softc *sc, const char *opts)
632+
uart_set_backend(struct uart_softc *sc, const char *backend, const char *devname)
633633
{
634634
int retval;
635635
int ptyfd;
636636
char *ptyname;
637637

638638
retval = -1;
639639

640-
if (opts == NULL)
640+
if (backend == NULL)
641641
return (0);
642642

643-
if (strcmp("stdio", opts) == 0 && !uart_stdio) {
643+
if (strcmp("stdio", backend) == 0 && !uart_stdio) {
644644
sc->tty.fd = STDIN_FILENO;
645645
sc->tty.opened = true;
646646
uart_stdio = true;
647647
retval = fcntl(sc->tty.fd, F_SETFL, O_NONBLOCK);
648-
} else if (strcmp("autopty", opts) == 0) {
648+
} else if (strcmp("autopty", backend) == 0) {
649649
if ((ptyfd = open("/dev/ptmx", O_RDWR | O_NONBLOCK)) == -1) {
650650
fprintf(stderr, "error opening /dev/ptmx char device");
651651
return retval;
@@ -666,12 +666,16 @@ uart_set_backend(struct uart_softc *sc, const char *opts)
666666
return retval;
667667
}
668668

669-
fprintf(stdout, "Hook up a terminal emulator to %s in order to access your VM\n", ptyname);
669+
fprintf(stdout, "%s connected to %s\n", devname, ptyname);
670+
671+
// Sends to Go land the device path name for the slave pseudo-terminal.
672+
go_set_pty_name(ptyname);
673+
670674
sc->tty.fd = ptyfd;
671675
sc->tty.name = ptyname;
672676
sc->tty.opened = true;
673677
retval = 0;
674-
} else if (uart_tty_backend(sc, opts) == 0) {
678+
} else if (uart_tty_backend(sc, backend) == 0) {
675679
retval = 0;
676680
}
677681

0 commit comments

Comments
 (0)