From patchwork Wed May 9 17:54:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 135328 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp53704lji; Wed, 9 May 2018 11:01:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrBNIm/ikRq+kJW/tx8xEd02Z0qaiVvRZaeYAkgThyqVsm5dZDmDHV0RO8a4n9e9AufJT+S X-Received: by 2002:a0c:96eb:: with SMTP id b40-v6mr42844181qvd.135.1525888906861; Wed, 09 May 2018 11:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525888906; cv=none; d=google.com; s=arc-20160816; b=AFqkc9fj4OppNCxlPJSH+07yTZXt5jOAp9gSDu4uQhTLPHu0qdF15JdqV/DVBT+YQr IlMYgO4Wyoj/dkmjdNdJLKS0aW82Rm7RmfcqYTw4wRwLORJZGru4XjPqfqUZLmxbdPD/ +UMAg4xGxaLPbPL6Dq4AqIbGePQ4GrGLbFrzXYeU66kfXE9g1tKWXkE9XzBv0oGGh0yg gYc7IZolqlnpLcoyzH4DGw4wVf+kpPNwanQ2eU0gBVEIVzndOLmtVx7goNkLhqR0Rw/F FtYW//dZ8HbN6nvez8xvQguzYLv5IKco9pUyndTGaE6CyRiUl9j78dybkCE7QoXKlQNf 5BXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=C6GLpnz32qLKJyll2w953Cqp2/0LFJEW5cEcvn8UW7A=; b=dtDqd1OSxID7gEOC38TRZU61t9kYKGhHX1C5xUViwOwLUiw+RokuPWST35dFWqj1nA MDCu10dmr3sH+dD5D/u54OrtA4Oc6VJteh2Qo5Rbfdn3pCFFy1Gu+YVfqXBXjNBd2NgT zEsFP0ngw9kXw5H29fRWTMhrKKxn/AAKQNS3DeFf8VGNSM3X1wWI0sHQfR+IEj0om0uQ gLIkW6G1xAX9p7bLUi7T1SsJrlBvHZpa12MWAKJGvUOUXrgC+0/Cp6KBX9dBfQsIkvTR XwTxg6t1vcV/2Ftaa707jOY9mqw/ouiJi6gbvIgTmipiihhTDwEDBTjXBpq4b/9cs7Ye uz7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QESz65bZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z12si901978qka.92.2018.05.09.11.01.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 09 May 2018 11:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QESz65bZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58133 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTPO-0004Cl-AH for patch@linaro.org; Wed, 09 May 2018 14:01:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTJ1-0004Pu-Vn for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGTIz-0005C0-2m for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:11 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:45091) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGTIy-0005Af-QV for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:08 -0400 Received: by mail-pf0-x244.google.com with SMTP id c10so25989251pfi.12 for ; Wed, 09 May 2018 10:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=C6GLpnz32qLKJyll2w953Cqp2/0LFJEW5cEcvn8UW7A=; b=QESz65bZTPC7yPTPpY+STOhoiYBPCgU4/QiO0596gwYXvkTjQwHPC/WUBCYJbojhMo B583JA22vQLtngjBgjpcpnrS0OVXS6zdoQTKYAWIbbztYFhVIBiz6z6GWNs9hetmPhCl KWv2oL7M/mXghJxdeaAXDsoEuSp7nkXbA63wY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=C6GLpnz32qLKJyll2w953Cqp2/0LFJEW5cEcvn8UW7A=; b=R4s1wPYYAm9cJf9GTPfMPzCzvXvHEY8aFciB7rGzNVyBSIh5HzlggHfw/Z8/7B1pIk Xn8eq5Ts0ZPkEDV9XPM2z2AcheRX6dPMvVqTQir1nupXC5axSb5rv+xTk4c3ybyIHVq7 WF0jkn+vS59GfuioLPFVGXEIvKm+1XtP5stuyipH7Q2Ld9tpJQ79LdwwSDT5mdCtziNZ J7XBKY/0d5mjvqaDIqR14o6RDPHZpD+G+YNQ8g05uqW3BUHS7MYYHrgWcH4APSdQxzx2 Cz1v+vgiCqvQRlvOfkp3OP4KlOPkToj7cDX/Tcjg/9HiHXeERmn+wym8xXLnfMOh7xlA nPAw== X-Gm-Message-State: ALQs6tCcClqXzPYFyeW06oNDuceCN0Wu8Ogsqhrh1C6QaivpyG6UfliX bZv0d2TTN6R6Z3jm15TVWMY6IZluyio= X-Received: by 2002:a63:a41a:: with SMTP id c26-v6mr15190057pgf.311.1525888507442; Wed, 09 May 2018 10:55:07 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-2-170.tukw.qwest.net. [97.113.2.170]) by smtp.gmail.com with ESMTPSA id l90sm60332813pfb.149.2018.05.09.10.55.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 10:55:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 9 May 2018 10:54:34 -0700 Message-Id: <20180509175458.15642-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509175458.15642-1-richard.henderson@linaro.org> References: <20180509175458.15642-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PULL 04/28] target/xtensa: avoid integer overflow in next_page PC check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Sagar Karandikar , David Hildenbrand , Palmer Dabbelt , Mark Cave-Ayland , Max Filippov , Michael Clark , "Edgar E. Iglesias" , Guan Xuetao , Yongbok Kim , Alexander Graf , "Emilio G. Cota" , Richard Henderson , Artyom Tarasenko , Eduardo Habkost , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, Stafford Horne , David Gibson , Peter Crosthwaite , Bastian Koppelmann , Cornelia Huck , Michael Walle , qemu-ppc@nongnu.org, Paolo Bonzini , Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" If the PC is in the last page of the address space, next_page_start overflows to 0. Fix it. Reviewed-by: Richard Henderson Acked-by: Max Filippov Cc: Max Filippov Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- target/xtensa/translate.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) -- 2.17.0 diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 4f6d03059f..aad496347d 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -1061,8 +1061,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) int insn_count = 0; int max_insns = tb_cflags(tb) & CF_COUNT_MASK; uint32_t pc_start = tb->pc; - uint32_t next_page_start = - (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; + uint32_t page_start = pc_start & TARGET_PAGE_MASK; if (max_insns == 0) { max_insns = CF_COUNT_MASK; @@ -1162,9 +1161,9 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) } } while (dc.is_jmp == DISAS_NEXT && insn_count < max_insns && - dc.pc < next_page_start && - dc.pc + xtensa_insn_len(env, &dc) <= next_page_start && - !tcg_op_buf_full()); + dc.pc - page_start < TARGET_PAGE_SIZE && + dc.pc - page_start + xtensa_insn_len(env, &dc) <= TARGET_PAGE_SIZE + && !tcg_op_buf_full()); done: reset_sar_tracker(&dc); if (dc.icount) {