Commit 0565103d authored by Anton Ivanov's avatar Anton Ivanov Committed by Richard Weinberger

um: Memory corruption on startup

The reverse case of this race (you must msync before read) is
well known. This is the not so common one.

It can be triggered only on systems which do a lot of task
switching and only at UML startup. If you are starting 200+ UMLs
~ 0.5% will always die without this fix.
Signed-off-by: default avatarAnton Ivanov <antivano@cisco.com>
[rw: minor whitespace fixes]
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent 9fcb663b
...@@ -136,6 +136,7 @@ extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg); ...@@ -136,6 +136,7 @@ extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg);
extern int os_get_ifname(int fd, char *namebuf); extern int os_get_ifname(int fd, char *namebuf);
extern int os_set_slip(int fd); extern int os_set_slip(int fd);
extern int os_mode_fd(int fd, int mode); extern int os_mode_fd(int fd, int mode);
extern int os_fsync_file(int fd);
extern int os_seek_file(int fd, unsigned long long offset); extern int os_seek_file(int fd, unsigned long long offset);
extern int os_open_file(const char *file, struct openflags flags, int mode); extern int os_open_file(const char *file, struct openflags flags, int mode);
......
...@@ -103,6 +103,7 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end, ...@@ -103,6 +103,7 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end,
*/ */
os_seek_file(physmem_fd, __pa(&__syscall_stub_start)); os_seek_file(physmem_fd, __pa(&__syscall_stub_start));
os_write_file(physmem_fd, &__syscall_stub_start, PAGE_SIZE); os_write_file(physmem_fd, &__syscall_stub_start, PAGE_SIZE);
os_fsync_file(physmem_fd);
bootmap_size = init_bootmem(pfn, pfn + delta); bootmap_size = init_bootmem(pfn, pfn + delta);
free_bootmem(__pa(reserve_end) + bootmap_size, free_bootmem(__pa(reserve_end) + bootmap_size,
......
...@@ -237,6 +237,12 @@ void os_close_file(int fd) ...@@ -237,6 +237,12 @@ void os_close_file(int fd)
{ {
close(fd); close(fd);
} }
int os_fsync_file(int fd)
{
if (fsync(fd) < 0)
return -errno;
return 0;
}
int os_seek_file(int fd, unsigned long long offset) int os_seek_file(int fd, unsigned long long offset)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment