From nobody Mon Aug 08 07:08:09 2022 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 4M1S2y2qfKz4YGlZ; Mon, 8 Aug 2022 07:08:10 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M1S2y1GtPz3D7k; Mon, 8 Aug 2022 07:08:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659942490; 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=YvqriZS0gvs6CvoAE0grNQqTzaWx8uSmzA55uIFajV0=; b=lHOQWDiqO0G91Ii7ZYngyRrpeLnNpBMrcfye9J01MTwHAYnlf7t7BU3gvgftADIUxkvSht oint4ASfebcYvA8qcXoyw26Je/hl10jgSn4f6otePRL8rNvtAuRcKK2rM13zkyt6nE5WNI iDqTJn26GmoEGsYpqoLhF0QljRcwmFiiOTHrYZRuGupNsMLJZDHk4ES/wT7ES8ecd2YVZ9 6fXj3DitlM02z4t3H7uLfCh+3lex8ad4zEP00DqwOr+lhTjuFp48HnXsdF2/FZXibO35il oao4HPHeRpO1fMJ0pwDvP8mWpEpD5uTyOhaywBgWNL8NP1dEEfEhxUGmJKmdJg== 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 4M1S2y0Nd9zjqQ; Mon, 8 Aug 2022 07:08:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 278789bP019268; Mon, 8 Aug 2022 07:08:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 278789L8019267; Mon, 8 Aug 2022 07:08:09 GMT (envelope-from git) Date: Mon, 8 Aug 2022 07:08:09 GMT Message-Id: <202208080708.278789L8019267@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Doug Moore Subject: git: fb110e510438 - stable/13 - iommu_gas: Eliminate redundant parameters and push down lock acquisition 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dougm X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: fb110e510438ecf93e834843add23fde9f965a4c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659942490; 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=YvqriZS0gvs6CvoAE0grNQqTzaWx8uSmzA55uIFajV0=; b=Vk1BINs+CUJDlsmwCz+7YqYHH37Z05tIFvFFTR6E4Pkfd6oEu8vUD3+Dic4OquzQ3FAgZh TbD/mH1ytIR64NRKxDsBVkkRhyONV4Tcgq3NAliZ174DPUWr18gFBPrRejlmlOPvPndaex GauBZcrp7QQH3Lm924IQsfALmP/uRr6k9hFX2Jrb94kCwiuJwrBVM4TDlfn+kUkKmfFQSM BGKB62lWnWJLpBButSXPqWHcYsrzvhQY+Fd6k1TzC4+b6RcGMm1TNApTjb63tNjjdHq6+i HvL1SylABisxYgvAQ0a20Pdd1bU11nvQ40z9/cDa9a8FzNVowDFo0nBMgxKtlQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659942490; a=rsa-sha256; cv=none; b=PrNhw+48XmY91z19P4O8Pbr9+tHXl5Ck09GeCMXTeC9NODSFH5j+PjBPvEC6EIwLkqBAwf 244m4Tr3lsR+LTHGSppiji2I0h2jdUB6cuuduC5eC5L6SDmIwuYqM98hRHoBNo1aXw+p33 HoJqkLd6BMUKpJfeUXqbgfaHVJiIWJ0QMRRLZJdNS9da8CTJpoGaaJoYbb3cg3izcJPcL6 gLmoHwIo3ndxnEk/gpKJJoR0oPVK4JYjg9/wuCKjYbtLHZOg9M+s6BthfbMio6N4+cgU4E kw/MlD78PmWClWWuzjKDYMS6hSmXMtQVjtA7C8qPVZAMvRbv41BaDktoFt4XdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=fb110e510438ecf93e834843add23fde9f965a4c commit fb110e510438ecf93e834843add23fde9f965a4c Author: Alan Cox AuthorDate: 2022-07-29 06:14:46 +0000 Commit: Doug Moore CommitDate: 2022-08-08 07:07:50 +0000 iommu_gas: Eliminate redundant parameters and push down lock acquisition Since IOMMU map entries store a reference to the domain in which they reside, there is no need to pass the domain to iommu_gas_free_entry(), iommu_gas_free_space(), and iommu_gas_free_region(). Push down the acquisition and release of the IOMMU domain lock into iommu_gas_free_space() and iommu_gas_free_region(). Both of these changes allow for simplifications in the callers of the functions without really complicating the functions themselves. Moreover, the latter change eliminates the direct use of the IOMMU domain lock from the x86-specific DMAR code. Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D35995 (cherry picked from commit 4670f90846d49027bf23435a30895a74264f1e79) --- sys/arm64/iommu/iommu.c | 10 ++-------- sys/dev/iommu/busdma_iommu.c | 4 ++-- sys/dev/iommu/iommu.h | 9 +++------ sys/dev/iommu/iommu_gas.c | 44 +++++++++++++++++++++++++------------------- sys/x86/iommu/intel_ctx.c | 13 ++++--------- sys/x86/iommu/intel_qi.c | 10 +++------- 6 files changed, 39 insertions(+), 51 deletions(-) diff --git a/sys/arm64/iommu/iommu.c b/sys/arm64/iommu/iommu.c index 0a7503976036..e8aa56f92c4f 100644 --- a/sys/arm64/iommu/iommu.c +++ b/sys/arm64/iommu/iommu.c @@ -280,16 +280,10 @@ iommu_free_ctx(struct iommu_ctx *ioctx) static void iommu_domain_free_entry(struct iommu_map_entry *entry, bool free) { - struct iommu_domain *iodom; - - iodom = entry->domain; - - IOMMU_DOMAIN_LOCK(iodom); - iommu_gas_free_space(iodom, entry); - IOMMU_DOMAIN_UNLOCK(iodom); + iommu_gas_free_space(entry); if (free) - iommu_gas_free_entry(iodom, entry); + iommu_gas_free_entry(entry); else entry->flags = 0; } diff --git a/sys/dev/iommu/busdma_iommu.c b/sys/dev/iommu/busdma_iommu.c index 4accafc64377..99960daa3219 100644 --- a/sys/dev/iommu/busdma_iommu.c +++ b/sys/dev/iommu/busdma_iommu.c @@ -1019,7 +1019,7 @@ bus_dma_iommu_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map1, ma = malloc(sizeof(vm_page_t) * atop(length), M_TEMP, waitok ? M_WAITOK : M_NOWAIT); if (ma == NULL) { - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); return (ENOMEM); } for (i = 0; i < atop(length); i++) { @@ -1034,7 +1034,7 @@ bus_dma_iommu_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map1, TAILQ_INSERT_TAIL(&map->map_entries, entry, dmamap_link); IOMMU_DMAMAP_UNLOCK(map); } else { - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); } for (i = 0; i < atop(length); i++) vm_page_putfake(ma[i]); diff --git a/sys/dev/iommu/iommu.h b/sys/dev/iommu/iommu.h index fefd0f615be5..ae4022c5c4f7 100644 --- a/sys/dev/iommu/iommu.h +++ b/sys/dev/iommu/iommu.h @@ -169,15 +169,12 @@ void iommu_gas_init_domain(struct iommu_domain *domain); void iommu_gas_fini_domain(struct iommu_domain *domain); struct iommu_map_entry *iommu_gas_alloc_entry(struct iommu_domain *domain, u_int flags); -void iommu_gas_free_entry(struct iommu_domain *domain, - struct iommu_map_entry *entry); -void iommu_gas_free_space(struct iommu_domain *domain, - struct iommu_map_entry *entry); +void iommu_gas_free_entry(struct iommu_map_entry *entry); +void iommu_gas_free_space(struct iommu_map_entry *entry); int iommu_gas_map(struct iommu_domain *domain, const struct bus_dma_tag_common *common, iommu_gaddr_t size, int offset, u_int eflags, u_int flags, vm_page_t *ma, struct iommu_map_entry **res); -void iommu_gas_free_region(struct iommu_domain *domain, - struct iommu_map_entry *entry); +void iommu_gas_free_region(struct iommu_map_entry *entry); int iommu_gas_map_region(struct iommu_domain *domain, struct iommu_map_entry *entry, u_int eflags, u_int flags, vm_page_t *ma); int iommu_gas_reserve_region(struct iommu_domain *domain, iommu_gaddr_t start, diff --git a/sys/dev/iommu/iommu_gas.c b/sys/dev/iommu/iommu_gas.c index bac15edcf849..bad56ab9140e 100644 --- a/sys/dev/iommu/iommu_gas.c +++ b/sys/dev/iommu/iommu_gas.c @@ -107,12 +107,11 @@ iommu_gas_alloc_entry(struct iommu_domain *domain, u_int flags) } void -iommu_gas_free_entry(struct iommu_domain *domain, struct iommu_map_entry *entry) +iommu_gas_free_entry(struct iommu_map_entry *entry) { + struct iommu_domain *domain; - KASSERT(domain == entry->domain, - ("mismatched free domain %p entry %p entry->domain %p", domain, - entry, entry->domain)); + domain = entry->domain; if (domain != NULL) atomic_subtract_int(&domain->entries_cnt, 1); uma_zfree(iommu_map_entry_zone, entry); @@ -261,7 +260,7 @@ iommu_gas_fini_domain(struct iommu_domain *domain) (IOMMU_MAP_ENTRY_PLACE | IOMMU_MAP_ENTRY_UNMAPPED), ("start entry flags %p", domain)); RB_REMOVE(iommu_gas_entries_tree, &domain->rb_root, entry); - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); entry = RB_MAX(iommu_gas_entries_tree, &domain->rb_root); KASSERT(entry->start == domain->end, ("end entry start %p", domain)); @@ -270,7 +269,7 @@ iommu_gas_fini_domain(struct iommu_domain *domain) (IOMMU_MAP_ENTRY_PLACE | IOMMU_MAP_ENTRY_UNMAPPED), ("end entry flags %p", domain)); RB_REMOVE(iommu_gas_entries_tree, &domain->rb_root, entry); - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); RB_FOREACH_SAFE(entry, iommu_gas_entries_tree, &domain->rb_root, entry1) { @@ -278,7 +277,7 @@ iommu_gas_fini_domain(struct iommu_domain *domain) ("non-RMRR entry left %p", domain)); RB_REMOVE(iommu_gas_entries_tree, &domain->rb_root, entry); - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); } } @@ -558,32 +557,37 @@ iommu_gas_alloc_region(struct iommu_domain *domain, struct iommu_map_entry *entr } void -iommu_gas_free_space(struct iommu_domain *domain, struct iommu_map_entry *entry) +iommu_gas_free_space(struct iommu_map_entry *entry) { + struct iommu_domain *domain; - IOMMU_DOMAIN_ASSERT_LOCKED(domain); + domain = entry->domain; KASSERT((entry->flags & (IOMMU_MAP_ENTRY_PLACE | IOMMU_MAP_ENTRY_RMRR | IOMMU_MAP_ENTRY_MAP)) == IOMMU_MAP_ENTRY_MAP, ("permanent entry %p %p", domain, entry)); + IOMMU_DOMAIN_LOCK(domain); iommu_gas_rb_remove(domain, entry); entry->flags &= ~IOMMU_MAP_ENTRY_MAP; #ifdef INVARIANTS if (iommu_check_free) iommu_gas_check_free(domain); #endif + IOMMU_DOMAIN_UNLOCK(domain); } void -iommu_gas_free_region(struct iommu_domain *domain, struct iommu_map_entry *entry) +iommu_gas_free_region(struct iommu_map_entry *entry) { + struct iommu_domain *domain; struct iommu_map_entry *next, *prev; - IOMMU_DOMAIN_ASSERT_LOCKED(domain); + domain = entry->domain; KASSERT((entry->flags & (IOMMU_MAP_ENTRY_PLACE | IOMMU_MAP_ENTRY_RMRR | IOMMU_MAP_ENTRY_MAP)) == IOMMU_MAP_ENTRY_RMRR, ("non-RMRR entry %p %p", domain, entry)); + IOMMU_DOMAIN_LOCK(domain); prev = RB_PREV(iommu_gas_entries_tree, &domain->rb_root, entry); next = RB_NEXT(iommu_gas_entries_tree, &domain->rb_root, entry); iommu_gas_rb_remove(domain, entry); @@ -593,6 +597,7 @@ iommu_gas_free_region(struct iommu_domain *domain, struct iommu_map_entry *entry iommu_gas_rb_insert(domain, domain->first_place); if (next == NULL) iommu_gas_rb_insert(domain, domain->last_place); + IOMMU_DOMAIN_UNLOCK(domain); } int @@ -621,7 +626,7 @@ iommu_gas_map(struct iommu_domain *domain, error = iommu_gas_find_space(&a); if (error == ENOMEM) { IOMMU_DOMAIN_UNLOCK(domain); - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); return (error); } #ifdef INVARIANTS @@ -657,6 +662,9 @@ iommu_gas_map_region(struct iommu_domain *domain, struct iommu_map_entry *entry, iommu_gaddr_t start; int error; + KASSERT(entry->domain == domain, + ("mismatched domain %p entry %p entry->domain %p", domain, + entry, entry->domain)); KASSERT(entry->flags == 0, ("used RMRR entry %p %p %x", domain, entry, entry->flags)); KASSERT((flags & ~(IOMMU_MF_CANWAIT | IOMMU_MF_RMRR)) == 0, @@ -716,7 +724,7 @@ iommu_gas_reserve_region(struct iommu_domain *domain, iommu_gaddr_t start, error = iommu_gas_reserve_region_locked(domain, start, end, entry); IOMMU_DOMAIN_UNLOCK(domain); if (error != 0) - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); else if (entry0 != NULL) *entry0 = entry; return (error); @@ -770,7 +778,7 @@ iommu_gas_reserve_region_extend(struct iommu_domain *domain, } /* Release a preallocated entry if it was not used. */ if (entry != NULL) - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); return (error); } @@ -788,11 +796,9 @@ iommu_unmap_msi(struct iommu_ctx *ctx) domain->ops->unmap(domain, entry->start, entry->end - entry->start, IOMMU_PGF_WAITOK); - IOMMU_DOMAIN_LOCK(domain); - iommu_gas_free_space(domain, entry); - IOMMU_DOMAIN_UNLOCK(domain); + iommu_gas_free_space(entry); - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); domain->msi_entry = NULL; domain->msi_base = 0; @@ -832,7 +838,7 @@ iommu_map_msi(struct iommu_ctx *ctx, iommu_gaddr_t size, int offset, * We lost the race and already have an * MSI page allocated. Free the unneeded entry. */ - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); } } else if (domain->msi_entry != NULL) { /* diff --git a/sys/x86/iommu/intel_ctx.c b/sys/x86/iommu/intel_ctx.c index b36531ec6d17..a51f799ccbd8 100644 --- a/sys/x86/iommu/intel_ctx.c +++ b/sys/x86/iommu/intel_ctx.c @@ -307,7 +307,7 @@ domain_init_rmrr(struct dmar_domain *domain, device_t dev, int bus, error = error1; } TAILQ_REMOVE(&rmrr_entries, entry, dmamap_link); - iommu_gas_free_entry(DOM2IODOM(domain), entry); + iommu_gas_free_entry(entry); } for (i = 0; i < size; i++) vm_page_putfake(ma[i]); @@ -848,17 +848,12 @@ dmar_find_ctx_locked(struct dmar_unit *dmar, uint16_t rid) void dmar_domain_free_entry(struct iommu_map_entry *entry, bool free) { - struct iommu_domain *domain; - - domain = entry->domain; - IOMMU_DOMAIN_LOCK(domain); if ((entry->flags & IOMMU_MAP_ENTRY_RMRR) != 0) - iommu_gas_free_region(domain, entry); + iommu_gas_free_region(entry); else - iommu_gas_free_space(domain, entry); - IOMMU_DOMAIN_UNLOCK(domain); + iommu_gas_free_space(entry); if (free) - iommu_gas_free_entry(domain, entry); + iommu_gas_free_entry(entry); else entry->flags = 0; } diff --git a/sys/x86/iommu/intel_qi.c b/sys/x86/iommu/intel_qi.c index 3a0012763000..baaf5b472a2c 100644 --- a/sys/x86/iommu/intel_qi.c +++ b/sys/x86/iommu/intel_qi.c @@ -415,7 +415,6 @@ static void dmar_qi_task(void *arg, int pending __unused) { struct dmar_unit *unit; - struct iommu_domain *domain; struct iommu_map_entry *entry, *head; uint32_t ics; @@ -440,14 +439,11 @@ dmar_qi_task(void *arg, int pending __unused) if (!dmar_qi_seq_processed(unit, &entry->gseq)) break; unit->tlb_flush_head = entry; - iommu_gas_free_entry(head->domain, head); - domain = entry->domain; - IOMMU_DOMAIN_LOCK(domain); + iommu_gas_free_entry(head); if ((entry->flags & IOMMU_MAP_ENTRY_RMRR) != 0) - iommu_gas_free_region(domain, entry); + iommu_gas_free_region(entry); else - iommu_gas_free_space(domain, entry); - IOMMU_DOMAIN_UNLOCK(domain); + iommu_gas_free_space(entry); } if (unit->inv_seq_waiters > 0) { /*