From patchwork Thu Aug 18 20:33:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dufresne X-Patchwork-Id: 12947862 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91BD7C00140 for ; Thu, 18 Aug 2022 20:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8t7X8QuUsfZT9Cmd6Skzrelq/6nsYKJe4UcFRFN4woE=; b=zFAsllb9UyQx40 ZwTxckXdqUuAlKGgVu7iWy+ZgBt9J5sukQculhvotJMRhgcpigqlrKw+tCM00nuqYg4XhFs3ScYiB YqDnJh7NJuY2j5zuqiy4g2eFBNfU4weuHiYN1BAzEgo7lqq4ez2bfgkIDjzg/vU9WVR2F7RsIDGKw ynQT0st8Zx1h9GBCzmGRLil+UQtywkb6FimeLOWHgiQjTJw40huktp3Vkad5hxth5q03wBDvOzXey qXD2+WQSmZBHEEnEezxkhBuehkFbZenosLw/txkNMo+KWLWaMx2GTE9M+jteEA4Zrfqr/l7LjT1Cp H/1GMI4/gvOCl5qPpj0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oOmDj-009GOF-Pa; Thu, 18 Aug 2022 20:34:28 +0000 Received: from madras.collabora.co.uk ([2a00:1098:0:82:1000:25:2eeb:e5ab]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oOmDI-009G6M-Jg for linux-arm-kernel@lists.infradead.org; Thu, 18 Aug 2022 20:34:01 +0000 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 To: linux-media@vger.kernel.org, Maxime Ripard , Paul Kocialkowski , Mauro Carvalho Chehab , Greg Kroah-Hartman , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: kernel@collabora.com, Dmitry Osipenko , stable@vger.kernel.org, Nicolas Dufresne , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220818_133400_803148_36943907 X-CRM114-Status: GOOD ( 13.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Dmitry Osipenko 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 Signed-off-by: Dmitry Osipenko Signed-off-by: Nicolas Dufresne --- 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"); count += tmp; }