From nobody Sun Jul 21 08:51:19 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WRcZv735Kz5R4Wg; Sun, 21 Jul 2024 08:51:19 +0000 (UTC) (envelope-from git@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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WRcZv5Jfvz4lTJ; Sun, 21 Jul 2024 08:51:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721551879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RLJV7/L4FEor+2LoE1quZL/+s8TV02zdLOcHL0YKQsQ=; b=p7dZnUA84THCsi6u2AkCZQEfPaBfby6m1jy5flhKWrT1znSaaOIg0MBfL0s58Z+gClxdma 4DOtEJhcZROokwTWsElwA1KBwBpSdF3cl7hg5nHPHxxAyemh6Onqz9L4CGkZbdBvpt14sX V80LVoo3awcd9dDea0EVncFl4yNUxwa0SQhyaYW0e2RupEZwf7g4Haf1PXa7VUi81mqCSG oJk2h9BLQvE4i0nE9IiWdrn398UAs6eSl2Cg4/p4YNhPEqJ46hR60tpYeR9IWquZ2JUP5l Yhn1ja0kUZHSFC2R3BDtqf6yatdsInzdwjqokfXxYvwEE9b1U9njaZ0UFoJDhg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721551879; a=rsa-sha256; cv=none; b=q8MPRmS2y+tV1so8/Pg58ZftecS18Cb5lYrEy4aJg73WyTsD/KET1X8WWSMJ5OE7/VaU/A nmgSTgYL24Cqg717eKFX7HPhmBfM+lBwI5z0CZ71gY+JpDPhKGetT/fF77l2XLrNy0S0An gVAqkGg/ZpNTOEKMyQ1KY9o6R0lJWqwMxlcg4oU2YCfbzJN4AkorF0L2Y4Id+glLs+2MLC OkiH9Kr5qQ5OW7nDpVJ/aEFMVb0nm6CjMefMYrDJPA+oAg/qwMYc8JM9eNRZ0q8hduU0GD 4T4dWLUKnLr1hGJOotBYJpHc6OSaAcYUW/43byOkF5jCC4zbExop+e54u0v6OQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721551879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RLJV7/L4FEor+2LoE1quZL/+s8TV02zdLOcHL0YKQsQ=; b=vAX9csPI6Lwh29q/DhKx1pN194AF12YZddd7K789noMZotGvhPSB8pDyFSktyGUy5MRE+F wmmzBva2kQrTH09EWQ3Xg8Ujpyzv+WO9dL90dmhrTrVGcCdGKxFUC9sRCfk/4S8ew36qhc p8xrFOnRAFuiUweubM5wrRstz5TeXf5rx/0jHz00M1TEHFzDr7bGNbyvxsRe+5nqFsrF/F AiTvv5fCxaBCZkwx/dYx1Ft7eHDIPTqoYpqS/WffdrdmhkxMvZ/Om9EezNX5YuyzHweWIr a7ShFaneJ+Gsy+YZ+q/gtmfl8wr1RKMDPVocuo34xYyVXYlxK9weEkbTgdjTYg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WRcZv4nmwzst9; Sun, 21 Jul 2024 08:51:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46L8pJpE071365; Sun, 21 Jul 2024 08:51:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46L8pJHE071362; Sun, 21 Jul 2024 08:51:19 GMT (envelope-from git) Date: Sun, 21 Jul 2024 08:51:19 GMT Message-Id: <202407210851.46L8pJHE071362@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 240ddb304ff3 - stable/14 - DMAR pagetables pages: handle ref_count special references List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 240ddb304ff327e831f75f8ae27f2e0220211b90 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=240ddb304ff327e831f75f8ae27f2e0220211b90 commit 240ddb304ff327e831f75f8ae27f2e0220211b90 Author: Konstantin Belousov AuthorDate: 2024-07-07 23:26:57 +0000 Commit: Konstantin Belousov CommitDate: 2024-07-21 08:50:29 +0000 DMAR pagetables pages: handle ref_count special references (cherry picked from commit 7773023b72de19c6c9a47fd04ac955ec52773f0f) --- sys/x86/iommu/intel_idpgtbl.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sys/x86/iommu/intel_idpgtbl.c b/sys/x86/iommu/intel_idpgtbl.c index 82cac8bb2d39..deee50858dd2 100644 --- a/sys/x86/iommu/intel_idpgtbl.c +++ b/sys/x86/iommu/intel_idpgtbl.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -391,7 +392,7 @@ retry: * pte write and clean while the lock is * dropped. */ - m->ref_count++; + vm_page_wire(m); sfp = NULL; ptep = domain_pgtbl_map_pte(domain, base, lvl - 1, @@ -399,7 +400,7 @@ retry: if (ptep == NULL) { KASSERT(m->pindex != 0, ("loosing root page %p", domain)); - m->ref_count--; + vm_page_unwire_noq(m); iommu_pgfree(domain->pgtbl_obj, m->pindex, flags); return (NULL); @@ -407,8 +408,8 @@ retry: dmar_pte_store(&ptep->pte, DMAR_PTE_R | DMAR_PTE_W | VM_PAGE_TO_PHYS(m)); dmar_flush_pte_to_ram(domain->dmar, ptep); - sf_buf_page(sfp)->ref_count += 1; - m->ref_count--; + vm_page_wire(sf_buf_page(sfp)); + vm_page_unwire_noq(m); iommu_unmap_pgtbl(sfp); /* Only executed once. */ goto retry; @@ -487,7 +488,7 @@ domain_map_buf_locked(struct dmar_domain *domain, iommu_gaddr_t base, dmar_pte_store(&pte->pte, VM_PAGE_TO_PHYS(ma[pi]) | pflags | (superpage ? DMAR_PTE_SP : 0)); dmar_flush_pte_to_ram(domain->dmar, pte); - sf_buf_page(sf)->ref_count += 1; + vm_page_wire(sf_buf_page(sf)); } if (sf != NULL) iommu_unmap_pgtbl(sf); @@ -593,8 +594,7 @@ domain_unmap_clear_pte(struct dmar_domain *domain, iommu_gaddr_t base, int lvl, iommu_unmap_pgtbl(*sf); *sf = NULL; } - m->ref_count--; - if (m->ref_count != 0) + if (!vm_page_unwire_noq(m)) return; KASSERT(lvl != 0, ("lost reference (lvl) on root pg domain %p base %jx lvl %d", @@ -710,7 +710,7 @@ domain_alloc_pgtbl(struct dmar_domain *domain) m = iommu_pgalloc(domain->pgtbl_obj, 0, IOMMU_PGF_WAITOK | IOMMU_PGF_ZERO | IOMMU_PGF_OBJL); /* No implicit free of the top level page table page. */ - m->ref_count = 1; + vm_page_wire(m); DMAR_DOMAIN_PGUNLOCK(domain); DMAR_LOCK(domain->dmar); domain->iodom.flags |= IOMMU_DOMAIN_PGTBL_INITED; @@ -742,8 +742,10 @@ domain_free_pgtbl(struct dmar_domain *domain) /* Obliterate ref_counts */ VM_OBJECT_ASSERT_WLOCKED(obj); - for (m = vm_page_lookup(obj, 0); m != NULL; m = vm_page_next(m)) - m->ref_count = 0; + for (m = vm_page_lookup(obj, 0); m != NULL; m = vm_page_next(m)) { + vm_page_clearref(m); + vm_wire_sub(1); + } VM_OBJECT_WUNLOCK(obj); vm_object_deallocate(obj); }