From patchwork Mon Feb 4 13:12:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 157415 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3918929jaa; Mon, 4 Feb 2019 05:30:58 -0800 (PST) X-Google-Smtp-Source: ALg8bN7Yra/7fInGkr3MYgghukcj03H7UeGOBbn5mbWpBK6NUjGCENCqj6aRDzg67jzLxi83PYa9 X-Received: by 2002:a81:78cc:: with SMTP id t195mr49051891ywc.387.1549287058061; Mon, 04 Feb 2019 05:30:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549287058; cv=none; d=google.com; s=arc-20160816; b=Jd3h7NJSbn/vDhO7AKNTdPbrVwwNs9HYiOtbkTweuadl9ZjWsHPUSSKFreYxUP+UUi dpT/4DGDO9h3Zd7EHMTD+GklPKbYlGYIMspJJmwEqp3Q1ubz/EC/aES5n/kAvz39mVst Xl6lVseY26sECbLTA7mIEHEpqB9RLREiE6lKRffPk/DTkS25aiVGXWYyrG5Vg1VfDH3V ljcZ3zqKVeJB1QXB6lxFnj7lgaAmzjiuLyqIQgee+ezeT7aTlvN3VxpHiN8V6EASYhUe fG0Qa9xfOXuIdpDUqNOJ0aMZkVhSzjdryAvApFv8zubcQ4MaSG9la3duhjBUUvL+usIF uNRw== 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=lbyy/bsGi0fyNQlbAg/fxtjNLMInEXPLl5dNrnW4OCZCtXl0yW38RIIXQGAMw5rdzT 0Ns9KsT2Pn4RkOTswSlFHI8DjFw1e2nIqIv5RP5o2HMwlmEjCc47AODpKHRKg11SXnc7 r/gTidJBlXhExvr0EKHozMF/JDay2O0cHBkQoveNh8XJ9FlAjuhxJgFu2sM42JQq9cnS CL9DWU48NLDFw/Vt8eN/uvOh1JgzypFNGmKEJUu6j0gtVho7r2o6h5WI3rtwJOfycUZb QsNVeF9Otn5yQdKYkfxbDQnlM1foG5PatwpG+i51it8QKFuJvjW5YTBNdKjoZ49IUSDT cetg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DF6goOZP; 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 n188si48265ywc.221.2019.02.04.05.30.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 04 Feb 2019 05:30:58 -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=DF6goOZP; 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]:42813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeKv-0007fZ-Fi for patch@linaro.org; Mon, 04 Feb 2019 08:30:57 -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) 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-Received: by 2002:adf:f449:: with SMTP id f9mr50386990wrp.40.1549285960313; 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.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 05:12:39 -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+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)