From owner-svn-src-all@freebsd.org Mon Dec 2 22:42:07 2019 Return-Path: Delivered-To: svn-src-all@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 13B3B1BB057; Mon, 2 Dec 2019 22:42:07 +0000 (UTC) (envelope-from jeff@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 47Rg8t6pv9z4Vnb; Mon, 2 Dec 2019 22:42:06 +0000 (UTC) (envelope-from jeff@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 B59F16357; Mon, 2 Dec 2019 22:42:06 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xB2Mg6YW044632; Mon, 2 Dec 2019 22:42:06 GMT (envelope-from jeff@FreeBSD.org) Received: (from jeff@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xB2Mg5pU044627; Mon, 2 Dec 2019 22:42:05 GMT (envelope-from jeff@FreeBSD.org) Message-Id: <201912022242.xB2Mg5pU044627@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jeff set sender to jeff@FreeBSD.org using -f From: Jeff Roberson Date: Mon, 2 Dec 2019 22:42:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r355314 - in head/sys: amd64/sgx arm/nvidia/drm2 dev/md vm x86/iommu X-SVN-Group: head X-SVN-Commit-Author: jeff X-SVN-Commit-Paths: in head/sys: amd64/sgx arm/nvidia/drm2 dev/md vm x86/iommu X-SVN-Commit-Revision: 355314 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.29 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, 02 Dec 2019 22:42:07 -0000 Author: jeff Date: Mon Dec 2 22:42:05 2019 New Revision: 355314 URL: https://svnweb.freebsd.org/changeset/base/355314 Log: Fix a few places that free a page from an object without busy held. This is tightening constraints on busy as a precursor to lockless page lookup and should largely be a NOP for these cases. Reviewed by: alc, kib, markj Differential Revision: https://reviews.freebsd.org/D22611 Modified: head/sys/amd64/sgx/sgx.c head/sys/arm/nvidia/drm2/tegra_bo.c head/sys/dev/md/md.c head/sys/vm/vm_glue.c head/sys/x86/iommu/intel_utils.c Modified: head/sys/amd64/sgx/sgx.c ============================================================================== --- head/sys/amd64/sgx/sgx.c Mon Dec 2 22:38:25 2019 (r355313) +++ head/sys/amd64/sgx/sgx.c Mon Dec 2 22:42:05 2019 (r355314) @@ -389,14 +389,16 @@ sgx_enclave_remove(struct sgx_softc *sc, * First remove all the pages except SECS, * then remove SECS page. */ - p_secs = NULL; +restart: TAILQ_FOREACH_SAFE(p, &object->memq, listq, p_next) { - if (p->pindex == SGX_SECS_VM_OBJECT_INDEX) { - p_secs = p; + if (p->pindex == SGX_SECS_VM_OBJECT_INDEX) continue; - } + if (vm_page_busy_acquire(p, VM_ALLOC_WAITFAIL) == 0) + goto restart; sgx_page_remove(sc, p); } + p_secs = vm_page_grab(object, SGX_SECS_VM_OBJECT_INDEX, + VM_ALLOC_NOCREAT); /* Now remove SECS page */ if (p_secs != NULL) sgx_page_remove(sc, p_secs); @@ -723,8 +725,9 @@ sgx_ioctl_create(struct sgx_softc *sc, struct sgx_encl if ((sc->state & SGX_STATE_RUNNING) == 0) { mtx_unlock(&sc->mtx); /* Remove VA page that was just created for SECS page. */ - p = vm_page_lookup(enclave->object, - - SGX_VA_PAGES_OFFS - SGX_SECS_VM_OBJECT_INDEX); + p = vm_page_grab(enclave->object, + - SGX_VA_PAGES_OFFS - SGX_SECS_VM_OBJECT_INDEX, + VM_ALLOC_NOCREAT); sgx_page_remove(sc, p); VM_OBJECT_WUNLOCK(object); goto error; @@ -736,8 +739,9 @@ sgx_ioctl_create(struct sgx_softc *sc, struct sgx_encl dprintf("%s: gp fault\n", __func__); mtx_unlock(&sc->mtx); /* Remove VA page that was just created for SECS page. */ - p = vm_page_lookup(enclave->object, - - SGX_VA_PAGES_OFFS - SGX_SECS_VM_OBJECT_INDEX); + p = vm_page_grab(enclave->object, + - SGX_VA_PAGES_OFFS - SGX_SECS_VM_OBJECT_INDEX, + VM_ALLOC_NOCREAT); sgx_page_remove(sc, p); VM_OBJECT_WUNLOCK(object); goto error; Modified: head/sys/arm/nvidia/drm2/tegra_bo.c ============================================================================== --- head/sys/arm/nvidia/drm2/tegra_bo.c Mon Dec 2 22:38:25 2019 (r355313) +++ head/sys/arm/nvidia/drm2/tegra_bo.c Mon Dec 2 22:42:05 2019 (r355314) @@ -64,6 +64,7 @@ tegra_bo_destruct(struct tegra_bo *bo) VM_OBJECT_WLOCK(bo->cdev_pager); for (i = 0; i < bo->npages; i++) { m = bo->m[i]; + vm_page_busy_acquire(m, 0); cdev_pager_free_page(bo->cdev_pager, m); m->flags &= ~PG_FICTITIOUS; vm_page_unwire_noq(m); Modified: head/sys/dev/md/md.c ============================================================================== --- head/sys/dev/md/md.c Mon Dec 2 22:38:25 2019 (r355313) +++ head/sys/dev/md/md.c Mon Dec 2 22:42:05 2019 (r355314) @@ -1024,14 +1024,6 @@ unmapped_step: return (error); } -static void -md_swap_page_free(vm_page_t m) -{ - - vm_page_xunbusy(m); - vm_page_free(m); -} - static int mdstart_swap(struct md_s *sc, struct bio *bp) { @@ -1080,7 +1072,7 @@ mdstart_swap(struct md_s *sc, struct bio *bp) rv = vm_pager_get_pages(sc->object, &m, 1, NULL, NULL); if (rv == VM_PAGER_ERROR) { - md_swap_page_free(m); + vm_page_free(m); break; } else if (rv == VM_PAGER_FAIL) { /* @@ -1110,7 +1102,7 @@ mdstart_swap(struct md_s *sc, struct bio *bp) rv = vm_pager_get_pages(sc->object, &m, 1, NULL, NULL); if (rv == VM_PAGER_ERROR) { - md_swap_page_free(m); + vm_page_free(m); break; } else if (rv == VM_PAGER_FAIL) pmap_zero_page(m); @@ -1137,10 +1129,10 @@ mdstart_swap(struct md_s *sc, struct bio *bp) rv = vm_pager_get_pages(sc->object, &m, 1, NULL, NULL); if (rv == VM_PAGER_ERROR) { - md_swap_page_free(m); + vm_page_free(m); break; } else if (rv == VM_PAGER_FAIL) { - md_swap_page_free(m); + vm_page_free(m); m = NULL; } else { /* Page is valid. */ @@ -1152,7 +1144,7 @@ mdstart_swap(struct md_s *sc, struct bio *bp) } } else { vm_pager_page_unswapped(m); - md_swap_page_free(m); + vm_page_free(m); m = NULL; } } Modified: head/sys/vm/vm_glue.c ============================================================================== --- head/sys/vm/vm_glue.c Mon Dec 2 22:38:25 2019 (r355313) +++ head/sys/vm/vm_glue.c Mon Dec 2 22:42:05 2019 (r355314) @@ -363,6 +363,7 @@ vm_thread_stack_dispose(vm_object_t ksobj, vm_offset_t m = vm_page_lookup(ksobj, i); if (m == NULL) panic("%s: kstack already missing?", __func__); + vm_page_busy_acquire(m, 0); vm_page_unwire_noq(m); vm_page_free(m); } Modified: head/sys/x86/iommu/intel_utils.c ============================================================================== --- head/sys/x86/iommu/intel_utils.c Mon Dec 2 22:38:25 2019 (r355313) +++ head/sys/x86/iommu/intel_utils.c Mon Dec 2 22:42:05 2019 (r355314) @@ -298,7 +298,7 @@ dmar_pgfree(vm_object_t obj, vm_pindex_t idx, int flag if ((flags & DMAR_PGF_OBJL) == 0) VM_OBJECT_WLOCK(obj); - m = vm_page_lookup(obj, idx); + m = vm_page_grab(obj, idx, VM_ALLOC_NOCREAT); if (m != NULL) { vm_page_free(m); atomic_subtract_int(&dmar_tbl_pagecnt, 1);