From patchwork Mon Jan 28 22:31:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156903 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3961769jaa; Mon, 28 Jan 2019 14:46:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN7rsR3KVDsL6+YndPxj64MM4J2o/TJLYQuvZdpNd2KQqHS8mnis/gMDfwXPzrBNYVz7r1YL X-Received: by 2002:a5d:494a:: with SMTP id r10mr24138170wrs.272.1548715566406; Mon, 28 Jan 2019 14:46:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548715566; cv=none; d=google.com; s=arc-20160816; b=irBL7BjBx+OavvrnQLZ8Ry14iWuyfjeiWp+fR1vXqmWf4CwIi2xFkrxGoc+J79Fwvu Bj0smhwtyGnvnOurXICLLt7XpcLw6ndV6lONd3OokDjvtEE+D7Ho60V/C2smCnlmicyq oBr++FYWoVJHhfuKVEJLfiLFued6oOfv8iWleVc9KsnrnMxLx2iwh7Wwj5WWYwLCQfpR sVKpnSx95SvkR7kPh91EddIsS224JsnwGDDF7Zh/YZ/GVBcDx9FIVgf/aV6YeSBOQq7F fLHp9LGPCPyjKY2LhTHS39ibrWagi3OaYcbanHMoqXEzObdFOU+dD0a1E+n2JJGVrU2a HYdA== 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:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=y0k/H38xJNqLR/HphofIOtky77ujQ33o+YBmpOTNSTs=; b=IUKK0u4uxfWW2uIGk8SABZyodT3cULVeNqu3fM8hp0OISCga2I05uHxMYjjnXdCoCt Sm2fnuiSUCM6k7EISwl5hDJLkPUpS1PBQ2dpKb5wMCnLYTjvcN2gypFTnWpS1OV4BGd7 5pqOIcmvSLJcuCwaJ5x2AsYjPzU4PlSptA/sh5pzoIAwGE0oIzeqWJPEFFcTedIkeVk1 h8DgWT4SwzRN3XM2nlIf0TGTqHCblus13t1wPTptpwf3oDCBPMn7ehG3BVes7E2NyGan SWPW6nM9k13FN1ku107z4/7+kY5KIE2hgSkk/4JXtqHRIIccdLuJ5ksCfKq2ME8KB6BO FCBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=D9WGvklm; 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=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 i17si9387877wrx.310.2019.01.28.14.46.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 14:46:06 -0800 (PST) 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=fail header.i=@linaro.org header.s=google header.b=D9WGvklm; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:39605 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFfJ-0008Np-8o for patch@linaro.org; Mon, 28 Jan 2019 17:46:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goFcA-0006iZ-1y for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:42:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goFRU-0006LD-IW for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:50 -0500 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]:42910) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goFRS-0006Fn-Ty for qemu-devel@nongnu.org; Mon, 28 Jan 2019 17:31:47 -0500 Received: by mail-ot1-x342.google.com with SMTP id v23so16154552otk.9 for ; Mon, 28 Jan 2019 14:31: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=D9WGvklmHUrmvl12m6DcI7j1Cwv/PNa/94u/02x2EPz4wNzIl2IJYqV2iZEf8oHDn4 hRuwltnEdQL6CT4+0ShoCpU0Q/O+YIkbZw4BW+OwOvMQdLTvkkiFzUZZhqUzKImFUlJa Fk4PxoFN/cEzZGAWStyMCgrbLSR0H1yTxDaok= 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=rqqHr8RgjqEke/y4gXvJKjsAcaDiWB9LXE90bOOu/Kfrd8Wv1scRA3nH3/FF9yam+k MA9fb1hT0zwy7wf2dWcoo0ERI4kNizfQUyqhrsHQMHwW0jY/hEfu4Ld9o4K4B5aAlqek 1rwLwgCEmN9oTgJH/ckRhDvJL0gSLfYoC9eEDGiDvv/T4tdMFnQU8kVJHefBmlEeaOXb uuP9F00SOq7IBe17WozxRuDVfp5pyz++ShjTRGjC936c6/LHW1qRQZL25dJpNL7lEw5e PEucxJn6uBap+EmA1HT2iRkaCQJU5SUDzYhuqOENiMLpTt/X41gjUbs4kjsQuj7kKDyG mMJg== X-Gm-Message-State: AJcUukfeqHwfXrbFUry38R2n7h6qLbbX2s2REYO+yyd/t0hgNyytu0Pc Sounf8Cparc46LUFNUQp+qR/ju3gEqk= X-Received: by 2002:a9d:a2e:: with SMTP id 43mr16449151otg.8.1548714698845; Mon, 28 Jan 2019 14:31:38 -0800 (PST) Received: from cloudburst.twiddle.net ([12.227.73.85]) by smtp.gmail.com with ESMTPSA id v3sm7460438oib.57.2019.01.28.14.31.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 14:31:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 14:31:18 -0800 Message-Id: <20190128223118.5255-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190128223118.5255-1-richard.henderson@linaro.org> References: <20190128223118.5255-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::342 Subject: [Qemu-devel] [PATCH v2 12/12] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 -- 2.17.2 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 += 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" \ + : "=r"(skipped) : : "x16") + +#define BTYPE_2(DEST) \ + asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \ + : "=r"(skipped) : : "x16", "x30") + +#define BTYPE_3(DEST) \ + asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \ + : "=r"(skipped) : : "x15") + +#define TEST(WHICH, DEST, EXPECT) \ + do { WHICH(DEST); fail += skipped ^ EXPECT; } while (0) + + +int main() +{ + int fail = 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.inc.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") = ret; + register int x8 __asm__("x8") = __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 = { fn, SA_SIGINFO, 0, 0 }; + + register int x0 __asm__("x0") = sig; + register void *x1 __asm__("x1") = &sa; + register void *x2 __asm__("x2") = 0; + register int x3 __asm__("x3") = sizeof(unsigned long); + register int x8 __asm__("x8") = __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 += $(AARCH64_SRC) # we don't build any of the ARM tests AARCH64_TESTS=$(filter-out $(ARM_TESTS), $(TESTS)) AARCH64_TESTS+=fcvt -TESTS:=$(AARCH64_TESTS) fcvt: LDFLAGS+=-lm run-fcvt: fcvt $(call run-test,$<,$(QEMU) $<, "$< on $(TARGET_NAME)") $(call diff-out,$<,$(AARCH64_SRC)/fcvt.ref) + +AARCH64_TESTS += bti-1 +bti-1: LDFLAGS += -nostartfiles -nodefaultlibs -nostdlib +run-bti-1: QEMU += -cpu max,x-guarded-pages=on + +TESTS:=$(AARCH64_TESTS)