pvcalls: check return value from copy_from/to_iter
Stefano Stabellini
maintainerPATCH 1/2 pvcalls: check return value from copy_from/to_iter
Check the return value of copy_from_iter in __write_ring and copy_to_iter in __read_ring. Update "len" accordingly.
In the cases where we issue two consecutive copy_from_iter, or two consecutive copy_to_iter, first check return, then goto out if it is not what we expect.
--- drivers/xen/pvcalls-front.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/xen/pvcalls-front.c +18 -12
@@ -456,18 +456,21 @@ static int __write_ring(struct pvcalls_data_intf *intf, masked_cons =pvcalls_mask (cons, array_size);if (masked_prod < masked_cons) { -copy_from_iter (data->out + masked_prod, len, msg_iter); + len =copy_from_iter (data->out + masked_prod, len, msg_iter); }else {if (len > array_size - masked_prod) { -copy_from_iter (data->out + masked_prod, +int ret =copy_from_iter (data->out + masked_prod, array_size - masked_prod, msg_iter); -copy_from_iter (data->out, - len - (array_size - masked_prod), - msg_iter); +if (ret != array_size - masked_prod) { + len = ret; + goto out; + } + len = ret +copy_from_iter (data->out, len - ret, msg_iter); }else { -copy_from_iter (data->out + masked_prod, len, msg_iter); + len =copy_from_iter (data->out + masked_prod, len, msg_iter); } } +out:/* write to ring before updating pointer */ virt_wmb (); intf->out_prod += len;
@@ -557,18 +560,21 @@ static int __read_ring(struct pvcalls_data_intf *intf, len = size;if (masked_prod > masked_cons) { -copy_to_iter (data->in + masked_cons, len, msg_iter); + len =copy_to_iter (data->in + masked_cons, len, msg_iter); }else {if (len > (array_size - masked_cons)) { -copy_to_iter (data->in + masked_cons, +int ret =copy_to_iter (data->in + masked_cons, array_size - masked_cons, msg_iter); -copy_to_iter (data->in, - len - (array_size - masked_cons), - msg_iter); +if (ret != array_size - masked_cons) { + len = ret; + goto out; + } + len = ret +copy_to_iter (data->in, len - ret, msg_iter); }else { -copy_to_iter (data->in + masked_cons, len, msg_iter); + len =copy_to_iter (data->in + masked_cons, len, msg_iter); } } +out:/* read data from the ring before increasing the index */ virt_mb ();if (!(flags &MSG_PEEK ))
Signature · 1 line
1.9.1
Stefano Stabellini
maintainerPATCH 2/2 pvcalls: fix casts to avoid warnings on 32 bit
Cast the map pointers to uintptr_t instead of uint64_t everywhere when setting the socket ids.
In pvcalls_front_event_handler, first cast the poll id to uintptr_t, then to struct sock_mapping * to avoid warnings. We know that the poll id is fine because it is was set by the frontend initially in the poll request.
--- drivers/xen/pvcalls-front.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/xen/pvcalls-front.c +9 -9
@@ -157,7 +157,7 @@ static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id) req_id = rsp->req_id;if (rsp->cmd ==PVCALLS_POLL ) { -struct sock_mapping *map = (struct sock_mapping *) +struct sock_mapping *map = (struct sock_mapping *)(uintptr_t ) rsp->u.poll.id; clear_bit(PVCALLS_FLAG_POLL_INFLIGHT,
@@ -280,7 +280,7 @@ int pvcalls_front_socket(struct socket *sock) req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_SOCKET ; - req->u.socket.id = (uint64_t ) map; + req->u.socket.id = (uintptr_t ) map; req->u.socket.domain =AF_INET ; req->u.socket.type =SOCK_STREAM ; req->u.socket.protocol =IPPROTO_IP ;
@@ -402,7 +402,7 @@ int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr, req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_CONNECT ; - req->u.connect.id = (uint64_t )map; + req->u.connect.id = (uintptr_t )map; req->u.connect.len = addr_len; req->u.connect.flags = flags; req->u.connect.ref = map->active.ref;
@@ -663,7 +663,7 @@ int pvcalls_front_bind(struct socket *sock, struct sockaddr *addr, int addr_len) req->req_id = req_id; map->sock = sock; req->cmd =PVCALLS_BIND ; - req->u.bind.id = (uint64_t )map; + req->u.bind.id = (uintptr_t )map;memcpy (req->u.bind.addr, addr,sizeof (*addr)); req->u.bind.len = addr_len;
@@ -725,7 +725,7 @@ int pvcalls_front_listen(struct socket *sock, int backlog) req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_LISTEN ; - req->u.listen.id = (uint64_t ) map; + req->u.listen.id = (uintptr_t ) map; req->u.listen.backlog = backlog; bedata->ring.req_prod_pvt++;
@@ -829,9 +829,9 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int flags) req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_ACCEPT ; - req->u.accept.id = (uint64_t ) map; + req->u.accept.id = (uintptr_t ) map; req->u.accept.ref = map2->active.ref; - req->u.accept.id_new = (uint64_t ) map2; + req->u.accept.id_new = (uintptr_t ) map2; req->u.accept.evtchn = evtchn; map->passive.accept_map = map2;
@@ -925,7 +925,7 @@ static unsigned int pvcalls_front_poll_passive(struct file *file, req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_POLL ; - req->u.poll.id = (uint64_t ) map; + req->u.poll.id = (uintptr_t ) map; bedata->ring.req_prod_pvt++;RING_PUSH_REQUESTS_AND_CHECK_NOTIFY (&bedata->ring, notify);
@@ -1023,7 +1023,7 @@ int pvcalls_front_release(struct socket *sock) req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_RELEASE ; - req->u.release.id = (uint64_t )map; + req->u.release.id = (uintptr_t )map; bedata->ring.req_prod_pvt++;RING_PUSH_REQUESTS_AND_CHECK_NOTIFY (&bedata->ring, notify);
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Stefano Stabellini
maintainerPATCH 2/2 pvcalls: fix casts to avoid warnings on 32 bit
In reply to Stefano StabelliniCast the map pointers to uintptr_t instead of uint64_t everywhere when setting the socket ids.
In pvcalls_front_event_handler, first cast the poll id to uintptr_t, then to struct sock_mapping * to avoid warnings. We know that the poll id is fine because it is was set by the frontend initially in the poll request.
--- drivers/xen/pvcalls-front.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/xen/pvcalls-front.c +9 -9
@@ -157,7 +157,7 @@ static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id) req_id = rsp->req_id;if (rsp->cmd ==PVCALLS_POLL ) { -struct sock_mapping *map = (struct sock_mapping *) +struct sock_mapping *map = (struct sock_mapping *)(uintptr_t ) rsp->u.poll.id; clear_bit(PVCALLS_FLAG_POLL_INFLIGHT,
@@ -280,7 +280,7 @@ int pvcalls_front_socket(struct socket *sock) req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_SOCKET ; - req->u.socket.id = (uint64_t ) map; + req->u.socket.id = (uintptr_t ) map; req->u.socket.domain =AF_INET ; req->u.socket.type =SOCK_STREAM ; req->u.socket.protocol =IPPROTO_IP ;
@@ -402,7 +402,7 @@ int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr, req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_CONNECT ; - req->u.connect.id = (uint64_t )map; + req->u.connect.id = (uintptr_t )map; req->u.connect.len = addr_len; req->u.connect.flags = flags; req->u.connect.ref = map->active.ref;
@@ -663,7 +663,7 @@ int pvcalls_front_bind(struct socket *sock, struct sockaddr *addr, int addr_len) req->req_id = req_id; map->sock = sock; req->cmd =PVCALLS_BIND ; - req->u.bind.id = (uint64_t )map; + req->u.bind.id = (uintptr_t )map;memcpy (req->u.bind.addr, addr,sizeof (*addr)); req->u.bind.len = addr_len;
@@ -725,7 +725,7 @@ int pvcalls_front_listen(struct socket *sock, int backlog) req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_LISTEN ; - req->u.listen.id = (uint64_t ) map; + req->u.listen.id = (uintptr_t ) map; req->u.listen.backlog = backlog; bedata->ring.req_prod_pvt++;
@@ -829,9 +829,9 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int flags) req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_ACCEPT ; - req->u.accept.id = (uint64_t ) map; + req->u.accept.id = (uintptr_t ) map; req->u.accept.ref = map2->active.ref; - req->u.accept.id_new = (uint64_t ) map2; + req->u.accept.id_new = (uintptr_t ) map2; req->u.accept.evtchn = evtchn; map->passive.accept_map = map2;
@@ -925,7 +925,7 @@ static unsigned int pvcalls_front_poll_passive(struct file *file, req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_POLL ; - req->u.poll.id = (uint64_t ) map; + req->u.poll.id = (uintptr_t ) map; bedata->ring.req_prod_pvt++;RING_PUSH_REQUESTS_AND_CHECK_NOTIFY (&bedata->ring, notify);
@@ -1023,7 +1023,7 @@ int pvcalls_front_release(struct socket *sock) req =RING_GET_REQUEST (&bedata->ring, req_id); req->req_id = req_id; req->cmd =PVCALLS_RELEASE ; - req->u.release.id = (uint64_t )map; + req->u.release.id = (uintptr_t )map; bedata->ring.req_prod_pvt++;RING_PUSH_REQUESTS_AND_CHECK_NOTIFY (&bedata->ring, notify);
Signature · 1 line
1.9.1