[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200715222228.jf2pv5u2wyhtc5o5@box>
Date: Thu, 16 Jul 2020 01:22:28 +0300
From: "Kirill A. Shutemov" <kirill@...temov.name>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Joel Fernandes <joel@...lfernandes.org>,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Linux-MM <linux-mm@...ck.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Naresh Kamboju <naresh.kamboju@...aro.org>,
William Kucharski <william.kucharski@...cle.com>
Subject: Re: [PATCHv2] mm: Fix warning in move_normal_pmd()
On Wed, Jul 15, 2020 at 02:43:00PM -0700, Linus Torvalds wrote:
> On Wed, Jul 15, 2020 at 2:31 PM Linus Torvalds
> <torvalds@...ux-foundation.org> wrote:
> >
> > Naresh - don't test that version. The bugs Joel found just make the
> > math wrong, so it won't work.
>
> Here's a new version with the thing that Joel and Kirill both noticed
> hopefully fixed.
>
> But I probably screwed it up again. I guess I should test it, but I
> don't have any really relevant environment (the plain mremap() case
> should have shown the obvious bugs, though, so that's just an excuse
> for my laziness)
Sorry, but the patch is broken.
It overcopies entires in some cases. It doesn't handles correctly if you
try to move PTEs from the middle of VMA.
The test case below rightly sigfaults without the patch when trying access
DST_ADDR[0], but not with the patch. It creates PTE entry at DST_ADDR that
doesn't belong to any VMA. :/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#define SRC_ADDR ((char *)(4UL << 30))
#define DST_ADDR ((char *)(5UL << 30))
int main(void)
{
mmap(SRC_ADDR, 2UL << 20, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
madvise(SRC_ADDR, 2UL << 20, MADV_NOHUGEPAGE);
memset(SRC_ADDR, 0x33, 2UL << 20);
mremap(SRC_ADDR + 4096, 4096, 4096, MREMAP_MAYMOVE | MREMAP_FIXED,
DST_ADDR + 4096);
printf("0: %#x 4096: %#x\n", DST_ADDR[0], DST_ADDR[4096]);
return 0;
}
--
Kirill A. Shutemov
Powered by blists - more mailing lists