From: Richard Henderson <richard.henderson@linaro.org>
To: Tim <mdspan.github@gmail.com>, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, zhao1.liu@intel.com
Subject: Re: [PATCH v2 3/5] target/i386: use separate MMU indexes for instruction fetch
Date: Fri, 20 Nov 2026 10:31:39 -0800 [thread overview]
Message-ID: <e4159fa3-e122-43f7-8ce3-e108ce8dcbf9@linaro.org> (raw)
In-Reply-To: <20261120104431.733136-4-mdspan.github@gmail.com>
On 11/20/26 02:44, Tim wrote:
> 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);
> }
Instead of "normal" vs "fetch", I suggest "normal" vs "masked".
This way, if no mask is enabled, only one mmu_idx is used and fewer page
table walks are required.
Thus ifetch would always be "normal".
r~
r~
next prev parent reply other threads:[~2026-11-20 18:32 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 ` [PATCH v2 3/5] target/i386: use separate MMU indexes for instruction fetch Tim
2026-11-20 18:31 ` Richard Henderson [this message]
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=e4159fa3-e122-43f7-8ce3-e108ce8dcbf9@linaro.org \
--to=richard.henderson@linaro.org \
--cc=mdspan.github@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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.