Skip to contentSkip to conversation

media: verisilicon: Fix kernel panic due to __initconst misuse

PATCH Superseded [email protected] 3 participants 5 messages Mar 5 – Mar 6

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

The imx8mq_vpu_shared_resources is referenced from non-init code, so keeping __initconst or __initconst_or_module here is wrong.

Drop the __initconst annotation and let it live in the normal .rodata section.

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

---
v2
- Remove __initconst
- Add missing Reported-by tag
- Add missing Suggested-by tag
- Remove comments of sentinel to pass checkpatch.pl

 drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +2 -2
index 6f8e43b7f157..6fbe3c581032 100644
@@ -343,10 +343,10 @@ 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[] = {
 	{ .compatible = "nxp,imx8mq-vpu-g1", },
 	{ .compatible = "nxp,imx8mq-vpu-g2", },
-	{ /* sentinel */ }
+	{}
 };
 
 const struct hantro_variant imx8mq_vpu_g1_variant = {
Signature · 1 line
2.52.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 17 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.

The imx8mq_vpu_shared_resources is referenced from non-init code, so keeping __initconst or __initconst_or_module here is wrong.

Quoted 7 lines

Drop the __initconst annotation and let it live in the normal .rodata section.

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

This fix was suggested by Krzysztof :)

Quoted 16 lines

---
v2
- Remove __initconst
- Add missing Reported-by tag
- Add missing Suggested-by tag
- Remove comments of sentinel to pass checkpatch.pl

 drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +0 -0
index 6f8e43b7f157..6fbe3c581032 100644

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

Quoted 9 lines
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +2 -2
@@ -343,10 +343,10 @@ 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[] = {
 	{ .compatible = "nxp,imx8mq-vpu-g1", },
 	{ .compatible = "nxp,imx8mq-vpu-g2", },
-	{ /* sentinel */ }
+	{}

Unnecessary change.

With both fixed:

Quoted 7 lines
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +0 -0
 };
 
 const struct hantro_variant imx8mq_vpu_g1_variant = {
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
Quoted 21 lines · Marco Felsch
Quoted 20 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.

The imx8mq_vpu_shared_resources is referenced from non-init code, so keeping __initconst or __initconst_or_module here is wrong.

Drop the __initconst annotation and let it live in the normal .rodata section.

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

This fix was suggested by Krzysztof :)

Or at least a bug of __initconst called from regular non-init probe code leading to bugs during probe deferrals or during unbind-bind cycles...

Closes:
https://lore.kernel.org/all/[email protected]/

?

Best regards,
Krzysztof

#4 lore raw
In reply to Marco Felsch

Hi Marco,

Quoted 21 lines · Marco Felsch
Quoted 20 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.

The imx8mq_vpu_shared_resources is referenced from non-init code, so keeping __initconst or __initconst_or_module here is wrong.

Drop the __initconst annotation and let it live in the normal .rodata section.

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

This fix was suggested by Krzysztof :)

I will add it in next version.

Quoted 19 lines
Quoted 19 lines

---
v2
- Remove __initconst
- Add missing Reported-by tag
- Add missing Suggested-by tag
- Remove comments of sentinel to pass checkpatch.pl

  drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +0 -0
index 6f8e43b7f157..6fbe3c581032 100644
@@ -343,10 +343,10 @@ const struct hantro_variant imx8mq_vpu_variant = {
  	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
  };
 
Quoted 9 lines

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

Quoted 6 lines
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +2 -2
-static const struct of_device_id imx8mq_vpu_shared_resources[] __initconst = {
+static const struct of_device_id imx8mq_vpu_shared_resources[] = {
  	{ .compatible = "nxp,imx8mq-vpu-g1", },
  	{ .compatible = "nxp,imx8mq-vpu-g2", },
-	{ /* sentinel */ }
+	{}

Unnecessary change.

Yes, I know, but I get the following error reported by checkpatch.pl

ERROR: missing sentinel in ID array
#50: FILE: drivers/media/platform/verisilicon/imx8m_vpu_hw.c:346:
+static const struct of_device_id imx8mq_vpu_shared_resources[] = {
{ .compatible = "XXXXXXXXXXXXXXXXX", },
{ .compatible = "XXXXXXXXXXXXXXXXX", },
{ }

total: 1 errors, 0 warnings, 0 checks, 8 lines checked

so I made this change to pass checkpatch.pl

Regards,
Ming

Quoted 13 lines

With both fixed:

Quoted 7 lines
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +0 -0
  };
 
  const struct hantro_variant imx8mq_vpu_g1_variant = {
Signature · 1 line
2.52.0
#3 lore raw
In reply to Krzysztof Kozlowski

Hi

Quoted 29 lines · Krzysztof Kozlowski
Quoted 21 lines · Marco Felsch
Quoted 20 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.

The imx8mq_vpu_shared_resources is referenced from non-init code, so keeping __initconst or __initconst_or_module here is wrong.

Drop the __initconst annotation and let it live in the normal .rodata section.

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

This fix was suggested by Krzysztof :)

Quoted 9 lines

Or at least a bug of __initconst called from regular non-init probe code leading to bugs during probe deferrals or during unbind-bind cycles...

Closes:
https://lore.kernel.org/all/[email protected]/

?

Thanks for your help, I will add this in next version.

Quoted 2 lines

Best regards,
Krzysztof