From: Shakeel Butt <shakeelb@google.com>
To: Mina Almasry <almasrymina@google.com>,
Marco Elver <elver@google.com>,
paulmck@kernel.org
Cc: Mike Kravetz <mike.kravetz@oracle.com>,
Muchun Song <songmuchun@bytedance.com>,
Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>, Miaohe Lin <linmiaohe@huawei.com>,
Oscar Salvador <osalvador@suse.de>,
Michal Hocko <mhocko@suse.com>,
David Rientjes <rientjes@google.com>, Jue Wang <juew@google.com>,
Yang Yao <ygyao@google.com>, Joanna Li <joannali@google.com>,
Cannon Matthews <cannonmatthews@google.com>,
Linux Memory Management List <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6] hugetlb: Add hugetlb.*.numa_stat file
Date: Mon, 15 Nov 2021 11:59:03 -0800 [thread overview]
Message-ID: <CALvZod7UEo100GLg+HW-CG6rp7gPJhdjYtcPfzaPMS7Yxa=ZPA@mail.gmail.com> (raw)
In-Reply-To: <CAHS8izP3aOZ6MOOH-eMQ2HzJy2Y8B6NYY-FfJiyoKLGu7_OoJA@mail.gmail.com>
)
On Mon, Nov 15, 2021 at 10:55 AM Mina Almasry <almasrymina@google.com> wrote:
>
> On Mon, Nov 15, 2021 at 10:22 AM Mike Kravetz <mike.kravetz@oracle.com> wrote:
> >
> > Subject: Re: [PATCH v6] hugetlb: Add hugetlb.*.numa_stat file
> >
> > To: Muchun Song <songmuchun@bytedance.com>, Shakeel Butt <shakeelb@google.com>, Mina Almasry <almasrymina@google.com>
> >
> > Cc: Andrew Morton <akpm@linux-foundation.org>, Shuah Khan <shuah@kernel.org>, Miaohe Lin <linmiaohe@huawei.com>, Oscar Salvador <osalvador@suse.de>, Michal Hocko <mhocko@suse.com>, David Rientjes <rientjes@google.com>, Jue Wang <juew@google.com>, Yang Yao <ygyao@google.com>, Joanna Li <joannali@google.com>, Cannon Matthews <cannonmatthews@google.com>, Linux Memory Management List <linux-mm@kvack.org>, LKML <linux-kernel@vger.kernel.org>
> >
> > Bcc:
> >
> > -=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=-
> >
> > On 11/14/21 5:43 AM, Muchun Song wrote:
> >
> > > On Sun, Nov 14, 2021 at 3:15 AM Shakeel Butt <shakeelb@google.com> wrote:
> >
> > >> On Sat, Nov 13, 2021 at 6:48 AM Mina Almasry <almasrymina@google.com> wrote:
> >
> > >>> On Fri, Nov 12, 2021 at 6:45 PM Muchun Song <songmuchun@bytedance.com> wrote:
> >
> > >>>> On Sat, Nov 13, 2021 at 7:36 AM Mike Kravetz <mike.kravetz@oracle.com> wrote:
> >
> > >> We have following options:
> >
> > >>
> >
> > >> 1) Use atomic type for usage.
> >
> > >> 2) Use "unsigned long" for usage along with WRITE_ONCE/READ_ONCE.
> >
> > >> 3) Use hugetlb_lock for hugetlb_cgroup_read_numa_stat as well.
> >
> > >>
> >
> > >> All options are valid but we would like to avoid (3).
> >
> > >>
> >
> > >> What if we use "unsigned long" type but without READ_ONCE/WRITE_ONCE.
> >
> > >> The potential issues with that are KCSAN will report this as race and
> >
> > >> possible garbage value on archs which do not support atomic writes to
> >
> > >> unsigned long.
> >
> > >
> >
> > > At least I totally agree with you. Thanks for your detailed explanation.
> >
> > >
> >
> >
> >
> > Thanks everyone. This makes sense.
> >
> >
> >
> > However, I should note that this same situation (updates to unsigned
> >
> > long variables under lock and reads of the the same variable without
> >
> > lock or READ/WRITE_ONCE) exists in hugetlb sysfs files today. Not
> >
> > suggesting that this makes it OK to ignore the potential issue. Just
> >
> > wanted to point this out.
> >
>
> Sorry I'm still a bit confused. READ_ONCE/WRITE_ONCE isn't documented
> to provide atomicity to the write or read, just prevents the compiler
> from re-ordering them. Is there something I'm missing, or is the
> suggestion to add READ_ONCE/WRITE_ONCE simply to supress the KCSAN
> warnings?
>
+Paul & Marco
Let's ask the experts.
We have a "unsigned long usage" variable that is updated within a lock
(hugetlb_lock) but is read without the lock.
Q1) I think KCSAN will complain about it and READ_ONCE() in the
unlocked read path should be good enough to silent KCSAN. So, the
question is should we still use WRITE_ONCE() as well for usage within
hugetlb_lock?
Q2) Second question is more about 64 bit archs breaking a 64 bit write
into two 32 bit writes. Is this a real issue? If yes, then the
combination of READ_ONCE()/WRITE_ONCE() are good enough for the given
use-case?
thanks,
Shakeel
next prev parent reply other threads:[~2021-11-15 19:59 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-11 1:50 Mina Almasry
2021-11-11 2:04 ` Shakeel Butt
2021-11-11 2:36 ` Muchun Song
2021-11-11 2:59 ` Shakeel Butt
2021-11-12 23:36 ` Mike Kravetz
2021-11-13 2:44 ` Muchun Song
2021-11-13 14:48 ` Mina Almasry
2021-11-13 19:15 ` Shakeel Butt
2021-11-14 13:43 ` Muchun Song
2021-11-15 18:22 ` Mike Kravetz
2021-11-15 18:55 ` Mina Almasry
2021-11-15 19:59 ` Shakeel Butt [this message]
2021-11-16 12:04 ` Marco Elver
2021-11-16 20:48 ` Mina Almasry
2021-11-16 20:59 ` Shakeel Butt
2021-11-16 21:47 ` Marco Elver
2021-11-16 21:53 ` Mina Almasry
2021-11-17 5:54 ` Muchun Song
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='CALvZod7UEo100GLg+HW-CG6rp7gPJhdjYtcPfzaPMS7Yxa=ZPA@mail.gmail.com' \
--to=shakeelb@google.com \
--cc=akpm@linux-foundation.org \
--cc=almasrymina@google.com \
--cc=cannonmatthews@google.com \
--cc=elver@google.com \
--cc=joannali@google.com \
--cc=juew@google.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=mike.kravetz@oracle.com \
--cc=osalvador@suse.de \
--cc=paulmck@kernel.org \
--cc=rientjes@google.com \
--cc=shuah@kernel.org \
--cc=songmuchun@bytedance.com \
--cc=ygyao@google.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