linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: volumes: Increase bioc pointer check
@ 2022-10-25  8:28 Li zeming
  2022-10-25  9:29 ` Nikolay Borisov
  2022-10-25  9:47 ` Qu Wenruo
  0 siblings, 2 replies; 5+ messages in thread
From: Li zeming @ 2022-10-25  8:28 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Li zeming

If kzalloc fails to allocate the bioc pointer, NULL is returned
directly.

Signed-off-by: Li zeming <zeming@nfschina.com>
---
 fs/btrfs/volumes.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 064ab2a79c80..f9cb815fe23d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5892,6 +5892,8 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_
 		 */
 		sizeof(u64) * (total_stripes),
 		GFP_NOFS|__GFP_NOFAIL);
+	if (!bioc)
+		return NULL;
 
 	atomic_set(&bioc->error, 0);
 	refcount_set(&bioc->refs, 1);
-- 
2.18.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: volumes: Increase bioc pointer check
  2022-10-25  8:28 [PATCH] btrfs: volumes: Increase bioc pointer check Li zeming
@ 2022-10-25  9:29 ` Nikolay Borisov
  2022-10-25  9:49   ` Qu Wenruo
  2022-10-25  9:47 ` Qu Wenruo
  1 sibling, 1 reply; 5+ messages in thread
From: Nikolay Borisov @ 2022-10-25  9:29 UTC (permalink / raw)
  To: Li zeming, clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel



On 25.10.22 г. 11:28 ч., Li zeming wrote:
> If kzalloc fails to allocate the bioc pointer, NULL is returned
> directly.
> 
> Signed-off-by: Li zeming <zeming@nfschina.com>

This patch clearly shows you haven't really understood the code. As is 
evident there is __GFP_NOFAIL flag so as per the guarantees for this 
flag we either loop infinitely trying to allocate a bioc or simply 
allocated it. So this check can never be triggered.

NAK
> ---
>   fs/btrfs/volumes.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 064ab2a79c80..f9cb815fe23d 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -5892,6 +5892,8 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_
>   		 */
>   		sizeof(u64) * (total_stripes),
>   		GFP_NOFS|__GFP_NOFAIL);
> +	if (!bioc)
> +		return NULL;
>   
>   	atomic_set(&bioc->error, 0);
>   	refcount_set(&bioc->refs, 1);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: volumes: Increase bioc pointer check
  2022-10-25  8:28 [PATCH] btrfs: volumes: Increase bioc pointer check Li zeming
  2022-10-25  9:29 ` Nikolay Borisov
@ 2022-10-25  9:47 ` Qu Wenruo
  2022-10-25 10:38   ` Li zeming
  1 sibling, 1 reply; 5+ messages in thread
From: Qu Wenruo @ 2022-10-25  9:47 UTC (permalink / raw)
  To: Li zeming, clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel



On 2022/10/25 16:28, Li zeming wrote:
> If kzalloc fails to allocate the bioc pointer, NULL is returned
> directly.

s/is returned/should be returned/

>
> Signed-off-by: Li zeming <zeming@nfschina.com>
> ---
>   fs/btrfs/volumes.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 064ab2a79c80..f9cb815fe23d 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -5892,6 +5892,8 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_
>   		 */
>   		sizeof(u64) * (total_stripes),
>   		GFP_NOFS|__GFP_NOFAIL);

I think you can also remove the __GFP_NOFAIL flag.

Especially the only caller is properly handling the error.

With that __GFP_NOFAIL flag there, it should not fail, but we can not
just rely on NOFAIL flag to save our asses.

Otherwise looks good to me.

With above two points fixed, you can add my tag:

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> +	if (!bioc)
> +		return NULL;
>
>   	atomic_set(&bioc->error, 0);
>   	refcount_set(&bioc->refs, 1);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: volumes: Increase bioc pointer check
  2022-10-25  9:29 ` Nikolay Borisov
@ 2022-10-25  9:49   ` Qu Wenruo
  0 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2022-10-25  9:49 UTC (permalink / raw)
  To: Nikolay Borisov, Li zeming, clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel



On 2022/10/25 17:29, Nikolay Borisov wrote:
>
>
> On 25.10.22 г. 11:28 ч., Li zeming wrote:
>> If kzalloc fails to allocate the bioc pointer, NULL is returned
>> directly.
>>
>> Signed-off-by: Li zeming <zeming@nfschina.com>
>
> This patch clearly shows you haven't really understood the code. As is
> evident there is __GFP_NOFAIL flag so as per the guarantees for this
> flag we either loop infinitely trying to allocate a bioc or simply
> allocated it. So this check can never be triggered.

I guess what he missed is just to also remove that NOFAIL flag.

NOFAIL will not 100% guarantee the allocation, and I don't see this
location to be so important, especially when the only caller is already
handing allocation failure.

Thanks,
Qu

>
> NAK
>> ---
>>   fs/btrfs/volumes.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index 064ab2a79c80..f9cb815fe23d 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -5892,6 +5892,8 @@ static struct btrfs_io_context
>> *alloc_btrfs_io_context(struct btrfs_fs_info *fs_
>>            */
>>           sizeof(u64) * (total_stripes),
>>           GFP_NOFS|__GFP_NOFAIL);
>> +    if (!bioc)
>> +        return NULL;
>>       atomic_set(&bioc->error, 0);
>>       refcount_set(&bioc->refs, 1);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: volumes: Increase bioc pointer check
  2022-10-25  9:47 ` Qu Wenruo
@ 2022-10-25 10:38   ` Li zeming
  0 siblings, 0 replies; 5+ messages in thread
From: Li zeming @ 2022-10-25 10:38 UTC (permalink / raw)
  To: quwenruo.btrfs; +Cc: clm, dsterba, josef, linux-btrfs, linux-kernel


very thankful. I have fixed these two problems and am ready to release v2 patches.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-25 10:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25  8:28 [PATCH] btrfs: volumes: Increase bioc pointer check Li zeming
2022-10-25  9:29 ` Nikolay Borisov
2022-10-25  9:49   ` Qu Wenruo
2022-10-25  9:47 ` Qu Wenruo
2022-10-25 10:38   ` Li zeming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).