From owner-svn-src-all@freebsd.org Mon Dec 18 11:57:06 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D8465E84B3C; Mon, 18 Dec 2017 11:57:06 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AD0F77706B; Mon, 18 Dec 2017 11:57:06 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBIBv5bI072331; Mon, 18 Dec 2017 11:57:05 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBIBv5xH072330; Mon, 18 Dec 2017 11:57:05 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201712181157.vBIBv5xH072330@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bde set sender to bde@FreeBSD.org using -f From: Bruce Evans Date: Mon, 18 Dec 2017 11:57:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326931 - head/sys/i386/i386 X-SVN-Group: head X-SVN-Commit-Author: bde X-SVN-Commit-Paths: head/sys/i386/i386 X-SVN-Commit-Revision: 326931 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Dec 2017 11:57:06 -0000 Author: bde Date: Mon Dec 18 11:57:05 2017 New Revision: 326931 URL: https://svnweb.freebsd.org/changeset/base/326931 Log: Fix the undersupported option KERNLOAD, part 2: fix crashes in locore when KERNLOAD is smaller than NBPDR (not the default) and PG_G is enabled (the default if the CPU supports it). This case has relatively minor problems with coherency of the permanent double mapping, but the fix in r167869 to improve coherency creates page tables with 3 different errors so never worked. The permanent double mapping is fundamentally broken and will be removed soon. It fundamentally breaks trapping for null pointers and requires complications to avoid cache coherency bugs. It is currently used for only a single instruction in ACPI resume, Many fixes VM86 and/or ACPI and/or the double map were attempted near r1200000. r167869 attempted to fix cache coherency bugs in an unusual case, but the bugs were unreachable because older errors in page tables caused a crash first. This commit just makes r167869 work as intended. Part 1 of these fixes fixed the other errors, but also stopped mapping the PDE for KERNBASE as a large page, so double mapping of this PDE only causes the same problems as when KERNLOAD is the default. Except for the problem of trapping null pointers, r167869 could be used to fix these problems, but it is inactive in usual cases. The only known other problem is that incoherent permissions for page 0 cause spurious traps in VM86 BIOS calls. Reviewed by: kib Modified: head/sys/i386/i386/locore.s Modified: head/sys/i386/i386/locore.s ============================================================================== --- head/sys/i386/i386/locore.s Mon Dec 18 09:35:04 2017 (r326930) +++ head/sys/i386/i386/locore.s Mon Dec 18 11:57:05 2017 (r326931) @@ -790,8 +790,9 @@ no_kernend: * mapping is destroyed in pmap_bootstrap(). Ordinarily, the same page table * pages are shared by the identity mapping and the kernel's native mapping. * However, the permanent identity mapping cannot contain PG_G mappings. - * Thus, if the kernel is loaded within the permanent identity mapping, that - * page table page must be duplicated and not shared. + * Thus, if the (physical) kernel overlaps the permanent identity mapping + * (and PG_G is enabled), the + * page table for the first PDE must be duplicated and not shared. * * N.B. Due to errata concerning large pages and physical address zero, * a PG_PS mapping is not used. @@ -804,10 +805,15 @@ no_kernend: testl $PG_G, R(pgeflag) jz 1f ALLOCPAGES(1) + movl %esi, %eax + movl $1, %ecx + fillkptphys($PG_RW) /* map the new page table in std map */ movl %esi, %edi movl R(IdlePTD), %eax - movl (%eax), %esi + movl (%eax), %esi /* top bits are 0 for PAE */ + andl $~PAGE_MASK, %esi movl %edi, (%eax) + orl $PG_V | PG_RW, (%eax) /* finish writing new PTD[0] */ movl $PAGE_SIZE, %ecx cld rep