migration/rdma: Fix qemu_rdma_cleanup null check
PATCH 1/1 migration/rdma: Fix qemu_rdma_cleanup null check
From: "Dr. David Alan Gilbert" <[email protected]>
If the migration fails before the channel is open (e.g. a bad address) we end up in the cleanup with rdma->channel==NULL.
Spotted by Coverity: CID 1398634
--- migration/rdma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
migration/rdma.c +3 -1
@@ -2321,7 +2321,9 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) rdma->connected = false; } -qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); +if (rdma->channel) { +qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); + }g_free (rdma->dest_blocks); rdma->dest_blocks =NULL ;
Signature · 1 line
2.20.1
Quoted 17 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
If the migration fails before the channel is open (e.g. a bad address) we end up in the cleanup with rdma->channel==NULL.
Spotted by Coverity: CID 1398634
Fixes fbbaacab2758cb3f32a0Signed-off-by Dr. David Alan Gilbert <[email protected]>--- migration/rdma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)migration/rdma.c +0
-0
migration/rdma.c static void qemu_rdma_cleanup(RDMAContext *rdma) · line 2326
Quoted 7 lines
migration/rdma.c +3
-1@@ -2321,7 +2321,9 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) rdma->connected = false; } -qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); +if (rdma->channel) { +qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); + }
IIUC there's no strict ordering constraint on resetting the fd handler, then how about simply moving this line into the below "if (rdma->channel)" altogether?
Regards,
Signature · 1 line
Peter Xu
Quoted 21 lines · * Peter Xu ([email protected]) wrote:
Quoted 20 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
If the migration fails before the channel is open (e.g. a bad address) we end up in the cleanup with rdma->channel==NULL.
Spotted by Coverity: CID 1398634
Fixes fbbaacab2758cb3f32a0Signed-off-by Dr. David Alan Gilbert <[email protected]>--- migration/rdma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)migration/rdma.c +0
-0@@ -2321,7 +2321,9 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) rdma->connected = false; }
Quoted 8 lines
migration/rdma.c static void qemu_rdma_cleanup(RDMAContext *rdma) · line 2326
Quoted 4 lines
migration/rdma.c +3
-1-qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); +if (rdma->channel) { +qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); + }IIUC there's no strict ordering constraint on resetting the fd handler, then how about simply moving this line into the below "if (
rdma->channel)" altogether?
The logic around the closing of the return path makes that check later a bit messy; rdma->channel can get set to Null before the other check.
Dave
Quoted 4 lines
Regards,
Signature · 1 line
Peter Xu
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Peter Xu
Reviewed-byQuoted 31 lines · Dr. David Alan Gilbert
Quoted 21 lines · * Peter Xu ([email protected]) wrote:
Quoted 20 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
If the migration fails before the channel is open (e.g. a bad address) we end up in the cleanup with rdma->channel==NULL.
Spotted by Coverity: CID 1398634
Fixes fbbaacab2758cb3f32a0Signed-off-by Dr. David Alan Gilbert <[email protected]>--- migration/rdma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)migration/rdma.c +0
-0@@ -2321,7 +2321,9 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) rdma->connected = false; }Quoted 8 lines
migration/rdma.c static void qemu_rdma_cleanup(RDMAContext *rdma) · line 2326
Quoted 4 lines
migration/rdma.c +3
-1-qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); +if (rdma->channel) { +qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); + }IIUC there's no strict ordering constraint on resetting the fd handler, then how about simply moving this line into the below "if (
rdma->channel)" altogether?
Quoted 2 lines
The logic around the closing of the return path makes that check later a bit messy;
rdma->channelcan get set to Null before the other check.
Ah I see, it's the mess by sharing listen_id and channel on destination side... Maybe we can clean them up along the way? I gave it a shot:
if (rdma->listen_id && rdma->is_return_path) {
/*
* The return path on the destination side, both listen_id and
* channel are shared with the other context so we skip
* freeing those but simply clear the pointers no matter what.
* The main context will help us to clean these.
*/
rdma->listen_id = NULL;
rdma->channel = NULL;
} else {
/*
* Either the source side, or the main context of the
* destination side: we are responsible for listen_id/channel
*/
if (rdma->listen_id) {
rdma_destroy_id(rdma->listen_id);
rdma->listen_id = NULL;
}
if (rdma->channel) {
qemu_set_fd_handler(rdma->channel->fd, NULL, NULL, NULL);
rdma_destroy_event_channel(rdma->channel);
rdma->channel = NULL;
}
}I slightly prefer to clean it up (if someone is still going to maintain the RDMA code... :), but either way is fine to me.
No matter what you prefer:
Thanks,
Signature · 1 line
Peter Xu
Quoted 18 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
If the migration fails before the channel is open (e.g. a bad address) we end up in the cleanup with rdma->channel==NULL.
Spotted by Coverity: CID 1398634
Fixes fbbaacab2758cb3f32a0Signed-off-by Dr. David Alan Gilbert <[email protected]>--- migration/rdma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)migration/rdma.c +0
-0
migration/rdma.c static void qemu_rdma_cleanup(RDMAContext *rdma) · line 2329
Quoted 10 lines
migration/rdma.c +3
-1@@ -2321,7 +2321,9 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) rdma->connected = false; } -qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); +if (rdma->channel) { +qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); + }g_free (rdma->dest_blocks); rdma->dest_blocks =NULL ;
Quoted 8 lines · * Dr. David Alan Gilbert (git) ([email protected]) wrote:
From: "Dr. David Alan Gilbert" <[email protected]>
If the migration fails before the channel is open (e.g. a bad address) we end up in the cleanup with rdma->channel==NULL.
Spotted by Coverity: CID 1398634
Fixes fbbaacab2758cb3f32a0Signed-off-by Dr. David Alan Gilbert <[email protected]>
Queued
Quoted 23 lines
--- migration/rdma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)migration/rdma.c +3
-1@@ -2321,7 +2321,9 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) rdma->connected = false; } -qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); +if (rdma->channel) { +qemu_set_fd_handler (rdma->channel->fd,NULL ,NULL ,NULL ); + }g_free (rdma->dest_blocks); rdma->dest_blocks =NULL ;Signature · 1 line
2.20.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK