All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dma-debug: fix debugfs initialization order
@ 2021-07-22  9:18 ` Anthony Iliopoulos via iommu
  0 siblings, 0 replies; 8+ messages in thread
From: Anthony Iliopoulos @ 2021-07-22  9:18 UTC (permalink / raw)
  To: Christoph Hellwig, Marek Szyprowski, Robin Murphy; +Cc: iommu, linux-kernel

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.

Fixes: 15b28bbcd567 ("dma-debug: move initialization to common code")
Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
---
 kernel/dma/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 14de1271463f..49d80ef7f995 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -915,7 +915,7 @@ static int dma_debug_init(void)
 	pr_info("debugging enabled by kernel config\n");
 	return 0;
 }
-core_initcall(dma_debug_init);
+postcore_initcall(dma_debug_init);
 
 static __init int dma_debug_cmdline(char *str)
 {
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] dma-debug: fix debugfs initialization order
@ 2021-07-22  9:18 ` Anthony Iliopoulos via iommu
  0 siblings, 0 replies; 8+ messages in thread
From: Anthony Iliopoulos via iommu @ 2021-07-22  9:18 UTC (permalink / raw)
  To: Christoph Hellwig, Marek Szyprowski, Robin Murphy; +Cc: iommu, linux-kernel

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.

Fixes: 15b28bbcd567 ("dma-debug: move initialization to common code")
Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
---
 kernel/dma/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 14de1271463f..49d80ef7f995 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -915,7 +915,7 @@ static int dma_debug_init(void)
 	pr_info("debugging enabled by kernel config\n");
 	return 0;
 }
-core_initcall(dma_debug_init);
+postcore_initcall(dma_debug_init);
 
 static __init int dma_debug_cmdline(char *str)
 {
-- 
2.32.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-debug: fix debugfs initialization order
  2021-07-22  9:18 ` Anthony Iliopoulos via iommu
@ 2021-07-22 10:10   ` Robin Murphy
  -1 siblings, 0 replies; 8+ messages in thread
From: Robin Murphy @ 2021-07-22 10:10 UTC (permalink / raw)
  To: Anthony Iliopoulos, Christoph Hellwig, Marek Szyprowski
  Cc: iommu, linux-kernel

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.

Robin.

[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 <ailiop@suse.com>
> ---
>   kernel/dma/debug.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
> index 14de1271463f..49d80ef7f995 100644
> --- a/kernel/dma/debug.c
> +++ b/kernel/dma/debug.c
> @@ -915,7 +915,7 @@ static int dma_debug_init(void)
>   	pr_info("debugging enabled by kernel config\n");
>   	return 0;
>   }
> -core_initcall(dma_debug_init);
> +postcore_initcall(dma_debug_init);
>   
>   static __init int dma_debug_cmdline(char *str)
>   {
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-debug: fix debugfs initialization order
@ 2021-07-22 10:10   ` Robin Murphy
  0 siblings, 0 replies; 8+ messages in thread
From: Robin Murphy @ 2021-07-22 10:10 UTC (permalink / raw)
  To: Anthony Iliopoulos, Christoph Hellwig, Marek Szyprowski
  Cc: iommu, linux-kernel

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.

Robin.

[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 <ailiop@suse.com>
> ---
>   kernel/dma/debug.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
> index 14de1271463f..49d80ef7f995 100644
> --- a/kernel/dma/debug.c
> +++ b/kernel/dma/debug.c
> @@ -915,7 +915,7 @@ static int dma_debug_init(void)
>   	pr_info("debugging enabled by kernel config\n");
>   	return 0;
>   }
> -core_initcall(dma_debug_init);
> +postcore_initcall(dma_debug_init);
>   
>   static __init int dma_debug_cmdline(char *str)
>   {
> 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-debug: fix debugfs initialization order
  2021-07-22 10:10   ` Robin Murphy
@ 2021-07-22 14:10     ` Anthony Iliopoulos via iommu
  -1 siblings, 0 replies; 8+ messages in thread
From: Anthony Iliopoulos @ 2021-07-22 14:10 UTC (permalink / raw)
  To: Robin Murphy; +Cc: Christoph Hellwig, Marek Szyprowski, iommu, linux-kernel

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 <ailiop@suse.com>

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 <ailiop@suse.com>
---
 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);

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-debug: fix debugfs initialization order
@ 2021-07-22 14:10     ` Anthony Iliopoulos via iommu
  0 siblings, 0 replies; 8+ messages in thread
From: Anthony Iliopoulos via iommu @ 2021-07-22 14:10 UTC (permalink / raw)
  To: Robin Murphy; +Cc: linux-kernel, iommu, Christoph Hellwig

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 <ailiop@suse.com>

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 <ailiop@suse.com>
---
 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);
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-debug: fix debugfs initialization order
  2021-07-22 14:10     ` Anthony Iliopoulos via iommu
@ 2021-08-09 15:15       ` Christoph Hellwig
  -1 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-08-09 15:15 UTC (permalink / raw)
  To: Anthony Iliopoulos
  Cc: Robin Murphy, Christoph Hellwig, Marek Szyprowski, iommu, linux-kernel

Thanks, applied.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-debug: fix debugfs initialization order
@ 2021-08-09 15:15       ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-08-09 15:15 UTC (permalink / raw)
  To: Anthony Iliopoulos; +Cc: linux-kernel, iommu, Robin Murphy, Christoph Hellwig

Thanks, applied.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-08-09 15:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22  9:18 [PATCH] dma-debug: fix debugfs initialization order Anthony Iliopoulos
2021-07-22  9:18 ` Anthony Iliopoulos via iommu
2021-07-22 10:10 ` Robin Murphy
2021-07-22 10:10   ` Robin Murphy
2021-07-22 14:10   ` Anthony Iliopoulos
2021-07-22 14:10     ` Anthony Iliopoulos via iommu
2021-08-09 15:15     ` Christoph Hellwig
2021-08-09 15:15       ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.