|
|
|
@ -264,64 +264,46 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in |
|
|
|
|
return rm; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int rds_message_copy_from_user(struct rds_message *rm, struct iovec *first_iov, |
|
|
|
|
size_t total_len) |
|
|
|
|
int rds_message_copy_from_user(struct rds_message *rm, struct iov_iter *from) |
|
|
|
|
{ |
|
|
|
|
unsigned long to_copy; |
|
|
|
|
unsigned long iov_off; |
|
|
|
|
unsigned long sg_off; |
|
|
|
|
struct iovec *iov; |
|
|
|
|
struct scatterlist *sg; |
|
|
|
|
int ret = 0; |
|
|
|
|
|
|
|
|
|
rm->m_inc.i_hdr.h_len = cpu_to_be32(total_len); |
|
|
|
|
rm->m_inc.i_hdr.h_len = cpu_to_be32(iov_iter_count(from)); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* now allocate and copy in the data payload. |
|
|
|
|
*/ |
|
|
|
|
sg = rm->data.op_sg; |
|
|
|
|
iov = first_iov; |
|
|
|
|
iov_off = 0; |
|
|
|
|
sg_off = 0; /* Dear gcc, sg->page will be null from kzalloc. */ |
|
|
|
|
|
|
|
|
|
while (total_len) { |
|
|
|
|
while (iov_iter_count(from)) { |
|
|
|
|
if (!sg_page(sg)) { |
|
|
|
|
ret = rds_page_remainder_alloc(sg, total_len, |
|
|
|
|
ret = rds_page_remainder_alloc(sg, iov_iter_count(from), |
|
|
|
|
GFP_HIGHUSER); |
|
|
|
|
if (ret) |
|
|
|
|
goto out; |
|
|
|
|
return ret; |
|
|
|
|
rm->data.op_nents++; |
|
|
|
|
sg_off = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while (iov_off == iov->iov_len) { |
|
|
|
|
iov_off = 0; |
|
|
|
|
iov++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
to_copy = min(iov->iov_len - iov_off, sg->length - sg_off); |
|
|
|
|
to_copy = min_t(size_t, to_copy, total_len); |
|
|
|
|
|
|
|
|
|
rdsdebug("copying %lu bytes from user iov [%p, %zu] + %lu to " |
|
|
|
|
"sg [%p, %u, %u] + %lu\n", |
|
|
|
|
to_copy, iov->iov_base, iov->iov_len, iov_off, |
|
|
|
|
(void *)sg_page(sg), sg->offset, sg->length, sg_off); |
|
|
|
|
to_copy = min_t(unsigned long, iov_iter_count(from), |
|
|
|
|
sg->length - sg_off); |
|
|
|
|
|
|
|
|
|
ret = rds_page_copy_from_user(sg_page(sg), sg->offset + sg_off, |
|
|
|
|
iov->iov_base + iov_off, |
|
|
|
|
to_copy); |
|
|
|
|
if (ret) |
|
|
|
|
goto out; |
|
|
|
|
rds_stats_add(s_copy_from_user, to_copy); |
|
|
|
|
ret = copy_page_from_iter(sg_page(sg), sg->offset + sg_off, |
|
|
|
|
to_copy, from); |
|
|
|
|
if (ret != to_copy) |
|
|
|
|
return -EFAULT; |
|
|
|
|
|
|
|
|
|
iov_off += to_copy; |
|
|
|
|
total_len -= to_copy; |
|
|
|
|
sg_off += to_copy; |
|
|
|
|
|
|
|
|
|
if (sg_off == sg->length) |
|
|
|
|
sg++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
out: |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|