From nobody Fri May 06 18:31:47 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 8F3071AC19E3;
Fri, 6 May 2022 18:31:56 +0000 (UTC)
(envelope-from br@bsdpad.com)
Received: from mail.bsdpad.com (mail.bsdpad.com [116.202.106.248])
(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 mx1.freebsd.org (Postfix) with ESMTPS id 4KvzgH6Hwnz4mjm;
Fri, 6 May 2022 18:31:55 +0000 (UTC)
(envelope-from br@bsdpad.com)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=bsdpad.com;
s=20201212; h=Subject:To:From;
bh=+7v3i6NYcdyhGoyam3ADKyT1lQjfurhaBBSe9SDdkpM=; b=k2S0h76IE0eD8OgVomkQFFiNtd
GUlreFQT2LFR+M02pI0hzc8gesyHZVC+iZJo/vdhXWGqR/BPzd4WN5bQQmwO+O855LzHS85QjySmV
sYeY7TqHE5nutQbGXAUlIx4T2e5DDIZu2MNced7FpCuLVTqIUI3OTzx/UZwObdT5yNSTCqu0GHVJt
HwZtP+SDFNK6K/OzoQLwLmmcT7v/mvuNuUHTGaLUyA5pDCC5IzyhSz1CgJ/iUdJASBhRRvscBnPxi
2OfS4w3JIfp4SaWhy+MYSWs7HWFwGD9C78XpLv1CacFxyjtBzRtUamgtX2Eb+WzmPmJJ9H/oPsE1L
f25A7CnA==;
Received: from localhost ([127.0.0.1] helo=bsdpad.com)
by mail.bsdpad.com with smtp (Exim 4.94 (FreeBSD))
(envelope-from
)
id 1nn2jz-000BZE-2I; Fri, 06 May 2022 19:31:47 +0100
Received: by bsdpad.com (nbSMTP-1.00) for uid 1001
br@bsdpad.com; Fri, 6 May 2022 19:31:47 +0100 (BST)
Date: Fri, 6 May 2022 19:31:47 +0100
From: Ruslan Bukin
To: Kyle Evans
Cc: Ravi Pokala ,
src-committers ,
"" ,
dev-commits-src-main@freebsd.org
Subject: Re: 0b6bacc7874f - main - Add ofw_bus_iommu_map() that maps PCI
requester ID to an IOMMU specifier based on "iommu-map" DTS property.
Message-ID:
References: <202205061551.246FpO6o060060@gitrepo.freebsd.org>
<450C9313-CB5A-4DCA-97FB-40FC87886F00@panasas.com>
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-Disposition: inline
In-Reply-To:
X-Rspamd-Queue-Id: 4KvzgH6Hwnz4mjm
X-Spamd-Bar: ---
Authentication-Results: mx1.freebsd.org;
dkim=pass header.d=bsdpad.com header.s=20201212 header.b=k2S0h76I;
dmarc=none;
spf=pass (mx1.freebsd.org: domain of br@bsdpad.com designates 116.202.106.248 as permitted sender) smtp.mailfrom=br@bsdpad.com
X-Spamd-Result: default: False [-3.20 / 15.00];
ARC_NA(0.00)[];
NEURAL_HAM_MEDIUM(-1.00)[-0.999];
R_DKIM_ALLOW(-0.20)[bsdpad.com:s=20201212];
FREEFALL_USER(0.00)[br];
FROM_HAS_DN(0.00)[];
TO_DN_SOME(0.00)[];
TO_MATCH_ENVRCPT_ALL(0.00)[];
R_SPF_ALLOW(-0.20)[+mx];
MIME_GOOD(-0.10)[text/plain];
DMARC_NA(0.00)[freebsd.org];
NEURAL_HAM_LONG(-1.00)[-1.000];
RCPT_COUNT_FIVE(0.00)[5];
DKIM_TRACE(0.00)[bsdpad.com:+];
NEURAL_HAM_SHORT(-1.00)[-1.000];
MLMMJ_DEST(0.00)[dev-commits-src-all,dev-commits-src-main];
FORGED_SENDER(0.30)[br@freebsd.org,br@bsdpad.com];
MIME_TRACE(0.00)[0:+];
RCVD_TLS_LAST(0.00)[];
ASN(0.00)[asn:24940, ipnet:116.202.0.0/16, country:DE];
FROM_NEQ_ENVFROM(0.00)[br@freebsd.org,br@bsdpad.com];
RCVD_COUNT_TWO(0.00)[2]
X-ThisMailContainsUnwantedMimeParts: N
On Fri, May 06, 2022 at 09:37:36AM -0700, Kyle Evans wrote:
> On Fri, May 6, 2022 at 9:25 AM Ravi Pokala wrote:
> >
> > -----Original Message-----
> > From: on behalf of Ruslan Bukin
> > Date: 2022-05-06, Friday at 08:51
> > To: , ,
> > Subject: git: 0b6bacc7874f - main - Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU specifier based on "iommu-map" DTS property.
> >
> > The branch main has been updated by br:
> >
> > URL: https://cgit.FreeBSD.org/src/commit/?id=0b6bacc7874f9c68ad35b06f1a7614171eb9ab10
> >
> > commit 0b6bacc7874f9c68ad35b06f1a7614171eb9ab10
> > Author: Ruslan Bukin
> > AuthorDate: 2022-05-06 15:41:11 +0000
> > Commit: Ruslan Bukin
> > CommitDate: 2022-05-06 15:48:04 +0000
> >
> > Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU
> > specifier based on "iommu-map" DTS property.
> >
> > Sponsored by: UKRI
> > ---
> > sys/dev/ofw/ofw_bus_subr.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> > sys/dev/ofw/ofw_bus_subr.h | 3 ++-
> > 2 files changed, 46 insertions(+), 1 deletion(-)
> >
> > diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c
> > index ea57d1086779..408d554b3c7f 100644
> > --- a/sys/dev/ofw/ofw_bus_subr.c
> > +++ b/sys/dev/ofw/ofw_bus_subr.c
> > @@ -491,6 +491,50 @@ ofw_bus_msimap(phandle_t node, uint16_t pci_rid, phandle_t *msi_parent,
> > return (err);
> > }
> >
> > +int
> > +ofw_bus_iommu_map(phandle_t node, uint16_t pci_rid, phandle_t *iommu_parent,
> > + uint32_t *iommu_rid)
> > +{
> > + pcell_t mask, iommu_base, rid_base, rid_length;
> > + uint32_t masked_rid;
> > + pcell_t map[4];
> > + ssize_t len;
> > + int err, i;
> > +
> > + len = OF_getproplen(node, "iommu-map");
> > + if (len <= 0)
> > + return (ENOENT);
> > + if (len > sizeof(map))
> > + return (ENOMEM);
> > +
> > + len = OF_getencprop(node, "iommu-map", map, 16);
> > +
> > + err = ENOENT;
> > + mask = 0xffffffff;
> > + OF_getencprop(node, "iommu-map-mask", &mask, sizeof(mask));
> > +
> > + masked_rid = pci_rid & mask;
> > + for (i = 0; i < len; i += 4) {
> > + rid_base = map[i + 0];
> > + rid_length = map[i + 3];
> >
> > Hi Ruslan,
> >
> > I'm confused by this. 'map' is declared as a 4-element array, which means 'map[i + 0]' and 'map[i + 3]' are both only valid when 'i' is 0. But 'i' is the loop iterator; doesn't that mean you're accessing outside the array after the 0th time through the loop?
> >
>
> The comparison looks like it's wrong and inherited from
> ofw_bus_msimap() -- i is in terms of # cells, OF_getencprop returns
> size in bytes, This version only holds one mapping (four cells) at a
> time, so the intention is just one iteration through the loop.
>
> We'll need to extend this at some point, the M1 FDT has 3 4-cell mappings
> here. ofw_bus_msimap() was almost an exact fit, and an adapted version
> is what I use in my m1 branch.
iommu-map property is an arbitrary number of tuples of (rid-base,iommu,iommu-base,length).
Do you mean that some of the items in the tuple could occupy more than one 32-bit cell?
I grepped DTS tree, so far each of occurrence takes just 1 cell.
Ruslan