On Mon, Oct 05, 2020 at 12:56:38PM +0200, Thierry Reding wrote: > On Mon, Oct 05, 2020 at 11:41:08AM +0300, Dmitry Osipenko wrote: > > 05.10.2020 00:57, Nicolin Chen пишет: > > > On Sat, Oct 03, 2020 at 05:06:42PM +0300, Dmitry Osipenko wrote: > > >> 03.10.2020 09:59, Nicolin Chen пишет: > > >>> static int tegra_smmu_of_xlate(struct device *dev, > > >>> struct of_phandle_args *args) > > >>> { > > >>> + struct platform_device *iommu_pdev = of_find_device_by_node(args->np); > > >>> + struct tegra_mc *mc = platform_get_drvdata(iommu_pdev); > > >>> u32 id = args->args[0]; > > >>> > > >>> + put_device(&iommu_pdev->dev); > > >>> + > > >>> + if (!mc || !mc->smmu) > > >>> + return -EPROBE_DEFER; > > >> > > >> I'm not very excited by seeing code in the patches that can't be > > >> explained by the patch authors and will appreciate if you could provide > > >> a detailed explanation about why this NULL checking is needed because I > > >> think it is unneeded, especially given that other IOMMU drivers don't > > >> have such check. > > > > > > This function could be called from of_iommu_configure(), which is > > > a part of other driver's probe(). So I think it's safer to have a > > > check. Yet, given mc driver is added to the "arch_initcall" stage, > > > you are probably right that there's no really need at this moment > > > because all clients should be called after mc/smmu are inited. So > > > I'll resend a v6, if that makes you happy. > > > > I wanted to get the explanation :) I'm very curious why it's actually > > needed because I'm not 100% sure whether it's not needed at all. > > > > I'd assume that the only possible problem could be if some device is > > created in parallel with the MC probing and there is no locking that > > could prevent this in the drivers core. It's not apparent to me whether > > this situation could happen at all in practice. > > > > The MC is created early and at that time everything is sequential, so > > it's indeed should be safe to remove the check. > > I think I now remember exactly why the "hack" in tegra_smmu_probe() > exists. The reason is that the MC driver does this: > > mc->smmu = tegra_smmu_probe(...); > > That means that mc->smmu is going to be NULL until tegra_smmu_probe() > has finished. But tegra_smmu_probe() calls bus_set_iommu() and that in > turn calls ->probe_device(). So the purpose of the "hack" in the > tegra_smmu_probe() function was to make sure mc->smmu was available at > that point, because, well, it is already known, but we haven't gotten > around to storing it yet. Yea, that's exactly what I described in the commit message of a later version of this patch. Yet, we can drop it now as a device will probe() and call ->probe_device() again. > ->of_xlate() can theoretically be called as early as right after > bus_set_iommu() via of_iommu_configure() if that is called in parallel > with tegra_smmu_probe(). I think that's very unlikely, but I'm not 100% > sure that it can't happen. As my previous reply to Dmitry above, I don't think it'd happen, given that mc/smmu drivers are inited during arch_initcall stage while all clients should be probed during device_initcall stage, once this rework patch gets merged. > In any case, I do agree with Dmitry that we should have a comment here > explaining why this is necessary. Even if we're completely certain that > this is necessary, it's not obvious and therefore should get that > comment. And if we're not certain that it's necessary, it's probably > also good to mention that in the comment so that eventually it can be > determined or the check removed if it proves to be unnecessary. Well, I have answered him, and also removed the mc/smmu check in v6 already.