Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Rémi Denis-Courmont via ffmpeg-devel" <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: "Rémi Denis-Courmont" <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] lavc/h264qpel: fix RISC-V stack usage (PR #21253)
Date: Sun, 21 Dec 2025 11:32:28 -0000
Message-ID: <176631674917.60.16296841859437111640@2cb04c0e5124> (raw)

PR #21253 opened by Rémi Denis-Courmont (Courmisch)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21253
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21253.patch

The function violated the ABI requirement not to write below SP
(this breaks asynchronous signal handling). On RV32, it also broke
did not align SP to 16 bytes and did not restore it correctly.

No changes to benchmarks as this patch only changes a few immediate
offsets.


From e000c237e39b58ffcd3007acbd9dc58fccbd497f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= <remi@remlab.net>
Date: Sun, 21 Dec 2025 13:28:50 +0200
Subject: [PATCH] lavc/h264qpel: fix RISC-V stack usage

The function violated the ABI requirement not to write below SP
(this breaks asynchronous signal handling). On RV32, it also broke
did not align SP to 16 bytes and did not restore it correctly.

No changes to benchmarks as this patch only changes a few immediate
offsets.
---
 libavcodec/riscv/h264qpel_rvv.S | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/libavcodec/riscv/h264qpel_rvv.S b/libavcodec/riscv/h264qpel_rvv.S
index 77a534767c..df6796748f 100644
--- a/libavcodec/riscv/h264qpel_rvv.S
+++ b/libavcodec/riscv/h264qpel_rvv.S
@@ -48,6 +48,9 @@
 #endif
 .endm
 
+#define XSZ            (__riscv_xlen / 8)
+#define STACK_ALIGN(x) (((x) + 15) & ~15)
+
         /* output is unclipped; clobbers v26-v31 plus t0 and t02 */
 .macro lowpass_h         vdst, src
         addi             t4, \src, 3
@@ -380,12 +383,12 @@ func ff_\op\()_h264_qpel\size\()_\case\()_\ext, zve32x
         lpad             0
         vsetivli         zero, \size, e8, \lmul, ta, ma
         csrwi            vxrm, 0
-        addi             sp, sp, (-(__riscv_xlen >> 2))
+        addi             sp, sp, -STACK_ALIGN(2 * XSZ + \size * \size)
         li               a4, \size
         li               t6, 20
         li               a7, -5
-        sx               a0, 0(sp)
-        sx               a1, (__riscv_xlen >> 3)(sp)
+        sx               a0,    (sp)
+        sx               a1, XSZ(sp)
     .ifc \off1, a2
         add              a1, a1, \off1
     .elseif \off1
@@ -394,18 +397,18 @@ func ff_\op\()_h264_qpel\size\()_\case\()_\ext, zve32x
         mv               a3, a2
     .ifc \op, avg
         // Use temporary array on stack for the first pass
-        addi             a0, sp, -(\size * \size)
+        addi             a0, sp, 2 * XSZ
         li               a2, \size
     .endif
         jal              t0, ff_put_h264_qpel_\dir1\()_lowpass_\lmul
-        lx               a0, 0(sp)
-        lx               a1, (__riscv_xlen >> 3)(sp)
+        lx               a0,    (sp)
+        lx               a1, XSZ(sp)
     .ifc \op, put
         // Directly reuse the first pass output buffer
         mv               a5, a0
         mv               a6, a2
     .else
-        addi             a5, sp, -(\size * \size)
+        addi             a5, sp, 2 * XSZ
         li               a6, \size
         mv               a2, a3
     .endif
@@ -414,7 +417,7 @@ func ff_\op\()_h264_qpel\size\()_\case\()_\ext, zve32x
     .endif
         li               a4, \size
         mv               t0, ra
-        addi             sp, sp, 16
+        addi             sp, sp, STACK_ALIGN(2 * XSZ + \size * \size)
         j                ff_\op\()_h264_qpel_\dir2\()_lowpass_\lmul\()_l2
 endfunc
 .endm
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-12-21 11:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=176631674917.60.16296841859437111640@2cb04c0e5124 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git