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-6.8-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip

Pull xen updates from Juergen Gross:

- update some Xen PV interface related headers

- fix some kernel-doc comments in the xenbus driver

- fix the Xen gntdev driver to not access the struct page of pages
imported from a DMA-buf

* tag 'for-linus-6.8-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip:
xen/gntdev: Fix the abuse of underlying struct page in DMA-buf import
xen/xenbus: client: fix kernel-doc comments
xen: update PV-device interface headers

+64 -55
+27 -27
drivers/xen/gntdev-dmabuf.c
··· 11 11 #include <linux/kernel.h> 12 12 #include <linux/errno.h> 13 13 #include <linux/dma-buf.h> 14 + #include <linux/dma-direct.h> 14 15 #include <linux/slab.h> 15 16 #include <linux/types.h> 16 17 #include <linux/uaccess.h> ··· 51 50 52 51 /* Number of pages this buffer has. */ 53 52 int nr_pages; 54 - /* Pages of this buffer. */ 53 + /* Pages of this buffer (only for dma-buf export). */ 55 54 struct page **pages; 56 55 }; 57 56 ··· 485 484 /* DMA buffer import support. */ 486 485 487 486 static int 488 - dmabuf_imp_grant_foreign_access(struct page **pages, u32 *refs, 487 + dmabuf_imp_grant_foreign_access(unsigned long *gfns, u32 *refs, 489 488 int count, int domid) 490 489 { 491 490 grant_ref_t priv_gref_head; ··· 508 507 } 509 508 510 509 gnttab_grant_foreign_access_ref(cur_ref, domid, 511 - xen_page_to_gfn(pages[i]), 0); 510 + gfns[i], 0); 512 511 refs[i] = cur_ref; 513 512 } 514 513 ··· 530 529 531 530 static void dmabuf_imp_free_storage(struct gntdev_dmabuf *gntdev_dmabuf) 532 531 { 533 - kfree(gntdev_dmabuf->pages); 534 532 kfree(gntdev_dmabuf->u.imp.refs); 535 533 kfree(gntdev_dmabuf); 536 534 } ··· 547 547 sizeof(gntdev_dmabuf->u.imp.refs[0]), 548 548 GFP_KERNEL); 549 549 if (!gntdev_dmabuf->u.imp.refs) 550 - goto fail; 551 - 552 - gntdev_dmabuf->pages = kcalloc(count, 553 - sizeof(gntdev_dmabuf->pages[0]), 554 - GFP_KERNEL); 555 - if (!gntdev_dmabuf->pages) 556 550 goto fail; 557 551 558 552 gntdev_dmabuf->nr_pages = count; ··· 570 576 struct dma_buf *dma_buf; 571 577 struct dma_buf_attachment *attach; 572 578 struct sg_table *sgt; 573 - struct sg_page_iter sg_iter; 579 + struct sg_dma_page_iter sg_iter; 580 + unsigned long *gfns; 574 581 int i; 575 582 576 583 dma_buf = dma_buf_get(fd); ··· 619 624 620 625 gntdev_dmabuf->u.imp.sgt = sgt; 621 626 622 - /* Now convert sgt to array of pages and check for page validity. */ 623 - i = 0; 624 - for_each_sgtable_page(sgt, &sg_iter, 0) { 625 - struct page *page = sg_page_iter_page(&sg_iter); 626 - /* 627 - * Check if page is valid: this can happen if we are given 628 - * a page from VRAM or other resources which are not backed 629 - * by a struct page. 630 - */ 631 - if (!pfn_valid(page_to_pfn(page))) { 632 - ret = ERR_PTR(-EINVAL); 633 - goto fail_unmap; 634 - } 635 - 636 - gntdev_dmabuf->pages[i++] = page; 627 + gfns = kcalloc(count, sizeof(*gfns), GFP_KERNEL); 628 + if (!gfns) { 629 + ret = ERR_PTR(-ENOMEM); 630 + goto fail_unmap; 637 631 } 638 632 639 - ret = ERR_PTR(dmabuf_imp_grant_foreign_access(gntdev_dmabuf->pages, 633 + /* 634 + * Now convert sgt to array of gfns without accessing underlying pages. 635 + * It is not allowed to access the underlying struct page of an sg table 636 + * exported by DMA-buf, but since we deal with special Xen dma device here 637 + * (not a normal physical one) look at the dma addresses in the sg table 638 + * and then calculate gfns directly from them. 639 + */ 640 + i = 0; 641 + for_each_sgtable_dma_page(sgt, &sg_iter, 0) { 642 + dma_addr_t addr = sg_page_iter_dma_address(&sg_iter); 643 + unsigned long pfn = bfn_to_pfn(XEN_PFN_DOWN(dma_to_phys(dev, addr))); 644 + 645 + gfns[i++] = pfn_to_gfn(pfn); 646 + } 647 + 648 + ret = ERR_PTR(dmabuf_imp_grant_foreign_access(gfns, 640 649 gntdev_dmabuf->u.imp.refs, 641 650 count, domid)); 651 + kfree(gfns); 642 652 if (IS_ERR(ret)) 643 653 goto fail_end_access; 644 654
+34 -25
drivers/xen/xenbus/xenbus_client.c
··· 119 119 * @callback: callback to register 120 120 * 121 121 * Register a @watch on the given path, using the given xenbus_watch structure 122 - * for storage, and the given @callback function as the callback. Return 0 on 123 - * success, or -errno on error. On success, the given @path will be saved as 124 - * @watch->node, and remains the caller's to free. On error, @watch->node will 122 + * for storage, and the given @callback function as the callback. On success, 123 + * the given @path will be saved as @watch->node, and remains the 124 + * caller's to free. On error, @watch->node will 125 125 * be NULL, the device will switch to %XenbusStateClosing, and the error will 126 126 * be saved in the store. 127 + * 128 + * Returns: %0 on success or -errno on error 127 129 */ 128 130 int xenbus_watch_path(struct xenbus_device *dev, const char *path, 129 131 struct xenbus_watch *watch, ··· 162 160 * @pathfmt: format of path to watch 163 161 * 164 162 * Register a watch on the given @path, using the given xenbus_watch 165 - * structure for storage, and the given @callback function as the callback. 166 - * Return 0 on success, or -errno on error. On success, the watched path 167 - * (@path/@path2) will be saved as @watch->node, and becomes the caller's to 168 - * kfree(). On error, watch->node will be NULL, so the caller has nothing to 163 + * structure for storage, and the given @callback function as the 164 + * callback. On success, the watched path (@path/@path2) will be saved 165 + * as @watch->node, and becomes the caller's to kfree(). 166 + * On error, watch->node will be NULL, so the caller has nothing to 169 167 * free, the device will switch to %XenbusStateClosing, and the error will be 170 168 * saved in the store. 169 + * 170 + * Returns: %0 on success or -errno on error 171 171 */ 172 172 int xenbus_watch_pathfmt(struct xenbus_device *dev, 173 173 struct xenbus_watch *watch, ··· 259 255 } 260 256 261 257 /** 262 - * xenbus_switch_state 258 + * xenbus_switch_state - save the new state of a driver 263 259 * @dev: xenbus device 264 260 * @state: new state 265 261 * 266 262 * Advertise in the store a change of the given driver to the given new_state. 267 - * Return 0 on success, or -errno on error. On error, the device will switch 268 - * to XenbusStateClosing, and the error will be saved in the store. 263 + * On error, the device will switch to XenbusStateClosing, and the error 264 + * will be saved in the store. 265 + * 266 + * Returns: %0 on success or -errno on error 269 267 */ 270 268 int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state state) 271 269 { ··· 311 305 } 312 306 313 307 /** 314 - * xenbus_dev_error 308 + * xenbus_dev_error - place an error message into the store 315 309 * @dev: xenbus device 316 310 * @err: error to report 317 311 * @fmt: error message format ··· 330 324 EXPORT_SYMBOL_GPL(xenbus_dev_error); 331 325 332 326 /** 333 - * xenbus_dev_fatal 327 + * xenbus_dev_fatal - put an error messages into the store and then shutdown 334 328 * @dev: xenbus device 335 329 * @err: error to report 336 330 * @fmt: error message format ··· 352 346 } 353 347 EXPORT_SYMBOL_GPL(xenbus_dev_fatal); 354 348 355 - /** 349 + /* 356 350 * Equivalent to xenbus_dev_fatal(dev, err, fmt, args), but helps 357 351 * avoiding recursion within xenbus_switch_state. 358 352 */ ··· 459 453 } 460 454 EXPORT_SYMBOL_GPL(xenbus_teardown_ring); 461 455 462 - /** 456 + /* 463 457 * Allocate an event channel for the given xenbus_device, assigning the newly 464 458 * created local port to *port. Return 0 on success, or -errno on error. On 465 459 * error, the device will switch to XenbusStateClosing, and the error will be ··· 485 479 EXPORT_SYMBOL_GPL(xenbus_alloc_evtchn); 486 480 487 481 488 - /** 482 + /* 489 483 * Free an existing event channel. Returns 0 on success or -errno on error. 490 484 */ 491 485 int xenbus_free_evtchn(struct xenbus_device *dev, evtchn_port_t port) ··· 505 499 506 500 507 501 /** 508 - * xenbus_map_ring_valloc 502 + * xenbus_map_ring_valloc - allocate & map pages of VA space 509 503 * @dev: xenbus device 510 504 * @gnt_refs: grant reference array 511 505 * @nr_grefs: number of grant references ··· 513 507 * 514 508 * Map @nr_grefs pages of memory into this domain from another 515 509 * domain's grant table. xenbus_map_ring_valloc allocates @nr_grefs 516 - * pages of virtual address space, maps the pages to that address, and 517 - * sets *vaddr to that address. Returns 0 on success, and -errno on 518 - * error. If an error is returned, device will switch to 510 + * pages of virtual address space, maps the pages to that address, and sets 511 + * *vaddr to that address. If an error is returned, device will switch to 519 512 * XenbusStateClosing and the error message will be saved in XenStore. 513 + * 514 + * Returns: %0 on success or -errno on error 520 515 */ 521 516 int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs, 522 517 unsigned int nr_grefs, void **vaddr) ··· 606 599 } 607 600 608 601 /** 609 - * xenbus_unmap_ring 602 + * xenbus_unmap_ring - unmap memory from another domain 610 603 * @dev: xenbus device 611 604 * @handles: grant handle array 612 605 * @nr_handles: number of handles in the array 613 606 * @vaddrs: addresses to unmap 614 607 * 615 608 * Unmap memory in this domain that was imported from another domain. 616 - * Returns 0 on success and returns GNTST_* on error 609 + * 610 + * Returns: %0 on success or GNTST_* on error 617 611 * (see xen/include/interface/grant_table.h). 618 612 */ 619 613 static int xenbus_unmap_ring(struct xenbus_device *dev, grant_handle_t *handles, ··· 720 712 } 721 713 722 714 /** 723 - * xenbus_unmap_ring_vfree 715 + * xenbus_unmap_ring_vfree - unmap a page of memory from another domain 724 716 * @dev: xenbus device 725 717 * @vaddr: addr to unmap 726 718 * ··· 728 720 * Unmap a page of memory in this domain that was imported from another domain. 729 721 * Use xenbus_unmap_ring_vfree if you mapped in your memory with 730 722 * xenbus_map_ring_valloc (it will free the virtual address space). 731 - * Returns 0 on success and returns GNTST_* on error 723 + * 724 + * Returns: %0 on success or GNTST_* on error 732 725 * (see xen/include/interface/grant_table.h). 733 726 */ 734 727 int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr) ··· 925 916 } 926 917 927 918 /** 928 - * xenbus_read_driver_state 919 + * xenbus_read_driver_state - read state from a store path 929 920 * @path: path for driver 930 921 * 931 - * Return the state of the driver rooted at the given store path, or 922 + * Returns: the state of the driver rooted at the given store path, or 932 923 * XenbusStateUnknown if no state can be read. 933 924 */ 934 925 enum xenbus_state xenbus_read_driver_state(const char *path)
+1 -1
include/xen/interface/io/displif.h
··· 537 537 538 538 struct xendispl_page_directory { 539 539 grant_ref_t gref_dir_next_page; 540 - grant_ref_t gref[1]; /* Variable length */ 540 + grant_ref_t gref[]; 541 541 }; 542 542 543 543 /*
+1 -1
include/xen/interface/io/ring.h
··· 95 95 RING_IDX req_prod, req_event; \ 96 96 RING_IDX rsp_prod, rsp_event; \ 97 97 uint8_t __pad[48]; \ 98 - union __name##_sring_entry ring[1]; /* variable-length */ \ 98 + union __name##_sring_entry ring[]; \ 99 99 }; \ 100 100 \ 101 101 /* "Front" end's private variables */ \
+1 -1
include/xen/interface/io/sndif.h
··· 659 659 660 660 struct xensnd_page_directory { 661 661 grant_ref_t gref_dir_next_page; 662 - grant_ref_t gref[1]; /* Variable length */ 662 + grant_ref_t gref[]; 663 663 }; 664 664 665 665 /*