Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: struct device - replace bus_id with dev_name()
lguest: move the initial guest page table creation code to the host
kvm-s390: implement config_changed for virtio on s390
virtio_console: support console resizing
virtio: add PCI device release() function
virtio_blk: fix type warning
virtio: block: dynamic maximum segments
virtio: set max_segment_size and max_sectors to infinite.
virtio: avoid implicit use of Linux page size in balloon interface
virtio: hand virtio ring alignment as argument to vring_new_virtqueue
virtio: use KVM_S390_VIRTIO_RING_ALIGN instead of relying on pagesize
virtio: use LGUEST_VRING_ALIGN instead of relying on pagesize
virtio: Don't use PAGE_SIZE for vring alignment in virtio_pci.
virtio: rename 'pagesize' arg to vring_init/vring_size
virtio: Don't use PAGE_SIZE in virtio_pci.c
virtio: struct device - replace bus_id with dev_name(), dev_set_name()
virtio-pci queue allocation not page-aligned

+253 -135
+9 -57
Documentation/lguest/lguest.c
··· 481 481 /* We return the initrd size. */ 482 482 return len; 483 483 } 484 - 485 - /* Once we know how much memory we have we can construct simple linear page 486 - * tables which set virtual == physical which will get the Guest far enough 487 - * into the boot to create its own. 488 - * 489 - * We lay them out of the way, just below the initrd (which is why we need to 490 - * know its size here). */ 491 - static unsigned long setup_pagetables(unsigned long mem, 492 - unsigned long initrd_size) 493 - { 494 - unsigned long *pgdir, *linear; 495 - unsigned int mapped_pages, i, linear_pages; 496 - unsigned int ptes_per_page = getpagesize()/sizeof(void *); 497 - 498 - mapped_pages = mem/getpagesize(); 499 - 500 - /* Each PTE page can map ptes_per_page pages: how many do we need? */ 501 - linear_pages = (mapped_pages + ptes_per_page-1)/ptes_per_page; 502 - 503 - /* We put the toplevel page directory page at the top of memory. */ 504 - pgdir = from_guest_phys(mem) - initrd_size - getpagesize(); 505 - 506 - /* Now we use the next linear_pages pages as pte pages */ 507 - linear = (void *)pgdir - linear_pages*getpagesize(); 508 - 509 - /* Linear mapping is easy: put every page's address into the mapping in 510 - * order. PAGE_PRESENT contains the flags Present, Writable and 511 - * Executable. */ 512 - for (i = 0; i < mapped_pages; i++) 513 - linear[i] = ((i * getpagesize()) | PAGE_PRESENT); 514 - 515 - /* The top level points to the linear page table pages above. */ 516 - for (i = 0; i < mapped_pages; i += ptes_per_page) { 517 - pgdir[i/ptes_per_page] 518 - = ((to_guest_phys(linear) + i*sizeof(void *)) 519 - | PAGE_PRESENT); 520 - } 521 - 522 - verbose("Linear mapping of %u pages in %u pte pages at %#lx\n", 523 - mapped_pages, linear_pages, to_guest_phys(linear)); 524 - 525 - /* We return the top level (guest-physical) address: the kernel needs 526 - * to know where it is. */ 527 - return to_guest_phys(pgdir); 528 - } 529 484 /*:*/ 530 485 531 486 /* Simple routine to roll all the commandline arguments together with spaces ··· 503 548 504 549 /*L:185 This is where we actually tell the kernel to initialize the Guest. We 505 550 * saw the arguments it expects when we looked at initialize() in lguest_user.c: 506 - * the base of Guest "physical" memory, the top physical page to allow, the 507 - * top level pagetable and the entry point for the Guest. */ 508 - static int tell_kernel(unsigned long pgdir, unsigned long start) 551 + * the base of Guest "physical" memory, the top physical page to allow and the 552 + * entry point for the Guest. */ 553 + static int tell_kernel(unsigned long start) 509 554 { 510 555 unsigned long args[] = { LHREQ_INITIALIZE, 511 556 (unsigned long)guest_base, 512 - guest_limit / getpagesize(), pgdir, start }; 557 + guest_limit / getpagesize(), start }; 513 558 int fd; 514 559 515 560 verbose("Guest: %p - %p (%#lx)\n", ··· 985 1030 /* Zero out the virtqueues. */ 986 1031 for (vq = dev->vq; vq; vq = vq->next) { 987 1032 memset(vq->vring.desc, 0, 988 - vring_size(vq->config.num, getpagesize())); 1033 + vring_size(vq->config.num, LGUEST_VRING_ALIGN)); 989 1034 lg_last_avail(vq) = 0; 990 1035 } 991 1036 } else if (dev->desc->status & VIRTIO_CONFIG_S_FAILED) { ··· 1166 1211 void *p; 1167 1212 1168 1213 /* First we need some memory for this virtqueue. */ 1169 - pages = (vring_size(num_descs, getpagesize()) + getpagesize() - 1) 1214 + pages = (vring_size(num_descs, LGUEST_VRING_ALIGN) + getpagesize() - 1) 1170 1215 / getpagesize(); 1171 1216 p = get_pages(pages); 1172 1217 ··· 1183 1228 vq->config.pfn = to_guest_phys(p) / getpagesize(); 1184 1229 1185 1230 /* Initialize the vring. */ 1186 - vring_init(&vq->vring, num_descs, p, getpagesize()); 1231 + vring_init(&vq->vring, num_descs, p, LGUEST_VRING_ALIGN); 1187 1232 1188 1233 /* Append virtqueue to this device's descriptor. We use 1189 1234 * device_config() to get the end of the device's current virtqueues; ··· 1896 1941 { 1897 1942 /* Memory, top-level pagetable, code startpoint and size of the 1898 1943 * (optional) initrd. */ 1899 - unsigned long mem = 0, pgdir, start, initrd_size = 0; 1944 + unsigned long mem = 0, start, initrd_size = 0; 1900 1945 /* Two temporaries and the /dev/lguest file descriptor. */ 1901 1946 int i, c, lguest_fd; 1902 1947 /* The boot information for the Guest. */ ··· 1995 2040 boot->hdr.type_of_loader = 0xFF; 1996 2041 } 1997 2042 1998 - /* Set up the initial linear pagetables, starting below the initrd. */ 1999 - pgdir = setup_pagetables(mem, initrd_size); 2000 - 2001 2043 /* The Linux boot header contains an "E820" memory map: ours is a 2002 2044 * simple, single region. */ 2003 2045 boot->e820_entries = 1; ··· 2016 2064 2017 2065 /* We tell the kernel to initialize the Guest: this returns the open 2018 2066 * /dev/lguest file descriptor. */ 2019 - lguest_fd = tell_kernel(pgdir, start); 2067 + lguest_fd = tell_kernel(start); 2020 2068 2021 2069 /* We clone off a thread, which wakes the Launcher whenever one of the 2022 2070 * input file descriptors needs attention. We call this the Waker, and
+4
arch/s390/include/asm/kvm_virtio.h
··· 50 50 #define KVM_S390_VIRTIO_RESET 1 51 51 #define KVM_S390_VIRTIO_SET_STATUS 2 52 52 53 + /* The alignment to use between consumer and producer parts of vring. 54 + * This is pagesize for historical reasons. */ 55 + #define KVM_S390_VIRTIO_RING_ALIGN 4096 56 + 53 57 #ifdef __KERNEL__ 54 58 /* early virtio console setup */ 55 59 #ifdef CONFIG_S390_GUEST
-15
arch/x86/lguest/i386_head.S
··· 30 30 movl $lguest_data - __PAGE_OFFSET, %edx 31 31 int $LGUEST_TRAP_ENTRY 32 32 33 - /* The Host put the toplevel pagetable in lguest_data.pgdir. The movsl 34 - * instruction uses %esi implicitly as the source for the copy we're 35 - * about to do. */ 36 - movl lguest_data - __PAGE_OFFSET + LGUEST_DATA_pgdir, %esi 37 - 38 - /* Copy first 32 entries of page directory to __PAGE_OFFSET entries. 39 - * This means the first 128M of kernel memory will be mapped at 40 - * PAGE_OFFSET where the kernel expects to run. This will get it far 41 - * enough through boot to switch to its own pagetables. */ 42 - movl $32, %ecx 43 - movl %esi, %edi 44 - addl $((__PAGE_OFFSET >> 22) * 4), %edi 45 - rep 46 - movsl 47 - 48 33 /* Set up the initial stack so we can run C code. */ 49 34 movl $(init_thread_union+THREAD_SIZE),%esp 50 35
+28 -13
drivers/block/virtio_blk.c
··· 6 6 #include <linux/virtio_blk.h> 7 7 #include <linux/scatterlist.h> 8 8 9 - #define VIRTIO_MAX_SG (3+MAX_PHYS_SEGMENTS) 10 9 #define PART_BITS 4 11 10 12 11 static int major, index; ··· 25 26 26 27 mempool_t *pool; 27 28 29 + /* What host tells us, plus 2 for header & tailer. */ 30 + unsigned int sg_elems; 31 + 28 32 /* Scatterlist: can be too big for stack. */ 29 - struct scatterlist sg[VIRTIO_MAX_SG]; 33 + struct scatterlist sg[/*sg_elems*/]; 30 34 }; 31 35 32 36 struct virtblk_req ··· 99 97 if (blk_barrier_rq(vbr->req)) 100 98 vbr->out_hdr.type |= VIRTIO_BLK_T_BARRIER; 101 99 102 - /* This init could be done at vblk creation time */ 103 - sg_init_table(vblk->sg, VIRTIO_MAX_SG); 104 100 sg_set_buf(&vblk->sg[0], &vbr->out_hdr, sizeof(vbr->out_hdr)); 105 101 num = blk_rq_map_sg(q, vbr->req, vblk->sg+1); 106 102 sg_set_buf(&vblk->sg[num+1], &vbr->status, sizeof(vbr->status)); ··· 130 130 131 131 while ((req = elv_next_request(q)) != NULL) { 132 132 vblk = req->rq_disk->private_data; 133 - BUG_ON(req->nr_phys_segments > ARRAY_SIZE(vblk->sg)); 133 + BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems); 134 134 135 135 /* If this request fails, stop queue and wait for something to 136 136 finish to restart it. */ ··· 196 196 int err; 197 197 u64 cap; 198 198 u32 v; 199 - u32 blk_size; 199 + u32 blk_size, sg_elems; 200 200 201 201 if (index_to_minor(index) >= 1 << MINORBITS) 202 202 return -ENOSPC; 203 203 204 - vdev->priv = vblk = kmalloc(sizeof(*vblk), GFP_KERNEL); 204 + /* We need to know how many segments before we allocate. */ 205 + err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX, 206 + offsetof(struct virtio_blk_config, seg_max), 207 + &sg_elems); 208 + if (err) 209 + sg_elems = 1; 210 + 211 + /* We need an extra sg elements at head and tail. */ 212 + sg_elems += 2; 213 + vdev->priv = vblk = kmalloc(sizeof(*vblk) + 214 + sizeof(vblk->sg[0]) * sg_elems, GFP_KERNEL); 205 215 if (!vblk) { 206 216 err = -ENOMEM; 207 217 goto out; ··· 220 210 INIT_LIST_HEAD(&vblk->reqs); 221 211 spin_lock_init(&vblk->lock); 222 212 vblk->vdev = vdev; 213 + vblk->sg_elems = sg_elems; 214 + sg_init_table(vblk->sg, vblk->sg_elems); 223 215 224 216 /* We expect one virtqueue, for output. */ 225 217 vblk->vq = vdev->config->find_vq(vdev, 0, blk_done); ··· 291 279 } 292 280 set_capacity(vblk->disk, cap); 293 281 282 + /* We can handle whatever the host told us to handle. */ 283 + blk_queue_max_phys_segments(vblk->disk->queue, vblk->sg_elems-2); 284 + blk_queue_max_hw_segments(vblk->disk->queue, vblk->sg_elems-2); 285 + 286 + /* No real sector limit. */ 287 + blk_queue_max_sectors(vblk->disk->queue, -1U); 288 + 294 289 /* Host can optionally specify maximum segment size and number of 295 290 * segments. */ 296 291 err = virtio_config_val(vdev, VIRTIO_BLK_F_SIZE_MAX, ··· 305 286 &v); 306 287 if (!err) 307 288 blk_queue_max_segment_size(vblk->disk->queue, v); 308 - 309 - err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX, 310 - offsetof(struct virtio_blk_config, seg_max), 311 - &v); 312 - if (!err) 313 - blk_queue_max_hw_segments(vblk->disk->queue, v); 289 + else 290 + blk_queue_max_segment_size(vblk->disk->queue, -1U); 314 291 315 292 /* Host can optionally specify the block size of the device */ 316 293 err = virtio_config_val(vdev, VIRTIO_BLK_F_BLK_SIZE,
+1
drivers/char/hvc_console.c
··· 695 695 hp->ws = ws; 696 696 schedule_work(&hp->tty_resize); 697 697 } 698 + EXPORT_SYMBOL_GPL(hvc_resize); 698 699 699 700 /* 700 701 * This kthread is either polling or interrupt driven. This is determined by
+29 -1
drivers/char/virtio_console.c
··· 138 138 } 139 139 140 140 /* 141 + * virtio console configuration. This supports: 142 + * - console resize 143 + */ 144 + static void virtcons_apply_config(struct virtio_device *dev) 145 + { 146 + struct winsize ws; 147 + 148 + if (virtio_has_feature(dev, VIRTIO_CONSOLE_F_SIZE)) { 149 + dev->config->get(dev, 150 + offsetof(struct virtio_console_config, cols), 151 + &ws.ws_col, sizeof(u16)); 152 + dev->config->get(dev, 153 + offsetof(struct virtio_console_config, rows), 154 + &ws.ws_row, sizeof(u16)); 155 + hvc_resize(hvc, ws); 156 + } 157 + } 158 + 159 + /* 141 160 * we support only one console, the hvc struct is a global var 142 - * There is no need to do anything 161 + * We set the configuration at this point, since we now have a tty 143 162 */ 144 163 static int notifier_add_vio(struct hvc_struct *hp, int data) 145 164 { 146 165 hp->irq_requested = 1; 166 + virtcons_apply_config(vdev); 167 + 147 168 return 0; 148 169 } 149 170 ··· 255 234 { 0 }, 256 235 }; 257 236 237 + static unsigned int features[] = { 238 + VIRTIO_CONSOLE_F_SIZE, 239 + }; 240 + 258 241 static struct virtio_driver virtio_console = { 242 + .feature_table = features, 243 + .feature_table_size = ARRAY_SIZE(features), 259 244 .driver.name = KBUILD_MODNAME, 260 245 .driver.owner = THIS_MODULE, 261 246 .id_table = id_table, 262 247 .probe = virtcons_probe, 248 + .config_changed = virtcons_apply_config, 263 249 }; 264 250 265 251 static int __init init(void)
+1 -1
drivers/lguest/lg.h
··· 164 164 void copy_gdt_tls(const struct lg_cpu *cpu, struct desc_struct *gdt); 165 165 166 166 /* page_tables.c: */ 167 - int init_guest_pagetable(struct lguest *lg, unsigned long pgtable); 167 + int init_guest_pagetable(struct lguest *lg); 168 168 void free_guest_pagetable(struct lguest *lg); 169 169 void guest_new_pagetable(struct lg_cpu *cpu, unsigned long pgtable); 170 170 void guest_set_pmd(struct lguest *lg, unsigned long gpgdir, u32 i);
+4 -4
drivers/lguest/lguest_device.c
··· 250 250 /* Figure out how many pages the ring will take, and map that memory */ 251 251 lvq->pages = lguest_map((unsigned long)lvq->config.pfn << PAGE_SHIFT, 252 252 DIV_ROUND_UP(vring_size(lvq->config.num, 253 - PAGE_SIZE), 253 + LGUEST_VRING_ALIGN), 254 254 PAGE_SIZE)); 255 255 if (!lvq->pages) { 256 256 err = -ENOMEM; ··· 259 259 260 260 /* OK, tell virtio_ring.c to set up a virtqueue now we know its size 261 261 * and we've got a pointer to its pages. */ 262 - vq = vring_new_virtqueue(lvq->config.num, vdev, lvq->pages, 263 - lg_notify, callback); 262 + vq = vring_new_virtqueue(lvq->config.num, LGUEST_VRING_ALIGN, 263 + vdev, lvq->pages, lg_notify, callback); 264 264 if (!vq) { 265 265 err = -ENOMEM; 266 266 goto unmap; ··· 272 272 * the interrupt as a source of randomness: it'd be nice to have that 273 273 * back.. */ 274 274 err = request_irq(lvq->config.irq, vring_interrupt, IRQF_SHARED, 275 - vdev->dev.bus_id, vq); 275 + dev_name(&vdev->dev), vq); 276 276 if (err) 277 277 goto destroy_vring; 278 278
+5 -8
drivers/lguest/lguest_user.c
··· 146 146 return 0; 147 147 } 148 148 149 - /*L:020 The initialization write supplies 4 pointer sized (32 or 64 bit) 149 + /*L:020 The initialization write supplies 3 pointer sized (32 or 64 bit) 150 150 * values (in addition to the LHREQ_INITIALIZE value). These are: 151 151 * 152 152 * base: The start of the Guest-physical memory inside the Launcher memory. ··· 154 154 * pfnlimit: The highest (Guest-physical) page number the Guest should be 155 155 * allowed to access. The Guest memory lives inside the Launcher, so it sets 156 156 * this to ensure the Guest can only reach its own memory. 157 - * 158 - * pgdir: The (Guest-physical) address of the top of the initial Guest 159 - * pagetables (which are set up by the Launcher). 160 157 * 161 158 * start: The first instruction to execute ("eip" in x86-speak). 162 159 */ ··· 163 166 * Guest. */ 164 167 struct lguest *lg; 165 168 int err; 166 - unsigned long args[4]; 169 + unsigned long args[3]; 167 170 168 171 /* We grab the Big Lguest lock, which protects against multiple 169 172 * simultaneous initializations. */ ··· 189 192 lg->mem_base = (void __user *)args[0]; 190 193 lg->pfn_limit = args[1]; 191 194 192 - /* This is the first cpu (cpu 0) and it will start booting at args[3] */ 193 - err = lg_cpu_start(&lg->cpus[0], 0, args[3]); 195 + /* This is the first cpu (cpu 0) and it will start booting at args[2] */ 196 + err = lg_cpu_start(&lg->cpus[0], 0, args[2]); 194 197 if (err) 195 198 goto release_guest; 196 199 197 200 /* Initialize the Guest's shadow page tables, using the toplevel 198 201 * address the Launcher gave us. This allocates memory, so can fail. */ 199 - err = init_guest_pagetable(lg, args[2]); 202 + err = init_guest_pagetable(lg); 200 203 if (err) 201 204 goto free_regs; 202 205
+70 -2
drivers/lguest/page_tables.c
··· 14 14 #include <linux/percpu.h> 15 15 #include <asm/tlbflush.h> 16 16 #include <asm/uaccess.h> 17 + #include <asm/bootparam.h> 17 18 #include "lg.h" 18 19 19 20 /*M:008 We hold reference to pages, which prevents them from being swapped. ··· 582 581 release_pgd(lg, lg->pgdirs[pgdir].pgdir + idx); 583 582 } 584 583 584 + /* Once we know how much memory we have we can construct simple identity 585 + * (which set virtual == physical) and linear mappings 586 + * which will get the Guest far enough into the boot to create its own. 587 + * 588 + * We lay them out of the way, just below the initrd (which is why we need to 589 + * know its size here). */ 590 + static unsigned long setup_pagetables(struct lguest *lg, 591 + unsigned long mem, 592 + unsigned long initrd_size) 593 + { 594 + pgd_t __user *pgdir; 595 + pte_t __user *linear; 596 + unsigned int mapped_pages, i, linear_pages, phys_linear; 597 + unsigned long mem_base = (unsigned long)lg->mem_base; 598 + 599 + /* We have mapped_pages frames to map, so we need 600 + * linear_pages page tables to map them. */ 601 + mapped_pages = mem / PAGE_SIZE; 602 + linear_pages = (mapped_pages + PTRS_PER_PTE - 1) / PTRS_PER_PTE; 603 + 604 + /* We put the toplevel page directory page at the top of memory. */ 605 + pgdir = (pgd_t *)(mem + mem_base - initrd_size - PAGE_SIZE); 606 + 607 + /* Now we use the next linear_pages pages as pte pages */ 608 + linear = (void *)pgdir - linear_pages * PAGE_SIZE; 609 + 610 + /* Linear mapping is easy: put every page's address into the 611 + * mapping in order. */ 612 + for (i = 0; i < mapped_pages; i++) { 613 + pte_t pte; 614 + pte = pfn_pte(i, __pgprot(_PAGE_PRESENT|_PAGE_RW|_PAGE_USER)); 615 + if (copy_to_user(&linear[i], &pte, sizeof(pte)) != 0) 616 + return -EFAULT; 617 + } 618 + 619 + /* The top level points to the linear page table pages above. 620 + * We setup the identity and linear mappings here. */ 621 + phys_linear = (unsigned long)linear - mem_base; 622 + for (i = 0; i < mapped_pages; i += PTRS_PER_PTE) { 623 + pgd_t pgd; 624 + pgd = __pgd((phys_linear + i * sizeof(pte_t)) | 625 + (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER)); 626 + 627 + if (copy_to_user(&pgdir[i / PTRS_PER_PTE], &pgd, sizeof(pgd)) 628 + || copy_to_user(&pgdir[pgd_index(PAGE_OFFSET) 629 + + i / PTRS_PER_PTE], 630 + &pgd, sizeof(pgd))) 631 + return -EFAULT; 632 + } 633 + 634 + /* We return the top level (guest-physical) address: remember where 635 + * this is. */ 636 + return (unsigned long)pgdir - mem_base; 637 + } 638 + 585 639 /*H:500 (vii) Setting up the page tables initially. 586 640 * 587 641 * When a Guest is first created, the Launcher tells us where the toplevel of 588 642 * its first page table is. We set some things up here: */ 589 - int init_guest_pagetable(struct lguest *lg, unsigned long pgtable) 643 + int init_guest_pagetable(struct lguest *lg) 590 644 { 645 + u64 mem; 646 + u32 initrd_size; 647 + struct boot_params __user *boot = (struct boot_params *)lg->mem_base; 648 + 649 + /* Get the Guest memory size and the ramdisk size from the boot header 650 + * located at lg->mem_base (Guest address 0). */ 651 + if (copy_from_user(&mem, &boot->e820_map[0].size, sizeof(mem)) 652 + || get_user(initrd_size, &boot->hdr.ramdisk_size)) 653 + return -EFAULT; 654 + 591 655 /* We start on the first shadow page table, and give it a blank PGD 592 656 * page. */ 593 - lg->pgdirs[0].gpgdir = pgtable; 657 + lg->pgdirs[0].gpgdir = setup_pagetables(lg, mem, initrd_size); 658 + if (IS_ERR_VALUE(lg->pgdirs[0].gpgdir)) 659 + return lg->pgdirs[0].gpgdir; 594 660 lg->pgdirs[0].pgdir = (pgd_t *)get_zeroed_page(GFP_KERNEL); 595 661 if (!lg->pgdirs[0].pgdir) 596 662 return -ENOMEM;
+27 -7
drivers/s390/kvm/kvm_virtio.c
··· 188 188 config = kvm_vq_config(kdev->desc)+index; 189 189 190 190 err = vmem_add_mapping(config->address, 191 - vring_size(config->num, PAGE_SIZE)); 191 + vring_size(config->num, 192 + KVM_S390_VIRTIO_RING_ALIGN)); 192 193 if (err) 193 194 goto out; 194 195 195 - vq = vring_new_virtqueue(config->num, vdev, (void *) config->address, 196 + vq = vring_new_virtqueue(config->num, KVM_S390_VIRTIO_RING_ALIGN, 197 + vdev, (void *) config->address, 196 198 kvm_notify, callback); 197 199 if (!vq) { 198 200 err = -ENOMEM; ··· 211 209 return vq; 212 210 unmap: 213 211 vmem_remove_mapping(config->address, 214 - vring_size(config->num, PAGE_SIZE)); 212 + vring_size(config->num, 213 + KVM_S390_VIRTIO_RING_ALIGN)); 215 214 out: 216 215 return ERR_PTR(err); 217 216 } ··· 223 220 224 221 vring_del_virtqueue(vq); 225 222 vmem_remove_mapping(config->address, 226 - vring_size(config->num, PAGE_SIZE)); 223 + vring_size(config->num, 224 + KVM_S390_VIRTIO_RING_ALIGN)); 227 225 } 228 226 229 227 /* ··· 299 295 */ 300 296 static void kvm_extint_handler(u16 code) 301 297 { 302 - void *data = (void *) *(long *) __LC_PFAULT_INTPARM; 303 - u16 subcode = S390_lowcore.cpu_addr; 298 + struct virtqueue *vq; 299 + u16 subcode; 300 + int config_changed; 304 301 302 + subcode = S390_lowcore.cpu_addr; 305 303 if ((subcode & 0xff00) != VIRTIO_SUBCODE_64) 306 304 return; 307 305 308 - vring_interrupt(0, data); 306 + /* The LSB might be overloaded, we have to mask it */ 307 + vq = (struct virtqueue *) ((*(long *) __LC_PFAULT_INTPARM) & ~1UL); 308 + 309 + /* We use the LSB of extparam, to decide, if this interrupt is a config 310 + * change or a "standard" interrupt */ 311 + config_changed = (*(int *) __LC_EXT_PARAMS & 1); 312 + 313 + if (config_changed) { 314 + struct virtio_driver *drv; 315 + drv = container_of(vq->vdev->dev.driver, 316 + struct virtio_driver, driver); 317 + if (drv->config_changed) 318 + drv->config_changed(vq->vdev); 319 + } else 320 + vring_interrupt(0, vq); 309 321 } 310 322 311 323 /*
+1 -1
drivers/virtio/virtio.c
··· 176 176 177 177 /* Assign a unique device index and hence name. */ 178 178 dev->index = dev_index++; 179 - sprintf(dev->dev.bus_id, "virtio%u", dev->index); 179 + dev_set_name(&dev->dev, "virtio%u", dev->index); 180 180 181 181 /* We always start by resetting the device, in case a previous 182 182 * driver messed it up. This also tests that code path a little. */
+11 -2
drivers/virtio/virtio_balloon.c
··· 56 56 { 0 }, 57 57 }; 58 58 59 + static u32 page_to_balloon_pfn(struct page *page) 60 + { 61 + unsigned long pfn = page_to_pfn(page); 62 + 63 + BUILD_BUG_ON(PAGE_SHIFT < VIRTIO_BALLOON_PFN_SHIFT); 64 + /* Convert pfn from Linux page size to balloon page size. */ 65 + return pfn >> (PAGE_SHIFT - VIRTIO_BALLOON_PFN_SHIFT); 66 + } 67 + 59 68 static void balloon_ack(struct virtqueue *vq) 60 69 { 61 70 struct virtio_balloon *vb; ··· 108 99 msleep(200); 109 100 break; 110 101 } 111 - vb->pfns[vb->num_pfns] = page_to_pfn(page); 102 + vb->pfns[vb->num_pfns] = page_to_balloon_pfn(page); 112 103 totalram_pages--; 113 104 vb->num_pages++; 114 105 list_add(&page->lru, &vb->pages); ··· 141 132 for (vb->num_pfns = 0; vb->num_pfns < num; vb->num_pfns++) { 142 133 page = list_first_entry(&vb->pages, struct page, lru); 143 134 list_del(&page->lru); 144 - vb->pfns[vb->num_pfns] = page_to_pfn(page); 135 + vb->pfns[vb->num_pfns] = page_to_balloon_pfn(page); 145 136 vb->num_pages--; 146 137 } 147 138
+27 -16
drivers/virtio/virtio_pci.c
··· 75 75 * would make more sense for virtio to not insist on having it's own device. */ 76 76 static struct device virtio_pci_root = { 77 77 .parent = NULL, 78 - .bus_id = "virtio-pci", 78 + .init_name = "virtio-pci", 79 79 }; 80 80 81 81 /* Convert a generic virtio device to our structure */ ··· 216 216 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 217 217 struct virtio_pci_vq_info *info; 218 218 struct virtqueue *vq; 219 - unsigned long flags; 219 + unsigned long flags, size; 220 220 u16 num; 221 221 int err; 222 222 ··· 237 237 info->queue_index = index; 238 238 info->num = num; 239 239 240 - info->queue = kzalloc(PAGE_ALIGN(vring_size(num,PAGE_SIZE)), GFP_KERNEL); 240 + size = PAGE_ALIGN(vring_size(num, VIRTIO_PCI_VRING_ALIGN)); 241 + info->queue = alloc_pages_exact(size, GFP_KERNEL|__GFP_ZERO); 241 242 if (info->queue == NULL) { 242 243 err = -ENOMEM; 243 244 goto out_info; 244 245 } 245 246 246 247 /* activate the queue */ 247 - iowrite32(virt_to_phys(info->queue) >> PAGE_SHIFT, 248 + iowrite32(virt_to_phys(info->queue) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT, 248 249 vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN); 249 250 250 251 /* create the vring */ 251 - vq = vring_new_virtqueue(info->num, vdev, info->queue, 252 - vp_notify, callback); 252 + vq = vring_new_virtqueue(info->num, VIRTIO_PCI_VRING_ALIGN, 253 + vdev, info->queue, vp_notify, callback); 253 254 if (!vq) { 254 255 err = -ENOMEM; 255 256 goto out_activate_queue; ··· 267 266 268 267 out_activate_queue: 269 268 iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN); 270 - kfree(info->queue); 269 + free_pages_exact(info->queue, size); 271 270 out_info: 272 271 kfree(info); 273 272 return ERR_PTR(err); ··· 278 277 { 279 278 struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev); 280 279 struct virtio_pci_vq_info *info = vq->priv; 281 - unsigned long flags; 280 + unsigned long flags, size; 282 281 283 282 spin_lock_irqsave(&vp_dev->lock, flags); 284 283 list_del(&info->node); ··· 290 289 iowrite16(info->queue_index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL); 291 290 iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN); 292 291 293 - kfree(info->queue); 292 + size = PAGE_ALIGN(vring_size(info->num, VIRTIO_PCI_VRING_ALIGN)); 293 + free_pages_exact(info->queue, size); 294 294 kfree(info); 295 295 } 296 296 ··· 306 304 .get_features = vp_get_features, 307 305 .finalize_features = vp_finalize_features, 308 306 }; 307 + 308 + static void virtio_pci_release_dev(struct device *_d) 309 + { 310 + struct virtio_device *dev = container_of(_d, struct virtio_device, dev); 311 + struct virtio_pci_device *vp_dev = to_vp_device(dev); 312 + struct pci_dev *pci_dev = vp_dev->pci_dev; 313 + 314 + free_irq(pci_dev->irq, vp_dev); 315 + pci_set_drvdata(pci_dev, NULL); 316 + pci_iounmap(pci_dev, vp_dev->ioaddr); 317 + pci_release_regions(pci_dev); 318 + pci_disable_device(pci_dev); 319 + kfree(vp_dev); 320 + } 309 321 310 322 /* the PCI probing function */ 311 323 static int __devinit virtio_pci_probe(struct pci_dev *pci_dev, ··· 344 328 return -ENOMEM; 345 329 346 330 vp_dev->vdev.dev.parent = &virtio_pci_root; 331 + vp_dev->vdev.dev.release = virtio_pci_release_dev; 347 332 vp_dev->vdev.config = &virtio_pci_config_ops; 348 333 vp_dev->pci_dev = pci_dev; 349 334 INIT_LIST_HEAD(&vp_dev->virtqueues); ··· 374 357 375 358 /* register a handler for the queue with the PCI device's interrupt */ 376 359 err = request_irq(vp_dev->pci_dev->irq, vp_interrupt, IRQF_SHARED, 377 - vp_dev->vdev.dev.bus_id, vp_dev); 360 + dev_name(&vp_dev->vdev.dev), vp_dev); 378 361 if (err) 379 362 goto out_set_drvdata; 380 363 ··· 404 387 struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); 405 388 406 389 unregister_virtio_device(&vp_dev->vdev); 407 - free_irq(pci_dev->irq, vp_dev); 408 - pci_set_drvdata(pci_dev, NULL); 409 - pci_iounmap(pci_dev, vp_dev->ioaddr); 410 - pci_release_regions(pci_dev); 411 - pci_disable_device(pci_dev); 412 - kfree(vp_dev); 413 390 } 414 391 415 392 #ifdef CONFIG_PM
+2 -1
drivers/virtio/virtio_ring.c
··· 274 274 }; 275 275 276 276 struct virtqueue *vring_new_virtqueue(unsigned int num, 277 + unsigned int vring_align, 277 278 struct virtio_device *vdev, 278 279 void *pages, 279 280 void (*notify)(struct virtqueue *), ··· 293 292 if (!vq) 294 293 return NULL; 295 294 296 - vring_init(&vq->vring, num, pages, PAGE_SIZE); 295 + vring_init(&vq->vring, num, pages, vring_align); 297 296 vq->vq.callback = callback; 298 297 vq->vq.vdev = vdev; 299 298 vq->vq.vq_ops = &vring_vq_ops;
+5 -1
include/linux/lguest_launcher.h
··· 54 54 /* Write command first word is a request. */ 55 55 enum lguest_req 56 56 { 57 - LHREQ_INITIALIZE, /* + base, pfnlimit, pgdir, start */ 57 + LHREQ_INITIALIZE, /* + base, pfnlimit, start */ 58 58 LHREQ_GETDMA, /* No longer used */ 59 59 LHREQ_IRQ, /* + irq */ 60 60 LHREQ_BREAK, /* + on/off flag (on blocks until someone does off) */ 61 61 }; 62 + 63 + /* The alignment to use between consumer and producer parts of vring. 64 + * x86 pagesize for historical reasons. */ 65 + #define LGUEST_VRING_ALIGN 4096 62 66 #endif /* _LINUX_LGUEST_LAUNCHER */
+3
include/linux/virtio_balloon.h
··· 10 10 /* The feature bitmap for virtio balloon */ 11 11 #define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */ 12 12 13 + /* Size of a PFN in the balloon interface. */ 14 + #define VIRTIO_BALLOON_PFN_SHIFT 12 15 + 13 16 struct virtio_balloon_config 14 17 { 15 18 /* Number of pages host wants Guest to give up. */
+11
include/linux/virtio_console.h
··· 7 7 /* The ID for virtio console */ 8 8 #define VIRTIO_ID_CONSOLE 3 9 9 10 + /* Feature bits */ 11 + #define VIRTIO_CONSOLE_F_SIZE 0 /* Does host provide console size? */ 12 + 13 + struct virtio_console_config { 14 + /* colums of the screens */ 15 + __u16 cols; 16 + /* rows of the screens */ 17 + __u16 rows; 18 + } __attribute__((packed)); 19 + 20 + 10 21 #ifdef __KERNEL__ 11 22 int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)); 12 23 #endif /* __KERNEL__ */
+8
include/linux/virtio_pci.h
··· 53 53 54 54 /* Virtio ABI version, this must match exactly */ 55 55 #define VIRTIO_PCI_ABI_VERSION 0 56 + 57 + /* How many bits to shift physical queue address written to QUEUE_PFN. 58 + * 12 is historical, and due to x86 page size. */ 59 + #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12 60 + 61 + /* The alignment to use between consumer and producer parts of vring. 62 + * x86 pagesize again. */ 63 + #define VIRTIO_PCI_VRING_ALIGN 4096 56 64 #endif
+7 -6
include/linux/virtio_ring.h
··· 83 83 * __u16 avail_idx; 84 84 * __u16 available[num]; 85 85 * 86 - * // Padding to the next page boundary. 86 + * // Padding to the next align boundary. 87 87 * char pad[]; 88 88 * 89 89 * // A ring of used descriptor heads with free-running index. ··· 93 93 * }; 94 94 */ 95 95 static inline void vring_init(struct vring *vr, unsigned int num, void *p, 96 - unsigned long pagesize) 96 + unsigned long align) 97 97 { 98 98 vr->num = num; 99 99 vr->desc = p; 100 100 vr->avail = p + num*sizeof(struct vring_desc); 101 - vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + pagesize-1) 102 - & ~(pagesize - 1)); 101 + vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + align-1) 102 + & ~(align - 1)); 103 103 } 104 104 105 - static inline unsigned vring_size(unsigned int num, unsigned long pagesize) 105 + static inline unsigned vring_size(unsigned int num, unsigned long align) 106 106 { 107 107 return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num) 108 - + pagesize - 1) & ~(pagesize - 1)) 108 + + align - 1) & ~(align - 1)) 109 109 + sizeof(__u16) * 2 + sizeof(struct vring_used_elem) * num; 110 110 } 111 111 ··· 115 115 struct virtqueue; 116 116 117 117 struct virtqueue *vring_new_virtqueue(unsigned int num, 118 + unsigned int vring_align, 118 119 struct virtio_device *vdev, 119 120 void *pages, 120 121 void (*notify)(struct virtqueue *vq),