qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Li Zhijian" <lizhijian@cn.fujitsu.com>,
	"Tony Nguyen" <tony.nguyen@bt.com>,
	"Alexey Kardashevskiy" <aik@ozlabs.ru>,
	"Julia Suvorova" <jusual@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Peter Xu" <peterx@redhat.com>,
	"Alexander Bulekov" <alxndr@bu.edu>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Richard Henderson" <rth@twiddle.net>,
	"Stefano Garzarella" <sgarzare@redhat.com>
Subject: [RFC PATCH 1/2] exec: Let memory_access_size() consider minimum valid access size
Date: Sun, 17 May 2020 13:38:03 +0200	[thread overview]
Message-ID: <20200517113804.9063-2-f4bug@amsat.org> (raw)
In-Reply-To: <20200517113804.9063-1-f4bug@amsat.org>

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é <f4bug@amsat.org>
---
 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	other threads:[~2020-05-17 11:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17 11:38 [RFC PATCH 0/2] exec: Fix (too) short device accesses Philippe Mathieu-Daudé
2020-05-17 11:38 ` Philippe Mathieu-Daudé [this message]
2020-05-17 11:38 ` [RFC PATCH 2/2] exec: Do not let flatview_read/write_continue do (too) short accesses Philippe Mathieu-Daudé
2020-05-17 13:51 ` [RFC PATCH 0/2] exec: Fix (too) short device accesses no-reply
2020-05-17 15:50   ` Philippe Mathieu-Daudé
2020-05-17 14:20 ` no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200517113804.9063-2-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=aik@ozlabs.ru \
    --cc=alxndr@bu.edu \
    --cc=jusual@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=sgarzare@redhat.com \
    --cc=tony.nguyen@bt.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).