From nobody Wed May 18 12:51:49 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 1D0261ADC987; Wed, 18 May 2022 12:51:50 +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 4L3CYL07ySz4WJn; Wed, 18 May 2022 12:51:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652878310; 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=LGU3vNAx4nnCJd33OVPMV5BM0IpslflUOpXbLJhXJxs=; b=ZlMgMpM6mB6YkS1lv5JLgj3Vg4Ktmk2242OhSVGqCqHL2w0Wr8BorY8us1iJVIt6PnrfVW fMJrjCudk4VFfbmA//GyKIqEKKAZT7tDx3KJ5ViqnjhJ+JN28BkBwGKuiumKKoCKUd0YYR 23qde4zZyneOIAn6l7O4BA5Jh6OVvHhaI0+z2pqtIzdTIgqmpNVHgBi+R8L/nlfdi7yjq4 A8uyeEbSZOBF9pRqy7O8xjcdGQVgYGn9kp7aG6PIudlPoPFyw4pYJd0VTdxvThWWQJD8M9 2eIQWChfMbatzhMtFuf2bc5uupR9eqQkKsFHq2C+YdofrnrQESx14hnsywp3QQ== 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 D8C571170; Wed, 18 May 2022 12:51:49 +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 24ICpnH7088277; Wed, 18 May 2022 12:51:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24ICpn4M088276; Wed, 18 May 2022 12:51:49 GMT (envelope-from git) Date: Wed, 18 May 2022 12:51:49 GMT Message-Id: <202205181251.24ICpn4M088276@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ruslan Bukin Subject: git: 182a69328da2 - main - Fix stream table entry (STE) initialization and removal. For PCI devices we have entire L1 descriptor for every session ID (SID), but for non-PCI (e.g. Display Processing Unit DPU), a single L1 descriptor serves multiple SIDs. So prevent re-initialization of L1 descriptor if already initialized. Don't free entire L1 descriptor on every STE removal. 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: br X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 182a69328da2aa081f61369540f5d674c23e277b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652878310; 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=LGU3vNAx4nnCJd33OVPMV5BM0IpslflUOpXbLJhXJxs=; b=UIpkr8FyewPlW4wnIjYeoz4KRuKTz/2UGHF4yLa0tmQ3GMRz+Gy8LpBApERTVAFAIbQHkp mtzDoM0Gd7kt2ftXufAxFtWy/Y6y80OWFHqDDshozJv+9x16b5WQsXmMYDMwE91h+Shs9R +wbCPzaGniscAPLo62VZ+KLW4PTY+C7dgmQsVz7ve23VnG2DVVp8Z0+OCbuyEdR0ITBXKi eE4lMtaMggW4A3jFe+huXnPDSV2wUi7AgK1a9dFm8cADXANGlhTFic7kG8+pWYtF8ls/ak QAQKtp4UJvfAxNYwXWvofSv9tBGLn4x2EAVVh3D2eQSo5CJDJW5cFk8X1aKyvA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652878310; a=rsa-sha256; cv=none; b=I/pJaeWi8d9MDWVs/H8FR8gFttW43wIGvskndQzgVsNbGqE4xK3ZfSXE3scYHoLgg7KCGl Q6cfx0SiJaWOw+gGvYQoAAUuuVH0GeSRjNi7tBIxTQ1t+9tO4U5s1ojwSQCAlGS22Z0OAq 2mkKkmumlxep23PcAGYM+sq7zJvDX31n0Z+eFiEAKBCPo+Sk92xuvADc11OjYL28Ntv6jZ QdFaDfoCcjK6k9igRri4uZqBi7EEnLoZur7HbfkSpq/6ATSwfjZ/M2WCaZwf0vhpR4nFPy HErGHR21Svpk08kbZpQZNMrLhsU40kG2grsp7dVlALIlpQkrFT49RbKNNIPVtg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by br: URL: https://cgit.FreeBSD.org/src/commit/?id=182a69328da2aa081f61369540f5d674c23e277b commit 182a69328da2aa081f61369540f5d674c23e277b Author: Ruslan Bukin AuthorDate: 2022-05-18 12:42:37 +0000 Commit: Ruslan Bukin CommitDate: 2022-05-18 12:42:37 +0000 Fix stream table entry (STE) initialization and removal. For PCI devices we have entire L1 descriptor for every session ID (SID), but for non-PCI (e.g. Display Processing Unit DPU), a single L1 descriptor serves multiple SIDs. So prevent re-initialization of L1 descriptor if already initialized. Don't free entire L1 descriptor on every STE removal. Sponsored by: UKRI --- sys/arm64/iommu/smmu.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/sys/arm64/iommu/smmu.c b/sys/arm64/iommu/smmu.c index ef1f96599789..5d4401c5cee9 100644 --- a/sys/arm64/iommu/smmu.c +++ b/sys/arm64/iommu/smmu.c @@ -776,8 +776,8 @@ smmu_init_ste_s1(struct smmu_softc *sc, struct smmu_cd *cd, return (0); } -static int -smmu_init_ste(struct smmu_softc *sc, struct smmu_cd *cd, int sid, bool bypass) +static uint64_t * +smmu_get_ste_addr(struct smmu_softc *sc, int sid) { struct smmu_strtab *strtab; struct l1_desc *l1_desc; @@ -794,6 +794,16 @@ smmu_init_ste(struct smmu_softc *sc, struct smmu_cd *cd, int sid, bool bypass) STRTAB_STE_DWORDS * 8 * sid); }; + return (addr); +} + +static int +smmu_init_ste(struct smmu_softc *sc, struct smmu_cd *cd, int sid, bool bypass) +{ + uint64_t *addr; + + addr = smmu_get_ste_addr(sc, sid); + if (bypass) smmu_init_ste_bypass(sc, sid, addr); else @@ -804,6 +814,21 @@ smmu_init_ste(struct smmu_softc *sc, struct smmu_cd *cd, int sid, bool bypass) return (0); } +static void +smmu_deinit_ste(struct smmu_softc *sc, int sid) +{ + uint64_t *ste; + + ste = smmu_get_ste_addr(sc, sid); + ste[0] = 0; + + smmu_invalidate_sid(sc, sid); + smmu_sync_cd(sc, sid, 0, true); + smmu_invalidate_sid(sc, sid); + + smmu_sync(sc); +} + static int smmu_init_cd(struct smmu_softc *sc, struct smmu_domain *domain) { @@ -990,6 +1015,10 @@ smmu_init_l1_entry(struct smmu_softc *sc, int sid) strtab = &sc->strtab; l1_desc = &strtab->l1[sid >> STRTAB_SPLIT]; + if (l1_desc->va) { + /* Already allocated. */ + return (0); + } size = 1 << (STRTAB_SPLIT + ilog2(STRTAB_STE_DWORDS) + 3); @@ -1021,7 +1050,7 @@ smmu_init_l1_entry(struct smmu_softc *sc, int sid) return (0); } -static void +static void __unused smmu_deinit_l1_entry(struct smmu_softc *sc, int sid) { struct smmu_strtab *strtab; @@ -1036,10 +1065,8 @@ smmu_deinit_l1_entry(struct smmu_softc *sc, int sid) STRTAB_L1_DESC_DWORDS * 8 * i); *addr = 0; - if (sc->features & SMMU_FEATURE_2_LVL_STREAM_TABLE) { - l1_desc = &strtab->l1[sid >> STRTAB_SPLIT]; - contigfree(l1_desc->va, l1_desc->size, M_SMMU); - } + l1_desc = &strtab->l1[sid >> STRTAB_SPLIT]; + contigfree(l1_desc->va, l1_desc->size, M_SMMU); } static int @@ -1883,7 +1910,7 @@ smmu_ctx_free(device_t dev, struct iommu_ctx *ioctx) sc = device_get_softc(dev); ctx = (struct smmu_ctx *)ioctx; - smmu_deinit_l1_entry(sc, ctx->sid); + smmu_deinit_ste(sc, ctx->sid); LIST_REMOVE(ctx, next);