Thu Feb 2 17:37:49 2017 UTC ()
The first va should depend on the text offset, not the kernel base. Use
rounddown. Note: this value is still wrong, it should be roundup. But
that's another issue that will be fixed in amd64 soon.


(maxv)
diff -r1.238 -r1.239 src/sys/arch/x86/x86/pmap.c

cvs diff -r1.238 -r1.239 src/sys/arch/x86/x86/pmap.c (expand / switch to unified diff)

--- src/sys/arch/x86/x86/pmap.c 2017/02/02 08:57:04 1.238
+++ src/sys/arch/x86/x86/pmap.c 2017/02/02 17:37:49 1.239
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.c,v 1.238 2017/02/02 08:57:04 maxv Exp $ */ 1/* $NetBSD: pmap.c,v 1.239 2017/02/02 17:37:49 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran, and by Maxime Villard. 8 * by Andrew Doran, and by Maxime Villard.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -161,27 +161,27 @@ @@ -161,27 +161,27 @@
161 * Hibler/Jolitz pmap, as modified for FreeBSD by John S. Dyson 161 * Hibler/Jolitz pmap, as modified for FreeBSD by John S. Dyson
162 * and David Greenman. 162 * and David Greenman.
163 * 163 *
164 * [3] the Mach pmap. this pmap, from CMU, seems to have migrated 164 * [3] the Mach pmap. this pmap, from CMU, seems to have migrated
165 * between several processors. the VAX version was done by 165 * between several processors. the VAX version was done by
166 * Avadis Tevanian, Jr., and Michael Wayne Young. the i386 166 * Avadis Tevanian, Jr., and Michael Wayne Young. the i386
167 * version was done by Lance Berc, Mike Kupfer, Bob Baron, 167 * version was done by Lance Berc, Mike Kupfer, Bob Baron,
168 * David Golub, and Richard Draves. the alpha version was 168 * David Golub, and Richard Draves. the alpha version was
169 * done by Alessandro Forin (CMU/Mach) and Chris Demetriou 169 * done by Alessandro Forin (CMU/Mach) and Chris Demetriou
170 * (NetBSD/alpha). 170 * (NetBSD/alpha).
171 */ 171 */
172 172
173#include <sys/cdefs.h> 173#include <sys/cdefs.h>
174__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.238 2017/02/02 08:57:04 maxv Exp $"); 174__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.239 2017/02/02 17:37:49 maxv Exp $");
175 175
176#include "opt_user_ldt.h" 176#include "opt_user_ldt.h"
177#include "opt_lockdebug.h" 177#include "opt_lockdebug.h"
178#include "opt_multiprocessor.h" 178#include "opt_multiprocessor.h"
179#include "opt_xen.h" 179#include "opt_xen.h"
180 180
181#include <sys/param.h> 181#include <sys/param.h>
182#include <sys/systm.h> 182#include <sys/systm.h>
183#include <sys/proc.h> 183#include <sys/proc.h>
184#include <sys/pool.h> 184#include <sys/pool.h>
185#include <sys/kernel.h> 185#include <sys/kernel.h>
186#include <sys/atomic.h> 186#include <sys/atomic.h>
187#include <sys/cpu.h> 187#include <sys/cpu.h>
@@ -1585,27 +1585,27 @@ pmap_init_directmap(struct pmap *kpm) @@ -1585,27 +1585,27 @@ pmap_init_directmap(struct pmap *kpm)
1585 * can. Called only once at boot time, if the CPU supports large pages. 1585 * can. Called only once at boot time, if the CPU supports large pages.
1586 */ 1586 */
1587static void 1587static void
1588pmap_remap_largepages(void) 1588pmap_remap_largepages(void)
1589{ 1589{
1590 extern char __rodata_start; 1590 extern char __rodata_start;
1591 extern char __data_start; 1591 extern char __data_start;
1592 extern char __kernel_end; 1592 extern char __kernel_end;
1593 pd_entry_t *pde; 1593 pd_entry_t *pde;
1594 vaddr_t kva, kva_end; 1594 vaddr_t kva, kva_end;
1595 paddr_t pa; 1595 paddr_t pa;
1596 1596
1597 /* Remap the kernel text using large pages. */ 1597 /* Remap the kernel text using large pages. */
1598 kva = KERNBASE; 1598 kva = rounddown((vaddr_t)KERNTEXTOFF, NBPD_L2);
1599 kva_end = rounddown((vaddr_t)&__rodata_start, NBPD_L1); 1599 kva_end = rounddown((vaddr_t)&__rodata_start, NBPD_L1);
1600 pa = kva - KERNBASE; 1600 pa = kva - KERNBASE;
1601 for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, pa += NBPD_L2) { 1601 for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, pa += NBPD_L2) {
1602 pde = &L2_BASE[pl2_i(kva)]; 1602 pde = &L2_BASE[pl2_i(kva)];
1603 *pde = pa | pmap_pg_g | PG_PS | PG_KR | PG_V; 1603 *pde = pa | pmap_pg_g | PG_PS | PG_KR | PG_V;
1604 tlbflushg(); 1604 tlbflushg();
1605 } 1605 }
1606#if defined(DEBUG) 1606#if defined(DEBUG)
1607 aprint_normal("kernel text is mapped with %" PRIuPSIZE " large " 1607 aprint_normal("kernel text is mapped with %" PRIuPSIZE " large "
1608 "pages and %" PRIuPSIZE " normal pages\n", 1608 "pages and %" PRIuPSIZE " normal pages\n",
1609 howmany(kva - KERNBASE, NBPD_L2), 1609 howmany(kva - KERNBASE, NBPD_L2),
1610 howmany((vaddr_t)&__rodata_start - kva, NBPD_L1)); 1610 howmany((vaddr_t)&__rodata_start - kva, NBPD_L1));
1611#endif /* defined(DEBUG) */ 1611#endif /* defined(DEBUG) */