From patchwork Wed Dec 15 10:40:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 524263 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp240030imb; Wed, 15 Dec 2021 03:25:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXfclcZI+L4ZKPozIziyKyxztBqZP7ocUAD8Qo+ceTD446otBamSrWjAz9MQKZAKbrgASJ X-Received: by 2002:a25:2d1:: with SMTP id 200mr5367056ybc.528.1639567501589; Wed, 15 Dec 2021 03:25:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639567501; cv=none; d=google.com; s=arc-20160816; b=jM/Ge+ZwrHB3/lC+UA9iv5WKJdTb2laZSPMR++Bxi8he6ZuahxeFe/uVHFV/BtuRiP 7TTvypYEy58ZQ6TOXO/ulNstTqUwup/BhfAyU8g5O1oIJAgW6HgrOZo+Qj+bwIkseT5p Y8kJXMFw9sc3aXufjkkoD5m+gfd47v4Wzpppv/EUfFCSmpfk5wGBbrD2XfElDYUXIQfO ZfXRzp29E5lwTfbmq6WD6stpFb0v5yVV9gcwbsR+jSJUWO0lSpuvMJX08C1DqQfB093t THkv+/+lGqGynckW67SUPex2gVVhBvJHQL34A78M5pu8Jdk+JZT6ohE0EXnlbE5Grlp/ RQqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=dWLzLfQlZup7XMFO5JjnyV3vJtIaJi3BRfsuFCKl1fw=; b=lESjtyase2g7dV/wPGNymTNxc3IkzxW8FL0lCN9EQxyRJ4LETU6gfDk+7k3ENv56fr wFsZ4oCTtAxQVXcnT1S1WE/BX1jM4ksBd3erEOW4KieMc7kKE7ZovB2vb+LzbQP/7Qal PSkRwU2zw9kqffhdeBvkXkSqzunbenMI5wbrnh0tQCPhsW2V4oD5xD77qr7ewlQfo8OP iadasvLWiukRg+7f+IFxgN7oAHSk4RRO33YotJukJSzWssf0kFvgxa5e9nP0VuCT+AvT rBAXGrLfJhExrc6ha06v/g5tXiQRcMdGSsx+aMsGf4l/0m1u/KxETO0VeUEtabqSl3l0 /1tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tjcHFBy+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 79si1933398ybn.822.2021.12.15.03.25.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Dec 2021 03:25:01 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tjcHFBy+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxSP7-0007MF-1h for patch@linaro.org; Wed, 15 Dec 2021 06:25:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxRia-0006sV-Nr for qemu-devel@nongnu.org; Wed, 15 Dec 2021 05:41:04 -0500 Received: from [2a00:1450:4864:20::42a] (port=44787 helo=mail-wr1-x42a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mxRiX-0008RN-9J for qemu-devel@nongnu.org; Wed, 15 Dec 2021 05:41:04 -0500 Received: by mail-wr1-x42a.google.com with SMTP id t18so37328573wrg.11 for ; Wed, 15 Dec 2021 02:41:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=dWLzLfQlZup7XMFO5JjnyV3vJtIaJi3BRfsuFCKl1fw=; b=tjcHFBy++rBJC+apkSX9pLVod0YN4PSXuNE+vIIA4etm0fwMGdon8hC7yx9pGxKx8p +a8W+FyjsdgU3wC4ph1hfngIiEHhyUXKqbk/Z6/1SIe9AVgLzErCPJ+OpmZDPdma9Wib EKCaij7bbjOvEGuH8gNQnZiDi9CTalLA30mENEMQNiB4IJv181gCx6IirBFI6FWZOJtZ KYYPfzPFqUjhf4ZYPq7h/wz1WxkAJpyWus7Wj37JypVSI9KYsg871Pzxpe8ubURBiLST J383CjWn7Nxi7ifXhAz0LOrQ1NMgaRPGHZtHXlEEun9V/vvkzgPDqfn84TBQe8VpDzjH JFag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dWLzLfQlZup7XMFO5JjnyV3vJtIaJi3BRfsuFCKl1fw=; b=aUoJcnoYIl0VuZMJWOFnuAoy4+ZmPL1vlfJ2QUcT6LgZIYazHeaAzPtsM/Ktn63GBm dvdi07uXaeJkRXn4UFaNr0mZs8QkI5OvlZ7ROzVDh+MjcI8BysWezU4k6R3TJ5BiKS0B +/+dOHnM8JpMbsnih3Yq4n0KeSvAfARZgdjwj2f4gQ/pqU7zY9gE3wNNHzeftneAkfN+ o1lngKBBY/XDIDgQBTpqts64hiAitDQEATspIvmCNN+aZTa+jhdKDKufzUZxdCu1mUuW vZvCAzCCUx+xP2rjNBNW5kdumAOvfVrcIlqeFPCRtNGDpzinKP8aRta6+lOkbg6TG0jv wpxw== X-Gm-Message-State: AOAM531o53hqhGK4oKb55FeSBTo6jbzxIbBxXka+PSuZNj8ghL+iKBh0 H4Fa17aB+IgDXXqUIVymruEmLoDQVF2V4A== X-Received: by 2002:a05:6000:1201:: with SMTP id e1mr3776973wrx.298.1639564860040; Wed, 15 Dec 2021 02:41:00 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id e18sm1600815wrs.48.2021.12.15.02.40.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 02:40:59 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 16/33] target/arm: Assert thumb pc is aligned Date: Wed, 15 Dec 2021 10:40:32 +0000 Message-Id: <20211215104049.2030475-17-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211215104049.2030475-1-peter.maydell@linaro.org> References: <20211215104049.2030475-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42a (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Misaligned thumb PC is architecturally impossible. Assert is better than proceeding, in case we've missed something somewhere. Expand a comment about aligning the pc in gdbstub. Fail an incoming migrate if a thumb pc is misaligned. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Signed-off-by: Peter Maydell --- target/arm/gdbstub.c | 9 +++++++-- target/arm/machine.c | 10 ++++++++++ target/arm/translate.c | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 134da0d0ae3..ca1de475116 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -77,8 +77,13 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) tmp = ldl_p(mem_buf); - /* Mask out low bit of PC to workaround gdb bugs. This will probably - cause problems if we ever implement the Jazelle DBX extensions. */ + /* + * Mask out low bits of PC to workaround gdb bugs. + * This avoids an assert in thumb_tr_translate_insn, because it is + * architecturally impossible to misalign the pc. + * This will probably cause problems if we ever implement the + * Jazelle DBX extensions. + */ if (n == 15) { tmp &= ~1; } diff --git a/target/arm/machine.c b/target/arm/machine.c index c74d8c3f4b3..135d2420b5c 100644 --- a/target/arm/machine.c +++ b/target/arm/machine.c @@ -794,6 +794,16 @@ static int cpu_post_load(void *opaque, int version_id) return -1; } } + + /* + * Misaligned thumb pc is architecturally impossible. + * We have an assert in thumb_tr_translate_insn to verify this. + * Fail an incoming migrate to avoid this assert. + */ + if (!is_a64(env) && env->thumb && (env->regs[15] & 1)) { + return -1; + } + if (!kvm_enabled()) { pmu_op_finish(&cpu->env); } diff --git a/target/arm/translate.c b/target/arm/translate.c index 45917c3a6d2..0a3840d227f 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -9646,6 +9646,9 @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) uint32_t insn; bool is_16bit; + /* Misaligned thumb PC is architecturally impossible. */ + assert((dc->base.pc_next & 1) == 0); + if (arm_check_ss_active(dc) || arm_check_kernelpage(dc)) { dc->base.pc_next = pc + 2; return;