Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp78245pxk; Mon, 5 Oct 2020 18:24:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfDBMDnLdPa1dF6Oxf5r9MZDPomgKmxWH8xoBDhgDwbOW5YZ0HnSDhZ2bCF8PYEdFSr4xC X-Received: by 2002:a17:906:f205:: with SMTP id gt5mr2643200ejb.48.1601947480988; Mon, 05 Oct 2020 18:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601947480; cv=none; d=google.com; s=arc-20160816; b=lO2xM7hJdrM80BosbUliaHfpeEK0H+w4I3o+v4ibrtjN+FIygbLEdGliacQaDMaLEC NbVM+ceUnaGSBLYY92Evwg2gx+xKE2wOAoqimCQKyo6MmfXB+Fnvc47qS1km8ITO0sll DGAKc2Hqqfk9vNxxVGNCumSCAScLOyEA88FeYG9AatD4DILxCf1zRnXLVWmPUL5k+wXR Ne8fxKD84SsyE/GH9RcCaRb51Yf+JPKOMK71vzSiYg6S5cpuTknn8s+gJC895QY4jLyJ aBXi2wYo0fCwe7lfKtg4AlTuSHsHFVaEz28SaUG7mhXjYMg99ouuv6tpAqiiIU8LNtID FOig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=0yWXKrqXMFP3HPBRZ+yjO3u40MSxEa60RyZK91ANWVM=; b=COXRWcCNHfIv4D9yPrBBKntZUo8iwE+/KFh+OaDA6dnJo2g8hJYDjaupuVXRPxtBam Q+wPKFlLm7ch6h9WqNAAduMZLA31KFWVYjhbcVeIvGI8mxHO9g9kEjJOImnB7XVk8rN5 XYKCKD6W4D4T1TWjwTVLC7F9fu+0hvk+hZWjA3DEhYHmYWXMddDWnxStPjwlcJ4pXkSS XIsFa2JrzYD+99ZookFLJsBLEV+hZgBfjaCkYTmf6JpWg58qQdbRshXS//VOx3unHbx/ 19kKEZlJWhpQrrtam6dk1NknJb0qVBJjP86X3KPEnwBXBqOq2ZhBFIdH91qpFEx+iMhQ GvYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IR2segjE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i27si1155311edb.55.2020.10.05.18.24.17; Mon, 05 Oct 2020 18:24:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IR2segjE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725917AbgJFBVJ (ORCPT + 99 others); Mon, 5 Oct 2020 21:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725872AbgJFBVI (ORCPT ); Mon, 5 Oct 2020 21:21:08 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85867C0613CE; Mon, 5 Oct 2020 18:21:08 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id n14so8062456pff.6; Mon, 05 Oct 2020 18:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=0yWXKrqXMFP3HPBRZ+yjO3u40MSxEa60RyZK91ANWVM=; b=IR2segjEJ+qR4NMC1gYN941vKF3ypk6RnWcPXyMrNE4vaUcV6vlM++CMQo+qS6pcWt voww5nAAvAGxSqSW1u3KPkqNqT2J4TRkKf6OI9m7VITITXKlgpbDd2sbHSaZG7zSUO7D WWUeu6P4x3+FWuC12b4SLzEp1RfY/nHE5l+tf5qD/MlPRSRxbiuNnN7Vdf1LL/AH1IjZ OUkuhRSZ/+FpnT6KiqemDn3RY7xoT5qLEtMFxkhPNCSqjUFRZRAHCDjd2BvZOylmyoM3 RNmH0K4LTk6mjGpWKoA+8ruiBRszLQ/7En+bg/l5oAIKGgDdFDFuNURnRcNS2p7wjikH u22w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=0yWXKrqXMFP3HPBRZ+yjO3u40MSxEa60RyZK91ANWVM=; b=FSxAGw+bQLVd6HRLrKIpg5+oyLdSRev8eKpBbKcNv6ixYuKndvBh4WLodMUSvi6Zv4 mFLx06a8GCCuTRA8nyYxN4Y1AStPk+u/1/3FySlc2YASTofBsnS9x62hFQa6xEovKs71 iKbhyWG8Xb4FOtgxG5OM+PDDEZj39hBEPuo4hptgfoSy7FR5Qiw/UYNHRj4d35mrdhvv 9EtZ+xkrojQ5xm7IG693DgwRg20Tw/6dfsH1T10YDH4Mux5k6Ut0sReLbZs2Jl3WNRJ6 0vShnQ++y3BXlfnbwbZml8Ha1lMNXx7K913LpoQn5MGJoXZfpktXsD9a+oJJGh2kQ1Po 7QtQ== X-Gm-Message-State: AOAM53272pRNCgLoDw4R8e2B/hpneH3rnijDfhUkKUSbh/14nN3AQQjB 4/ELiP45BHNpAeoFjbQAHfLQnkfl0Qw= X-Received: by 2002:a63:e212:: with SMTP id q18mr1900863pgh.356.1601947267951; Mon, 05 Oct 2020 18:21:07 -0700 (PDT) Received: from Asurada-Nvidia (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id v205sm1283135pfc.110.2020.10.05.18.21.07 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Oct 2020 18:21:07 -0700 (PDT) Date: Mon, 5 Oct 2020 18:14:34 -0700 From: Nicolin Chen To: Thierry Reding Cc: Dmitry Osipenko , joro@8bytes.org, vdumpa@nvidia.com, jonathanh@nvidia.com, linux-tegra@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 2/3] iommu/tegra-smmu: Rework tegra_smmu_probe_device() Message-ID: <20201006011434.GC28640@Asurada-Nvidia> References: <20201003065947.18671-1-nicoleotsuka@gmail.com> <20201003065947.18671-3-nicoleotsuka@gmail.com> <4a5a5b1c-080a-327a-1e2f-dc087948e1a1@gmail.com> <20201004215731.GA21420@Asurada-Nvidia> <689c3d90-e05c-d36a-bf37-0bec100040f5@gmail.com> <20201005105638.GO425362@ulmo> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20201005105638.GO425362@ulmo> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.