From aad71fb6e2c05a495c69a4243de1032451f63437 Mon Sep 17 00:00:00 2001 From: pooka Date: Wed, 9 Jun 2010 12:02:37 +0000 Subject: [PATCH] On amd64, allocate module_map memory from the lowest 2GB. --- sys/rump/librump/rumpkern/vm.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/sys/rump/librump/rumpkern/vm.c b/sys/rump/librump/rumpkern/vm.c index 9746a81c0af7..fded09ba2362 100644 --- a/sys/rump/librump/rumpkern/vm.c +++ b/sys/rump/librump/rumpkern/vm.c @@ -1,4 +1,4 @@ -/* $NetBSD: vm.c,v 1.81 2010/06/09 11:35:36 pooka Exp $ */ +/* $NetBSD: vm.c,v 1.82 2010/06/09 12:02:37 pooka Exp $ */ /* * Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved. @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.81 2010/06/09 11:35:36 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.82 2010/06/09 12:02:37 pooka Exp $"); #include #include @@ -528,15 +528,39 @@ uvm_map_protect(struct vm_map *map, vaddr_t start, vaddr_t end, vaddr_t uvm_km_alloc(struct vm_map *map, vsize_t size, vsize_t align, uvm_flag_t flags) { - void *rv; + void *rv, *desired = NULL; int alignbit, error; +#ifdef __x86_64__ + /* + * On amd64, allocate all module memory from the lowest 2GB. + * This is because NetBSD kernel modules are compiled + * with -mcmodel=kernel and reserve only 4 bytes for + * offsets. If we load code compiled with -mcmodel=kernel + * anywhere except the lowest or highest 2GB, it will not + * work. Since userspace does not have access to the highest + * 2GB, use the lowest 2GB. + * + * Note: this assumes the rump kernel resides in + * the lowest 2GB as well. + * + * Note2: yes, it's a quick hack, but since this the only + * place where we care about the map we're allocating from, + * just use a simple "if" instead of coming up with a fancy + * generic solution. + */ + extern struct vm_map *module_map; + if (map == module_map) { + desired = (void *)(0x80000000 - size); + } +#endif + alignbit = 0; if (align) { alignbit = ffs(align)-1; } - rv = rumpuser_anonmmap(NULL, size, alignbit, flags & UVM_KMF_EXEC, + rv = rumpuser_anonmmap(desired, size, alignbit, flags & UVM_KMF_EXEC, &error); if (rv == NULL) { if (flags & (UVM_KMF_CANFAIL | UVM_KMF_NOWAIT))