Skip to content

Commit 82fd5ee

Browse files
committed
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
2 parents 09d1c6a + 2d2db7d commit 82fd5ee

File tree

5 files changed

+62
-53
lines changed

5 files changed

+62
-53
lines changed

drivers/xen/gntdev-dmabuf.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/kernel.h>
1212
#include <linux/errno.h>
1313
#include <linux/dma-buf.h>
14+
#include <linux/dma-direct.h>
1415
#include <linux/slab.h>
1516
#include <linux/types.h>
1617
#include <linux/uaccess.h>
@@ -50,7 +51,7 @@ struct gntdev_dmabuf {
5051

5152
/* Number of pages this buffer has. */
5253
int nr_pages;
53-
/* Pages of this buffer. */
54+
/* Pages of this buffer (only for dma-buf export). */
5455
struct page **pages;
5556
};
5657

@@ -484,7 +485,7 @@ static int dmabuf_exp_from_refs(struct gntdev_priv *priv, int flags,
484485
/* DMA buffer import support. */
485486

486487
static int
487-
dmabuf_imp_grant_foreign_access(struct page **pages, u32 *refs,
488+
dmabuf_imp_grant_foreign_access(unsigned long *gfns, u32 *refs,
488489
int count, int domid)
489490
{
490491
grant_ref_t priv_gref_head;
@@ -507,7 +508,7 @@ dmabuf_imp_grant_foreign_access(struct page **pages, u32 *refs,
507508
}
508509

509510
gnttab_grant_foreign_access_ref(cur_ref, domid,
510-
xen_page_to_gfn(pages[i]), 0);
511+
gfns[i], 0);
511512
refs[i] = cur_ref;
512513
}
513514

@@ -529,7 +530,6 @@ static void dmabuf_imp_end_foreign_access(u32 *refs, int count)
529530

530531
static void dmabuf_imp_free_storage(struct gntdev_dmabuf *gntdev_dmabuf)
531532
{
532-
kfree(gntdev_dmabuf->pages);
533533
kfree(gntdev_dmabuf->u.imp.refs);
534534
kfree(gntdev_dmabuf);
535535
}
@@ -549,12 +549,6 @@ static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count)
549549
if (!gntdev_dmabuf->u.imp.refs)
550550
goto fail;
551551

552-
gntdev_dmabuf->pages = kcalloc(count,
553-
sizeof(gntdev_dmabuf->pages[0]),
554-
GFP_KERNEL);
555-
if (!gntdev_dmabuf->pages)
556-
goto fail;
557-
558552
gntdev_dmabuf->nr_pages = count;
559553

560554
for (i = 0; i < count; i++)
@@ -576,7 +570,8 @@ dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, struct device *dev,
576570
struct dma_buf *dma_buf;
577571
struct dma_buf_attachment *attach;
578572
struct sg_table *sgt;
579-
struct sg_page_iter sg_iter;
573+
struct sg_dma_page_iter sg_iter;
574+
unsigned long *gfns;
580575
int i;
581576

582577
dma_buf = dma_buf_get(fd);
@@ -624,26 +619,31 @@ dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, struct device *dev,
624619

625620
gntdev_dmabuf->u.imp.sgt = sgt;
626621

