From owner-svn-src-head@freebsd.org Thu Jul 16 23:29:28 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 88CB0370A2D; Thu, 16 Jul 2020 23:29:28 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B79Sm2xnJz4F6Y; Thu, 16 Jul 2020 23:29:28 +0000 (UTC) (envelope-from cem@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 49640102A6; Thu, 16 Jul 2020 23:29:28 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06GNTS0b089415; Thu, 16 Jul 2020 23:29:28 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06GNTQs0089408; Thu, 16 Jul 2020 23:29:26 GMT (envelope-from cem@FreeBSD.org) Message-Id: <202007162329.06GNTQs0089408@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Thu, 16 Jul 2020 23:29:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363266 - in head/sys: amd64/amd64 i386/i386 mips/mips powerpc/aim powerpc/booke X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: in head/sys: amd64/amd64 i386/i386 mips/mips powerpc/aim powerpc/booke X-SVN-Commit-Revision: 363266 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2020 23:29:28 -0000 Author: cem Date: Thu Jul 16 23:29:26 2020 New Revision: 363266 URL: https://svnweb.freebsd.org/changeset/base/363266 Log: Revert r240317 to prevent leaking pmap entries Subsequent to r240317, kmem_free() was replaced with kva_free() (r254025). kva_free() releases the KVA allocation for the mapped region, but no longer clears the pmap (pagetable) entries. An affected pmap_unmapdev operation would leave the still-pmap'd VA space free for allocation by other KVA consumers. However, this bug easily avoided notice for ~7 years because most devices (1) never call pmap_unmapdev and (2) on amd64, mostly fit within the DMAP and do not need KVA allocations. Other affected arch are less popular: i386, MIPS, and PowerPC. Arm64, arm32, and riscv are not affected. Reported by: Don Morris Submitted by: Don Morris (amd64 part) Reviewed by: kib, markj, Don (!amd64 parts) MFC after: I don't intend to, but you might want to Sponsored by: Dell Isilon Differential Revision: https://reviews.freebsd.org/D25689 Modified: head/sys/amd64/amd64/pmap.c head/sys/i386/i386/pmap.c head/sys/mips/mips/pmap.c head/sys/powerpc/aim/mmu_oea.c head/sys/powerpc/aim/mmu_oea64.c head/sys/powerpc/aim/mmu_radix.c head/sys/powerpc/booke/pmap.c Modified: head/sys/amd64/amd64/pmap.c ============================================================================== --- head/sys/amd64/amd64/pmap.c Thu Jul 16 23:05:18 2020 (r363265) +++ head/sys/amd64/amd64/pmap.c Thu Jul 16 23:29:26 2020 (r363266) @@ -8279,8 +8279,10 @@ pmap_unmapdev(vm_offset_t va, vm_size_t size) return; } } - if (pmap_initialized) + if (pmap_initialized) { + pmap_qremove(va, atop(size)); kva_free(va, size); + } } /* Modified: head/sys/i386/i386/pmap.c ============================================================================== --- head/sys/i386/i386/pmap.c Thu Jul 16 23:05:18 2020 (r363265) +++ head/sys/i386/i386/pmap.c Thu Jul 16 23:29:26 2020 (r363266) @@ -5538,8 +5538,10 @@ __CONCAT(PMTYPE, unmapdev)(vm_offset_t va, vm_size_t s return; } } - if (pmap_initialized) + if (pmap_initialized) { + pmap_qremove(va, atop(size)); kva_free(va, size); + } } /* Modified: head/sys/mips/mips/pmap.c ============================================================================== --- head/sys/mips/mips/pmap.c Thu Jul 16 23:05:18 2020 (r363265) +++ head/sys/mips/mips/pmap.c Thu Jul 16 23:29:26 2020 (r363266) @@ -3264,6 +3264,7 @@ pmap_unmapdev(vm_offset_t va, vm_size_t size) base = trunc_page(va); offset = va & PAGE_MASK; size = roundup(size + offset, PAGE_SIZE); + pmap_qremove(base, atop(size)); kva_free(base, size); #endif } Modified: head/sys/powerpc/aim/mmu_oea.c ============================================================================== --- head/sys/powerpc/aim/mmu_oea.c Thu Jul 16 23:05:18 2020 (r363265) +++ head/sys/powerpc/aim/mmu_oea.c Thu Jul 16 23:29:26 2020 (r363266) @@ -2673,6 +2673,7 @@ moea_unmapdev(vm_offset_t va, vm_size_t size) base = trunc_page(va); offset = va & PAGE_MASK; size = roundup(offset + size, PAGE_SIZE); + moea_qremove(base, atop(size)); kva_free(base, size); } } Modified: head/sys/powerpc/aim/mmu_oea64.c ============================================================================== --- head/sys/powerpc/aim/mmu_oea64.c Thu Jul 16 23:05:18 2020 (r363265) +++ head/sys/powerpc/aim/mmu_oea64.c Thu Jul 16 23:29:26 2020 (r363266) @@ -2869,6 +2869,7 @@ moea64_unmapdev(vm_offset_t va, vm_size_t size) offset = va & PAGE_MASK; size = roundup2(offset + size, PAGE_SIZE); + moea64_qremove(base, atop(size)); kva_free(base, size); } Modified: head/sys/powerpc/aim/mmu_radix.c ============================================================================== --- head/sys/powerpc/aim/mmu_radix.c Thu Jul 16 23:05:18 2020 (r363265) +++ head/sys/powerpc/aim/mmu_radix.c Thu Jul 16 23:29:26 2020 (r363266) @@ -5846,8 +5846,10 @@ mmu_radix_unmapdev(vm_offset_t va, vm_size_t size) size = round_page(offset + size); va = trunc_page(va); - if (pmap_initialized) + if (pmap_initialized) { + mmu_radix_qremove(va, atop(size)); kva_free(va, size); + } } static __inline void Modified: head/sys/powerpc/booke/pmap.c ============================================================================== --- head/sys/powerpc/booke/pmap.c Thu Jul 16 23:05:18 2020 (r363265) +++ head/sys/powerpc/booke/pmap.c Thu Jul 16 23:29:26 2020 (r363266) @@ -2322,6 +2322,7 @@ mmu_booke_unmapdev(vm_offset_t va, vm_size_t size) base = trunc_page(va); offset = va & PAGE_MASK; size = roundup(offset + size, PAGE_SIZE); + mmu_booke_qremove(base, atop(size)); kva_free(base, size); } #endif