From patchwork Wed May 20 14:05:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 186984 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp652807ilb; Wed, 20 May 2020 07:09:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+JOK5btIIpzypvKk9SalqX8CaI8gR9BaW0P0rPUz+AKq3gTUFejlJIfrQKNriKU//woIj X-Received: by 2002:ac8:4a88:: with SMTP id l8mr5184424qtq.337.1589983779301; Wed, 20 May 2020 07:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589983779; cv=none; d=google.com; s=arc-20160816; b=YNr7iiww88yXgDVbXZ/qpA3eyGgiPCcxqQAspap5RmUNJ0YJH6rUjmugkRzIu0dsBI 1qS4CasIEUIJxiTe6Tmhit+GkN5+rUmf77BGb23dN0jaUaxM8Ll6r+Awlso62KBhO0+3 tCDSInRcGej2NNz5f44EK9hAHk3yAGPqcjTOnSsBGmn3JuLOjX4NnzVq5hGTwqqnD+74 +XWeyTXTRqO7wYhORJEO4lHdCmyC5WH6qKBcLXATBewstFUzP6a4Z88hc7R520PepISG StQkhiGL2QWSMLKXkKNCd3prFutjs+eGPJHQnvL72X+cD49CXiqIoIK+BS3VVO854tGn KgwA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=OnH5KqCVhWj9cyXiWz451vuApV6MafEp8c06IXaPDWI=; b=DhExLeL9lFjOXC7Kw/aDQAF6Nin8u6mAQyttGd3nNxChN9FewufyYfo9eNyyHeaiXk ueUMSE3kJdibFm1+xX6cKqg3U+UkzfxqMaxPeOdP/5Y114nN1Efi4zn7bVUEPeOqL4oD 9hYPJe43pgI0aoQbni7G0gxH7GkzsLW7Z4DBrQR61LAVK9OfVo6tsSu1MXIeJO4IPwhA 6JuD8S1dVgQRCy8NwqBXOqCnOKBi5ryRBnAmqFwqOPCKQj75B/w+HIyLxV+Ludsw7zCl XMGbSeUTCW7jHyGMQmcfJ9bDduz1obwlQn82wAmpfQ8Z8IyswE7hfV2FLClnVm385+kg t5cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MEb5p9Fq; 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 e9si1645261qtg.398.2020.05.20.07.09.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 May 2020 07:09:39 -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=fail header.i=@linaro.org header.s=google header.b=MEb5p9Fq; 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 ([::1]:40466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbPPe-0005cT-ND for patch@linaro.org; Wed, 20 May 2020 10:09:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbPM9-0000Jl-VO for qemu-devel@nongnu.org; Wed, 20 May 2020 10:06:05 -0400 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]:35269) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbPM7-00021P-TA for qemu-devel@nongnu.org; Wed, 20 May 2020 10:06:01 -0400 Received: by mail-ed1-x541.google.com with SMTP id be9so3198333edb.2 for ; Wed, 20 May 2020 07:05:59 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=OnH5KqCVhWj9cyXiWz451vuApV6MafEp8c06IXaPDWI=; b=MEb5p9Fq08K/9ndYREC/gwvkLrVm8MJVEgOVEZcaTRlqPmqmNCscLj8vk3s3GFJzhS xfqzARF8aFGNXUVbQZRkuqWyexguHlZUyqgp7lvIfqg9fIu+Q/7ygC6uWAbwra3pLvjH kq0P5XxSnQcw9URbzTubjYFYSZceSjI6OzOUaFUhGsJWqMrBJZIlAOLp3I3mMXWhVGU+ UWPG1nYAFHC9WRIoFflSarx6Avs8tQ7i4BGQb16ILKl77s6wuy/KqgOkCbA1qMp5iwLC C/WtcMm15fcvhAWctIT9O4WOcp6izd/4VpWAilGKTTsdo4Qvckny05ZcukGafSGLlhyp CnyQ== 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:mime-version:content-transfer-encoding; bh=OnH5KqCVhWj9cyXiWz451vuApV6MafEp8c06IXaPDWI=; b=dcWSFsF5EJwqoqPzCarcr/yB/vAEkZxoywecLhlvb+aIV0OqWlFglBGTM2nGP3DvyA fYO3+rn4EkMjgxUF6kPuueMQ+ilfmRCFRLKUXUJ8eM6pqWmIE+eS9fUH/ix+3HCMyGi1 /tjTJYQ3LvipRDRAGF3g353GPaO7BWpccy9iBYk7HJESSFjnLQ69gQXH2ZW4IopGXI7J QtQxfymdAmNOtr+WDfBv3502yuLseUuyv6lCeoREIvhlIMANzgkR9tcMsKurkyNBtQLn AHSiN9v/bhDzg2ec0H1adNVOu+pkflcFjZ595lMNI77WjZFHpzxFPjM4kOFNmGbYI28W wKLw== X-Gm-Message-State: AOAM5321UU54mrP5ovK7ClDmjzGPQz3qeA8k8qPILJnkOD7gDC5UADCc Unb5lz2HfNQvTldUd99pjLzhhxu/kSU= X-Received: by 2002:a05:6402:c11:: with SMTP id co17mr3630780edb.218.1589983558259; Wed, 20 May 2020 07:05:58 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id bi7sm1984952edb.17.2020.05.20.07.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 07:05:49 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 356041FF9A; Wed, 20 May 2020 15:05:42 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 11/15] tests/tcg/aarch64: Add bti smoke test Date: Wed, 20 May 2020 15:05:37 +0100 Message-Id: <20200520140541.30256-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200520140541.30256-1-alex.bennee@linaro.org> References: <20200520140541.30256-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::541; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , "open list:ARM TCG CPUs" , Richard Henderson , Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Requires gcc 10 for -mbranch-protection=standard. Signed-off-by: Richard Henderson Message-Id: <20200520023139.9812-3-richard.henderson@linaro.org> [AJB: add CROSS_CC_HAS_ARMV8_BTI check] Signed-off-by: Alex Bennée --- tests/tcg/aarch64/bti-1.c | 62 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 9 +++++ tests/tcg/configure.sh | 4 ++ 4 files changed, 126 insertions(+) create mode 100644 tests/tcg/aarch64/bti-1.c create mode 100644 tests/tcg/aarch64/bti-crt.inc.c -- 2.20.1 diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c new file mode 100644 index 00000000000..61924f0d7a4 --- /dev/null +++ b/tests/tcg/aarch64/bti-1.c @@ -0,0 +1,62 @@ +/* + * 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; + uc->uc_mcontext.pstate = 1; +} + +#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 00000000000..ef7831ad76a --- /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 312f36cde5f..8d39f4b2f45 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -24,6 +24,15 @@ run-pauth-%: QEMU_OPTS += -cpu max pauth-%: CFLAGS += -march=armv8.3-a endif +# We need binutils-2.32 to link this test case without warnings. +# And if we know that we have 2.32, we also don't need the linker script. +# In the meantime, disable the test by default. +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),) +AARCH64_TESTS += bti-1 +bti-%: CFLAGS += -mbranch-protection=standard +bti-1: LDFLAGS += -nostdlib +endif + # Semihosting smoke test for linux-user AARCH64_TESTS += semihosting run-semihosting: semihosting diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh index 2326f978562..ebfe3e2ce5a 100755 --- a/tests/tcg/configure.sh +++ b/tests/tcg/configure.sh @@ -231,6 +231,10 @@ for target in $target_list; do -march=armv8.3-a -o $TMPE $TMPC; then echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak fi + if do_compiler "$target_compiler" $target_compiler_cflags \ + -mbranch-protection=standard -o $TMPE $TMPC; then + echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak + fi ;; esac