From nobody Wed Apr 9 22:02:46 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1606132320; cv=none; d=zohomail.com; s=zohoarc; b=OKE5dbWLGUMx+YSgq6wtcOlm1t28itn8TpcewhYvn4wAwtpb8+rDpHcE2mjANM286+zTLUDxp2+O0fbQ4EamOUHIITLouHNEUXvEMrpOyMiH2MaoHXgo3LCA05bkm+G8BNHLkugJtWMhg4UIXhrl4CJ7mmZfLTjCowqkFP4agZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606132320; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yr0RRNusj+c+w++psVed1AMwBpNn/6sJlaWnKcTBKLQ=; b=GqLIP0gp45+CGuajIodyn1VvfOEsSFdAtP6MLc8JmIN1tz9PPX6/oaFHkkDu0LHjK04HgaHtEd+5XyUcrS35V3psUnyCMfJO5cWtlw8jo79VI4pHVLMgqLg4NO+wPuHjsMLdAyNo+Pizxa6t26ZykSDxKyvWeQzJzXkEePJqXmQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160613232055148.155864278868535; Mon, 23 Nov 2020 03:52:00 -0800 (PST) Received: from localhost ([::1]:44192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1khANz-0007sz-3h for importer@patchew.org; Mon, 23 Nov 2020 06:51:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khAFt-0004jF-NH for qemu-devel@nongnu.org; Mon, 23 Nov 2020 06:43:37 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:43960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1khAFr-0002ku-Qb for qemu-devel@nongnu.org; Mon, 23 Nov 2020 06:43:37 -0500 Received: by mail-wr1-x441.google.com with SMTP id s8so18237167wrw.10 for ; Mon, 23 Nov 2020 03:43:35 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id g186sm50836495wma.1.2020.11.23.03.43.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 03:43:33 -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=yr0RRNusj+c+w++psVed1AMwBpNn/6sJlaWnKcTBKLQ=; b=xvDLs0uAVOcQfX56X9nitH+ALtKckCrH0z0IyVRslwJ3OuVmkpWb+9gva4P+A988Rk 6OfK4gstDfK0hwFQWOQtN6vwPva48X4m1kAEv5u6AEykYlSaEg5vabcXl5EO+iiH7IAo gsCtxiV6dZCFRlf8Ck7UrLtV+0LxV0ZE7VNMqzpBz6uJlvrOBWxv0z3RCAWucVaWIz2I YGvMKjGXxpBFSj6VsVwwqhWUXp33IhwdpZeq0qXtnz4eewZ0pHqDdr8GQlgrX6qLi3oU hrF2dIuwKRzbp1GESybZ2aHhq4vrSwKQy410rJvjoOa7ZgWnSLBSFvvhHrqv9//XudP8 wNrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yr0RRNusj+c+w++psVed1AMwBpNn/6sJlaWnKcTBKLQ=; b=NljLvnjKGPvWrFmiFQXmfTS7ws1gSz5iYS9GdUJDuL/s+4ixN/snUsfFPO298a1Cih 05P67uGleALyKSRN+0RZhPC8yrPcqaDM4agyvPObmU6RFsuRY+g25DjBtAfP6v+St6vH /fy4kZ6TLUpypbaocq+G7lvzjjNCjFiVorePxgx/kWvLc2J3wz8jwLXC5hTRQZNqlJUN TqQwPCaYFd3eNXw5OPyKdH+IIulx6R3TnZSTjykPcEkf4JUWfk7u3cGGVleVNUmgswvJ Nf7xx0LOLmvXf+C7lzi4CZDiKG/oiyQw7ie2q/2JyYUWJPUbPcaLsOOUmAzHVFVG5U7q /oaQ== X-Gm-Message-State: AOAM5336lUp9Z2CCG0352xFoUVatmnBj+SFKm8SF6ISBl3jbW8jk6pVL bkPuL5TH3EXS4eYcJTSuB0D0DkHFPR5Piw== X-Google-Smtp-Source: ABdhPJw1t1JAVkexcbOyTzTzHRSXleF+WvdSm+osNojXqvwBOoHCIc2e5+Zj6BehPf1GmyDeOY+p8Q== X-Received: by 2002:adf:c443:: with SMTP id a3mr32439321wrg.249.1606131814280; Mon, 23 Nov 2020 03:43:34 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 15/24] linux-user/arm: Deliver SIGTRAP for UDF patterns used as breakpoints Date: Mon, 23 Nov 2020 11:43:06 +0000 Message-Id: <20201123114315.13372-16-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201123114315.13372-1-peter.maydell@linaro.org> References: <20201123114315.13372-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x441.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" The Linux kernel doesn't use the official bkpt insn for breakpoints; instead it uses three instructions in the guaranteed-to-UNDEF space, and generates SIGTRAP for these rather than the SIGILL that most UNDEF insns generate: https://elixir.bootlin.com/linux/v5.9.8/source/arch/arm/kernel/ptrace.c#L197 Make QEMU treat these insns specially too. The main benefit of this is that if you're running a debugger on a guest program that runs into a GCC __builtin_trap() or LLVM "trap because execution should never reach here" then you'll get the expected signal rather than a SIGILL. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20201117155634.6924-1-peter.maydell@linaro.org --- linux-user/arm/cpu_loop.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index 13629ee1f6a..3d272b56ef0 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -205,6 +205,24 @@ do_kernel_trap(CPUARMState *env) return 0; } =20 +static bool insn_is_linux_bkpt(uint32_t opcode, bool is_thumb) +{ + /* + * Return true if this insn is one of the three magic UDF insns + * which the kernel treats as breakpoint insns. + */ + if (!is_thumb) { + return (opcode & 0x0fffffff) =3D=3D 0x07f001f0; + } else { + /* + * Note that we get the two halves of the 32-bit T32 insn + * in the opposite order to the value the kernel uses in + * its undef_hook struct. + */ + return ((opcode & 0xffff) =3D=3D 0xde01) || (opcode =3D=3D 0xa000f= 7f0); + } +} + void cpu_loop(CPUARMState *env) { CPUState *cs =3D env_cpu(env); @@ -234,6 +252,16 @@ void cpu_loop(CPUARMState *env) /* FIXME - what to do if get_user() fails? */ get_user_code_u32(opcode, env->regs[15], env); =20 + /* + * The Linux kernel treats some UDF patterns specially + * to use as breakpoints (instead of the architectural + * bkpt insn). These should trigger a SIGTRAP rather + * than SIGILL. + */ + if (insn_is_linux_bkpt(opcode, env->thumb)) { + goto excp_debug; + } + rc =3D EmulateAll(opcode, &ts->fpa, env); if (rc =3D=3D 0) { /* illegal instruction */ info.si_signo =3D TARGET_SIGILL; --=20 2.20.1