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.

swiotlb: provide swiotlb_init variants that remap the buffer

To shared more code between swiotlb and xen-swiotlb, offer a
swiotlb_init_remap interface and add a remap callback to
swiotlb_init_late that will allow Xen to remap the buffer without
duplicating much of the logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>

+38 -5
+1 -1
arch/x86/pci/sta2x11-fixup.c
··· 57 57 int size = STA2X11_SWIOTLB_SIZE; 58 58 /* First instance: register your own swiotlb area */ 59 59 dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size); 60 - if (swiotlb_init_late(size, GFP_DMA)) 60 + if (swiotlb_init_late(size, GFP_DMA, NULL)) 61 61 dev_emerg(&pdev->dev, "init swiotlb failed\n"); 62 62 } 63 63 list_add(&instance->list, &sta2x11_instance_list);
+4 -1
include/linux/swiotlb.h
··· 36 36 37 37 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags); 38 38 unsigned long swiotlb_size_or_default(void); 39 + void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags, 40 + int (*remap)(void *tlb, unsigned long nslabs)); 41 + int swiotlb_init_late(size_t size, gfp_t gfp_mask, 42 + int (*remap)(void *tlb, unsigned long nslabs)); 39 43 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs); 40 - int swiotlb_init_late(size_t size, gfp_t gfp_mask); 41 44 extern void __init swiotlb_update_mem_attributes(void); 42 45 43 46 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
+33 -3
kernel/dma/swiotlb.c
··· 256 256 * Statically reserve bounce buffer space and initialize bounce buffer data 257 257 * structures for the software IO TLB used to implement the DMA API. 258 258 */ 259 - void __init swiotlb_init(bool addressing_limit, unsigned int flags) 259 + void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags, 260 + int (*remap)(void *tlb, unsigned long nslabs)) 260 261 { 261 - size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT); 262 + unsigned long nslabs = default_nslabs; 263 + size_t bytes; 262 264 void *tlb; 263 265 264 266 if (!addressing_limit && !swiotlb_force_bounce) ··· 273 271 * allow to pick a location everywhere for hypervisors with guest 274 272 * memory encryption. 275 273 */ 274 + retry: 275 + bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT); 276 276 if (flags & SWIOTLB_ANY) 277 277 tlb = memblock_alloc(bytes, PAGE_SIZE); 278 278 else 279 279 tlb = memblock_alloc_low(bytes, PAGE_SIZE); 280 280 if (!tlb) 281 281 goto fail; 282 + if (remap && remap(tlb, nslabs) < 0) { 283 + memblock_free(tlb, PAGE_ALIGN(bytes)); 284 + 285 + nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE); 286 + if (nslabs < IO_TLB_MIN_SLABS) 287 + panic("%s: Failed to remap %zu bytes\n", 288 + __func__, bytes); 289 + goto retry; 290 + } 282 291 if (swiotlb_init_with_tbl(tlb, default_nslabs, flags)) 283 292 goto fail_free_mem; 284 293 return; ··· 300 287 pr_warn("Cannot allocate buffer"); 301 288 } 302 289 290 + void __init swiotlb_init(bool addressing_limit, unsigned int flags) 291 + { 292 + return swiotlb_init_remap(addressing_limit, flags, NULL); 293 + } 294 + 303 295 /* 304 296 * Systems with larger DMA zones (those that don't support ISA) can 305 297 * initialize the swiotlb later using the slab allocator if needed. 306 298 * This should be just like above, but with some error catching. 307 299 */ 308 - int swiotlb_init_late(size_t size, gfp_t gfp_mask) 300 + int swiotlb_init_late(size_t size, gfp_t gfp_mask, 301 + int (*remap)(void *tlb, unsigned long nslabs)) 309 302 { 310 303 unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE); 311 304 unsigned long bytes; ··· 322 303 if (swiotlb_force_disable) 323 304 return 0; 324 305 306 + retry: 325 307 order = get_order(nslabs << IO_TLB_SHIFT); 326 308 nslabs = SLABS_PER_PAGE << order; 327 309 bytes = nslabs << IO_TLB_SHIFT; ··· 342 322 pr_warn("only able to allocate %ld MB\n", 343 323 (PAGE_SIZE << order) >> 20); 344 324 nslabs = SLABS_PER_PAGE << order; 325 + } 326 + if (remap) 327 + rc = remap(vstart, nslabs); 328 + if (rc) { 329 + free_pages((unsigned long)vstart, order); 330 + 331 + nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE); 332 + if (nslabs < IO_TLB_MIN_SLABS) 333 + return rc; 334 + goto retry; 345 335 } 346 336 rc = swiotlb_late_init_with_tbl(vstart, nslabs); 347 337 if (rc)