aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lguest/lguest.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lguest/lguest.c')
-rw-r--r--tools/lguest/lguest.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c
index 07a03452c227..68f67cf3d318 100644
--- a/tools/lguest/lguest.c
+++ b/tools/lguest/lguest.c
@@ -42,14 +42,6 @@
42#include <pwd.h> 42#include <pwd.h>
43#include <grp.h> 43#include <grp.h>
44 44
45#include <linux/virtio_config.h>
46#include <linux/virtio_net.h>
47#include <linux/virtio_blk.h>
48#include <linux/virtio_console.h>
49#include <linux/virtio_rng.h>
50#include <linux/virtio_ring.h>
51#include <asm/bootparam.h>
52#include "../../include/linux/lguest_launcher.h"
53/*L:110 45/*L:110
54 * We can ignore the 43 include files we need for this program, but I do want 46 * We can ignore the 43 include files we need for this program, but I do want
55 * to draw attention to the use of kernel-style types. 47 * to draw attention to the use of kernel-style types.
@@ -65,6 +57,15 @@ typedef uint16_t u16;
65typedef uint8_t u8; 57typedef uint8_t u8;
66/*:*/ 58/*:*/
67 59
60#include <linux/virtio_config.h>
61#include <linux/virtio_net.h>
62#include <linux/virtio_blk.h>
63#include <linux/virtio_console.h>
64#include <linux/virtio_rng.h>
65#include <linux/virtio_ring.h>
66#include <asm/bootparam.h>
67#include "../../include/linux/lguest_launcher.h"
68
68#define BRIDGE_PFX "bridge:" 69#define BRIDGE_PFX "bridge:"
69#ifndef SIOCBRADDIF 70#ifndef SIOCBRADDIF
70#define SIOCBRADDIF 0x89a2 /* add interface to bridge */ 71#define SIOCBRADDIF 0x89a2 /* add interface to bridge */
@@ -177,7 +178,8 @@ static struct termios orig_term;
177 * in precise order. 178 * in precise order.
178 */ 179 */
179#define wmb() __asm__ __volatile__("" : : : "memory") 180#define wmb() __asm__ __volatile__("" : : : "memory")
180#define mb() __asm__ __volatile__("" : : : "memory") 181#define rmb() __asm__ __volatile__("lock; addl $0,0(%%esp)" : : : "memory")
182#define mb() __asm__ __volatile__("lock; addl $0,0(%%esp)" : : : "memory")
181 183
182/* Wrapper for the last available index. Makes it easier to change. */ 184/* Wrapper for the last available index. Makes it easier to change. */
183#define lg_last_avail(vq) ((vq)->last_avail_idx) 185#define lg_last_avail(vq) ((vq)->last_avail_idx)
@@ -676,6 +678,12 @@ static unsigned wait_for_vq_desc(struct virtqueue *vq,
676 errx(1, "Guest moved used index from %u to %u", 678 errx(1, "Guest moved used index from %u to %u",
677 last_avail, vq->vring.avail->idx); 679 last_avail, vq->vring.avail->idx);
678 680
681 /*
682 * Make sure we read the descriptor number *after* we read the ring
683 * update; don't let the cpu or compiler change the order.
684 */
685 rmb();
686
679 /* 687 /*
680 * Grab the next descriptor number they're advertising, and increment 688 * Grab the next descriptor number they're advertising, and increment
681 * the index we've seen. 689 * the index we've seen.
@@ -695,6 +703,12 @@ static unsigned wait_for_vq_desc(struct virtqueue *vq,
695 i = head; 703 i = head;
696 704
697 /* 705 /*
706 * We have to read the descriptor after we read the descriptor number,
707 * but there's a data dependency there so the CPU shouldn't reorder
708 * that: no rmb() required.
709 */
710
711 /*
698 * If this is an indirect entry, then this buffer contains a descriptor 712 * If this is an indirect entry, then this buffer contains a descriptor
699 * table which we handle as if it's any normal descriptor chain. 713 * table which we handle as if it's any normal descriptor chain.
700 */ 714 */