linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
	Abhishek Shah <abhishek.shah@columbia.edu>,
	Gabriel Ryan <gabe@cs.columbia.edu>
Subject: Re: [PATCH] mm: ksm: fix data-race in __ksm_enter / run_store
Date: Thu, 11 Aug 2022 16:00:20 -0700	[thread overview]
Message-ID: <20220811160020.1e6823094217e8d6d3aaebdf@linux-foundation.org> (raw)
In-Reply-To: <20220802151550.159076-1-wangkefeng.wang@huawei.com>

On Tue, 2 Aug 2022 23:15:50 +0800 Kefeng Wang <wangkefeng.wang@huawei.com> wrote:

> Abhishek reported a data-race issue,

OK, but it would be better to perform an analysis of the alleged bug,
describe the potential effects if the race is hit, etc.

> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -2507,6 +2507,7 @@ int __ksm_enter(struct mm_struct *mm)
>  {
>  	struct mm_slot *mm_slot;
>  	int needs_wakeup;
> +	bool ksm_run_unmerge;
>  
>  	mm_slot = alloc_mm_slot();
>  	if (!mm_slot)
> @@ -2515,6 +2516,10 @@ int __ksm_enter(struct mm_struct *mm)
>  	/* Check ksm_run too?  Would need tighter locking */
>  	needs_wakeup = list_empty(&ksm_mm_head.mm_list);
>  
> +	mutex_lock(&ksm_thread_mutex);
> +	ksm_run_unmerge = !!(ksm_run & KSM_RUN_UNMERGE);
> +	mutex_unlock(&ksm_thread_mutex);
>
>  	spin_lock(&ksm_mmlist_lock);
>  	insert_to_mm_slots_hash(mm, mm_slot);
>  	/*
> @@ -2527,7 +2532,7 @@ int __ksm_enter(struct mm_struct *mm)
>  	 * scanning cursor, otherwise KSM pages in newly forked mms will be
>  	 * missed: then we might as well insert at the end of the list.
>  	 */
> -	if (ksm_run & KSM_RUN_UNMERGE)
> +	if (ksm_run_unmerge)

run_store() can alter ksm_run right here, so __ksm_enter() is still
acting on the old setting?

>  		list_add_tail(&mm_slot->mm_list, &ksm_mm_head.mm_list);
>  	else
>  		list_add_tail(&mm_slot->mm_list, &ksm_scan.mm_slot->mm_list);



  parent reply	other threads:[~2022-08-11 23:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-02 15:15 Kefeng Wang
2022-08-02 15:44 ` Matthew Wilcox
2022-08-02 17:20   ` Gabriel Ryan
2022-08-11 23:00 ` Andrew Morton [this message]
2022-08-19 12:00   ` Abhishek Shah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220811160020.1e6823094217e8d6d3aaebdf@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=abhishek.shah@columbia.edu \
    --cc=gabe@cs.columbia.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=wangkefeng.wang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox