From patchwork Thu Dec 13 11:55:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 153637 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp709999ljp; Thu, 13 Dec 2018 03:59:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/X/dv9F86fxwJs/QGPVROxBqH1LXPWl4eqxehEgLNKzm4/ys//G3xA6t6zIcsEQvwrPPHY0 X-Received: by 2002:a37:ef07:: with SMTP id j7mr21526931qkk.35.1544702362720; Thu, 13 Dec 2018 03:59:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544702362; cv=none; d=google.com; s=arc-20160816; b=bleJcCjhWhMbN1YIzpX4unRlfCIfIJz8j5+lA9GZZ13bzCU+Ln4tbTBzkQb9uSKVn9 S7ivZtQ1SXiWer7DLSvqu7BcxJZSamu5LG9xN1FP5W6bTWLbiPO17BYokH3w1/Q1nRoS yE1khfWMjVmQSqxHpBdhfF6kbAjpL70xmEWcyQMexAybIJmGLCVSNfRlfatfR/QJbq4i tarxXnPP7LcTO3jS8VakqObK6tkiTK9brKbzxvnbT40OkWbcf9LNSR/yOJRZvZz7AVV7 UEnSeXvXOdlLBRJSubLghwD+gap8tRl7EDD0urSE/Hm2mda6Q/KR4KrwXYiJegmdiOgF TSkA== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=2WKnsWU8peQgKSPMtKad0YkSHbbdgmPXuVtkQNcYNoU=; b=N1ISo73xYyYqGqFuRHuGvfDeNPksbUUQs54K1EAxTJmXytiZw442q6fpRDPOUNDXVq 2MvYbTFWUHwC8ouZUVKAnyqRhwpAhyLAw825KtkgbE0If6YJ53rEVzrAX78aEEnQpRXB baEOMbNcvJAwsWmP4zsFP7HBzAVMABA14Wn5cjYAT07nS71AVtIZAceZmd9+zPsC93CK QGrVHxseDi+iat95iIqfh5HUrEhr98hwMx0gDMuhEieNwfV9NM/T4Oz0vkYaoBMkKoyZ pBgLdbPERapWasfWrdeAUBArbp55UKhK5DHbFUvUeCYHNQ7Nx/D/w64Kyz08zwqqh9+E CHzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dYMnoe7Q; 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 a24si959448qvd.18.2018.12.13.03.59.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Dec 2018 03:59:22 -0800 (PST) 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=dYMnoe7Q; 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]:51930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXPeE-00025v-2Z for patch@linaro.org; Thu, 13 Dec 2018 06:59:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXPaB-0007dT-TJ for qemu-devel@nongnu.org; Thu, 13 Dec 2018 06:55:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXPa6-00007G-JS for qemu-devel@nongnu.org; Thu, 13 Dec 2018 06:55:11 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:35368) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXPa6-000069-Ba for qemu-devel@nongnu.org; Thu, 13 Dec 2018 06:55:06 -0500 Received: by mail-wm1-x342.google.com with SMTP id c126so2096223wmh.0 for ; Thu, 13 Dec 2018 03:55:06 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=2WKnsWU8peQgKSPMtKad0YkSHbbdgmPXuVtkQNcYNoU=; b=dYMnoe7QWiKtyHhcJDjD4B5nuaEo8q04K6tsbW0Z2KdmFfnDgtsK+/cjBcAu3aDwQK 0+b9TlFf1665Qp18UEnru5Jtd0Q9DnH9Vc34IWhBrTtnv47QV5rdAdI6wI9axoRqgEK2 /TJlr7sKLaZkK8NqaLBpTv5yf61ineFqUySkU= 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:mime-version:content-transfer-encoding; bh=2WKnsWU8peQgKSPMtKad0YkSHbbdgmPXuVtkQNcYNoU=; b=CRFGWYNloC01+K1/Yt1FUYT4HS63OoHKGvnqLRZQxXYTkZoJ9KnKPZE//+/A9whJcR 6uHCW6CGtuUR0RHwgaTenbSKyUlrMNq6CVb3Zhlml4anhd0MeC4vXQHqOlV8G6tqmvIn sLSu/fIRuIAL+lnSjF+0kwt3fTr8d3CEow1FjKwrtnZnQU1kVghe07Zl3Ogu8cYNxQSf N1IzOBnCxk5DXMmFuPwodmeif5kCp8W4blNTNvKZv6s+uusPXazeBj+UgVoEl4k5sOWP d7FXnjIpcbKmfFefGihdumq02z8qK/U2j05cnh6O95C6Bx1dHf1eM3ME33oDfDqmZsNE e1Uw== X-Gm-Message-State: AA+aEWamL1eXGuYXeJYyp2bVnOPsbIfUVpgspuGLCDt1i3mp0S9Lx0h5 /lTbg6RlJQoYsFmhotoX9JehWtMkxyI= X-Received: by 2002:a1c:c90b:: with SMTP id f11mr9889949wmb.33.1544702105176; Thu, 13 Dec 2018 03:55:05 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id v5sm2174274wrn.71.2018.12.13.03.55.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Dec 2018 03:55:04 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 844A43E035F; Thu, 13 Dec 2018 11:55:03 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2018 11:55:02 +0000 Message-Id: <20181213115503.24188-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181213115503.24188-1-alex.bennee@linaro.org> References: <20181213115503.24188-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PATCH v1 1/2] target/arm: kvm64 make guest debug AA32 break point aware 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: mark.rutland@arm.com, Peter Maydell , Omair Javaid , ard.biesheuvel@linaro.org, qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" When supported by the hardware we can run AA32 guests or even AA64 EL1 code with AA32 EL0 mode code. Inserting a AA64 break point into AA32 code tends to break things. This is especially acute with gdb as it inserts temporary breakpoints when stepping through code. The heuristic of checking the current mode works but it's not perfect. A user could be placing a break point in code after a mode switch and that will still fail. However there doesn't seem to be a way to force a hbreak by default. According to "set breakpoint auto-hw on": This is the default behavior. When GDB sets a breakpoint, it will try to use the target memory map to decide if software or hardware breakpoint must be used. Reported-by: Ard Biesheuvel Signed-off-by: Alex Bennée Cc: Omair Javaid --- target/arm/kvm64.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 0a502091e7..dd564a59b7 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -989,14 +989,20 @@ int kvm_arch_get_registers(CPUState *cs) return ret; } -/* C6.6.29 BRK instruction */ +/* BRK (A64) and BKPT (A32) instructions */ static const uint32_t brk_insn = 0xd4200000; +static const uint32_t bkpt_insn = 0xe1200070; int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) { + CPUARMState *env = &ARM_CPU(cs)->env; + int el = arm_current_el(env); + bool is_aa64 = arm_el_is_aa64(env, el); + const uint32_t *bpi = is_aa64 ? &brk_insn : &bkpt_insn; + if (have_guest_debug) { if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, 4, 0) || - cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&brk_insn, 4, 1)) { + cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)bpi, 4, 1)) { return -EINVAL; } return 0; @@ -1012,7 +1018,7 @@ int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) if (have_guest_debug) { if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&brk, 4, 0) || - brk != brk_insn || + !(brk == brk_insn || brk == bkpt_insn) || cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, 4, 1)) { return -EINVAL; } @@ -1055,6 +1061,7 @@ bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit) return false; } break; + case EC_AA32_BKPT: case EC_AA64_BKPT: if (kvm_find_sw_breakpoint(cs, env->pc)) { return true;