soc: fsl: qbman: qman_portal: defer probing when qman is not available
PATCH 1/2 soc: fsl: qbman: qman_portal: defer probing when qman is not available
If the qman driver (qman_ccsr) doesn't probe or fail to probe before qman_portal, qm_ccsr_start will be either NULL or a stale pointer to an unmapped page.
This leads to a crash when probing qman_portal as the init_pcfg function calls qman_liodn_fixup that tries to read qman registers.
Assume that qman didn't probe when the pool mask is 0.
--- drivers/soc/fsl/qbman/qman_portal.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/soc/fsl/qbman/qman_portal.c +2 -0
@@ -277,6 +277,8 @@ static int qman_portal_probe(struct platform_device *pdev) } pcfg->pools =qm_get_pools_sdqcr (); +if (pcfg->pools ==0 ) +return -EPROBE_DEFER ;spin_lock (&qman_lock); cpu =cpumask_next_zero (-1 , &portal_cpus);
Signature · 1 line
2.18.0
PATCH 2/2 soc: fsl: qbman: qman: avoid allocating from non existing gen_pool
If the qman driver didn't probe, calling qman_alloc_fqid_range, qman_alloc_pool_range or qman_alloc_cgrid_range (as done in dpaa_eth) will pass a NULL pointer to gen_pool_alloc, leading to a NULL pointer dereference.
--- drivers/soc/fsl/qbman/qman.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/soc/fsl/qbman/qman.c +3 -0
@@ -2729,6 +2729,9 @@ static int qman_alloc_range(struct gen_pool *p, u32 *result, u32 cnt) {unsigned long addr; +if (!p) +return -ENODEV ; + addr =gen_pool_alloc (p, cnt);if (!addr)return -ENOMEM ;
Signature · 1 line
2.18.0
Quoted 19 lines · Alexandre Belloni
If the qman driver (
qman_ccsr) doesn't probe or fail to probe beforeqman_portal,qm_ccsr_startwill be either NULL or a stale pointer to an unmapped page.This leads to a crash when probing
qman_portalas theinit_pcfgfunction callsqman_liodn_fixupthat tries to read qman registers.Assume that qman didn't probe when the pool mask is 0.
Signed-off-by Alexandre Belloni <[email protected]>--- drivers/soc/fsl/qbman/qman_portal.c | 2 ++ 1 file changed, 2 insertions(+)drivers/soc/fsl/qbman/qman_portal.c +0
-0
drivers/soc/fsl/qbman/qman_portal.c static int qman_portal_probe(struct platform_device *pdev) · line 284
Quoted 8 lines
drivers/soc/fsl/qbman/qman_portal.c +2
-0@@ -277,6 +277,8 @@ static int qman_portal_probe(struct platform_device *pdev) } pcfg->pools =qm_get_pools_sdqcr (); +if (pcfg->pools ==0 ) +return -EPROBE_DEFER ;spin_lock (&qman_lock); cpu =cpumask_next_zero (-1 , &portal_cpus);
Re: [PATCH 2/2] soc: fsl: qbman: qman: avoid allocating from non existing gen_pool
In reply to Alexandre BelloniQuoted 15 lines · Alexandre Belloni
If the qman driver didn't probe, calling
qman_alloc_fqid_range,qman_alloc_pool_rangeorqman_alloc_cgrid_range(as done indpaa_eth) will pass a NULL pointer togen_pool_alloc, leading to a NULL pointer dereference.Signed-off-by Alexandre Belloni <[email protected]>--- drivers/soc/fsl/qbman/qman.c | 3 +++ 1 file changed, 3 insertions(+)drivers/soc/fsl/qbman/qman.c +0
-0
drivers/soc/fsl/qbman/qman.c static int qman_alloc_range(struct gen_pool *p, u32 *result, u32 cnt) · line 2737
Quoted 9 lines
drivers/soc/fsl/qbman/qman.c +3
-0@@ -2729,6 +2729,9 @@ static int qman_alloc_range(struct gen_pool *p, u32 *result, u32 cnt) {unsigned long addr; +if (!p) +return -ENODEV ; + addr =gen_pool_alloc (p, cnt);if (!addr)return -ENOMEM ;
Quoted 6 lines · Roy Pledge
Quoted 4 lines · Alexandre Belloni
If the qman driver (
qman_ccsr) doesn't probe or fail to probe beforeqman_portal,qm_ccsr_startwill be either NULL or a stale pointer to an unmapped page.
Quoted 6 lines
Quoted 6 lines
This leads to a crash when probing
qman_portalas theinit_pcfgfunction callsqman_liodn_fixupthat tries to read qman registers.Assume that qman didn't probe when the pool mask is 0.
Signed-off-by Alexandre Belloni <[email protected]>
Series applied to the fix branch of soc/fsl.
Quoted 21 lines
Quoted 9 lines
--- drivers/soc/fsl/qbman/qman_portal.c | 2 ++ 1 file changed, 2 insertions(+)drivers/soc/fsl/qbman/qman_portal.c +0
-0drivers/soc/fsl/qbman/qman_portal.c static int qman_portal_probe(struct platform_device *pdev) · line 284
Quoted 8 lines
drivers/soc/fsl/qbman/qman_portal.c +2
-0@@ -277,6 +277,8 @@ static int qman_portal_probe(struct platform_device *pdev) } pcfg->pools =qm_get_pools_sdqcr (); +if (pcfg->pools ==0 ) +return -EPROBE_DEFER ;spin_lock (&qman_lock); cpu =cpumask_next_zero (-1 , &portal_cpus);Reviewed-by Roy Pledge <[email protected]>
Hi,
Quoted 20 lines · Alexandre Belloni
If the qman driver (
qman_ccsr) doesn't probe or fail to probe beforeqman_portal,qm_ccsr_startwill be either NULL or a stale pointer to an unmapped page.This leads to a crash when probing
qman_portalas theinit_pcfgfunction callsqman_liodn_fixupthat tries to read qman registers.Assume that qman didn't probe when the pool mask is 0.
Signed-off-by Alexandre Belloni <[email protected]>--- drivers/soc/fsl/qbman/qman_portal.c | 2 ++ 1 file changed, 2 insertions(+)drivers/soc/fsl/qbman/qman_portal.c +0
-0
drivers/soc/fsl/qbman/qman_portal.c static int qman_portal_probe(struct platform_device *pdev) · line 281
Quoted 5 lines
drivers/soc/fsl/qbman/qman_portal.c +2
-0@@ -277,6 +277,8 @@ static int qman_portal_probe(struct platform_device *pdev) } pcfg->pools =qm_get_pools_sdqcr (); +if (pcfg->pools ==0 ) +return -EPROBE_DEFER ;
This is quite late in the probe, after a bunch of resources have been claimed.
Note that the ioremaps above this are doing unwinds, and you'll end up doing duplicate ioremaps if you come in and probe again.
You should probably unwind those allocations, or move them to devm_* or do this check earlier in the function.
-Olof
Quoted 34 lines · Olof Johansson
Hi,
Quoted 20 lines · Alexandre Belloni
If the qman driver (
qman_ccsr) doesn't probe or fail to probe beforeqman_portal,qm_ccsr_startwill be either NULL or a stale pointer to an unmapped page.This leads to a crash when probing
qman_portalas theinit_pcfgfunction callsqman_liodn_fixupthat tries to read qman registers.Assume that qman didn't probe when the pool mask is 0.
Signed-off-by Alexandre Belloni <[email protected]>--- drivers/soc/fsl/qbman/qman_portal.c | 2 ++ 1 file changed, 2 insertions(+)drivers/soc/fsl/qbman/qman_portal.c +0
-0drivers/soc/fsl/qbman/qman_portal.c static int qman_portal_probe(struct platform_device *pdev) · line 281
Quoted 5 lines
drivers/soc/fsl/qbman/qman_portal.c +2
-0@@ -277,6 +277,8 @@ static int qman_portal_probe(struct platform_device *pdev) } pcfg->pools =qm_get_pools_sdqcr (); +if (pcfg->pools ==0 ) +return -EPROBE_DEFER ;This is quite late in the probe, after a bunch of resources have been claimed.
Quoted 5 lines
Note that the ioremaps above this are doing unwinds, and you'll end up doing duplicate ioremaps if you come in and probe again.
You should probably unwind those allocations, or move them to devm_* or do this check earlier in the function.
Hi Roy,
Is there any more straightforward indicator on if qman has been probed? So that we can check it at the begining of the probe?
Regards,
Leo
Quoted 33 lines · Olof Johansson
Hi,
Quoted 20 lines · Alexandre Belloni
If the qman driver (
qman_ccsr) doesn't probe or fail to probe beforeqman_portal,qm_ccsr_startwill be either NULL or a stale pointer to an unmapped page.This leads to a crash when probing
qman_portalas theinit_pcfgfunction callsqman_liodn_fixupthat tries to read qman registers.Assume that qman didn't probe when the pool mask is 0.
Signed-off-by Alexandre Belloni <[email protected]>--- drivers/soc/fsl/qbman/qman_portal.c | 2 ++ 1 file changed, 2 insertions(+)drivers/soc/fsl/qbman/qman_portal.c +0
-0drivers/soc/fsl/qbman/qman_portal.c static int qman_portal_probe(struct platform_device *pdev) · line 281
Quoted 5 lines
drivers/soc/fsl/qbman/qman_portal.c +2
-0@@ -277,6 +277,8 @@ static int qman_portal_probe(struct platform_device *pdev) } pcfg->pools =qm_get_pools_sdqcr (); +if (pcfg->pools ==0 ) +return -EPROBE_DEFER ;This is quite late in the probe, after a bunch of resources have been claimed.
Quoted 6 lines
Note that the ioremaps above this are doing unwinds, and you'll end up doing duplicate ioremaps if you come in and probe again.
You should probably unwind those allocations, or move them to devm_* or do this check earlier in the function.
The actual chance of having that happen is quite small (this was coming from a non working DT) and I mainly wanted to avoid a crash so the platform could still boot. I would think moving to devm_ would be the right thing to do.
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 38 lines · Alexandre Belloni
Quoted 36 lines · Olof Johansson
Hi,
Quoted 20 lines · Alexandre Belloni
If the qman driver (
qman_ccsr) doesn't probe or fail to probe beforeqman_portal,qm_ccsr_startwill be either NULL or a stale pointer to an unmapped page.This leads to a crash when probing
qman_portalas theinit_pcfgfunction callsqman_liodn_fixupthat tries to read qman registers.Assume that qman didn't probe when the pool mask is 0.
Signed-off-by Alexandre Belloni <[email protected]>--- drivers/soc/fsl/qbman/qman_portal.c | 2 ++ 1 file changed, 2 insertions(+)drivers/soc/fsl/qbman/qman_portal.c +0
-0drivers/soc/fsl/qbman/qman_portal.c static int qman_portal_probe(struct platform_device *pdev) · line 281
Quoted 5 lines
drivers/soc/fsl/qbman/qman_portal.c +2
-0@@ -277,6 +277,8 @@ static int qman_portal_probe(struct platform_device *pdev) } pcfg->pools =qm_get_pools_sdqcr (); +if (pcfg->pools ==0 ) +return -EPROBE_DEFER ;This is quite late in the probe, after a bunch of resources have been claimed.
Note that the ioremaps above this are doing unwinds, and you'll end up doing duplicate ioremaps if you come in and probe again.
Quoted 8 lines
Quoted 3 lines
You should probably unwind those allocations, or move them to devm_* or do this check earlier in the function.
The actual chance of having that happen is quite small (this was coming from a non working DT) and I mainly wanted to avoid a crash so the platform could still boot. I would think moving to
devm_would be the right thing to do.
Even if it is not failing with the upstreamed device trees, it is still good to harden the driver for possible issues. Moving to devm_ is definitely a right thing to do. But I also think checking if the qman is already probed should be the first thing to do before starting to allocate resources and etc and rolling back later. Probably we can move the qm_get_pools_sdqcr() to the begining of the probe to determine if qman is probed as it doesn't seem to depend on any of the setups done right now.
Regards,
Leo
Quoted 50 lines · Li Yang
Quoted 38 lines · Alexandre Belloni
Quoted 36 lines · Olof Johansson
Hi,
Quoted 20 lines · Alexandre Belloni
If the qman driver (
qman_ccsr) doesn't probe or fail to probe beforeqman_portal,qm_ccsr_startwill be either NULL or a stale pointer to an unmapped page.This leads to a crash when probing
qman_portalas theinit_pcfgfunction callsqman_liodn_fixupthat tries to read qman registers.Assume that qman didn't probe when the pool mask is 0.
Signed-off-by Alexandre Belloni <[email protected]>--- drivers/soc/fsl/qbman/qman_portal.c | 2 ++ 1 file changed, 2 insertions(+)drivers/soc/fsl/qbman/qman_portal.c +0
-0drivers/soc/fsl/qbman/qman_portal.c static int qman_portal_probe(struct platform_device *pdev) · line 281
Quoted 5 lines
drivers/soc/fsl/qbman/qman_portal.c +2
-0@@ -277,6 +277,8 @@ static int qman_portal_probe(struct platform_device *pdev) } pcfg->pools =qm_get_pools_sdqcr (); +if (pcfg->pools ==0 ) +return -EPROBE_DEFER ;This is quite late in the probe, after a bunch of resources have been claimed.
Note that the ioremaps above this are doing unwinds, and you'll end up doing duplicate ioremaps if you come in and probe again.
Quoted 8 lines
Quoted 3 lines
You should probably unwind those allocations, or move them to devm_* or do this check earlier in the function.
The actual chance of having that happen is quite small (this was coming from a non working DT) and I mainly wanted to avoid a crash so the platform could still boot. I would think moving to
devm_would be the right thing to do.
Quoted 8 lines
Even if it is not failing with the upstreamed device trees, it is still good to harden the driver for possible issues. Moving to
devm_is definitely a right thing to do. But I also think checking if the qman is already probed should be the first thing to do before starting to allocate resources and etc and rolling back later. Probably we can move theqm_get_pools_sdqcr()to the begining of the probe to determine if qman is probed as it doesn't seem to depend on any of the setups done right now.
I just find out Laurentiu also included the following patches in his SMMU patch series (although not neccessarily related to SMMU) which also fix the same problem. I think they are more straightforward and can deal with the case that qman failed to probe. So we can take these to fix this problem instead in 4.19.
https://patchwork.kernel.org/patch/10616021/
https://patchwork.kernel.org/patch/10616019/
https://patchwork.kernel.org/patch/10615971/
Regards,
Leo