All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] pvcalls fixes
@ 2018-12-21 23:06 Stefano Stabellini
  2018-12-21 23:06 ` [PATCH 1/5] pvcalls-front: read all data before closing the connection Stefano Stabellini
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Stefano Stabellini @ 2018-12-21 23:06 UTC (permalink / raw)
  To: xen-devel; +Cc: jgross, boris.ostrovsky, sstabellini

Hi all,

This series is a collection of small pvcalls fixes.

Cheers,

Stefano


Stefano Stabellini (5):
      pvcalls-front: read all data before closing the connection
      pvcalls-front: don't try to free unallocated rings
      pvcalls-front: properly allocate sk
      pvcalls-front: don't return error when the ring is full
      pvcalls-back: set -ENOTCONN in pvcalls_conn_back_read

 drivers/xen/pvcalls-back.c  |  7 ++++---
 drivers/xen/pvcalls-front.c | 20 +++++++++++++-------
 2 files changed, 17 insertions(+), 10 deletions(-)

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] pvcalls-front: read all data before closing the connection
  2018-12-21 23:06 [PATCH 0/5] pvcalls fixes Stefano Stabellini
@ 2018-12-21 23:06 ` Stefano Stabellini
  2018-12-21 23:06 ` [PATCH 2/5] pvcalls-front: don't try to free unallocated rings Stefano Stabellini
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Stefano Stabellini @ 2018-12-21 23:06 UTC (permalink / raw)
  To: xen-devel; +Cc: jgross, Stefano Stabellini, boris.ostrovsky, sstabellini

When a connection is closing in_error is set to ENOTCONN. There could
still be outstanding data on the ring left by the backend. Before
closing the connection on the frontend side, drain the ring.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
---
 drivers/xen/pvcalls-front.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 77224d8..e5d95aa 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -560,15 +560,13 @@ static int __read_ring(struct pvcalls_data_intf *intf,
 	error = intf->in_error;
 	/* get pointers before reading from the ring */
 	virt_rmb();
-	if (error < 0)
-		return error;
 
 	size = pvcalls_queued(prod, cons, array_size);
 	masked_prod = pvcalls_mask(prod, array_size);
 	masked_cons = pvcalls_mask(cons, array_size);
 
 	if (size == 0)
-		return 0;
+		return error ?: size;
 
 	if (len > size)
 		len = size;
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] pvcalls-front: don't try to free unallocated rings
  2018-12-21 23:06 [PATCH 0/5] pvcalls fixes Stefano Stabellini
  2018-12-21 23:06 ` [PATCH 1/5] pvcalls-front: read all data before closing the connection Stefano Stabellini
@ 2018-12-21 23:06 ` Stefano Stabellini
  2018-12-21 23:06 ` [PATCH 3/5] pvcalls-front: properly allocate sk Stefano Stabellini
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Stefano Stabellini @ 2018-12-21 23:06 UTC (permalink / raw)
  To: xen-devel; +Cc: jgross, Stefano Stabellini, boris.ostrovsky, sstabellini

inflight_req_id is 0 when initialized. If inflight_req_id is 0, there is
no accept_map to free. Fix the check in pvcalls_front_release.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index e5d95aa..4f3d664 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -1030,8 +1030,8 @@ int pvcalls_front_release(struct socket *sock)
 		spin_lock(&bedata->socket_lock);
 		list_del(&map->list);
 		spin_unlock(&bedata->socket_lock);
-		if (READ_ONCE(map->passive.inflight_req_id) !=
-		    PVCALLS_INVALID_ID) {
+		if (READ_ONCE(map->passive.inflight_req_id) != PVCALLS_INVALID_ID &&
+			READ_ONCE(map->passive.inflight_req_id) != 0) {
 			pvcalls_front_free_map(bedata,
 					       map->passive.accept_map);
 		}
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] pvcalls-front: properly allocate sk
  2018-12-21 23:06 [PATCH 0/5] pvcalls fixes Stefano Stabellini
  2018-12-21 23:06 ` [PATCH 1/5] pvcalls-front: read all data before closing the connection Stefano Stabellini
  2018-12-21 23:06 ` [PATCH 2/5] pvcalls-front: don't try to free unallocated rings Stefano Stabellini
@ 2018-12-21 23:06 ` Stefano Stabellini
  2018-12-21 23:06 ` [PATCH 4/5] pvcalls-front: don't return error when the ring is full Stefano Stabellini
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Stefano Stabellini @ 2018-12-21 23:06 UTC (permalink / raw)
  To: xen-devel; +Cc: jgross, Stefano Stabellini, boris.ostrovsky, sstabellini

Don't use kzalloc: it ends up leaving sk->sk_prot not properly
initialized. Use sk_alloc instead and define our own trivial struct
proto.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
---
 drivers/xen/pvcalls-front.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 4f3d664..0158858 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -31,6 +31,12 @@
 #define PVCALLS_NR_RSP_PER_RING __CONST_RING_SIZE(xen_pvcalls, XEN_PAGE_SIZE)
 #define PVCALLS_FRONT_MAX_SPIN 5000
 
+static struct proto pvcalls_proto = {
+	.name	= "PVCalls",
+	.owner	= THIS_MODULE,
+	.obj_size = sizeof(struct sock),
+};
+
 struct pvcalls_bedata {
 	struct xen_pvcalls_front_ring ring;
 	grant_ref_t ref;
@@ -837,7 +843,7 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int flags)
 
 received:
 	map2->sock = newsock;
