From c95747d9a12efd3e5ae1bb838e2141c8531827b3 Mon Sep 17 00:00:00 2001 From: jhb Date: Thu, 27 Jul 2006 19:47:22 +0000 Subject: [PATCH] Don't allow MAXMEM or hw.physmem to extend the top of memory if our memory map was obtained from the SMAP. SMAP is trustworthy, and the memory extending feature is a band-aid for older systems where FreeBSD's methods of detecting memory were not always trustworthy. This fixes the issue where using hw.physmem could result in the ACPI tables getting trashed breaking ACPI. MFC after: 3 days Tested on: i386 --- sys/amd64/amd64/machdep.c | 14 +++++++------- sys/i386/i386/machdep.c | 11 ++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 43c19d39e0ca..ff2367884107 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -947,17 +947,17 @@ getmemsize(caddr_t kmdp, u_int64_t first) if (TUNABLE_ULONG_FETCH("hw.physmem", &physmem_tunable)) Maxmem = atop(physmem_tunable); + /* + * Don't allow MAXMEM or hw.physmem to extend the amount of memory + * in the system. + */ + if (Maxmem > atop(physmap[physmap_idx + 1])) + Maxmem = atop(physmap[physmap_idx + 1]); + if (atop(physmap[physmap_idx + 1]) != Maxmem && (boothowto & RB_VERBOSE)) printf("Physical memory use set to %ldK\n", Maxmem * 4); - /* - * If Maxmem has been increased beyond what the system has detected, - * extend the last memory segment to the new limit. - */ - if (atop(physmap[physmap_idx + 1]) < Maxmem) - physmap[physmap_idx + 1] = ptoa((vm_paddr_t)Maxmem); - /* call pmap initialization to make new kernel address space */ pmap_bootstrap(&first); diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index f3c21da21d64..95d59a007c7a 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -1633,7 +1633,7 @@ static void getmemsize(int first) { int i, physmap_idx, pa_indx, da_indx; - int hasbrokenint12; + int hasbrokenint12, has_smap; u_long physmem_tunable; u_int extmem; struct vm86frame vmf; @@ -1661,6 +1661,7 @@ getmemsize(int first) bzero(&vmf, sizeof(vmf)); bzero(physmap, sizeof(physmap)); basemem = 0; + has_smap = 0; /* * Some newer BIOSes has broken INT 12H implementation which cause @@ -1742,6 +1743,7 @@ getmemsize(int first) if (boothowto & RB_VERBOSE) printf("SMAP type=%02x base=%016llx len=%016llx\n", smap->type, smap->base, smap->length); + has_smap = 1; if (smap->type != 0x01) continue; @@ -1883,6 +1885,13 @@ getmemsize(int first) if (TUNABLE_ULONG_FETCH("hw.physmem", &physmem_tunable)) Maxmem = atop(physmem_tunable); + /* + * If we have an SMAP, don't allow MAXMEM or hw.physmem to extend + * the amount of memory in the system. + */ + if (has_smap && Maxmem > atop(physmap[physmap_idx + 1])) + Maxmem = atop(physmap[physmap_idx + 1]); + if (atop(physmap[physmap_idx + 1]) != Maxmem && (boothowto & RB_VERBOSE)) printf("Physical memory use set to %ldK\n", Maxmem * 4);