Michael Tokarev
688e4a6e77
linux-user/mmap.c: fix "of of" typo in comment
...
Suggested-by: Thomas Huth <thuth@redhat.com >
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru >
2025-05-09 23:49:26 +03:00
Richard Henderson
4d3ad3c3ba
include/exec: Split out mmap-lock.h
...
Split out mmap_lock, et al from page-protection.h
to a new header.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
2025-04-23 14:08:17 -07:00
Philippe Mathieu-Daudé
c9ce8a1ffd
linux-user: Only include 'exec/tb-flush.h' header when necessary
...
Very few source files require to access "exec/tb-flush.h"
declarations, and except a pair, they all include it
explicitly. No need to overload the generic "user-internals.h".
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Message-Id: <20250102182521.65428-2-philmd@linaro.org >
2025-03-09 14:54:32 +01:00
Philippe Mathieu-Daudé
8865049bab
accel/tcg: Move tcg_cflags_has/set() to 'exec/translation-block.h'
...
The TranslationBlock flags are defined in 'exec/translation-block.h'.
tcg_cflags_has/set() use them, it is more logical to declare them in
the same place. Move them there too.
Suggested-by: Richard Henderson <richard.henderson@linaro.org >
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Reviewed-by: Richard Henderson <richard.henderson@linaro.org >
Message-Id: <20241212144430.66224-2-philmd@linaro.org >
2024-12-20 17:44:57 +01:00
Philippe Mathieu-Daudé
970ae60e9b
accel/tcg: Move user-related declarations out of 'exec/cpu-all.h' (1/4)
...
Move declarations related to page protection under user
emulation from "exec/cpu-all.h" to "user/page-protection.h".
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Reviewed-by: Richard Henderson <richard.henderson@linaro.org >
Message-Id: <20241212185341.2857-12-philmd@linaro.org >
2024-12-20 17:44:57 +01:00
Richard Henderson
a4ad4a9d98
linux-user: Handle short reads in mmap_h_gt_g
...
In particular, if an image has a large bss, we can hit
EOF before reading all host_len bytes of the mapping.
Create a helper, mmap_pread to handle the job for both
the larger block in mmap_h_gt_g itself, as well as the
smaller block in mmap_frag.
Cc: qemu-stable@nongnu.org
Fixes: eb5027ac61 ("linux-user: Split out mmap_h_gt_g")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2504
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Message-Id: <20240820050848.165253-2-richard.henderson@linaro.org >
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org >
2024-08-21 09:09:46 +10:00
Richard Henderson
3aefee3ec0
linux-user: Preserve NULL hit in target_mmap subroutines
...
Do not pass guest_base to the host mmap instead of zero hint.
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2353
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
2024-08-15 11:03:47 +10:00
Philippe Mathieu-Daudé
b254c342cf
accel/tcg: Access tcg_cflags with getter / setter
...
Access the CPUState::tcg_cflags via tcg_cflags_has() and
tcg_cflags_set() helpers.
Mechanical change using the following Coccinelle spatch script:
@@
expression cpu;
expression flags;
@@
- cpu->tcg_cflags & flags
+ tcg_cflags_has(cpu, flags)
@@
expression cpu;
expression flags;
@@
- (tcg_cflags_has(cpu, flags))
+ tcg_cflags_has(cpu, flags)
@@
expression cpu;
expression flags;
@@
- cpu->tcg_cflags |= flags;
+ tcg_cflags_set(cpu, flags);
Then manually moving the declarations, and adding both
tcg_cflags_has() and tcg_cflags_set() definitions.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Reviewed-by: Richard Henderson <richard.henderson@linaro.org >
Message-Id: <20240427155714.53669-15-philmd@linaro.org >
2024-05-06 11:21:05 +02:00
Philippe Mathieu-Daudé
74781c0888
exec/cpu: Extract page-protection definitions to page-protection.h
...
Extract page-protection definitions from "exec/cpu-all.h"
to "exec/page-protection.h".
The list of files requiring the new header was generated
using:
$ git grep -wE \
'PAGE_(READ|WRITE|EXEC|RWX|VALID|ANON|RESERVED|TARGET_.|PASSTHROUGH)'
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Acked-by: Nicholas Piggin <npiggin@gmail.com >
Acked-by: Richard Henderson <richard.henderson@linaro.org >
Message-Id: <20240427155714.53669-3-philmd@linaro.org >
2024-05-06 11:17:15 +02:00
BALATON Zoltan and Philippe Mathieu-Daudé
86b7c55182
exec/cpu: Rename PAGE_BITS macro to PAGE_RWX
...
This macro can be used to abbreviate PAGE_READ | PAGE_WRITE | PAGE_EXEC
for which PAGE_RWX is a better name and renaming it also shows it is
not related to TARGET_PAGE_BITS.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu >
Reviewed-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Message-ID: <20240505121008.44A0D4E602D@zero.eik.bme.hu >
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org >
2024-05-06 11:17:15 +02:00
Ilya Leoshkevich and Richard Henderson
fa527b44c2
linux-user: Fix shmat(NULL) for h != g
...
In the h != g && shmaddr == NULL && !reserved_va case, target_shmat()
incorrectly mmap()s the initial anonymous range with
MAP_FIXED_NOREPLACE, even though the earlier mmap_find_vma() has
already reserved the respective address range.
Fix by using MAP_FIXED when "mapped", which is set after
mmap_find_vma(), is true.
Fixes: 78bc8ed9a8 ("linux-user: Rewrite target_shmat")
Reviewed-by: Richard Henderson <richard.henderson@linaro.org >
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com >
Message-Id: <20240325192436.561154-4-iii@linux.ibm.com >
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
2024-03-26 18:20:36 -10:00
Richard Henderson
78bc8ed9a8
linux-user: Rewrite target_shmat
...
Handle combined host and guest alignment requirements.
Handle host and guest page size differences.
Handle SHM_EXEC.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/115
Tested-by: Richard Purdie <richard.purdie@linuxfoundation.org >
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
2024-03-01 08:09:55 -10:00
Richard Henderson
eb5027ac61
linux-user: Split out mmap_h_gt_g
...
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-24-richard.henderson@linaro.org >
2024-02-29 11:35:37 -10:00
Richard Henderson
8080b2f804
linux-user: Split out mmap_h_lt_g
...
Work much harder to get alignment and mapping beyond the end
of the file correct. Both of which are excercised by our
test-mmap for alpha (8k pages) on any 4k page host.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-23-richard.henderson@linaro.org >
2024-02-29 11:35:37 -10:00
Richard Henderson
68098de90e
linux-user: Split out mmap_h_eq_g
...
Move the MAX_FIXED_NOREPLACE check for reserved_va earlier.
Move the computation of host_prot earlier.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-22-richard.henderson@linaro.org >
2024-02-29 11:35:37 -10:00
Richard Henderson
3bfa271e46
linux-user: Use do_munmap for target_mmap failure
...
For the cases for which the host mmap succeeds, but does
not yield the desired address, use do_munmap to restore
the reserved_va memory reservation.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
2024-02-29 11:35:37 -10:00
Richard Henderson
2952b642a5
linux-user: Split out do_munmap
...
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
2024-02-29 11:35:37 -10:00
Richard Henderson
ad87d26e6b
linux-user: Do early mmap placement only for reserved_va
...
For reserved_va, place all non-fixed maps then proceed
as for MAP_FIXED.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-21-richard.henderson@linaro.org >
2024-02-29 11:35:36 -10:00
Richard Henderson
6ecc25570f
linux-user: Split out mmap_end
...
Use a subroutine instead of a goto within target_mmap__locked.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-20-richard.henderson@linaro.org >
2024-02-29 11:35:36 -10:00
Richard Henderson
f0a362c476
linux-user: Fix sub-host-page mmap
...
We cannot skip over the_end1 to the_end, because we fail to
record the validity of the guest page with the interval tree.
Remove "the_end" and rename "the_end1" to "the_end".
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-19-richard.henderson@linaro.org >
2024-02-29 11:35:36 -10:00
Richard Henderson
e8cec51be0
linux-user: Move some mmap checks outside the lock
...
Basic validation of operands does not require the lock.
Hoist them from target_mmap__locked back into target_mmap.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-18-richard.henderson@linaro.org >
2024-02-29 11:35:36 -10:00
Richard Henderson
d558c395a9
linux-user: Split out target_mmap__locked
...
All "goto fail" may be transformed to "return -1".
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-17-richard.henderson@linaro.org >
2024-02-29 11:35:36 -10:00
Richard Henderson
b36b2b1d3d
linux-user: Remove HOST_PAGE_ALIGN from mmap.c
...
This removes a hidden use of qemu_host_page_size, using instead
the existing host_page_size local within each function.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-11-richard.henderson@linaro.org >
2024-02-29 11:35:36 -10:00
Richard Henderson
e56922abf0
linux-user: Remove REAL_HOST_PAGE_ALIGN from mmap.c
...
We already have qemu_real_host_page_size() in a local variable.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org >
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-10-richard.henderson@linaro.org >
2024-02-29 11:35:36 -10:00
Richard Henderson
621ac47d37
linux-user: Remove qemu_host_page_{size, mask} from mmap.c
...
Use qemu_real_host_page_size instead.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org >
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com >
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org >
Acked-by: Helge Deller <deller@gmx.de >
Message-Id: <20240102015808.132373-9-richard.henderson@linaro.org >
2024-02-29 11:35:36 -10:00