From: Mike Kravetz <mike.kravetz@oracle.com>
To: Andi Kleen <ak@linux.intel.com>, Muchun Song <songmuchun@bytedance.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mm/hugetlb: Fix a race between hugetlb sysctl handlers
Date: Fri, 28 Aug 2020 10:14:16 -0700 [thread overview]
Message-ID: <fee0c3a6-af68-5971-1959-a66d41ea16a3@oracle.com> (raw)
In-Reply-To: <20200828145950.GS1509399@tassilo.jf.intel.com>
On 8/28/20 7:59 AM, Andi Kleen wrote:
>> Fixes: e5ff215941d5 ("hugetlb: multiple hstates for multiple page sizes")
>
> I believe the Fixes line is still not correct. The original patch
> didn't have that problem. Please identify which patch added
> the problematic code.
Hi Andi,
I agree with Muchun's assessment that the issue was caused by e5ff215941d5.
Why?
Commit e5ff215941d5 changed initialization of the .data field in the
ctl_table structure for hugetlb_sysctl_handler. This was required because
the commit introduced multiple hstates. As a result, it can not be known
until runtime the value for .data. This code was added to
hugetlb_sysctl_handler to set the value at runtime.
@@ -1037,8 +1109,19 @@ int hugetlb_sysctl_handler(struct ctl_table *table, int write,
struct file *file, void __user *buffer,
size_t *length, loff_t *ppos)
{
+ struct hstate *h = &default_hstate;
+ unsigned long tmp;
+
+ if (!write)
+ tmp = h->max_huge_pages;
+
+ table->data = &tmp;
+ table->maxlen = sizeof(unsigned long);
The problem is that two threads running in parallel can modify table->data
in the global data structure without any synchronization. Worse yet, is
that that value is local to their stacks. That was the root cause of the
issue addressed by Muchun's patch.
Does that analysis make sense? Or, are we missing something.
--
Mike Kravetz
next prev parent reply other threads:[~2020-08-28 17:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-28 3:11 Muchun Song
2020-08-28 14:46 ` Mike Kravetz
2020-08-28 14:59 ` Andi Kleen
2020-08-28 17:14 ` Mike Kravetz [this message]
2020-08-28 20:30 ` Andi Kleen
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=fee0c3a6-af68-5971-1959-a66d41ea16a3@oracle.com \
--to=mike.kravetz@oracle.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=songmuchun@bytedance.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