From patchwork Wed Apr 27 04:23:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 566744 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp4174274map; Tue, 26 Apr 2022 21:24:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJtm3AR7v1h1bXNkRTew2sqNKjFt9Dl9jzTzoQ2WBuTyEzdewTfASq1KDJLwHfgmqqAOlU X-Received: by 2002:a05:622a:454:b0:2f3:642e:6be2 with SMTP id o20-20020a05622a045400b002f3642e6be2mr11573348qtx.563.1651033465766; Tue, 26 Apr 2022 21:24:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651033465; cv=none; d=google.com; s=arc-20160816; b=kW4f3xAR7PAz2KxGE7H5S8FT/lWy5DdXzbO8sFFNr0Lxj/GCV2DPBYzu3J/dPntG0Z gTbFuy9TlphwfXIxEV8fmNZfbUnxSTRq8w0ce9P3wfQ81E+TfYGGGFsnlsxdEXomUi1l CD6+0dJsashYZoOhiUu+7LHCIqCg1uX9RQ6gy37xKOKCcFGcv4RuhGYjUvFxCVRJHUnM Xhy6zbNrLirIqnDdlp8sR2Wr3ojmDz8NKf54sTps6/B14oXMfIaApB8b8fHpFlK0zovr ecnSg3ieRNn45E5t6mI+Yk/og3zuGqv48Cyrsc+fre4O0BS9QMS5vQeMmKDJsoE1uYH+ xwvg== 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:message-id:date:subject:to:from:dkim-signature; bh=tRHn2mdN0R0av8YyHUzJgxZG/sPCJkq9JFL0TZYgnqQ=; b=NTz0OEP2G2XFTWy1A+FfkWgv5GjlUhojOYNlaQcdthKPS4oH8nhRmEbUhPSNP2q7fH zpJcjuQE0zjRwkDWOr+r6zxlu+C9XLdFTfu62Pq2Ba9Evy3qI6ioZXhGXkr+81ur9xpT R9/ihHxIusoC/3DPmMVeP1JacvnVv3yOFNM7G6x2tKPohLEKT88yVaHUZC84KOI5y+Cm Pyo8je0fq8xwpzP1s+4pjEIeYWhGbxzPcJCccBMuWRo3stWkUCcIpMzVUWAuFh42f0Ry KwabEit0R3ExHnDGLcV+ktqFpMZlYYVMiEXuPVKuuq4tLqjCp0QC84Jk0DwMJzlXvS2B YU8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gq2SusrU; 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=pass (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 r14-20020ac85c8e000000b002f3685278f4si96906qta.217.2022.04.26.21.24.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Apr 2022 21:24:25 -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=pass header.i=@linaro.org header.s=google header.b=Gq2SusrU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1njZE1-00015F-AE for patch@linaro.org; Wed, 27 Apr 2022 00:24:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1njZD3-00014c-6n for qemu-devel@nongnu.org; Wed, 27 Apr 2022 00:23:25 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:54882) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1njZCw-0004pt-Bq for qemu-devel@nongnu.org; Wed, 27 Apr 2022 00:23:21 -0400 Received: by mail-pj1-x1034.google.com with SMTP id fv2so428031pjb.4 for ; Tue, 26 Apr 2022 21:23:15 -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:mime-version :content-transfer-encoding; bh=tRHn2mdN0R0av8YyHUzJgxZG/sPCJkq9JFL0TZYgnqQ=; b=Gq2SusrUeJPU7fI4BBK7yWivjCeTz9Rpm1knngsr/kmYtGTmrzeWvi5o31VHPEyi2U +2gmxMFNsAUwRL+OJJnjAxz+zdGYeJLkB797gSeeTRjf4eKDLzRD1jcm2I9TTOSfyJ4E pkpCqpl9OE0EoSfSUs943xilkOU+uG0a8wiSRBC71E5bry4yDRwHadKcWAyeIuuNKTHY UVYfyXlTTinXRVJRptaVB1hBOm38jOc5BrwAcbwRdN6bF6clONABiAtPa3WgvyjURIJA SsbvzCglVn9yWhzbuFr4H0rjhfJX9Vlzk/kMqTZs9SHxr60eyQHeec5o4aMEDD0t36F5 /hQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tRHn2mdN0R0av8YyHUzJgxZG/sPCJkq9JFL0TZYgnqQ=; b=8PGgBsZVew0RrxxdN7z3Q8TiO+s8cvbEvnCK3Ps2X1Ij+Npd0+DHDFT7ZhzlAaAM/t 1cdXsNB5rWGuZVOy2UWfZPzW/Z1HIRfeYIJkCER4TVSgzg3+O1zicHPHgBcMvWTDSnMi Nl+vK7wTFhg2RKwGDijzSM3K5HmyoWn8KA8bbzSuuIUvacoip5L50EBG9U4NjzbYzHaO KYfss8soSKwyS8POTypT9HwhkRwhnTUif7enUq2Uqu9Pywg+YmDlIANjwAC26A2ZjQ2T 6LmgtcyAN3CDXGgksH7TacVcjHTAobTclVnvcX2n9ncRwc3gxBSD9BWjIN2jSgOf64vx P22A== X-Gm-Message-State: AOAM531//9BMV6CD3XIc+XFcYe4OmUCos8kldKdJyTKynbK7d5DD3q0v VxE4R4F0XYUQMr49DbguYJ6Z2x0Gb+sAWQ== X-Received: by 2002:a17:90a:ba15:b0:1cb:be7d:bbca with SMTP id s21-20020a17090aba1500b001cbbe7dbbcamr41341075pjr.143.1651033393867; Tue, 26 Apr 2022 21:23:13 -0700 (PDT) Received: from stoup.. (174-21-142-130.tukw.qwest.net. [174.21.142.130]) by smtp.gmail.com with ESMTPSA id iy19-20020a17090b16d300b001cd4989fee6sm4846064pjb.50.2022.04.26.21.23.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 21:23:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH] target/arm: Enable SCTLR_EL1.BT0 for aarch64-linux-user Date: Tue, 26 Apr 2022 21:23:12 -0700 Message-Id: <20220427042312.294300-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.google.com 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_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This controls whether the PACI{A,B}SP instructions trap with BTYPE=3 (indirect branch from register other than x16/x17). The linux kernel sets this in bti_enable(). Resolves: https://gitlab.com/qemu-project/qemu/-/issues/998 Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/cpu.c | 2 ++ tests/tcg/aarch64/bti-3.c | 42 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 8 +++--- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 tests/tcg/aarch64/bti-3.c diff --git a/target/arm/cpu.c b/target/arm/cpu.c index e3f8215203..c50a8dca0b 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -197,6 +197,8 @@ static void arm_cpu_reset(DeviceState *dev) /* Enable all PAC keys. */ env->cp15.sctlr_el[1] |= (SCTLR_EnIA | SCTLR_EnIB | SCTLR_EnDA | SCTLR_EnDB); + /* Trap on btype=3 for PACIxSP. */ + env->cp15.sctlr_el[1] |= SCTLR_BT0; /* and to the FP/Neon instructions */ env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 20, 2, 3); /* and to the SVE instructions */ diff --git a/tests/tcg/aarch64/bti-3.c b/tests/tcg/aarch64/bti-3.c new file mode 100644 index 0000000000..a852856d9a --- /dev/null +++ b/tests/tcg/aarch64/bti-3.c @@ -0,0 +1,42 @@ +/* + * BTI vs PACIASP + */ + +#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 BTYPE_1() \ + asm("mov %0,#1; adr x16, 1f; br x16; 1: hint #25; mov %0,#0" \ + : "=r"(skipped) : : "x16", "x30") + +#define BTYPE_2() \ + asm("mov %0,#1; adr x16, 1f; blr x16; 1: hint #25; mov %0,#0" \ + : "=r"(skipped) : : "x16", "x30") + +#define BTYPE_3() \ + asm("mov %0,#1; adr x15, 1f; br x15; 1: hint #25; mov %0,#0" \ + : "=r"(skipped) : : "x15", "x30") + +#define TEST(WHICH, EXPECT) \ + do { WHICH(); fail += skipped ^ EXPECT; } while (0) + +int main() +{ + int fail = 0; + int skipped; + + /* Signal-like with SA_SIGINFO. */ + signal_info(SIGILL, skip2_sigill); + + /* With SCTLR_EL1.BT0 set, PACIASP is not compatible with type=3. */ + TEST(BTYPE_1, 0); + TEST(BTYPE_2, 0); + TEST(BTYPE_3, 1); + + return fail; +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target index 6ad0ad49f9..a738eb137c 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -26,11 +26,11 @@ run-plugin-pauth-%: QEMU_OPTS += -cpu max endif # BTI Tests -# bti-1 tests the elf notes, so we require special compiler support. +# bti-1 test the elf notes, so we require special compiler support. ifneq ($(CROSS_CC_HAS_ARMV8_BTI),) -AARCH64_TESTS += bti-1 -bti-1: CFLAGS += -mbranch-protection=standard -bti-1: LDFLAGS += -nostdlib +AARCH64_TESTS += bti-1 bti-3 +bti-1 bti-3: CFLAGS += -mbranch-protection=standard +bti-1 bti-3: LDFLAGS += -nostdlib endif # bti-2 tests PROT_BTI, so no special compiler support required. AARCH64_TESTS += bti-2