All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Sampanis <nicksampanis@gmail.com>
To: qemu-devel@nongnu.org
Cc: Nick Sampanis <Nicksampanis@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	qemu-stable@nongnu.org
Subject: [PATCH] target/i386/tcg: fix SVM intercept for MOV from CRn
Date: Sat,  5 Dec 2026 16:50:18 +0200	[thread overview]
Message-ID: <20261205145019.1385-1-Nicksampanis@gmail.com> (raw)

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



                 reply	other threads:[~2026-12-05 14:51 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=20261205145019.1385-1-Nicksampanis@gmail.com \
    --to=nicksampanis@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=richard.henderson@linaro.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.