From: Andrey Ryabinin <ryabinin.a.a@gmail.com>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Andrey Ryabinin <a.ryabinin@samsung.com>,
Andrew Morton <akpm@linux-foundation.org>,
Dave Hansen <dave.hansen@intel.com>,
Sasha Levin <sasha.levin@oracle.com>,
David Rientjes <rientjes@google.com>,
linux-mm@kvack.org
Subject: Re: [PATCH 1/2] mm: close race between do_fault_around() and fault_around_bytes_set()
Date: Tue, 29 Jul 2014 21:07:45 +0400 [thread overview]
Message-ID: <CAPAsAGx_mpWcFXODjUBk9Pxr7xMWybH-0Uc9mFgB=ObV00g3Cw@mail.gmail.com> (raw)
In-Reply-To: <20140729142710.656A9E00A3@blue.fi.intel.com>
2014-07-29 18:27 GMT+04:00 Kirill A. Shutemov <kirill.shutemov@linux.intel.com>:
> Andrey Ryabinin wrote:
>> On 07/29/14 15:33, Kirill A. Shutemov wrote:
>> > Things can go wrong if fault_around_bytes will be changed under
>> > do_fault_around(): between fault_around_mask() and fault_around_pages().
>> >
>> > Let's read fault_around_bytes only once during do_fault_around() and
>> > calculate mask based on the reading.
>> >
>> > Note: fault_around_bytes can only be updated via debug interface. Also
>> > I've tried but was not able to trigger a bad behaviour without the
>> > patch. So I would not consider this patch as urgent.
>> >
>> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>> > ---
>> > mm/memory.c | 17 +++++++++++------
>> > 1 file changed, 11 insertions(+), 6 deletions(-)
>> >
>> > diff --git a/mm/memory.c b/mm/memory.c
>> > index 9d66bc66f338..2ce07dc9b52b 100644
>> > --- a/mm/memory.c
>> > +++ b/mm/memory.c
>> > @@ -2772,12 +2772,12 @@ static unsigned long fault_around_bytes = rounddown_pow_of_two(65536);
>> >
>> > static inline unsigned long fault_around_pages(void)
>> > {
>> > - return fault_around_bytes >> PAGE_SHIFT;
>> > + return ACCESS_ONCE(fault_around_bytes) >> PAGE_SHIFT;
>> > }
>> >
>> > -static inline unsigned long fault_around_mask(void)
>> > +static inline unsigned long fault_around_mask(unsigned long nr_pages)
>> > {
>> > - return ~(fault_around_bytes - 1) & PAGE_MASK;
>> > + return ~(nr_pages * PAGE_SIZE - 1) & PAGE_MASK;
>> > }
>> >
>> >
>> > @@ -2844,12 +2844,17 @@ late_initcall(fault_around_debugfs);
>> > static void do_fault_around(struct vm_area_struct *vma, unsigned long address,
>> > pte_t *pte, pgoff_t pgoff, unsigned int flags)
>> > {
>> > - unsigned long start_addr;
>> > + unsigned long start_addr, nr_pages;
>> > pgoff_t max_pgoff;
>> > struct vm_fault vmf;
>> > int off;
>> >
>> > - start_addr = max(address & fault_around_mask(), vma->vm_start);
>> > + nr_pages = fault_around_pages();
>> > + /* race with fault_around_bytes_set() */
>> > + if (nr_pages <= 1)
>>
>> unlikely() ?
>
> Yep.
>
Btw, do we need this check at all? nr_pages can't be 0, and code below
seems able to handle nr_page == 1.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2014-07-29 17:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 11:33 [PATCH 0/2] faultaround updates Kirill A. Shutemov
2014-07-29 11:33 ` [PATCH 1/2] mm: close race between do_fault_around() and fault_around_bytes_set() Kirill A. Shutemov
2014-07-29 13:32 ` Andrey Ryabinin
2014-07-29 14:27 ` Kirill A. Shutemov
2014-07-29 17:07 ` Andrey Ryabinin [this message]
2014-07-29 22:36 ` David Rientjes
2014-07-29 23:16 ` Kirill A. Shutemov
2014-07-29 11:33 ` [PATCH 2/2] mm: mark fault_around_bytes __read_mostly Kirill A. Shutemov
2014-07-29 22:38 ` David Rientjes
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='CAPAsAGx_mpWcFXODjUBk9Pxr7xMWybH-0Uc9mFgB=ObV00g3Cw@mail.gmail.com' \
--to=ryabinin.a.a@gmail.com \
--cc=a.ryabinin@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@intel.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=sasha.levin@oracle.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