Skip to contentSkip to conversation

target/i386: emulate: MMU fixes

PATCH New Mohamed Mediouni 1 participant 3 messages Mar 24

lore
Share & tools
lore
#0 lore raw

cover target/i386: emulate: MMU fixes

Two small commits I had around...

Mohamed Mediouni (2):
target/i386: emulate: set PG_ERROR_W_MASK as expected target/i386: emulate: follow priv_check_exempt

 target/i386/emulate/x86_mmu.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

PATCH 1/2 target/i386: emulate: set PG_ERROR_W_MASK as expected

Make setting PG_ERROR_W_MASK no longer dependent on the access being a priv violation.

---
 target/i386/emulate/x86_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/emulate/x86_mmu.c +1 -1
index ba0ebe4268..1aa373f5b3 100644
@@ -248,7 +248,7 @@ static int translate_res_to_error_code(MMUTranslateResult res, bool is_write, bo
     if (!(res & MMU_TRANSLATE_PAGE_NOT_MAPPED)) {
         error_code |= PG_ERROR_P_MASK;
     }
-    if (is_write && (res & MMU_TRANSLATE_PRIV_VIOLATION)) {
+    if (is_write) {
         error_code |= PG_ERROR_W_MASK;
     }
     if (res & MMU_TRANSLATE_INVALID_PT_FLAGS) {
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw

PATCH 2/2 target/i386: emulate: follow priv_check_exempt

In reply to Mohamed Mediouni

Follow priv_check_exempt flag argument for
x86_write_mem_priv/x86_read_mem_priv.

---
 target/i386/emulate/x86_mmu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
target/i386/emulate/x86_mmu.c +12 -2
index 1aa373f5b3..c69ae96acb 100644
@@ -263,14 +263,19 @@ static MMUTranslateResult x86_write_mem_ex(CPUState *cpu, void *data, target_ulo
     CPUX86State *env = &x86_cpu->env;
 
     MMUTranslateResult translate_res = MMU_TRANSLATE_SUCCESS;
+    MMUTranslateFlags translate_flags = MMU_TRANSLATE_VALIDATE_WRITE;
     MemTxResult mem_tx_res;
     uint64_t gpa;
 
+    if (priv_check_exempt) {
+        translate_flags |= MMU_TRANSLATE_PRIV_CHECKS_EXEMPT;
+    }
+
     while (bytes > 0) {
         /* copy page */
         int copy = MIN(bytes, 0x1000 - (gva & 0xfff));
 
-        translate_res = mmu_gva_to_gpa(cpu, gva, &gpa, MMU_TRANSLATE_VALIDATE_WRITE);
+        translate_res = mmu_gva_to_gpa(cpu, gva, &gpa, translate_flags);
         if (translate_res) {
             int error_code = translate_res_to_error_code(translate_res, true, is_user(cpu));
             env->cr[2] = gva;
@@ -311,14 +316,19 @@ static MMUTranslateResult x86_read_mem_ex(CPUState *cpu, void *data, target_ulon
     CPUX86State *env = &x86_cpu->env;
 
     MMUTranslateResult translate_res = MMU_TRANSLATE_SUCCESS;
+    MMUTranslateFlags translate_flags = 0;
     MemTxResult mem_tx_res;
     uint64_t gpa;
 
+    if (priv_check_exempt) {
+        translate_flags |= MMU_TRANSLATE_PRIV_CHECKS_EXEMPT;
+    }
+
     while (bytes > 0) {
         /* copy page */
         int copy = MIN(bytes, 0x1000 - (gva & 0xfff));
 
-        translate_res = mmu_gva_to_gpa(cpu, gva, &gpa, 0);
+        translate_res = mmu_gva_to_gpa(cpu, gva, &gpa, translate_flags);
         if (translate_res) {
             int error_code = translate_res_to_error_code(translate_res, false, is_user(cpu));
             env->cr[2] = gva;
Signature · 1 line
2.50.1 (Apple Git-155)