diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/cpumask.c | 2 | ||||
| -rw-r--r-- | lib/iovec.c | 59 | ||||
| -rw-r--r-- | lib/lz4/lz4_decompress.c | 10 | ||||
| -rw-r--r-- | lib/swiotlb.c | 28 |
4 files changed, 86 insertions, 13 deletions
diff --git a/lib/cpumask.c b/lib/cpumask.c index c101230658eb..b6513a9f2892 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c | |||
| @@ -191,7 +191,7 @@ int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp) | |||
| 191 | 191 | ||
| 192 | i %= num_online_cpus(); | 192 | i %= num_online_cpus(); |
| 193 | 193 | ||
| 194 | if (!cpumask_of_node(numa_node)) { | 194 | if (numa_node == -1 || !cpumask_of_node(numa_node)) { |
| 195 | /* Use all online cpu's for non numa aware system */ | 195 | /* Use all online cpu's for non numa aware system */ |
| 196 | cpumask_copy(mask, cpu_online_mask); | 196 | cpumask_copy(mask, cpu_online_mask); |
| 197 | } else { | 197 | } else { |
diff --git a/lib/iovec.c b/lib/iovec.c index 454baa88bf27..df3abd1eaa4a 100644 --- a/lib/iovec.c +++ b/lib/iovec.c | |||
| @@ -51,3 +51,62 @@ int memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len) | |||
| 51 | return 0; | 51 | return 0; |
| 52 | } | 52 | } |
| 53 | EXPORT_SYMBOL(memcpy_toiovec); | 53 | EXPORT_SYMBOL(memcpy_toiovec); |
| 54 | |||
| 55 | /* | ||
| 56 | * Copy kernel to iovec. Returns -EFAULT on error. | ||
| 57 | */ | ||
| 58 | |||
| 59 | int memcpy_toiovecend(const struct iovec *iov, unsigned char *kdata, | ||
| 60 | int offset, int len) | ||
| 61 | { | ||
| 62 | int copy; | ||
| 63 | for (; len > 0; ++iov) { | ||
| 64 | /* Skip over the finished iovecs */ | ||
| 65 | if (unlikely(offset >= iov->iov_len)) { | ||
| 66 | offset -= iov->iov_len; | ||
| 67 | continue; | ||
| 68 | } | ||
| 69 | copy = min_t(unsigned int, iov->iov_len - offset, len); | ||
| 70 | if (copy_to_user(iov->iov_base + offset, kdata, copy)) | ||
| 71 | return -EFAULT; | ||
| 72 | offset = 0; | ||
| 73 | kdata += copy; | ||
| 74 | len -= copy; | ||
| 75 | } | ||
| 76 | |||
| 77 | return 0; | ||
| 78 | } | ||
| 79 | EXPORT_SYMBOL(memcpy_toiovecend); | ||
| 80 | |||
| 81 | /* | ||
| 82 | * Copy iovec to kernel. Returns -EFAULT on error. | ||
| 83 | */ | ||
| 84 | |||
| 85 | int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov, | ||
| 86 | int offset, int len) | ||
| 87 | { | ||
| 88 | /* No data? Done! */ | ||
| 89 | if (len == 0) | ||
| 90 | return 0; | ||
| 91 | |||
| 92 | /* Skip over the finished iovecs */ | ||
| 93 | while (offset >= iov->iov_len) { | ||
| 94 | offset -= iov->iov_len; | ||
| 95 | iov++; | ||
| 96 | } | ||
| 97 | |||
| 98 | while (len > 0) { | ||
| 99 | u8 __user *base = iov->iov_base + offset; | ||
| 100 | int copy = min_t(unsigned int, len, iov->iov_len - offset); | ||
| 101 | |||
| 102 | offset = 0; | ||
| 103 | if (copy_from_user(kdata, base, copy)) | ||
| 104 | return -EFAULT; | ||
| 105 | len -= copy; | ||
| 106 | kdata += copy; | ||
| 107 | iov++; | ||
| 108 | } | ||
| 109 | |||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | EXPORT_SYMBOL(memcpy_fromiovecend); | ||
diff --git a/lib/lz4/lz4_decompress.c b/lib/lz4/lz4_decompress.c index 99a03acb7d47..7a85967060a5 100644 --- a/lib/lz4/lz4_decompress.c +++ b/lib/lz4/lz4_decompress.c | |||
| @@ -108,6 +108,8 @@ static int lz4_uncompress(const char *source, char *dest, int osize) | |||
| 108 | if (length == ML_MASK) { | 108 | if (length == ML_MASK) { |
| 109 | for (; *ip == 255; length += 255) | 109 | for (; *ip == 255; length += 255) |
| 110 | ip++; | 110 | ip++; |
| 111 | if (unlikely(length > (size_t)(length + *ip))) | ||
| 112 | goto _output_error; | ||
| 111 | length += *ip++; | 113 | length += *ip++; |
| 112 | } | 114 | } |
| 113 | 115 | ||
| @@ -157,7 +159,7 @@ static int lz4_uncompress(const char *source, char *dest, int osize) | |||
| 157 | 159 | ||
| 158 | /* write overflow error detected */ | 160 | /* write overflow error detected */ |
| 159 | _output_error: | 161 | _output_error: |
| 160 | return (int) (-(((char *)ip) - source)); | 162 | return -1; |
| 161 | } | 163 | } |
| 162 | 164 | ||
| 163 | static int lz4_uncompress_unknownoutputsize(const char *source, char *dest, | 165 | static int lz4_uncompress_unknownoutputsize(const char *source, char *dest, |
| @@ -190,6 +192,8 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest, | |||
| 190 | int s = 255; | 192 | int s = 255; |
| 191 | while ((ip < iend) && (s == 255)) { | 193 | while ((ip < iend) && (s == 255)) { |
| 192 | s = *ip++; | 194 | s = *ip++; |
| 195 | if (unlikely(length > (size_t)(length + s))) | ||
| 196 | goto _output_error; | ||
| 193 | length += s; | 197 | length += s; |
| 194 | } | 198 | } |
| 195 | } | 199 | } |
| @@ -230,6 +234,8 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest, | |||
| 230 | if (length == ML_MASK) { | 234 | if (length == ML_MASK) { |
| 231 | while (ip < iend) { | 235 | while (ip < iend) { |
| 232 | int s = *ip++; | 236 | int s = *ip++; |
| 237 | if (unlikely(length > (size_t)(length + s))) | ||
| 238 | goto _output_error; | ||
| 233 | length += s; | 239 | length += s; |
| 234 | if (s == 255) | 240 | if (s == 255) |
| 235 | continue; | 241 | continue; |
| @@ -282,7 +288,7 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest, | |||
| 282 | 288 | ||
| 283 | /* write overflow error detected */ | 289 | /* write overflow error detected */ |
| 284 | _output_error: | 290 | _output_error: |
| 285 | return (int) (-(((char *) ip) - source)); | 291 | return -1; |
| 286 | } | 292 | } |
| 287 | 293 | ||
| 288 | int lz4_decompress(const unsigned char *src, size_t *src_len, | 294 | int lz4_decompress(const unsigned char *src, size_t *src_len, |
diff --git a/lib/swiotlb.c b/lib/swiotlb.c index 649d097853a1..4abda074ea45 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c | |||
| @@ -86,6 +86,7 @@ static unsigned int io_tlb_index; | |||
| 86 | * We need to save away the original address corresponding to a mapped entry | 86 | * We need to save away the original address corresponding to a mapped entry |
| 87 | * for the sync operations. | 87 | * for the sync operations. |
| 88 | */ | 88 | */ |
| 89 | #define INVALID_PHYS_ADDR (~(phys_addr_t)0) | ||
| 89 | static phys_addr_t *io_tlb_orig_addr; | 90 | static phys_addr_t *io_tlb_orig_addr; |
| 90 | 91 | ||
| 91 | /* | 92 | /* |
| @@ -188,12 +189,14 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) | |||
| 188 | io_tlb_list = memblock_virt_alloc( | 189 | io_tlb_list = memblock_virt_alloc( |
| 189 | PAGE_ALIGN(io_tlb_nslabs * sizeof(int)), | 190 | PAGE_ALIGN(io_tlb_nslabs * sizeof(int)), |
| 190 | PAGE_SIZE); | 191 | PAGE_SIZE); |
| 191 | for (i = 0; i < io_tlb_nslabs; i++) | ||
| 192 | io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); | ||
| 193 | io_tlb_index = 0; | ||
| 194 | io_tlb_orig_addr = memblock_virt_alloc( | 192 | io_tlb_orig_addr = memblock_virt_alloc( |
| 195 | PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)), | 193 | PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)), |
| 196 | PAGE_SIZE); | 194 | PAGE_SIZE); |
| 195 | for (i = 0; i < io_tlb_nslabs; i++) { | ||
| 196 | io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); | ||
| 197 | io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; | ||
| 198 | } | ||
| 199 | io_tlb_index = 0; | ||
| 197 | 200 | ||
| 198 | if (verbose) | 201 | if (verbose) |
| 199 | swiotlb_print_info(); | 202 | swiotlb_print_info(); |
| @@ -313,10 +316,6 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) | |||
| 313 | if (!io_tlb_list) | 316 | if (!io_tlb_list) |
| 314 | goto cleanup3; | 317 | goto cleanup3; |
| 315 | 318 | ||
| 316 | for (i = 0; i < io_tlb_nslabs; i++) | ||
| 317 | io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); | ||
| 318 | io_tlb_index = 0; | ||
| 319 | |||
| 320 | io_tlb_orig_addr = (phys_addr_t *) | 319 | io_tlb_orig_addr = (phys_addr_t *) |
| 321 | __get_free_pages(GFP_KERNEL, | 320 | __get_free_pages(GFP_KERNEL, |
| 322 | get_order(io_tlb_nslabs * | 321 | get_order(io_tlb_nslabs * |
| @@ -324,7 +323,11 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) | |||
| 324 | if (!io_tlb_orig_addr) | 323 | if (!io_tlb_orig_addr) |
| 325 | goto cleanup4; | 324 | goto cleanup4; |
| 326 | 325 | ||
| 327 | memset(io_tlb_orig_addr, 0, io_tlb_nslabs * sizeof(phys_addr_t)); | 326 | for (i = 0; i < io_tlb_nslabs; i++) { |
| 327 | io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); | ||
| 328 | io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; | ||
| 329 | } | ||
| 330 | io_tlb_index = 0; | ||
| 328 | 331 | ||
| 329 | swiotlb_print_info(); | 332 | swiotlb_print_info(); |
| 330 | 333 | ||
| @@ -556,7 +559,8 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, | |||
| 556 | /* | 559 | /* |
| 557 | * First, sync the memory before unmapping the entry | 560 | * First, sync the memory before unmapping the entry |
| 558 | */ | 561 | */ |
| 559 | if (orig_addr && ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL))) | 562 | if (orig_addr != INVALID_PHYS_ADDR && |
| 563 | ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL))) | ||
| 560 | swiotlb_bounce(orig_addr, tlb_addr, size, DMA_FROM_DEVICE); | 564 | swiotlb_bounce(orig_addr, tlb_addr, size, DMA_FROM_DEVICE); |
| 561 | 565 | ||
| 562 | /* | 566 | /* |
| @@ -573,8 +577,10 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, | |||
| 573 | * Step 1: return the slots to the free list, merging the | 577 | * Step 1: return the slots to the free list, merging the |
| 574 | * slots with superceeding slots | 578 | * slots with superceeding slots |
| 575 | */ | 579 | */ |
| 576 | for (i = index + nslots - 1; i >= index; i--) | 580 | for (i = index + nslots - 1; i >= index; i--) { |
| 577 | io_tlb_list[i] = ++count; | 581 | io_tlb_list[i] = ++count; |
| 582 | io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; | ||
| 583 | } | ||
| 578 | /* | 584 | /* |
| 579 | * Step 2: merge the returned slots with the preceding slots, | 585 | * Step 2: merge the returned slots with the preceding slots, |
| 580 | * if available (non zero) | 586 | * if available (non zero) |
| @@ -593,6 +599,8 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, | |||
| 593 | int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT; | 599 | int index = (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT; |
| 594 | phys_addr_t orig_addr = io_tlb_orig_addr[index]; | 600 | phys_addr_t orig_addr = io_tlb_orig_addr[index]; |
| 595 | 601 | ||
| 602 | if (orig_addr == INVALID_PHYS_ADDR) | ||
| 603 | return; | ||
| 596 | orig_addr += (unsigned long)tlb_addr & ((1 << IO_TLB_SHIFT) - 1); | 604 | orig_addr += (unsigned long)tlb_addr & ((1 << IO_TLB_SHIFT) - 1); |
| 597 | 605 | ||
| 598 | switch (target) { | 606 | switch (target) { |
