Commit 29da93aae9 for qemu.org

commit 29da93aae9eb2a221d59a0e2112a57d6361fd941
Author: NickSampanis <nicksampanis@gmail.com>
Date:   Mon Oct 26 01:18:02 2026 +0200

    target/i386/tcg: Fix 64-bit RSP truncation on far call in 64-bit mode

    When executing a direct far call to a code segment (no call gate
    involved) in 64-bit mode with a 16- or 32-bit operand size,
    `lcall_protected` falls back to `get_sp_mask(SS.flags)`. This gives a
    16- or 32-bit mask, but in 64-bit mode the stack always uses the full
    RSP and the attributes are ignored. As a result, the pushes of the return
    address and the stack pointer update (`SET_ESP`) truncate RSP. This is
    the same bug fixed for retf in the previous patch.

    Use the full stack pointer, with no mask, for a direct far call when
    CS is 64-bit.

    Signed-off-by: NickSampanis <nicksampanis@gmail.com>
    Link: https://lore.kernel.org/r/20261025231803.870-3-nicksampanis@gmail.com
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

diff --git a/target/i386/tcg/seg_helper.c b/target/i386/tcg/seg_helper.c
index af18aec694..87492a2f64 100644
--- a/target/i386/tcg/seg_helper.c
+++ b/target/i386/tcg/seg_helper.c
@@ -1731,7 +1731,11 @@ void HELPER(lcall_protected)(CPUX86State *env, int new_cs, target_ulong new_eip,
 #endif
         {
             sa.sp = env->regs[R_ESP];
-            sa.sp_mask = get_sp_mask(env->segs[R_SS].flags);
+            if (env->hflags & HF_CS64_MASK) {
+                sa.sp_mask = -1;
+            } else {
+                sa.sp_mask = get_sp_mask(env->segs[R_SS].flags);
+            }
             sa.ss_base = env->segs[R_SS].base;
             if (shift) {
                 pushl(&sa, env->segs[R_CS].selector);