diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-07-30 19:45:03 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-07-30 19:45:03 -0400 |
| commit | 6ae7d6f0195a0ec7e5d07821e62c79898cd33fdc (patch) | |
| tree | ed7975b5ae042e16500c1f5cb8b5756a6bf8d643 | |
| parent | ec30c5f3a18722f8fcf8c83146a10b03ac4d9ff1 (diff) | |
| parent | 1842f23c05b6a866be831aa60bc8a8731c58ddd0 (diff) | |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus:
lguest and virtio: cleanup struct definitions to Linux style.
lguest: update commentry
lguest: fix comment style
virtio: refactor find_vqs
virtio: delete vq from list
virtio: fix memory leak on device removal
lguest: fix descriptor corruption in example launcher
lguest: dereferencing freed mem in add_eventfd()
| -rw-r--r-- | Documentation/lguest/lguest.c | 721 | ||||
| -rw-r--r-- | arch/x86/include/asm/lguest.h | 3 | ||||
| -rw-r--r-- | arch/x86/include/asm/lguest_hcall.h | 18 | ||||
| -rw-r--r-- | arch/x86/lguest/boot.c | 509 | ||||
| -rw-r--r-- | arch/x86/lguest/i386_head.S | 112 | ||||
| -rw-r--r-- | drivers/lguest/core.c | 119 | ||||
| -rw-r--r-- | drivers/lguest/hypercalls.c | 145 | ||||
| -rw-r--r-- | drivers/lguest/interrupts_and_traps.c | 288 | ||||
| -rw-r--r-- | drivers/lguest/lg.h | 32 | ||||
| -rw-r--r-- | drivers/lguest/lguest_device.c | 160 | ||||
| -rw-r--r-- | drivers/lguest/lguest_user.c | 232 | ||||
| -rw-r--r-- | drivers/lguest/page_tables.c | 489 | ||||
| -rw-r--r-- | drivers/lguest/segments.c | 106 | ||||
| -rw-r--r-- | drivers/lguest/x86/core.c | 374 | ||||
| -rw-r--r-- | drivers/lguest/x86/switcher_32.S | 22 | ||||
| -rw-r--r-- | drivers/virtio/virtio_pci.c | 240 | ||||
| -rw-r--r-- | include/linux/lguest.h | 39 | ||||
| -rw-r--r-- | include/linux/lguest_launcher.h | 18 | ||||
| -rw-r--r-- | include/linux/virtio_blk.h | 6 | ||||
| -rw-r--r-- | include/linux/virtio_config.h | 3 | ||||
| -rw-r--r-- | include/linux/virtio_net.h | 6 | ||||
| -rw-r--r-- | include/linux/virtio_ring.h | 12 |
22 files changed, 2422 insertions, 1232 deletions
diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c index 9ebcd6ef361b..950cde6d6e58 100644 --- a/Documentation/lguest/lguest.c +++ b/Documentation/lguest/lguest.c | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | /*P:100 This is the Launcher code, a simple program which lays out the | 1 | /*P:100 |
| 2 | * "physical" memory for the new Guest by mapping the kernel image and | 2 | * This is the Launcher code, a simple program which lays out the "physical" |
| 3 | * the virtual devices, then opens /dev/lguest to tell the kernel | 3 | * memory for the new Guest by mapping the kernel image and the virtual |
| 4 | * about the Guest and control it. :*/ | 4 | * devices, then opens /dev/lguest to tell the kernel about the Guest and |
| 5 | * control it. | ||
| 6 | :*/ | ||
| 5 | #define _LARGEFILE64_SOURCE | 7 | #define _LARGEFILE64_SOURCE |
| 6 | #define _GNU_SOURCE | 8 | #define _GNU_SOURCE |
| 7 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -46,13 +48,15 @@ | |||
| 46 | #include "linux/virtio_rng.h" | 48 | #include "linux/virtio_rng.h" |
| 47 | #include "linux/virtio_ring.h" | 49 | #include "linux/virtio_ring.h" |
| 48 | #include "asm/bootparam.h" | 50 | #include "asm/bootparam.h" |
| 49 | /*L:110 We can ignore the 39 include files we need for this program, but I do | 51 | /*L:110 |
| 50 | * want to draw attention to the use of kernel-style types. | 52 | * We can ignore the 42 include files we need for this program, but I do want |
| 53 | * to draw attention to the use of kernel-style types. | ||
| 51 | * | 54 | * |
| 52 | * As Linus said, "C is a Spartan language, and so should your naming be." I | 55 | * As Linus said, "C is a Spartan language, and so should your naming be." I |
| 53 | * like these abbreviations, so we define them here. Note that u64 is always | 56 | * like these abbreviations, so we define them here. Note that u64 is always |
| 54 | * unsigned long long, which works on all Linux systems: this means that we can | 57 | * unsigned long long, which works on all Linux systems: this means that we can |
| 55 | * use %llu in printf for any u64. */ | 58 | * use %llu in printf for any u64. |
| 59 | */ | ||
| 56 | typedef unsigned long long u64; | 60 | typedef unsigned long long u64; |
| 57 | typedef uint32_t u32; | 61 | typedef uint32_t u32; |
| 58 | typedef uint16_t u16; | 62 | typedef uint16_t u16; |
| @@ -69,8 +73,10 @@ typedef uint8_t u8; | |||
| 69 | /* This will occupy 3 pages: it must be a power of 2. */ | 73 | /* This will occupy 3 pages: it must be a power of 2. */ |
| 70 | #define VIRTQUEUE_NUM 256 | 74 | #define VIRTQUEUE_NUM 256 |
| 71 | 75 | ||
| 72 | /*L:120 verbose is both a global flag and a macro. The C preprocessor allows | 76 | /*L:120 |
| 73 | * this, and although I wouldn't recommend it, it works quite nicely here. */ | 77 | * verbose is both a global flag and a macro. The C preprocessor allows |
| 78 | * this, and although I wouldn't recommend it, it works quite nicely here. | ||
| 79 | */ | ||
| 74 | static bool verbose; | 80 | static bool verbose; |
| 75 | #define verbose(args...) \ | 81 | #define verbose(args...) \ |
| 76 | do { if (verbose) printf(args); } while(0) | 82 | do { if (verbose) printf(args); } while(0) |
| @@ -87,8 +93,7 @@ static int lguest_fd; | |||
| 87 | static unsigned int __thread cpu_id; | 93 | static unsigned int __thread cpu_id; |
| 88 | 94 | ||
| 89 | /* This is our list of devices. */ | 95 | /* This is our list of devices. */ |
| 90 | struct device_list | 96 | struct device_list { |
| 91 | { | ||
| 92 | /* Counter to assign interrupt numbers. */ | 97 | /* Counter to assign interrupt numbers. */ |
| 93 | unsigned int next_irq; | 98 | unsigned int next_irq; |
| 94 | 99 | ||
| @@ -100,8 +105,7 @@ struct device_list | |||
| 100 | 105 | ||
| 101 | /* A single linked list of devices. */ | 106 | /* A single linked list of devices. */ |
| 102 | struct device *dev; | 107 | struct device *dev; |
| 103 | /* And a pointer to the last device for easy append and also for | 108 | /* And a pointer to the last device for easy append. */ |
| 104 | * configuration appending. */ | ||
| 105 | struct device *lastdev; | 109 | struct device *lastdev; |
| 106 | }; | 110 | }; |
| 107 | 111 | ||
| @@ -109,8 +113,7 @@ struct device_list | |||
| 109 | static struct device_list devices; | 113 | static struct device_list devices; |
| 110 | 114 | ||
| 111 | /* The device structure describes a single device. */ | 115 | /* The device structure describes a single device. */ |
| 112 | struct device | 116 | struct device { |
| 113 | { | ||
| 114 | /* The linked-list pointer. */ | 117 | /* The linked-list pointer. */ |
| 115 | struct device *next; | 118 | struct device *next; |
| 116 | 119 | ||
| @@ -135,8 +138,7 @@ struct device | |||
| 135 | }; | 138 | }; |
| 136 | 139 | ||
| 137 | /* The virtqueue structure describes a queue attached to a device. */ | 140 | /* The virtqueue structure describes a queue attached to a device. */ |
| 138 | struct virtqueue | 141 | struct virtqueue { |
| 139 | { | ||
| 140 | struct virtqueue *next; | 142 | struct virtqueue *next; |
| 141 | 143 | ||
| 142 | /* Which device owns me. */ | 144 | /* Which device owns me. */ |
| @@ -168,20 +170,24 @@ static char **main_args; | |||
| 168 | /* The original tty settings to restore on exit. */ | 170 | /* The original tty settings to restore on exit. */ |
| 169 | static struct termios orig_term; | 171 | static struct termios orig_term; |
| 170 | 172 | ||
| 171 | /* We have to be careful with barriers: our devices are all run in separate | 173 | /* |
| 174 | * We have to be careful with barriers: our devices are all run in separate | ||
| 172 | * threads and so we need to make sure that changes visible to the Guest happen | 175 | * threads and so we need to make sure that changes visible to the Guest happen |
| 173 | * in precise order. */ | 176 | * in precise order. |
| 177 | */ | ||
| 174 | #define wmb() __asm__ __volatile__("" : : : "memory") | 178 | #define wmb() __asm__ __volatile__("" : : : "memory") |
| 175 | #define mb() __asm__ __volatile__("" : : : "memory") | 179 | #define mb() __asm__ __volatile__("" : : : "memory") |
| 176 | 180 | ||
| 177 | /* Convert an iovec element to the given type. | 181 | /* |
| 182 | * Convert an iovec element to the given type. | ||
| 178 | * | 183 | * |
| 179 | * This is a fairly ugly trick: we need to know the size of the type and | 184 | * This is a fairly ugly trick: we need to know the size of the type and |
| 180 | * alignment requirement to check the pointer is kosher. It's also nice to | 185 | * alignment requirement to check the pointer is kosher. It's also nice to |
| 181 | * have the name of the type in case we report failure. | 186 | * have the name of the type in case we report failure. |
| 182 | * | 187 | * |
| 183 | * Typing those three things all the time is cumbersome and error prone, so we | 188 | * Typing those three things all the time is cumbersome and error prone, so we |
| 184 | * have a macro which sets them all up and passes to the real function. */ | 189 | * have a macro which sets them all up and passes to the real function. |
| 190 | */ | ||
| 185 | #define convert(iov, type) \ | 191 | #define convert(iov, type) \ |
| 186 | ((type *)_convert((iov), sizeof(type), __alignof__(type), #type)) | 192 | ((type *)_convert((iov), sizeof(type), __alignof__(type), #type)) |
| 187 | 193 | ||
| @@ -198,8 +204,10 @@ static void *_convert(struct iovec *iov, size_t size, size_t align, | |||
| 198 | /* Wrapper for the last available index. Makes it easier to change. */ | 204 | /* Wrapper for the last available index. Makes it easier to change. */ |
| 199 | #define lg_last_avail(vq) ((vq)->last_avail_idx) | 205 | #define lg_last_avail(vq) ((vq)->last_avail_idx) |
| 200 | 206 | ||
| 201 | /* The virtio configuration space is defined to be little-endian. x86 is | 207 | /* |
| 202 | * little-endian too, but it's nice to be explicit so we have these helpers. */ | 208 | * The virtio configuration space is defined to be little-endian. x86 is |
| 209 | * little-endian too, but it's nice to be explicit so we have these helpers. | ||
| 210 | */ | ||
| 203 | #define cpu_to_le16(v16) (v16) | 211 | #define cpu_to_le16(v16) (v16) |
| 204 | #define cpu_to_le32(v32) (v32) | 212 | #define cpu_to_le32(v32) (v32) |
| 205 | #define cpu_to_le64(v64) (v64) | 213 | #define cpu_to_le64(v64) (v64) |
| @@ -241,11 +249,12 @@ static u8 *get_feature_bits(struct device *dev) | |||
| 241 | + dev->num_vq * sizeof(struct lguest_vqconfig); | 249 | + dev->num_vq * sizeof(struct lguest_vqconfig); |
| 242 | } | 250 | } |
| 243 | 251 | ||
| 244 | /*L:100 The Launcher code itself takes us out into userspace, that scary place | ||
