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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-linus-5.8b-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip

Pull xen fixes from Juergen Gross:
"One small cleanup patch for ARM and two patches for the xenbus driver
fixing latent problems (large stack allocations and bad return code
settings)"

* tag 'for-linus-5.8b-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip:
xen/xenbus: let xenbus_map_ring_valloc() return errno values only
xen/xenbus: avoid large structs and arrays on the stack
arm/xen: remove the unused macro GRANT_TABLE_PHYSADDR

+81 -87
-1
arch/arm/xen/enlighten.c
··· 241 241 * see Documentation/devicetree/bindings/arm/xen.txt for the 242 242 * documentation of the Xen Device Tree format. 243 243 */ 244 - #define GRANT_TABLE_PHYSADDR 0 245 244 void __init xen_early_init(void) 246 245 { 247 246 of_scan_flat_dt(fdt_find_hyper_node, NULL);
+81 -86
drivers/xen/xenbus/xenbus_client.c
··· 69 69 unsigned int nr_handles; 70 70 }; 71 71 72 + struct map_ring_valloc { 73 + struct xenbus_map_node *node; 74 + 75 + /* Why do we need two arrays? See comment of __xenbus_map_ring */ 76 + union { 77 + unsigned long addrs[XENBUS_MAX_RING_GRANTS]; 78 + pte_t *ptes[XENBUS_MAX_RING_GRANTS]; 79 + }; 80 + phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS]; 81 + 82 + struct gnttab_map_grant_ref map[XENBUS_MAX_RING_GRANTS]; 83 + struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS]; 84 + 85 + unsigned int idx; /* HVM only. */ 86 + }; 87 + 72 88 static DEFINE_SPINLOCK(xenbus_valloc_lock); 73 89 static LIST_HEAD(xenbus_valloc_pages); 74 90 75 91 struct xenbus_ring_ops { 76 - int (*map)(struct xenbus_device *dev, 92 + int (*map)(struct xenbus_device *dev, struct map_ring_valloc *info, 77 93 grant_ref_t *gnt_refs, unsigned int nr_grefs, 78 94 void **vaddr); 79 95 int (*unmap)(struct xenbus_device *dev, void *vaddr); ··· 456 440 * Map @nr_grefs pages of memory into this domain from another 457 441 * domain's grant table. xenbus_map_ring_valloc allocates @nr_grefs 458 442 * pages of virtual address space, maps the pages to that address, and 459 - * sets *vaddr to that address. Returns 0 on success, and GNTST_* 460 - * (see xen/include/interface/grant_table.h) or -ENOMEM / -EINVAL on 443 + * sets *vaddr to that address. Returns 0 on success, and -errno on 461 444 * error. If an error is returned, device will switch to 462 445 * XenbusStateClosing and the error message will be saved in XenStore. 463 446 */ ··· 464 449 unsigned int nr_grefs, void **vaddr) 465 450 { 466 451 int err; 452 + struct map_ring_valloc *info; 467 453 468 - err = ring_ops->map(dev, gnt_refs, nr_grefs, vaddr); 469 - /* Some hypervisors are buggy and can return 1. */ 470 - if (err > 0) 471 - err = GNTST_general_error; 454 + *vaddr = NULL; 472 455 456 + if (nr_grefs > XENBUS_MAX_RING_GRANTS) 457 + return -EINVAL; 458 + 459 + info = kzalloc(sizeof(*info), GFP_KERNEL); 460 + if (!info) 461 + return -ENOMEM; 462 + 463 + info->node = kzalloc(sizeof(*info->node), GFP_KERNEL); 464 + if (!info->node) 465 + err = -ENOMEM; 466 + else 467 + err = ring_ops->map(dev, info, gnt_refs, nr_grefs, vaddr); 468 + 469 + kfree(info->node); 470 + kfree(info); 473 471 return err; 474 472 } 475 473 EXPORT_SYMBOL_GPL(xenbus_map_ring_valloc); ··· 494 466 grant_ref_t *gnt_refs, 495 467 unsigned int nr_grefs, 496 468 grant_handle_t *handles, 497 - phys_addr_t *addrs, 469 + struct map_ring_valloc *info, 498 470 unsigned int flags, 499 471 bool *leaked) 500 472 { 501 - struct gnttab_map_grant_ref map[XENBUS_MAX_RING_GRANTS]; 502 - struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS]; 503 473 int i, j; 504 - int err = GNTST_okay; 505 474 506 475 if (nr_grefs > XENBUS_MAX_RING_GRANTS) 507 476 return -EINVAL; 508 477 509 478 for (i = 0; i < nr_grefs; i++) { 510 - memset(&map[i], 0, sizeof(map[i])); 511 - gnttab_set_map_op(&map[i], addrs[i], flags, gnt_refs[i], 512 - dev->otherend_id); 479 + gnttab_set_map_op(&info->map[i], info->phys_addrs[i], flags, 480 + gnt_refs[i], dev->otherend_id); 513 481 handles[i] = INVALID_GRANT_HANDLE; 514 482 } 515 483 516 - gnttab_batch_map(map, i); 484 + gnttab_batch_map(info->map, i); 517 485 518 486 for (i = 0; i < nr_grefs; i++) { 519 - if (map[i].status != GNTST_okay) { 520 - err = map[i].status; 521 - xenbus_dev_fatal(dev, map[i].status, 487 + if (info->map[i].status != GNTST_okay) { 488 + xenbus_dev_fatal(dev, info->map[i].status, 522 489 "mapping in shared page %d from domain %d", 523 490 gnt_refs[i], dev->otherend_id); 524 491 goto fail; 525 492 } else 526 - handles[i] = map[i].handle; 493 + handles[i] = info->map[i].handle; 527 494 } 528 495 529 - return GNTST_okay; 496 + return 0; 530 497 531 498 fail: 532 499 for (i = j = 0; i < nr_grefs; i++) { 533 500 if (handles[i] != INVALID_GRANT_HANDLE) { 534 - memset(&unmap[j], 0, sizeof(unmap[j])); 535 - gnttab_set_unmap_op(&unmap[j], (phys_addr_t)addrs[i], 501 + gnttab_set_unmap_op(&info->unmap[j], 502 + info->phys_addrs[i], 536 503 GNTMAP_host_map, handles[i]); 537 504 j++; 538 505 } 539 506 } 540 507 541 - if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap, j)) 508 + if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, info->unmap, j)) 542 509 BUG(); 543 510 544 511 *leaked = false; 545 512 for (i = 0; i < j; i++) { 546 - if (unmap[i].status != GNTST_okay) { 513 + if (info->unmap[i].status != GNTST_okay) { 547 514 *leaked = true; 548 515 break; 549 516 } 550 517 } 551 518 552 - return err; 519 + return -ENOENT; 553 520 } 554 521 555 522 /** ··· 589 566 return err; 590 567 } 591 568 592 - struct map_ring_valloc_hvm 593 - { 594 - unsigned int idx; 595 - 596 - /* Why do we need two arrays? See comment of __xenbus_map_ring */ 597 - phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS]; 598 - unsigned long addrs[XENBUS_MAX_RING_GRANTS]; 599 - }; 600 - 601 569 static void xenbus_map_ring_setup_grant_hvm(unsigned long gfn, 602 570 unsigned int goffset, 603 571 unsigned int len, 604 572 void *data) 605 573 { 606 - struct map_ring_valloc_hvm *info = data; 574 + struct map_ring_valloc *info = data; 607 575 unsigned long vaddr = (unsigned long)gfn_to_virt(gfn); 608 576 609 577 info->phys_addrs[info->idx] = vaddr; ··· 603 589 info->idx++; 604 590 } 605 591 606 - static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev, 607 - grant_ref_t *gnt_ref, 608 - unsigned int nr_grefs, 609 - void **vaddr) 592 + static int xenbus_map_ring_hvm(struct xenbus_device *dev, 593 + struct map_ring_valloc *info, 594 + grant_ref_t *gnt_ref, 595 + unsigned int nr_grefs, 596 + void **vaddr) 610 597 { 611 - struct xenbus_map_node *node; 598 + struct xenbus_map_node *node = info->node; 612 599 int err; 613 600 void *addr; 614 601 bool leaked = false; 615 - struct map_ring_valloc_hvm info = { 616 - .idx = 0, 617 - }; 618 602 unsigned int nr_pages = XENBUS_PAGES(nr_grefs); 619 - 620 - if (nr_grefs > XENBUS_MAX_RING_GRANTS) 621 - return -EINVAL; 622 - 623 - *vaddr = NULL; 624 - 625 - node = kzalloc(sizeof(*node), GFP_KERNEL); 626 - if (!node) 627 - return -ENOMEM; 628 603 629 604 err = alloc_xenballooned_pages(nr_pages, node->hvm.pages); 630 605 if (err) ··· 621 618 622 619 gnttab_foreach_grant(node->hvm.pages, nr_grefs, 623 620 xenbus_map_ring_setup_grant_hvm, 624 - &info); 621 + info); 625 622 626 623 err = __xenbus_map_ring(dev, gnt_ref, nr_grefs, node->handles, 627 - info.phys_addrs, GNTMAP_host_map, &leaked); 624 + info, GNTMAP_host_map, &leaked); 628 625 node->nr_handles = nr_grefs; 629 626 630 627 if (err) ··· 644 641 spin_unlock(&xenbus_valloc_lock); 645 642 646 643 *vaddr = addr; 644 + info->node = NULL; 645 + 647 646 return 0; 648 647 649 648 out_xenbus_unmap_ring: 650 649 if (!leaked) 651 - xenbus_unmap_ring(dev, node->handles, nr_grefs, info.addrs); 650 + xenbus_unmap_ring(dev, node->handles, nr_grefs, info->addrs); 652 651 else 653 652 pr_alert("leaking %p size %u page(s)", 654 653 addr, nr_pages); ··· 658 653 if (!leaked) 659 654 free_xenballooned_pages(nr_pages, node->hvm.pages); 660 655 out_err: 661 - kfree(node); 662 656 return err; 663 657 } 664 658 ··· 680 676 EXPORT_SYMBOL_GPL(xenbus_unmap_ring_vfree); 681 677 682 678 #ifdef CONFIG_XEN_PV 683 - static int xenbus_map_ring_valloc_pv(struct xenbus_device *dev, 684 - grant_ref_t *gnt_refs, 685 - unsigned int nr_grefs, 686 - void **vaddr) 679 + static int xenbus_map_ring_pv(struct xenbus_device *dev, 680 + struct map_ring_valloc *info, 681 + grant_ref_t *gnt_refs, 682 + unsigned int nr_grefs, 683 + void **vaddr) 687 684 { 688 - struct xenbus_map_node *node; 685 + struct xenbus_map_node *node = info->node; 689 686 struct vm_struct *area; 690 - pte_t *ptes[XENBUS_MAX_RING_GRANTS]; 691 - phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS]; 692 687 int err = GNTST_okay; 693 688 int i; 694 689 bool leaked; 695 690 696 - *vaddr = NULL; 697 - 698 - if (nr_grefs > XENBUS_MAX_RING_GRANTS) 699 - return -EINVAL; 700 - 701 - node = kzalloc(sizeof(*node), GFP_KERNEL); 702 - if (!node) 703 - return -ENOMEM; 704 - 705 - area = alloc_vm_area(XEN_PAGE_SIZE * nr_grefs, ptes); 691 + area = alloc_vm_area(XEN_PAGE_SIZE * nr_grefs, info->ptes); 706 692 if (!area) { 707 693 kfree(node); 708 694 return -ENOMEM; 709 695 } 710 696 711 697 for (i = 0; i < nr_grefs; i++) 712 - phys_addrs[i] = arbitrary_virt_to_machine(ptes[i]).maddr; 698 + info->phys_addrs[i] = 699 + arbitrary_virt_to_machine(info->ptes[i]).maddr; 713 700 714 701 err = __xenbus_map_ring(dev, gnt_refs, nr_grefs, node->handles, 715 - phys_addrs, 716 - GNTMAP_host_map | GNTMAP_contains_pte, 702 + info, GNTMAP_host_map | GNTMAP_contains_pte, 717 703 &leaked); 718 704 if (err) 719 705 goto failed; ··· 716 722 spin_unlock(&xenbus_valloc_lock); 717 723 718 724 *vaddr = area->addr; 725 + info->node = NULL; 726 + 719 727 return 0; 720 728 721 729 failed: ··· 726 730 else 727 731 pr_alert("leaking VM area %p size %u page(s)", area, nr_grefs); 728 732 729 - kfree(node); 730 733 return err; 731 734 } 732 735 733 - static int xenbus_unmap_ring_vfree_pv(struct xenbus_device *dev, void *vaddr) 736 + static int xenbus_unmap_ring_pv(struct xenbus_device *dev, void *vaddr) 734 737 { 735 738 struct xenbus_map_node *node; 736 739 struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS]; ··· 793 798 } 794 799 795 800 static const struct xenbus_ring_ops ring_ops_pv = { 796 - .map = xenbus_map_ring_valloc_pv, 797 - .unmap = xenbus_unmap_ring_vfree_pv, 801 + .map = xenbus_map_ring_pv, 802 + .unmap = xenbus_unmap_ring_pv, 798 803 }; 799 804 #endif 800 805 801 - struct unmap_ring_vfree_hvm 806 + struct unmap_ring_hvm 802 807 { 803 808 unsigned int idx; 804 809 unsigned long addrs[XENBUS_MAX_RING_GRANTS]; ··· 809 814 unsigned int len, 810 815 void *data) 811 816 { 812 - struct unmap_ring_vfree_hvm *info = data; 817 + struct unmap_ring_hvm *info = data; 813 818 814 819 info->addrs[info->idx] = (unsigned long)gfn_to_virt(gfn); 815 820 816 821 info->idx++; 817 822 } 818 823 819 - static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr) 824 + static int xenbus_unmap_ring_hvm(struct xenbus_device *dev, void *vaddr) 820 825 { 821 826 int rv; 822 827 struct xenbus_map_node *node; 823 828 void *addr; 824 - struct unmap_ring_vfree_hvm info = { 829 + struct unmap_ring_hvm info = { 825 830 .idx = 0, 826 831 }; 827 832 unsigned int nr_pages; ··· 882 887 EXPORT_SYMBOL_GPL(xenbus_read_driver_state); 883 888 884 889 static const struct xenbus_ring_ops ring_ops_hvm = { 885 - .map = xenbus_map_ring_valloc_hvm, 886 - .unmap = xenbus_unmap_ring_vfree_hvm, 890 + .map = xenbus_map_ring_hvm, 891 + .unmap = xenbus_unmap_ring_hvm, 887 892 }; 888 893 889 894 void __init xenbus_ring_ops_init(void)