mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-09-06 18:05:37 +00:00
![Ilya Leoshkevich](/assets/img/avatar_default.png)
Currently QEMU ignores madvise(MADV_DONTNEED), which break apps that
rely on this for zeroing out memory [1]. Improve the situation by doing
a passthrough when the range in question is a host-page-aligned
anonymous mapping.
This is based on the patches from Simon Hausmann [2] and Chris Fallin
[3]. The structure is taken from Simon's patch. The PAGE_MAP_ANONYMOUS
bits are superseded by commit 26bab757d4
("linux-user: Introduce
PAGE_ANON"). In the end the patch acts like the one from Chris: we
either pass-through the entire syscall, or do nothing, since doing this
only partially would not help the affected applications much. Finally,
add some extra checks to match the behavior of the Linux kernel [4].
[1] https://gitlab.com/qemu-project/qemu/-/issues/326
[2] https://patchew.org/QEMU/20180827084037.25316-1-simon.hausmann@qt.io/
[3] https://github.com/bytecodealliance/wasmtime/blob/v0.37.0/ci/qemu-madvise.patch
[4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/madvise.c?h=v5.19-rc3#n1368
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220621144205.158452-1-iii@linux.ibm.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
36 lines
1.5 KiB
C
36 lines
1.5 KiB
C
/*
|
|
* user-mmap.h: prototypes for linux-user guest binary loader
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef LINUX_USER_USER_MMAP_H
|
|
#define LINUX_USER_USER_MMAP_H
|
|
|
|
int target_mprotect(abi_ulong start, abi_ulong len, int prot);
|
|
abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
|
|
int flags, int fd, abi_ulong offset);
|
|
int target_munmap(abi_ulong start, abi_ulong len);
|
|
abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
|
|
abi_ulong new_size, unsigned long flags,
|
|
abi_ulong new_addr);
|
|
abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice);
|
|
extern unsigned long last_brk;
|
|
extern abi_ulong mmap_next_start;
|
|
abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong);
|
|
void mmap_fork_start(void);
|
|
void mmap_fork_end(int child);
|
|
|
|
#endif /* LINUX_USER_USER_MMAP_H */
|