vhost/vsock: handle vhost_vq_init_access() error
Subsystems (3)
Stefan Hajnoczi
maintainerPATCH 1/1 vhost/vsock: handle vhost_vq_init_access() error
Propagate the error when vhost_vq_init_access() fails and set vq->private_data to NULL.
--- drivers/vhost/vsock.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/vhost/vsock.c +9 -4
@@ -373,6 +373,7 @@ static void vhost_vsock_handle_rx_kick(struct vhost_work *work)static int vhost_vsock_start (struct vhost_vsock *vsock) { +struct vhost_virtqueue *vq;size_t i;int ret;
@@ -383,19 +384,20 @@ static int vhost_vsock_start(struct vhost_vsock *vsock) goto err;for (i =0 ; i <ARRAY_SIZE (vsock->vqs); i++) { -struct vhost_virtqueue *vq = &vsock->vqs[i]; + vq = &vsock->vqs[i];mutex_lock (&vq->mutex);if (!vhost_vq_access_ok (vq)) { ret = -EFAULT ; -mutex_unlock (&vq->mutex); goto err_vq; }if (!vq->private_data) { vq->private_data = vsock; -vhost_vq_init_access (vq); + ret =vhost_vq_init_access (vq); +if (ret) + goto err_vq; }mutex_unlock (&vq->mutex);
@@ -405,8 +407,11 @@ static int vhost_vsock_start(struct vhost_vsock *vsock)return 0 ; err_vq: + vq->private_data =NULL ; +mutex_unlock (&vq->mutex); +for (i =0 ; i <ARRAY_SIZE (vsock->vqs); i++) { -struct vhost_virtqueue *vq = &vsock->vqs[i]; + vq = &vsock->vqs[i];mutex_lock (&vq->mutex); vq->private_data =NULL ;
Signature · 1 line
2.9.3
Quoted 45 lines · Stefan Hajnoczi
Propagate the error when
vhost_vq_init_access()fails and setvq->private_datato NULL.Signed-off-by Stefan Hajnoczi <[email protected]>--- drivers/vhost/vsock.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/vhost/vsock.c +5
-3@@ -373,6 +373,7 @@ static void vhost_vsock_handle_rx_kick(struct vhost_work *work)static int vhost_vsock_start (struct vhost_vsock *vsock) { +struct vhost_virtqueue *vq;size_t i;int ret;@@ -383,19 +384,20 @@ static int vhost_vsock_start(struct vhost_vsock *vsock) goto err;for (i =0 ; i <ARRAY_SIZE (vsock->vqs); i++) { -struct vhost_virtqueue *vq = &vsock->vqs[i]; + vq = &vsock->vqs[i];mutex_lock (&vq->mutex);if (!vhost_vq_access_ok (vq)) { ret = -EFAULT ; -mutex_unlock (&vq->mutex); goto err_vq; }if (!vq->private_data) { vq->private_data = vsock; -vhost_vq_init_access (vq); + ret =vhost_vq_init_access (vq); +if (ret) + goto err_vq; }mutex_unlock (&vq->mutex);
drivers/vhost/vsock.c static int vhost_vsock_start(struct vhost_vsock *vsock) · line 410
Quoted 4 lines
drivers/vhost/vsock.c +1
-0@@ -405,8 +407,11 @@ static int vhost_vsock_start(struct vhost_vsock *vsock)return 0 ; err_vq: + vq->private_data =NULL ;
Looks like this will be done twice?
Thanks
Quoted 8 lines
drivers/vhost/vsock.c +3
-1+mutex_unlock (&vq->mutex); +for (i =0 ; i <ARRAY_SIZE (vsock->vqs); i++) { -struct vhost_virtqueue *vq = &vsock->vqs[i]; + vq = &vsock->vqs[i];mutex_lock (&vq->mutex); vq->private_data =NULL ;
Stefan Hajnoczi
maintainerQuoted 38 lines · Jason Wang
Quoted 35 lines · Stefan Hajnoczi
Propagate the error when
vhost_vq_init_access()fails and setvq->private_datato NULL.Signed-off-by Stefan Hajnoczi <[email protected]>--- drivers/vhost/vsock.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/vhost/vsock.c +5
-3@@ -373,6 +373,7 @@ static void vhost_vsock_handle_rx_kick(struct vhost_work *work)static int vhost_vsock_start (struct vhost_vsock *vsock) { +struct vhost_virtqueue *vq;size_t i;int ret;@@ -383,19 +384,20 @@ static int vhost_vsock_start(struct vhost_vsock *vsock) goto err;for (i =0 ; i <ARRAY_SIZE (vsock->vqs); i++) { -struct vhost_virtqueue *vq = &vsock->vqs[i]; + vq = &vsock->vqs[i];mutex_lock (&vq->mutex);if (!vhost_vq_access_ok (vq)) { ret = -EFAULT ; -mutex_unlock (&vq->mutex); goto err_vq; }if (!vq->private_data) { vq->private_data = vsock; -vhost_vq_init_access (vq); + ret =vhost_vq_init_access (vq); +if (ret) + goto err_vq;
Quoted 8 lines
drivers/vhost/vsock.c static int vhost_vsock_start(struct vhost_vsock *vsock) · line 409
Quoted 6 lines
drivers/vhost/vsock.c +1
-0}mutex_unlock (&vq->mutex);@@ -405,8 +407,11 @@ static int vhost_vsock_start(struct vhost_vsock *vsock)return 0 ; err_vq: + vq->private_data =NULL ;Looks like this will be done twice?
Here we still hold the vq mutex. If we release the mutex then a virtqueue kick could be processed.
Stefan
Quoted 45 lines · Stefan Hajnoczi
Quoted 36 lines · Jason Wang
Quoted 34 lines · Stefan Hajnoczi
Propagate the error when
vhost_vq_init_access()fails and setvq->private_datato NULL.Signed-off-by Stefan Hajnoczi <[email protected]>--- drivers/vhost/vsock.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/vhost/vsock.c +4
-3@@ -373,6 +373,7 @@ static void vhost_vsock_handle_rx_kick(struct vhost_work *work)static int vhost_vsock_start (struct vhost_vsock *vsock) { +struct vhost_virtqueue *vq;size_t i;int ret;@@ -383,19 +384,20 @@ static int vhost_vsock_start(struct vhost_vsock *vsock) goto err;for (i =0 ; i <ARRAY_SIZE (vsock->vqs); i++) { -struct vhost_virtqueue *vq = &vsock->vqs[i]; + vq = &vsock->vqs[i];mutex_lock (&vq->mutex);if (!vhost_vq_access_ok (vq)) { ret = -EFAULT ; -mutex_unlock (&vq->mutex); goto err_vq; }if (!vq->private_data) { vq->private_data = vsock; -vhost_vq_init_access (vq); + ret =vhost_vq_init_access (vq); +if (ret)Quoted 8 lines
drivers/vhost/vsock.c static int vhost_vsock_start(struct vhost_vsock *vsock) · line 409
Quoted 7 lines
drivers/vhost/vsock.c +2
-0+ goto err_vq; }mutex_unlock (&vq->mutex);@@ -405,8 +407,11 @@ static int vhost_vsock_start(struct vhost_vsock *vsock)return 0 ; err_vq: + vq->private_data =NULL ;Looks like this will be done twice?
Quoted 4 lines
Here we still hold the vq mutex. If we release the mutex then a virtqueue kick could be processed.
Stefan
Ok, then it's better to assign vq->private_data after vhost_vq_init_acess() succeed.
Thanks
Quoted 48 lines · Jason Wang
Quoted 45 lines · Stefan Hajnoczi
Quoted 44 lines · Jason Wang
Quoted 38 lines · Stefan Hajnoczi
Propagate the error when
vhost_vq_init_access()fails and setvq->private_datato NULL.Signed-off-by Stefan Hajnoczi <[email protected]>--- drivers/vhost/vsock.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/vhost/vsock.c +5
-3@@ -373,6 +373,7 @@ static void vhost_vsock_handle_rx_kick(struct vhost_work *work)static int vhost_vsock_start (struct vhost_vsock *vsock) { +struct vhost_virtqueue *vq;size_t i;int ret;@@ -383,19 +384,20 @@ static int vhost_vsock_start(struct vhost_vsock *vsock) goto err;for (i =0 ; i <ARRAY_SIZE (vsock->vqs); i++) { -struct vhost_virtqueue *vq = &vsock->vqs[i]; + vq = &vsock->vqs[i];mutex_lock (&vq->mutex);if (!vhost_vq_access_ok (vq)) { ret = -EFAULT ; -mutex_unlock (&vq->mutex); goto err_vq; }if (!vq->private_data) { vq->private_data = vsock; -vhost_vq_init_access (vq); + ret =vhost_vq_init_access (vq); +if (ret) + goto err_vq; }mutex_unlock (&vq->mutex);drivers/vhost/vsock.c static int vhost_vsock_start(struct vhost_vsock *vsock) · line 409
Quoted 3 lines
drivers/vhost/vsock.c +1
-0@@ -405,8 +407,11 @@ static int vhost_vsock_start(struct vhost_vsock *vsock)return 0 ; err_vq: + vq->private_data =NULL ;Looks like this will be done twice?
Quoted 7 lines
Quoted 4 lines
Here we still hold the vq mutex. If we release the mutex then a virtqueue kick could be processed.
Stefan
Ok, then it's better to assign
vq->private_dataaftervhost_vq_init_acess()succeed.
No, that won't work because vhost_vq_init_acess() requires that vq->private_data is non-NULL.
Stefan
Jason Wang
Acked-byQuoted 50 lines · Stefan Hajnoczi
Quoted 49 lines · Jason Wang
Quoted 47 lines · Stefan Hajnoczi
Quoted 35 lines · Jason Wang
Quoted 34 lines · Stefan Hajnoczi
Propagate the error when
vhost_vq_init_access()fails and setvq->private_datato NULL.Signed-off-by Stefan Hajnoczi <[email protected]>--- drivers/vhost/vsock.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/vhost/vsock.c +4
-3@@ -373,6 +373,7 @@ static void vhost_vsock_handle_rx_kick(struct vhost_work *work)static int vhost_vsock_start (struct vhost_vsock *vsock) { +struct vhost_virtqueue *vq;size_t i;int ret;@@ -383,19 +384,20 @@ static int vhost_vsock_start(struct vhost_vsock *vsock) goto err;for (i =0 ; i <ARRAY_SIZE (vsock->vqs); i++) { -struct vhost_virtqueue *vq = &vsock->vqs[i]; + vq = &vsock->vqs[i];mutex_lock (&vq->mutex);if (!vhost_vq_access_ok (vq)) { ret = -EFAULT ; -mutex_unlock (&vq->mutex); goto err_vq; }if (!vq->private_data) { vq->private_data = vsock; -vhost_vq_init_access (vq); + ret =vhost_vq_init_access (vq); +if (ret)Quoted 8 lines
drivers/vhost/vsock.c static int vhost_vsock_start(struct vhost_vsock *vsock) · line 409
Quoted 7 lines
drivers/vhost/vsock.c +2
-0+ goto err_vq; }mutex_unlock (&vq->mutex);@@ -405,8 +407,11 @@ static int vhost_vsock_start(struct vhost_vsock *vsock)return 0 ; err_vq: + vq->private_data =NULL ;Looks like this will be done twice?
Here we still hold the vq mutex. If we release the mutex then a virtqueue kick could be processed.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Stefan
Ok, then it's better to assign
vq->private_dataaftervhost_vq_init_acess()succeed.No, that won't work because
vhost_vq_init_acess()requires thatvq->private_datais non-NULL.Stefan
Oh right. Then