lkml.org 
[lkml]   [2022]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] mm: ksm: fix data-race in __ksm_enter / run_store
On Tue, Aug 02, 2022 at 11:15:50PM +0800, Kefeng Wang wrote:
> The ksm_run is alread protected by ksm_thread_mutex in run_store, we
> could add this lock in __ksm_enter() to avoid the above issue.

I don't think this is a great fix. Why not protect the store with
ksm_mmlist_lock? ie:

mutex_lock(&ksm_thread_mutex);
wait_while_offlining();
if (ksm_run != flags) {
+ spin_lock(&ksm_mmlist_lock);
ksm_run = flags;
+ spin_unlock(&ksm_mmlist_lock);
if (flags & KSM_RUN_UNMERGE) {
set_current_oom_origin();
err = unmerge_and_remove_all_rmap_items();
clear_current_oom_origin();
if (err) {
+ spin_lock(&ksm_mmlist_lock);
ksm_run = KSM_RUN_STOP;
+ spin_unlock(&ksm_mmlist_lock);
...

(I also don't think this is a real bug, because the call to
unmerge_and_remove_all_rmap_items() will "cure" the misplacement of
items in the list, but there's value in shutting up the tools, I suppose)

\
 
 \ /
  Last update: 2022-08-02 17:46    [W:0.084 / U:0.232 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site