From patchwork Thu Jan 10 12:17:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 155152 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1839238jaa; Thu, 10 Jan 2019 04:29:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN77P69KRFDDwxZMXeelmwhOh869nhgzwSM0OzZoMdxyhjo25gKB3K+C3ojn0HnHtUjgG0z5 X-Received: by 2002:a7b:c08f:: with SMTP id r15mr9946048wmh.118.1547123380428; Thu, 10 Jan 2019 04:29:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547123380; cv=none; d=google.com; s=arc-20160816; b=OrJcp4tZevnAloeh3PNeJhrQBo+zg/967lS9BxqiQ+Wo7NTXpKnM9ySe2Tlj1+GBpt lgNvn056R6PodyhBIIqIMqeodOZ1a7ju34c1OfvwxWaqokF7m98OunG0D8K/AkVTs0f8 MCiC06Jl+tmXvUb8nB6iMXqLYg8gfLaFeQ0IquORviaqwG+ViQOGpNIbNAkLZuaQj3s1 bHtggWW/j8FcClBOv8nWAHTgTEqdXm2f6GorLqqsZ9yyYgFNu3JSx6k5SNuW2Ofth0xj L0QXgs7/JGDMdZOQlmweW2rClUdWUjwC1rd3FnjtSQG+KfX3egJakyQHIiKgzTLgGLEx DCcw== 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=DkHGGDD7DZ0xeYnvEOJO+AcazmZv0MJI3ad+LhKQaBM=; b=HgdtETFUyBMaLatmWNiHrLhu6vrDSAKEhqG1JX8TDRyUCaKk9F6QNw2dTjLpDc0oWx bPqGaEAE+XZRWhJrwTXDlsuFie2mqt72CrMzg5FSezeEvbmM6O66g/TnghduLsPUyKgc oR0+QKI6sxTzZUBOO2qUGKD7b028lEvgHWfNyCO2fEB9FThKlXT6tIZqPMKOsrjMcgzK +vhzQJhDSJG8O68koggkeH8OBemhuui28qPjD74HscDyrEDTksXOdzKK65dM0ynjOw0V 4/zi96qy6n5Et1wGMrt3+cnLVmUE3VS1+R2mrxpVhN12BC14iUVbVNsIVC5cWDfZaX3s H9kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZWbOKnno; 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 t14si11203841wrp.81.2019.01.10.04.29.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 10 Jan 2019 04:29:40 -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=ZWbOKnno; 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]:59008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZSt-0004qq-Ar for patch@linaro.org; Thu, 10 Jan 2019 07:29:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghZIC-0004ww-Ch for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghZIA-0007vL-CE for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:36 -0500 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:39998) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghZIA-0007lM-5m for qemu-devel@nongnu.org; Thu, 10 Jan 2019 07:18:34 -0500 Received: by mail-pf1-x441.google.com with SMTP id i12so5226894pfo.7 for ; Thu, 10 Jan 2019 04:18:12 -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=DkHGGDD7DZ0xeYnvEOJO+AcazmZv0MJI3ad+LhKQaBM=; b=ZWbOKnnoVob0MUDon/MRZWEq8OtvqHwAOpVhlbbnFPFssNXnwD9e8xlqZSMkmTpZRX sPR+Ng7H7YxNmdDeB63qrJNP3FTGvoESiXppuiBEpfeQapQj8JGsZ+94wbITps2PDTPR lQfCqO5QP166uuiW2Adytxrn3l0oQFHPGPymo= 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=DkHGGDD7DZ0xeYnvEOJO+AcazmZv0MJI3ad+LhKQaBM=; b=D3/w2VlA6+zMiPtYYqWoxRkCwCJPocHT9/KG/6kY7jFjZs4PadhBDe6BcYQBndHUkF EXNq1LKZKgA/hXnV0Ahts4S5Ryw+yBF4DqcUPdiulOphaypN/OfYPsJhnhDGN6hEYbik qW1QAlsJ4OGbNQjNfQpQbba61VnuogUSiNdKJ3N8FqbCJHL/9LWq2lmNOYl7+FAlW5xT 9KcX0EXmqOtwTUOzREOKbz29WLxWbKq6cCo3n10PZ/ecosYFVhH0XMQfJZUeamN0R9VR l1GmKA9QtPbqxoh4npxSCJQ0Xl8Hcux1w49cn4IbDklyIj6lKXaV9nzQsu/7jmV0BQVU VHEg== X-Gm-Message-State: AJcUukf/isM6U1L8Bfme12srhbnGrJXyjFsk1UD8p+M15zjHRKfcwJpR +wacHqLV8VZv7u8JfIELxUALP1kWnQVAmw== X-Received: by 2002:a62:8e19:: with SMTP id k25mr9978801pfe.185.1547122691272; Thu, 10 Jan 2019 04:18:11 -0800 (PST) Received: from cloudburst.twiddle.net (c220-239-117-135.belrs4.nsw.optusnet.com.au. [220.239.117.135]) by smtp.gmail.com with ESMTPSA id h74sm140934699pfd.35.2019.01.10.04.18.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 04:18:10 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 23:17:36 +1100 Message-Id: <20190110121736.23448-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190110121736.23448-1-richard.henderson@linaro.org> References: <20190110121736.23448-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::441 Subject: [Qemu-devel] [PATCH 11/11] 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..3d56e7c6ea 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,guarded_pages=on + +TESTS:=$(AARCH64_TESTS)