9pfs: fix migration_block leak
PATCH 1/1 9pfs: fix migration_block leak
The guest can leave the pdu->s->migration_blocker exists by attach but not remove a fid. Then if we hot unplug the 9pfs device, the v9fs_reset() just free the fids, but not free the migration_blocker. This will leak a memory leak. This patch avoid this.
--- hw/9pfs/9p.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/9pfs/9p.c +6 -0
@@ -548,6 +548,12 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu)free_fid (pdu, fidp); } } + +if (pdu->s->migration_blocker) { +migrate_del_blocker (pdu->s->migration_blocker); +error_free (pdu->s->migration_blocker); + pdu->s->migration_blocker =NULL ; + } }#define P9_QID_TYPE_DIR 0x80
Signature · 1 line
1.8.3.1
Quoted 1 line · Li Qiang
The guest can leave the
pdu->s->migration_blockerexists by attach
s/exists/in place/
s/attach/attaching/
Quoted 1 line
but not remove a fid. Then if we hot unplug the 9pfs device, the
s/remove/removing/
Quoted 2 lines
v9fs_reset()just free the fids, but not free themigration_blocker. This will leak a memory leak. This patch avoid this.
s/leak a/cause a/
s/avoid/avoids/
Quoted 5 lines
Signed-off-by Li Qiang <[email protected]>--- hw/9pfs/9p.c | 6 ++++++ 1 file changed, 6 insertions(+)
Probably worth including in 2.9 as a bug fix.
Quoted 19 lines
hw/9pfs/9p.c +6
-0@@ -548,6 +548,12 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu)free_fid (pdu, fidp); } } + +if (pdu->s->migration_blocker) { +migrate_del_blocker (pdu->s->migration_blocker); +error_free (pdu->s->migration_blocker); + pdu->s->migration_blocker =NULL ; + } }#define P9_QID_TYPE_DIR 0x80
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 8 lines · On Thu, 30 Mar 2017 08:25:25 -0500 Eric Blake <[email protected]> wrote:
Quoted 1 line · Li Qiang
The guest can leave the
pdu->s->migration_blockerexists by attachs/exists/in place/
s/attach/attaching/Quoted 1 line
but not remove a fid. Then if we hot unplug the 9pfs device, the
In theory you're right, but the current 9p client in linux won't let you hot unplug the device unless you unmount the 9p share first, hence freeing the blocker.
Quoted 4 lines
s/remove/removing/
Quoted 2 lines
v9fs_reset()just free the fids, but not free themigration_blocker. This will leak a memory leak. This patch avoid this.
I had a similar issue sitting my TODO list for quite a time: the blocker survives a system_reset. It doesn't cause a memory leak but it prevents migration until the guest mounts/unmounts the 9p share again.
This boils down to virtfs_reset() calling free_fid() instead of put_fid() IIRC.
Quoted 15 lines
s/leak a/cause a/
s/avoid/avoids/Quoted 5 lines
Signed-off-by Li Qiang <[email protected]>--- hw/9pfs/9p.c | 6 ++++++ 1 file changed, 6 insertions(+)Probably worth including in 2.9 as a bug fix.
Reviewed-by Eric Blake <[email protected]>Quoted 1 line
Quoted 14 lines
Quoted 5 lines
hw/9pfs/9p.c +0
-0hw/9pfs/9p.c static void coroutine_fn virtfs_reset(V9fsPDU *pdu) · line 556
Quoted 9 lines
hw/9pfs/9p.c +6
-0@@ -548,6 +548,12 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu)free_fid (pdu, fidp); } } + +if (pdu->s->migration_blocker) { +migrate_del_blocker (pdu->s->migration_blocker); +error_free (pdu->s->migration_blocker); + pdu->s->migration_blocker =NULL ; + }
I'd prefer to drain all PDUs in virtfs_reset() and have the loop above to call put_fid() instead of free_fid(). If this isn't doable for 2.9, I'll apply this patch with a comment.
Quoted 5 lines
Quoted 4 lines
hw/9pfs/9p.c +0
-0}#define P9_QID_TYPE_DIR 0x80
Hello,
2017-03-30 23:46 GMT+08:00 Greg Kurz <[email protected]>:
Quoted 10 lines
Quoted 6 lines · On Thu, 30 Mar 2017 08:25:25 -0500 Eric Blake <[email protected]> wrote:
Quoted 1 line · Li Qiang
The guest can leave the
pdu->s->migration_blockerexists by attachs/exists/in place/
s/attach/attaching/
Eric,
Thanks for pointing my mistakes!
Quoted 9 lines
Quoted 2 lines
Quoted 1 line
but not remove a fid. Then if we hot unplug the 9pfs device, the
In theory you're right, but the current 9p client in linux won't let you hot
unplug the device unless you unmount the 9p share first, hence freeing the blocker.
I think we should consider every possible situation.
Quoted 43 lines
Quoted 4 lines
s/remove/removing/
Quoted 2 lines
v9fs_reset()just free the fids, but not free themigration_blocker. This will leak a memory leak. This patch avoid this.I had a similar issue sitting my TODO list for quite a time: the blocker survives a
system_reset. It doesn't cause a memory leak but it prevents migration until the guest mounts/unmounts the 9p share again.This boils down to
virtfs_reset()callingfree_fid()instead ofput_fid()IIRC.Quoted 12 lines
s/leak a/cause a/
s/avoid/avoids/Quoted 5 lines
Signed-off-by Li Qiang <[email protected]>--- hw/9pfs/9p.c | 6 ++++++ 1 file changed, 6 insertions(+)Probably worth including in 2.9 as a bug fix.
Quoted 8 lines
Reviewed-by Eric Blake <[email protected]>hw/9pfs/9p.c static void coroutine_fn virtfs_reset(V9fsPDU
Quoted 6 lines
hw/9pfs/9p.c +0
-0@@ -548,6 +548,12 @@ static void coroutine_fn virtfs_reset(V9fsPDU*pdu)
Quoted 9 lines
hw/9pfs/9p.c static void coroutine_fn virtfs_reset(V9fsPDU · line 556
Quoted 9 lines
hw/9pfs/9p.c +6
-0free_fid (pdu, fidp); } } + +if (pdu->s->migration_blocker) { +migrate_del_blocker (pdu->s->migration_blocker); +error_free (pdu->s->migration_blocker); + pdu->s->migration_blocker =NULL ; + }
Quoted 5 lines
I'd prefer to drain all PDUs in
virtfs_reset()and have the loop above to callput_fid()instead offree_fid(). If this isn't doable for 2.9, I'll apply this patch with a comment.
Yes, I have considered to use put_fid() to fix this. But I'm not sure the 'fidp->ref' is at most 1 in virtfs_reset() function(I think it is).
IIUC I think omit the 'else' branch, and call put_fid() directly like this.
hw/9pfs/9p.c +1 -2
@@ -544,9 +544,8 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu)if (fidp->ref) { fidp->clunked =1 ; - }else { -free_fid (pdu, fidp); } +put_fid (pdu, fidp); } }
If you agree, I will send a formal patch.
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
hw/9pfs/9p.c +0
-0}#define P9_QID_TYPE_DIR 0x80
Quoted 74 lines · On Fri, 31 Mar 2017 09:26:35 +0800 Li Qiang <[email protected]> wrote:
Hello,
2017-03-30 23:46 GMT+08:00 Greg Kurz <[email protected]>:
Quoted 10 lines
Quoted 6 lines · On Thu, 30 Mar 2017 08:25:25 -0500 Eric Blake <[email protected]> wrote:
Quoted 1 line · Li Qiang
The guest can leave the
pdu->s->migration_blockerexists by attachs/exists/in place/
s/attach/attaching/Eric,
Thanks for pointing my mistakes!Quoted 9 lines
Quoted 2 lines
Quoted 1 line
but not remove a fid. Then if we hot unplug the 9pfs device, the
In theory you're right, but the current 9p client in linux won't let you hot
unplug the device unless you unmount the 9p share first, hence freeing the blocker.I think we should consider every possible situation.
Quoted 43 lines
Quoted 4 lines
s/remove/removing/
Quoted 2 lines
v9fs_reset()just free the fids, but not free themigration_blocker. This will leak a memory leak. This patch avoid this.I had a similar issue sitting my TODO list for quite a time: the blocker survives a
system_reset. It doesn't cause a memory leak but it prevents migration until the guest mounts/unmounts the 9p share again.This boils down to
virtfs_reset()callingfree_fid()instead ofput_fid()IIRC.Quoted 12 lines
s/leak a/cause a/
s/avoid/avoids/Quoted 5 lines
Signed-off-by Li Qiang <[email protected]>--- hw/9pfs/9p.c | 6 ++++++ 1 file changed, 6 insertions(+)Probably worth including in 2.9 as a bug fix.
Quoted 8 lines
Reviewed-by Eric Blake <[email protected]>hw/9pfs/9p.c static void coroutine_fn virtfs_reset(V9fsPDU
Quoted 6 lines
hw/9pfs/9p.c +0
-0@@ -548,6 +548,12 @@ static void coroutine_fn virtfs_reset(V9fsPDU*pdu)
Quoted 9 lines
Quoted 9 lines
hw/9pfs/9p.c +6
-0free_fid (pdu, fidp); } } + +if (pdu->s->migration_blocker) { +migrate_del_blocker (pdu->s->migration_blocker); +error_free (pdu->s->migration_blocker); + pdu->s->migration_blocker =NULL ; + }
Quoted 8 lines
Quoted 5 lines
I'd prefer to drain all PDUs in
virtfs_reset()and have the loop above to callput_fid()instead offree_fid(). If this isn't doable for 2.9, I'll apply this patch with a comment.Yes, I have considered to use
put_fid()to fix this. But I'm not sure the 'fidp->ref' is at most 1 invirtfs_reset()function(I think it is).
And indeed, if the fid is involved in an I/O then its ref will be != 0.
Quoted 2 lines
IIUC I think omit the 'else' branch, and call
put_fid()directly like this.
This won't work: we must ensure that fidp->ref reaches zero (ie, drain all PDUs), then we can fidp->ref++ (ie, get a ref on the fid) and call put_fid(), which will drop the last ref of the fid and clear the blocker if this is the root fid.
Quoted 27 lines
hw/9pfs/9p.c +1
-2@@ -544,9 +544,8 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu)if (fidp->ref) { fidp->clunked =1 ; - }else { -free_fid (pdu, fidp); } +put_fid (pdu, fidp); } }If you agree, I will send a formal patch.
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
hw/9pfs/9p.c +0
-0}#define P9_QID_TYPE_DIR 0x80
2017-03-31 15:07 GMT+08:00 Greg Kurz <[email protected]>:
Quoted 93 lines
Quoted 10 lines · On Fri, 31 Mar 2017 09:26:35 +0800 Li Qiang <[email protected]> wrote:
Hello,
2017-03-30 23:46 GMT+08:00 Greg Kurz <[email protected]>:
Quoted 6 lines
Quoted 3 lines · On Thu, 30 Mar 2017 08:25:25 -0500 Eric Blake <[email protected]> wrote:
Quoted 1 line · Li Qiang
The guest can leave the
pdu->s->migration_blockerexists by attachQuoted 13 lines
Quoted 4 lines
Quoted 3 lines
s/exists/in place/
s/attach/attaching/Eric,
Thanks for pointing my mistakes!Quoted 4 lines
Quoted 2 lines
Quoted 1 line
but not remove a fid. Then if we hot unplug the 9pfs device, the
In theory you're right, but the current 9p client in linux won't let
you
Quoted 2 lines
Quoted 2 lines
hot
unplug the device unless you unmount the 9p share first, hence freeingthe
Quoted 9 lines
Quoted 3 lines
blocker.
I think we should consider every possible situation.
Quoted 3 lines
Quoted 3 lines
s/remove/removing/
Quoted 1 line
v9fs_reset()just free the fids, but not free the
migration_blocker.Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
This will leak a memory leak. This patch avoid this.
I had a similar issue sitting my TODO list for quite a time: the
blocker
Quoted 4 lines
Quoted 4 lines
survives a
system_reset. It doesn't cause a memory leak but it prevents migration until the guest mounts/unmounts the 9p share again.This boils down to
virtfs_reset()callingfree_fid()instead of
put_fid()Quoted 33 lines
Quoted 33 lines
IIRC.
Quoted 12 lines
s/leak a/cause a/
s/avoid/avoids/Quoted 5 lines
Signed-off-by Li Qiang <[email protected]>--- hw/9pfs/9p.c | 6 ++++++ 1 file changed, 6 insertions(+)Probably worth including in 2.9 as a bug fix.
Quoted 8 lines
Reviewed-by Eric Blake <[email protected]>hw/9pfs/9p.c static void coroutine_fn virtfs_reset(V9fsPDU
Quoted 6 lines
hw/9pfs/9p.c +0
-0@@ -548,6 +548,12 @@ static void coroutine_fn virtfs_reset(V9fsPDU*pdu)
Quoted 9 lines
Quoted 9 lines
hw/9pfs/9p.c +6
-0free_fid (pdu, fidp); } } + +if (pdu->s->migration_blocker) { +migrate_del_blocker (pdu->s->migration_blocker); +error_free (pdu->s->migration_blocker); + pdu->s->migration_blocker =NULL ; + }Quoted 8 lines
Quoted 5 lines
I'd prefer to drain all PDUs in
virtfs_reset()and have the loop above to callput_fid()instead offree_fid(). If this isn't doable for 2.9, I'll apply this patch with a comment.Yes, I have considered to use
put_fid()to fix this. But I'm not sure the 'fidp->ref' is at most 1 invirtfs_reset()function(I think it is).And indeed, if the fid is involved in an I/O then its ref will be != 0.
Quoted 10 lines
Quoted 1 line
IIUC I think omit the 'else' branch, and call
put_fid()directly likethis.
Quoted 1 line
This won't work: we must ensure that
fidp->refreaches zero (ie, drain all PDUs), then we can fidp->ref++ (ie, get a ref on the fid) and callput_fid(), which will drop the last ref of the fid and clear the blocker if this is the root fid.
Right, but how can we ensure we have drained all PDUs? Any idea?
Thanks.
Quoted 29 lines
Quoted 27 lines
hw/9pfs/9p.c +1
-2@@ -544,9 +544,8 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu)if (fidp->ref) { fidp->clunked =1 ; - }else { -free_fid (pdu, fidp); } +put_fid (pdu, fidp); } }If you agree, I will send a formal patch.
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
hw/9pfs/9p.c +0
-0}#define P9_QID_TYPE_DIR 0x80
Quoted 99 lines · On Fri, 31 Mar 2017 16:01:15 +0800 Li Qiang <[email protected]> wrote:
2017-03-31 15:07 GMT+08:00 Greg Kurz <[email protected]>:
Quoted 97 lines
Quoted 10 lines · On Fri, 31 Mar 2017 09:26:35 +0800 Li Qiang <[email protected]> wrote:
Hello,
2017-03-30 23:46 GMT+08:00 Greg Kurz <[email protected]>:
Quoted 6 lines
Quoted 3 lines · On Thu, 30 Mar 2017 08:25:25 -0500 Eric Blake <[email protected]> wrote:
Quoted 1 line · Li Qiang
The guest can leave the
pdu->s->migration_blockerexists by attachQuoted 13 lines
Quoted 4 lines
Quoted 3 lines
s/exists/in place/
s/attach/attaching/Eric,
Thanks for pointing my mistakes!Quoted 4 lines
Quoted 2 lines
Quoted 1 line
but not remove a fid. Then if we hot unplug the 9pfs device, the
In theory you're right, but the current 9p client in linux won't let
you
Quoted 2 lines
Quoted 2 lines
hot
unplug the device unless you unmount the 9p share first, hence freeingthe
Quoted 9 lines
Quoted 3 lines
blocker.
I think we should consider every possible situation.
Quoted 3 lines
Quoted 3 lines
s/remove/removing/
Quoted 1 line
v9fs_reset()just free the fids, but not free the
migration_blocker.Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
This will leak a memory leak. This patch avoid this.
I had a similar issue sitting my TODO list for quite a time: the
blocker
Quoted 4 lines
Quoted 4 lines
survives a
system_reset. It doesn't cause a memory leak but it prevents migration until the guest mounts/unmounts the 9p share again.This boils down to
virtfs_reset()callingfree_fid()instead of
put_fid()Quoted 33 lines
Quoted 33 lines
IIRC.
Quoted 12 lines
s/leak a/cause a/
s/avoid/avoids/Quoted 5 lines
Signed-off-by Li Qiang <[email protected]>--- hw/9pfs/9p.c | 6 ++++++ 1 file changed, 6 insertions(+)Probably worth including in 2.9 as a bug fix.
Quoted 8 lines
Reviewed-by Eric Blake <[email protected]>hw/9pfs/9p.c static void coroutine_fn virtfs_reset(V9fsPDU
Quoted 6 lines
hw/9pfs/9p.c +0
-0@@ -548,6 +548,12 @@ static void coroutine_fn virtfs_reset(V9fsPDU*pdu)
Quoted 9 lines
Quoted 9 lines
hw/9pfs/9p.c +6
-0free_fid (pdu, fidp); } } + +if (pdu->s->migration_blocker) { +migrate_del_blocker (pdu->s->migration_blocker); +error_free (pdu->s->migration_blocker); + pdu->s->migration_blocker =NULL ; + }Quoted 8 lines
Quoted 5 lines
I'd prefer to drain all PDUs in
virtfs_reset()and have the loop above to callput_fid()instead offree_fid(). If this isn't doable for 2.9, I'll apply this patch with a comment.Yes, I have considered to use
put_fid()to fix this. But I'm not sure the 'fidp->ref' is at most 1 invirtfs_reset()function(I think it is).And indeed, if the fid is involved in an I/O then its ref will be != 0.
Quoted 1 line
IIUC I think omit the 'else' branch, and call
put_fid()directly likethis.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
This won't work: we must ensure that
fidp->refreaches zero (ie, drain all PDUs), then we can fidp->ref++ (ie, get a ref on the fid) and callput_fid(), which will drop the last ref of the fid and clear the blocker if this is the root fid.Right, but how can we ensure we have drained all PDUs? Any idea?
Yep, I'll send patches shorty and Cc you.
Quoted 33 lines
Thanks.
Quoted 29 lines
Quoted 27 lines
hw/9pfs/9p.c +1
-2@@ -544,9 +544,8 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu)if (fidp->ref) { fidp->clunked =1 ; - }else { -free_fid (pdu, fidp); } +put_fid (pdu, fidp); } }If you agree, I will send a formal patch.
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
hw/9pfs/9p.c +0
-0}#define P9_QID_TYPE_DIR 0x80