Received: by 2002:ac2:52b1:0:0:0:0:0 with SMTP id r17csp4309992lfm; Mon, 20 Apr 2020 14:24:19 -0700 (PDT) X-Google-Smtp-Source: APiQypIq2KSAD3euWfwF5X4CBfh/79sDwV8gp5OjyWyMwctWGS4pyyBhwiVBlF0MAPyDLw70L2G0 X-Received: by 2002:ae9:e805:: with SMTP id a5mr18025854qkg.493.1587417859165; Mon, 20 Apr 2020 14:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587417859; cv=none; d=google.com; s=arc-20160816; b=Yf3FhELGB8cTb4F3nkp/NIlOgWH4UHKizCO6DIRQf/dAGCwV/2OfVeW0cmrs9jSHWn PxLFdAmzRWAcxrgOk+njB9wYshmM2pvb7DUEdVu8Dnniue685Q6qZ93/opxmxkHo22na b+duXt0VCClM54oEhwMehZ4YsI0eSfGb8qkP40YT304bBnSvEOg8S7CJ+vbzb9haOLv7 RvW7JlJKyMu0UADFd8sJeqMS5Z7r1kmPlhk/Ox90LDW/25fLyaDWRMc23anSWvBUjiSM r86s6Gly2mMUhocRwTrqYC70uXkc3xgB7qFAU8GuFIiT7+aA1CwzPOQOyX81mWD3cmJL +Z5A== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=g25xx+IbQ36/3S818ce09veNakgmIRGfyJNXoNjOE3o=; b=BIq8Y7XqiGx4AtZAwUUr4NC+cUuftgH4M76ucKvDSNI23Joe3/3pf8RSe3TlbeVbDD pajgmtw/iWbQtcS4BMuxllfnQH1WUdrKo1JRRxbQdbMACDrLv+NeVRLcEYq3WI5MKul+ bWgexFyo8eIYuQaiyp2V4jq5CASMw9dxf2Up0X3sD9L/cgIoOXBm42he0x86ZqgMnN8f B0BAiD1wvA7t8Ga480cWr993EEoME8BX/ewqqKL6PsAoWUY3tvpGsridM+lftT//6mdx PNJxiX2FZkCkiC1GGXVcjhjXrNlzGjSsf4150juv2Z7G0tuu8w1OkA1PQo2jQkjht1wc hY9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=lMhoM1tr; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=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. [209.51.188.17]) by mx.google.com with ESMTPS id k141si299078qke.172.2020.04.20.14.24.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Apr 2020 14:24:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=lMhoM1tr; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdtq-0001H5-9k for alex.bennee@linaro.org; Mon, 20 Apr 2020 17:24:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42096) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdrp-0006nY-Bf for qemu-arm@nongnu.org; Mon, 20 Apr 2020 17:22:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQdro-0006n4-JJ for qemu-arm@nongnu.org; Mon, 20 Apr 2020 17:22:13 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:37542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jQdro-0006kE-6c for qemu-arm@nongnu.org; Mon, 20 Apr 2020 17:22:12 -0400 Received: by mail-wr1-x441.google.com with SMTP id k1so14036952wrx.4 for ; Mon, 20 Apr 2020 14:22:11 -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 :mime-version:content-transfer-encoding; bh=g25xx+IbQ36/3S818ce09veNakgmIRGfyJNXoNjOE3o=; b=lMhoM1trFpGPR441mTxkus+s2KnaNfFLUfBiME74Lrh2FIwePepyuJXydluRmH8zVf 6dO6gS8jF1T5/vSZ9TM9XfzsEBbJ4/LobmAeR12tT3WKqVcxqd0LisvNRMplMbun8ZWm GHUQwDDDtUrjBRbDCcGIL8mixkjmH/vnjgNGRd6n+0UDgbZYlDtXyRMAHlNi6ikPOXvc eyBmQB/bc/QyXa3U9BoS7iWD4/tmnnBYPCxUWzbADcGnDMnBdDnYH08NxMAADzXmT6hy RmWXFzch0+vMV0QPR4WaAAMzw5sgcVd8TCTkvkuj8uYrkQOx2uFKz0yn2pfk0muLLqdS uqhA== 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=g25xx+IbQ36/3S818ce09veNakgmIRGfyJNXoNjOE3o=; b=lDFz/hfWhug05FPcLSNIi3efdHgXM+xdySfuaUX6wHWofcnquUtko25XB5EeShwkkn v3dZZJylEd8qS4B82SaKnBzLxKlogdRy57i5emAznI2JR6oswjljq8+4l5Oi+tTPA85R e2qk8mxtn5kLXiebD5EUfs3KHw7ZQbJw6xj7+k6tL+lql0jsh0sD6hhI9FPH7GD4GRiS 26myuOEB4aiNpvce4n86eGaD9igAMyVx/LUxHUeGnnX7/bk7sSaomxYn2IymZWmZFKWZ FLjbEK5KA5fps6K6THbeVjdtbrTCydKin0YJWYig/JpsVZt2AubZaNXZSmgt/1Spt6Gi 0LuQ== X-Gm-Message-State: AGi0PuaqpTL15lupY93K9AfzA9R7ifbAowLbOFffEVIJ9LHA/UjVMAYR qNDLDvJ3AnyMxmyaKH9h+/3yDB66WOCpZQ== X-Received: by 2002:adf:9cc8:: with SMTP id h8mr19974679wre.167.1587417730598; Mon, 20 Apr 2020 14:22:10 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id j10sm823663wmi.18.2020.04.20.14.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 14:22:10 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 1/4] linux-user/arm: BKPT should cause SIGTRAP, not be a syscall Date: Mon, 20 Apr 2020 22:22:03 +0100 Message-Id: <20200420212206.12776-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200420212206.12776-1-peter.maydell@linaro.org> References: <20200420212206.12776-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a00:1450:4864:20::441 X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: omerg681@gmail.com, Riku Voipio , Laurent Vivier Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: VLfiAyW0Eno0 In linux-user/arm/cpu-loop.c we incorrectly treat EXCP_BKPT similarly to EXCP_SWI, which means that if the guest executes a BKPT insn then QEMU will perform a syscall for it (which syscall depends on what value happens to be in r7...). The correct behaviour is that the guest process should take a SIGTRAP. This code has been like this (more or less) since commit 06c949e62a098f in 2006 which added BKPT in the first place. This is probably because at the time the same code path was used to handle both Linux syscalls and semihosting calls, and (on M profile) BKPT with a suitable magic number is used for semihosting calls. But these days we've moved handling of semihosting out to an entirely different codepath, so we can fix this bug by simply removing this handling of EXCP_BKPT and instead making it deliver a SIGTRAP like EXCP_DEBUG (as we do already on aarch64). Reported-by: Fixes: https://bugs.launchpad.net/qemu/+bug/1873898 Signed-off-by: Peter Maydell --- linux-user/arm/cpu_loop.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index cf618daa1ca..82d0dd3c312 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -295,32 +295,17 @@ void cpu_loop(CPUARMState *env) } break; case EXCP_SWI: - case EXCP_BKPT: { env->eabi = 1; /* system call */ - if (trapnr == EXCP_BKPT) { - if (env->thumb) { - /* FIXME - what to do if get_user() fails? */ - get_user_code_u16(insn, env->regs[15], env); - n = insn & 0xff; - env->regs[15] += 2; - } else { - /* FIXME - what to do if get_user() fails? */ - get_user_code_u32(insn, env->regs[15], env); - n = (insn & 0xf) | ((insn >> 4) & 0xff0); - env->regs[15] += 4; - } + if (env->thumb) { + /* FIXME - what to do if get_user() fails? */ + get_user_code_u16(insn, env->regs[15] - 2, env); + n = insn & 0xff; } else { - if (env->thumb) { - /* FIXME - what to do if get_user() fails? */ - get_user_code_u16(insn, env->regs[15] - 2, env); - n = insn & 0xff; - } else { - /* FIXME - what to do if get_user() fails? */ - get_user_code_u32(insn, env->regs[15] - 4, env); - n = insn & 0xffffff; - } + /* FIXME - what to do if get_user() fails? */ + get_user_code_u32(insn, env->regs[15] - 4, env); + n = insn & 0xffffff; } if (n == ARM_NR_cacheflush) { @@ -396,6 +381,7 @@ void cpu_loop(CPUARMState *env) } break; case EXCP_DEBUG: + case EXCP_BKPT: excp_debug: info.si_signo = TARGET_SIGTRAP; info.si_errno = 0; -- 2.20.1