From nobody Sat Oct 05 07:11:35 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 4XLGml6kDzz5XrVX; Sat, 05 Oct 2024 07:11:35 +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 4XLGml38BQz4NZd; Sat, 5 Oct 2024 07:11:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112295; 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=I4M26U1c4xyYVcwBUCu9OyaJMiW0X6nmQRTdnXmoL/c=; b=IK0E56271XO7vx+VY0wSNQmZWUbPeXVIRJGB/dwaIxO2z2gMJa6ogGmIAbC8sD2kZWM2q5 HOaB6VIOA1/nkR0TrPNPoBTFRt/y+v6/iynnRM39KNAl7d0tJt4kJZbSUdWC5gJw/6nuWU +VDG+AzwT0+rKLTEeNgCM1Zb3EA1EJ7v7wEz2R5ca5QO+ThTOvItZJlXH24sUIjqC4btZy q5vQp9M0PhVskbIluV726d7YnLgfum74fEuDrc7insOmilnyxY+BD2wnvU/KYVOyj/LOMC /TfR9dPAUUp/PGeLDCr64QhFFThr5+kHNHP+2QdtXB1CtGEbSqz5mmzxZZE8mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112295; 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=I4M26U1c4xyYVcwBUCu9OyaJMiW0X6nmQRTdnXmoL/c=; b=C+WReJTcsm6zso0jvFw+8lUwCNVeK12XW6ofUE/6idbfNBhjBXSpxlv90yIX20MIl2KXEh ZNkTwLBQC6kR0zLkRa3hDi5MdiFg9RHqgHoxehN+OlcU7t3dODP4y4mrPE+B0dOaNBJIHK hn53JW5SZNXXcxJaDargKqPaaYqHsvzOuGWWaV1lsqD+ctu1Craa5IiCfu1RFF2hqsKUbN nVujcRtbl2a0WJ+MDnNGMPFP70EpMObzOhj3Q+w2A1CqIm1nhXlu8pIl/ZfR6alJnbE9aW gs7dGlvjg7LKz0QUttzx6ovph4D5Igg/aW9rLXnPkBNKWwQqTrYtaDHxpRoNGw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728112295; a=rsa-sha256; cv=none; b=UtgU9SPKfnHKTLpjTAimq+/v5ImDyF/hW0j0A6WJAEDpmOAi0VEFsJi/ywv/pD8YUNNdcH eOkeVK7A25YrlaSuROOOd5HTcdMmu2dgWQqWoc5PuwHF5gT0XRvcbcZbVfzPbftLU6lXOt 03qWcfs0QdGQ+T77Xkex7Qi3vB7kyFLEmgXhoDh1HirvMbAe3ZVQiHd5kXO41TbmodbSG2 Fk8k7rlspcJjVI1iqwJWYr4GHCsDYjHwzCLSMeAFqEWaa9Ai7tH0tjYHIs1ODmCZDrwdTB 1PriHyH7qvWApXCzd86q9E9i1Oko6LtMIrUOvfF2SljnLw/wc/vz1OFhIpnM5w== 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 4XLGml2mXsz17pP; Sat, 5 Oct 2024 07:11:35 +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 4957BZxm001929; Sat, 5 Oct 2024 07:11:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4957BZah001926; Sat, 5 Oct 2024 07:11:35 GMT (envelope-from git) Date: Sat, 5 Oct 2024 07:11:35 GMT Message-Id: <202410050711.4957BZah001926@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: 0c7e13cfe204 - stable/14 - iommu: extend iommu_map_entry to store the list of associated freed page table pages 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 0c7e13cfe2045fb17a0583d0a2a1f685225bf7d5 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0c7e13cfe2045fb17a0583d0a2a1f685225bf7d5 commit 0c7e13cfe2045fb17a0583d0a2a1f685225bf7d5 Author: Konstantin Belousov AuthorDate: 2024-09-25 01:50:34 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-05 07:08:56 +0000 iommu: extend iommu_map_entry to store the list of associated freed page table pages (cherry picked from commit f713ed6694d949ec37365533afbb47c04f919572) --- sys/dev/iommu/iommu.h | 3 +++ sys/dev/iommu/iommu_gas.c | 14 +++++++++++--- sys/x86/iommu/intel_idpgtbl.c | 4 ++-- sys/x86/iommu/iommu_utils.c | 15 +++++++++++---- sys/x86/iommu/x86_iommu.h | 3 ++- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/sys/dev/iommu/iommu.h b/sys/dev/iommu/iommu.h index 84d8c3680b71..73d0a6f1279b 100644 --- a/sys/dev/iommu/iommu.h +++ b/sys/dev/iommu/iommu.h @@ -31,6 +31,8 @@ #ifndef _DEV_IOMMU_IOMMU_H_ #define _DEV_IOMMU_IOMMU_H_ +#include +#include #include struct bus_dma_tag_common; @@ -61,6 +63,7 @@ struct iommu_map_entry { RB_ENTRY(iommu_map_entry) rb_entry; /* Links for domain entries */ struct iommu_domain *domain; struct iommu_qi_genseq gseq; + struct spglist pgtbl_free; }; struct iommu_unit { diff --git a/sys/dev/iommu/iommu_gas.c b/sys/dev/iommu/iommu_gas.c index 26ac38da3c4f..d97bdee47b28 100644 --- a/sys/dev/iommu/iommu_gas.c +++ b/sys/dev/iommu/iommu_gas.c @@ -96,9 +96,12 @@ iommu_gas_alloc_entry(struct iommu_domain *domain, u_int flags) res = uma_zalloc(iommu_map_entry_zone, ((flags & IOMMU_PGF_WAITOK) != 0 ? M_WAITOK : M_NOWAIT) | M_ZERO); - if (res != NULL && domain != NULL) { - res->domain = domain; - atomic_add_int(&domain->entries_cnt, 1); + if (res != NULL) { + SLIST_INIT(&res->pgtbl_free); + if (domain != NULL) { + res->domain = domain; + atomic_add_int(&domain->entries_cnt, 1); + } } return (res); } @@ -107,7 +110,12 @@ void iommu_gas_free_entry(struct iommu_map_entry *entry) { struct iommu_domain *domain; + int n __unused; + n = vm_page_free_pages_toq(&entry->pgtbl_free, false); +#if defined(__i386__) || defined(__amd64__) + atomic_subtract_int(&iommu_tbl_pagecnt, n); +#endif domain = entry->domain; if (domain != NULL) atomic_subtract_int(&domain->entries_cnt, 1); diff --git a/sys/x86/iommu/intel_idpgtbl.c b/sys/x86/iommu/intel_idpgtbl.c index a949e38cc9b1..9dc7a2d58b3f 100644 --- a/sys/x86/iommu/intel_idpgtbl.c +++ b/sys/x86/iommu/intel_idpgtbl.c @@ -368,7 +368,7 @@ retry: ("loosing root page %p", domain)); vm_page_unwire_noq(m); iommu_pgfree(domain->pgtbl_obj, m->pindex, - flags); + flags, NULL); return (NULL); } dmar_pte_store(&ptep->pte, DMAR_PTE_R | DMAR_PTE_W | @@ -572,7 +572,7 @@ dmar_unmap_clear_pte(struct dmar_domain *domain, iommu_gaddr_t base, int lvl, KASSERT(m->pindex != 0, ("lost reference (idx) on root pg domain %p base %jx lvl %d", domain, (uintmax_t)base, lvl)); - iommu_pgfree(domain->pgtbl_obj, m->pindex, flags); + iommu_pgfree(domain->pgtbl_obj, m->pindex, flags, NULL); dmar_free_pgtbl_pde(domain, base, lvl - 1, flags); } diff --git a/sys/x86/iommu/iommu_utils.c b/sys/x86/iommu/iommu_utils.c index 2011c632f770..8ff15cc86cb8 100644 --- a/sys/x86/iommu/iommu_utils.c +++ b/sys/x86/iommu/iommu_utils.c @@ -109,7 +109,8 @@ iommu_pgalloc(vm_object_t obj, vm_pindex_t idx, int flags) } void -iommu_pgfree(vm_object_t obj, vm_pindex_t idx, int flags) +iommu_pgfree(vm_object_t obj, vm_pindex_t idx, int flags, + struct iommu_map_entry *entry) { vm_page_t m; @@ -117,8 +118,13 @@ iommu_pgfree(vm_object_t obj, vm_pindex_t idx, int flags) VM_OBJECT_WLOCK(obj); m = vm_page_grab(obj, idx, VM_ALLOC_NOCREAT); if (m != NULL) { - vm_page_free(m); - atomic_subtract_int(&iommu_tbl_pagecnt, 1); + if (entry == NULL) { + vm_page_free(m); + atomic_subtract_int(&iommu_tbl_pagecnt, 1); + } else { + vm_page_remove_xbusy(m); /* keep page busy */ + SLIST_INSERT_HEAD(&entry->pgtbl_free, m, plinks.s.ss); + } } if ((flags & IOMMU_PGF_OBJL) == 0) VM_OBJECT_WUNLOCK(obj); @@ -154,7 +160,8 @@ iommu_map_pgtbl(vm_object_t obj, vm_pindex_t idx, int flags, sched_unpin(); if (allocated) { VM_OBJECT_ASSERT_WLOCKED(obj); - iommu_pgfree(obj, m->pindex, flags | IOMMU_PGF_OBJL); + iommu_pgfree(obj, m->pindex, flags | IOMMU_PGF_OBJL, + NULL); } if ((flags & IOMMU_PGF_OBJL) == 0) VM_OBJECT_WUNLOCK(obj); diff --git a/sys/x86/iommu/x86_iommu.h b/sys/x86/iommu/x86_iommu.h index a1ed5c71c513..4d0ac8351e2e 100644 --- a/sys/x86/iommu/x86_iommu.h +++ b/sys/x86/iommu/x86_iommu.h @@ -48,7 +48,8 @@ struct vm_object; struct vm_page *iommu_pgalloc(struct vm_object *obj, vm_pindex_t idx, int flags); -void iommu_pgfree(struct vm_object *obj, vm_pindex_t idx, int flags); +void iommu_pgfree(struct vm_object *obj, vm_pindex_t idx, int flags, + struct iommu_map_entry *entry); void *iommu_map_pgtbl(struct vm_object *obj, vm_pindex_t idx, int flags, struct sf_buf **sf); void iommu_unmap_pgtbl(struct sf_buf *sf);