Message ID | 20220818203308.439043-4-nicolas.dufresne@collabora.com (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Hans Verkuil |
Headers |
Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from <linux-media-owner@vger.kernel.org>) id 1oOmDP-006F8i-WC; Thu, 18 Aug 2022 20:34:08 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346104AbiHRUeE (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Thu, 18 Aug 2022 16:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346103AbiHRUeC (ORCPT <rfc822;linux-media@vger.kernel.org>); Thu, 18 Aug 2022 16:34:02 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FA1F3F1E2; Thu, 18 Aug 2022 13:34:00 -0700 (PDT) Received: from whitebuilder.lan (192-222-136-102.qc.cable.ebox.net [192.222.136.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nicolas) by madras.collabora.co.uk (Postfix) with ESMTPSA id 606AE6601BCA; Thu, 18 Aug 2022 21:33:57 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1660854839; bh=GgPaajQKLXv1616Hqx0PaERx4rlMxlMQza9pzPITvMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JYDZhzavP0trr+jEEMho+vU+B85/kDtbonYhDioXoPlFOh/TXFSNbC08MUU+JTXQc HSaIkIYCz6PG8Ab++c23BV+/fPUBLzM8FSyaxqBHSVBJRnvf/+QDfW3Y5zQza7TlvO +3HPLFDWffWf5GTbgqED4lOZEfVTuSgVHUcVoVHBBlcYIqeR2jq/ky7b8W1X6SrFnY oz6Fc087flGK0HZ0J2xWb1KjOd1N5XaR1mnAY4y9jFq+N7ylsDPIriVrZV4eCwwmtq Dx71wDW//MViP5NhPmjnZ2qCcPrifKhCxa9vmOBcDSY+5X7FnLP5KGosaC+0r02iMC qEeno4yLzr6Cg== From: Nicolas Dufresne <nicolas.dufresne@collabora.com> To: linux-media@vger.kernel.org, Maxime Ripard <mripard@kernel.org>, Paul Kocialkowski <paul.kocialkowski@bootlin.com>, Mauro Carvalho Chehab <mchehab@kernel.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Chen-Yu Tsai <wens@csie.org>, Jernej Skrabec <jernej.skrabec@gmail.com>, Samuel Holland <samuel@sholland.org> Cc: kernel@collabora.com, Dmitry Osipenko <dmitry.osipenko@collabora.com>, stable@vger.kernel.org, Nicolas Dufresne <nicolas.dufresne@collabora.com>, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/3] media: cedrus: Fix endless loop in cedrus_h265_skip_bits() Date: Thu, 18 Aug 2022 16:33:08 -0400 Message-Id: <20220818203308.439043-4-nicolas.dufresne@collabora.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220818203308.439043-1-nicolas.dufresne@collabora.com> References: <20220818203308.439043-1-nicolas.dufresne@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no |
Series |
cedrus: Various bug fixes
|
|
Commit Message
Nicolas Dufresne
Aug. 18, 2022, 8:33 p.m. UTC
From: Dmitry Osipenko <dmitry.osipenko@collabora.com> The busy status bit may never de-assert if number of programmed skip bits is incorrect, resulting in a kernel hang because the bit is polled endlessly in the code. Fix it by adding timeout for the bit-polling. This problem is reproducible by setting the data_bit_offset field of the HEVC slice params to a wrong value by userspace. Cc: stable@vger.kernel.org Reported-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> --- drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Comments
On 8/18/22 23:33, Nicolas Dufresne wrote: > From: Dmitry Osipenko <dmitry.osipenko@collabora.com> > > The busy status bit may never de-assert if number of programmed skip > bits is incorrect, resulting in a kernel hang because the bit is polled > endlessly in the code. Fix it by adding timeout for the bit-polling. > This problem is reproducible by setting the data_bit_offset field of > the HEVC slice params to a wrong value by userspace. > > Cc: stable@vger.kernel.org > Reported-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > --- > drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > index f703c585d91c5..f0bc118021b0a 100644 > --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > @@ -227,6 +227,7 @@ static void cedrus_h265_pred_weight_write(struct cedrus_dev *dev, > static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num) > { > int count = 0; > + u32 reg; This "reg" variable isn't needed anymore after switching to cedrus_wait_for(). Sorry, I missed it :) > while (count < num) { > int tmp = min(num - count, 32); > @@ -234,8 +235,9 @@ static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num) > cedrus_write(dev, VE_DEC_H265_TRIGGER, > VE_DEC_H265_TRIGGER_FLUSH_BITS | > VE_DEC_H265_TRIGGER_TYPE_N_BITS(tmp)); > - while (cedrus_read(dev, VE_DEC_H265_STATUS) & VE_DEC_H265_STATUS_VLD_BUSY) > - udelay(1); > + > + if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, VE_DEC_H265_STATUS_VLD_BUSY)) > + dev_err_ratelimited(dev->dev, "timed out waiting to skip bits\n"); > > count += tmp; > }
Le jeudi 18 août 2022 à 23:39 +0300, Dmitry Osipenko a écrit : > On 8/18/22 23:33, Nicolas Dufresne wrote: > > From: Dmitry Osipenko <dmitry.osipenko@collabora.com> > > > > The busy status bit may never de-assert if number of programmed skip > > bits is incorrect, resulting in a kernel hang because the bit is polled > > endlessly in the code. Fix it by adding timeout for the bit-polling. > > This problem is reproducible by setting the data_bit_offset field of > > the HEVC slice params to a wrong value by userspace. > > > > Cc: stable@vger.kernel.org > > Reported-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > > --- > > drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > > index f703c585d91c5..f0bc118021b0a 100644 > > --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > > +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > > @@ -227,6 +227,7 @@ static void cedrus_h265_pred_weight_write(struct cedrus_dev *dev, > > static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num) > > { > > int count = 0; > > + u32 reg; > > This "reg" variable isn't needed anymore after switching to > cedrus_wait_for(). Sorry, I missed it :) Good catch thanks, will fix. > > > while (count < num) { > > int tmp = min(num - count, 32); > > @@ -234,8 +235,9 @@ static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num) > > cedrus_write(dev, VE_DEC_H265_TRIGGER, > > VE_DEC_H265_TRIGGER_FLUSH_BITS | > > VE_DEC_H265_TRIGGER_TYPE_N_BITS(tmp)); > > - while (cedrus_read(dev, VE_DEC_H265_STATUS) & VE_DEC_H265_STATUS_VLD_BUSY) > > - udelay(1); > > + > > + if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, VE_DEC_H265_STATUS_VLD_BUSY)) > > + dev_err_ratelimited(dev->dev, "timed out waiting to skip bits\n"); > > > > count += tmp; > > } > >
Dne četrtek, 18. avgust 2022 ob 22:33:08 CEST je Nicolas Dufresne napisal(a): > From: Dmitry Osipenko <dmitry.osipenko@collabora.com> > > The busy status bit may never de-assert if number of programmed skip > bits is incorrect, resulting in a kernel hang because the bit is polled > endlessly in the code. Fix it by adding timeout for the bit-polling. > This problem is reproducible by setting the data_bit_offset field of > the HEVC slice params to a wrong value by userspace. > > Cc: stable@vger.kernel.org > Reported-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Fixes tag would be nice. > --- > drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c index > f703c585d91c5..f0bc118021b0a 100644 > --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > @@ -227,6 +227,7 @@ static void cedrus_h265_pred_weight_write(struct > cedrus_dev *dev, static void cedrus_h265_skip_bits(struct cedrus_dev *dev, > int num) { > int count = 0; > + u32 reg; > > while (count < num) { > int tmp = min(num - count, 32); > @@ -234,8 +235,9 @@ static void cedrus_h265_skip_bits(struct cedrus_dev > *dev, int num) cedrus_write(dev, VE_DEC_H265_TRIGGER, > VE_DEC_H265_TRIGGER_FLUSH_BITS | > VE_DEC_H265_TRIGGER_TYPE_N_BITS(tmp)); > - while (cedrus_read(dev, VE_DEC_H265_STATUS) & > VE_DEC_H265_STATUS_VLD_BUSY) - udelay(1); > + > + if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, > VE_DEC_H265_STATUS_VLD_BUSY)) + dev_err_ratelimited(dev->dev, "timed out > waiting to skip bits\n"); Reporting issue is nice, but better would be to propagate error, since there is no way to properly decode this slice if above code block fails. Best regards, Jernej > > count += tmp; > }
Le vendredi 19 août 2022 à 06:16 +0200, Jernej Škrabec a écrit : > Dne četrtek, 18. avgust 2022 ob 22:33:08 CEST je Nicolas Dufresne napisal(a): > > From: Dmitry Osipenko <dmitry.osipenko@collabora.com> > > > > The busy status bit may never de-assert if number of programmed skip > > bits is incorrect, resulting in a kernel hang because the bit is polled > > endlessly in the code. Fix it by adding timeout for the bit-polling. > > This problem is reproducible by setting the data_bit_offset field of > > the HEVC slice params to a wrong value by userspace. > > > > Cc: stable@vger.kernel.org > > Reported-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > > Fixes tag would be nice. > > > --- > > drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > > b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c index > > f703c585d91c5..f0bc118021b0a 100644 > > --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > > +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > > @@ -227,6 +227,7 @@ static void cedrus_h265_pred_weight_write(struct > > cedrus_dev *dev, static void cedrus_h265_skip_bits(struct cedrus_dev *dev, > > int num) { > > int count = 0; > > + u32 reg; > > > > while (count < num) { > > int tmp = min(num - count, 32); > > @@ -234,8 +235,9 @@ static void cedrus_h265_skip_bits(struct cedrus_dev > > *dev, int num) cedrus_write(dev, VE_DEC_H265_TRIGGER, > > VE_DEC_H265_TRIGGER_FLUSH_BITS | > > VE_DEC_H265_TRIGGER_TYPE_N_BITS(tmp)); > > - while (cedrus_read(dev, VE_DEC_H265_STATUS) & > > VE_DEC_H265_STATUS_VLD_BUSY) - udelay(1); > > + > > + if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, > > VE_DEC_H265_STATUS_VLD_BUSY)) + > dev_err_ratelimited(dev->dev, "timed out > > waiting to skip bits\n"); > > Reporting issue is nice, but better would be to propagate error, since there > is no way to properly decode this slice if above code block fails. This mimic what was already there, mind if we do that later ? The propagation is doing to be a lot more intrusive. > > Best regards, > Jernej > > > > > count += tmp; > > } > > > >
Dne petek, 19. avgust 2022 ob 17:39:25 CEST je Nicolas Dufresne napisal(a): > Le vendredi 19 août 2022 à 06:16 +0200, Jernej Škrabec a écrit : > > Dne četrtek, 18. avgust 2022 ob 22:33:08 CEST je Nicolas Dufresne napisal(a): > > > From: Dmitry Osipenko <dmitry.osipenko@collabora.com> > > > > > > The busy status bit may never de-assert if number of programmed skip > > > bits is incorrect, resulting in a kernel hang because the bit is polled > > > endlessly in the code. Fix it by adding timeout for the bit-polling. > > > This problem is reproducible by setting the data_bit_offset field of > > > the HEVC slice params to a wrong value by userspace. > > > > > > Cc: stable@vger.kernel.org > > > Reported-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > > > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > > > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > > > > Fixes tag would be nice. > > > > > --- > > > > > > drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 6 ++++-- > > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > > > b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c index > > > f703c585d91c5..f0bc118021b0a 100644 > > > --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > > > +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c > > > @@ -227,6 +227,7 @@ static void cedrus_h265_pred_weight_write(struct > > > cedrus_dev *dev, static void cedrus_h265_skip_bits(struct cedrus_dev > > > *dev, > > > int num) { > > > > > > int count = 0; > > > > > > + u32 reg; > > > > > > while (count < num) { > > > > > > int tmp = min(num - count, 32); > > > > > > @@ -234,8 +235,9 @@ static void cedrus_h265_skip_bits(struct cedrus_dev > > > *dev, int num) cedrus_write(dev, VE_DEC_H265_TRIGGER, > > > > > > VE_DEC_H265_TRIGGER_FLUSH_BITS | > > > VE_DEC_H265_TRIGGER_TYPE_N_BITS(tmp)); > > > > > > - while (cedrus_read(dev, VE_DEC_H265_STATUS) & > > > VE_DEC_H265_STATUS_VLD_BUSY) - udelay(1); > > > + > > > + if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, > > > VE_DEC_H265_STATUS_VLD_BUSY)) + > > > > dev_err_ratelimited(dev->dev, "timed out > > > > > waiting to skip bits\n"); > > > > Reporting issue is nice, but better would be to propagate error, since > > there is no way to properly decode this slice if above code block fails. > This mimic what was already there, mind if we do that later ? The > propagation is doing to be a lot more intrusive. Since backporting fixes before 6.0 isn't priority, viability for backpporting isn't that important. You would only need to return 0 or -ETIMEDOUT and check for error in only one location. That doesn't sound very intrusive for me. Best regards, Jernej > > > Best regards, > > Jernej > > > > > count += tmp; > > > > > > }
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c index f703c585d91c5..f0bc118021b0a 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c @@ -227,6 +227,7 @@ static void cedrus_h265_pred_weight_write(struct cedrus_dev *dev, static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num) { int count = 0; + u32 reg; while (count < num) { int tmp = min(num - count, 32); @@ -234,8 +235,9 @@ static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num) cedrus_write(dev, VE_DEC_H265_TRIGGER, VE_DEC_H265_TRIGGER_FLUSH_BITS | VE_DEC_H265_TRIGGER_TYPE_N_BITS(tmp)); - while (cedrus_read(dev, VE_DEC_H265_STATUS) & VE_DEC_H265_STATUS_VLD_BUSY) - udelay(1); + + if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, VE_DEC_H265_STATUS_VLD_BUSY)) + dev_err_ratelimited(dev->dev, "timed out waiting to skip bits\n"); count += tmp; }