From: Matthew Wilcox <willy@infradead.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: linux-mm@kvack.org
Subject: Re: [PATCH v2 1/6] mm: introduce vma->vm_flags modifier functions
Date: Wed, 25 Jan 2023 22:02:49 +0000 [thread overview]
Message-ID: <Y9GnCUcNGoWf78wG@casper.infradead.org> (raw)
In-Reply-To: <CAJuCfpGTP83Qt+3WwzDMKuVohUg+UBfO8tc5fzwxfGYm_=u5qQ@mail.gmail.com>
On Wed, Jan 25, 2023 at 01:08:13PM -0800, Suren Baghdasaryan wrote:
> On Wed, Jan 25, 2023 at 1:07 PM Suren Baghdasaryan <surenb@google.com> wrote:
> >
> > On Wed, Jan 25, 2023 at 1:04 PM Suren Baghdasaryan <surenb@google.com> wrote:
> > >
> > > On Wed, Jan 25, 2023 at 12:35 PM Matthew Wilcox <willy@infradead.org> wrote:
> > > >
> > > > [I'm just going to trim the incredibly long list of recipients. Too
> > > > many bounces, and I doubt any of them really care]
> > > >
> > > > On Wed, Jan 25, 2023 at 11:21:56AM -0800, Suren Baghdasaryan wrote:
> > > > > On Wed, Jan 25, 2023 at 10:37 AM Matthew Wilcox <willy@infradead.org> wrote:
> > > > > > Here's a trick I saw somewhere in the VFS:
> > > > > >
> > > > > > union {
> > > > > > const vm_flags_t vm_flags;
> > > > > > vm_flags_t __private __vm_flags;
> > > > > > };
> > > > > >
> > > > > > Now it can be read by anybody but written only by those using
> > > > > > ACCESS_PRIVATE.
> > > > >
> > > > > Huh, this is quite nice! I think it does not save us from the cases
> > > > > when vma->vm_flags is passed by a reference and modified indirectly,
> > > > > like in ksm_madvise()? Though maybe such usecases are so rare (I found
> > > > > only 2 cases) that we can ignore this?
> > > >
> > > > Taking the address of vma->vm_flags will give you a const-qualified
> > > > pointer, which gcc will then warn about passing to a non-const-qualified
> > > > function argument, so I think we're good?
> > >
> > > Yes, actually I just realized that too when trying to use
> > > &ACCESS_PRIVATE() to get the address of vm->vm_flags in dump_vma().
> > > So, I think your trick gives us an easy way to have a read-only
> > > vm_flags. Thanks!
> >
> > Another nasty problem I hit is that READ_ONCE() requires an l-value,
> > so READ_ONCE(vma->vm_flags) would not be directly convertible into
> > READ_ONCE(get_vm_flags(vma->vm_flags)). I'm not sure if
>
> s/READ_ONCE(get_vm_flags(vma->vm_flags))/READ_ONCE(get_vm_flags(vma))
>
> > ACCESS_PRIVATE() implicitly constitutes READ_ONCE(). With your
> > approach that would not be needed but I'm still curious how this issue
> > could be solved.
I think you'd have to bury the READ_ONCE() inside get_vm_flags() or
have a get_vm_flags_once() variant.
next prev parent reply other threads:[~2023-01-25 22:02 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-25 8:38 [PATCH v2 0/6] introduce vm_flags " Suren Baghdasaryan
2023-01-25 8:38 ` [PATCH v2 1/6] mm: introduce vma->vm_flags " Suren Baghdasaryan
2023-01-25 8:56 ` Michal Hocko
2023-01-25 9:09 ` Peter Zijlstra
2023-01-25 16:49 ` Suren Baghdasaryan
2023-01-25 18:37 ` Matthew Wilcox
[not found] ` <CAJuCfpHO7g-5GZep0e7r=dFTBhVHpN3R_pHMGOqetgrKyYzMFQ@mail.gmail.com>
2023-01-25 20:35 ` Matthew Wilcox
2023-01-25 21:04 ` Suren Baghdasaryan
2023-01-25 21:07 ` Suren Baghdasaryan
2023-01-25 21:08 ` Suren Baghdasaryan
2023-01-25 22:02 ` Matthew Wilcox [this message]
2023-01-25 22:15 ` Suren Baghdasaryan
2023-01-25 18:33 ` Matthew Wilcox
2023-01-25 19:22 ` Suren Baghdasaryan
2023-01-26 9:17 ` Mike Rapoport
2023-01-26 14:50 ` Mike Rapoport
2023-01-26 15:09 ` Matthew Wilcox
2023-01-26 16:25 ` Suren Baghdasaryan
2023-01-25 8:38 ` [PATCH v2 2/6] mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK Suren Baghdasaryan
2023-01-25 9:02 ` Michal Hocko
2023-01-26 9:19 ` Mike Rapoport
2023-01-25 8:38 ` [PATCH v2 3/6] mm: replace vma->vm_flags direct modifications with modifier calls Suren Baghdasaryan
2023-01-25 9:30 ` Michal Hocko
2023-01-25 16:55 ` Suren Baghdasaryan
2023-01-26 9:21 ` Mike Rapoport
2023-01-26 17:07 ` Sebastian Reichel
2023-01-25 8:38 ` [PATCH v2 4/6] mm: replace vma->vm_flags indirect modification in ksm_madvise Suren Baghdasaryan
2023-01-25 9:38 ` Michal Hocko
[not found] ` <CAJuCfpGd2eG0RSMte9OVgsRVWPo+Sj7+t8EOo8o_iKzZoh1MXA@mail.gmail.com>
2023-01-25 17:08 ` Michal Hocko
2023-01-26 9:26 ` Mike Rapoport
2023-01-25 8:38 ` [PATCH v2 5/6] mm: introduce mod_vm_flags_nolock and use it in untrack_pfn Suren Baghdasaryan
2023-01-25 9:42 ` Michal Hocko
2023-01-25 17:00 ` Suren Baghdasaryan
2023-01-26 9:34 ` Mike Rapoport
[not found] ` <20230125083851.27759-7-surenb@google.com>
2023-01-25 9:43 ` [PATCH v2 6/6] mm: export dump_mm() Michal Hocko
2023-01-26 14:48 ` Mike Rapoport
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=Y9GnCUcNGoWf78wG@casper.infradead.org \
--to=willy@infradead.org \
--cc=linux-mm@kvack.org \
--cc=surenb@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