From patchwork Mon Aug 15 19:02:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 597269 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1761972maz; Mon, 15 Aug 2022 12:12:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR7JYvxl8bq1alUzPoR7OCpd/OFm2+W5i5trdwTNyPIrB3rd4Euz7M119ezidMCtbeJNrA8z X-Received: by 2002:ac8:7fd1:0:b0:343:67ec:9f9e with SMTP id b17-20020ac87fd1000000b0034367ec9f9emr15050478qtk.453.1660590749660; Mon, 15 Aug 2022 12:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660590749; cv=none; d=google.com; s=arc-20160816; b=WKenQBGyyKWY5HWQus2SChrypDvr8lQmBcj1F6/zftuz86biNDGY7CRQB1uMhFkG6m s5ivoMIsO7baZKkdD6hrJm8kxE23ELq/d/ZnkMMVHFU9n+Ap438TrdNYG4CVPB5wwRm/ Cn8jYq1fuhetCQ4Hp7vTewdc9x8E++tqn7QtBx7GGffGE2RbAv8JaTJQ/sUTStD7VTdK ooCovFg3Tam+sDBQbXwY5NJ4QFqFcihijpv62LoCghqVE4eROrMTO+SQ8vFCfjFbn3ap YdpzZrZxpoZkgFT9Y6RmVJpaNGexYra2dttIbRRzJ/sO0tEa42MYKF+EQxJ95EgsOJiZ Jt1w== 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:cc:to :from:dkim-signature; bh=yL2kCSEaX64Q/NPJAtRoJiqW85LCPcZ6AySZ3J3a/uE=; b=0n/xxYp9qV5d86xiZV6tRaKMZpPQkrGXoQy3jM9nEzFSMb36+RGWCdbSQFGt+Fple0 9/fZH+iyNFTaQqVUACw7PYCm1HZ4/5cieZvJsk1ApBUjdLnwbkPEBlUV72A2LlwTUbtn R/Tyz2f8uICFcVzpdD9IXpnY2KURLTV7nU1fm9EC0iliRmLkiaTUTQ+rgWucdyS3vJel vdwPGslWDWFySIhjzGKSU72G3A4hCugwKQpNRymoJXG6RqddMGzjeLLQ1moYczy89RA9 PqCawCzkNwdidkQ4gV823cje8cF0Y/02kGqtq6qxNCSAvCjBxaliFuPfcEbTQEJmyWOo Toag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OrCsM1gB; 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 h10-20020a37de0a000000b006b921145770si4657886qkj.449.2022.08.15.12.12.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Aug 2022 12:12:29 -0700 (PDT) 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=OrCsM1gB; 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]:53464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNfVj-00013f-JR for patch@linaro.org; Mon, 15 Aug 2022 15:12:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNfN0-0002y5-Og for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:26 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:56175) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNfMl-0006Kq-Fw for qemu-devel@nongnu.org; Mon, 15 Aug 2022 15:03:26 -0400 Received: by mail-wm1-x32e.google.com with SMTP id d5so1944860wms.5 for ; Mon, 15 Aug 2022 12:03:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=yL2kCSEaX64Q/NPJAtRoJiqW85LCPcZ6AySZ3J3a/uE=; b=OrCsM1gBbnPay5eEdRjbJBP2AlvrnZEpp+mSTgO/wZSFxV6k3MEZT+wNFPoyyAvvCJ ZVyZbYwLV521HVBEJML8Ir58Qs43nc7IqnWmkY9/4vXwdgP50CaLtKW4WHM5TJgWkXY2 1lPNW7FpzR90IqAb7lCsG782CZ/1cKuZvmI9qFo68ih0z1/RmH3FZvvb+G/I9mrDJCV+ tioZJGijJBXlStK2gb22YdzHdxm9hj1C1CvOZ8csBl5aD4Xql8pfaTMyOK1uBAJQbuU9 ZZ3V1iIHK8NKYXeKrR0tkmy+9YDv7wPjC0QELHfar3DXdklqdeIEQ33ewgZdK/gwROoW YcZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=yL2kCSEaX64Q/NPJAtRoJiqW85LCPcZ6AySZ3J3a/uE=; b=CUfXGS83Z2hO9NF6FyvudN+e0+Ip3lECy+IACLNgFrEpzZUBQY4Kw3wl1+eQyNZ9Ty go+HOUcE+YOBXCwTFGbIYu/Zb6Jtg9r27Fnpw1XC7YKWvwWL8VgRT6TAwk4LbFl18+YO u0iPouwF5uLrmzhffoEzMvMZGmnQy4rf6uxe2GZ6YxeixOusIYMdeasui4yZgFB9Xo4D S9yJ+KLY5ffAxvO3b0hTE46KWLTSfXaCj/iRH2CUOAt199/MOj/CVSfSMlKr1vPTBI42 uXV7/trfElPuRk4BdSUg+0JOrL0fLgsEPBcsn+igaZW1YF4Tf86Rt029kUYIv+ccWr9H pT9g== X-Gm-Message-State: ACgBeo0Z92lZqirIpWAot+m1hcMUi0YW7HgfEEnW7ykl9sz77P5woMop XhwusdDUKzkJylnQ+mGRVM/ECg== X-Received: by 2002:a05:600c:4f07:b0:3a3:2277:7064 with SMTP id l7-20020a05600c4f0700b003a322777064mr10859341wmq.181.1660590189958; Mon, 15 Aug 2022 12:03:09 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u4-20020a5d5144000000b00220606afdf4sm8009162wrt.43.2022.08.15.12.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 12:03:09 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aleksandar Rikalo , Stefan Pejic , Chris Wulff , Marek Vasut , Palmer Dabbelt , Alistair Francis , Bin Meng , Max Filippov , Richard Henderson , Furquan Shaikh Subject: [PATCH 2/7] target/arm: Honour -semihosting-config userspace=on Date: Mon, 15 Aug 2022 20:02:58 +0100 Message-Id: <20220815190303.2061559-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220815190303.2061559-1-peter.maydell@linaro.org> References: <20220815190303.2061559-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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" Honour the commandline -semihosting-config userspace=on option, instead of never permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(), instead of manually checking and always forbidding semihosting if the guest is in userspace and this isn't the linux-user build. Signed-off-by: Peter Maydell --- target/arm/translate-a64.c | 12 +----------- target/arm/translate.c | 16 ++++------------ 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 3decc8da573..9bed336b47e 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -2219,17 +2219,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) * it is required for halting debug disabled: it will UNDEF. * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction. */ - if (semihosting_enabled(false) && imm16 == 0xf000) { -#ifndef CONFIG_USER_ONLY - /* In system mode, don't allow userspace access to semihosting, - * to provide some semblance of security (and for consistency - * with our 32-bit semihosting). - */ - if (s->current_el == 0) { - unallocated_encoding(s); - break; - } -#endif + if (semihosting_enabled(s->current_el == 0) && imm16 == 0xf000) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { unallocated_encoding(s); diff --git a/target/arm/translate.c b/target/arm/translate.c index b85be8a818d..54543b7c2a8 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -1169,10 +1169,7 @@ static inline void gen_hlt(DisasContext *s, int imm) * semihosting, to provide some semblance of security * (and for consistency with our 32-bit semihosting). */ - if (semihosting_enabled(false) && -#ifndef CONFIG_USER_ONLY - s->current_el != 0 && -#endif + if (semihosting_enabled(s->current_el != 0) && (imm == (s->thumb ? 0x3c : 0xf000))) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); return; @@ -6556,10 +6553,7 @@ static bool trans_BKPT(DisasContext *s, arg_BKPT *a) /* BKPT is OK with ECI set and leaves it untouched */ s->eci_handled = true; if (arm_dc_feature(s, ARM_FEATURE_M) && - semihosting_enabled(false) && -#ifndef CONFIG_USER_ONLY - !IS_USER(s) && -#endif + semihosting_enabled(s->current_el == 0) && (a->imm == 0xab)) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { @@ -8764,10 +8758,8 @@ static bool trans_SVC(DisasContext *s, arg_SVC *a) { const uint32_t semihost_imm = s->thumb ? 0xab : 0x123456; - if (!arm_dc_feature(s, ARM_FEATURE_M) && semihosting_enabled(false) && -#ifndef CONFIG_USER_ONLY - !IS_USER(s) && -#endif + if (!arm_dc_feature(s, ARM_FEATURE_M) && + semihosting_enabled(s->current_el == 0) && (a->imm == semihost_imm)) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else {