From nobody Tue Dec 26 01:28:55 2023 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 4SzccS2bX7z55H02; Tue, 26 Dec 2023 01:28:56 +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 4SzccS02GJz3gKx; Tue, 26 Dec 2023 01:28:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703554136; 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=zurRu4gAQgy+MvS9pWW+ATYFD481vHXtXvNCJOcNDsY=; b=vlD8agzD56a8YWFR3F7zqe3uTIwwboxsnSq3vL6e/3hMaPzSywlVVrwLa6PNfyjvcf3WD6 iJgjdu5eNMEDa83nHTu05mQl9Myw95/ET6BBVbxEz1iQSM3CPEXtknP1gyH8ILsl6ffzON Onyl+RvDlDgl1edaeIxA6fYyXzyWN50JfwjSo4dsGr+fPr4PeMKhmZBtXwzV4mWu4MwqjN b0HIPNQfb66avF0DZF20A7UD3Tb7kUMHbFwfYL8R+giOZo0r+JwXiqMyIACHCvL5PRadSL D9CC+ZMPWExsg4Z0+gtxp5SNTSEGQOO5GORdDSyIZfQS8rds5sCu2GVcROKGrQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703554136; a=rsa-sha256; cv=none; b=cNB9l9CRSysB6MqZzjKmlKe4MpBS0n0qZgPVNpbLM2rLjfCuqBdvZuOOmr7qcykQ2LYKwc z4664q9iu1sUcPzE4hWfmr2S5mkMZKIY2BuPF+zzGAgtvlJxqh/CT8WrY2k16m1EnleIax mOpvUFz83TsGmLLUwnKG0fYpH01IVb+b8y1ysCIB16SISgq26UnzdPkrTY4BBpTgW3nsJf 28FYb6cEHb/8bUTA76A8VrzOmV5Vi0xWXOfsVnPxWYjfiT5qkeifDzZ8IHOq8zbQScFi+6 RHVznSj+EMe8+im4boZVA3hCrDndbbJOw6rEUV8nXqWbJqMeLlSMw0P9s5/NSQ== 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=1703554136; 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=zurRu4gAQgy+MvS9pWW+ATYFD481vHXtXvNCJOcNDsY=; b=Wk0zgz0tFQ0oyJKcQXB2/kQdhYN2CCo7j0DI91ln/vwoYzd+fbwrdBZiLwHbhwFpp2DX4P 9pAK2NuMbNQdppTesud6It1q+d4dCoUuyOy04Xhn+oX9sVevrGWQL0xIxo5KZsvwqf6wxZ IvzlqRsrkz4ggFGIg1FhBQ70SXl+cQTNMsUF6aD7rF2JyLbIivW8D4HzYgau5ToxysW7w9 vrw8KKw8BHaILtPLqG2a/U4LeVNypr2WvPESwwdtxGdHS3tmjIic1lzhkrDVXCGptI9u7v Pip27mOXdUU3Vl3PChXvhWP3oNtGVIi4eE2D/0pF8ENRCcbPaGb/dMUotuafCQ== 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 4SzccR65rczZxd; Tue, 26 Dec 2023 01:28:55 +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 3BQ1Stnm035697; Tue, 26 Dec 2023 01:28:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BQ1StOf035694; Tue, 26 Dec 2023 01:28:55 GMT (envelope-from git) Date: Tue, 26 Dec 2023 01:28:55 GMT Message-Id: <202312260128.3BQ1StOf035694@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: 273b4de3462d - main - iommu: add iommu_gas_remove_locked() 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 273b4de3462d7825ebe4ace7a1930f098311287f Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=273b4de3462d7825ebe4ace7a1930f098311287f commit 273b4de3462d7825ebe4ace7a1930f098311287f Author: Konstantin Belousov AuthorDate: 2023-12-14 02:41:31 +0000 Commit: Konstantin Belousov CommitDate: 2023-12-26 01:28:22 +0000 iommu: add iommu_gas_remove_locked() Sponsored by: The FreeBSD Foundation MFC after: 1 week --- 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