Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp229551imm; Thu, 6 Sep 2018 01:15:47 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda/pG413loGh1NWTQ3G1bbVww7p9Upzxq4ypxG/dF8dch0BSBJvd0KCENJooL4KzQRObSuI X-Received: by 2002:a63:cc04:: with SMTP id x4-v6mr1550546pgf.33.1536221747777; Thu, 06 Sep 2018 01:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536221747; cv=none; d=google.com; s=arc-20160816; b=oRNONvTZupCGTDQWD8J99TewVzPFqr211PvYpptlGFOjGTgZTZhG7i4l8b2TJaz9rg 7rVwUpcP7pyR1JOO2+Zke3ZYAMC1oL0B3ozPKjGzuBB4vTNyBe6v2ea+Y3kMBGOvBFA/ 1JyHfnoMnUGdTVWJsMcsE8zo0kuAMg3onfp2Ivyn5CX/K9klBKXCG/qaBfYlLgOyd/it k0AW4Opu5YGoGNJGNTxWgrjGgsqYWqMeUjbacEzWw+7lkqT3ieITBycjaGUDgq3sLZSL szv3yysxcTfpgDjOUo2DYIPrX9wXsIeIqtJ9Uuc6LXkLQpp24gEvur0iNWU11O2w/Xmf ObyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=oGWVWw+8PmXiBvjvoGobufnudHm6hcB3X52S464j7Wk=; b=LKYwKLf65edMX2QuSpaX26JQVwGMch/dMsM0R6EH/h9KeM0FK3eJbCqHreP2hpYAVF LjG21Nyn92TK0jgu4848LgjNzMY/W8ZgzqxS0/i7g5ZThTSXL8CAzv5v26fhyRQOmldn PeCCvbwoNjRKY1Y78cw6akZ9IL2noBsv1lqTZRjhwnALpQ8gV/l6pmQ6Af6wcejxkHLy +T1thE2SOqMv25ETTMrPI8KaQUlBPyA9gGu4bx7nvz0a7/2yXf+WPHX2qUG4jIcDg2IC v9IETgbgKuzJvLfsxi3P7qgdMaka57oF9AnU9A3mgSN519xgSuD14jwFQUsKByQz9FKN xSEg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3-v6si4179038plb.249.2018.09.06.01.15.32; Thu, 06 Sep 2018 01:15:47 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727993AbeIFMry (ORCPT + 99 others); Thu, 6 Sep 2018 08:47:54 -0400 Received: from bmailout1.hostsharing.net ([83.223.95.100]:48371 "EHLO bmailout1.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725913AbeIFMrx (ORCPT ); Thu, 6 Sep 2018 08:47:53 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id 49FE430002258; Thu, 6 Sep 2018 10:13:37 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 214F854F8A9; Thu, 6 Sep 2018 10:13:37 +0200 (CEST) Date: Thu, 6 Sep 2018 10:13:37 +0200 From: Lukas Wunner To: Mika Westerberg 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: <20180906081337.3mosfpfggfmoj633@wunner.de> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180905094602.GH2283@lahna.fi.intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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(). Thanks, Lukas