Re: [PATCH v4] f2fs: fix to avoid race during access gc_thread pointer

From: Jaegeuk Kim
Date: Mon May 07 2018 - 17:36:18 EST


On 05/07, Chao Yu wrote:
> Thread A Thread B Thread C
> - f2fs_remount
> - stop_gc_thread
> - f2fs_sbi_store
> - issue_discard_thread
> sbi->gc_thread = NULL;
> sbi->gc_thread->gc_wake = 1
> access sbi->gc_thread->gc_urgent
>
> Previously, we allocate memory for sbi->gc_thread based on background
> gc thread mount option, the memory can be released if we turn off
> that mount option, but still there are several places access gc_thread
> pointer without considering race condition, result in NULL point
> dereference.
>
> In order to fix this issue, introduce gc_rwsem to exclude those operations.
>
> Signed-off-by: Chao Yu <yuchao0@xxxxxxxxxx>
> ---
> v4:
> - use introduced sbi.gc_rwsem lock instead of sb.s_umount.

We can use this first.