Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp387459imm; Thu, 6 Sep 2018 04:12:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaDcIHAsraINqwGfUncwlMMWc1UsEtqW2ay0sPKx6m6wqWyzKNVjwHBxUWzUcwv1uup8VOS X-Received: by 2002:a62:2b50:: with SMTP id r77-v6mr2222535pfr.51.1536232330321; Thu, 06 Sep 2018 04:12:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536232330; cv=none; d=google.com; s=arc-20160816; b=JGeo/Vo0NalHa8Z4poJxPifRmk2m9qC2RHp4X0PqiisGy4adxreQexFz5PPS+BPjzx 1aF0ZMMDA8nqr8N7ctn6xtD7MOpgc5UmzWsDOKLZI7FYJDVcOnOH7r9Cz0tBBODQsEN9 O4neXLVvzQ0fVMCbORjb1svzwN5HKCGaNRSAeyyOMIIRPfEzV8Tlmns+uq3wi4tahXyW p3lIGNtAJv1CtYzLzSVM9WqiDMQxHZd/VR6re53jW1jBYPaWVyP7mcV0RDDyHlGiMTnR aBlwmeuxGYqqzALdRbul+V+zMb8E9OpFPuxIO/9PwarUChkEQ2pCgAalnxbtBmEtSeRq 6wlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=3W3Rhz1GHtVkIiGklAJ+4IjZAAqtTfM2I359FeYpW1Y=; b=HjzaFGP9vNzF0ot4yVWlR3eKkYDnI66iI+I6MwzJ2LKVphDlxoDIfDEGktuHXBQfcO UAyEpC5rmywwLnuAyJp+trBwoP9xXixXtNHOxneQLd+KFs9XaTTsdZBL37DtRipaw6VM 33O6blnx7OBfzaaOm0if2e7t7cNeYMu2V0OJBJkreSY3M78l/j+Pr5MBjlrFWJ+GfUYT NuIgJlMz4rZhZCesA/TcstlwB+9EvUeaeGWYlfmcQ1e51ItfzKGy2saKCLpOHX5tFDJV g+Xs2h3GR5SFH7vBCHDOSba8JD4N9uMuLzCG/iB+o7Lcjys06b8uQM702fIkLquZNqfG wlzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a27-v6si4985425pfh.164.2018.09.06.04.11.54; Thu, 06 Sep 2018 04:12:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728324AbeIFPK7 (ORCPT + 99 others); Thu, 6 Sep 2018 11:10:59 -0400 Received: from mga09.intel.com ([134.134.136.24]:13978 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbeIFPK7 (ORCPT ); Thu, 6 Sep 2018 11:10:59 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Sep 2018 03:36:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,337,1531810800"; d="scan'208";a="260327585" Received: from lahna.fi.intel.com (HELO lahna) ([10.237.72.157]) by fmsmga005.fm.intel.com with SMTP; 06 Sep 2018 03:36:03 -0700 Received: by lahna (sSMTP sendmail emulation); Thu, 06 Sep 2018 13:36:02 +0300 Date: Thu, 6 Sep 2018 13:36:02 +0300 From: Mika Westerberg To: Lukas Wunner Cc: linux-kernel@vger.kernel.org, Andreas Noever , Michael Jamet , Yehezkel Bernat , Lu Baolu Subject: Re: [PATCH 2/2] thunderbolt: Initialize after IOMMUs Message-ID: <20180906103602.GV2283@lahna.fi.intel.com> References: <20180903132012.23531-1-mika.westerberg@linux.intel.com> <20180903132012.23531-2-mika.westerberg@linux.intel.com> <20180905084746.xmckzskxzsdliz3e@wunner.de> <20180905094602.GH2283@lahna.fi.intel.com> <20180906081337.3mosfpfggfmoj633@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180906081337.3mosfpfggfmoj633@wunner.de> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 06, 2018 at 10:13:37AM +0200, Lukas Wunner wrote: > On Wed, Sep 05, 2018 at 12:46:02PM +0300, Mika Westerberg wrote: > > On Wed, Sep 05, 2018 at 10:47:46AM +0200, Lukas Wunner wrote: > > > On Mon, Sep 03, 2018 at 04:20:12PM +0300, Mika Westerberg wrote: > > > > If IOMMU is enabled and Thunderbolt driver is built into the kernel > > > > image, it will be probed before IOMMUs are attached to the PCI bus. > > > > Because of this DMA mappings the driver does will not go through IOMMU > > > > and start failing right after IOMMUs are enabled. > > > > > > > > For this reason move the Thunderbolt driver initialization happen at > > > > rootfs level. > > > > > > > > Signed-off-by: Mika Westerberg > > > > --- > > > > drivers/thunderbolt/nhi.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c > > > > index 88cff05a1808..5cd6bdfa068f 100644 > > > > --- a/drivers/thunderbolt/nhi.c > > > > +++ b/drivers/thunderbolt/nhi.c > > > > @@ -1191,5 +1191,5 @@ static void __exit nhi_unload(void) > > > > tb_domain_exit(); > > > > } > > > > > > > > -fs_initcall(nhi_init); > > > > +rootfs_initcall(nhi_init); > > > > module_exit(nhi_unload); > > > > > > I think the dependency on the IOMMU should be open coded by returning > > > -EPROBE_DEFER from the ->probe hook if it's not yet attached. > > > Shuffling around initcall order is just applying duct tape. > > > > It is not a dependency. The same thing can happen with any other driver > > if they happen to initialize any DMA with the device before IOMMUs are > > initialized. > > > > > Commit acb40d841257 already changed module_init() to fs_initcall() > > > and now it has to be changed again. Shows how fragile this is. > > > > It is a bit fragile but I don't see any other way to handle this than > > trusting on the link ordering. Both -EPROBE_DEFER and device_links are > > out of the question AFAICT. > > So with this patch, you rely on the linker ordering nhi_init() after > ir_dev_scope_init(), however to the best of my knowledge the link > order is not guaranteed. What says that? As far as I can tell it has been used with initcalls forever to make sure certain block of code gets executed at certain time. > In that sense, commit acb40d841257 was already flawed because it > executed nhi_init() at "fs" initcall level, the *same* level used by > map_properties() in drivers/firmware/efi/apple-properties.c, which > retrieves the DROM device property needed by tb_drom_copy_efi(). > > That was arguably a regression which the above patch cures because > "rootfs" is guaranteed to run after "fs". Still, the fragility > remains that ir_dev_scope_init() isn't guaranteed to run before > nhi_init(). > > Looking at commit acb40d841257, which started this, I'm wondering > why you did not simply export tbnet_init() and call it from the > thunderbolt driver after the property stuff has been fully set up? > After all, thunderbolt-net is useless without thunderbolt or am I > missing something? Then you could revert back to module_init(). The same reason you don't call PCI driver functions from PCI core. It makes absolutely zero sense. Thunderbolt is bus and provides driver API to drivers. We hopefully are getting other service drivers (say SCSI over TBT) that are going to be use the same interfaces.