[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 2/8] target/i386: allow modifying TCG phys-addr-bits
From: |
Paolo Bonzini |
Subject: |
[PULL 2/8] target/i386: allow modifying TCG phys-addr-bits |
Date: |
Fri, 19 Mar 2021 10:39:18 -0400 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/cpu.c | 23 ++++++++---------------
target/i386/cpu.h | 1 -
target/i386/tcg/excp_helper.c | 7 ++++---
target/i386/tcg/helper-tcg.h | 12 ++++--------
4 files changed, 16 insertions(+), 27 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ae9fd9f31d..6b3e9467f1 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6785,21 +6785,14 @@ static void x86_cpu_realizefn(DeviceState *dev, Error
**errp)
cpu->phys_bits = cpu->host_phys_bits_limit;
}
}
-
- if (cpu->phys_bits &&
- (cpu->phys_bits > TARGET_PHYS_ADDR_SPACE_BITS ||
- cpu->phys_bits < 32)) {
- error_setg(errp, "phys-bits should be between 32 and %u "
- " (but is %u)",
- TARGET_PHYS_ADDR_SPACE_BITS, cpu->phys_bits);
- return;
- }
- } else {
- if (cpu->phys_bits && cpu->phys_bits != TCG_PHYS_ADDR_BITS) {
- error_setg(errp, "TCG only supports phys-bits=%u",
- TCG_PHYS_ADDR_BITS);
- return;
- }
+ }
+ if (cpu->phys_bits &&
+ (cpu->phys_bits > TARGET_PHYS_ADDR_SPACE_BITS ||
+ cpu->phys_bits < 32)) {
+ error_setg(errp, "phys-bits should be between 32 and %u "
+ " (but is %u)",
+ TARGET_PHYS_ADDR_SPACE_BITS, cpu->phys_bits);
+ return;
}
/* 0 means it was not explicitly set by the user (or by machine
* compat_props or by the host code above). In this case, the default
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index b4b136cd0d..570f916878 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -290,7 +290,6 @@ typedef enum X86Seg {
#define PG_GLOBAL_MASK (1 << PG_GLOBAL_BIT)
#define PG_PSE_PAT_MASK (1 << PG_PSE_PAT_BIT)
#define PG_ADDRESS_MASK 0x000ffffffffff000LL
-#define PG_HI_RSVD_MASK (PG_ADDRESS_MASK & ~PHYS_ADDR_MASK)
#define PG_HI_USER_MASK 0x7ff0000000000000LL
#define PG_PKRU_MASK (15ULL << PG_PKRU_BIT)
#define PG_NX_MASK (1ULL << PG_NX_BIT)
diff --git a/target/i386/tcg/excp_helper.c b/target/i386/tcg/excp_helper.c
index b7d6259e4a..1e71e44510 100644
--- a/target/i386/tcg/excp_helper.c
+++ b/target/i386/tcg/excp_helper.c
@@ -142,8 +142,9 @@ void raise_exception_ra(CPUX86State *env, int
exception_index, uintptr_t retaddr
static hwaddr get_hphys(CPUState *cs, hwaddr gphys, MMUAccessType access_type,
int *prot)
{
- CPUX86State *env = &X86_CPU(cs)->env;
- uint64_t rsvd_mask = PG_HI_RSVD_MASK;
+ X86CPU *cpu = X86_CPU(cs);
+ CPUX86State *env = &cpu->env;
+ uint64_t rsvd_mask = PG_ADDRESS_MASK & ~MAKE_64BIT_MASK(0, cpu->phys_bits);
uint64_t ptep, pte;
uint64_t exit_info_1 = 0;
target_ulong pde_addr, pte_addr;
@@ -358,7 +359,7 @@ static int handle_mmu_fault(CPUState *cs, vaddr addr, int
size,
int error_code = 0;
int is_dirty, prot, page_size, is_write, is_user;
hwaddr paddr;
- uint64_t rsvd_mask = PG_HI_RSVD_MASK;
+ uint64_t rsvd_mask = PG_ADDRESS_MASK & ~MAKE_64BIT_MASK(0, cpu->phys_bits);
uint32_t page_offset;
target_ulong vaddr;
uint32_t pkr;
diff --git a/target/i386/tcg/helper-tcg.h b/target/i386/tcg/helper-tcg.h
index c133c63555..ef60e2e04b 100644
--- a/target/i386/tcg/helper-tcg.h
+++ b/target/i386/tcg/helper-tcg.h
@@ -25,17 +25,13 @@
/* Maximum instruction code size */
#define TARGET_MAX_INSN_SIZE 16
-/*
- * XXX: This value should match the one returned by CPUID
- * and in exec.c
- */
-# if defined(TARGET_X86_64)
+#if defined(TARGET_X86_64)
# define TCG_PHYS_ADDR_BITS 40
-# else
+#else
# define TCG_PHYS_ADDR_BITS 36
-# endif
+#endif
-#define PHYS_ADDR_MASK MAKE_64BIT_MASK(0, TCG_PHYS_ADDR_BITS)
+QEMU_BUILD_BUG_ON(TCG_PHYS_ADDR_BITS > TARGET_PHYS_ADDR_SPACE_BITS);
/**
* x86_cpu_do_interrupt:
--
2.26.2
- [PULL 0/8] Misc bugfixes for QEMU soft freeze, Paolo Bonzini, 2021/03/19
- [PULL 1/8] qom: use qemu_printf to print help for user-creatable objects, Paolo Bonzini, 2021/03/19
- [PULL 3/8] target/i386: fail if toggling LA57 in 64-bit mode, Paolo Bonzini, 2021/03/19
- [PULL 2/8] target/i386: allow modifying TCG phys-addr-bits,
Paolo Bonzini <=
- [PULL 8/8] tests/qtest: cleanup the testcase for bug 1878642, Paolo Bonzini, 2021/03/19
- [PULL 6/8] i386: Make migration fail when Hyper-V reenlightenment was enabled but 'user_tsc_khz' is unset, Paolo Bonzini, 2021/03/19
- [PULL 7/8] hw/intc/i8259: Refactor pic_read_irq() to avoid uninitialized variable, Paolo Bonzini, 2021/03/19
- [PULL 4/8] target/i386: svm: do not discard high 32 bits of EXITINFO1, Paolo Bonzini, 2021/03/19
- [PULL 5/8] i386: Fix 'hypercall_hypercall' typo, Paolo Bonzini, 2021/03/19
- Re: [PULL 0/8] Misc bugfixes for QEMU soft freeze, no-reply, 2021/03/19
- Re: [PULL 0/8] Misc bugfixes for QEMU soft freeze, Peter Maydell, 2021/03/20
- Re: [PULL 0/8] Misc bugfixes for QEMU soft freeze, Thomas Huth, 2021/03/22