From nobody Sun Apr 28 22:52:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549286880513443.6964551400873; Mon, 4 Feb 2019 05:28:00 -0800 (PST) Received: from localhost ([127.0.0.1]:42775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeHy-0005fD-BX for importer@patchew.org; Mon, 04 Feb 2019 08:27:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeC2-00010y-05 for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:21:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqe3P-0002cN-GT for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:12:52 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:40957) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gqe3P-000244-7Q for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:12:51 -0500 Received: by mail-wm1-x32a.google.com with SMTP id f188so13378113wmf.5 for ; Mon, 04 Feb 2019 05:12:37 -0800 (PST) Received: from cloudburst.twiddle.net (host81-133-38-158.in-addr.btopenworld.com. [81.133.38.158]) by smtp.gmail.com with ESMTPSA id z9sm22283025wrs.63.2019.02.04.05.12.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 05:12:35 -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; bh=0GfXFPH+bA70OWj0aXJdKkY3vjWPFrkkY8GJhmcgmoA=; b=S245WnOkTj7AAzIW97Xnb7E2ElqnCRndsRD6BKoGtykUdsbaZTxm25qoYBpZp2nLs2 T60s1Pdi9Udx/oDPjP2RBSaeHZd4inxjsOgfpJ4cS+Cn9uRnvvxSBguLxFpsDrSGKPwr KsfIJwSmfpXKmle7NsgWD9g6V0bYTcBKfFQhU= 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; bh=0GfXFPH+bA70OWj0aXJdKkY3vjWPFrkkY8GJhmcgmoA=; b=E9y2PfLe2xOPawRsomZKpwY29NwagCXXBJKDBiCskKR7IeKad1GpM6B/V7QZ25aNyT wHqH1ySEJo8NKEc6jA3JbEOsFt2a47xMYXVatZk2uR+HOXj+5D2AdPnG+elDbq3r0gc/ NBvPkSg0K0T2YQARB+aCS2aGnqoSA9WcmNpb/79jkvm/w/O2C9zhMVFtHojuUvrjb+gn fYYFmjPQhyU0snub24Po1JfKVy5zZ7v/g1lF2fO7bErOYTm6b0RN68eR62wm1YDi2vKb DgtH7xAtVrx+gODakxcBHJdyDN7r/7AaKd0lV3HH0u88KOWiPiPjlF4SPPSxAjxXx/f5 EOJw== X-Gm-Message-State: AHQUAuaW+TOxpaywLIBUGW/pdyu3WdPD2qcsz8d6Acykty517LcJpZPD VuF4SlegbKCXCi7SNBbQgGQDdAYpCr4doA== X-Google-Smtp-Source: AHgI3IYA3GJc2G9NEAw/pDum91+/Y5YRuYhVQek0hmOQMOqf5XmJG24esya+ZniZ5rpbS2o8d6CACg== X-Received: by 2002:a1c:6607:: with SMTP id a7mr12976366wmc.129.1549285956279; Mon, 04 Feb 2019 05:12:36 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 13:12:25 +0000 Message-Id: <20190204131228.25949-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190204131228.25949-1-richard.henderson@linaro.org> References: <20190204131228.25949-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32a Subject: [Qemu-devel] [PATCH v3 1/4] fixup! target/arm: Cache the GP bit for a page in MemTxAttrs 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We talked about changing this, but missed when applying to target-arm.next. --- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 2edf84b898..be0ec7de2a 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10757,7 +10757,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, ta= rget_ulong address, } /* Merge in attributes from table descriptors */ attrs |=3D nstable << 3; /* NS */ - guarded |=3D extract64(descriptor, 50, 1); /* GP */ + guarded =3D extract64(descriptor, 50, 1); /* GP */ if (param.hpd) { /* HPD disables all the table attributes except NSTable. */ break; --=20 2.17.2 From nobody Sun Apr 28 22:52:53 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549286821186176.80398163568236; Mon, 4 Feb 2019 05:27:01 -0800 (PST) Received: from localhost ([127.0.0.1]:42771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeGv-0004jq-HO for importer@patchew.org; Mon, 04 Feb 2019 08:26:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeC2-0000pZ-4E for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:21:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqe3P-0002bM-C5 for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:12:52 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:33833) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gqe3P-00025a-2Y for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:12:51 -0500 Received: by mail-wm1-x341.google.com with SMTP id y185so10057755wmd.1 for ; Mon, 04 Feb 2019 05:12:39 -0800 (PST) Received: from cloudburst.twiddle.net (host81-133-38-158.in-addr.btopenworld.com. [81.133.38.158]) by smtp.gmail.com with ESMTPSA id z9sm22283025wrs.63.2019.02.04.05.12.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 05:12:36 -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; bh=gn75mc+OMgblL2fopLWb2r86Mz9qxLDmnmE1KtGd/sQ=; b=D8POpQhmQBSqOi4itPMuZDutl35p4bs/6QbEWoYm7kx74ZxrRIWWF36YlPLy4zF/vC mwB6it1Z+rCOzi5YfWNuYGEhbdjDNcYrRdedzv9TOkLDzB1SebJoSUeSTACnxxYIpf0f yLdBX9+yeC/4rnTI8zA3LdgtDcbSg+PdbGifU= 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; bh=gn75mc+OMgblL2fopLWb2r86Mz9qxLDmnmE1KtGd/sQ=; b=DNPPWdXrDIve/oxcfIiZgb+aHbxZKObb/b6/NC65KBaiTNcmzMHAgBFFmHpp5mr+Tx XB2VJWb5uWZW7UxIa/YrCPHSBWg/SkG8ECMqOl48J/x++wksCmMclILjmJIYMRNNDjWq IpWS1vz3E3AafnBtnVqZbxGlfcXD2TmkEKJZfhSSHSwTaec5nmxp1Q2fpNwJHyOpKbeH LCroxWwRA72CD1G6gx3FqSnIaAAfozIugYxmesW3j6+2nAixtCGu3lVv4rF5w5aT3P7/ cvKw97fKGd5Z4vCLXQM1ZytXbc715LcNz4pLU54oYax1Ir3jXfiXiK+xrBwTQnPLcmu+ EWkg== X-Gm-Message-State: AHQUAuZHaIaa6Iyoofs3o1i8ubj/D9SzzGWX/akAcZzd3ap0Ml43++2w 7ICVOoPs9jmrqJmzEf962D7ZESYIBoygMA== X-Google-Smtp-Source: AHgI3IbvlG2ZgkY2nCDGdemkIh6NntXR7MeO4OCx/j6PU00gjThwBAPpcBBLqqR/fIjlVZFeUv/FCA== X-Received: by 2002:a7b:c399:: with SMTP id s25mr13845875wmj.90.1549285957739; Mon, 04 Feb 2019 05:12:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 13:12:26 +0000 Message-Id: <20190204131228.25949-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190204131228.25949-1-richard.henderson@linaro.org> References: <20190204131228.25949-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PATCH v3 2/4] target/arm: Add x-guarded-pages cpu property for user-only 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" While waiting for a proper userland ABI, allow static test cases to be written assuming that GP is set for all pages. Signed-off-by: Richard Henderson --- v2: Renamed the property with x- prefix --- target/arm/cpu.h | 4 ++++ target/arm/cpu64.c | 20 ++++++++++++++++++++ target/arm/translate-a64.c | 8 +++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 1ff7197efd..366ab97db3 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -900,6 +900,10 @@ struct ARMCPU { */ bool cfgend; =20 +#ifdef CONFIG_USER_ONLY + bool guarded_pages; +#endif + QLIST_HEAD(, ARMELChangeHook) pre_el_change_hooks; QLIST_HEAD(, ARMELChangeHook) el_change_hooks; =20 diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index eff0f164dd..c5675fe7d1 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -281,6 +281,20 @@ static void cpu_max_set_sve_vq(Object *obj, Visitor *v= , const char *name, error_propagate(errp, err); } =20 +#ifdef CONFIG_USER_ONLY +static bool aarch64_cpu_get_guarded_pages(Object *obj, Error **errp) +{ + ARMCPU *cpu =3D ARM_CPU(obj); + return cpu->guarded_pages; +} + +static void aarch64_cpu_set_guarded_pages(Object *obj, bool val, Error **e= rrp) +{ + ARMCPU *cpu =3D ARM_CPU(obj); + cpu->guarded_pages =3D val; +} +#endif + /* -cpu max: if KVM is enabled, like -cpu host (best possible with this ho= st); * otherwise, a CPU with as many features enabled as our emulation support= s. * The version of '-cpu max' for qemu-system-arm is defined in cpu.c; @@ -360,6 +374,12 @@ static void aarch64_max_initfn(Object *obj) */ cpu->ctr =3D 0x80038003; /* 32 byte I and D cacheline size, VIPT i= cache */ cpu->dcz_blocksize =3D 7; /* 512 bytes */ + + object_property_add_bool(obj, "x-guarded-pages", + aarch64_cpu_get_guarded_pages, + aarch64_cpu_set_guarded_pages, NULL); + object_property_set_description(obj, "x-guarded-pages", + "Set on/off GuardPage bit for all pages", NULL); #endif =20 cpu->sve_max_vq =3D ARM_MAX_VQ; diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 7375ebf7a9..37077138e3 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -13817,7 +13817,13 @@ static void disas_data_proc_simd_fp(DisasContext *= s, uint32_t insn) static bool is_guarded_page(CPUARMState *env, DisasContext *s) { #ifdef CONFIG_USER_ONLY - return false; /* FIXME */ + /* + * FIXME: What is the userland ABI for this? + * For the moment this is controlled by an attribute: + * -cpu max,guarded_pages=3Don. + */ + ARMCPU *cpu =3D arm_env_get_cpu(env); + return cpu->guarded_pages; #else uint64_t addr =3D s->base.pc_first; int mmu_idx =3D arm_to_core_mmu_idx(s->mmu_idx); --=20 2.17.2 From nobody Sun Apr 28 22:52:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549287193765395.13296939252064; Mon, 4 Feb 2019 05:33:13 -0800 (PST) Received: from localhost ([127.0.0.1]:42875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeN1-0001RZ-NA for importer@patchew.org; Mon, 04 Feb 2019 08:33:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeC2-000110-In for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:21:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqe3P-0002bU-CY for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:12:52 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:54503) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gqe3P-00027S-2P for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:12:51 -0500 Received: by mail-wm1-x342.google.com with SMTP id a62so13134249wmh.4 for ; Mon, 04 Feb 2019 05:12:40 -0800 (PST) Received: from cloudburst.twiddle.net (host81-133-38-158.in-addr.btopenworld.com. [81.133.38.158]) by smtp.gmail.com with ESMTPSA id z9sm22283025wrs.63.2019.02.04.05.12.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 05:12:38 -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; bh=1yNoac1ShBnXw/zdOxjpmLH8NTh7CPRm4nWUT3FtlnU=; b=X4aMjpUz18dlq8P0P5vGpst/OI30cR1MBmnGhQs4TTR12ckntJvSqs1MDg4YYgeKjO 09s11Z9OSV056cbuXfx1IfGriN+1SAK+APHf1aX2QzyhHigbRnft/N1F+5J157uUdPK9 YA+pitMqWkvdKEBCMcJEaj1yB6abLiBYc5ISE= 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; bh=1yNoac1ShBnXw/zdOxjpmLH8NTh7CPRm4nWUT3FtlnU=; b=UQ62owgGwpMy87f7FyAE0WQE9BQ9Ern1WhhnXVHSUfQ1QHRxFGK5WWldxGNV9WcETf DE3VewqSOhALWwi/drYZMJNHPDLshX9WMXpBsuWJiQtKVptFuf6qSIVnnezvRVSGRdKY z84cacAQ/mYQqJWy7dhAA7g570USsdBXDOsYCx+g/D9zt0Q5FzORWpON8f0lCtgjh86S pm+o0yScFwiRVsLYfp1E8F9d0NXxzRaf6UEVr+kc1I+XRkwYkq4RoeAIkWJa0MmaguQQ O+JLTdoW2LyH3bGti23Zyyjyb2oiODlZh67x3rtiutGcamcOxzaA+oSB9HFv018srevj eRzQ== X-Gm-Message-State: AHQUAuYS1x71Xk7bvdU990h43U0TiAx3PHM05ZsKFFFpVzYTAtIEEePk gHKSPcHUgn7Tdf4+hi6HSJcJAEBWtjH/yw== X-Google-Smtp-Source: AHgI3IYnOU2/SOXpdfLpFvJ8mWeKf1rzuLTNuCQ7OfmmNusDrcz3aGnAa/swmGdScb1owZeBPlDQsg== X-Received: by 2002:a1c:2c6:: with SMTP id 189mr13045736wmc.21.1549285959070; Mon, 04 Feb 2019 05:12:39 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 13:12:27 +0000 Message-Id: <20190204131228.25949-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190204131228.25949-1-richard.henderson@linaro.org> References: <20190204131228.25949-1-richard.henderson@linaro.org> 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 v3 3/4] linux-user/aarch64: Reset btype for syscalls and signals 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The value of btype for syscalls is CONSTRAINED UNPREDICTABLE, so we need to make sure that the value is 0 before clone, fork, or syscall return. The value of btype for signals is defined, but it does not make sense for a SIGILL handler to enter with the btype set as for the indirect branch that caused the SIGILL. Clearing the value early means that btype is zero within the pstate saved into the signal frame, and so is also zero on (normal) signal return, but also allows the signal handler to adjust the value as seen after the sigcontext restore. This last is a guess at a future kernel's user-space ABI. Signed-off-by: Richard Henderson --- v3: Do not clear btype for semihost. --- linux-user/aarch64/cpu_loop.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index d75fd9d3e2..3f046dbbd7 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -83,8 +83,19 @@ void cpu_loop(CPUARMState *env) cpu_exec_end(cs); process_queued_cpu_work(cs); =20 + /* + * The state of BTYPE on syscall and interrupt entry is CONSTRAINED + * UNPREDICTABLE. The real kernel will need to tidy this up as we= ll. + * Do this before syscalls and signals, so that the value is corre= ct + * both within signal handlers, and on return from syscall (especi= ally + * clone & fork) and from signal handlers. + * + * The SIGILL signal handler, for BTITrap, can see the failing BTY= PE + * within the ESR value in the signal frame. + */ switch (trapnr) { case EXCP_SWI: + env->btype =3D 0; ret =3D do_syscall(env, env->xregs[8], env->xregs[0], @@ -104,6 +115,7 @@ void cpu_loop(CPUARMState *env) /* just indicate that signals should be handled asap */ break; case EXCP_UDEF: + env->btype =3D 0; info.si_signo =3D TARGET_SIGILL; info.si_errno =3D 0; info.si_code =3D TARGET_ILL_ILLOPN; @@ -112,6 +124,7 @@ void cpu_loop(CPUARMState *env) break; case EXCP_PREFETCH_ABORT: case EXCP_DATA_ABORT: + env->btype =3D 0; info.si_signo =3D TARGET_SIGSEGV; info.si_errno =3D 0; /* XXX: check env->error_code */ @@ -121,6 +134,7 @@ void cpu_loop(CPUARMState *env) break; case EXCP_DEBUG: case EXCP_BKPT: + env->btype =3D 0; info.si_signo =3D TARGET_SIGTRAP; info.si_errno =3D 0; info.si_code =3D TARGET_TRAP_BRKPT; --=20 2.17.2 From nobody Sun Apr 28 22:52:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549287017947613.7477004858084; Mon, 4 Feb 2019 05:30:17 -0800 (PST) Received: from localhost ([127.0.0.1]:42813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeK9-0007fZ-9A for importer@patchew.org; Mon, 04 Feb 2019 08:30:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeC2-0000pe-4E for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:21:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqe3P-0002bq-Dq for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:12:52 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:38044) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gqe3P-0002Bi-3z for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:12:51 -0500 Received: by mail-wr1-x441.google.com with SMTP id v13so14305456wrw.5 for ; Mon, 04 Feb 2019 05:12:41 -0800 (PST) Received: from cloudburst.twiddle.net (host81-133-38-158.in-addr.btopenworld.com. [81.133.38.158]) by smtp.gmail.com with ESMTPSA id z9sm22283025wrs.63.2019.02.04.05.12.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 05:12:39 -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; bh=y0k/H38xJNqLR/HphofIOtky77ujQ33o+YBmpOTNSTs=; b=DF6goOZP32Yb6jONXDDD6p4I1H43G6GwdQ5fkKp2UmX3qwvl6vlUN7lS3KzUQzYL41 nOSN+AFY/hZvxDCmIXUJVTTsH15/mtW9hkj9S2AL14rTByNu/Yk8b4dSms/WbgJ6tOvg GPyis9CKsDUYUJpc6+pBK1WBTf8aafR4Y1qKg= 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; bh=y0k/H38xJNqLR/HphofIOtky77ujQ33o+YBmpOTNSTs=; b=WDmX1DM1bAuobEwkmopxj++HG27lkMlPZIR/ht3p+eAq+ZEolYLKIb8grUaMg+0gK9 QREaYlVqpPk+rNHukPiIoICTkNKqbjuy9Afh3igRD0a+zlqM77ri9LBQJOTFMHNUfhZs cYocYorCV/5y/wQCRERSugbuJtrDmV+TaXroWVIwSExmePQ0P9Gt798aeHQm0Mfq28Kb FEhoOPvV5LIYiD5QgDnSghYgmOE/huAXEwX6YfxvGFegpc8+viRg0kGzklGfxdb+smht sCise0t1u7jYsBYcyhfO2lXBvtGHwJjrGi3L/w3y1mdru4RIDjDnRukEWtIUb98EBVYB HxtQ== X-Gm-Message-State: AJcUukcCHE36Dxu4/xWvtdGlKmXZxi9L+FICnBttr0hpVS+ldgKdQTa8 kDM9YQdB2jOPUZ7Kq6qPAl/ZHIFyh5e3Ww== X-Google-Smtp-Source: ALg8bN6aFxMKY69677qr6yu8gIA2/bDFx6T4Ubkv6XBQrqWkhqb9CIObrD9BQt082tjtX3hFdoFVhQ== X-Received: by 2002:adf:f449:: with SMTP id f9mr50386990wrp.40.1549285960313; Mon, 04 Feb 2019 05:12:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 13:12:28 +0000 Message-Id: <20190204131228.25949-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190204131228.25949-1-richard.henderson@linaro.org> References: <20190204131228.25949-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v3 4/4] tests/tcg/aarch64: Add bti smoke test 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- tests/tcg/aarch64/bti-1.c | 61 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/bti-crt.inc.c | 51 ++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 7 +++- 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/aarch64/bti-1.c create mode 100644 tests/tcg/aarch64/bti-crt.inc.c diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c new file mode 100644 index 0000000000..fa8a521a47 --- /dev/null +++ b/tests/tcg/aarch64/bti-1.c @@ -0,0 +1,61 @@ +/* + * Branch target identification, basic notskip cases. + */ + +#include "bti-crt.inc.c" + +static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc) +{ + uc->uc_mcontext.pc +=3D 8; +} + +#define NOP "nop" +#define BTI_N "hint #32" +#define BTI_C "hint #34" +#define BTI_J "hint #36" +#define BTI_JC "hint #38" + +#define BTYPE_1(DEST) \ + asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \ + : "=3Dr"(skipped) : : "x16") + +#define BTYPE_2(DEST) \ + asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \ + : "=3Dr"(skipped) : : "x16", "x30") + +#define BTYPE_3(DEST) \ + asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \ + : "=3Dr"(skipped) : : "x15") + +#define TEST(WHICH, DEST, EXPECT) \ + do { WHICH(DEST); fail +=3D skipped ^ EXPECT; } while (0) + + +int main() +{ + int fail =3D 0; + int skipped; + + /* Signal-like with SA_SIGINFO. */ + signal_info(SIGILL, skip2_sigill); + + TEST(BTYPE_1, NOP, 1); + TEST(BTYPE_1, BTI_N, 1); + TEST(BTYPE_1, BTI_C, 0); + TEST(BTYPE_1, BTI_J, 0); + TEST(BTYPE_1, BTI_JC, 0); + + TEST(BTYPE_2, NOP, 1); + TEST(BTYPE_2, BTI_N, 1); + TEST(BTYPE_2, BTI_C, 0); + TEST(BTYPE_2, BTI_J, 1); + TEST(BTYPE_2, BTI_JC, 0); + + TEST(BTYPE_3, NOP, 1); + TEST(BTYPE_3, BTI_N, 1); + TEST(BTYPE_3, BTI_C, 1); + TEST(BTYPE_3, BTI_J, 0); + TEST(BTYPE_3, BTI_JC, 0); + + return fail; +} diff --git a/tests/tcg/aarch64/bti-crt.inc.c b/tests/tcg/aarch64/bti-crt.in= c.c new file mode 100644 index 0000000000..ef7831ad76 --- /dev/null +++ b/tests/tcg/aarch64/bti-crt.inc.c @@ -0,0 +1,51 @@ +/* + * Minimal user-environment for testing BTI. + * + * Normal libc is not built with BTI support enabled, and so could + * generate a BTI TRAP before ever reaching main. + */ + +#include +#include +#include +#include + +int main(void); + +void _start(void) +{ + exit(main()); +} + +void exit(int ret) +{ + register int x0 __asm__("x0") =3D ret; + register int x8 __asm__("x8") =3D __NR_exit; + + asm volatile("svc #0" : : "r"(x0), "r"(x8)); + __builtin_unreachable(); +} + +/* + * Irritatingly, the user API struct sigaction does not match the + * kernel API struct sigaction. So for simplicity, isolate the + * kernel ABI here, and make this act like signal. + */ +void signal_info(int sig, void (*fn)(int, siginfo_t *, ucontext_t *)) +{ + struct kernel_sigaction { + void (*handler)(int, siginfo_t *, ucontext_t *); + unsigned long flags; + unsigned long restorer; + unsigned long mask; + } sa =3D { fn, SA_SIGINFO, 0, 0 }; + + register int x0 __asm__("x0") =3D sig; + register void *x1 __asm__("x1") =3D &sa; + register void *x2 __asm__("x2") =3D 0; + register int x3 __asm__("x3") =3D sizeof(unsigned long); + register int x8 __asm__("x8") =3D __NR_rt_sigaction; + + asm volatile("svc #0" + : : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory= "); +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 08c45b8470..b529a8c9c9 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -8,10 +8,15 @@ VPATH +=3D $(AARCH64_SRC) # we don't build any of the ARM tests AARCH64_TESTS=3D$(filter-out $(ARM_TESTS), $(TESTS)) AARCH64_TESTS+=3Dfcvt -TESTS:=3D$(AARCH64_TESTS) =20 fcvt: LDFLAGS+=3D-lm =20 run-fcvt: fcvt $(call run-test,$<,$(QEMU) $<, "$< on $(TARGET_NAME)") $(call diff-out,$<,$(AARCH64_SRC)/fcvt.ref) + +AARCH64_TESTS +=3D bti-1 +bti-1: LDFLAGS +=3D -nostartfiles -nodefaultlibs -nostdlib +run-bti-1: QEMU +=3D -cpu max,x-guarded-pages=3Don + +TESTS:=3D$(AARCH64_TESTS) --=20 2.17.2