From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f5uQK-00082W-Kq for qemu-devel@nongnu.org; Tue, 10 Apr 2018 10:39:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f5uQH-0000WN-Fs for qemu-devel@nongnu.org; Tue, 10 Apr 2018 10:39:04 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:53937) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f5uQH-0000Vo-A1 for qemu-devel@nongnu.org; Tue, 10 Apr 2018 10:39:01 -0400 Date: Tue, 10 Apr 2018 10:38:58 -0400 From: "Emilio G. Cota" Message-ID: <20180410143858.GB22989@flamenco> References: <1523038800-2494-1-git-send-email-cota@braap.org> <1523038800-2494-18-git-send-email-cota@braap.org> <37e6c5c3-dc83-c557-658a-901485e20e19@linaro.org> <20180410125904.GA22304@flamenco> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH v2 17/17] target/riscv: convert to TranslatorOps List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Richard Henderson , Bastian Koppelmann , Michael Clark , Palmer Dabbelt , qemu-devel@nongnu.org, Sagar Karandikar On Tue, Apr 10, 2018 at 09:05:06 -0500, Eric Blake wrote: > On 04/10/2018 07:59 AM, Emilio G. Cota wrote: > > On Tue, Apr 10, 2018 at 11:24:37 +1000, Richard Henderson wrote: > >> On 04/07/2018 04:20 AM, Emilio G. Cota wrote: > >>> + next_page = (ctx->base.pc_first & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; > >>> + if (ctx->base.pc_next >= next_page) { > >> > >> This fails for the last page of the address space. > >> Better is > >> > >> page_start = ctx->base.pc_first & TARGET_PAGE_MASK; > >> if (ctx->base.pc_next - page_start >= TARGET_PAGE_SIZE) { > > > > Apart from the variable name change, I fail to see how this (A - B >= C) > > is not equivalent to the above (A => B + C). What am I missing? > > Integer overflow. Adding TARGET_PAGE_SIZE might wrap next_page to 0, > which changes the semantics of the conditional; while performing the > subtraction avoids the case of overflow. Ah indeed. Thanks. Turns out we have this problem in other targets as well -- will fix. E.