From nobody Fri May 06 18:44:01 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 5B1741AC5329; Fri, 6 May 2022 18:44:08 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KvzxN20T4z4pcx; Fri, 6 May 2022 18:44:08 +0000 (UTC) (envelope-from kevans@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651862648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/RbhQx4VmutIg88RnQQJrDoOkVrLqsnIkPT/a5/JrgE=; b=ZuzaXOxTTBF/1AZkR9eSTqnls0PS3sNxPA7cSvJwCss3mBNrvtssx0m8yJIhjtwTmROvOv zf7rDpkNzlwJsLV9TwI5bEaaxy2Nv51S3r91MO4bUZTH7/uBmhIgxTitRBssGeqR91A/MD TUteWA2U/oveViVcNhO0uCRIOEBcyISUdUCtIxXWoAZVih55IxY86DkNWLP9Kk+s7jpQhB gm63gdWI4KsFkkmopQ9CBfgxWY7Xyj8mIEI4CpqsCem/avCsAaLcW9QmcaYdfHoL7KuLce 6vC0nXlRefA40feV6SnJB0CXWecKZ+AHDcQyCoaNPMXhYkiUgoUemLjb0tgUrQ== Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) (Authenticated sender: kevans) by smtp.freebsd.org (Postfix) with ESMTPSA id 1F838BEB; Fri, 6 May 2022 18:44:08 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: by mail-lf1-f54.google.com with SMTP id w1so14022292lfa.4; Fri, 06 May 2022 11:44:08 -0700 (PDT) X-Gm-Message-State: AOAM53061Orvpxt+yrrVYnCnQXk1/joMFLCKhLltmu6o2LeYoWS6m1Ms z+93lt1jlwRiwvAOy7V3YFbHyxMk4M7O5c3YUag= X-Google-Smtp-Source: ABdhPJxeAjUgG8Gp5sax1hwJlRSHbLsCqAGOE9JXvOshca14zjIDpEgg6iiEF8x42idOFKqdMJGTB10R8eeWzlU7EXs= X-Received: by 2002:a05:6512:400e:b0:450:e09d:c9a6 with SMTP id br14-20020a056512400e00b00450e09dc9a6mr3543894lfb.243.1651862646744; Fri, 06 May 2022 11:44:06 -0700 (PDT) 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 References: <202205061551.246FpO6o060060@gitrepo.freebsd.org> <450C9313-CB5A-4DCA-97FB-40FC87886F00@panasas.com> In-Reply-To: From: Kyle Evans Date: Fri, 6 May 2022 11:44:01 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: 0b6bacc7874f - main - Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU specifier based on "iommu-map" DTS property. To: Ruslan Bukin Cc: Kyle Evans , Ravi Pokala , src-committers , "" , dev-commits-src-main@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651862648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/RbhQx4VmutIg88RnQQJrDoOkVrLqsnIkPT/a5/JrgE=; b=OwJ7tcuJzQyM5R9d3dL7z0oC5ISchMarq2szGT+nJk9k7Kg6ILJb9b6HDvTA/vooS5ytax ORB1MaHeXn2o1rT3WbGB2l8A2fKRKGjOABug0ODRasJymo4bBFUjf95X3TjAaQHOCRerFG Ui5etmuGxHTTidWxGXZeU6SZCpSWMhd6gKcYzd7I0C/RgemaS2DPJPOqon+K9JYpOUcajT iqubZlk5R2UwTaWBaV48uy4sQJXCUb4ESHXkqtHaNq3dH9wmTVXJWPY7JG9EqWtI3IMg8P 5ML4kXQK8EJ7zR5AU9FN+m2SKnWuKV8j3DUApdHkd2TSq9XQxKcDZPOkwUN2wg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651862648; a=rsa-sha256; cv=none; b=QpOHyLuUt6qOfojKcZOVMhh/xsaxJ1Uq/f8NTgsH6VhGizXBZfZzq1c/AKMLKfdWTCDOQM 8ruMDTnJQeh14UzVufjtKr6+AsGinS+G9J7WBf+N8Yf5C7RSSrL5+0bFsm6P4nwo/P3pSL ET7c4BDeHX8HeXyyqBOlvHnV3SHrNnVpCFPSu4ttXAh/k7O4zlCNbY++hN8sAi6ojzPC22 BcODDnccfP0Re7064RLud1UhYCrOBUeOJx+WHt6GpE2kAAAdF7OBPnF3MpaoN+pjFubHq6 4ew0nHuDETx6O+4xjZgufWo86B10OnCZlv4hwlq4TUn0rBDLckNonOchktB40g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N On Fri, May 6, 2022 at 11:31 AM Ruslan Bukin wrote: > > 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=3D0b6bacc7874f9c68ad= 35b06f1a7614171eb9ab10 > > > > > > 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 IOMM= U > > > 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_sub= r.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 *i= ommu_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 =3D OF_getproplen(node, "iommu-map"); > > > + if (len <=3D 0) > > > + return (ENOENT); > > > + if (len > sizeof(map)) > > > + return (ENOMEM); > > > + > > > + len =3D OF_getencprop(node, "iommu-map", map, 16); > > > + > > > + err =3D ENOENT; > > > + mask =3D 0xffffffff; > > > + OF_getencprop(node, "iommu-map-mask", &mask, sizeof(mask)); > > > + > > > + masked_rid =3D pci_rid & mask; > > > + for (i =3D 0; i < len; i +=3D 4) { > > > + rid_base =3D map[i + 0]; > > > + rid_length =3D map[i + 3]; > > > > > > Hi Ruslan, > > > > > > I'm confused by this. 'map' is declared as a 4-element array, which m= eans '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 arr= ay 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 mappin= gs > > 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,io= mmu-base,length). > Do you mean that some of the items in the tuple could occupy more than on= e 32-bit cell? > I grepped DTS tree, so far each of occurrence takes just 1 cell. > Oh, sorry, I'm wrong about this still holding. What I was talking about specifically was: + for (i =3D 0; i < len; i +=3D 4) { i is an index into map, but len should be the number of bytes (sizeof(pcell_t) * 4, so 16 in all of your cases) that was allocated for map rather than the number of entries in it. i.e., this should have been i * sizeof(pcell_t) or len / sizeof(pcell_t) as a terminal. But this is the difference between OF_*_multi() and the non-multi versions, the non-multi versions return the size in bytes of the map while the multi versions return the number of cells.