Skip to contentSkip to conversation

xfs: Fix leak of discard bio

PATCH In review Jan Kara 4 participants 5 messages Aug 2, 2017 – Aug 5, 2017

Subsystems (2)
lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 xfs: Fix leak of discard bio

The bio describing discard operation is allocated by __blkdev_issue_discard() which returns us a reference to it. That reference is never released and thus we leak this bio. Drop the bio reference once it completes in xlog_discard_endio().

Fixes 4560e78f40cb55bd2ea8f1ef4001c5baa88531c7
---
 fs/xfs/xfs_log_cil.c | 1 +
 1 file changed, 1 insertion(+)

Note, this is untested. It's just something I've noticed when looking at the code.

fs/xfs/xfs_log_cil.c +1 -0
index fbe72b134bef..43aa42a3a5d3 100644
@@ -539,6 +539,7 @@ xlog_discard_endio(
 
 	INIT_WORK(&ctx->discard_endio_work, xlog_discard_endio_work);
 	queue_work(xfs_discard_wq, &ctx->discard_endio_work);
+	bio_put(bio);
 }
 
 static void
Signature · 1 line
2.12.3
#1 lore raw
Quoted 20 lines · Jan Kara

The bio describing discard operation is allocated by __blkdev_issue_discard() which returns us a reference to it. That reference is never released and thus we leak this bio. Drop the bio reference once it completes in xlog_discard_endio().

Fixes 4560e78f40cb55bd2ea8f1ef4001c5baa88531c7
---
 fs/xfs/xfs_log_cil.c | 1 +
 1 file changed, 1 insertion(+)

Note, this is untested. It's just something I've noticed when looking at the code.

fs/xfs/xfs_log_cil.c +0 -0
index fbe72b134bef..43aa42a3a5d3 100644

fs/xfs/xfs_log_cil.c xlog_discard_endio( · line 543

Quoted 5 lines
fs/xfs/xfs_log_cil.c +1 -0
@@ -539,6 +539,7 @@ xlog_discard_endio(
 
 	INIT_WORK(&ctx->discard_endio_work, xlog_discard_endio_work);
 	queue_work(xfs_discard_wq, &ctx->discard_endio_work);
+	bio_put(bio);
 }

At a quick glance, it does seem that we are leaking the bio here. It appears to me that ext4_process_freed_data() also has the same problem and leaks the discard_bio....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
author
#2 lore raw
Quoted 22 lines · Dave Chinner
Quoted 21 lines · Jan Kara

The bio describing discard operation is allocated by __blkdev_issue_discard() which returns us a reference to it. That reference is never released and thus we leak this bio. Drop the bio reference once it completes in xlog_discard_endio().

Fixes 4560e78f40cb55bd2ea8f1ef4001c5baa88531c7
---
 fs/xfs/xfs_log_cil.c | 1 +
 1 file changed, 1 insertion(+)

Note, this is untested. It's just something I've noticed when looking at the code.

fs/xfs/xfs_log_cil.c +0 -0
index fbe72b134bef..43aa42a3a5d3 100644
@@ -539,6 +539,7 @@ xlog_discard_endio(
 
Quoted 8 lines

fs/xfs/xfs_log_cil.c xlog_discard_endio( · line 543

Quoted 4 lines
fs/xfs/xfs_log_cil.c +1 -0
 	INIT_WORK(&ctx->discard_endio_work, xlog_discard_endio_work);
 	queue_work(xfs_discard_wq, &ctx->discard_endio_work);
+	bio_put(bio);
 }

At a quick glance, it does seem that we are leaking the bio here. It appears to me that ext4_process_freed_data() also has the same problem and leaks the discard_bio....

Yes, and a fix of that prompted me to look into how XFS does things ;)

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
Reviewed-by on v1 1/1
#3 lore raw
In reply to Jan Kara
Quoted 20 lines · Jan Kara

The bio describing discard operation is allocated by __blkdev_issue_discard() which returns us a reference to it. That reference is never released and thus we leak this bio. Drop the bio reference once it completes in xlog_discard_endio().

Fixes 4560e78f40cb55bd2ea8f1ef4001c5baa88531c7
---
 fs/xfs/xfs_log_cil.c | 1 +
 1 file changed, 1 insertion(+)

Note, this is untested. It's just something I've noticed when looking at the code.

fs/xfs/xfs_log_cil.c +0 -0
index fbe72b134bef..43aa42a3a5d3 100644

fs/xfs/xfs_log_cil.c xlog_discard_endio( · line 542

Quoted 4 lines
fs/xfs/xfs_log_cil.c +1 -0
@@ -539,6 +539,7 @@ xlog_discard_endio(
 
 	INIT_WORK(&ctx->discard_endio_work, xlog_discard_endio_work);
 	queue_work(xfs_discard_wq, &ctx->discard_endio_work);
+	bio_put(bio);

It would seem that we /do/ leak the bio here. :(

--D

Quoted 10 lines
fs/xfs/xfs_log_cil.c +0 -0
 }
 
 static void
Signature · 6 lines
2.12.3

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html