Received: from eggs.gnu.org ([2001:4830:134:3::10]:36610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiA1Y-0003qA-9v for qemu-devel@nongnu.org; Thu, 30 May 2013 17:04:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UiA1T-0001ik-Me for qemu-devel@nongnu.org; Thu, 30 May 2013 17:04:40 -0400 Received: from mail-ea0-x235.google.com ([2a00:1450:4013:c01::235]:34136) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiA1T-0001ig-GY for qemu-devel@nongnu.org; Thu, 30 May 2013 17:04:35 -0400 Received: by mail-ea0-f181.google.com with SMTP id a11so850808eae.26 for ; Thu, 30 May 2013 14:04:34 -0700 (PDT) Received: from playground.lan (net-37-116-217-184.cust.dsl.vodafone.it. [37.116.217.184]) by mx.google.com with ESMTPSA id y2sm62707218eeu.2.2013.05.30.14.04.32 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 30 May 2013 14:04:34 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 30 May 2013 23:03:50 +0200 Message-Id: <1369947836-2638-17-git-send-email-pbonzini@redhat.com> In-Reply-To: <1369947836-2638-1-git-send-email-pbonzini@redhat.com> References: <1369947836-2638-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 16/22] memory: accept mismatching sizes in memory_region_access_valid List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org The memory API is able to use smaller/wider accesses than requested, match that in memory_region_access_valid. Of course, the accepts callback is still free to reject those accesses. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- memory.c | 29 ++++++++++++++++++++--------- 1 files changed, 20 insertions(+), 9 deletions(-) diff --git a/memory.c b/memory.c index 9e1c1a3..c72f56d 100644 --- a/memory.c +++ b/memory.c @@ -856,24 +856,35 @@ bool memory_region_access_valid(MemoryRegion *mr, unsigned size, bool is_write) { - if (mr->ops->valid.accepts - && !mr->ops->valid.accepts(mr->opaque, addr, size, is_write)) { - return false; - } + int access_size_min, access_size_max; + int access_size, i; if (!mr->ops->valid.unaligned && (addr & (size - 1))) { return false; } - /* Treat zero as compatibility all valid */ - if (!mr->ops->valid.max_access_size) { + if (!mr->ops->valid.accepts) { return true; } - if (size > mr->ops->valid.max_access_size - || size < mr->ops->valid.min_access_size) { - return false; + access_size_min = mr->ops->valid.min_access_size; + if (!mr->ops->valid.min_access_size) { + access_size_min = 1; + } + + access_size_max = mr->ops->valid.max_access_size; + if (!mr->ops->valid.max_access_size) { + access_size_max = 4; + } + + access_size = MAX(MIN(size, access_size_max), access_size_min); + for (i = 0; i < size; i += access_size) { + if (!mr->ops->valid.accepts(mr->opaque, addr + i, access_size, + is_write)) { + return false; + } } + return true; } -- 1.7.4.1