mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-17 09:43:59 +08:00
rds: switch rds_message_copy_from_user() to iov_iter
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
c310e72c89
commit
083735f4b0
@ -264,64 +264,46 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in
|
|||||||
return rm;
|
return rm;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rds_message_copy_from_user(struct rds_message *rm, struct iovec *first_iov,
|
int rds_message_copy_from_user(struct rds_message *rm, struct iov_iter *from)
|
||||||
size_t total_len)
|
|
||||||
{
|
{
|
||||||
unsigned long to_copy;
|
unsigned long to_copy;
|
||||||
unsigned long iov_off;
|
|
||||||
unsigned long sg_off;
|
unsigned long sg_off;
|
||||||
struct iovec *iov;
|
|
||||||
struct scatterlist *sg;
|
struct scatterlist *sg;
|
||||||
int ret = 0;
|
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.
|
* now allocate and copy in the data payload.
|
||||||
*/
|
*/
|
||||||
sg = rm->data.op_sg;
|
sg = rm->data.op_sg;
|
||||||
iov = first_iov;
|
|
||||||
iov_off = 0;
|
|
||||||
sg_off = 0; /* Dear gcc, sg->page will be null from kzalloc. */
|
sg_off = 0; /* Dear gcc, sg->page will be null from kzalloc. */
|
||||||
|
|
||||||
while (total_len) {
|
while (iov_iter_count(from)) {
|
||||||
if (!sg_page(sg)) {
|
if (!sg_page(sg)) {
|
||||||
ret = rds_page_remainder_alloc(sg, total_len,
|
ret = rds_page_remainder_alloc(sg, iov_iter_count(from),
|
||||||
GFP_HIGHUSER);
|
GFP_HIGHUSER);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
return ret;
|
||||||
rm->data.op_nents++;
|
rm->data.op_nents++;
|
||||||
sg_off = 0;
|
sg_off = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (iov_off == iov->iov_len) {
|
to_copy = min_t(unsigned long, iov_iter_count(from),
|
||||||
iov_off = 0;
|
sg->length - sg_off);
|
||||||
iov++;
|
|
||||||
}
|
|
||||||
|
|
||||||
to_copy = min(iov->iov_len - iov_off, sg->length - sg_off);
|
rds_stats_add(s_copy_from_user, to_copy);
|
||||||
to_copy = min_t(size_t, to_copy, total_len);
|
ret = copy_page_from_iter(sg_page(sg), sg->offset + sg_off,
|
||||||
|
to_copy, from);
|
||||||
|
if (ret != to_copy)
|
||||||
|
return -EFAULT;
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
ret = rds_page_copy_from_user(sg_page(sg), sg->offset + sg_off,
|
|
||||||
iov->iov_base + iov_off,
|
|
||||||
to_copy);
|
|
||||||
if (ret)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
iov_off += to_copy;
|
|
||||||
total_len -= to_copy;
|
|
||||||
sg_off += to_copy;
|
sg_off += to_copy;
|
||||||
|
|
||||||
if (sg_off == sg->length)
|
if (sg_off == sg->length)
|
||||||
sg++;
|
sg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,8 +656,7 @@ rds_conn_connecting(struct rds_connection *conn)
|
|||||||
/* message.c */
|
/* message.c */
|
||||||
struct rds_message *rds_message_alloc(unsigned int nents, gfp_t gfp);
|
struct rds_message *rds_message_alloc(unsigned int nents, gfp_t gfp);
|
||||||
struct scatterlist *rds_message_alloc_sgs(struct rds_message *rm, int nents);
|
struct scatterlist *rds_message_alloc_sgs(struct rds_message *rm, int nents);
|
||||||
int rds_message_copy_from_user(struct rds_message *rm, struct iovec *first_iov,
|
int rds_message_copy_from_user(struct rds_message *rm, struct iov_iter *from);
|
||||||
size_t total_len);
|
|
||||||
struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned int total_len);
|
struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned int total_len);
|
||||||
void rds_message_populate_header(struct rds_header *hdr, __be16 sport,
|
void rds_message_populate_header(struct rds_header *hdr, __be16 sport,
|
||||||
__be16 dport, u64 seq);
|
__be16 dport, u64 seq);
|
||||||
|
@ -934,7 +934,9 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
|
|||||||
int queued = 0, allocated_mr = 0;
|
int queued = 0, allocated_mr = 0;
|
||||||
int nonblock = msg->msg_flags & MSG_DONTWAIT;
|
int nonblock = msg->msg_flags & MSG_DONTWAIT;
|
||||||
long timeo = sock_sndtimeo(sk, nonblock);
|
long timeo = sock_sndtimeo(sk, nonblock);
|
||||||
|
struct iov_iter from;
|
||||||
|
|
||||||
|
iov_iter_init(&from, WRITE, msg->msg_iov, msg->msg_iovlen, payload_len);
|
||||||
/* Mirror Linux UDP mirror of BSD error message compatibility */
|
/* Mirror Linux UDP mirror of BSD error message compatibility */
|
||||||
/* XXX: Perhaps MSG_MORE someday */
|
/* XXX: Perhaps MSG_MORE someday */
|
||||||
if (msg->msg_flags & ~(MSG_DONTWAIT | MSG_CMSG_COMPAT)) {
|
if (msg->msg_flags & ~(MSG_DONTWAIT | MSG_CMSG_COMPAT)) {
|
||||||
@ -982,7 +984,7 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
|
|||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
ret = rds_message_copy_from_user(rm, msg->msg_iov, payload_len);
|
ret = rds_message_copy_from_user(rm, &from);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user