Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp569741pxv; Thu, 22 Jul 2021 07:12:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoVZffyeISPhrk68CFCUYe064+/KJoa/WHkL/28CAMmACudPfJnYzCcZ58GFLx6psyJRe9 X-Received: by 2002:a6b:794b:: with SMTP id j11mr30494246iop.129.1626963127146; Thu, 22 Jul 2021 07:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626963127; cv=none; d=google.com; s=arc-20160816; b=g4cLf5RfeYnZv/Yh5Q6PHqeIAIA4WgffffW/59qufE5sIts9g/LGW+CX84VJwYOeY3 xLSBU/PobSUGFjlbbp91/RjMj45g7+FwHunO1wmyLfsIC81KsrtU2F0eef3huHhXJiA9 XPur2qky9t+8xkiJTRr0aTla1PoDvAnVEYV+p3a5Ok/OaOSqj5241AzGkHnHCsnHHPfy paUplLzq3HEPlFlFSFpSrbDQtOxfwHFyU18WD0bbLONSpRxyJZMo5xf6DsfC6SK78Yl2 qO3/K4YsyGC94zXErSSQHnN1Z7WaLtpOhSCRJ/eWZYhQvgT7r/QTe73W+T9b+RhvnqTl I6aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=znqZXEBvAg7dEbM5a2gQPS3YjNE0Yq928OYkD/5qLAI=; b=Xbm4ojpLPTTnixKRcdT4vGgHH6eVKnvLNuzuDSywVjtIq6aH+4HxtPqPxpsIVd22uQ mEifbOHC7WNkeqaE7KqTObtohKEj3rUTsiW1nNbhf+Ovya2ZLwxb3CfxllKCZdsFa7Jx kO+WH32G9/mlWMiIuOT7D6GwHayEcprHcsehqvE2yHq3eHHByGpwF0WEwJrVSKWS5QOi E+DJLlxFrd1+fYnCv8grjdeAq30R/NXisvg6SbMDAjO46c9RuFXcMipEvouO4LhZO38N un8U252o5Z9NahTp9dqbamTnI4iIEZCL/Nvs4xOfC481fRiQ0Ug8okTh9LEZiS6Eh4aF JaYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=AZV3erzg; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n21si21679770jaj.97.2021.07.22.07.11.55; Thu, 22 Jul 2021 07:12:07 -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=@suse.com header.s=susede1 header.b=AZV3erzg; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232241AbhGVNaZ (ORCPT + 99 others); Thu, 22 Jul 2021 09:30:25 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:53066 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232105AbhGVNaY (ORCPT ); Thu, 22 Jul 2021 09:30:24 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id DE25922674; Thu, 22 Jul 2021 14:10:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1626963058; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=znqZXEBvAg7dEbM5a2gQPS3YjNE0Yq928OYkD/5qLAI=; b=AZV3erzgxGYb6H+cbwB2i3k4ARqpI4fnEI/VqXsoGEdXqlEn3d7a3CXeJ7rd9yjpMP4j8S cgatLfrtzOrSESMbl05PfuIciKEyDPg1Z7EIFjTnwCGdEcybeT3Ol/OBHce0iDUEnNymg2 bbuZ9x1ORBRKhWbdB2VxMcvuRNzWA+M= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A8FAF13DCE; Thu, 22 Jul 2021 14:10:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UawqJ3J8+WC9VAAAMHmgww (envelope-from ); Thu, 22 Jul 2021 14:10:58 +0000 Date: Thu, 22 Jul 2021 16:10:55 +0200 From: Anthony Iliopoulos To: Robin Murphy Cc: Christoph Hellwig , Marek Szyprowski , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] dma-debug: fix debugfs initialization order Message-ID: References: <20210722091818.13434-1-ailiop@suse.com> <1ea36b32-9bbc-a611-402d-9fa196eda166@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1ea36b32-9bbc-a611-402d-9fa196eda166@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 22, 2021 at 11:10:24AM +0100, Robin Murphy wrote: > On 2021-07-22 10:18, Anthony Iliopoulos wrote: > > Due to link order, dma_debug_init is called before debugfs has a chance > > to initialize (via debugfs_init which also happens in the core initcall > > stage), so the directories for dma-debug are never created. > > > > Move the dma_debug_init initcall from core to postcore stage so that > > debugfs will already be initialized by the time this is called, making > > it oblivious to link-ordering. > > Playing initcall chicken here doesn't work so well - the later you > initialise dma-debug itself, the more chance it has to miss early mappings > and raise false positives later. As discussed previously[1] the better > solution would be to decouple the debugfs setup so that just that part can > be deferred until core_initcall_sync or later. Thanks for pointing it out, makes sense. What about the following: From: Anthony Iliopoulos Due to link order, dma_debug_init is called before debugfs has a chance to initialize (via debugfs_init which also happens in the core initcall stage), so the directories for dma-debug are never created. Decouple dma_debug_fs_init from dma_debug_init and defer its init until core_initcall_sync (after debugfs has been initialized) while letting dma-debug initialization occur as soon as possible to catch any early mappings, as suggested in [1]. [1] https://lore.kernel.org/linux-iommu/YIgGa6yF%2Fadg8OSN@kroah.com/ Fixes: 15b28bbcd567 ("dma-debug: move initialization to common code") Signed-off-by: Anthony Iliopoulos --- kernel/dma/debug.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c index 14de1271463f..445754529917 100644 --- a/kernel/dma/debug.c +++ b/kernel/dma/debug.c @@ -794,7 +794,7 @@ static int dump_show(struct seq_file *seq, void *v) } DEFINE_SHOW_ATTRIBUTE(dump); -static void dma_debug_fs_init(void) +static int __init dma_debug_fs_init(void) { struct dentry *dentry = debugfs_create_dir("dma-api", NULL); @@ -807,7 +807,10 @@ static void dma_debug_fs_init(void) debugfs_create_u32("nr_total_entries", 0444, dentry, &nr_total_entries); debugfs_create_file("driver_filter", 0644, dentry, NULL, &filter_fops); debugfs_create_file("dump", 0444, dentry, NULL, &dump_fops); + + return 0; } +core_initcall_sync(dma_debug_fs_init); static int device_dma_allocations(struct device *dev, struct dma_debug_entry **out_entry) { @@ -892,8 +895,6 @@ static int dma_debug_init(void) spin_lock_init(&dma_entry_hash[i].lock); } - dma_debug_fs_init(); - nr_pages = DIV_ROUND_UP(nr_prealloc_entries, DMA_DEBUG_DYNAMIC_ENTRIES); for (i = 0; i < nr_pages; ++i) dma_debug_create_entries(GFP_KERNEL);