aio-posix: epoll cleanups
cover aio-posix: epoll cleanups
The first fixes a NULL-pointer dereference that was reported by Coverity (so definitely for 2.8). The second is a small simplification.
Paolo Bonzini (2):
aio-posix: avoid NULL pointer dereference in aio_epoll_update
aio-posix: simplify aio_epoll_update
aio-posix.c | 56 ++++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 30 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/2 aio-posix: avoid NULL pointer dereference in aio_epoll_update
aio_epoll_update dereferences parameter "node", but it could have been NULL if deleting an fd handler that was not registered in the first place.
--- aio-posix.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)
aio-posix.c +18 -15
@@ -217,21 +217,24 @@ void aio_set_fd_handler(AioContext *ctx,/* Are we deleting the fd handler? */ if (!io_read && !io_write) { -if (node) { -g_source_remove_poll (&ctx->source, &node->pfd); - -/* If the lock is held, just mark the node as deleted */ -if (ctx->walking_handlers) { - node->deleted =1 ; - node->pfd.revents =0 ; - }else { -/* Otherwise, delete it for real. We can't just mark it as -* deleted because deleted nodes are only cleaned up after -* releasing the walking_handlers lock. -*/ -QLIST_REMOVE (node, node); - deleted = true; - } +if (node ==NULL ) { +return ; + } + + node->pfd.events =0 ; +g_source_remove_poll (&ctx->source, &node->pfd); + +/* If the lock is held, just mark the node as deleted */ +if (ctx->walking_handlers) { + node->deleted =1 ; + node->pfd.revents =0 ; + }else { +/* Otherwise, delete it for real. We can't just mark it as +* deleted because deleted nodes are only cleaned up after +* releasing the walking_handlers lock. +*/ +QLIST_REMOVE (node, node); + deleted = true; } }else {if (node ==NULL ) {
Signature · 1 line
2.7.4
Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] aio-posix: avoid NULL pointer dereference in aio_epoll_update
Quoted 26 lines · Paolo Bonzini
aio_epoll_updatedereferences parameter "node", but it could have been NULL if deleting an fd handler that was not registered in the first place.Signed-off-by Paolo Bonzini <[email protected]>--- aio-posix.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)aio-posix.c +0
-10@@ -217,21 +217,24 @@ void aio_set_fd_handler(AioContext *ctx,/* Are we deleting the fd handler? */ if (!io_read && !io_write) { -if (node) { -g_source_remove_poll (&ctx->source, &node->pfd); - -/* If the lock is held, just mark the node as deleted */ -if (ctx->walking_handlers) { - node->deleted =1 ; - node->pfd.revents =0 ; - }else { -/* Otherwise, delete it for real. We can't just mark it as -* deleted because deleted nodes are only cleaned up after
aio-posix.c void aio_set_fd_handler(AioContext *ctx, · line 224
Quoted 10 lines
aio-posix.c +5
-5-* releasing the walking_handlers lock. -*/ -QLIST_REMOVE (node, node); - deleted = true; - } +if (node ==NULL ) { +return ; + } + + node->pfd.events =0 ;
^--- is this left over from debugging...
aio-posix.c void aio_set_fd_handler(AioContext *ctx, · line 230
Quoted 6 lines
aio-posix.c +6
-0+g_source_remove_poll (&ctx->source, &node->pfd); + +/* If the lock is held, just mark the node as deleted */ +if (ctx->walking_handlers) { + node->deleted =1 ; + node->pfd.revents =0 ;
...the original code clears revents here?
Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] aio-posix: avoid NULL pointer dereference in aio_epoll_update
Quoted 31 lines · Stefan Hajnoczi
Quoted 30 lines · Paolo Bonzini
aio_epoll_updatedereferences parameter "node", but it could have been NULL if deleting an fd handler that was not registered in the first place.Signed-off-by Paolo Bonzini <[email protected]>--- aio-posix.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)aio-posix.c +0
-14@@ -217,21 +217,24 @@ void aio_set_fd_handler(AioContext *ctx,/* Are we deleting the fd handler? */ if (!io_read && !io_write) { -if (node) { -g_source_remove_poll (&ctx->source, &node->pfd); - -/* If the lock is held, just mark the node as deleted */ -if (ctx->walking_handlers) { - node->deleted =1 ; - node->pfd.revents =0 ; - }else { -/* Otherwise, delete it for real. We can't just mark it as -* deleted because deleted nodes are only cleaned up after -* releasing the walking_handlers lock. -*/ -QLIST_REMOVE (node, node); - deleted = true;
Quoted 8 lines
aio-posix.c void aio_set_fd_handler(AioContext *ctx, · line 224
Quoted 6 lines
aio-posix.c +5
-1- } +if (node ==NULL ) { +return ; + } + + node->pfd.events =0 ;^--- is this left over from debugging...
No, it's left over from solving conflicts. This is an old patch that got lost. Will send v2, thanks for the review!
Paolo
Quoted 9 lines
aio-posix.c void aio_set_fd_handler(AioContext *ctx, · line 230
Quoted 6 lines
aio-posix.c +6
-0+g_source_remove_poll (&ctx->source, &node->pfd); + +/* If the lock is held, just mark the node as deleted */ +if (ctx->walking_handlers) { + node->deleted =1 ; + node->pfd.revents =0 ;...the original code clears revents here?
PATCH 2/2 aio-posix: simplify aio_epoll_update
In reply to Paolo BonziniExtract common code out of the "if".
--- aio-posix.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
aio-posix.c +8 -15
@@ -81,29 +81,22 @@ static void aio_epoll_update(AioContext *ctx, AioHandler *node, bool is_new) {struct epoll_event event;int r; +int ctl;if (!ctx->epoll_enabled) {return ; }if (!node->pfd.events) { - r =epoll_ctl (ctx->epollfd,EPOLL_CTL_DEL , node->pfd.fd, &event); -if (r) { -aio_epoll_disable (ctx); - } + ctl =EPOLL_CTL_DEL ; }else { event.data.ptr = node; event.events =epoll_events_from_pfd (node->pfd.events); -if (is_new) { - r =epoll_ctl (ctx->epollfd,EPOLL_CTL_ADD , node->pfd.fd, &event); -if (r) { -aio_epoll_disable (ctx); - } - }else { - r =epoll_ctl (ctx->epollfd,EPOLL_CTL_MOD , node->pfd.fd, &event); -if (r) { -aio_epoll_disable (ctx); - } - } + ctl = is_new ?EPOLL_CTL_ADD :EPOLL_CTL_MOD ; + } + + r =epoll_ctl (ctx->epollfd, ctl, node->pfd.fd, &event); +if (r) { +aio_epoll_disable (ctx); } }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] aio-posix: simplify aio_epoll_update
Quoted 6 lines · Paolo Bonzini
Extract common code out of the "if".
Signed-off-by Paolo Bonzini <[email protected]>--- aio-posix.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
Quoted 6 lines · Paolo Bonzini
The first fixes a NULL-pointer dereference that was reported by Coverity (so definitely for 2.8). The second is a small simplification.
Paolo Bonzini (2):
aio-posix: avoid NULL pointer dereference inaio_epoll_update
aio-posix: simplifyaio_epoll_update