From nobody Tue Jan 02 00:41:59 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 4T3vF44J1nz560Lj; Tue, 2 Jan 2024 00:42:00 +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 4T3vF401pwz3PpT; Tue, 2 Jan 2024 00:42:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704156120; 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=nmNJ2C4dlDaLNkIkOu9gZE2XajGQauJNW5JVwKO1ehg=; b=PX7+08NwzhBDRRV7C5rdCE31ENblVZD8AHp1MYCO/5DgiNkwUVBMzNfZ6ETACahMdcmoOA GoT/sZHLXgj6i9e4XlByEncrSSf92MzREsdWhj2dXpBcdgsifFKV4x8SGhSbIXG7o7tojV 3UEv94ouiFwlJ0VZvp3Lv+lhwyC5toMVAEPSK4kFgoDUGZKK1a78JQhgyMAnVfoE228iKl q73BPUS0xj+DoBeyslEP/q5GfOQOJvnwn/G5yHymqOLcQ/VQJXYsJ0QncLDADiYFD2QT9z /NNmuaSHr9ShFIJz2lJOd4M41jvI8+3ThimQiREsMekjCnPxB2vmmE+MIF7dvQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704156120; a=rsa-sha256; cv=none; b=LaK/3CyZhjAnAyEKqwW+5Chmu7GxSlazCRuL97qSWiEg9xJGn0lNg+YB6+Cl3u8s+eeplx FJaNOZbsTRhg534Z2nI6G2IlGu0/QZwalyqV3Jc8dhVeQgJ3VnSiLqV0tWH7YTgsVu1LgU oVuqKN8hlcXr9Xe3cFCF518jhDyLeycDYo3AINNexEtsOFOq9UZWg2oafJMWMDVYR7nMDH BJGM07lzfBo9CfeSgkFR2wwFOHenZCFBNYYy69kpfeYdxO+6EGgbNtN4bbhcsBiqn0cH/q moKOtwNnpNnFKHewno39s758HCD9NqWHmaAb6odjuQQ9fwNpWrFAyc08DboAtQ== 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=1704156120; 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=nmNJ2C4dlDaLNkIkOu9gZE2XajGQauJNW5JVwKO1ehg=; b=UookIOCu2HxbhGFqs0ANDUVw2t79zYADcZ8EnxIBeeFavDVUbGaERWGOv0s/32OoEog+6D 1pRwWxOvHKKZFTV52jF9ls3vkFQu6kg3wp1iHDBymNq7bEnO4xwk3z6Z3dt7oj40Y8Qoc9 WOBZ0Y8jGO4aJX6nFBmIR1tbZltFCIsP7dAf3sHJ0niTX9U11a0LaF+gw8ebBr5QybArO4 yrYQeDFGUySYkR1Djyx27ggKVyXmBeU58BMoqi8Q/luQYQ2L4Za3uRJV2oDJzp9H3xKgzB R1lZF9ZzILMfZrsCrzJZz1VHEKRBZrtFXQz2BffX2tE5iKAvv3UseCyH2/5Hcg== 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 4T3vF35JZlzfbj; Tue, 2 Jan 2024 00:41:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4020fxMk096979; Tue, 2 Jan 2024 00:41:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4020fxH7096976; Tue, 2 Jan 2024 00:41:59 GMT (envelope-from git) Date: Tue, 2 Jan 2024 00:41:59 GMT Message-Id: <202401020041.4020fxH7096976@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: 264e49515fb0 - stable/14 - iommu: add iommu_gas_remove_locked() 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: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: 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: 264e49515fb0028bc77af953d8f98ff9de24ae8f Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=264e49515fb0028bc77af953d8f98ff9de24ae8f commit 264e49515fb0028bc77af953d8f98ff9de24ae8f Author: Konstantin Belousov AuthorDate: 2023-12-14 02:41:31 +0000 Commit: Konstantin Belousov CommitDate: 2024-01-02 00:41:39 +0000 iommu: add iommu_gas_remove_locked() (cherry picked from commit 273b4de3462d7825ebe4ace7a1930f098311287f) --- sys/dev/iommu/iommu_gas.c | 83 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/sys/dev/iommu/iommu_gas.c b/sys/dev/iommu/iommu_gas.c index dc850747512a..9a74854f926f 100644 --- a/sys/dev/iommu/iommu_gas.c +++ b/sys/dev/iommu/iommu_gas.c @@ -708,28 +708,20 @@ iommu_gas_remove_unmap(struct iommu_domain *domain, TAILQ_INSERT_TAIL(gcp, entry, dmamap_link); } -/* - * Remove specified range from the GAS of the domain. Note that the - * removal is not guaranteed to occur upon the function return, it - * might be finalized some time after, when hardware reports that - * (queued) IOTLB invalidation was performed. - */ -void -iommu_gas_remove(struct iommu_domain *domain, iommu_gaddr_t start, - iommu_gaddr_t size) +static void +iommu_gas_remove_locked(struct iommu_domain *domain, + iommu_gaddr_t start, iommu_gaddr_t size, + struct iommu_map_entries_tailq *gc, + struct iommu_map_entry **r1, struct iommu_map_entry **r2) { - struct iommu_map_entry *entry, *nentry, *r1, *r2; - struct iommu_map_entries_tailq gc; + struct iommu_map_entry *entry, *nentry; iommu_gaddr_t end; - end = start + size; - r1 = iommu_gas_alloc_entry(domain, IOMMU_PGF_WAITOK); - r2 = iommu_gas_alloc_entry(domain, IOMMU_PGF_WAITOK); - TAILQ_INIT(&gc); + IOMMU_DOMAIN_ASSERT_LOCKED(domain); - IOMMU_DOMAIN_LOCK(domain); + end = start + size; - nentry = iommu_gas_remove_clip_left(domain, start, end, &r1); + nentry = iommu_gas_remove_clip_left(domain, start, end, r1); RB_FOREACH_FROM(entry, iommu_gas_entries_tree, nentry) { if (entry->start >= end) break; @@ -738,11 +730,11 @@ iommu_gas_remove(struct iommu_domain *domain, iommu_gaddr_t start, entry->start, entry->end, start)); if ((entry->flags & IOMMU_MAP_ENTRY_RMRR) != 0) continue; - iommu_gas_remove_unmap(domain, entry, &gc); + iommu_gas_remove_unmap(domain, entry, gc); } - if (iommu_gas_remove_clip_right(domain, end, entry, r2)) { - iommu_gas_remove_unmap(domain, r2, &gc); - r2 = NULL; + if (iommu_gas_remove_clip_right(domain, end, entry, *r2)) { + iommu_gas_remove_unmap(domain, *r2, gc); + *r2 = NULL; } #ifdef INVARIANTS @@ -755,13 +747,52 @@ iommu_gas_remove(struct iommu_domain *domain, iommu_gaddr_t start, entry->start, entry->end, start, end)); } #endif +} + +static void +iommu_gas_remove_init(struct iommu_domain *domain, + struct iommu_map_entries_tailq *gc, struct iommu_map_entry **r1, + struct iommu_map_entry **r2) +{ + TAILQ_INIT(gc); + *r1 = iommu_gas_alloc_entry(domain, IOMMU_PGF_WAITOK); + *r2 = iommu_gas_alloc_entry(domain, IOMMU_PGF_WAITOK); +} +static void +iommu_gas_remove_cleanup(struct iommu_domain *domain, + struct iommu_map_entries_tailq *gc, struct iommu_map_entry **r1, + struct iommu_map_entry **r2) +{ + if (*r1 != NULL) { + iommu_gas_free_entry(*r1); + *r1 = NULL; + } + if (*r2 != NULL) { + iommu_gas_free_entry(*r2); + *r2 = NULL; + } + iommu_domain_unload(domain, gc, true); +} + +/* + * Remove specified range from the GAS of the domain. Note that the + * removal is not guaranteed to occur upon the function return, it + * might be finalized some time after, when hardware reports that + * (queued) IOTLB invalidation was performed. + */ +void +iommu_gas_remove(struct iommu_domain *domain, iommu_gaddr_t start, + iommu_gaddr_t size) +{ + struct iommu_map_entry *r1, *r2; + struct iommu_map_entries_tailq gc; + + iommu_gas_remove_init(domain, &gc, &r1, &r2); + IOMMU_DOMAIN_LOCK(domain); + iommu_gas_remove_locked(domain, start, size, &gc, &r1, &r2); IOMMU_DOMAIN_UNLOCK(domain); - if (r1 != NULL) - iommu_gas_free_entry(r1); - if (r2 != NULL) - iommu_gas_free_entry(r2); - iommu_domain_unload(domain, &gc, true); + iommu_gas_remove_cleanup(domain, &gc, &r1, &r2); } int