Skip to contentSkip to conversation

target/i386: Fix #GP error code for INT instructions

PATCH Applied Andrew Cooper 2 participants 6 messages Mar 12, 2025 – Dec 12, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386: Fix #GP error code for INT instructions

While the (intno << shift) expression is correct for indexing the IDT based on whether Long Mode is active, the error code itself was unchanged with AMD64, and is still the index with 3 bits of metadata in the bottom.

Found when running a Xen unit test, all under QEMU. The unit test objected to being told there was an error with IDT index 256 when INT $0x80 (128) was the problem instruction:

...
Error: Unexpected fault 0x800d0802, #GP[IDT[256]]
...

Fixes d2fd1af76777 ("x86_64 linux user emulation")

---
CC: Paolo Bonzini <[email protected]>
CC: Richard Henderson <[email protected]>
CC: Eduardo Habkost <[email protected]>

---
 target/i386/tcg/user/seg_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/user/seg_helper.c +1 -1
index c45f2ac2ba68..ff328b2a9522 100644
@@ -64,7 +64,7 @@ static void do_interrupt_user(CPUX86State *env, int intno, int is_int,
         cpl = env->hflags & HF_CPL_MASK;
         /* check privilege if software int */
         if (dpl < cpl) {
-            raise_exception_err(env, EXCP0D_GPF, (intno << shift) + 2);
+            raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
         }
     }
 

base-commit: 825b96dbcee23d134b691fc75618b59c5f53da32

Signature · 1 line
2.39.5
#1 lore raw

Ping?

Quoted 37 lines · Andrew Cooper

While the (intno << shift) expression is correct for indexing the IDT based on whether Long Mode is active, the error code itself was unchanged with AMD64, and is still the index with 3 bits of metadata in the bottom.

Found when running a Xen unit test, all under QEMU. The unit test objected to being told there was an error with IDT index 256 when INT $0x80 (128) was the problem instruction:

...
Error: Unexpected fault 0x800d0802, #GP[IDT[256]]
...

Fixes d2fd1af76777 ("x86_64 linux user emulation")

---
CC: Paolo Bonzini <[email protected]>
CC: Richard Henderson <[email protected]>
CC: Eduardo Habkost <[email protected]>

---
 target/i386/tcg/user/seg_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/user/seg_helper.c +1 -1
index c45f2ac2ba68..ff328b2a9522 100644
@@ -64,7 +64,7 @@ static void do_interrupt_user(CPUX86State *env, int intno, int is_int,
         cpl = env->hflags & HF_CPL_MASK;
         /* check privilege if software int */
         if (dpl < cpl) {
-            raise_exception_err(env, EXCP0D_GPF, (intno << shift) + 2);
+            raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
         }
     }
 

base-commit: 825b96dbcee23d134b691fc75618b59c5f53da32

#2 lore raw

Ping again?

~Andrew

Quoted 40 lines · Andrew Cooper

Ping?

Quoted 37 lines · Andrew Cooper

While the (intno << shift) expression is correct for indexing the IDT based on whether Long Mode is active, the error code itself was unchanged with AMD64, and is still the index with 3 bits of metadata in the bottom.

Found when running a Xen unit test, all under QEMU. The unit test objected to being told there was an error with IDT index 256 when INT $0x80 (128) was the problem instruction:

...
Error: Unexpected fault 0x800d0802, #GP[IDT[256]]
...

Fixes d2fd1af76777 ("x86_64 linux user emulation")

---
CC: Paolo Bonzini <[email protected]>
CC: Richard Henderson <[email protected]>
CC: Eduardo Habkost <[email protected]>

---
 target/i386/tcg/user/seg_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/user/seg_helper.c +1 -1
index c45f2ac2ba68..ff328b2a9522 100644
@@ -64,7 +64,7 @@ static void do_interrupt_user(CPUX86State *env, int intno, int is_int,
         cpl = env->hflags & HF_CPL_MASK;
         /* check privilege if software int */
         if (dpl < cpl) {
-            raise_exception_err(env, EXCP0D_GPF, (intno << shift) + 2);
+            raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
         }
     }
 

base-commit: 825b96dbcee23d134b691fc75618b59c5f53da32

#3 lore raw

Trying some other x86 maintainers this time...

~Andrew

Quoted 45 lines · Andrew Cooper

Ping again?

~Andrew

Quoted 40 lines · Andrew Cooper

Ping?

Quoted 37 lines · Andrew Cooper

While the (intno << shift) expression is correct for indexing the IDT based on whether Long Mode is active, the error code itself was unchanged with AMD64, and is still the index with 3 bits of metadata in the bottom.

Found when running a Xen unit test, all under QEMU. The unit test objected to being told there was an error with IDT index 256 when INT $0x80 (128) was the problem instruction:

...
Error: Unexpected fault 0x800d0802, #GP[IDT[256]]
...

Fixes d2fd1af76777 ("x86_64 linux user emulation")

---
CC: Paolo Bonzini <[email protected]>
CC: Richard Henderson <[email protected]>
CC: Eduardo Habkost <[email protected]>

---
 target/i386/tcg/user/seg_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/user/seg_helper.c +1 -1
index c45f2ac2ba68..ff328b2a9522 100644
@@ -64,7 +64,7 @@ static void do_interrupt_user(CPUX86State *env, int intno, int is_int,
         cpl = env->hflags & HF_CPL_MASK;
         /* check privilege if software int */
         if (dpl < cpl) {
-            raise_exception_err(env, EXCP0D_GPF, (intno << shift) + 2);
+            raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
         }
     }
 

base-commit: 825b96dbcee23d134b691fc75618b59c5f53da32

#4 lore raw
In reply to Andrew Cooper
Quoted 3 lines

While the (intno << shift) expression is correct for indexing the IDT based on whether Long Mode is active, the error code itself was unchanged with AMD64, and is still the index with 3 bits of metadata in the bottom.

Queued, thanks. I'm really sorry about the delay.

Paolo

#5 lore raw
Quoted 4 lines · Paolo Bonzini
Quoted 3 lines

While the (intno << shift) expression is correct for indexing the IDT based on whether Long Mode is active, the error code itself was unchanged with AMD64, and is still the index with 3 bits of metadata in the bottom.

Queued, thanks. I'm really sorry about the delay.

No worries.  Thanks.

~Andrew