Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp866808rwb; Thu, 18 Aug 2022 13:49:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR5cQ6w1fpaKT2G5wOPL3MbjJjxsWMihGVGVsM0VoFWxqZisUX1iBQw+HZ3j1qCbmMusHyDZ X-Received: by 2002:a17:906:4795:b0:738:5b91:6e7 with SMTP id cw21-20020a170906479500b007385b9106e7mr2757133ejc.716.1660855783356; Thu, 18 Aug 2022 13:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660855783; cv=none; d=google.com; s=arc-20160816; b=mlgDuwtbioXZ7+CiaI9wtsq82usbhQ8IuA0uhPySHV4Y0kgYnJjfcSZwUykttZKcNp 5gQ+H6BF1g7T0MV1ggW0lp0acTpLd2WxbmFFPMnn1rhsZp8PIrliUYl3yvUeSTJsU6O7 r7lFeVr7pJ9AO9zWiPoPXc3RfA0TRp3YYQFw0GyZL90cbSNJOlgidXteGnx0IqvlKC40 ZyaYVucoqU1Rd2VifiKRFOlkmDzOXLDTwa7Vs1QHcyVBoavUmD4FN2vwBu2hZBXywFcu 9+k0yjHC0qzxo6Uw9e+6ShFFzCHmSroUvz0J28I7uVO2OTdW9HvdGXRUjd/4xLCag5rj BeSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jLUlziRUiVLH7qliTA1e9GCME0Bwy+c0lAlINKQAAU4=; b=HVW3MAvSKsxgczFTnjswGuiChurP2Irw/qO00CMC7afF3sbAApaOijlfoqOQmttSlx 7pwNOUXpkg3v8P0fioKb6+2rkNCyAYxZPzGdN1QpOP9GXH1s8gahHy9BUx9G4cgKVg5J 14inDo9LAUvgw2nRGfm4mtJKMhadKklG8l0mkISntAd4OQ3oTdPeRVN7DtiQkmJUXNlN 5oJGBnRMRfA6wPopADnToQnTIC6xnm/XSr9RPJ92ckAypjW4mvwBe4PKEyMuXdR5+uPo zUjnCPw6njHuxxjdng9G0kjCMXf3jxKiTRDEhFK5z7DMEDoWEVNki7vpeT48Vk8OPhvs 7vpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=JYDZhzav; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y88-20020a50bb61000000b0044601111c9fsi1637164ede.289.2022.08.18.13.49.15; Thu, 18 Aug 2022 13:49:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=JYDZhzav; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345474AbiHRUeG (ORCPT + 99 others); Thu, 18 Aug 2022 16:34:06 -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 ); 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 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 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: X-Mailing-List: linux-kernel@vger.kernel.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; } -- 2.37.2