All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] target/i386/tcg: fix SVM intercept for MOV from CRn
@ 2026-12-05 14:50 Nick Sampanis
  0 siblings, 0 replies; only message in thread
From: Nick Sampanis @ 2026-12-05 14:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Nick Sampanis, Paolo Bonzini, Richard Henderson, qemu-stable

In decode_op(), the X86_TYPE_C case only adds the control register
index (op->n) to the intercept code when the base intercept value is
non-zero. Because the 0F 20 entry in opcodes_0F uses the svm() macro
with SVM_EXIT_READ_CR0 (0), that addition is skipped for CRn reads.

As a result, every MOV from CRn checks the CR0 read intercept and, on
exit, reports exit code 0 instead of the CRn read exit code. Without
NPT, a hypervisor that intercepts CR3 reads gets no exit, so the guest
reads the shadow page-table root instead of its own CR3. This was
noticed while testing a nested hypervisor.

Check has_intercept instead of the intercept value. The corresponding
X86_TYPE_D change for debug registers does not alter behaviour because
both DR base exit codes are non-zero, and is included for consistency.

Fixes: a1af7fba5a00 ("target/i386: convert MOV from/to CR and DR to new decoder")
Signed-off-by: Nick Sampanis <Nicksampanis@gmail.com>
---
 target/i386/tcg/decode-new.c.inc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.c.inc
index a10641995e..b063ec5a38 100644
--- a/target/i386/tcg/decode-new.c.inc
+++ b/target/i386/tcg/decode-new.c.inc
@@ -2565,7 +2565,7 @@ static bool decode_op(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode,
         if (op->n != 0 && op->n != 2 && op->n != 3 && op->n != 4 && op->n != 8) {
             return false;
         }
-        if (decode->e.intercept) {
+        if (decode->e.has_intercept) {
             decode->e.intercept += op->n;
         }
         break;
@@ -2580,7 +2580,7 @@ static bool decode_op(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode,
              */
             return false;
         }
-        if (decode->e.intercept) {
+        if (decode->e.has_intercept) {
             decode->e.intercept += op->n;
         }
         break;
-- 
2.51.0.windows.2



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05 14:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 14:50 [PATCH] target/i386/tcg: fix SVM intercept for MOV from CRn Nick Sampanis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.