qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 1/2] exec: Let memory_access_size() consider minimum valid ac


From: Philippe Mathieu-Daudé
Subject: [RFC PATCH 1/2] exec: Let memory_access_size() consider minimum valid access size
Date: Sun, 17 May 2020 13:38:03 +0200

As it is illegal to access a device with less that its
minimum valid size, also check for access_size_min.

Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
 exec.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/exec.c b/exec.c
index 5162f0d12f..d3ec30f995 100644
--- a/exec.c
+++ b/exec.c
@@ -3066,10 +3066,14 @@ void memory_region_flush_rom_device(MemoryRegion *mr, 
hwaddr addr, hwaddr size)
 
 static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
 {
+    unsigned access_size_min = mr->ops->valid.min_access_size;
     unsigned access_size_max = mr->ops->valid.max_access_size;
 
     /* Regions are assumed to support 1-4 byte accesses unless
        otherwise specified.  */
+    if (access_size_min == 0) {
+        access_size_min = 1;
+    }
     if (access_size_max == 0) {
         access_size_max = 4;
     }
@@ -3082,11 +3086,14 @@ static int memory_access_size(MemoryRegion *mr, 
unsigned l, hwaddr addr)
         }
     }
 
-    /* Don't attempt accesses larger than the maximum.  */
-    if (l > access_size_max) {
+    /* Don't attempt accesses not in the minimum/maximum range.  */
+    if (l < access_size_min) {
+        l = access_size_min;
+    } else if (l > access_size_max) {
         l = access_size_max;
+    } else {
+        l = pow2floor(l);
     }
-    l = pow2floor(l);
 
     return l;
 }
-- 
2.21.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]