* [PATCH 1/2] pvcalls: check return value from copy_from/to_iter
@ 2017-10-30 21:40 Stefano Stabellini
2017-10-30 21:40 ` [PATCH 2/2] pvcalls: fix casts to avoid warnings on 32 bit Stefano Stabellini
2017-10-30 21:40 ` Stefano Stabellini
0 siblings, 2 replies; 3+ messages in thread
From: Stefano Stabellini @ 2017-10-30 21:40 UTC (permalink / raw)
To: boris.ostrovsky; +Cc: sstabellini, xen-devel, linux-kernel, jgross, stefano
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.
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
---
drivers/xen/pvcalls-front.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 8e7426083..f2dcac88 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -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))
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] pvcalls: fix casts to avoid warnings on 32 bit
2017-10-30 21:40 [PATCH 1/2] pvcalls: check return value from copy_from/to_iter Stefano Stabellini
@ 2017-10-30 21:40 ` Stefano Stabellini
2017-10-30 21:40 ` Stefano Stabellini
1 sibling, 0 replies; 3+ messages in thread
From: Stefano Stabellini @ 2017-10-30 21:40 UTC (permalink / raw)
To: boris.ostrovsky; +Cc: sstabellini, xen-devel, linux-kernel, jgross, stefano
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.
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
---
drivers/xen/pvcalls-front.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index f2dcac88..0c1ec68 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -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);
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] pvcalls: fix casts to avoid warnings on 32 bit
2017-10-30 21:40 [PATCH 1/2] pvcalls: check return value from copy_from/to_iter Stefano Stabellini
2017-10-30 21:40 ` [PATCH 2/2] pvcalls: fix casts to avoid warnings on 32 bit Stefano Stabellini
@ 2017-10-30 21:40 ` Stefano Stabellini
1 sibling, 0 replies; 3+ messages in thread
From: Stefano Stabellini @ 2017-10-30 21:40 UTC (permalink / raw)
To: boris.ostrovsky; +Cc: jgross, stefano, sstabellini, linux-kernel, xen-devel
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.
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
---
drivers/xen/pvcalls-front.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index f2dcac88..0c1ec68 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -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);
--
1.9.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-30 21:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-30 21:40 [PATCH 1/2] pvcalls: check return value from copy_from/to_iter Stefano Stabellini
2017-10-30 21:40 ` [PATCH 2/2] pvcalls: fix casts to avoid warnings on 32 bit Stefano Stabellini
2017-10-30 21:40 ` Stefano Stabellini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.