From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D09AC4332D for ; Sat, 16 Jan 2021 17:08:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AF3622B37 for ; Sat, 16 Jan 2021 17:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727986AbhAPRIj convert rfc822-to-8bit (ORCPT ); Sat, 16 Jan 2021 12:08:39 -0500 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:35311 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727943AbhAPRIg (ORCPT ); Sat, 16 Jan 2021 12:08:36 -0500 X-Originating-IP: 93.29.109.196 Received: from collins (196.109.29.93.rev.sfr.net [93.29.109.196]) (Authenticated sender: paul.kocialkowski@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 6BD541BF205; Sat, 16 Jan 2021 17:07:52 +0000 (UTC) Date: Sat, 16 Jan 2021 18:07:51 +0100 From: Paul Kocialkowski To: Robin Murphy Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jernej Skrabec , Daniel Vetter , Maxime Ripard , Chen-Yu Tsai , Rob Herring , Thomas Petazzoni , Frank Rowand Subject: Re: [PATCH 1/2] of: device: Allow DMA range map to be set before of_dma_configure_id Message-ID: References: <20210115175831.1184260-1-paul.kocialkowski@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Robin, Le Sat 16 Jan 21, 14:57, Robin Murphy a écrit : > On 2021-01-15 17:58, Paul Kocialkowski wrote: > > A mechanism was recently introduced for the sunxi architecture where > > the DMA offset for specific devices (under the MBUS) is set by a common > > driver (sunxi_mbus). This driver calls dma_direct_set_offset to set > > the device's dma_range_map manually. > > > > However this information was overwritten by of_dma_configure_id, which > > obtains the map from of_dma_get_range (or keeps it NULL when it fails > > and the force_dma argument is true, which is the case for platform > > devices). > > > > As a result, the dma_range_map was always overwritten and the mechanism > > could not correctly take effect. > > > > This adds a check to ensure that no previous DMA range map is > > overwritten and prints a warning when the map was already set while > > also being available from dt. In this case, the map that was already > > set is kept. > > Hang on, the hard-coded offset is only intended to be installed when there > *isn't* anything described in DT, in which case of_dma_get_range() should > always bail out early without touching it anyway. This sounds like > something's not quite right in the MBUS driver, so I don't think working > around it in core code is really the right thing to do. That's right, there is no practical case where the two are in conflict. The problem that I'm solving here is that dev->dma_range_map is *always* assigned, even when of_dma_get_range bailed and map still is NULL. This has the effect of always overwriting what the MBUS driver does (and leaking its memory too). > Do you have a case where one of the relevant devices inherits a "dma-ranges" > via the regular hierarchy without indirecting via an "interconnects" > reference? Currently you're only checking for the latter, so that would be > one way things could go awry (although to be a problem, said "dma-ranges" > would also have to encode something *other* than the appropriate MBUS > offset, which implies an incorrect or at least inaccurately-structured DT as > well). No, I think things are good in that regard. No messed up dt or anything like that :) Cheers, Paul > Robin. > > > Fixes: b4bdc4fbf8d0 ("soc: sunxi: Deal with the MBUS DMA offsets in a central place") > > Signed-off-by: Paul Kocialkowski > > --- > > drivers/of/device.c | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/of/device.c b/drivers/of/device.c > > index aedfaaafd3e7..db1b8634c2c7 100644 > > --- a/drivers/of/device.c > > +++ b/drivers/of/device.c > > @@ -181,7 +181,14 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > - dev->dma_range_map = map; > > + if (!dev->dma_range_map) { > > + dev->dma_range_map = map; > > + } else if (map) { > > + dev_warn(dev, > > + "DMA range map was already set, ignoring range map from dt\n"); > > + kfree(map); > > + } > > + > > return 0; > > } > > EXPORT_SYMBOL_GPL(of_dma_configure_id); > > -- Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com