diff mbox series

[2/2] arm/ptw: respect sctlr.{u}wxn in get_phys_addr_v6

Message ID 20241114165953.6894-1-paskripkin@gmail.com (mailing list archive)
State New
Headers show
Series [1/2] arm/ptw: factor out wxn logic to separate functions | expand

Commit Message

Pavel Skripkin Nov. 14, 2024, 4:59 p.m. UTC
get_phys_addr_v6() is used for decoding armv7's short descriptor format.
Based on ARM ARM AArch32.S1SDHasPermissionsFault(), WXN should be
respected in !LPAE mode as well.

Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 target/arm/ptw.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/target/arm/ptw.c b/target/arm/ptw.c
index 2a3933adec..892932620e 100644
--- a/target/arm/ptw.c
+++ b/target/arm/ptw.c
@@ -1169,6 +1169,8 @@  static bool get_phys_addr_v6(CPUARMState *env, S1Translate *ptw,
     uint32_t dacr;
     bool ns;
     int user_prot;
+    int wxn = arm_wxn_enabled(env, mmu_idx);
+    int uwxn = arm_uwxn_enabled(env, mmu_idx);
 
     /* Pagetable walk.  */
     /* Lookup l1 descriptor.  */
@@ -1288,6 +1290,15 @@  static bool get_phys_addr_v6(CPUARMState *env, S1Translate *ptw,
         if (result->f.prot && !xn) {
             result->f.prot |= PAGE_EXEC;
         }
+
+        if (result->f.prot & PAGE_WRITE) {
+            /* WXN works for PL1&0, while UWXN only for PL0. */
+            if (wxn)
+                result->f.prot &= ~PAGE_EXEC;
+            if (uwxn && regime_is_user(env, mmu_idx))
+                result->f.prot &= ~PAGE_EXEC;
+        }
+
         if (!(result->f.prot & (1 << access_type))) {
             /* Access permission fault.  */
             fi->type = ARMFault_Permission;