All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tim <mdspan.github@gmail.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, richard.henderson@linaro.org,
	zhao1.liu@intel.com, Tim <mdspan.github@gmail.com>
Subject: [PATCH v2 3/5] target/i386: use separate MMU indexes for instruction fetch
Date: Fri, 20 Nov 2026 10:44:29 +0000	[thread overview]
Message-ID: <20261120104431.733136-4-mdspan.github@gmail.com> (raw)
In-Reply-To: <20261120104431.733136-1-mdspan.github@gmail.com>

x86_cpu_mmu_index() ignores ifetch, so instruction fetches and data
accesses at the same privilege level share a TLB.  Add user and
supervisor fetch indexes, each in 64-bit and 32-bit forms, and return
them for fetches.  Supervisor fetches need no SMAP variant, since SMAP
does not apply to instruction fetches.

This lets the fetch and data translations of a linear address differ,
which LAM needs.

Signed-off-by: Tim <mdspan.github@gmail.com>
---
v2: new patch, as suggested in review of v1.

 target/i386/cpu.h         | 11 ++++++++---
 target/i386/tcg/tcg-cpu.c |  9 ++++++++-
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 3945e903..5bc19d5e 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2838,8 +2838,12 @@ uint64_t cpu_get_tsc(CPUX86State *env);
 #define MMU_USER32_IDX     3
 #define MMU_KNOSMAP64_IDX  4
 #define MMU_KNOSMAP32_IDX  5
-#define MMU_PHYS_IDX       6
-#define MMU_NESTED_IDX     7
+#define MMU_KFETCH64_IDX   6
+#define MMU_KFETCH32_IDX   7
+#define MMU_UFETCH64_IDX   8
+#define MMU_UFETCH32_IDX   9
+#define MMU_PHYS_IDX       10
+#define MMU_NESTED_IDX     11
 
 #ifdef CONFIG_USER_ONLY
 #ifdef TARGET_X86_64
@@ -2856,7 +2860,8 @@ static inline bool is_mmu_index_smap(int mmu_index)
 
 static inline bool is_mmu_index_user(int mmu_index)
 {
-    return (mmu_index & ~1) == MMU_USER64_IDX;
+    return (mmu_index & ~1) == MMU_USER64_IDX ||
+           (mmu_index & ~1) == MMU_UFETCH64_IDX;
 }
 
 static inline bool is_mmu_index_32(int mmu_index)
diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c
index 167ff769..b8f20f20 100644
--- a/target/i386/tcg/tcg-cpu.c
+++ b/target/i386/tcg/tcg-cpu.c
@@ -130,7 +130,14 @@ int x86_mmu_index_pl(CPUX86State *env, unsigned pl)
 static int x86_cpu_mmu_index(CPUState *cs, bool ifetch)
 {
     CPUX86State *env = cpu_env(cs);
-    return x86_mmu_index_pl(env, env->hflags & HF_CPL_MASK);
+    unsigned pl = env->hflags & HF_CPL_MASK;
+
+    if (ifetch) {
+        int mmu_index_32 = (env->hflags & HF_CS64_MASK) ? 0 : 1;
+
+        return (pl == 3 ? MMU_UFETCH64_IDX : MMU_KFETCH64_IDX) + mmu_index_32;
+    }
+    return x86_mmu_index_pl(env, pl);
 }
 
 #ifndef CONFIG_USER_ONLY
-- 
2.47.3



  parent reply	other threads:[~2026-11-20 10:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 10:44 [PATCH v2 0/5] target/i386: emulate LAM in TCG Tim
2026-11-20 10:44 ` [PATCH v2 1/5] target/i386: mask the PML5 table address taken from CR3 Tim
2026-11-20 10:44 ` [PATCH v2 2/5] accel/tcg: compare large pages under the flush mask Tim
2026-11-20 10:44 ` Tim [this message]
2026-11-20 18:31   ` [PATCH v2 3/5] target/i386: use separate MMU indexes for instruction fetch Richard Henderson
2026-11-20 10:44 ` [PATCH v2 4/5] target/i386: emulate LAM in TCG Tim
2026-11-20 10:44 ` [PATCH v2 5/5] tests/tcg/x86_64: add a LAM system test Tim

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=20261120104431.733136-4-mdspan.github@gmail.com \
    --to=mdspan.github@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=zhao1.liu@intel.com \
    /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.