[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] tools: blktap2 fix stack overflow when closing vbd with pending_requests



From: Weiwei Li<nuonuoli@xxxxxxxxxxx>

When we close blktap and pending_requests have been completed yet, the 
callchain like this:
 
tapdisk_vbd_close-->with pending_requests
-->td_flag_set(vbd->state, TD_VBD_SHUTDOWN_REQUESTED);
-->tapdisk_vbd_kick
-->tapdisk_vbd_check_state
-->tapdisk_vbd_close
-->tapdisk_vbd_shutdown
-->tapdisk_vbd_kick
which will inter a deadloop as above and makes stack overflow.
To fix this, we just clear TD_VBD_SHUTDOWN_REQUESTED flag before
tapdisk_vbd_shutdown.
 
Signed-off-by: Weiwei Li<nuonuoli@xxxxxxxxxxx>
Signed-off-by: Xiaoming Gao <newtongao@xxxxxxxxxxx>
Signed-off-by: Yi Li <peteryili@xxxxxxxxxxx>
 
---
 tools/blktap2/drivers/tapdisk-vbd.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
 
diff --git a/tools/blktap2/drivers/tapdisk-vbd.c b/tools/blktap2/drivers/tapdisk-vbd.c
index c665f27..a6f697d 100644
--- a/tools/blktap2/drivers/tapdisk-vbd.c
+++ b/tools/blktap2/drivers/tapdisk-vbd.c
@@ -795,6 +795,7 @@ tapdisk_vbd_close(td_vbd_t *vbd)
       !list_empty(&vbd->completed_requests)))
  goto fail;
 
+ td_flag_clear(vbd->state, TD_VBD_SHUTDOWN_REQUESTED);
  return tapdisk_vbd_shutdown(vbd);
 
 fail:
@@ -1100,7 +1101,7 @@ tapdisk_vbd_check_state(td_vbd_t *vbd)
  if (td_flag_test(vbd->state, TD_VBD_PAUSE_REQUESTED))
  tapdisk_vbd_pause(vbd);
 
- if (td_flag_test(vbd->state, TD_VBD_SHUTDOWN_REQUESTED))
+ if (td_flag_test(vbd->state, TD_VBD_SHUTDOWN_REQUESTED) && list_empty(&vbd->pending_requests))
  tapdisk_vbd_close(vbd);
 }
 
-- 
1.7.1
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.