From owner-svn-src-head@freebsd.org Wed Feb 20 22:41:18 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 375DB14DF54F; Wed, 20 Feb 2019 22:41:18 +0000 (UTC) (envelope-from andrew@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) server-signature RSA-PSS (4096 bits) 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 CAE9872928; Wed, 20 Feb 2019 22:41:17 +0000 (UTC) (envelope-from andrew@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 B609BC1FF; Wed, 20 Feb 2019 22:41:14 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x1KMfEdJ055515; Wed, 20 Feb 2019 22:41:14 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x1KMfEpZ055514; Wed, 20 Feb 2019 22:41:14 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201902202241.x1KMfEpZ055514@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Wed, 20 Feb 2019 22:41:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r344391 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: andrew X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 344391 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: CAE9872928 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.950,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-0.999,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 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: Wed, 20 Feb 2019 22:41:18 -0000 Author: andrew Date: Wed Feb 20 22:41:14 2019 New Revision: 344391 URL: https://svnweb.freebsd.org/changeset/base/344391 Log: Unwire the kcov buffer when freeing the info struct. Without this the physical memory will not be returned to the kernel. While here call vm_object_reference on the object when mmapping the buffer. This removed the need for buggy tracking of if it has been mapped or not. This fixes issues where kcov could use all the system memory. Reported by: tuexen Reviewed by: kib Sponsored by: DARPA, AFTL Differential Revision: https://reviews.freebsd.org/D19252 Modified: head/sys/kern/kern_kcov.c Modified: head/sys/kern/kern_kcov.c ============================================================================== --- head/sys/kern/kern_kcov.c Wed Feb 20 22:32:28 2019 (r344390) +++ head/sys/kern/kern_kcov.c Wed Feb 20 22:41:14 2019 (r344391) @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include MALLOC_DEFINE(M_KCOV_INFO, "kcovinfo", "KCOV info type"); @@ -347,6 +348,7 @@ kcov_mmap_single(struct cdev *dev, vm_ooffset_t *offse info->mmap != false) return (EINVAL); + vm_object_reference(info->bufobj); info->mmap = true; *offset = 0; *object = info->bufobj; @@ -393,13 +395,26 @@ kcov_alloc(struct kcov_info *info, size_t entries) static void kcov_free(struct kcov_info *info) { + vm_page_t m; + size_t i; if (info->kvaddr != 0) { pmap_qremove(info->kvaddr, info->bufsize / PAGE_SIZE); kva_free(info->kvaddr, info->bufsize); } - if (info->bufobj != NULL && !info->mmap) + if (info->bufobj != NULL) { + VM_OBJECT_WLOCK(info->bufobj); + m = vm_page_lookup(info->bufobj, 0); + for (i = 0; i < info->bufsize / PAGE_SIZE; i++) { + vm_page_lock(m); + vm_page_unwire_noq(m); + vm_page_unlock(m); + + m = vm_page_next(m); + } + VM_OBJECT_WUNLOCK(info->bufobj); vm_object_deallocate(info->bufobj); + } free(info, M_KCOV_INFO); }