Skip to content

Commit 083735f

Browse files
author
Al Viro
committed
rds: switch rds_message_copy_from_user() to iov_iter
Signed-off-by: Al Viro <[email protected]>
1 parent c310e72 commit 083735f

File tree

3 files changed

+16
-33
lines changed

3 files changed

+16
-33
lines changed

net/rds/message.c

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -264,64 +264,46 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in
264264
return rm;
265265
}
266266

267-
int rds_message_copy_from_user(struct rds_message *rm, struct iovec *first_iov,
268-
size_t total_len)
267+
int rds_message_copy_from_user(struct rds_message *rm, struct iov_iter *from)
269268
{
270269
unsigned long to_copy;
271-
unsigned long iov_off;
272270
unsigned long sg_off;
273-
struct iovec *iov;
274271
struct scatterlist *sg;
275272
int ret = 0;
276273

277-
rm->m_inc.i_hdr.h_len = cpu_to_be32(total_len);
274+
rm->m_inc.i_hdr.h_len = cpu_to_be32(iov_iter_count(from));
278275

279276
/*
280277
* now allocate and copy in the data payload.
281278
*/
282279
sg = rm->data.op_sg;
283-
iov = first_iov;
284-
iov_off = 0;
285280
sg_off = 0; /* Dear gcc, sg->page will be null from kzalloc. */
286281

287-
while (total_len) {
282+
while (iov_iter_count(from)) {
288283
if (!sg_page(sg)) {
289-
ret = rds_page_remainder_alloc(sg, total_len,
284+
ret = rds_page_remainder_alloc(sg, iov_iter_count(from),
290285
GFP_HIGHUSER);
291286
if (ret)
292-
goto out;
287+
return ret;
293288
rm->data.op_nents++;
294289
sg_off = 0;
295290
}
296291

297-
while (iov_off == iov->iov_len) {
298-
iov_off = 0;
299-
iov++;
300-
}
301-
302-
to_copy = min(iov->iov_len - iov_off, sg->length - sg_off);
303-
to_copy = min_t(size_t, to_copy, total_len);
304-
305-
rdsdebug("copying %lu bytes from user iov [%p, %zu] + %lu to "
306-
"sg [%p, %u, %u] + %lu\n",
307-
to_copy, iov->iov_base, iov->iov_len, iov_off,
308-
(void *)sg_page(sg), sg->offset, sg->length, sg_off);
292+
to_copy = min_t(unsigned long, iov_iter_count(from),
293+
sg->length - sg_off);
309294

310-
ret = rds_page_copy_from_user(sg_page(sg), sg->offset + sg_off,
311-
iov->iov_base + iov_off,
312-
to_copy);
313-
if (ret)
314-
goto out;
295+
rds_stats_add(s_copy_from_user, to_copy);
296+
ret = copy_page_from_iter(sg_page(sg), sg->offset + sg_off,
297+
to_copy, from);
298+
if (ret != to_copy)
299+
return -EFAULT;
315300

316-
iov_off += to_copy;
317-
total_len -= to_copy;
318301
sg_off += to_copy;
319302

320303
if (sg_off == sg->length)
321304
sg++;
322305
}
323306

324-
out:
325307
return ret;
326308
}
327309

net/rds/rds.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,7 @@ rds_conn_connecting(struct rds_connection *conn)
656656
/* message.c */
657657
struct rds_message *rds_message_alloc(unsigned int nents, gfp_t gfp);
658658
struct scatterlist *rds_message_alloc_sgs(struct rds_message *rm, int nents);
659-
int rds_message_copy_from_user(struct rds_message *rm, struct iovec *first_iov,
660-
size_t total_len);
659+
int rds_message_copy_from_user(struct rds_message *rm, struct iov_iter *from);
661660
struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned int total_len);
662661
void rds_message_populate_header(struct rds_header *hdr, __be16 sport,
663662
__be16 dport, u64 seq);

net/rds/send.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,9 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
934934
int queued = 0, allocated_mr = 0;
935935
int nonblock = msg->msg_flags & MSG_DONTWAIT;
936936
long timeo = sock_sndtimeo(sk, nonblock);
937+
struct iov_iter from;
937938

939+
iov_iter_init(&from, WRITE, msg->msg_iov, msg->msg_iovlen, payload_len);
938940
/* Mirror Linux UDP mirror of BSD error message compatibility */
939941
/* XXX: Perhaps MSG_MORE someday */
940942
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,
982984
ret = -ENOMEM;
983985
goto out;
984986
}
985-
ret = rds_message_copy_from_user(rm, msg->msg_iov, payload_len);
987+
ret = rds_message_copy_from_user(rm, &from);
986988
if (ret)
987989
goto out;
988990
}

0 commit comments

Comments
 (0)