Skip to contentSkip to conversation

media: verisilicon: Fix kernel panic due to __initconst misuse

PATCH Superseded [email protected] 5 participants 9 messages Mar 5

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: verisilicon: Fix kernel panic due to __initconst misuse

From: Ming Qian <[email protected]>

Fix a kernel panic when probing the driver as a module:

  Unable to handle kernel paging request at virtual address
  ffffd9c18eb05000
  of_find_matching_node_and_match+0x5c/0x1a0
  hantro_probe+0x2f4/0x7d0 [hantro_vpu]

The imx8mq_vpu_shared_resources array is referenced by variant structures through their shared_devices field. When built as a module, __initconst causes this data to be freed after module init, but it's later accessed during probe, causing a page fault.

Use __initconst_or_module to keep the data available when built as a module while still allowing it to be freed when built-in.

Fixes e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")
---
 drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +1 -1
index 6f8e43b7f157..fa429e6e8281 100644
@@ -343,7 +343,7 @@ const struct hantro_variant imx8mq_vpu_variant = {
 	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
 };
 
-static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst = {
+static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst_or_module = {
 	{ .compatible = "nxp,imx8mq-vpu-g1", },
 	{ .compatible = "nxp,imx8mq-vpu-g2", },
 	{ /* sentinel */ }
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Ming,

Quoted 9 lines · On 26-03-05, [email protected] wrote:

From: Ming Qian <[email protected]>

Fix a kernel panic when probing the driver as a module:

  Unable to handle kernel paging request at virtual address
  ffffd9c18eb05000
  of_find_matching_node_and_match+0x5c/0x1a0
  hantro_probe+0x2f4/0x7d0 [hantro_vpu]
Quoted 7 lines

The imx8mq_vpu_shared_resources array is referenced by variant structures through their shared_devices field. When built as a module, __initconst causes this data to be freed after module init, but it's later accessed during probe, causing a page fault.

Use __initconst_or_module to keep the data available when built as a module while still allowing it to be freed when built-in.

would be nice if I get at least some credit for pointing to the correct fix ;)

Quoted 2 lines
Fixes e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")

However, patch looks fine:

Quoted 21 lines
---
 drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +1 -1
index 6f8e43b7f157..fa429e6e8281 100644
@@ -343,7 +343,7 @@ const struct hantro_variant imx8mq_vpu_variant = {
 	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
 };
 
-static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst = {
+static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst_or_module = {
 	{ .compatible = "nxp,imx8mq-vpu-g1", },
 	{ .compatible = "nxp,imx8mq-vpu-g2", },
 	{ /* sentinel */ }
Signature · 1 line
2.52.0
Signature · 7 lines
#gernperDu 
#CallMeByMyFirstName

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | https://www.pengutronix.de/ |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-9    |
#2 lore raw

Hi Marco,

Quoted 17 lines · Marco Felsch

Hi Ming,

Quoted 14 lines · On 26-03-05, [email protected] wrote:

From: Ming Qian <[email protected]>

Fix a kernel panic when probing the driver as a module:

   Unable to handle kernel paging request at virtual address
   ffffd9c18eb05000
   of_find_matching_node_and_match+0x5c/0x1a0
   hantro_probe+0x2f4/0x7d0 [hantro_vpu]

The imx8mq_vpu_shared_resources array is referenced by variant structures through their shared_devices field. When built as a module, __initconst causes this data to be freed after module init, but it's later accessed during probe, causing a page fault.

Quoted 5 lines
Quoted 2 lines

Use __initconst_or_module to keep the data available when built as a module while still allowing it to be freed when built-in.

would be nice if I get at least some credit for pointing to the correct fix ;)

I'm sorry that I forget to add your Suggested-by tag. I will include a Suggested-by tag in the next revision. Appreciate your help.

Regards,
Ming

Quoted 30 lines
Quoted 3 lines
Fixes e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")

However, patch looks fine:

Quoted 21 lines
---
  drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +1 -1
index 6f8e43b7f157..fa429e6e8281 100644
@@ -343,7 +343,7 @@ const struct hantro_variant imx8mq_vpu_variant = {
  	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
  };
 
-static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst = {
+static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst_or_module = {
  	{ .compatible = "nxp,imx8mq-vpu-g1", },
  	{ .compatible = "nxp,imx8mq-vpu-g2", },
  	{ /* sentinel */ }
Signature · 1 line
2.52.0
#3 lore raw
In reply to Marco Felsch
Quoted 23 lines · Marco Felsch

Hi Ming,

Quoted 9 lines · On 26-03-05, [email protected] wrote:

From: Ming Qian <[email protected]>

Fix a kernel panic when probing the driver as a module:

  Unable to handle kernel paging request at virtual address
  ffffd9c18eb05000
  of_find_matching_node_and_match+0x5c/0x1a0
  hantro_probe+0x2f4/0x7d0 [hantro_vpu]
Quoted 7 lines

The imx8mq_vpu_shared_resources array is referenced by variant structures through their shared_devices field. When built as a module, __initconst causes this data to be freed after module init, but it's later accessed during probe, causing a page fault.

Use __initconst_or_module to keep the data available when built as a module while still allowing it to be freed when built-in.

would be nice if I get at least some credit for pointing to the correct fix ;)

Quoted 6 lines
Quoted 2 lines
Fixes e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")

However, patch looks fine:

Patch is not correct. This is being referenced from other data where nothing is __init. Section mismatch might not point it, but I don't think the code is readable and actually correct.

You can exercise it by rebinding device when built-in.

Best regards,
Krzysztof

#4 lore raw
Quoted 29 lines · Krzysztof Kozlowski
Quoted 28 lines · Marco Felsch

Hi Ming,

Quoted 9 lines · On 26-03-05, [email protected] wrote:

From: Ming Qian <[email protected]>

Fix a kernel panic when probing the driver as a module:

  Unable to handle kernel paging request at virtual address
  ffffd9c18eb05000
  of_find_matching_node_and_match+0x5c/0x1a0
  hantro_probe+0x2f4/0x7d0 [hantro_vpu]
Quoted 7 lines

The imx8mq_vpu_shared_resources array is referenced by variant structures through their shared_devices field. When built as a module, __initconst causes this data to be freed after module init, but it's later accessed during probe, causing a page fault.

Use __initconst_or_module to keep the data available when built as a module while still allowing it to be freed when built-in.

would be nice if I get at least some credit for pointing to the correct fix ;)

Quoted 2 lines
Fixes e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")

However, patch looks fine:

Quoted 7 lines
Quoted 1 line

Patch is not correct. This is being referenced from other data where nothing is __init. Section mismatch might not point it, but I don't think the code is readable and actually correct.

You can exercise it by rebinding device when built-in.

That's correct, I didn't consider the manual unbind for the built-in case in which you will trigger the issue again! Dropping the annotation is the correct fix, thanks!

Regards,
Marco

Quoted 4 lines

Best regards,
Krzysztof

Signature · 7 lines
#gernperDu 
#CallMeByMyFirstName

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | https://www.pengutronix.de/ |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-9    |
Tested-by on v1 1/1
#5 lore raw
In reply to [email protected]

Hi,

Quoted 9 lines · On Thu, Mar 05, 2026 at 04:03:52PM +0800, [email protected] wrote:

From: Ming Qian <[email protected]>

Fix a kernel panic when probing the driver as a module:

  Unable to handle kernel paging request at virtual address
  ffffd9c18eb05000
  of_find_matching_node_and_match+0x5c/0x1a0
  hantro_probe+0x2f4/0x7d0 [hantro_vpu]
Quoted 7 lines

The imx8mq_vpu_shared_resources array is referenced by variant structures through their shared_devices field. When built as a module, __initconst causes this data to be freed after module init, but it's later accessed during probe, causing a page fault.

Use __initconst_or_module to keep the data available when built as a module while still allowing it to be freed when built-in.

Thanks for the fix. I tested it on our Verdin iMX8MP hardware.

Kind regards,
Franz

#6 lore raw
In reply to [email protected]
Quoted 28 lines · On 05/03/2026 09:03, [email protected] wrote:

From: Ming Qian <[email protected]>

Fix a kernel panic when probing the driver as a module:

  Unable to handle kernel paging request at virtual address
  ffffd9c18eb05000
  of_find_matching_node_and_match+0x5c/0x1a0
  hantro_probe+0x2f4/0x7d0 [hantro_vpu]

The imx8mq_vpu_shared_resources array is referenced by variant structures through their shared_devices field. When built as a module, __initconst causes this data to be freed after module init, but it's later accessed during probe, causing a page fault.

Use __initconst_or_module to keep the data available when built as a module while still allowing it to be freed when built-in.

Fixes e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")
---
 drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +0 -0
index 6f8e43b7f157..fa429e6e8281 100644

drivers/media/platform/verisilicon/imx8m_vpu_hw.c const struct hantro_variant imx8mq_vpu_variant = { · line 347

Quoted 6 lines
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +1 -1
@@ -343,7 +343,7 @@ const struct hantro_variant imx8mq_vpu_variant = {
 	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
 };
 
-static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst = {
+static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst_or_module = {
 	{ .compatible = "nxp,imx8mq-vpu-g1", },

I have some doubts this was tested with section mismatch analysis. It is still referenced by non initconst data, but it should not. You have a dangling pointer.

And build test would probably point it out.

Best regards,
Krzysztof

#7 lore raw

Hi,

Quoted 41 lines · Krzysztof Kozlowski
Quoted 28 lines · On 05/03/2026 09:03, [email protected] wrote:

From: Ming Qian <[email protected]>

Fix a kernel panic when probing the driver as a module:

   Unable to handle kernel paging request at virtual address
   ffffd9c18eb05000
   of_find_matching_node_and_match+0x5c/0x1a0
   hantro_probe+0x2f4/0x7d0 [hantro_vpu]

The imx8mq_vpu_shared_resources array is referenced by variant structures through their shared_devices field. When built as a module, __initconst causes this data to be freed after module init, but it's later accessed during probe, causing a page fault.

Use __initconst_or_module to keep the data available when built as a module while still allowing it to be freed when built-in.

Fixes e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")
---
  drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +0 -0
index 6f8e43b7f157..fa429e6e8281 100644

drivers/media/platform/verisilicon/imx8m_vpu_hw.c const struct hantro_variant imx8mq_vpu_variant = { · line 347

Quoted 6 lines
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +1 -1
@@ -343,7 +343,7 @@ const struct hantro_variant imx8mq_vpu_variant = {
  	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
  };
 
-static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst = {
+static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst_or_module = {
  	{ .compatible = "nxp,imx8mq-vpu-g1", },

I have some doubts this was tested with section mismatch analysis. It is still referenced by non initconst data, but it should not. You have a dangling pointer.

Quoted 1 line

And build test would probably point it out.

Thanks, that makes sense.

I'll remove the annotation and let it live in the normal .rodata section.

An updated patch will follow.

Regards,
Ming

Quoted 4 lines

Best regards,
Krzysztof

#8 lore raw
In reply to [email protected]
Quoted 14 lines · On Thu, Mar 05, 2026 at 04:03:52PM +0800, [email protected] wrote:

From: Ming Qian <[email protected]>

Fix a kernel panic when probing the driver as a module:

  Unable to handle kernel paging request at virtual address
  ffffd9c18eb05000
  of_find_matching_node_and_match+0x5c/0x1a0
  hantro_probe+0x2f4/0x7d0 [hantro_vpu]

The imx8mq_vpu_shared_resources array is referenced by variant structures through their shared_devices field. When built as a module, __initconst causes this data to be freed after module init, but it's later accessed during probe, causing a page fault.

Quoted 5 lines

Use __initconst_or_module to keep the data available when built as a module while still allowing it to be freed when built-in.

Fixes e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")

In addition to what Marco asked ...

Francesco