SHA256
1
0
forked from pool/qemu

- resolve VMAs downwards, fixes arm git build for real

OBS-URL: https://build.opensuse.org/package/show/Virtualization/qemu?expand=0&rev=60
This commit is contained in:
Alexander Graf 2012-03-05 01:46:36 +00:00 committed by Git OBS Bridge
parent 44bce8debe
commit 444bd2feaa
5 changed files with 122 additions and 76 deletions

View File

@ -1,41 +0,0 @@
From 76d6efef547a23ba6e4e1ed0f1f198b36ae9c7ff Mon Sep 17 00:00:00 2001
From: Alexander Graf <agraf@suse.de>
Date: Sat, 3 Mar 2012 23:14:31 +0100
Subject: [PATCH] linux-user: map at TARGET_UNMAPPED_BASE with reserved_va
When mmap()'ing memory somewhere where it's not allowed, we should not
default to the "next free page" which could be right after brk()'ed memory,
but rather at TARGET_UNMAPPED_BASE, which ensures that brk() can extend its
space later on.
Reported-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
v1 -> v2:
- use consistent constant naming
---
linux-user/mmap.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index e4db455..2245f40 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -244,7 +244,13 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size)
}
prot = page_get_flags(addr);
if (prot) {
- last_addr = addr + qemu_host_page_size;
+ if (addr < TASK_UNMAPPED_BASE) {
+ /* Someone randomly shot into potential brk space,
+ better remap higher up when already remapping */
+ last_addr = TASK_UNMAPPED_BASE;
+ } else {
+ last_addr = addr + qemu_host_page_size;
+ }
}
}
mmap_next_start = addr;

View File

@ -0,0 +1,116 @@
From a6664afab4b925f8ae74b6fe20e3634f42690e90 Mon Sep 17 00:00:00 2001
From: Alexander Graf <agraf@suse.de>
Date: Sun, 4 Mar 2012 02:41:14 +0100
Subject: [PATCH] linux-user: resolve reserved_va vma downwards
After consulting with Paul Brook, we concluded that it's best to search
the VMA space downwards, so that we don't even get the chance to conflict
with the brk range.
This patch resolves a bunch of allocation conflicts when using -R.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
This replaces the other patches I sent out earlier today.
---
linux-user/main.c | 1 +
linux-user/mmap.c | 35 ++++++++++++++++++++++++-----------
linux-user/qemu.h | 1 +
3 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/linux-user/main.c b/linux-user/main.c
index 6a5dfde..d61d731 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3437,6 +3437,7 @@ int main(int argc, char **argv, char **envp)
guest_base = HOST_PAGE_ALIGN((unsigned long)p);
}
qemu_log("Reserved 0x%lx bytes of guest address space\n", reserved_va);
+ mmap_next_start = reserved_va;
}
if (reserved_va || have_guest_base) {
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index e4db455..2620f88 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -212,7 +212,7 @@ static int mmap_frag(abi_ulong real_start,
#else
# define TASK_UNMAPPED_BASE 0x18000000
#endif
-static abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;
+abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;
unsigned long last_brk;
@@ -222,7 +222,7 @@ unsigned long last_brk;
static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size)
{
abi_ulong addr;
- abi_ulong last_addr;
+ abi_ulong end_addr;
int prot;
int looped = 0;
@@ -230,25 +230,38 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size)
return (abi_ulong)-1;
}
- last_addr = start;
- for (addr = start; last_addr + size != addr; addr += qemu_host_page_size) {
- if (last_addr + size >= RESERVED_VA
- || (abi_ulong)(last_addr + size) < last_addr) {
+ size = HOST_PAGE_ALIGN(size);
+ end_addr = start + size;
+ if (end_addr > RESERVED_VA) {
+ end_addr = RESERVED_VA;
+ }
+ addr = end_addr - qemu_host_page_size;
+
+ while (1) {
+ if (addr > end_addr) {
if (looped) {
return (abi_ulong)-1;
}
- last_addr = qemu_host_page_size;
- addr = 0;
+ end_addr = RESERVED_VA;
+ addr = end_addr - qemu_host_page_size;
looped = 1;
continue;
}
prot = page_get_flags(addr);
if (prot) {
- last_addr = addr + qemu_host_page_size;
+ end_addr = addr;
+ }
+ if (addr + size == end_addr) {
+ break;
}
+ addr -= qemu_host_page_size;
+ }
+
+ if (start == mmap_next_start) {
+ mmap_next_start = addr;
}
- mmap_next_start = addr;
- return last_addr;
+
+ return addr;
}
#endif
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index aa06acf..5dc0720 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -254,6 +254,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
abi_ulong new_addr);
int target_msync(abi_ulong start, abi_ulong len, int flags);
extern unsigned long last_brk;
+extern abi_ulong mmap_next_start;
void mmap_lock(void);
void mmap_unlock(void);
abi_ulong mmap_find_vma(abi_ulong, abi_ulong);

View File

@ -1,32 +0,0 @@
From 48bc21facc19b458cef7e6936da6a012150f0bec Mon Sep 17 00:00:00 2001
From: Alexander Graf <agraf@suse.de>
Date: Sun, 4 Mar 2012 00:18:05 +0100
Subject: [PATCH] linux-user: guard mmap_next_start from specific maps
If the guest process tells us to map at a specific address, we shouldn't
increase the "last automatic mapping ended here" variable.
This patch brings the reserved_va code in line with the default case.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
linux-user/mmap.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 2245f40..a0c1347 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -253,7 +253,11 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size)
}
}
}
- mmap_next_start = addr;
+
+ if (start == mmap_next_start && addr >= TASK_UNMAPPED_BASE) {
+ mmap_next_start = addr;
+ }
+
return last_addr;
}
#endif

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Mon Mar 5 01:31:42 UTC 2012 - agraf@suse.com
- resolve VMAs downwards, fixes arm git build for real
-------------------------------------------------------------------
Sat Mar 3 23:27:14 UTC 2012 - agraf@suse.com

View File

@ -71,8 +71,7 @@ Patch0043: 0043-linux-user-Add-ioctl-for-BLKBSZGET.patch
Patch0044: 0044-linux-user-take-RESERVED_VA-into-account-for-g2h_val.patch
Patch0045: 0045-linux-user-binfmt-support-host-binaries.patch
Patch0046: 0046-linux-user-fix-fallocate.patch
Patch0047: 0047-linux-user-map-at-TARGET_UNMAPPED_BASE-with-reserved.patch
Patch0048: 0048-linux-user-guard-mmap_next_start-from-specific-maps.patch
Patch0047: 0047-linux-user-resolve-reserved_va-vma-downwards.patch
# this is to make lint happy
Source300: rpmlintrc
Source400: update_git.sh
@ -187,7 +186,6 @@ run cross architectures builds
%patch0045 -p1
%patch0046 -p1
%patch0047 -p1
%patch0048 -p1
%build
# build QEMU