xfs: handle register_shrinker error
PATCH 1/1 xfs: handle register_shrinker error
From: Michal Hocko <[email protected]>
xfs_alloc_buftarg doesn't handle register_shrinker error path. While it is unlikely to trigger it is not impossible especially with large NUMAs. Let's handle the failure to make the code more robust.
---
Hi,
this is not tested but it looks quite straightforward. There is one more unchecked register_shrinker in xfs_qm_init_quotainfo but my absolute lack of familiarity with the code didn't allow me to come up with a mechanical fix like this one.
fs/xfs/xfs_buf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/xfs/xfs_buf.c +4 -1
@@ -1827,7 +1827,10 @@ xfs_alloc_buftarg( btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks =DEFAULT_SEEKS ; btp->bt_shrinker.flags =SHRINKER_NUMA_AWARE ; -register_shrinker (&btp->bt_shrinker); +if (register_shrinker (&btp->bt_shrinker)) { +percpu_counter_destroy (&btp->bt_io_count); + goto error; + }return btp; error:
Signature · 1 line
2.15.0
Quoted 3 lines · Christoph Hellwig
Looks good,
Reviewed-by Christoph Hellwig <[email protected]>
Thanks!
Quoted 1 line
I can take a stab at the quota one.
That would be really great!
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 11 lines · Michal Hocko
Quoted 3 lines · Christoph Hellwig
Looks good,
Reviewed-by Christoph Hellwig <[email protected]>Thanks!
Quoted 1 line
I can take a stab at the quota one.
That would be really great!
Again, it does not look good. Since kmem_free() does only kvfree(), nothing will release memory allocated by list_lru_init().
Quoted 6 lines · Tetsuo Handa
Quoted 5 lines · Michal Hocko
Quoted 3 lines · Christoph Hellwig
Looks good,
Reviewed-by Christoph Hellwig <[email protected]>
Quoted 8 lines
Quoted 6 lines
Thanks!
Quoted 1 line
I can take a stab at the quota one.
That would be really great!
Again, it does not look good. Since
kmem_free()does onlykvfree(), nothing will release memory allocated bylist_lru_init().
Hmm, you are right. I have (blindly) followed the current code flow which is wrong as well. The following should do the trick. Should I split that into two patches?
---
fs/xfs/xfs_buf.c +10 -8
@@ -1815,25 +1815,27 @@ xfs_alloc_buftarg( btp->bt_daxdev = dax_dev;if (xfs_setsize_buftarg_early (btp, bdev)) - goto error; + goto error_free;if (list_lru_init (&btp->bt_lru)) - goto error; + goto error_free;if (percpu_counter_init (&btp->bt_io_count,0 ,GFP_KERNEL )) - goto error; + goto error_lru; btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks =DEFAULT_SEEKS ; btp->bt_shrinker.flags =SHRINKER_NUMA_AWARE ; -if (register_shrinker (&btp->bt_shrinker)) { -percpu_counter_destroy (&btp->bt_io_count); - goto error; - } +if (register_shrinker (&btp->bt_shrinker)) + goto error_pcpu;return btp; -error: +error_pcpu: +percpu_counter_destroy (&btp->bt_io_count); +error_lru: +list_lru_destroy (&btp->bt_lru); +error_free:kmem_free (btp);return NULL ; }
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 3 lines · Michal Hocko
Hmm, you are right. I have (blindly) followed the current code flow which is wrong as well. The following should do the trick. Should I split that into two patches?
Well, xfs_alloc_buftarg() needs to be more careful.
xfs_alloc_buftarg(
struct xfs_mount *mp,
struct block_device *bdev,
struct dax_device *dax_dev)
{
xfs_buftarg_t *btp;
btp = kmem_zalloc(sizeof(*btp), KM_SLEEP | KM_NOFS); // This is GFP_NOFS context. But...
btp->bt_mount = mp;
btp->bt_dev = bdev->bd_dev;
btp->bt_bdev = bdev;
btp->bt_daxdev = dax_dev;
if (xfs_setsize_buftarg_early(btp, bdev))
goto error;
if (list_lru_init(&btp->bt_lru)) // This is GFP_KERNEL context.
goto error;
if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL)) // This is GFP_KERNEL context.
goto error; // Need to undo list_lru_init() before kmem_free().
btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count;
btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan;
btp->bt_shrinker.seeks = DEFAULT_SEEKS;
btp->bt_shrinker.flags = SHRINKER_NUMA_AWARE;
register_shrinker(&btp->bt_shrinker); // This is GFP_KERNEL context.
return btp;error:
kmem_free(btp);
return NULL;
}Quoted 6 lines · Tetsuo Handa
Quoted 3 lines · Michal Hocko
Hmm, you are right. I have (blindly) followed the current code flow which is wrong as well. The following should do the trick. Should I split that into two patches?
Well,
xfs_alloc_buftarg()needs to be more careful.
[...]
Quoted 1 line
btp =
kmem_zalloc(sizeof(*btp), KM_SLEEP | KM_NOFS); // This isGFP_NOFScontext. But...
[...]
Quoted 1 line
if (list_lru_init(&btp->bt_lru)) // This is GFP_KERNEL context.
this sounds like a separate thing to cleanup or document.
Signature · 2 lines
Michal Hocko SUSE Labs
Dave Chinner
Acked-byQuoted 11 lines · Michal Hocko
Quoted 10 lines · Tetsuo Handa
Quoted 9 lines · Michal Hocko
Quoted 3 lines · Christoph Hellwig
Looks good,
Reviewed-by Christoph Hellwig <[email protected]>Thanks!
Quoted 1 line
I can take a stab at the quota one.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
That would be really great!
Again, it does not look good. Since
kmem_free()does onlykvfree(), nothing will release memory allocated bylist_lru_init().Hmm, you are right. I have (blindly) followed the current code flow which is wrong as well. The following should do the trick. Should I split that into two patches?
One is fine by me - if we're need to backport one fix, then we need to backport both :/
Quoted 30 lines
---
fs/xfs/xfs_buf.c +5
-7@@ -1815,25 +1815,27 @@ xfs_alloc_buftarg( btp->bt_daxdev = dax_dev;if (xfs_setsize_buftarg_early (btp, bdev)) - goto error; + goto error_free;if (list_lru_init (&btp->bt_lru)) - goto error; + goto error_free;if (percpu_counter_init (&btp->bt_io_count,0 ,GFP_KERNEL )) - goto error; + goto error_lru; btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks =DEFAULT_SEEKS ; btp->bt_shrinker.flags =SHRINKER_NUMA_AWARE ; -if (register_shrinker (&btp->bt_shrinker)) { -percpu_counter_destroy (&btp->bt_io_count); - goto error; - } +if (register_shrinker (&btp->bt_shrinker)) + goto error_pcpu;
fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1840
Quoted 10 lines
fs/xfs/xfs_buf.c +5
-1return btp; -error: +error_pcpu: +percpu_counter_destroy (&btp->bt_io_count); +error_lru: +list_lru_destroy (&btp->bt_lru); +error_free:kmem_free (btp);return NULL ;
That should do the trick.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v2 1/1 xfs: handle register_shrinker error
Quoted 17 lines · Dave Chinner
Quoted 16 lines · Michal Hocko
Quoted 14 lines · Tetsuo Handa
Quoted 11 lines · Michal Hocko
Quoted 3 lines · Christoph Hellwig
Looks good,
Reviewed-by Christoph Hellwig <[email protected]>Thanks!
Quoted 1 line
I can take a stab at the quota one.
That would be really great!
Again, it does not look good. Since
kmem_free()does onlykvfree(), nothing will release memory allocated bylist_lru_init().
Quoted 6 lines
Quoted 3 lines
Hmm, you are right. I have (blindly) followed the current code flow which is wrong as well. The following should do the trick. Should I split that into two patches?
One is fine by me - if we're need to backport one fix, then we need to backport both :/
OK
Quoted 43 lines
Quoted 30 lines
---
fs/xfs/xfs_buf.c +5
-7@@ -1815,25 +1815,27 @@ xfs_alloc_buftarg( btp->bt_daxdev = dax_dev;if (xfs_setsize_buftarg_early (btp, bdev)) - goto error; + goto error_free;if (list_lru_init (&btp->bt_lru)) - goto error; + goto error_free;if (percpu_counter_init (&btp->bt_io_count,0 ,GFP_KERNEL )) - goto error; + goto error_lru; btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks =DEFAULT_SEEKS ; btp->bt_shrinker.flags =SHRINKER_NUMA_AWARE ; -if (register_shrinker (&btp->bt_shrinker)) { -percpu_counter_destroy (&btp->bt_io_count); - goto error; - } +if (register_shrinker (&btp->bt_shrinker)) + goto error_pcpu;fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1840
Quoted 10 lines
fs/xfs/xfs_buf.c +5
-1return btp; -error: +error_pcpu: +percpu_counter_destroy (&btp->bt_io_count); +error_lru: +list_lru_destroy (&btp->bt_lru); +error_free:kmem_free (btp);return NULL ;That should do the trick.
Quoted 1 line
Acked-by Dave Chinner <[email protected]>
Thanks. Updated patch below
---
Quoted 1 line
From
1009db61988c48c9a9e327a9d076945b29b02eeeMon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 23 Nov 2017 17:13:40 +0100
Subject: [PATCH] xfs: fortify xfs_alloc_buftarg error handling
percpu_counter_init failure path doesn't clean up &btp->bt_lru list. Call list_lru_destroy in that error path. Similarly register_shrinker error path is not handled.
While it is unlikely to trigger these error path, it is not impossible especially the later might fail with large NUMAs. Let's handle the failure to make the code more robust.
--- fs/xfs/xfs_buf.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
fs/xfs/xfs_buf.c +10 -5
@@ -1815,22 +1815,27 @@ xfs_alloc_buftarg( btp->bt_daxdev = dax_dev;if (xfs_setsize_buftarg_early (btp, bdev)) - goto error; + goto error_free;if (list_lru_init (&btp->bt_lru)) - goto error; + goto error_free;if (percpu_counter_init (&btp->bt_io_count,0 ,GFP_KERNEL )) - goto error; + goto error_lru; btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks =DEFAULT_SEEKS ; btp->bt_shrinker.flags =SHRINKER_NUMA_AWARE ; -register_shrinker (&btp->bt_shrinker); +if (register_shrinker (&btp->bt_shrinker)) + goto error_pcpu;return btp; -error: +error_pcpu: +percpu_counter_destroy (&btp->bt_io_count); +error_lru: +list_lru_destroy (&btp->bt_lru); +error_free:kmem_free (btp);return NULL ; }
Signature · 5 lines
2.15.0 -- Michal Hocko SUSE Labs
Quoted 6 lines · Michal Hocko
Thanks. Updated patch below
---
From1009db61988c48c9a9e327a9d076945b29b02eeeMon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 23 Nov 2017 17:13:40 +0100
Subject: [PATCH] xfs: fortifyxfs_alloc_buftargerror handling
Do we need below patch on top of Michal's patch?KM_NOFS was added by commit b17cb364dbbbf65a ("xfs: fix missing KM_NOFS tags to keep lockdep happy"). If not needed, some comment is expected.
--- fs/xfs/xfs_buf.c | 3 +++ 1 file changed, 3 insertions(+)
fs/xfs/xfs_buf.c +3 -0
@@ -1806,6 +1806,7 @@ struct xfs_buf * struct dax_device *dax_dev) {xfs_buftarg_t *btp; +unsigned int nofs_flag =memalloc_nofs_save (); btp =kmem_zalloc (sizeof (*btp),KM_SLEEP |KM_NOFS );
@@ -1829,6 +1830,7 @@ struct xfs_buf * btp->bt_shrinker.flags =SHRINKER_NUMA_AWARE ;if (register_shrinker (&btp->bt_shrinker)) goto error_pcpu; +memalloc_nofs_restore (nofs_flag);return btp; error_pcpu:
@@ -1837,6 +1839,7 @@ struct xfs_buf *list_lru_destroy (&btp->bt_lru); error_free:kmem_free (btp); +memalloc_nofs_restore (nofs_flag);return NULL ; }
Signature · 1 line
1.8.3.1
Quoted 11 lines · Tetsuo Handa
Quoted 6 lines · Michal Hocko
Thanks. Updated patch below
---
From1009db61988c48c9a9e327a9d076945b29b02eeeMon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 23 Nov 2017 17:13:40 +0100
Subject: [PATCH] xfs: fortifyxfs_alloc_buftargerror handlingDo we need below patch on top of Michal's patch?
KM_NOFSwas added by commitb17cb364dbbbf65a("xfs: fix missingKM_NOFStags to keep lockdep happy"). If not needed, some comment is expected.
I am not not familiar with the code but git blame says that the whole point of NOFS here was to make lockdep happy. We do have means to silence the warning if the original concern still applies.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 11 lines · Tetsuo Handa
Quoted 6 lines · Michal Hocko
Thanks. Updated patch below
---
From1009db61988c48c9a9e327a9d076945b29b02eeeMon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 23 Nov 2017 17:13:40 +0100
Subject: [PATCH] xfs: fortifyxfs_alloc_buftargerror handlingDo we need below patch on top of Michal's patch?
KM_NOFSwas added by commitb17cb364dbbbf65a("xfs: fix missingKM_NOFStags to keep lockdep happy"). If not needed, some comment is expected.
Quite frankly, if the fix is "sprinkle magic undocumented memalloc_nofs_save() calls around", then you need to think a little more about the things you just read and the context we're operating on here.
IOWs:
Quoted 9 lines
--- fs/xfs/xfs_buf.c | 3 +++ 1 file changed, 3 insertions(+)fs/xfs/xfs_buf.c +0
-0
fs/xfs/xfs_buf.c struct xfs_buf * · line 1811
Quoted 6 lines
fs/xfs/xfs_buf.c +1
-0@@ -1806,6 +1806,7 @@ struct xfs_buf * struct dax_device *dax_dev) {xfs_buftarg_t *btp; +unsigned int nofs_flag =memalloc_nofs_save (); btp =kmem_zalloc (sizeof (*btp),KM_SLEEP |KM_NOFS );
xfs_alloc_buftarg() isn't called from transaction context, so this KM_NOFS flag wasn't added to prevent reclaim deadlocks - it was added to avoid stupid lockdep false positives (as was stated in the commit you quoted).
IOWs, GFP_KERNEL allocations in this function used to trigger lockdep false positives.
So - think for a minute rather than bashing on the keyboard. Why aren't the other GFP_KERNEL allocations from this function causing lockdep to trigger warnings?
Yeah - lockdep is a lot smarter these days and the false positive trigger has clearly been fixed. i.e. there's no false positive detection occurring here any more under GFP_KERNEL allocations, so we don't need the KM_NOFS flag anymore.
IOWs, we don't actually need to touch this code, but if you really must, just remove the KM_NOFS tag.
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 2 lines · Dave Chinner
IOWs, we don't actually need to touch this code, but if you really must, just remove the
KM_NOFStag.
OK. Then, please remove KM_NOFS. GFP_KERNEL is safer than GFP_NOFS in the sense that it won't cause OOM lockup due to unable to invoke the OOM killer.
Quoted 7 lines · Tetsuo Handa
Quoted 2 lines · Dave Chinner
IOWs, we don't actually need to touch this code, but if you really must, just remove the
KM_NOFStag.OK. Then, please remove
KM_NOFS.GFP_KERNELis safer thanGFP_NOFSin the sense that it won't cause OOM lockup due to unable to invoke the OOM killer.
I agree that we should remove nofs request if they are not really needed. But arguing your usual OOM lockup is (again) over exaggerating. As a rule of thumb, it is almost always better to have the full reclaim context rather than reduced one because the later one can influence other parts of the system as they might need to do more work.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 120 lines · Michal Hocko
Quoted 17 lines · Dave Chinner
Quoted 16 lines · Michal Hocko
Quoted 14 lines · Tetsuo Handa
Quoted 11 lines · Michal Hocko
Quoted 3 lines · Christoph Hellwig
Looks good,
Reviewed-by Christoph Hellwig <[email protected]>Thanks!
Quoted 1 line
I can take a stab at the quota one.
That would be really great!
Again, it does not look good. Since
kmem_free()does onlykvfree(), nothing will release memory allocated bylist_lru_init().Quoted 6 lines
Quoted 3 lines
Hmm, you are right. I have (blindly) followed the current code flow which is wrong as well. The following should do the trick. Should I split that into two patches?
One is fine by me - if we're need to backport one fix, then we need to backport both :/
OK
Quoted 43 lines
Quoted 30 lines
---
fs/xfs/xfs_buf.c +5
-7@@ -1815,25 +1815,27 @@ xfs_alloc_buftarg( btp->bt_daxdev = dax_dev;if (xfs_setsize_buftarg_early (btp, bdev)) - goto error; + goto error_free;if (list_lru_init (&btp->bt_lru)) - goto error; + goto error_free;if (percpu_counter_init (&btp->bt_io_count,0 ,GFP_KERNEL )) - goto error; + goto error_lru; btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks =DEFAULT_SEEKS ; btp->bt_shrinker.flags =SHRINKER_NUMA_AWARE ; -if (register_shrinker (&btp->bt_shrinker)) { -percpu_counter_destroy (&btp->bt_io_count); - goto error; - } +if (register_shrinker (&btp->bt_shrinker)) + goto error_pcpu;fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1840
Quoted 10 lines
fs/xfs/xfs_buf.c +5
-1return btp; -error: +error_pcpu: +percpu_counter_destroy (&btp->bt_io_count); +error_lru: +list_lru_destroy (&btp->bt_lru); +error_free:kmem_free (btp);return NULL ;That should do the trick.
Quoted 1 line
Acked-by Dave Chinner <[email protected]>Thanks. Updated patch below
---
From1009db61988c48c9a9e327a9d076945b29b02eeeMon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 23 Nov 2017 17:13:40 +0100
Subject: [PATCH] xfs: fortifyxfs_alloc_buftargerror handling
percpu_counter_initfailure path doesn't clean up&btp->bt_lrulist. Calllist_lru_destroyin that error path. Similarlyregister_shrinkererror path is not handled.While it is unlikely to trigger these error path, it is not impossible especially the later might fail with large NUMAs. Let's handle the failure to make the code more robust.
Acked-by Dave Chinner <[email protected]>Noticed-by Tetsuo Handa <[email protected]>Signed-off-by Michal Hocko <[email protected]>--- fs/xfs/xfs_buf.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)fs/xfs/xfs_buf.c +5
-4@@ -1815,22 +1815,27 @@ xfs_alloc_buftarg( btp->bt_daxdev = dax_dev;if (xfs_setsize_buftarg_early (btp, bdev)) - goto error; + goto error_free;if (list_lru_init (&btp->bt_lru)) - goto error; + goto error_free;if (percpu_counter_init (&btp->bt_io_count,0 ,GFP_KERNEL )) - goto error; + goto error_lru; btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks =DEFAULT_SEEKS ; btp->bt_shrinker.flags =SHRINKER_NUMA_AWARE ; -register_shrinker (&btp->bt_shrinker); +if (register_shrinker (&btp->bt_shrinker)) + goto error_pcpu;
fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1840
Quoted 10 lines
fs/xfs/xfs_buf.c +5
-1return btp; -error: +error_pcpu: +percpu_counter_destroy (&btp->bt_io_count); +error_lru: +list_lru_destroy (&btp->bt_lru); +error_free:kmem_free (btp);return NULL ;
This part looks ok,
Quoted 11 lines
fs/xfs/xfs_buf.c +0
-0}Signature · 9 lines
2.15.0 -- Michal Hocko SUSE Labs -- 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
On Mon 27-11-17 09:44:53, Darrick J. Wong wrote:
[...]
Quoted 58 lines
Quoted 46 lines
From
1009db61988c48c9a9e327a9d076945b29b02eeeMon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 23 Nov 2017 17:13:40 +0100
Subject: [PATCH] xfs: fortifyxfs_alloc_buftargerror handling
percpu_counter_initfailure path doesn't clean up&btp->bt_lrulist. Calllist_lru_destroyin that error path. Similarlyregister_shrinkererror path is not handled.While it is unlikely to trigger these error path, it is not impossible especially the later might fail with large NUMAs. Let's handle the failure to make the code more robust.
Acked-by Dave Chinner <[email protected]>Noticed-by Tetsuo Handa <[email protected]>Signed-off-by Michal Hocko <[email protected]>--- fs/xfs/xfs_buf.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)fs/xfs/xfs_buf.c +5
-4@@ -1815,22 +1815,27 @@ xfs_alloc_buftarg( btp->bt_daxdev = dax_dev;if (xfs_setsize_buftarg_early (btp, bdev)) - goto error; + goto error_free;if (list_lru_init (&btp->bt_lru)) - goto error; + goto error_free;if (percpu_counter_init (&btp->bt_io_count,0 ,GFP_KERNEL )) - goto error; + goto error_lru; btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks =DEFAULT_SEEKS ; btp->bt_shrinker.flags =SHRINKER_NUMA_AWARE ; -register_shrinker (&btp->bt_shrinker); +if (register_shrinker (&btp->bt_shrinker)) + goto error_pcpu;fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1840
Quoted 10 lines
fs/xfs/xfs_buf.c +5
-1return btp; -error: +error_pcpu: +percpu_counter_destroy (&btp->bt_io_count); +error_lru: +list_lru_destroy (&btp->bt_lru); +error_free:kmem_free (btp);return NULL ;This part looks ok,
Quoted 1 line
Reviewed-by Darrick J. Wong <[email protected]>
Are you going to apply the patch or should I re-send it with acks/reviewed-by?
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 62 lines · Michal Hocko
On Mon 27-11-17 09:44:53, Darrick J. Wong wrote:
[...]Quoted 58 lines
Quoted 46 lines
From
1009db61988c48c9a9e327a9d076945b29b02eeeMon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 23 Nov 2017 17:13:40 +0100
Subject: [PATCH] xfs: fortifyxfs_alloc_buftargerror handling
percpu_counter_initfailure path doesn't clean up&btp->bt_lrulist. Calllist_lru_destroyin that error path. Similarlyregister_shrinkererror path is not handled.While it is unlikely to trigger these error path, it is not impossible especially the later might fail with large NUMAs. Let's handle the failure to make the code more robust.
Acked-by Dave Chinner <[email protected]>Noticed-by Tetsuo Handa <[email protected]>Signed-off-by Michal Hocko <[email protected]>--- fs/xfs/xfs_buf.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)fs/xfs/xfs_buf.c +5
-4@@ -1815,22 +1815,27 @@ xfs_alloc_buftarg( btp->bt_daxdev = dax_dev;if (xfs_setsize_buftarg_early (btp, bdev)) - goto error; + goto error_free;if (list_lru_init (&btp->bt_lru)) - goto error; + goto error_free;if (percpu_counter_init (&btp->bt_io_count,0 ,GFP_KERNEL )) - goto error; + goto error_lru; btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks =DEFAULT_SEEKS ; btp->bt_shrinker.flags =SHRINKER_NUMA_AWARE ; -register_shrinker (&btp->bt_shrinker); +if (register_shrinker (&btp->bt_shrinker)) + goto error_pcpu;fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1840
Quoted 10 lines
fs/xfs/xfs_buf.c +5
-1return btp; -error: +error_pcpu: +percpu_counter_destroy (&btp->bt_io_count); +error_lru: +list_lru_destroy (&btp->bt_lru); +error_free:kmem_free (btp);return NULL ;This part looks ok,
Quoted 1 line
Reviewed-by Darrick J. Wong <[email protected]>
Quoted 2 lines
Are you going to apply the patch or should I re-send it with acks/reviewed-by?
I injected all of those when I added the patch to my tree:
--D
Quoted 7 lines
Signature · 6 lines
Michal Hocko SUSE Labs -- 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
Quoted 1 line · Darrick J. Wong
On Tue, Nov 28, 2017 at 10:35:51AM +0100, Michal Hocko wrote:
[...]
Quoted 10 lines
Quoted 2 lines
Are you going to apply the patch or should I re-send it with acks/reviewed-by?
I injected all of those when I added the patch to my tree:
Noticed-by Tetsuo Handa <[email protected]>Signed-off-by Michal Hocko <[email protected]>Acked-by Dave Chinner <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Signed-off-by Darrick J. Wong <[email protected]>
Thanks!
Signature · 2 lines
Michal Hocko SUSE Labs