Wed Apr 24 06:37:31 2019 UTC ()
In fdt_add_boot_physmem make sure the memory range has pages available
before adding it to the fdt_physmem array.

Fixes a problem that jmcneill@ pointed out to me.


(skrll)
diff -r1.61 -r1.62 src/sys/arch/evbarm/fdt/fdt_machdep.c

cvs diff -r1.61 -r1.62 src/sys/arch/evbarm/fdt/fdt_machdep.c (expand / switch to unified diff)

--- src/sys/arch/evbarm/fdt/fdt_machdep.c 2019/03/30 13:17:23 1.61
+++ src/sys/arch/evbarm/fdt/fdt_machdep.c 2019/04/24 06:37:31 1.62
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fdt_machdep.c,v 1.61 2019/03/30 13:17:23 jmcneill Exp $ */ 1/* $NetBSD: fdt_machdep.c,v 1.62 2019/04/24 06:37:31 skrll Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2015-2017 Jared McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2015-2017 Jared McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.61 2019/03/30 13:17:23 jmcneill Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.62 2019/04/24 06:37:31 skrll Exp $");
31 31
32#include "opt_machdep.h" 32#include "opt_machdep.h"
33#include "opt_bootconfig.h" 33#include "opt_bootconfig.h"
34#include "opt_ddb.h" 34#include "opt_ddb.h"
35#include "opt_md.h" 35#include "opt_md.h"
36#include "opt_arm_debug.h" 36#include "opt_arm_debug.h"
37#include "opt_multiprocessor.h" 37#include "opt_multiprocessor.h"
38#include "opt_cpuoptions.h" 38#include "opt_cpuoptions.h"
39#include "opt_efi.h" 39#include "opt_efi.h"
40 40
41#include "ukbd.h" 41#include "ukbd.h"
42#include "wsdisplay.h" 42#include "wsdisplay.h"
43 43
@@ -241,34 +241,42 @@ fdt_add_dram_blocks(const struct fdt_mem @@ -241,34 +241,42 @@ fdt_add_dram_blocks(const struct fdt_mem
241 bc->dram[bc->dramblocks].address = m->start; 241 bc->dram[bc->dramblocks].address = m->start;
242 bc->dram[bc->dramblocks].pages = 242 bc->dram[bc->dramblocks].pages =
243 (m->end - m->start) / PAGE_SIZE; 243 (m->end - m->start) / PAGE_SIZE;
244 bc->dramblocks++; 244 bc->dramblocks++;
245} 245}
246 246
247#define MAX_PHYSMEM 64 247#define MAX_PHYSMEM 64
248static int nfdt_physmem = 0; 248static int nfdt_physmem = 0;
249static struct boot_physmem fdt_physmem[MAX_PHYSMEM]; 249static struct boot_physmem fdt_physmem[MAX_PHYSMEM];
250 250
251static void 251static void
252fdt_add_boot_physmem(const struct fdt_memory *m, void *arg) 252fdt_add_boot_physmem(const struct fdt_memory *m, void *arg)
253{ 253{
254 struct boot_physmem *bp = &fdt_physmem[nfdt_physmem++]; 254 const paddr_t saddr = round_page(m->start);
 255 const paddr_t eaddr = trunc_page(m->end);
255 256
256 VPRINTF(" %" PRIx64 " - %" PRIx64 "\n", m->start, m->end - 1); 257 VPRINTF(" %" PRIx64 " - %" PRIx64, m->start, m->end - 1);
 258 if (saddr >= eaddr) {
 259 VPRINTF(" skipped\n");
 260 return;
 261 }
 262 VPRINTF("\n");
 263
 264 struct boot_physmem *bp = &fdt_physmem[nfdt_physmem++];
257 265
258 KASSERT(nfdt_physmem <= MAX_PHYSMEM); 266 KASSERT(nfdt_physmem <= MAX_PHYSMEM);
259 267
260 bp->bp_start = atop(round_page(m->start)); 268 bp->bp_start = atop(saddr);
261 bp->bp_pages = atop(trunc_page(m->end)) - bp->bp_start; 269 bp->bp_pages = atop(eaddr) - bp->bp_start;
262 bp->bp_freelist = VM_FREELIST_DEFAULT; 270 bp->bp_freelist = VM_FREELIST_DEFAULT;
263 271
264#ifdef _LP64 272#ifdef _LP64
265 if (m->end > 0x100000000) 273 if (m->end > 0x100000000)
266 bp->bp_freelist = VM_FREELIST_HIGHMEM; 274 bp->bp_freelist = VM_FREELIST_HIGHMEM;
267#endif 275#endif
268 276
269#ifdef PMAP_NEED_ALLOC_POOLPAGE 277#ifdef PMAP_NEED_ALLOC_POOLPAGE
270 const uint64_t memory_size = *(uint64_t *)arg; 278 const uint64_t memory_size = *(uint64_t *)arg;
271 if (atop(memory_size) > bp->bp_pages) { 279 if (atop(memory_size) > bp->bp_pages) {
272 arm_poolpage_vmfreelist = VM_FREELIST_DIRECTMAP; 280 arm_poolpage_vmfreelist = VM_FREELIST_DIRECTMAP;
273 bp->bp_freelist = VM_FREELIST_DIRECTMAP; 281 bp->bp_freelist = VM_FREELIST_DIRECTMAP;
274 } 282 }