-	newsock->sk = kzalloc(sizeof(*newsock->sk), GFP_KERNEL);
+	newsock->sk = sk_alloc(sock_net(sock->sk), PF_INET, GFP_KERNEL, &pvcalls_proto, false);
 	if (!newsock->sk) {
 		bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID;
 		map->passive.inflight_req_id = PVCALLS_INVALID_ID;
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] pvcalls-front: don't return error when the ring is full
  2018-12-21 23:06 [PATCH 0/5] pvcalls fixes Stefano Stabellini
                   ` (2 preceding siblings ...)
  2018-12-21 23:06 ` [PATCH 3/5] pvcalls-front: properly allocate sk Stefano Stabellini
@ 2018-12-21 23:06 ` Stefano Stabellini
  2018-12-21 23:06 ` [PATCH 5/5] pvcalls-back: set -ENOTCONN in pvcalls_conn_back_read Stefano Stabellini
  2019-01-02 16:51 ` [PATCH 0/5] pvcalls fixes Boris Ostrovsky
  5 siblings, 0 replies; 7+ messages in thread
From: Stefano Stabellini @ 2018-12-21 23:06 UTC (permalink / raw)
  To: xen-devel; +Cc: jgross, Stefano Stabellini, boris.ostrovsky, sstabellini

When the ring is full, size == array_size. It is not an error condition,
so simply return 0 instead of an error.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
---
 drivers/xen/pvcalls-front.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 0158858..1a893a1 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -475,8 +475,10 @@ static int __write_ring(struct pvcalls_data_intf *intf,
 	virt_mb();
 
 	size = pvcalls_queued(prod, cons, array_size);
-	if (size >= array_size)
+	if (size > array_size)
 		return -EINVAL;
+	if (size == array_size)
+		return 0;
 	if (len > array_size - size)
 		len = array_size - size;
 
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] pvcalls-back: set -ENOTCONN in pvcalls_conn_back_read
  2018-12-21 23:06 [PATCH 0/5] pvcalls fixes Stefano Stabellini
                   ` (3 preceding siblings ...)
  2018-12-21 23:06 ` [PATCH 4/5] pvcalls-front: don't return error when the ring is full Stefano Stabellini
@ 2018-12-21 23:06 ` Stefano Stabellini
  2019-01-02 16:51 ` [PATCH 0/5] pvcalls fixes Boris Ostrovsky
  5 siblings, 0 replies; 7+ messages in thread
From: Stefano Stabellini @ 2018-12-21 23:06 UTC (permalink / raw)
  To: xen-devel; +Cc: jgross, Stefano Stabellini, boris.ostrovsky, sstabellini

When a connection is closing we receive on pvcalls_sk_state_change
notification. Instead of setting the connection as closed immediately
(-ENOTCONN), let's read one more time from it: pvcalls_conn_back_read
will set the connection as closed when necessary.

That way, we avoid races between pvcalls_sk_state_change and
pvcalls_back_ioworker.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
---
 drivers/xen/pvcalls-back.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c
index 2e5d845..71b6287 100644
--- a/drivers/xen/pvcalls-back.c
+++ b/drivers/xen/pvcalls-back.c
@@ -160,9 +160,10 @@ static void pvcalls_conn_back_read(void *opaque)
 
 	/* write the data, then modify the indexes */
 	virt_wmb();
-	if (ret < 0)
+	if (ret < 0) {
+		atomic_set(&map->read, 0);
 		intf->in_error = ret;
-	else
+	} else
 		intf->in_prod = prod + ret;
 	/* update the indexes, then notify the other end */
 	virt_wmb();
@@ -288,7 +289,7 @@ static void pvcalls_sk_state_change(struct sock *sock)
 		return;
 
 	intf = map->ring;
-	intf->in_error = -ENOTCONN;
+	atomic_inc(&map->read);
 	notify_remote_via_irq(map->irq);
 }
 
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] pvcalls fixes
  2018-12-21 23:06 [PATCH 0/5] pvcalls fixes Stefano Stabellini
                   ` (4 preceding siblings ...)
  2018-12-21 23:06 ` [PATCH 5/5] pvcalls-back: set -ENOTCONN in pvcalls_conn_back_read Stefano Stabellini
@ 2019-01-02 16:51 ` Boris Ostrovsky
  5 siblings, 0 replies; 7+ messages in thread
From: Boris Ostrovsky @ 2019-01-02 16:51 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel; +Cc: jgross

On 12/21/18 6:06 PM, Stefano Stabellini wrote:
> Hi all,
>
> This series is a collection of small pvcalls fixes.
>
> Cheers,
>
> Stefano
>
>
> Stefano Stabellini (5):
>       pvcalls-front: read all data before closing the connection
>       pvcalls-front: don't try to free unallocated rings
>       pvcalls-front: properly allocate sk
>       pvcalls-front: don't return error when the ring is full
>       pvcalls-back: set -ENOTCONN in pvcalls_conn_back_read
>
>  drivers/xen/pvcalls-back.c  |  7 ++++---
>  drivers/xen/pvcalls-front.c | 20 +++++++++++++-------
>  2 files changed, 17 insertions(+), 10 deletions(-)


Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>

Applied to for-linus-21.



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-01-02 16:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-21 23:06 [PATCH 0/5] pvcalls fixes Stefano Stabellini
2018-12-21 23:06 ` [PATCH 1/5] pvcalls-front: read all data before closing the connection Stefano Stabellini
2018-12-21 23:06 ` [PATCH 2/5] pvcalls-front: don't try to free unallocated rings Stefano Stabellini
2018-12-21 23:06 ` [PATCH 3/5] pvcalls-front: properly allocate sk Stefano Stabellini
2018-12-21 23:06 ` [PATCH 4/5] pvcalls-front: don't return error when the ring is full Stefano Stabellini
2018-12-21 23:06 ` [PATCH 5/5] pvcalls-back: set -ENOTCONN in pvcalls_conn_back_read Stefano Stabellini
2019-01-02 16:51 ` [PATCH 0/5] pvcalls fixes Boris Ostrovsky

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.