* [PATCH v1 0/2] media: rockchip: rkcif: Fix a system hang and validate the pixel format
@ 2026-11-12 18:32 Mehdi Djait
2026-11-12 18:32 ` [PATCH v1 1/2] media: rockchip: rkcif: Don't reset the hardware in runtime suspend Mehdi Djait
2026-11-12 18:32 ` [PATCH v1 2/2] media: rockchip: rkcif: Validate the pixel format against the media bus code Mehdi Djait
0 siblings, 2 replies; 7+ messages in thread
From: Mehdi Djait @ 2026-11-12 18:32 UTC (permalink / raw)
To: michael.riesch
Cc: linux-media, paul.elder, daniel, linux-rockchip, Mehdi Djait
Hello Michael :)
Sorry for the additional work with this flood of patches...
This series fixes two issues in the rkcif driver that stayed long enough on
my TODO list.
I am using an RK3588 ROCK 5B with an IMX415 sensor.
Patch 1 drops the reset from the runtime suspend. The reset also resets
the VICAP IOMMU and hangs the system when the IOMMU driver accesses the
IOMMU registers at the same time. This was reproduced by repeatedly
starting and stopping the stream with runtime PM enabled.
Steps to reproduce the issue:
* configure the media pipeline
* You can use this script here:
--------------------------------------------------------------------------------
$ cat stream-loop.sh
#!/bin/bash
# Start and stop yavta in a loop: stream for a random 0.1-1 s
# Usage: ./stream-loop.sh [device]
DEV=${1:-/dev/video0}
trap 'echo; echo "stopped after $i iterations"; exit 0' INT
i=0
while true; do
i=$((i + 1))
stream=$(printf "0.%03d" $((100 + RANDOM % 900)))
echo "=== iteration $i: stream ${stream}s"
timeout -s INT "$stream" yavta -c -f SGBRG10 -s 3864x2192 "$DEV"
done
--------------------------------------------------------------------------------
Patch 2 rejects pipelines where the pixel format does not match the
media bus code on the source pad.
Steps to reproduce the issue:
* configure the media pipeline to use SGBRG10
* try to capture with yavta using the format SGBRG12
Fyi:
Another patch is also needed to not get the timeout everytime the
streaming is stopped but some of the work on that patch is already done
in Daniel's 4th patch:
https://lore.kernel.org/linux-media/cover.1793702189.git.daniel@makrotopia.org/
Mehdi Djait (2):
media: rockchip: rkcif: Don't reset the hardware in runtime suspend
media: rockchip: rkcif: Validate the pixel format against the media
bus code
.../media/platform/rockchip/rkcif/rkcif-common.h | 1 -
drivers/media/platform/rockchip/rkcif/rkcif-dev.c | 15 ---------------
.../media/platform/rockchip/rkcif/rkcif-stream.c | 12 ++++++++++++
3 files changed, 12 insertions(+), 16 deletions(-)
--
2.56.0
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v1 1/2] media: rockchip: rkcif: Don't reset the hardware in runtime suspend 2026-11-12 18:32 [PATCH v1 0/2] media: rockchip: rkcif: Fix a system hang and validate the pixel format Mehdi Djait @ 2026-11-12 18:32 ` Mehdi Djait 2026-11-16 10:58 ` Michael Riesch 2026-11-12 18:32 ` [PATCH v1 2/2] media: rockchip: rkcif: Validate the pixel format against the media bus code Mehdi Djait 1 sibling, 1 reply; 7+ messages in thread From: Mehdi Djait @ 2026-11-12 18:32 UTC (permalink / raw) To: michael.riesch Cc: linux-media, paul.elder, daniel, linux-rockchip, Mehdi Djait, stable The reset in the runtime suspend also resets the VICAP IOMMU. When the IOMMU driver accesses the IOMMU registers inside the delay window between the assert and deassert, e.g. in rk_iommu_zap_lines() to shootdown IOTLB entries, the system hangs. Drop the reset and the now unused reset control. Fixes: f53fb31a3889 ("media: rockchip: add driver for the rockchip camera interface") Cc: stable@vger.kernel.org Signed-off-by: Mehdi Djait <mehdi.djait@linux.intel.com> --- .../media/platform/rockchip/rkcif/rkcif-common.h | 1 - drivers/media/platform/rockchip/rkcif/rkcif-dev.c | 15 --------------- 2 files changed, 16 deletions(-) diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-common.h b/drivers/media/platform/rockchip/rkcif/rkcif-common.h index 4d9211ba9bda..38208e8b7b2d 100644 --- a/drivers/media/platform/rockchip/rkcif/rkcif-common.h +++ b/drivers/media/platform/rockchip/rkcif/rkcif-common.h @@ -237,7 +237,6 @@ struct rkcif_device { struct clk_bulk_data clks[RKCIF_CLK_MAX]; unsigned int clks_num; struct regmap *grf; - struct reset_control *reset; void __iomem *base_addr; struct rkcif_interface interfaces[RKCIF_IF_MAX]; diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-dev.c b/drivers/media/platform/rockchip/rkcif/rkcif-dev.c index be3a174b9aab..dceabee2ecd6 100644 --- a/drivers/media/platform/rockchip/rkcif/rkcif-dev.c +++ b/drivers/media/platform/rockchip/rkcif/rkcif-dev.c @@ -10,7 +10,6 @@ */ #include <linux/clk.h> -#include <linux/delay.h> #include <linux/interrupt.h> #include <linux/mfd/syscon.h> #include <linux/module.h> @@ -18,7 +17,6 @@ #include <linux/of_graph.h> #include <linux/of_platform.h> #include <linux/pm_runtime.h> -#include <linux/reset.h> #include <media/v4l2-fwnode.h> #include <media/v4l2-mc.h> @@ -201,10 +199,6 @@ static int rkcif_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "failed to get clocks\n"); - rkcif->reset = devm_reset_control_array_get_exclusive(dev); - if (IS_ERR(rkcif->reset)) - return PTR_ERR(rkcif->reset); - rkcif->grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,grf"); if (IS_ERR(rkcif->grf)) @@ -273,15 +267,6 @@ static int rkcif_runtime_suspend(struct device *dev) { struct rkcif_device *rkcif = dev_get_drvdata(dev); - /* - * Reset CIF (CRU, DMA, FIFOs) to allow a clean resume. - * Since this resets the IOMMU too, we cannot issue this reset when - * resuming. - */ - reset_control_assert(rkcif->reset); - udelay(5); - reset_control_deassert(rkcif->reset); - clk_bulk_disable_unprepare(rkcif->clks_num, rkcif->clks); return 0; -- 2.56.0 _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] media: rockchip: rkcif: Don't reset the hardware in runtime suspend 2026-11-12 18:32 ` [PATCH v1 1/2] media: rockchip: rkcif: Don't reset the hardware in runtime suspend Mehdi Djait @ 2026-11-16 10:58 ` Michael Riesch 2026-11-16 14:30 ` Mehdi Djait 0 siblings, 1 reply; 7+ messages in thread From: Michael Riesch @ 2026-11-16 10:58 UTC (permalink / raw) To: Mehdi Djait; +Cc: linux-media, paul.elder, daniel, linux-rockchip, stable Hi Mehdi, On 11/12/26 19:32, Mehdi Djait wrote: > The reset in the runtime suspend also resets the VICAP IOMMU. > > When the IOMMU driver accesses the IOMMU registers inside the delay window > between the assert and deassert, e.g. in rk_iommu_zap_lines() to shootdown > IOTLB entries, the system hangs. > > Drop the reset and the now unused reset control. I agree that the current situation is nothing more than a crude hack that happened to work in most cases. But I doubt simply removing the reset is the correct solution. Recently, I saw some downstream patch that makes the reset a shared one, which seems like the right thing to do here. What would you think about that? Best regards, Michael > > Fixes: f53fb31a3889 ("media: rockchip: add driver for the rockchip camera interface") > Cc: stable@vger.kernel.org > Signed-off-by: Mehdi Djait <mehdi.djait@linux.intel.com> > --- > .../media/platform/rockchip/rkcif/rkcif-common.h | 1 - > drivers/media/platform/rockchip/rkcif/rkcif-dev.c | 15 --------------- > 2 files changed, 16 deletions(-) > > diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-common.h b/drivers/media/platform/rockchip/rkcif/rkcif-common.h > index 4d9211ba9bda..38208e8b7b2d 100644 > --- a/drivers/media/platform/rockchip/rkcif/rkcif-common.h > +++ b/drivers/media/platform/rockchip/rkcif/rkcif-common.h > @@ -237,7 +237,6 @@ struct rkcif_device { > struct clk_bulk_data clks[RKCIF_CLK_MAX]; > unsigned int clks_num; > struct regmap *grf; > - struct reset_control *reset; > void __iomem *base_addr; > > struct rkcif_interface interfaces[RKCIF_IF_MAX]; > diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-dev.c b/drivers/media/platform/rockchip/rkcif/rkcif-dev.c > index be3a174b9aab..dceabee2ecd6 100644 > --- a/drivers/media/platform/rockchip/rkcif/rkcif-dev.c > +++ b/drivers/media/platform/rockchip/rkcif/rkcif-dev.c > @@ -10,7 +10,6 @@ > */ > > #include <linux/clk.h> > -#include <linux/delay.h> > #include <linux/interrupt.h> > #include <linux/mfd/syscon.h> > #include <linux/module.h> > @@ -18,7 +17,6 @@ > #include <linux/of_graph.h> > #include <linux/of_platform.h> > #include <linux/pm_runtime.h> > -#include <linux/reset.h> > > #include <media/v4l2-fwnode.h> > #include <media/v4l2-mc.h> > @@ -201,10 +199,6 @@ static int rkcif_probe(struct platform_device *pdev) > if (ret) > return dev_err_probe(dev, ret, "failed to get clocks\n"); > > - rkcif->reset = devm_reset_control_array_get_exclusive(dev); > - if (IS_ERR(rkcif->reset)) > - return PTR_ERR(rkcif->reset); > - > rkcif->grf = syscon_regmap_lookup_by_phandle(dev->of_node, > "rockchip,grf"); > if (IS_ERR(rkcif->grf)) > @@ -273,15 +267,6 @@ static int rkcif_runtime_suspend(struct device *dev) > { > struct rkcif_device *rkcif = dev_get_drvdata(dev); > > - /* > - * Reset CIF (CRU, DMA, FIFOs) to allow a clean resume. > - * Since this resets the IOMMU too, we cannot issue this reset when > - * resuming. > - */ > - reset_control_assert(rkcif->reset); > - udelay(5); > - reset_control_deassert(rkcif->reset); > - > clk_bulk_disable_unprepare(rkcif->clks_num, rkcif->clks); > > return 0; _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] media: rockchip: rkcif: Don't reset the hardware in runtime suspend 2026-11-16 10:58 ` Michael Riesch @ 2026-11-16 14:30 ` Mehdi Djait 2026-11-17 9:09 ` Mehdi Djait 0 siblings, 1 reply; 7+ messages in thread From: Mehdi Djait @ 2026-11-16 14:30 UTC (permalink / raw) To: Michael Riesch; +Cc: linux-media, paul.elder, daniel, linux-rockchip, stable Hi Michael, On Mon, Nov 16, 2026 at 11:58:35AM +0100, Michael Riesch wrote: > Hi Mehdi, > > On 11/12/26 19:32, Mehdi Djait wrote: > > The reset in the runtime suspend also resets the VICAP IOMMU. > > > > When the IOMMU driver accesses the IOMMU registers inside the delay window > > between the assert and deassert, e.g. in rk_iommu_zap_lines() to shootdown > > IOTLB entries, the system hangs. > > > > Drop the reset and the now unused reset control. > > I agree that the current situation is nothing more than a crude hack > that happened to work in most cases. But I doubt simply removing the > reset is the correct solution. Recently, I saw some downstream patch > that makes the reset a shared one, which seems like the right thing to > do here. What would you think about that? Do you have a link for these patches ? I also agree that this patch will not be the solution that will go in but the situation needs to change. The VICAP_GLB_CTRL register does expose this: reset the VICAP(except MMU/AXI MASTER/REG FILE) The Rockchip-bsp kernel exports the disable and enable functions of the iommu driver and calls them in the rkcif driver, see: https://github.com/rockchip-linux/kernel/blob/develop-6.1/drivers/media/platform/rockchip/cif/capture.c#L7269 -- Kind regards Mehdi Djait _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] media: rockchip: rkcif: Don't reset the hardware in runtime suspend 2026-11-16 14:30 ` Mehdi Djait @ 2026-11-17 9:09 ` Mehdi Djait 0 siblings, 0 replies; 7+ messages in thread From: Mehdi Djait @ 2026-11-17 9:09 UTC (permalink / raw) To: Michael Riesch; +Cc: linux-media, paul.elder, daniel, linux-rockchip, stable On Mon, Nov 16, 2026 at 03:30:33PM +0100, Mehdi Djait wrote: > Hi Michael, > > On Mon, Nov 16, 2026 at 11:58:35AM +0100, Michael Riesch wrote: > > Hi Mehdi, > > > > On 11/12/26 19:32, Mehdi Djait wrote: > > > The reset in the runtime suspend also resets the VICAP IOMMU. > > > > > > When the IOMMU driver accesses the IOMMU registers inside the delay window > > > between the assert and deassert, e.g. in rk_iommu_zap_lines() to shootdown > > > IOTLB entries, the system hangs. > > > > > > Drop the reset and the now unused reset control. > > > > I agree that the current situation is nothing more than a crude hack > > that happened to work in most cases. But I doubt simply removing the > > reset is the correct solution. Recently, I saw some downstream patch > > that makes the reset a shared one, which seems like the right thing to > > do here. What would you think about that? > > Do you have a link for these patches ? > > I also agree that this patch will not be the solution that will go in > but the situation needs to change. > > The VICAP_GLB_CTRL register does expose this: > reset the VICAP(except MMU/AXI MASTER/REG FILE) > > The Rockchip-bsp kernel exports the disable and enable functions of the > iommu driver and calls them in the rkcif driver, see: > https://github.com/rockchip-linux/kernel/blob/develop-6.1/drivers/media/platform/rockchip/cif/capture.c#L7269 > I mean, I of course don't think this is a solution to be considered, but this is what I found for now.. -- Kind regards Mehdi Djait _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 2/2] media: rockchip: rkcif: Validate the pixel format against the media bus code 2026-11-12 18:32 [PATCH v1 0/2] media: rockchip: rkcif: Fix a system hang and validate the pixel format Mehdi Djait 2026-11-12 18:32 ` [PATCH v1 1/2] media: rockchip: rkcif: Don't reset the hardware in runtime suspend Mehdi Djait @ 2026-11-12 18:32 ` Mehdi Djait 2026-11-16 10:55 ` Michael Riesch 1 sibling, 1 reply; 7+ messages in thread From: Mehdi Djait @ 2026-11-12 18:32 UTC (permalink / raw) To: michael.riesch Cc: linux-media, paul.elder, daniel, linux-rockchip, Mehdi Djait The link validation only checks the frame size, so a pixel format that does not match the media bus code on the source pad is accepted. Reject such pipelines with -EPIPE. Signed-off-by: Mehdi Djait <mehdi.djait@linux.intel.com> --- drivers/media/platform/rockchip/rkcif/rkcif-stream.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c index 3130d420ad55..66726f654674 100644 --- a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c +++ b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c @@ -460,6 +460,7 @@ static int rkcif_stream_link_validate(struct media_link *link) { struct video_device *vdev = media_entity_to_video_device(link->sink->entity); + const struct rkcif_output_fmt *fmt; struct v4l2_mbus_framefmt *source_fmt; struct v4l2_subdev *sd; struct v4l2_subdev_state *state; @@ -489,6 +490,17 @@ static int rkcif_stream_link_validate(struct media_link *link) goto out; } + fmt = rkcif_stream_find_output_fmt(stream, false, + stream->pix.pixelformat); + if (!fmt || (fmt->mbus_code && fmt->mbus_code != source_fmt->code)) { + dev_dbg(stream->rkcif->dev, + "link '%s':%u -> '%s':%u not valid: Format mismatch\n", + link->source->entity->name, link->source->index, + link->sink->entity->name, link->sink->index); + ret = -EPIPE; + goto out; + } + ret = 0; out: -- 2.56.0 _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 2/2] media: rockchip: rkcif: Validate the pixel format against the media bus code 2026-11-12 18:32 ` [PATCH v1 2/2] media: rockchip: rkcif: Validate the pixel format against the media bus code Mehdi Djait @ 2026-11-16 10:55 ` Michael Riesch 0 siblings, 0 replies; 7+ messages in thread From: Michael Riesch @ 2026-11-16 10:55 UTC (permalink / raw) To: Mehdi Djait Cc: linux-media, paul.elder, daniel, linux-rockchip, Gerald Loacker Hi Mehdi, Thanks for the patch! I think I had a check like this in the source code once, but kicked it out because it broke one of my valid pipelines. Let's take the first entry of mipi_out_fmts for instance: the capture block can write V4L2_PIX_FMT_YUYV image data to memory. However, I *think* it can not only accept MEDIA_BUS_FMT_YUYV8_1X16 as input format for that, but other mbus formats too. Thus, if I am not mistaken, we need to rework that at some point. Cc: Gerald who might have a pipeline that will be broken by this patch... On 11/12/26 19:32, Mehdi Djait wrote: > The link validation only checks the frame size, so a pixel format that > does not match the media bus code on the source pad is accepted. > > Reject such pipelines with -EPIPE. > > Signed-off-by: Mehdi Djait <mehdi.djait@linux.intel.com> ...but all the above said, the patch as such is valid, but I think the definition of possible formats needs a rework. I'll leave my Reviewed-by: Michael Riesch <michael.riesch@collabora.com> here just in case. Best regards, Michael > --- > drivers/media/platform/rockchip/rkcif/rkcif-stream.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c > index 3130d420ad55..66726f654674 100644 > --- a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c > +++ b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c > @@ -460,6 +460,7 @@ static int rkcif_stream_link_validate(struct media_link *link) > { > struct video_device *vdev = > media_entity_to_video_device(link->sink->entity); > + const struct rkcif_output_fmt *fmt; > struct v4l2_mbus_framefmt *source_fmt; > struct v4l2_subdev *sd; > struct v4l2_subdev_state *state; > @@ -489,6 +490,17 @@ static int rkcif_stream_link_validate(struct media_link *link) > goto out; > } > > + fmt = rkcif_stream_find_output_fmt(stream, false, > + stream->pix.pixelformat); > + if (!fmt || (fmt->mbus_code && fmt->mbus_code != source_fmt->code)) { > + dev_dbg(stream->rkcif->dev, > + "link '%s':%u -> '%s':%u not valid: Format mismatch\n", > + link->source->entity->name, link->source->index, > + link->sink->entity->name, link->sink->index); > + ret = -EPIPE; > + goto out; > + } > + > ret = 0; > > out: _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-17 9:09 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-12 18:32 [PATCH v1 0/2] media: rockchip: rkcif: Fix a system hang and validate the pixel format Mehdi Djait 2026-11-12 18:32 ` [PATCH v1 1/2] media: rockchip: rkcif: Don't reset the hardware in runtime suspend Mehdi Djait 2026-11-16 10:58 ` Michael Riesch 2026-11-16 14:30 ` Mehdi Djait 2026-11-17 9:09 ` Mehdi Djait 2026-11-12 18:32 ` [PATCH v1 2/2] media: rockchip: rkcif: Validate the pixel format against the media bus code Mehdi Djait 2026-11-16 10:55 ` Michael Riesch
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox