From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3nnl-0008Oh-Dt for qemu-devel@nongnu.org; Mon, 29 Jul 2013 09:47:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V3nne-0007D2-Up for qemu-devel@nongnu.org; Mon, 29 Jul 2013 09:47:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56455) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3nne-0007Ct-OE for qemu-devel@nongnu.org; Mon, 29 Jul 2013 09:47:46 -0400 Message-ID: <51F6726D.5020405@redhat.com> Date: Mon, 29 Jul 2013 15:47:25 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1375100921-12990-1-git-send-email-pbonzini@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH for-1.6] exec: fix writing to MMIO area with non-power-of-two length List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: alxchk@gmail.com, qemu-devel@nongnu.org Il 29/07/2013 14:41, Peter Maydell ha scritto: > On 29 July 2013 13:28, Paolo Bonzini wrote: >> The problem is introduced by commit 2332616 (exec: Support 64-bit >> operations in address_space_rw, 2013-07-08). Before that commit, >> memory_access_size would only return 1/2/4. >> >> Since alignment is already handled above, reduce l to the largest >> power of two that is smaller than l. >> >> Reported-by: Oleksii Shevchuk >> Tested-by: Oleksii Shevchuk >> Signed-off-by: Paolo Bonzini >> --- >> exec.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/exec.c b/exec.c >> index c4f2894..e122c81 100644 >> --- a/exec.c >> +++ b/exec.c >> @@ -1925,6 +1925,9 @@ static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) >> if (l > access_size_max) { >> l = access_size_max; >> } >> + if (l & (l - 1)) { >> + l = 1 << (qemu_fls(l) - 1); >> + } > > Is this a hot enough code path that we care about going via > the not-inline qemu_fls() rather than calling clz32() directly? It is not that hot because of the "if". > (probably not, I guess.) Alternatively, we seem to have a > pow2floor() function... Yeah, pow2floor is also nice. There's still a lot of opportunity for unification... Paolo