From patchwork Wed Oct 19 17:45:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 13012244 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 B30C3C433FE for ; Wed, 19 Oct 2022 17:47:10 +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: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:In-Reply-To:References: List-Owner; bh=xsMXScD20POYWtRiG+Q+QbA0kmeba+7paxXVL+Hgdl8=; b=1KafiNV67t06gL 9OeR0YKolXnAJ+6s6jjqf3hCDaYRxNtD/IM6Fai4AomHbFJd5QTlv8t4qXlkARHigSOH0Lf5BCa0W K1ioTawxc5TtefvlsC5P/YVMLXhmBtTG101Aok9lK/qYlilUz7gD/T1vPYSJOqOY9lq2kJZ912Rl5 KonSoJchr2NOmkabe+HCH7v3VUNfI5sawZ0udA6RvmfvAJDE9CGOblMeEBV7K0UF/cgjiRz0e5iVv fZ58GYmwdxpt47vDQrkA9b5EQ1+5EBuXKwOsIeK6zzWPSxNPCj6t72X5RnNjGtYQY2QWxL+Cjcyc3 xxicuAeFEWjpmGEod8Cw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olD8j-004bQM-JY; Wed, 19 Oct 2022 17:46:01 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1olD8f-004bO8-Cf for linux-arm-kernel@lists.infradead.org; Wed, 19 Oct 2022 17:45:59 +0000 Received: by mail-ed1-x52d.google.com with SMTP id m16so26414594edc.4 for ; Wed, 19 Oct 2022 10:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=b3qQsYa/7ZweA0u9kpHAV4Ioh1PIQ7YV+2Zy1Ir6xbc=; b=EF+8GxOqjD7tz5bBqhQA4A8MVrYO9BfsHFXvcqliLTVztgNGNy46gTL+cw8it3RwDk I/yhw3zBTCKhOcz/MgyqQTstezO7xTAkqm0DgFYQ4Tx83dsic6vwctukoJj3QKIMWym0 x75Ep7MCrpFRgXJuifRFM79uan1zhrm/Yy7bXUf/HDFQ3dP3EMZUYM6SGW5RNUd6aL5u EUc/wtxvAwVC0n+0OSEmsqktGpgf6+SMfQdJgBK7Jxr4LzxOhQpW+d2LaXnc+cpxZdmp xqyfYl5yO4B1HRkjPdhh33z4p7MAPeFrW3wRXwICAgaTIPIVpFTcNF0U9GRU0JWpsX/e LRkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=b3qQsYa/7ZweA0u9kpHAV4Ioh1PIQ7YV+2Zy1Ir6xbc=; b=WPf4ZfnWw1uaN23LC8aYxNA6ddWm9z7cBcZpnwSHQam8VB+jSdvn3us2FNLiUbc0r0 jrvvKCTIoiGICqGtPqAUJPP7MeRbpGD0i+q53/f1J+wyZuPljvkcDpTiArYFScgHtTGO i4pF6fv7xM1Xc//DP5WxhSsB8B/HOMTtvtGM4HMx2xvxGzxc6FTAXwcpAF/hdz8BvqVW SAnrt8+Y1MhpC8Hj334sjI4/iS3yaw18T21rtfB1gRyDSj4jVcNkq16shcaQi3QeE7YJ wFVfCkcH4yYqi4mpKQl+EGpadM9vDE9juz9HSZOy2cOhmMxrStUW8oNQKjxrusWXfUtq DkGw== X-Gm-Message-State: ACrzQf04dfuMWF3ewAPcTME2jUXD0p6GfYVElmBI1WKfuChGGsj3ejaO Cm2DRKHeD7KPp1cjqBz0iq0= X-Google-Smtp-Source: AMsMyM7+C12t1o8higEU9r6SRH5hrJEdLyfeE4a3rQuBGmahnVZeQqTgOz5AVJmtx85oAd+c0bbn/g== X-Received: by 2002:aa7:ca45:0:b0:458:d9a2:6164 with SMTP id j5-20020aa7ca45000000b00458d9a26164mr8734873edt.340.1666201555073; Wed, 19 Oct 2022 10:45:55 -0700 (PDT) Received: from kista.localdomain (82-149-19-102.dynamic.telemach.net. [82.149.19.102]) by smtp.gmail.com with ESMTPSA id qn24-20020a170907211800b0073c10031dc9sm9218382ejb.80.2022.10.19.10.45.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 10:45:54 -0700 (PDT) From: Jernej Skrabec To: mripard@kernel.org, paul.kocialkowski@bootlin.com Cc: mchehab@kernel.org, gregkh@linuxfoundation.org, wens@csie.org, samuel@sholland.org, hverkuil-cisco@xs4all.nl, linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec Subject: [PATCH 0/2] media: cedrus: h264/h265: Improve aux buffer management Date: Wed, 19 Oct 2022 19:45:49 +0200 Message-Id: <20221019174551.2695149-1-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221019_104558_587628_A15CFBEC X-CRM114-Status: GOOD ( 10.44 ) 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 Current handling of mv col aux buffers in h264 and h265 code is not optimal. In h264 case, it allocates pool for worst case possible which basically never happens with typical videos. This also prevents it from working well on very memory constrained devices, where CMA pool is very small. In h265 case, number of buffers in a pool is equal to number of capture buffers allocated before streaming is started. If any capture buffer is allocated afterwards, Cedrus gets bogus pointers. This might cause memory corruption. Solution is the same in both cases. Instead of using memory pool, do individual allocations later, right before aux buffer is first used. Such approach allocates just right amount of buffers of optimal size. Proposed solution frees aux buffers in streaming off callback, which is first possible occasion. I can move this to .buf_cleanup too, if you think that it's more appropriate. Finally, h265 patch can be considered as a fix (prevents overwriting random memory). If deemed appropriate, fixes tag can be added. Let me know what you think. Best regards, Jernej Jernej Skrabec (2): media: cedrus: h265: Associate mv col buffers with buffer media: cedrus: h264: Optimize mv col buffer allocation drivers/staging/media/sunxi/cedrus/cedrus.h | 16 +-- .../staging/media/sunxi/cedrus/cedrus_h264.c | 118 +++++++++--------- .../staging/media/sunxi/cedrus/cedrus_h265.c | 63 +++++----- 3 files changed, 99 insertions(+), 98 deletions(-) --- 2.38.0