lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <3b140eaf883b4666985c0be0db8d53e8@skidata.com>
Date:   Fri, 21 Aug 2020 11:58:45 +0000
From:   Benjamin Bara - SKIDATA <Benjamin.Bara@...data.com>
To:     "p.zabel@...gutronix.de" <p.zabel@...gutronix.de>,
        "mchehab@...nel.org" <mchehab@...nel.org>
CC:     "linux-media@...r.kernel.org" <linux-media@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "Richard Leitner - SKIDATA" <Richard.Leitner@...data.com>
Subject: [PATCH] media: coda: avoid starvation on well-compressed data

The prefetcher requires two 256 byte periods beyond the current one.
However, currently it is only checked if there are at least 512 bytes
beyond the current meta available.
This only works under the assumption that every buffer has a size of
at least 256 bytes.

To ensure that the requirement is fulfilled with buffers < 256 bytes,
the queue head and the queue tail must not be below this threshold.
Otherwise, additional buffers are enqueued to ensure a full window.

Signed-off-by: Benjamin Bara <benjamin.bara@...data.com>
---
 drivers/media/platform/coda/coda-bit.c | 8 ++++++--
 drivers/media/platform/coda/coda.h     | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index b021604eceaa..8158f3b34b36 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -323,7 +323,7 @@ static bool coda_bitstream_try_queue(struct coda_ctx *ctx,
 void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list)
 {
 	struct vb2_v4l2_buffer *src_buf;
-	struct coda_buffer_meta *meta;
+	struct coda_buffer_meta *meta, *last_meta;
 	u32 start;
 
 	if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG)
@@ -343,6 +343,8 @@ void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list)
 		    ctx->num_metas >= ctx->num_internal_frames) {
 			meta = list_first_entry(&ctx->buffer_meta_list,
 						struct coda_buffer_meta, list);
+			last_meta = list_last_entry(&ctx->buffer_meta_list,
+						struct coda_buffer_meta, list);
 
 			/*
 			 * If we managed to fill in at least a full reorder
@@ -352,7 +354,8 @@ void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list)
 			 * the first buffer to fetch, we can safely stop queuing
 			 * in order to limit the decoder drain latency.
 			 */
-			if (coda_bitstream_can_fetch_past(ctx, meta->end))
+			if (!meta->below_threshold && !last_meta->below_threshold &&
+				coda_bitstream_can_fetch_past(ctx, meta->end))
 				break;
 		}
 
@@ -403,6 +406,7 @@ void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list)
 				meta->start = start;
 				meta->end = ctx->bitstream_fifo.kfifo.in;
 				meta->last = src_buf->flags & V4L2_BUF_FLAG_LAST;
+				meta->below_threshold = (meta->end - meta->start) < 256;
 				if (meta->last)
 					coda_dbg(1, ctx, "marking last meta");
 				spin_lock(&ctx->buffer_meta_lock);
diff --git a/drivers/media/platform/coda/coda.h b/drivers/media/platform/coda/coda.h
index b81f3aca9209..6f77553e81b8 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.h
@@ -160,6 +160,7 @@ struct coda_buffer_meta {
 	unsigned int		start;
 	unsigned int		end;
 	bool			last;
+	bool			below_threshold;
 };
 
 /* Per-queue, driver-specific private data */
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