627-
/* Now convert sgt to array of pages and check for page validity. */
622+
gfns = kcalloc(count, sizeof(*gfns), GFP_KERNEL);
623+
if (!gfns) {
624+
ret = ERR_PTR(-ENOMEM);
625+
goto fail_unmap;
626+
}
627+
628+
/*
629+
* Now convert sgt to array of gfns without accessing underlying pages.
630+
* It is not allowed to access the underlying struct page of an sg table
631+
* exported by DMA-buf, but since we deal with special Xen dma device here
632+
* (not a normal physical one) look at the dma addresses in the sg table
633+
* and then calculate gfns directly from them.
634+
*/
628635
i = 0;
629-
for_each_sgtable_page(sgt, &sg_iter, 0) {
630-
struct page *page = sg_page_iter_page(&sg_iter);
631-
/*
632-
* Check if page is valid: this can happen if we are given
633-
* a page from VRAM or other resources which are not backed
634-
* by a struct page.
635-
*/
636-
if (!pfn_valid(page_to_pfn(page))) {
637-
ret = ERR_PTR(-EINVAL);
638-
goto fail_unmap;
639-
}
636+
for_each_sgtable_dma_page(sgt, &sg_iter, 0) {
637+
dma_addr_t addr = sg_page_iter_dma_address(&sg_iter);
638+
unsigned long pfn = bfn_to_pfn(XEN_PFN_DOWN(dma_to_phys(dev, addr)));
640639

641-
gntdev_dmabuf->pages[i++] = page;
640+
gfns[i++] = pfn_to_gfn(pfn);
642641
}
643642

644-
ret = ERR_PTR(dmabuf_imp_grant_foreign_access(gntdev_dmabuf->pages,
643+
ret = ERR_PTR(dmabuf_imp_grant_foreign_access(gfns,
645644
gntdev_dmabuf->u.imp.refs,
646645
count, domid));
646+
kfree(gfns);
647647
if (IS_ERR(ret))
648648
goto fail_end_access;
649649

drivers/xen/xenbus/xenbus_client.c

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,13 @@ EXPORT_SYMBOL_GPL(xenbus_strstate);
119119
* @callback: callback to register
120120
*
121121
* 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
125125
* be NULL, the device will switch to %XenbusStateClosing, and the error will
126126
* be saved in the store.
127+
*
128+
* Returns: %0 on success or -errno on error
127129
*/
128130
int xenbus_watch_path(struct xenbus_device *dev, const char *path,
129131
struct xenbus_watch *watch,
@@ -160,12 +162,14 @@ EXPORT_SYMBOL_GPL(xenbus_watch_path);
160162
* @pathfmt: format of path to watch
161163
*
162164
* Register a watch on the given @path, using the given xenbus_watch
163-
* structure for storage, and the given @callback function as the callback.
164-
* Return 0 on success, or -errno on error. On success, the watched path
165-
* (@path/@path2) will be saved as @watch->node, and becomes the caller's to
166-
* kfree(). On error, watch->node will be NULL, so the caller has nothing to
165+
* structure for storage, and the given @callback function as the
166+
* callback. On success, the watched path (@path/@path2) will be saved
167+
* as @watch->node, and becomes the caller's to kfree().
168+
* On error, watch->node will be NULL, so the caller has nothing to
167169
* free, the device will switch to %XenbusStateClosing, and the error will be
168170
* saved in the store.
171+
*
172+
* Returns: %0 on success or -errno on error
169173
*/
170174
int xenbus_watch_pathfmt(struct xenbus_device *dev,
171175
struct xenbus_watch *watch,
@@ -255,13 +259,15 @@ __xenbus_switch_state(struct xenbus_device *dev,
255259
}
256260

257261
/**
258-
* xenbus_switch_state
262+
* xenbus_switch_state - save the new state of a driver
259263
* @dev: xenbus device
260264
* @state: new state
261265
*
262266
* Advertise in the store a change of the given driver to the given new_state.
263-
* Return 0 on success, or -errno on error. On error, the device will switch
264-
* to XenbusStateClosing, and the error will be saved in the store.
267+
* On error, the device will switch to XenbusStateClosing, and the error
268+
* will be saved in the store.
269+
*
270+
* Returns: %0 on success or -errno on error
265271
*/
266272
int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state state)
267273
{
@@ -305,7 +311,7 @@ static void xenbus_va_dev_error(struct xenbus_device *dev, int err,
305311
}
306312

307313
/**
308-
* xenbus_dev_error
314+
* xenbus_dev_error - place an error message into the store
309315
* @dev: xenbus device
310316
* @err: error to report
311317
* @fmt: error message format
@@ -324,7 +330,7 @@ void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...)
324330
EXPORT_SYMBOL_GPL(xenbus_dev_error);
325331

326332
/**
327-
* xenbus_dev_fatal
333+
* xenbus_dev_fatal - put an error messages into the store and then shutdown
328334
* @dev: xenbus device
329335
* @err: error to report
330336
* @fmt: error message format
@@ -346,7 +352,7 @@ void xenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt, ...)
346352
}
347353
EXPORT_SYMBOL_GPL(xenbus_dev_fatal);
348354

349-
/**
355+
/*
350356
* Equivalent to xenbus_dev_fatal(dev, err, fmt, args), but helps
351357
* avoiding recursion within xenbus_switch_state.
352358
*/
@@ -453,7 +459,7 @@ void xenbus_teardown_ring(void **vaddr, unsigned int nr_pages,
453459
}
454460
EXPORT_SYMBOL_GPL(xenbus_teardown_ring);
455461

456-
/**
462+
/*
457463
* Allocate an event channel for the given xenbus_device, assigning the newly
458464
* created local port to *port. Return 0 on success, or -errno on error. On
459465
* error, the device will switch to XenbusStateClosing, and the error will be
@@ -479,7 +485,7 @@ int xenbus_alloc_evtchn(struct xenbus_device *dev, evtchn_port_t *port)
479485
EXPORT_SYMBOL_GPL(xenbus_alloc_evtchn);
480486

481487

482-
/**
488+
/*
483489
* Free an existing event channel. Returns 0 on success or -errno on error.
484490
*/
485491
int xenbus_free_evtchn(struct xenbus_device *dev, evtchn_port_t port)
@@ -499,18 +505,19 @@ EXPORT_SYMBOL_GPL(xenbus_free_evtchn);
499505

500506

501507
/**
502-
* xenbus_map_ring_valloc
508+
* xenbus_map_ring_valloc - allocate & map pages of VA space
503509
* @dev: xenbus device
504510
* @gnt_refs: grant reference array
505511
* @nr_grefs: number of grant references
506512
* @vaddr: pointer to address to be filled out by mapping
507513
*
508514
* Map @nr_grefs pages of memory into this domain from another
509515
* domain's grant table. xenbus_map_ring_valloc allocates @nr_grefs
510-
* pages of virtual address space, maps the pages to that address, and
511-
* sets *vaddr to that address. Returns 0 on success, and -errno on
512-
* error. If an error is returned, device will switch to
516+
* pages of virtual address space, maps the pages to that address, and sets
517+
* *vaddr to that address. If an error is returned, device will switch to
513518
* XenbusStateClosing and the error message will be saved in XenStore.
519+
*
520+
* Returns: %0 on success or -errno on error
514521
*/
515522
int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs,
516523
unsigned int nr_grefs, void **vaddr)
@@ -599,14 +606,15 @@ static int __xenbus_map_ring(struct xenbus_device *dev,
599606
}
600607

601608
/**
602-
* xenbus_unmap_ring
609+
* xenbus_unmap_ring - unmap memory from another domain
603610
* @dev: xenbus device
604611
* @handles: grant handle array
605612
* @nr_handles: number of handles in the array
606613
* @vaddrs: addresses to unmap
607614
*
608615
* Unmap memory in this domain that was imported from another domain.
609-
* Returns 0 on success and returns GNTST_* on error
616+
*
617+
* Returns: %0 on success or GNTST_* on error
610618
* (see xen/include/interface/grant_table.h).
611619
*/
612620
static int xenbus_unmap_ring(struct xenbus_device *dev, grant_handle_t *handles,
@@ -712,15 +720,16 @@ static int xenbus_map_ring_hvm(struct xenbus_device *dev,
712720
}
713721

714722
/**
715-
* xenbus_unmap_ring_vfree
723+
* xenbus_unmap_ring_vfree - unmap a page of memory from another domain
716724
* @dev: xenbus device
717725
* @vaddr: addr to unmap
718726
*
719727
* Based on Rusty Russell's skeleton driver's unmap_page.
720728
* Unmap a page of memory in this domain that was imported from another domain.
721729
* Use xenbus_unmap_ring_vfree if you mapped in your memory with
722730
* xenbus_map_ring_valloc (it will free the virtual address space).
723-
* Returns 0 on success and returns GNTST_* on error
731+
*
732+
* Returns: %0 on success or GNTST_* on error
724733
* (see xen/include/interface/grant_table.h).
725734
*/
726735
int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
@@ -916,10 +925,10 @@ static int xenbus_unmap_ring_hvm(struct xenbus_device *dev, void *vaddr)
916925
}
917926

918927
/**
919-
* xenbus_read_driver_state
928+
* xenbus_read_driver_state - read state from a store path
920929
* @path: path for driver
921930
*
922-
* Return the state of the driver rooted at the given store path, or
931+
* Returns: the state of the driver rooted at the given store path, or
923932
* XenbusStateUnknown if no state can be read.
924933
*/
925934
enum xenbus_state xenbus_read_driver_state(const char *path)

include/xen/interface/io/displif.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ struct xendispl_dbuf_create_req {
537537

538538
struct xendispl_page_directory {
539539
grant_ref_t gref_dir_next_page;
540-
grant_ref_t gref[1]; /* Variable length */
540+
grant_ref_t gref[];
541541
};
542542

543543
/*

include/xen/interface/io/ring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct __name##_sring { \
9595
RING_IDX req_prod, req_event; \
9696
RING_IDX rsp_prod, rsp_event; \
9797
uint8_t __pad[48]; \
98-
union __name##_sring_entry ring[1]; /* variable-length */ \
98+
union __name##_sring_entry ring[]; \
9999
}; \
100100
\
101101
/* "Front" end's private variables */ \

include/xen/interface/io/sndif.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ struct xensnd_open_req {
659659

660660
struct xensnd_page_directory {
661661
grant_ref_t gref_dir_next_page;
662-
grant_ref_t gref[1]; /* Variable length */
662+
grant_ref_t gref[];
663663
};
664664

665665
/*

0 commit comments

Comments
 (0)