From: stsp <stsp2@yandex.ru>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: linux-mm@kvack.org
Subject: MREMAP_DONTUNMAP corrupts initial mapping
Date: Thu, 30 Mar 2023 17:38:15 +0500 [thread overview]
Message-ID: <aee53ac3-6d25-5009-7416-3f7c5fe1f989@yandex.ru> (raw)
[-- Attachment #1: Type: text/plain, Size: 320 bytes --]
Hello.
Attached is a small test-case that
demonstrates the problem.
The problem happens if you change
some data in a file-backed private
mapping and then use mremap on
it with MREMAP_DONTUNMAP flag.
The result is:
- destination copy is valid
- source copy restored from the original file
So the 2 copies do not match.
[-- Attachment #2: mretst.c --]
[-- Type: text/x-csrc, Size: 838 bytes --]
#define _GNU_SOURCE
#include <sys/mman.h>
#include <assert.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
int main(void)
{
const char *file = "mretst.c";
char *addr, *addr2;
int fd;
char c;
fd = open (file, O_RDONLY);
if (fd == -1)
return EXIT_FAILURE;
addr = mmap (NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd);
if (addr == MAP_FAILED)
return EXIT_FAILURE;
c = addr[0];
assert(addr[0]);
addr[0] = 0;
assert(!addr[0]);
addr2 = mremap (addr, PAGE_SIZE, PAGE_SIZE,
MREMAP_MAYMOVE | MREMAP_DONTUNMAP);
assert(!addr2[0]);
if (addr[0] == c)
printf("Test FAILED\n");
else
printf("Test PASSED\n");
return 0;
}
next reply other threads:[~2023-03-30 12:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-30 12:38 stsp [this message]
2023-03-30 14:45 ` stsp
2023-03-30 18:42 ` Lorenzo Stoakes
2023-03-31 6:53 ` stsp
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=aee53ac3-6d25-5009-7416-3f7c5fe1f989@yandex.ru \
--to=stsp2@yandex.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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
all inboxes | Powered by JetHome®