* [PATCH 0/5] target/hppa: Clean up conversion from/to MMU index and priviledge level
@ 2023-08-24 21:04 deller
2023-08-24 21:04 ` [PATCH 1/5] target/hppa: Add missing PL1 and PL2 priviledge levels deller
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: deller @ 2023-08-24 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson, Helge Deller
From: Helge Deller <deller@gmx.de>
Make the conversion between priviledge level and QEMU MMU index
consitent, and afterwards switch to MMU indices 11-15.
Signed-off-by: Helge Deller <deller@gmx.de>
Helge Deller (5):
target/hppa: Add missing PL1 and PL2 priviledge levels
target/hppa: Add priviledge to MMU index conversion helpers
target/hppa: Do not use hardcoded value for tlb_flush_*()
target/hppa: Use privilege helper in hppa_get_physical_address()
target/hppa: Switch to use MMU indices 11-15
target/hppa/cpu.h | 19 +++++++++++++++----
target/hppa/helper.c | 2 +-
target/hppa/mem_helper.c | 16 ++++++++--------
target/hppa/translate.c | 9 +++++----
4 files changed, 29 insertions(+), 17 deletions(-)
--
2.41.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/5] target/hppa: Add missing PL1 and PL2 priviledge levels
2023-08-24 21:04 [PATCH 0/5] target/hppa: Clean up conversion from/to MMU index and priviledge level deller
@ 2023-08-24 21:04 ` deller
2023-08-25 7:11 ` Philippe Mathieu-Daudé
2023-08-24 21:04 ` [PATCH 2/5] target/hppa: Add priviledge to MMU index conversion helpers deller
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: deller @ 2023-08-24 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson, Helge Deller
From: Helge Deller <deller@gmx.de>
The hppa CPU has 4 priviledge levels (0-3).
Mention the missing PL1 and PL2 levels, although the Linux kernel
uses only 0 (KERNEL) and 3 (USER). Not sure about HP-UX.
Signed-off-by: Helge Deller <deller@gmx.de>
---
target/hppa/cpu.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h
index 75c5c0ccf7..6c5b0e67c8 100644
--- a/target/hppa/cpu.h
+++ b/target/hppa/cpu.h
@@ -31,8 +31,11 @@
#define TCG_GUEST_DEFAULT_MO TCG_MO_ALL
#define MMU_KERNEL_IDX 0
+#define MMU_PL1_IDX 1
+#define MMU_PL2_IDX 2
#define MMU_USER_IDX 3
#define MMU_PHYS_IDX 4
+
#define TARGET_INSN_START_EXTRA_WORDS 1
/* Hardware exceptions, interrupts, faults, and traps. */
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/5] target/hppa: Add priviledge to MMU index conversion helpers
2023-08-24 21:04 [PATCH 0/5] target/hppa: Clean up conversion from/to MMU index and priviledge level deller
2023-08-24 21:04 ` [PATCH 1/5] target/hppa: Add missing PL1 and PL2 priviledge levels deller
@ 2023-08-24 21:04 ` deller
2023-08-25 7:09 ` Philippe Mathieu-Daudé
2023-08-24 21:04 ` [PATCH 3/5] target/hppa: Do not use hardcoded value for tlb_flush_*() deller
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: deller @ 2023-08-24 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson, Helge Deller
From: Helge Deller <deller@gmx.de>
Add two macros which convert priviledge level to/from MMU index:
- PRIV_TO_MMU_IDX(priv)
returns the MMU index for the given priviledge level
- MMU_IDX_TO_PRIV(mmu_idx)
returns the corresponding priviledge level for this MMU index
The introduction of those macros make the code easier to read and
will help to improve performance in follow-up patch.
Signed-off-by: Helge Deller <deller@gmx.de>
---
target/hppa/cpu.h | 5 ++++-
target/hppa/translate.c | 9 +++++----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h
index 6c5b0e67c8..50b513f0ea 100644
--- a/target/hppa/cpu.h
+++ b/target/hppa/cpu.h
@@ -36,6 +36,9 @@
#define MMU_USER_IDX 3
#define MMU_PHYS_IDX 4
+#define PRIV_TO_MMU_IDX(priv) (priv)
+#define MMU_IDX_TO_PRIV(mmu_idx) (mmu_idx)
+
#define TARGET_INSN_START_EXTRA_WORDS 1
/* Hardware exceptions, interrupts, faults, and traps. */
@@ -236,7 +239,7 @@ static inline int cpu_mmu_index(CPUHPPAState *env, bool ifetch)
return MMU_USER_IDX;
#else
if (env->psw & (ifetch ? PSW_C : PSW_D)) {
- return env->iaoq_f & 3;
+ return PRIV_TO_MMU_IDX(env->iaoq_f & 3);
}
return MMU_PHYS_IDX; /* mmu disabled */
#endif
diff --git a/target/hppa/translate.c b/target/hppa/translate.c
index d66fcb3e6a..e3af668252 100644
--- a/target/hppa/translate.c
+++ b/target/hppa/translate.c
@@ -4057,14 +4057,15 @@ static void hppa_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
ctx->tb_flags = ctx->base.tb->flags;
#ifdef CONFIG_USER_ONLY
- ctx->privilege = MMU_USER_IDX;
+ ctx->privilege = MMU_IDX_TO_PRIV(MMU_USER_IDX);
ctx->mmu_idx = MMU_USER_IDX;
- ctx->iaoq_f = ctx->base.pc_first | MMU_USER_IDX;
- ctx->iaoq_b = ctx->base.tb->cs_base | MMU_USER_IDX;
+ ctx->iaoq_f = ctx->base.pc_first | ctx->privilege;
+ ctx->iaoq_b = ctx->base.tb->cs_base | ctx->privilege;
ctx->unalign = (ctx->tb_flags & TB_FLAG_UNALIGN ? MO_UNALN : MO_ALIGN);
#else
ctx->privilege = (ctx->tb_flags >> TB_FLAG_PRIV_SHIFT) & 3;
- ctx->mmu_idx = (ctx->tb_flags & PSW_D ? ctx->privilege : MMU_PHYS_IDX);
+ ctx->mmu_idx = (ctx->tb_flags & PSW_D ?
+ PRIV_TO_MMU_IDX(ctx->privilege) : MMU_PHYS_IDX);
/* Recover the IAOQ values from the GVA + PRIV. */
uint64_t cs_base = ctx->base.tb->cs_base;
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/5] target/hppa: Do not use hardcoded value for tlb_flush_*()
2023-08-24 21:04 [PATCH 0/5] target/hppa: Clean up conversion from/to MMU index and priviledge level deller
2023-08-24 21:04 ` [PATCH 1/5] target/hppa: Add missing PL1 and PL2 priviledge levels deller
2023-08-24 21:04 ` [PATCH 2/5] target/hppa: Add priviledge to MMU index conversion helpers deller
@ 2023-08-24 21:04 ` deller
2023-08-25 7:14 ` Philippe Mathieu-Daudé
2023-08-24 21:04 ` [PATCH 4/5] target/hppa: Use privilege helper in hppa_get_physical_address() deller
2023-08-24 21:04 ` [PATCH 5/5] target/hppa: Switch to use MMU indices 11-15 deller
4 siblings, 1 reply; 10+ messages in thread
From: deller @ 2023-08-24 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson, Helge Deller
From: Helge Deller <deller@gmx.de>
Avoid using hardcoded values when calling the tlb_flush*() functions.
Instead define the correct mask (HPPA_MMU_FLUSH_MASK) and use it.
Skip flushing the MMU for physical addresses.
Signed-off-by: Helge Deller <deller@gmx.de>
---
target/hppa/cpu.h | 5 +++++
target/hppa/helper.c | 2 +-
target/hppa/mem_helper.c | 7 +++----
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h
index 50b513f0ea..6623712644 100644
--- a/target/hppa/cpu.h
+++ b/target/hppa/cpu.h
@@ -41,6 +41,11 @@
#define TARGET_INSN_START_EXTRA_WORDS 1
+/* No need to flush MMU_PHYS_IDX */
+#define HPPA_MMU_FLUSH_MASK \
+ (1 << MMU_KERNEL_IDX | 1 << MMU_PL1_IDX | \
+ 1 << MMU_PL2_IDX | 1 << MMU_USER_IDX)
+
/* Hardware exceptions, interrupts, faults, and traps. */
#define EXCP_HPMC 1 /* high priority machine check */
#define EXCP_POWER_FAIL 2
diff --git a/target/hppa/helper.c b/target/hppa/helper.c
index 74b8747083..a8d3f456ee 100644
--- a/target/hppa/helper.c
+++ b/target/hppa/helper.c
@@ -71,7 +71,7 @@ void cpu_hppa_put_psw(CPUHPPAState *env, target_ureg psw)
/* If PSW_P changes, it affects how we translate addresses. */
if ((psw ^ old_psw) & PSW_P) {
#ifndef CONFIG_USER_ONLY
- tlb_flush_by_mmuidx(env_cpu(env), 0xf);
+ tlb_flush_by_mmuidx(env_cpu(env), HPPA_MMU_FLUSH_MASK);
#endif
}
}
diff --git a/target/hppa/mem_helper.c b/target/hppa/mem_helper.c
index 5046cc8f9d..6f04c101dd 100644
--- a/target/hppa/mem_helper.c
+++ b/target/hppa/mem_helper.c
@@ -50,8 +50,7 @@ static void hppa_flush_tlb_ent(CPUHPPAState *env, hppa_tlb_entry *ent)
trace_hppa_tlb_flush_ent(env, ent, ent->va_b, ent->va_e, ent->pa);
for (i = 0; i < n; ++i, addr += TARGET_PAGE_SIZE) {
- /* Do not flush MMU_PHYS_IDX. */
- tlb_flush_page_by_mmuidx(cs, addr, 0xf);
+ tlb_flush_page_by_mmuidx(cs, addr, HPPA_MMU_FLUSH_MASK);
}
memset(ent, 0, sizeof(*ent));
@@ -335,13 +334,13 @@ void HELPER(ptlbe)(CPUHPPAState *env)
{
trace_hppa_tlb_ptlbe(env);
memset(env->tlb, 0, sizeof(env->tlb));
- tlb_flush_by_mmuidx(env_cpu(env), 0xf);
+ tlb_flush_by_mmuidx(env_cpu(env), HPPA_MMU_FLUSH_MASK);
}
void cpu_hppa_change_prot_id(CPUHPPAState *env)
{
if (env->psw & PSW_P) {
- tlb_flush_by_mmuidx(env_cpu(env), 0xf);
+ tlb_flush_by_mmuidx(env_cpu(env), HPPA_MMU_FLUSH_MASK);
}
}
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/5] target/hppa: Use privilege helper in hppa_get_physical_address()
2023-08-24 21:04 [PATCH 0/5] target/hppa: Clean up conversion from/to MMU index and priviledge level deller
` (2 preceding siblings ...)
2023-08-24 21:04 ` [PATCH 3/5] target/hppa: Do not use hardcoded value for tlb_flush_*() deller
@ 2023-08-24 21:04 ` deller
2023-08-25 7:15 ` Philippe Mathieu-Daudé
2023-08-24 21:04 ` [PATCH 5/5] target/hppa: Switch to use MMU indices 11-15 deller
4 siblings, 1 reply; 10+ messages in thread
From: deller @ 2023-08-24 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson, Helge Deller
From: Helge Deller <deller@gmx.de>
Convert hppa_get_physical_address() to use the privilege helper macro.
Signed-off-by: Helge Deller <deller@gmx.de>
---
target/hppa/mem_helper.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/target/hppa/mem_helper.c b/target/hppa/mem_helper.c
index 6f04c101dd..66cf84a0d9 100644
--- a/target/hppa/mem_helper.c
+++ b/target/hppa/mem_helper.c
@@ -73,7 +73,7 @@ int hppa_get_physical_address(CPUHPPAState *env, vaddr addr, int mmu_idx,
int type, hwaddr *pphys, int *pprot)
{
hwaddr phys;
- int prot, r_prot, w_prot, x_prot;
+ int prot, r_prot, w_prot, x_prot, mmu_priv;
hppa_tlb_entry *ent;
int ret = -1;
@@ -97,9 +97,10 @@ int hppa_get_physical_address(CPUHPPAState *env, vaddr addr, int mmu_idx,
phys = ent->pa + (addr & ~TARGET_PAGE_MASK);
/* Map TLB access_rights field to QEMU protection. */
- r_prot = (mmu_idx <= ent->ar_pl1) * PAGE_READ;
- w_prot = (mmu_idx <= ent->ar_pl2) * PAGE_WRITE;
- x_prot = (ent->ar_pl2 <= mmu_idx && mmu_idx <= ent->ar_pl1) * PAGE_EXEC;
+ mmu_priv = MMU_IDX_TO_PRIV(mmu_idx);
+ r_prot = (mmu_priv <= ent->ar_pl1) * PAGE_READ;
+ w_prot = (mmu_priv <= ent->ar_pl2) * PAGE_WRITE;
+ x_prot = (ent->ar_pl2 <= mmu_priv && mmu_priv <= ent->ar_pl1) * PAGE_EXEC;
switch (ent->ar_type) {
case 0: /* read-only: data page */
prot = r_prot;
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/5] target/hppa: Switch to use MMU indices 11-15
2023-08-24 21:04 [PATCH 0/5] target/hppa: Clean up conversion from/to MMU index and priviledge level deller
` (3 preceding siblings ...)
2023-08-24 21:04 ` [PATCH 4/5] target/hppa: Use privilege helper in hppa_get_physical_address() deller
@ 2023-08-24 21:04 ` deller
4 siblings, 0 replies; 10+ messages in thread
From: deller @ 2023-08-24 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson, Helge Deller
From: Helge Deller <deller@gmx.de>
The MMU indices 9-15 will use shorter assembler instructions
when run on a x86-64 host. So, switch over to those to get
smaller code and maybe minimally faster emulation.
Signed-off-by: Helge Deller <deller@gmx.de>
---
target/hppa/cpu.h | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h
index 6623712644..fa13694dab 100644
--- a/target/hppa/cpu.h
+++ b/target/hppa/cpu.h
@@ -30,14 +30,14 @@
basis. It's probably easier to fall back to a strong memory model. */
#define TCG_GUEST_DEFAULT_MO TCG_MO_ALL
-#define MMU_KERNEL_IDX 0
-#define MMU_PL1_IDX 1
-#define MMU_PL2_IDX 2
-#define MMU_USER_IDX 3
-#define MMU_PHYS_IDX 4
-
-#define PRIV_TO_MMU_IDX(priv) (priv)
-#define MMU_IDX_TO_PRIV(mmu_idx) (mmu_idx)
+#define MMU_KERNEL_IDX 11
+#define MMU_PL1_IDX 12
+#define MMU_PL2_IDX 13
+#define MMU_USER_IDX 14
+#define MMU_PHYS_IDX 15
+
+#define PRIV_TO_MMU_IDX(priv) (MMU_KERNEL_IDX + (priv))
+#define MMU_IDX_TO_PRIV(mmu_idx) ((mmu_idx) - MMU_KERNEL_IDX)
#define TARGET_INSN_START_EXTRA_WORDS 1
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/5] target/hppa: Add priviledge to MMU index conversion helpers
2023-08-24 21:04 ` [PATCH 2/5] target/hppa: Add priviledge to MMU index conversion helpers deller
@ 2023-08-25 7:09 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-08-25 7:09 UTC (permalink / raw)
To: deller, qemu-devel; +Cc: Richard Henderson, Helge Deller
On 24/8/23 23:04, deller@kernel.org wrote:
> From: Helge Deller <deller@gmx.de>
>
> Add two macros which convert priviledge level to/from MMU index:
>
> - PRIV_TO_MMU_IDX(priv)
> returns the MMU index for the given priviledge level
>
> - MMU_IDX_TO_PRIV(mmu_idx)
> returns the corresponding priviledge level for this MMU index
>
> The introduction of those macros make the code easier to read and
> will help to improve performance in follow-up patch.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
> target/hppa/cpu.h | 5 ++++-
> target/hppa/translate.c | 9 +++++----
> 2 files changed, 9 insertions(+), 5 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/5] target/hppa: Add missing PL1 and PL2 priviledge levels
2023-08-24 21:04 ` [PATCH 1/5] target/hppa: Add missing PL1 and PL2 priviledge levels deller
@ 2023-08-25 7:11 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-08-25 7:11 UTC (permalink / raw)
To: deller, qemu-devel; +Cc: Richard Henderson, Helge Deller
On 24/8/23 23:04, deller@kernel.org wrote:
> From: Helge Deller <deller@gmx.de>
>
> The hppa CPU has 4 priviledge levels (0-3).
> Mention the missing PL1 and PL2 levels, although the Linux kernel
> uses only 0 (KERNEL) and 3 (USER). Not sure about HP-UX.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
> target/hppa/cpu.h | 3 +++
> 1 file changed, 3 insertions(+)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/5] target/hppa: Do not use hardcoded value for tlb_flush_*()
2023-08-24 21:04 ` [PATCH 3/5] target/hppa: Do not use hardcoded value for tlb_flush_*() deller
@ 2023-08-25 7:14 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-08-25 7:14 UTC (permalink / raw)
To: deller, qemu-devel; +Cc: Richard Henderson, Helge Deller
On 24/8/23 23:04, deller@kernel.org wrote:
> From: Helge Deller <deller@gmx.de>
>
> Avoid using hardcoded values when calling the tlb_flush*() functions.
> Instead define the correct mask (HPPA_MMU_FLUSH_MASK) and use it.
> Skip flushing the MMU for physical addresses.
Alternatively:
Instead, define and use HPPA_MMU_FLUSH_MASK (keeping the current
behavior, which doesn't flush the physical address MMU).
>
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
> target/hppa/cpu.h | 5 +++++
> target/hppa/helper.c | 2 +-
> target/hppa/mem_helper.c | 7 +++----
> 3 files changed, 9 insertions(+), 5 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 4/5] target/hppa: Use privilege helper in hppa_get_physical_address()
2023-08-24 21:04 ` [PATCH 4/5] target/hppa: Use privilege helper in hppa_get_physical_address() deller
@ 2023-08-25 7:15 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-08-25 7:15 UTC (permalink / raw)
To: deller, qemu-devel; +Cc: Richard Henderson, Helge Deller
On 24/8/23 23:04, deller@kernel.org wrote:
> From: Helge Deller <deller@gmx.de>
>
> Convert hppa_get_physical_address() to use the privilege helper macro.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
> target/hppa/mem_helper.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-08-25 7:15 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-24 21:04 [PATCH 0/5] target/hppa: Clean up conversion from/to MMU index and priviledge level deller
2023-08-24 21:04 ` [PATCH 1/5] target/hppa: Add missing PL1 and PL2 priviledge levels deller
2023-08-25 7:11 ` Philippe Mathieu-Daudé
2023-08-24 21:04 ` [PATCH 2/5] target/hppa: Add priviledge to MMU index conversion helpers deller
2023-08-25 7:09 ` Philippe Mathieu-Daudé
2023-08-24 21:04 ` [PATCH 3/5] target/hppa: Do not use hardcoded value for tlb_flush_*() deller
2023-08-25 7:14 ` Philippe Mathieu-Daudé
2023-08-24 21:04 ` [PATCH 4/5] target/hppa: Use privilege helper in hppa_get_physical_address() deller
2023-08-25 7:15 ` Philippe Mathieu-Daudé
2023-08-24 21:04 ` [PATCH 5/5] target/hppa: Switch to use MMU indices 11-15 deller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).