From nobody Mon Jul 15 07:13:34 2024 X-Original-To: dev-commits-src-all@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 4WMtht4ng0z5QljL; Mon, 15 Jul 2024 07:13:34 +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 4WMtht49nzz4gFn; Mon, 15 Jul 2024 07:13:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721027614; 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=qyn869qAXcD2XwfjMwsS84HtqzMfEjCykzTiTIa71pA=; b=Jjzjepvu5D1iy8SfVAZy8y5V1B/QZXlgMJ82oS3/JZFAxixx9xZmDBxHlF90hYo6Z/vK4i +KC1xpcEg1e+qcSBpvDdOEqHNs4yQbwj2zzm4QWFmtyrP6eED7m2OqUeU/hMS5lPA24m8P WxGnf8Hs9SCmUI/SjXB+HKfSdLOYi0OvO2fivKOvnj6E+tGnPIi8MODMzYf8F3TZXO+MZp FK5ebfd51esln0pqKjhaEPr8p+TzII04+DKhJVUNljr6EB2XuLqvLxYktJV4mdEy/7cozg pUJRlBCfckK1ovWBQ7/rK8N0z10Jycbk0Pi3JFHolJAPH3PKtO9tLzy0zzdxnA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721027614; a=rsa-sha256; cv=none; b=Xx0YRnuFbcg5J+JbrVsqsUfnQI1lr64PPaJZ6kNnnEk07GWaYbbx66TuLNfh51O2degm6M xS3FcUgCauS/P03C1YcJgCc7fnXwFyCY6m5h3MVOi+U060v2GqhhcJQP+fhKov/4YT3vGs 9GNeSRFX+LKeJBUTVTBW+s0LaEcc+DD8+UIvy9rcGMcrtUg7kohor6L1FBSRwLHsYNkite BIkmPKAu6r3r7Vg+0B/3x0GuMpnvTGaWYt7PG4rSR0swHnf7UGJd2k/hshlwv1KC1hFo7X +GANFFSJTrsxVhU+HVkiEoA3NVIYjezXO03wTJE5rPl/kOpLcH6EKi2PttFHDg== 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=1721027614; 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=qyn869qAXcD2XwfjMwsS84HtqzMfEjCykzTiTIa71pA=; b=mb0eo0bE97Xf1QGJBGuxZRiAaIAsN3gSjXB3vCzuogczmLdVq5wc4sVlvDtxqF8SU7KnOw J/cB2rsNRSiolztGBT2WZsqxU51amLuQ0nYj4BJgSiQuLwaQ19yG3LoPa6sNbgpU/BBUoZ 3YKJ7xoolSU9mU+wARVTgVjJQEsakmASezxGy8clQyXGXfg0zH91en3jKu9g/AVIJTREz6 3+ZHypaWnQyDyKRAR+hihhYiV99sal3SSC/eUjN+JvKNQmsBoA8qaSkQ4FpcduxWwJojIh ZmGQoc20aMjiHUVDHarUX8IIHuMO5yS06DXdg5opM8iV3ogIpWIamn/jIJkvJQ== 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 4WMtht3b0Jzjlh; Mon, 15 Jul 2024 07:13:34 +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 46F7DYbV015482; Mon, 15 Jul 2024 07:13:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46F7DYLm015479; Mon, 15 Jul 2024 07:13:34 GMT (envelope-from git) Date: Mon, 15 Jul 2024 07:13:34 GMT Message-Id: <202407150713.46F7DYLm015479@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 7773023b72de - main - DMAR pagetables pages: handle ref_count special references List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 7773023b72de19c6c9a47fd04ac955ec52773f0f Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=7773023b72de19c6c9a47fd04ac955ec52773f0f commit 7773023b72de19c6c9a47fd04ac955ec52773f0f Author: Konstantin Belousov AuthorDate: 2024-07-07 23:26:57 +0000 Commit: Konstantin Belousov CommitDate: 2024-07-15 06:15:53 +0000 DMAR pagetables pages: handle ref_count special references Preserve object reference and block bit during refcount arithmetic and obliteration, by using vm_page_wire()/unwire_noq(). Reviewed by: markj Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D45910 --- 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 157afaec75ef..de38a6fece94 100644 --- a/sys/x86/iommu/intel_idpgtbl.c +++ b/sys/x86/iommu/intel_idpgtbl.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -390,7 +391,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, @@ -398,7 +399,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); @@ -406,8 +407,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; @@ -486,7 +487,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); @@ -592,8 +593,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", @@ -709,7 +709,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; @@ -741,8 +741,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); }