Re: [PATCH 1/5] debugobjects: Fix the misuse of global variables in fill_pool()
From: Leizhen (ThunderTown)
Date: Tue Sep 03 2024 - 07:15:00 EST
On 2024/9/3 17:37, Thomas Gleixner wrote:
> On Tue, Sep 03 2024 at 15:00, Leizhen wrote:
>>>> @@ -84,10 +85,7 @@ static int __data_racy debug_objects_fixups __read_mostly;
>>>> static int __data_racy debug_objects_warnings __read_mostly;
>>>> static int __data_racy debug_objects_enabled __read_mostly
>>>> = CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT;
>>>> -static int __data_racy debug_objects_pool_size __read_mostly
>>>> - = ODEBUG_POOL_SIZE;
>>>> -static int __data_racy debug_objects_pool_min_level __read_mostly
>>>> - = ODEBUG_POOL_MIN_LEVEL;
>>>> +static int __data_racy obj_pool_min_free = ODEBUG_POOL_SIZE;
>>
>> Sorry, I rechecked it again. After this patch, obj_pool_min_free is referenced in the
>> same way as obj_pool_max_used. The only race point is located in debug_stats_show().
>> However, this reference point does not need to be included in the race analysis. So
>> there is no need to add __data_racy for obj_pool_min_free.
>
> The read races against the write, so KCSAN can detect it and complain, no?
Oh, I just saw that there were a lot of other global variables in that function
that didn't mask KCSAN's detection. So I'll recheck each global variable.
However, for obj_pool_min_free, it seems that it would be better to just add
READ_ONCE() in debug_stats_show(). This does not prevent the compiler from
optimizing variable references in the lock.
# define __data_racy volatile
>
> Thanks,
>
> tglx
> .
>
--
Regards,
Zhen Lei