media: verisilicon: Fix kernel panic due to __initconst misuse
Subsystems (3)
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.
---
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
@@ -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
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_resourcesarray is referenced by variant structures through theirshared_devicesfield. When built as a module,__initconstcauses this data to be freed after module init, but it's later accessed during probe, causing a page fault.The
imx8mq_vpu_shared_resourcesis referenced from non-init code, so keeping__initconstor__initconst_or_modulehere is wrong.
Quoted 7 lines
Drop the
__initconstannotation and let it live in the normal .rodata section.Fixes e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")Reported-by Franz Schnyder <[email protected]>Closes https://lore.kernel.org/all/n3qmcb62tepxltoskpf7ws6yiirc2so62ia23b42rj3wlmpl67@rvkbuirx7kkp/ open hereSuggested-by Marco Felsch <[email protected]>
This fix was suggested by Krzysztof :)
Quoted 16 lines
Signed-off-by Ming Qian <[email protected]>---
v2
- Remove__initconst
- Add missing Reported-by tag
- Add missing Suggested-by tag
- Remove comments of sentinel to pass checkpatch.pldrivers/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
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 |
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_resourcesarray is referenced by variant structures through theirshared_devicesfield. When built as a module,__initconstcauses this data to be freed after module init, but it's later accessed during probe, causing a page fault.The
imx8mq_vpu_shared_resourcesis referenced from non-init code, so keeping__initconstor__initconst_or_modulehere is wrong.Drop the
__initconstannotation 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")Reported-by Franz Schnyder <[email protected]>Closes https://lore.kernel.org/all/n3qmcb62tepxltoskpf7ws6yiirc2so62ia23b42rj3wlmpl67@rvkbuirx7kkp/ open hereSuggested-by Marco Felsch <[email protected]>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
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_resourcesarray is referenced by variant structures through theirshared_devicesfield. When built as a module,__initconstcauses this data to be freed after module init, but it's later accessed during probe, causing a page fault.The
imx8mq_vpu_shared_resourcesis referenced from non-init code, so keeping__initconstor__initconst_or_modulehere is wrong.Drop the
__initconstannotation 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")Reported-by Franz Schnyder <[email protected]>Closes https://lore.kernel.org/all/n3qmcb62tepxltoskpf7ws6yiirc2so62ia23b42rj3wlmpl67@rvkbuirx7kkp/ open hereSuggested-by Marco Felsch <[email protected]>This fix was suggested by Krzysztof :)
I will add it in next version.
Quoted 19 lines
Quoted 19 lines
Signed-off-by Ming Qian <[email protected]>---
v2
- Remove__initconst
- Add missing Reported-by tag
- Add missing Suggested-by tag
- Remove comments of sentinel to pass checkpatch.pldrivers/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@@ -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:
Reviewed-by Marco Felsch <[email protected]>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
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_resourcesarray is referenced by variant structures through theirshared_devicesfield. When built as a module,__initconstcauses this data to be freed after module init, but it's later accessed during probe, causing a page fault.The
imx8mq_vpu_shared_resourcesis referenced from non-init code, so keeping__initconstor__initconst_or_modulehere is wrong.Drop the
__initconstannotation 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")Reported-by Franz Schnyder <[email protected]>Closes https://lore.kernel.org/all/n3qmcb62tepxltoskpf7ws6yiirc2so62ia23b42rj3wlmpl67@rvkbuirx7kkp/ open hereSuggested-by Marco Felsch <[email protected]>This fix was suggested by Krzysztof :)
Quoted 9 lines
Or at least a bug of
__initconstcalled 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]/Reported-by Krzysztof Kozlowski <[email protected]>?
Thanks for your help, I will add this in next version.
Quoted 2 lines
Best regards,
Krzysztof