Al Viro | 4f18cd3 | 2014-02-05 19:11:33 -0500 | [diff] [blame] | 1 | #include <linux/export.h> |
| 2 | #include <linux/uio.h> |
| 3 | #include <linux/pagemap.h> |
Al Viro | 91f79c4 | 2014-03-21 04:58:33 -0400 | [diff] [blame] | 4 | #include <linux/slab.h> |
| 5 | #include <linux/vmalloc.h> |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 6 | #include <linux/splice.h> |
Al Viro | a604ec7 | 2014-11-24 01:08:00 -0500 | [diff] [blame] | 7 | #include <net/checksum.h> |
Al Viro | 4f18cd3 | 2014-02-05 19:11:33 -0500 | [diff] [blame] | 8 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 9 | #define PIPE_PARANOIA /* for now */ |
| 10 | |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 11 | #define iterate_iovec(i, n, __v, __p, skip, STEP) { \ |
| 12 | size_t left; \ |
| 13 | size_t wanted = n; \ |
| 14 | __p = i->iov; \ |
| 15 | __v.iov_len = min(n, __p->iov_len - skip); \ |
| 16 | if (likely(__v.iov_len)) { \ |
| 17 | __v.iov_base = __p->iov_base + skip; \ |
| 18 | left = (STEP); \ |
| 19 | __v.iov_len -= left; \ |
| 20 | skip += __v.iov_len; \ |
| 21 | n -= __v.iov_len; \ |
| 22 | } else { \ |
| 23 | left = 0; \ |
| 24 | } \ |
| 25 | while (unlikely(!left && n)) { \ |
| 26 | __p++; \ |
| 27 | __v.iov_len = min(n, __p->iov_len); \ |
| 28 | if (unlikely(!__v.iov_len)) \ |
| 29 | continue; \ |
| 30 | __v.iov_base = __p->iov_base; \ |
| 31 | left = (STEP); \ |
| 32 | __v.iov_len -= left; \ |
| 33 | skip = __v.iov_len; \ |
| 34 | n -= __v.iov_len; \ |
| 35 | } \ |
| 36 | n = wanted - n; \ |
| 37 | } |
| 38 | |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 39 | #define iterate_kvec(i, n, __v, __p, skip, STEP) { \ |
| 40 | size_t wanted = n; \ |
| 41 | __p = i->kvec; \ |
| 42 | __v.iov_len = min(n, __p->iov_len - skip); \ |
| 43 | if (likely(__v.iov_len)) { \ |
| 44 | __v.iov_base = __p->iov_base + skip; \ |
| 45 | (void)(STEP); \ |
| 46 | skip += __v.iov_len; \ |
| 47 | n -= __v.iov_len; \ |
| 48 | } \ |
| 49 | while (unlikely(n)) { \ |
| 50 | __p++; \ |
| 51 | __v.iov_len = min(n, __p->iov_len); \ |
| 52 | if (unlikely(!__v.iov_len)) \ |
| 53 | continue; \ |
| 54 | __v.iov_base = __p->iov_base; \ |
| 55 | (void)(STEP); \ |
| 56 | skip = __v.iov_len; \ |
| 57 | n -= __v.iov_len; \ |
| 58 | } \ |
| 59 | n = wanted; \ |
| 60 | } |
| 61 | |
Ming Lei | 1bdc76a | 2016-05-30 21:34:32 +0800 | [diff] [blame] | 62 | #define iterate_bvec(i, n, __v, __bi, skip, STEP) { \ |
| 63 | struct bvec_iter __start; \ |
| 64 | __start.bi_size = n; \ |
| 65 | __start.bi_bvec_done = skip; \ |
| 66 | __start.bi_idx = 0; \ |
| 67 | for_each_bvec(__v, i->bvec, __bi, __start) { \ |
| 68 | if (!__v.bv_len) \ |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 69 | continue; \ |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 70 | (void)(STEP); \ |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 71 | } \ |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 72 | } |
| 73 | |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 74 | #define iterate_all_kinds(i, n, v, I, B, K) { \ |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 75 | size_t skip = i->iov_offset; \ |
| 76 | if (unlikely(i->type & ITER_BVEC)) { \ |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 77 | struct bio_vec v; \ |
Ming Lei | 1bdc76a | 2016-05-30 21:34:32 +0800 | [diff] [blame] | 78 | struct bvec_iter __bi; \ |
| 79 | iterate_bvec(i, n, v, __bi, skip, (B)) \ |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 80 | } else if (unlikely(i->type & ITER_KVEC)) { \ |
| 81 | const struct kvec *kvec; \ |
| 82 | struct kvec v; \ |
| 83 | iterate_kvec(i, n, v, kvec, skip, (K)) \ |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 84 | } else { \ |
| 85 | const struct iovec *iov; \ |
| 86 | struct iovec v; \ |
| 87 | iterate_iovec(i, n, v, iov, skip, (I)) \ |
| 88 | } \ |
| 89 | } |
| 90 | |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 91 | #define iterate_and_advance(i, n, v, I, B, K) { \ |
Al Viro | dd254f5 | 2016-05-09 11:54:48 -0400 | [diff] [blame] | 92 | if (unlikely(i->count < n)) \ |
| 93 | n = i->count; \ |
Al Viro | 19f1845 | 2016-05-25 17:36:19 -0400 | [diff] [blame] | 94 | if (i->count) { \ |
Al Viro | dd254f5 | 2016-05-09 11:54:48 -0400 | [diff] [blame] | 95 | size_t skip = i->iov_offset; \ |
| 96 | if (unlikely(i->type & ITER_BVEC)) { \ |
Ming Lei | 1bdc76a | 2016-05-30 21:34:32 +0800 | [diff] [blame] | 97 | const struct bio_vec *bvec = i->bvec; \ |
Al Viro | dd254f5 | 2016-05-09 11:54:48 -0400 | [diff] [blame] | 98 | struct bio_vec v; \ |
Ming Lei | 1bdc76a | 2016-05-30 21:34:32 +0800 | [diff] [blame] | 99 | struct bvec_iter __bi; \ |
| 100 | iterate_bvec(i, n, v, __bi, skip, (B)) \ |
| 101 | i->bvec = __bvec_iter_bvec(i->bvec, __bi); \ |
| 102 | i->nr_segs -= i->bvec - bvec; \ |
| 103 | skip = __bi.bi_bvec_done; \ |
Al Viro | dd254f5 | 2016-05-09 11:54:48 -0400 | [diff] [blame] | 104 | } else if (unlikely(i->type & ITER_KVEC)) { \ |
| 105 | const struct kvec *kvec; \ |
| 106 | struct kvec v; \ |
| 107 | iterate_kvec(i, n, v, kvec, skip, (K)) \ |
| 108 | if (skip == kvec->iov_len) { \ |
| 109 | kvec++; \ |
| 110 | skip = 0; \ |
| 111 | } \ |
| 112 | i->nr_segs -= kvec - i->kvec; \ |
| 113 | i->kvec = kvec; \ |
| 114 | } else { \ |
| 115 | const struct iovec *iov; \ |
| 116 | struct iovec v; \ |
| 117 | iterate_iovec(i, n, v, iov, skip, (I)) \ |
| 118 | if (skip == iov->iov_len) { \ |
| 119 | iov++; \ |
| 120 | skip = 0; \ |
| 121 | } \ |
| 122 | i->nr_segs -= iov - i->iov; \ |
| 123 | i->iov = iov; \ |
Al Viro | 7ce2a91 | 2014-11-27 13:59:45 -0500 | [diff] [blame] | 124 | } \ |
Al Viro | dd254f5 | 2016-05-09 11:54:48 -0400 | [diff] [blame] | 125 | i->count -= n; \ |
| 126 | i->iov_offset = skip; \ |
Al Viro | 7ce2a91 | 2014-11-27 13:59:45 -0500 | [diff] [blame] | 127 | } \ |
Al Viro | 7ce2a91 | 2014-11-27 13:59:45 -0500 | [diff] [blame] | 128 | } |
| 129 | |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 130 | static size_t copy_page_to_iter_iovec(struct page *page, size_t offset, size_t bytes, |
Al Viro | 4f18cd3 | 2014-02-05 19:11:33 -0500 | [diff] [blame] | 131 | struct iov_iter *i) |
| 132 | { |
| 133 | size_t skip, copy, left, wanted; |
| 134 | const struct iovec *iov; |
| 135 | char __user *buf; |
| 136 | void *kaddr, *from; |
| 137 | |
| 138 | if (unlikely(bytes > i->count)) |
| 139 | bytes = i->count; |
| 140 | |
| 141 | if (unlikely(!bytes)) |
| 142 | return 0; |
| 143 | |
| 144 | wanted = bytes; |
| 145 | iov = i->iov; |
| 146 | skip = i->iov_offset; |
| 147 | buf = iov->iov_base + skip; |
| 148 | copy = min(bytes, iov->iov_len - skip); |
| 149 | |
Mikulas Patocka | 3fa6c50 | 2016-07-28 15:48:50 -0700 | [diff] [blame] | 150 | if (IS_ENABLED(CONFIG_HIGHMEM) && !fault_in_pages_writeable(buf, copy)) { |
Al Viro | 4f18cd3 | 2014-02-05 19:11:33 -0500 | [diff] [blame] | 151 | kaddr = kmap_atomic(page); |
| 152 | from = kaddr + offset; |
| 153 | |
| 154 | /* first chunk, usually the only one */ |
| 155 | left = __copy_to_user_inatomic(buf, from, copy); |
| 156 | copy -= left; |
| 157 | skip += copy; |
| 158 | from += copy; |
| 159 | bytes -= copy; |
| 160 | |
| 161 | while (unlikely(!left && bytes)) { |
| 162 | iov++; |
| 163 | buf = iov->iov_base; |
| 164 | copy = min(bytes, iov->iov_len); |
| 165 | left = __copy_to_user_inatomic(buf, from, copy); |
| 166 | copy -= left; |
| 167 | skip = copy; |
| 168 | from += copy; |
| 169 | bytes -= copy; |
| 170 | } |
| 171 | if (likely(!bytes)) { |
| 172 | kunmap_atomic(kaddr); |
| 173 | goto done; |
| 174 | } |
| 175 | offset = from - kaddr; |
| 176 | buf += copy; |
| 177 | kunmap_atomic(kaddr); |
| 178 | copy = min(bytes, iov->iov_len - skip); |
| 179 | } |
| 180 | /* Too bad - revert to non-atomic kmap */ |
Mikulas Patocka | 3fa6c50 | 2016-07-28 15:48:50 -0700 | [diff] [blame] | 181 | |
Al Viro | 4f18cd3 | 2014-02-05 19:11:33 -0500 | [diff] [blame] | 182 | kaddr = kmap(page); |
| 183 | from = kaddr + offset; |
| 184 | left = __copy_to_user(buf, from, copy); |
| 185 | copy -= left; |
| 186 | skip += copy; |
| 187 | from += copy; |
| 188 | bytes -= copy; |
| 189 | while (unlikely(!left && bytes)) { |
| 190 | iov++; |
| 191 | buf = iov->iov_base; |
| 192 | copy = min(bytes, iov->iov_len); |
| 193 | left = __copy_to_user(buf, from, copy); |
| 194 | copy -= left; |
| 195 | skip = copy; |
| 196 | from += copy; |
| 197 | bytes -= copy; |
| 198 | } |
| 199 | kunmap(page); |
Mikulas Patocka | 3fa6c50 | 2016-07-28 15:48:50 -0700 | [diff] [blame] | 200 | |
Al Viro | 4f18cd3 | 2014-02-05 19:11:33 -0500 | [diff] [blame] | 201 | done: |
Al Viro | 81055e5 | 2014-04-04 19:23:46 -0400 | [diff] [blame] | 202 | if (skip == iov->iov_len) { |
| 203 | iov++; |
| 204 | skip = 0; |
| 205 | } |
Al Viro | 4f18cd3 | 2014-02-05 19:11:33 -0500 | [diff] [blame] | 206 | i->count -= wanted - bytes; |
| 207 | i->nr_segs -= iov - i->iov; |
| 208 | i->iov = iov; |
| 209 | i->iov_offset = skip; |
| 210 | return wanted - bytes; |
| 211 | } |
Al Viro | 4f18cd3 | 2014-02-05 19:11:33 -0500 | [diff] [blame] | 212 | |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 213 | static size_t copy_page_from_iter_iovec(struct page *page, size_t offset, size_t bytes, |
Al Viro | f0d1bec | 2014-04-03 15:05:18 -0400 | [diff] [blame] | 214 | struct iov_iter *i) |
| 215 | { |
| 216 | size_t skip, copy, left, wanted; |
| 217 | const struct iovec *iov; |
| 218 | char __user *buf; |
| 219 | void *kaddr, *to; |
| 220 | |
| 221 | if (unlikely(bytes > i->count)) |
| 222 | bytes = i->count; |
| 223 | |
| 224 | if (unlikely(!bytes)) |
| 225 | return 0; |
| 226 | |
| 227 | wanted = bytes; |
| 228 | iov = i->iov; |
| 229 | skip = i->iov_offset; |
| 230 | buf = iov->iov_base + skip; |
| 231 | copy = min(bytes, iov->iov_len - skip); |
| 232 | |
Mikulas Patocka | 3fa6c50 | 2016-07-28 15:48:50 -0700 | [diff] [blame] | 233 | if (IS_ENABLED(CONFIG_HIGHMEM) && !fault_in_pages_readable(buf, copy)) { |
Al Viro | f0d1bec | 2014-04-03 15:05:18 -0400 | [diff] [blame] | 234 | kaddr = kmap_atomic(page); |
| 235 | to = kaddr + offset; |
| 236 | |
| 237 | /* first chunk, usually the only one */ |
| 238 | left = __copy_from_user_inatomic(to, buf, copy); |
| 239 | copy -= left; |
| 240 | skip += copy; |
| 241 | to += copy; |
| 242 | bytes -= copy; |
| 243 | |
| 244 | while (unlikely(!left && bytes)) { |
| 245 | iov++; |
| 246 | buf = iov->iov_base; |
| 247 | copy = min(bytes, iov->iov_len); |
| 248 | left = __copy_from_user_inatomic(to, buf, copy); |
| 249 | copy -= left; |
| 250 | skip = copy; |
| 251 | to += copy; |
| 252 | bytes -= copy; |
| 253 | } |
| 254 | if (likely(!bytes)) { |
| 255 | kunmap_atomic(kaddr); |
| 256 | goto done; |
| 257 | } |
| 258 | offset = to - kaddr; |
| 259 | buf += copy; |
| 260 | kunmap_atomic(kaddr); |
| 261 | copy = min(bytes, iov->iov_len - skip); |
| 262 | } |
| 263 | /* Too bad - revert to non-atomic kmap */ |
Mikulas Patocka | 3fa6c50 | 2016-07-28 15:48:50 -0700 | [diff] [blame] | 264 | |
Al Viro | f0d1bec | 2014-04-03 15:05:18 -0400 | [diff] [blame] | 265 | kaddr = kmap(page); |
| 266 | to = kaddr + offset; |
| 267 | left = __copy_from_user(to, buf, copy); |
| 268 | copy -= left; |
| 269 | skip += copy; |
| 270 | to += copy; |
| 271 | bytes -= copy; |
| 272 | while (unlikely(!left && bytes)) { |
| 273 | iov++; |
| 274 | buf = iov->iov_base; |
| 275 | copy = min(bytes, iov->iov_len); |
| 276 | left = __copy_from_user(to, buf, copy); |
| 277 | copy -= left; |
| 278 | skip = copy; |
| 279 | to += copy; |
| 280 | bytes -= copy; |
| 281 | } |
| 282 | kunmap(page); |
Mikulas Patocka | 3fa6c50 | 2016-07-28 15:48:50 -0700 | [diff] [blame] | 283 | |
Al Viro | f0d1bec | 2014-04-03 15:05:18 -0400 | [diff] [blame] | 284 | done: |
Al Viro | 81055e5 | 2014-04-04 19:23:46 -0400 | [diff] [blame] | 285 | if (skip == iov->iov_len) { |
| 286 | iov++; |
| 287 | skip = 0; |
| 288 | } |
Al Viro | f0d1bec | 2014-04-03 15:05:18 -0400 | [diff] [blame] | 289 | i->count -= wanted - bytes; |
| 290 | i->nr_segs -= iov - i->iov; |
| 291 | i->iov = iov; |
| 292 | i->iov_offset = skip; |
| 293 | return wanted - bytes; |
| 294 | } |
Al Viro | f0d1bec | 2014-04-03 15:05:18 -0400 | [diff] [blame] | 295 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 296 | #ifdef PIPE_PARANOIA |
| 297 | static bool sanity(const struct iov_iter *i) |
| 298 | { |
| 299 | struct pipe_inode_info *pipe = i->pipe; |
| 300 | int idx = i->idx; |
| 301 | int next = pipe->curbuf + pipe->nrbufs; |
| 302 | if (i->iov_offset) { |
| 303 | struct pipe_buffer *p; |
| 304 | if (unlikely(!pipe->nrbufs)) |
| 305 | goto Bad; // pipe must be non-empty |
| 306 | if (unlikely(idx != ((next - 1) & (pipe->buffers - 1)))) |
| 307 | goto Bad; // must be at the last buffer... |
| 308 | |
| 309 | p = &pipe->bufs[idx]; |
| 310 | if (unlikely(p->offset + p->len != i->iov_offset)) |
| 311 | goto Bad; // ... at the end of segment |
| 312 | } else { |
| 313 | if (idx != (next & (pipe->buffers - 1))) |
| 314 | goto Bad; // must be right after the last buffer |
| 315 | } |
| 316 | return true; |
| 317 | Bad: |
| 318 | printk(KERN_ERR "idx = %d, offset = %zd\n", i->idx, i->iov_offset); |
| 319 | printk(KERN_ERR "curbuf = %d, nrbufs = %d, buffers = %d\n", |
| 320 | pipe->curbuf, pipe->nrbufs, pipe->buffers); |
| 321 | for (idx = 0; idx < pipe->buffers; idx++) |
| 322 | printk(KERN_ERR "[%p %p %d %d]\n", |
| 323 | pipe->bufs[idx].ops, |
| 324 | pipe->bufs[idx].page, |
| 325 | pipe->bufs[idx].offset, |
| 326 | pipe->bufs[idx].len); |
| 327 | WARN_ON(1); |
| 328 | return false; |
| 329 | } |
| 330 | #else |
| 331 | #define sanity(i) true |
| 332 | #endif |
| 333 | |
| 334 | static inline int next_idx(int idx, struct pipe_inode_info *pipe) |
| 335 | { |
| 336 | return (idx + 1) & (pipe->buffers - 1); |
| 337 | } |
| 338 | |
| 339 | static size_t copy_page_to_iter_pipe(struct page *page, size_t offset, size_t bytes, |
| 340 | struct iov_iter *i) |
| 341 | { |
| 342 | struct pipe_inode_info *pipe = i->pipe; |
| 343 | struct pipe_buffer *buf; |
| 344 | size_t off; |
| 345 | int idx; |
| 346 | |
| 347 | if (unlikely(bytes > i->count)) |
| 348 | bytes = i->count; |
| 349 | |
| 350 | if (unlikely(!bytes)) |
| 351 | return 0; |
| 352 | |
| 353 | if (!sanity(i)) |
| 354 | return 0; |
| 355 | |
| 356 | off = i->iov_offset; |
| 357 | idx = i->idx; |
| 358 | buf = &pipe->bufs[idx]; |
| 359 | if (off) { |
| 360 | if (offset == off && buf->page == page) { |
| 361 | /* merge with the last one */ |
| 362 | buf->len += bytes; |
| 363 | i->iov_offset += bytes; |
| 364 | goto out; |
| 365 | } |
| 366 | idx = next_idx(idx, pipe); |
| 367 | buf = &pipe->bufs[idx]; |
| 368 | } |
| 369 | if (idx == pipe->curbuf && pipe->nrbufs) |
| 370 | return 0; |
| 371 | pipe->nrbufs++; |
| 372 | buf->ops = &page_cache_pipe_buf_ops; |
| 373 | get_page(buf->page = page); |
| 374 | buf->offset = offset; |
| 375 | buf->len = bytes; |
| 376 | i->iov_offset = offset + bytes; |
| 377 | i->idx = idx; |
| 378 | out: |
| 379 | i->count -= bytes; |
| 380 | return bytes; |
| 381 | } |
| 382 | |
Al Viro | 4f18cd3 | 2014-02-05 19:11:33 -0500 | [diff] [blame] | 383 | /* |
Anton Altaparmakov | 171a020 | 2015-03-11 10:43:31 -0400 | [diff] [blame] | 384 | * Fault in one or more iovecs of the given iov_iter, to a maximum length of |
| 385 | * bytes. For each iovec, fault in each page that constitutes the iovec. |
| 386 | * |
| 387 | * Return 0 on success, or non-zero if the memory could not be accessed (i.e. |
| 388 | * because it is an invalid address). |
| 389 | */ |
Al Viro | d4690f1 | 2016-09-16 00:11:45 +0100 | [diff] [blame] | 390 | int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes) |
Anton Altaparmakov | 171a020 | 2015-03-11 10:43:31 -0400 | [diff] [blame] | 391 | { |
| 392 | size_t skip = i->iov_offset; |
| 393 | const struct iovec *iov; |
| 394 | int err; |
| 395 | struct iovec v; |
| 396 | |
| 397 | if (!(i->type & (ITER_BVEC|ITER_KVEC))) { |
| 398 | iterate_iovec(i, bytes, v, iov, skip, ({ |
Al Viro | 4bce9f6 | 2016-09-17 18:02:44 -0400 | [diff] [blame] | 399 | err = fault_in_pages_readable(v.iov_base, v.iov_len); |
Anton Altaparmakov | 171a020 | 2015-03-11 10:43:31 -0400 | [diff] [blame] | 400 | if (unlikely(err)) |
| 401 | return err; |
| 402 | 0;})) |
| 403 | } |
| 404 | return 0; |
| 405 | } |
Al Viro | d4690f1 | 2016-09-16 00:11:45 +0100 | [diff] [blame] | 406 | EXPORT_SYMBOL(iov_iter_fault_in_readable); |
Anton Altaparmakov | 171a020 | 2015-03-11 10:43:31 -0400 | [diff] [blame] | 407 | |
Al Viro | 71d8e53 | 2014-03-05 19:28:09 -0500 | [diff] [blame] | 408 | void iov_iter_init(struct iov_iter *i, int direction, |
| 409 | const struct iovec *iov, unsigned long nr_segs, |
| 410 | size_t count) |
| 411 | { |
| 412 | /* It will get better. Eventually... */ |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 413 | if (segment_eq(get_fs(), KERNEL_DS)) { |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 414 | direction |= ITER_KVEC; |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 415 | i->type = direction; |
| 416 | i->kvec = (struct kvec *)iov; |
| 417 | } else { |
| 418 | i->type = direction; |
| 419 | i->iov = iov; |
| 420 | } |
Al Viro | 71d8e53 | 2014-03-05 19:28:09 -0500 | [diff] [blame] | 421 | i->nr_segs = nr_segs; |
| 422 | i->iov_offset = 0; |
| 423 | i->count = count; |
| 424 | } |
| 425 | EXPORT_SYMBOL(iov_iter_init); |
Al Viro | 7b2c99d | 2014-03-15 04:05:57 -0400 | [diff] [blame] | 426 | |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 427 | static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t len) |
| 428 | { |
| 429 | char *from = kmap_atomic(page); |
| 430 | memcpy(to, from + offset, len); |
| 431 | kunmap_atomic(from); |
| 432 | } |
| 433 | |
Al Viro | 36f7a8a | 2015-12-06 16:49:22 -0500 | [diff] [blame] | 434 | static void memcpy_to_page(struct page *page, size_t offset, const char *from, size_t len) |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 435 | { |
| 436 | char *to = kmap_atomic(page); |
| 437 | memcpy(to + offset, from, len); |
| 438 | kunmap_atomic(to); |
| 439 | } |
| 440 | |
Matthew Wilcox | c35e024 | 2014-08-01 09:27:22 -0400 | [diff] [blame] | 441 | static void memzero_page(struct page *page, size_t offset, size_t len) |
| 442 | { |
| 443 | char *addr = kmap_atomic(page); |
| 444 | memset(addr + offset, 0, len); |
| 445 | kunmap_atomic(addr); |
| 446 | } |
| 447 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 448 | static inline bool allocated(struct pipe_buffer *buf) |
| 449 | { |
| 450 | return buf->ops == &default_pipe_buf_ops; |
| 451 | } |
| 452 | |
| 453 | static inline void data_start(const struct iov_iter *i, int *idxp, size_t *offp) |
| 454 | { |
| 455 | size_t off = i->iov_offset; |
| 456 | int idx = i->idx; |
| 457 | if (off && (!allocated(&i->pipe->bufs[idx]) || off == PAGE_SIZE)) { |
| 458 | idx = next_idx(idx, i->pipe); |
| 459 | off = 0; |
| 460 | } |
| 461 | *idxp = idx; |
| 462 | *offp = off; |
| 463 | } |
| 464 | |
| 465 | static size_t push_pipe(struct iov_iter *i, size_t size, |
| 466 | int *idxp, size_t *offp) |
| 467 | { |
| 468 | struct pipe_inode_info *pipe = i->pipe; |
| 469 | size_t off; |
| 470 | int idx; |
| 471 | ssize_t left; |
| 472 | |
| 473 | if (unlikely(size > i->count)) |
| 474 | size = i->count; |
| 475 | if (unlikely(!size)) |
| 476 | return 0; |
| 477 | |
| 478 | left = size; |
| 479 | data_start(i, &idx, &off); |
| 480 | *idxp = idx; |
| 481 | *offp = off; |
| 482 | if (off) { |
| 483 | left -= PAGE_SIZE - off; |
| 484 | if (left <= 0) { |
| 485 | pipe->bufs[idx].len += size; |
| 486 | return size; |
| 487 | } |
| 488 | pipe->bufs[idx].len = PAGE_SIZE; |
| 489 | idx = next_idx(idx, pipe); |
| 490 | } |
| 491 | while (idx != pipe->curbuf || !pipe->nrbufs) { |
| 492 | struct page *page = alloc_page(GFP_USER); |
| 493 | if (!page) |
| 494 | break; |
| 495 | pipe->nrbufs++; |
| 496 | pipe->bufs[idx].ops = &default_pipe_buf_ops; |
| 497 | pipe->bufs[idx].page = page; |
| 498 | pipe->bufs[idx].offset = 0; |
| 499 | if (left <= PAGE_SIZE) { |
| 500 | pipe->bufs[idx].len = left; |
| 501 | return size; |
| 502 | } |
| 503 | pipe->bufs[idx].len = PAGE_SIZE; |
| 504 | left -= PAGE_SIZE; |
| 505 | idx = next_idx(idx, pipe); |
| 506 | } |
| 507 | return size - left; |
| 508 | } |
| 509 | |
| 510 | static size_t copy_pipe_to_iter(const void *addr, size_t bytes, |
| 511 | struct iov_iter *i) |
| 512 | { |
| 513 | struct pipe_inode_info *pipe = i->pipe; |
| 514 | size_t n, off; |
| 515 | int idx; |
| 516 | |
| 517 | if (!sanity(i)) |
| 518 | return 0; |
| 519 | |
| 520 | bytes = n = push_pipe(i, bytes, &idx, &off); |
| 521 | if (unlikely(!n)) |
| 522 | return 0; |
| 523 | for ( ; n; idx = next_idx(idx, pipe), off = 0) { |
| 524 | size_t chunk = min_t(size_t, n, PAGE_SIZE - off); |
| 525 | memcpy_to_page(pipe->bufs[idx].page, off, addr, chunk); |
| 526 | i->idx = idx; |
| 527 | i->iov_offset = off + chunk; |
| 528 | n -= chunk; |
| 529 | addr += chunk; |
| 530 | } |
| 531 | i->count -= bytes; |
| 532 | return bytes; |
| 533 | } |
| 534 | |
Al Viro | 36f7a8a | 2015-12-06 16:49:22 -0500 | [diff] [blame] | 535 | size_t copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i) |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 536 | { |
Al Viro | 36f7a8a | 2015-12-06 16:49:22 -0500 | [diff] [blame] | 537 | const char *from = addr; |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 538 | if (unlikely(i->type & ITER_PIPE)) |
| 539 | return copy_pipe_to_iter(addr, bytes, i); |
Al Viro | 3d4d3e4 | 2014-11-27 14:28:06 -0500 | [diff] [blame] | 540 | iterate_and_advance(i, bytes, v, |
| 541 | __copy_to_user(v.iov_base, (from += v.iov_len) - v.iov_len, |
| 542 | v.iov_len), |
| 543 | memcpy_to_page(v.bv_page, v.bv_offset, |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 544 | (from += v.bv_len) - v.bv_len, v.bv_len), |
| 545 | memcpy(v.iov_base, (from += v.iov_len) - v.iov_len, v.iov_len) |
Al Viro | 3d4d3e4 | 2014-11-27 14:28:06 -0500 | [diff] [blame] | 546 | ) |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 547 | |
Al Viro | 3d4d3e4 | 2014-11-27 14:28:06 -0500 | [diff] [blame] | 548 | return bytes; |
Matthew Wilcox | c35e024 | 2014-08-01 09:27:22 -0400 | [diff] [blame] | 549 | } |
| 550 | EXPORT_SYMBOL(copy_to_iter); |
| 551 | |
| 552 | size_t copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) |
| 553 | { |
Al Viro | 0dbca9a | 2014-11-27 14:26:43 -0500 | [diff] [blame] | 554 | char *to = addr; |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 555 | if (unlikely(i->type & ITER_PIPE)) { |
| 556 | WARN_ON(1); |
| 557 | return 0; |
| 558 | } |
Al Viro | 0dbca9a | 2014-11-27 14:26:43 -0500 | [diff] [blame] | 559 | iterate_and_advance(i, bytes, v, |
| 560 | __copy_from_user((to += v.iov_len) - v.iov_len, v.iov_base, |
| 561 | v.iov_len), |
| 562 | memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 563 | v.bv_offset, v.bv_len), |
| 564 | memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) |
Al Viro | 0dbca9a | 2014-11-27 14:26:43 -0500 | [diff] [blame] | 565 | ) |
| 566 | |
| 567 | return bytes; |
Matthew Wilcox | c35e024 | 2014-08-01 09:27:22 -0400 | [diff] [blame] | 568 | } |
| 569 | EXPORT_SYMBOL(copy_from_iter); |
| 570 | |
Al Viro | aa58309 | 2014-11-27 20:27:08 -0500 | [diff] [blame] | 571 | size_t copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i) |
| 572 | { |
| 573 | char *to = addr; |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 574 | if (unlikely(i->type & ITER_PIPE)) { |
| 575 | WARN_ON(1); |
| 576 | return 0; |
| 577 | } |
Al Viro | aa58309 | 2014-11-27 20:27:08 -0500 | [diff] [blame] | 578 | iterate_and_advance(i, bytes, v, |
| 579 | __copy_from_user_nocache((to += v.iov_len) - v.iov_len, |
| 580 | v.iov_base, v.iov_len), |
| 581 | memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, |
| 582 | v.bv_offset, v.bv_len), |
| 583 | memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) |
| 584 | ) |
| 585 | |
| 586 | return bytes; |
| 587 | } |
| 588 | EXPORT_SYMBOL(copy_from_iter_nocache); |
| 589 | |
Al Viro | d271524 | 2014-11-27 14:22:37 -0500 | [diff] [blame] | 590 | size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, |
| 591 | struct iov_iter *i) |
| 592 | { |
| 593 | if (i->type & (ITER_BVEC|ITER_KVEC)) { |
| 594 | void *kaddr = kmap_atomic(page); |
| 595 | size_t wanted = copy_to_iter(kaddr + offset, bytes, i); |
| 596 | kunmap_atomic(kaddr); |
| 597 | return wanted; |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 598 | } else if (likely(!(i->type & ITER_PIPE))) |
Al Viro | d271524 | 2014-11-27 14:22:37 -0500 | [diff] [blame] | 599 | return copy_page_to_iter_iovec(page, offset, bytes, i); |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 600 | else |
| 601 | return copy_page_to_iter_pipe(page, offset, bytes, i); |
Al Viro | d271524 | 2014-11-27 14:22:37 -0500 | [diff] [blame] | 602 | } |
| 603 | EXPORT_SYMBOL(copy_page_to_iter); |
| 604 | |
| 605 | size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, |
| 606 | struct iov_iter *i) |
| 607 | { |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 608 | if (unlikely(i->type & ITER_PIPE)) { |
| 609 | WARN_ON(1); |
| 610 | return 0; |
| 611 | } |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 612 | if (i->type & (ITER_BVEC|ITER_KVEC)) { |
Al Viro | d271524 | 2014-11-27 14:22:37 -0500 | [diff] [blame] | 613 | void *kaddr = kmap_atomic(page); |
| 614 | size_t wanted = copy_from_iter(kaddr + offset, bytes, i); |
| 615 | kunmap_atomic(kaddr); |
| 616 | return wanted; |
| 617 | } else |
| 618 | return copy_page_from_iter_iovec(page, offset, bytes, i); |
| 619 | } |
| 620 | EXPORT_SYMBOL(copy_page_from_iter); |
| 621 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 622 | static size_t pipe_zero(size_t bytes, struct iov_iter *i) |
| 623 | { |
| 624 | struct pipe_inode_info *pipe = i->pipe; |
| 625 | size_t n, off; |
| 626 | int idx; |
| 627 | |
| 628 | if (!sanity(i)) |
| 629 | return 0; |
| 630 | |
| 631 | bytes = n = push_pipe(i, bytes, &idx, &off); |
| 632 | if (unlikely(!n)) |
| 633 | return 0; |
| 634 | |
| 635 | for ( ; n; idx = next_idx(idx, pipe), off = 0) { |
| 636 | size_t chunk = min_t(size_t, n, PAGE_SIZE - off); |
| 637 | memzero_page(pipe->bufs[idx].page, off, chunk); |
| 638 | i->idx = idx; |
| 639 | i->iov_offset = off + chunk; |
| 640 | n -= chunk; |
| 641 | } |
| 642 | i->count -= bytes; |
| 643 | return bytes; |
| 644 | } |
| 645 | |
Matthew Wilcox | c35e024 | 2014-08-01 09:27:22 -0400 | [diff] [blame] | 646 | size_t iov_iter_zero(size_t bytes, struct iov_iter *i) |
| 647 | { |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 648 | if (unlikely(i->type & ITER_PIPE)) |
| 649 | return pipe_zero(bytes, i); |
Al Viro | 8442fa4 | 2014-11-27 14:18:54 -0500 | [diff] [blame] | 650 | iterate_and_advance(i, bytes, v, |
| 651 | __clear_user(v.iov_base, v.iov_len), |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 652 | memzero_page(v.bv_page, v.bv_offset, v.bv_len), |
| 653 | memset(v.iov_base, 0, v.iov_len) |
Al Viro | 8442fa4 | 2014-11-27 14:18:54 -0500 | [diff] [blame] | 654 | ) |
| 655 | |
| 656 | return bytes; |
Matthew Wilcox | c35e024 | 2014-08-01 09:27:22 -0400 | [diff] [blame] | 657 | } |
| 658 | EXPORT_SYMBOL(iov_iter_zero); |
| 659 | |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 660 | size_t iov_iter_copy_from_user_atomic(struct page *page, |
| 661 | struct iov_iter *i, unsigned long offset, size_t bytes) |
| 662 | { |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 663 | char *kaddr = kmap_atomic(page), *p = kaddr + offset; |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 664 | if (unlikely(i->type & ITER_PIPE)) { |
| 665 | kunmap_atomic(kaddr); |
| 666 | WARN_ON(1); |
| 667 | return 0; |
| 668 | } |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 669 | iterate_all_kinds(i, bytes, v, |
| 670 | __copy_from_user_inatomic((p += v.iov_len) - v.iov_len, |
| 671 | v.iov_base, v.iov_len), |
| 672 | memcpy_from_page((p += v.bv_len) - v.bv_len, v.bv_page, |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 673 | v.bv_offset, v.bv_len), |
| 674 | memcpy((p += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 675 | ) |
| 676 | kunmap_atomic(kaddr); |
| 677 | return bytes; |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 678 | } |
| 679 | EXPORT_SYMBOL(iov_iter_copy_from_user_atomic); |
| 680 | |
Al Viro | d06367a | 2017-01-14 19:33:08 -0500 | [diff] [blame] | 681 | static inline void pipe_truncate(struct iov_iter *i) |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 682 | { |
| 683 | struct pipe_inode_info *pipe = i->pipe; |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 684 | if (pipe->nrbufs) { |
Al Viro | d06367a | 2017-01-14 19:33:08 -0500 | [diff] [blame] | 685 | size_t off = i->iov_offset; |
| 686 | int idx = i->idx; |
| 687 | int nrbufs = (idx - pipe->curbuf) & (pipe->buffers - 1); |
| 688 | if (off) { |
| 689 | pipe->bufs[idx].len = off - pipe->bufs[idx].offset; |
| 690 | idx = next_idx(idx, pipe); |
| 691 | nrbufs++; |
| 692 | } |
| 693 | while (pipe->nrbufs > nrbufs) { |
Miklos Szeredi | a779638 | 2016-09-27 10:45:12 +0200 | [diff] [blame] | 694 | pipe_buf_release(pipe, &pipe->bufs[idx]); |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 695 | idx = next_idx(idx, pipe); |
| 696 | pipe->nrbufs--; |
| 697 | } |
| 698 | } |
Al Viro | d06367a | 2017-01-14 19:33:08 -0500 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | static void pipe_advance(struct iov_iter *i, size_t size) |
| 702 | { |
| 703 | struct pipe_inode_info *pipe = i->pipe; |
| 704 | if (unlikely(i->count < size)) |
| 705 | size = i->count; |
| 706 | if (size) { |
| 707 | struct pipe_buffer *buf; |
| 708 | size_t off = i->iov_offset, left = size; |
| 709 | int idx = i->idx; |
| 710 | if (off) /* make it relative to the beginning of buffer */ |
| 711 | left += off - pipe->bufs[idx].offset; |
| 712 | while (1) { |
| 713 | buf = &pipe->bufs[idx]; |
| 714 | if (left <= buf->len) |
| 715 | break; |
| 716 | left -= buf->len; |
| 717 | idx = next_idx(idx, pipe); |
| 718 | } |
| 719 | i->idx = idx; |
| 720 | i->iov_offset = buf->offset + left; |
| 721 | } |
| 722 | i->count -= size; |
| 723 | /* ... and discard everything past that point */ |
| 724 | pipe_truncate(i); |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 725 | } |
| 726 | |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 727 | void iov_iter_advance(struct iov_iter *i, size_t size) |
| 728 | { |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 729 | if (unlikely(i->type & ITER_PIPE)) { |
| 730 | pipe_advance(i, size); |
| 731 | return; |
| 732 | } |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 733 | iterate_and_advance(i, size, v, 0, 0, 0) |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 734 | } |
| 735 | EXPORT_SYMBOL(iov_iter_advance); |
| 736 | |
| 737 | /* |
| 738 | * Return the count of just the current iov_iter segment. |
| 739 | */ |
| 740 | size_t iov_iter_single_seg_count(const struct iov_iter *i) |
| 741 | { |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 742 | if (unlikely(i->type & ITER_PIPE)) |
| 743 | return i->count; // it is a silly place, anyway |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 744 | if (i->nr_segs == 1) |
| 745 | return i->count; |
| 746 | else if (i->type & ITER_BVEC) |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 747 | return min(i->count, i->bvec->bv_len - i->iov_offset); |
Paul Mackerras | ad0eab9 | 2014-11-13 20:15:23 +1100 | [diff] [blame] | 748 | else |
| 749 | return min(i->count, i->iov->iov_len - i->iov_offset); |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 750 | } |
| 751 | EXPORT_SYMBOL(iov_iter_single_seg_count); |
| 752 | |
Al Viro | abb78f8 | 2014-11-24 14:46:11 -0500 | [diff] [blame] | 753 | void iov_iter_kvec(struct iov_iter *i, int direction, |
Al Viro | 05afcb7 | 2015-01-23 01:08:07 -0500 | [diff] [blame] | 754 | const struct kvec *kvec, unsigned long nr_segs, |
Al Viro | abb78f8 | 2014-11-24 14:46:11 -0500 | [diff] [blame] | 755 | size_t count) |
| 756 | { |
| 757 | BUG_ON(!(direction & ITER_KVEC)); |
| 758 | i->type = direction; |
Al Viro | 05afcb7 | 2015-01-23 01:08:07 -0500 | [diff] [blame] | 759 | i->kvec = kvec; |
Al Viro | abb78f8 | 2014-11-24 14:46:11 -0500 | [diff] [blame] | 760 | i->nr_segs = nr_segs; |
| 761 | i->iov_offset = 0; |
| 762 | i->count = count; |
| 763 | } |
| 764 | EXPORT_SYMBOL(iov_iter_kvec); |
| 765 | |
Al Viro | 05afcb7 | 2015-01-23 01:08:07 -0500 | [diff] [blame] | 766 | void iov_iter_bvec(struct iov_iter *i, int direction, |
| 767 | const struct bio_vec *bvec, unsigned long nr_segs, |
| 768 | size_t count) |
| 769 | { |
| 770 | BUG_ON(!(direction & ITER_BVEC)); |
| 771 | i->type = direction; |
| 772 | i->bvec = bvec; |
| 773 | i->nr_segs = nr_segs; |
| 774 | i->iov_offset = 0; |
| 775 | i->count = count; |
| 776 | } |
| 777 | EXPORT_SYMBOL(iov_iter_bvec); |
| 778 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 779 | void iov_iter_pipe(struct iov_iter *i, int direction, |
| 780 | struct pipe_inode_info *pipe, |
| 781 | size_t count) |
| 782 | { |
| 783 | BUG_ON(direction != ITER_PIPE); |
Al Viro | d06367a | 2017-01-14 19:33:08 -0500 | [diff] [blame] | 784 | WARN_ON(pipe->nrbufs == pipe->buffers); |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 785 | i->type = direction; |
| 786 | i->pipe = pipe; |
| 787 | i->idx = (pipe->curbuf + pipe->nrbufs) & (pipe->buffers - 1); |
| 788 | i->iov_offset = 0; |
| 789 | i->count = count; |
| 790 | } |
| 791 | EXPORT_SYMBOL(iov_iter_pipe); |
| 792 | |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 793 | unsigned long iov_iter_alignment(const struct iov_iter *i) |
| 794 | { |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 795 | unsigned long res = 0; |
| 796 | size_t size = i->count; |
| 797 | |
| 798 | if (!size) |
| 799 | return 0; |
| 800 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 801 | if (unlikely(i->type & ITER_PIPE)) { |
| 802 | if (i->iov_offset && allocated(&i->pipe->bufs[i->idx])) |
| 803 | return size | i->iov_offset; |
| 804 | return size; |
| 805 | } |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 806 | iterate_all_kinds(i, size, v, |
| 807 | (res |= (unsigned long)v.iov_base | v.iov_len, 0), |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 808 | res |= v.bv_offset | v.bv_len, |
| 809 | res |= (unsigned long)v.iov_base | v.iov_len |
Al Viro | 04a3116 | 2014-11-27 13:51:41 -0500 | [diff] [blame] | 810 | ) |
| 811 | return res; |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 812 | } |
| 813 | EXPORT_SYMBOL(iov_iter_alignment); |
| 814 | |
Al Viro | 357f435 | 2016-04-08 19:05:19 -0400 | [diff] [blame] | 815 | unsigned long iov_iter_gap_alignment(const struct iov_iter *i) |
| 816 | { |
| 817 | unsigned long res = 0; |
| 818 | size_t size = i->count; |
| 819 | if (!size) |
| 820 | return 0; |
| 821 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 822 | if (unlikely(i->type & ITER_PIPE)) { |
| 823 | WARN_ON(1); |
| 824 | return ~0U; |
| 825 | } |
| 826 | |
Al Viro | 357f435 | 2016-04-08 19:05:19 -0400 | [diff] [blame] | 827 | iterate_all_kinds(i, size, v, |
| 828 | (res |= (!res ? 0 : (unsigned long)v.iov_base) | |
| 829 | (size != v.iov_len ? size : 0), 0), |
| 830 | (res |= (!res ? 0 : (unsigned long)v.bv_offset) | |
| 831 | (size != v.bv_len ? size : 0)), |
| 832 | (res |= (!res ? 0 : (unsigned long)v.iov_base) | |
| 833 | (size != v.iov_len ? size : 0)) |
| 834 | ); |
| 835 | return res; |
| 836 | } |
| 837 | EXPORT_SYMBOL(iov_iter_gap_alignment); |
| 838 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 839 | static inline size_t __pipe_get_pages(struct iov_iter *i, |
| 840 | size_t maxsize, |
| 841 | struct page **pages, |
| 842 | int idx, |
| 843 | size_t *start) |
| 844 | { |
| 845 | struct pipe_inode_info *pipe = i->pipe; |
Al Viro | 1689c73 | 2016-10-11 18:21:14 +0100 | [diff] [blame] | 846 | ssize_t n = push_pipe(i, maxsize, &idx, start); |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 847 | if (!n) |
| 848 | return -EFAULT; |
| 849 | |
| 850 | maxsize = n; |
| 851 | n += *start; |
Al Viro | 1689c73 | 2016-10-11 18:21:14 +0100 | [diff] [blame] | 852 | while (n > 0) { |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 853 | get_page(*pages++ = pipe->bufs[idx].page); |
| 854 | idx = next_idx(idx, pipe); |
| 855 | n -= PAGE_SIZE; |
| 856 | } |
| 857 | |
| 858 | return maxsize; |
| 859 | } |
| 860 | |
| 861 | static ssize_t pipe_get_pages(struct iov_iter *i, |
| 862 | struct page **pages, size_t maxsize, unsigned maxpages, |
| 863 | size_t *start) |
| 864 | { |
| 865 | unsigned npages; |
| 866 | size_t capacity; |
| 867 | int idx; |
| 868 | |
| 869 | if (!sanity(i)) |
| 870 | return -EFAULT; |
| 871 | |
| 872 | data_start(i, &idx, start); |
| 873 | /* some of this one + all after this one */ |
| 874 | npages = ((i->pipe->curbuf - idx - 1) & (i->pipe->buffers - 1)) + 1; |
| 875 | capacity = min(npages,maxpages) * PAGE_SIZE - *start; |
| 876 | |
| 877 | return __pipe_get_pages(i, min(maxsize, capacity), pages, idx, start); |
| 878 | } |
| 879 | |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 880 | ssize_t iov_iter_get_pages(struct iov_iter *i, |
Miklos Szeredi | 2c80929 | 2014-09-24 17:09:11 +0200 | [diff] [blame] | 881 | struct page **pages, size_t maxsize, unsigned maxpages, |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 882 | size_t *start) |
| 883 | { |
Al Viro | e5393fa | 2014-11-27 14:12:09 -0500 | [diff] [blame] | 884 | if (maxsize > i->count) |
| 885 | maxsize = i->count; |
| 886 | |
| 887 | if (!maxsize) |
| 888 | return 0; |
| 889 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 890 | if (unlikely(i->type & ITER_PIPE)) |
| 891 | return pipe_get_pages(i, pages, maxsize, maxpages, start); |
Al Viro | e5393fa | 2014-11-27 14:12:09 -0500 | [diff] [blame] | 892 | iterate_all_kinds(i, maxsize, v, ({ |
| 893 | unsigned long addr = (unsigned long)v.iov_base; |
| 894 | size_t len = v.iov_len + (*start = addr & (PAGE_SIZE - 1)); |
| 895 | int n; |
| 896 | int res; |
| 897 | |
| 898 | if (len > maxpages * PAGE_SIZE) |
| 899 | len = maxpages * PAGE_SIZE; |
| 900 | addr &= ~(PAGE_SIZE - 1); |
| 901 | n = DIV_ROUND_UP(len, PAGE_SIZE); |
| 902 | res = get_user_pages_fast(addr, n, (i->type & WRITE) != WRITE, pages); |
| 903 | if (unlikely(res < 0)) |
| 904 | return res; |
| 905 | return (res == n ? len : res * PAGE_SIZE) - *start; |
| 906 | 0;}),({ |
| 907 | /* can't be more than PAGE_SIZE */ |
| 908 | *start = v.bv_offset; |
| 909 | get_page(*pages = v.bv_page); |
| 910 | return v.bv_len; |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 911 | }),({ |
| 912 | return -EFAULT; |
Al Viro | e5393fa | 2014-11-27 14:12:09 -0500 | [diff] [blame] | 913 | }) |
| 914 | ) |
| 915 | return 0; |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 916 | } |
| 917 | EXPORT_SYMBOL(iov_iter_get_pages); |
| 918 | |
Al Viro | 1b17f1f | 2014-11-27 14:14:31 -0500 | [diff] [blame] | 919 | static struct page **get_pages_array(size_t n) |
| 920 | { |
| 921 | struct page **p = kmalloc(n * sizeof(struct page *), GFP_KERNEL); |
| 922 | if (!p) |
| 923 | p = vmalloc(n * sizeof(struct page *)); |
| 924 | return p; |
| 925 | } |
| 926 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 927 | static ssize_t pipe_get_pages_alloc(struct iov_iter *i, |
| 928 | struct page ***pages, size_t maxsize, |
| 929 | size_t *start) |
| 930 | { |
| 931 | struct page **p; |
| 932 | size_t n; |
| 933 | int idx; |
| 934 | int npages; |
| 935 | |
| 936 | if (!sanity(i)) |
| 937 | return -EFAULT; |
| 938 | |
| 939 | data_start(i, &idx, start); |
| 940 | /* some of this one + all after this one */ |
| 941 | npages = ((i->pipe->curbuf - idx - 1) & (i->pipe->buffers - 1)) + 1; |
| 942 | n = npages * PAGE_SIZE - *start; |
| 943 | if (maxsize > n) |
| 944 | maxsize = n; |
| 945 | else |
| 946 | npages = DIV_ROUND_UP(maxsize + *start, PAGE_SIZE); |
| 947 | p = get_pages_array(npages); |
| 948 | if (!p) |
| 949 | return -ENOMEM; |
| 950 | n = __pipe_get_pages(i, maxsize, p, idx, start); |
| 951 | if (n > 0) |
| 952 | *pages = p; |
| 953 | else |
| 954 | kvfree(p); |
| 955 | return n; |
| 956 | } |
| 957 | |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 958 | ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, |
| 959 | struct page ***pages, size_t maxsize, |
| 960 | size_t *start) |
| 961 | { |
Al Viro | 1b17f1f | 2014-11-27 14:14:31 -0500 | [diff] [blame] | 962 | struct page **p; |
| 963 | |
| 964 | if (maxsize > i->count) |
| 965 | maxsize = i->count; |
| 966 | |
| 967 | if (!maxsize) |
| 968 | return 0; |
| 969 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 970 | if (unlikely(i->type & ITER_PIPE)) |
| 971 | return pipe_get_pages_alloc(i, pages, maxsize, start); |
Al Viro | 1b17f1f | 2014-11-27 14:14:31 -0500 | [diff] [blame] | 972 | iterate_all_kinds(i, maxsize, v, ({ |
| 973 | unsigned long addr = (unsigned long)v.iov_base; |
| 974 | size_t len = v.iov_len + (*start = addr & (PAGE_SIZE - 1)); |
| 975 | int n; |
| 976 | int res; |
| 977 | |
| 978 | addr &= ~(PAGE_SIZE - 1); |
| 979 | n = DIV_ROUND_UP(len, PAGE_SIZE); |
| 980 | p = get_pages_array(n); |
| 981 | if (!p) |
| 982 | return -ENOMEM; |
| 983 | res = get_user_pages_fast(addr, n, (i->type & WRITE) != WRITE, p); |
| 984 | if (unlikely(res < 0)) { |
| 985 | kvfree(p); |
| 986 | return res; |
| 987 | } |
| 988 | *pages = p; |
| 989 | return (res == n ? len : res * PAGE_SIZE) - *start; |
| 990 | 0;}),({ |
| 991 | /* can't be more than PAGE_SIZE */ |
| 992 | *start = v.bv_offset; |
| 993 | *pages = p = get_pages_array(1); |
| 994 | if (!p) |
| 995 | return -ENOMEM; |
| 996 | get_page(*p = v.bv_page); |
| 997 | return v.bv_len; |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 998 | }),({ |
| 999 | return -EFAULT; |
Al Viro | 1b17f1f | 2014-11-27 14:14:31 -0500 | [diff] [blame] | 1000 | }) |
| 1001 | ) |
| 1002 | return 0; |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 1003 | } |
| 1004 | EXPORT_SYMBOL(iov_iter_get_pages_alloc); |
| 1005 | |
Al Viro | a604ec7 | 2014-11-24 01:08:00 -0500 | [diff] [blame] | 1006 | size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, |
| 1007 | struct iov_iter *i) |
| 1008 | { |
| 1009 | char *to = addr; |
| 1010 | __wsum sum, next; |
| 1011 | size_t off = 0; |
Al Viro | a604ec7 | 2014-11-24 01:08:00 -0500 | [diff] [blame] | 1012 | sum = *csum; |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 1013 | if (unlikely(i->type & ITER_PIPE)) { |
| 1014 | WARN_ON(1); |
| 1015 | return 0; |
| 1016 | } |
Al Viro | a604ec7 | 2014-11-24 01:08:00 -0500 | [diff] [blame] | 1017 | iterate_and_advance(i, bytes, v, ({ |
| 1018 | int err = 0; |
| 1019 | next = csum_and_copy_from_user(v.iov_base, |
| 1020 | (to += v.iov_len) - v.iov_len, |
| 1021 | v.iov_len, 0, &err); |
| 1022 | if (!err) { |
| 1023 | sum = csum_block_add(sum, next, off); |
| 1024 | off += v.iov_len; |
| 1025 | } |
| 1026 | err ? v.iov_len : 0; |
| 1027 | }), ({ |
| 1028 | char *p = kmap_atomic(v.bv_page); |
| 1029 | next = csum_partial_copy_nocheck(p + v.bv_offset, |
| 1030 | (to += v.bv_len) - v.bv_len, |
| 1031 | v.bv_len, 0); |
| 1032 | kunmap_atomic(p); |
| 1033 | sum = csum_block_add(sum, next, off); |
| 1034 | off += v.bv_len; |
| 1035 | }),({ |
| 1036 | next = csum_partial_copy_nocheck(v.iov_base, |
| 1037 | (to += v.iov_len) - v.iov_len, |
| 1038 | v.iov_len, 0); |
| 1039 | sum = csum_block_add(sum, next, off); |
| 1040 | off += v.iov_len; |
| 1041 | }) |
| 1042 | ) |
| 1043 | *csum = sum; |
| 1044 | return bytes; |
| 1045 | } |
| 1046 | EXPORT_SYMBOL(csum_and_copy_from_iter); |
| 1047 | |
Al Viro | 36f7a8a | 2015-12-06 16:49:22 -0500 | [diff] [blame] | 1048 | size_t csum_and_copy_to_iter(const void *addr, size_t bytes, __wsum *csum, |
Al Viro | a604ec7 | 2014-11-24 01:08:00 -0500 | [diff] [blame] | 1049 | struct iov_iter *i) |
| 1050 | { |
Al Viro | 36f7a8a | 2015-12-06 16:49:22 -0500 | [diff] [blame] | 1051 | const char *from = addr; |
Al Viro | a604ec7 | 2014-11-24 01:08:00 -0500 | [diff] [blame] | 1052 | __wsum sum, next; |
| 1053 | size_t off = 0; |
Al Viro | a604ec7 | 2014-11-24 01:08:00 -0500 | [diff] [blame] | 1054 | sum = *csum; |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 1055 | if (unlikely(i->type & ITER_PIPE)) { |
| 1056 | WARN_ON(1); /* for now */ |
| 1057 | return 0; |
| 1058 | } |
Al Viro | a604ec7 | 2014-11-24 01:08:00 -0500 | [diff] [blame] | 1059 | iterate_and_advance(i, bytes, v, ({ |
| 1060 | int err = 0; |
| 1061 | next = csum_and_copy_to_user((from += v.iov_len) - v.iov_len, |
| 1062 | v.iov_base, |
| 1063 | v.iov_len, 0, &err); |
| 1064 | if (!err) { |
| 1065 | sum = csum_block_add(sum, next, off); |
| 1066 | off += v.iov_len; |
| 1067 | } |
| 1068 | err ? v.iov_len : 0; |
| 1069 | }), ({ |
| 1070 | char *p = kmap_atomic(v.bv_page); |
| 1071 | next = csum_partial_copy_nocheck((from += v.bv_len) - v.bv_len, |
| 1072 | p + v.bv_offset, |
| 1073 | v.bv_len, 0); |
| 1074 | kunmap_atomic(p); |
| 1075 | sum = csum_block_add(sum, next, off); |
| 1076 | off += v.bv_len; |
| 1077 | }),({ |
| 1078 | next = csum_partial_copy_nocheck((from += v.iov_len) - v.iov_len, |
| 1079 | v.iov_base, |
| 1080 | v.iov_len, 0); |
| 1081 | sum = csum_block_add(sum, next, off); |
| 1082 | off += v.iov_len; |
| 1083 | }) |
| 1084 | ) |
| 1085 | *csum = sum; |
| 1086 | return bytes; |
| 1087 | } |
| 1088 | EXPORT_SYMBOL(csum_and_copy_to_iter); |
| 1089 | |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 1090 | int iov_iter_npages(const struct iov_iter *i, int maxpages) |
| 1091 | { |
Al Viro | e0f2dc4 | 2014-11-27 14:09:46 -0500 | [diff] [blame] | 1092 | size_t size = i->count; |
| 1093 | int npages = 0; |
| 1094 | |
| 1095 | if (!size) |
| 1096 | return 0; |
| 1097 | |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 1098 | if (unlikely(i->type & ITER_PIPE)) { |
| 1099 | struct pipe_inode_info *pipe = i->pipe; |
| 1100 | size_t off; |
| 1101 | int idx; |
| 1102 | |
| 1103 | if (!sanity(i)) |
| 1104 | return 0; |
| 1105 | |
| 1106 | data_start(i, &idx, &off); |
| 1107 | /* some of this one + all after this one */ |
| 1108 | npages = ((pipe->curbuf - idx - 1) & (pipe->buffers - 1)) + 1; |
| 1109 | if (npages >= maxpages) |
| 1110 | return maxpages; |
| 1111 | } else iterate_all_kinds(i, size, v, ({ |
Al Viro | e0f2dc4 | 2014-11-27 14:09:46 -0500 | [diff] [blame] | 1112 | unsigned long p = (unsigned long)v.iov_base; |
| 1113 | npages += DIV_ROUND_UP(p + v.iov_len, PAGE_SIZE) |
| 1114 | - p / PAGE_SIZE; |
| 1115 | if (npages >= maxpages) |
| 1116 | return maxpages; |
| 1117 | 0;}),({ |
| 1118 | npages++; |
| 1119 | if (npages >= maxpages) |
| 1120 | return maxpages; |
Al Viro | a280455 | 2014-11-27 14:48:42 -0500 | [diff] [blame] | 1121 | }),({ |
| 1122 | unsigned long p = (unsigned long)v.iov_base; |
| 1123 | npages += DIV_ROUND_UP(p + v.iov_len, PAGE_SIZE) |
| 1124 | - p / PAGE_SIZE; |
| 1125 | if (npages >= maxpages) |
| 1126 | return maxpages; |
Al Viro | e0f2dc4 | 2014-11-27 14:09:46 -0500 | [diff] [blame] | 1127 | }) |
| 1128 | ) |
| 1129 | return npages; |
Al Viro | 62a8067 | 2014-04-04 23:12:29 -0400 | [diff] [blame] | 1130 | } |
Al Viro | f67da30 | 2014-03-19 01:16:16 -0400 | [diff] [blame] | 1131 | EXPORT_SYMBOL(iov_iter_npages); |
Al Viro | 4b8164b | 2015-01-31 20:08:47 -0500 | [diff] [blame] | 1132 | |
| 1133 | const void *dup_iter(struct iov_iter *new, struct iov_iter *old, gfp_t flags) |
| 1134 | { |
| 1135 | *new = *old; |
Al Viro | 241699c | 2016-09-22 16:33:12 -0400 | [diff] [blame] | 1136 | if (unlikely(new->type & ITER_PIPE)) { |
| 1137 | WARN_ON(1); |
| 1138 | return NULL; |
| 1139 | } |
Al Viro | 4b8164b | 2015-01-31 20:08:47 -0500 | [diff] [blame] | 1140 | if (new->type & ITER_BVEC) |
| 1141 | return new->bvec = kmemdup(new->bvec, |
| 1142 | new->nr_segs * sizeof(struct bio_vec), |
| 1143 | flags); |
| 1144 | else |
| 1145 | /* iovec and kvec have identical layout */ |
| 1146 | return new->iov = kmemdup(new->iov, |
| 1147 | new->nr_segs * sizeof(struct iovec), |
| 1148 | flags); |
| 1149 | } |
| 1150 | EXPORT_SYMBOL(dup_iter); |
Al Viro | bc917be | 2015-03-21 17:45:43 -0400 | [diff] [blame] | 1151 | |
Vegard Nossum | ffecee4 | 2016-10-08 11:18:07 +0200 | [diff] [blame] | 1152 | /** |
| 1153 | * import_iovec() - Copy an array of &struct iovec from userspace |
| 1154 | * into the kernel, check that it is valid, and initialize a new |
| 1155 | * &struct iov_iter iterator to access it. |
| 1156 | * |
| 1157 | * @type: One of %READ or %WRITE. |
| 1158 | * @uvector: Pointer to the userspace array. |
| 1159 | * @nr_segs: Number of elements in userspace array. |
| 1160 | * @fast_segs: Number of elements in @iov. |
| 1161 | * @iov: (input and output parameter) Pointer to pointer to (usually small |
| 1162 | * on-stack) kernel array. |
| 1163 | * @i: Pointer to iterator that will be initialized on success. |
| 1164 | * |
| 1165 | * If the array pointed to by *@iov is large enough to hold all @nr_segs, |
| 1166 | * then this function places %NULL in *@iov on return. Otherwise, a new |
| 1167 | * array will be allocated and the result placed in *@iov. This means that |
| 1168 | * the caller may call kfree() on *@iov regardless of whether the small |
| 1169 | * on-stack array was used or not (and regardless of whether this function |
| 1170 | * returns an error or not). |
| 1171 | * |
| 1172 | * Return: 0 on success or negative error code on error. |
| 1173 | */ |
Al Viro | bc917be | 2015-03-21 17:45:43 -0400 | [diff] [blame] | 1174 | int import_iovec(int type, const struct iovec __user * uvector, |
| 1175 | unsigned nr_segs, unsigned fast_segs, |
| 1176 | struct iovec **iov, struct iov_iter *i) |
| 1177 | { |
| 1178 | ssize_t n; |
| 1179 | struct iovec *p; |
| 1180 | n = rw_copy_check_uvector(type, uvector, nr_segs, fast_segs, |
| 1181 | *iov, &p); |
| 1182 | if (n < 0) { |
| 1183 | if (p != *iov) |
| 1184 | kfree(p); |
| 1185 | *iov = NULL; |
| 1186 | return n; |
| 1187 | } |
| 1188 | iov_iter_init(i, type, p, nr_segs, n); |
| 1189 | *iov = p == *iov ? NULL : p; |
| 1190 | return 0; |
| 1191 | } |
| 1192 | EXPORT_SYMBOL(import_iovec); |
| 1193 | |
| 1194 | #ifdef CONFIG_COMPAT |
| 1195 | #include <linux/compat.h> |
| 1196 | |
| 1197 | int compat_import_iovec(int type, const struct compat_iovec __user * uvector, |
| 1198 | unsigned nr_segs, unsigned fast_segs, |
| 1199 | struct iovec **iov, struct iov_iter *i) |
| 1200 | { |
| 1201 | ssize_t n; |
| 1202 | struct iovec *p; |
| 1203 | n = compat_rw_copy_check_uvector(type, uvector, nr_segs, fast_segs, |
| 1204 | *iov, &p); |
| 1205 | if (n < 0) { |
| 1206 | if (p != *iov) |
| 1207 | kfree(p); |
| 1208 | *iov = NULL; |
| 1209 | return n; |
| 1210 | } |
| 1211 | iov_iter_init(i, type, p, nr_segs, n); |
| 1212 | *iov = p == *iov ? NULL : p; |
| 1213 | return 0; |
| 1214 | } |
| 1215 | #endif |
| 1216 | |
| 1217 | int import_single_range(int rw, void __user *buf, size_t len, |
| 1218 | struct iovec *iov, struct iov_iter *i) |
| 1219 | { |
| 1220 | if (len > MAX_RW_COUNT) |
| 1221 | len = MAX_RW_COUNT; |
| 1222 | if (unlikely(!access_ok(!rw, buf, len))) |
| 1223 | return -EFAULT; |
| 1224 | |
| 1225 | iov->iov_base = buf; |
| 1226 | iov->iov_len = len; |
| 1227 | iov_iter_init(i, rw, iov, 1, len); |
| 1228 | return 0; |
| 1229 | } |
Al Viro | e126758 | 2015-12-06 20:38:56 -0500 | [diff] [blame] | 1230 | EXPORT_SYMBOL(import_single_range); |