From patchwork Thu May 5 09:11:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 569926 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:66c4:0:0:0:0 with SMTP id x4csp581870mal; Thu, 5 May 2022 02:15:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWjntnQabZaFDubm3v0CY7qfmyml2MfYzBmdMefqPETvUOplsaNe5JK8Q8XXd5g9q0gmTv X-Received: by 2002:a0c:e393:0:b0:45a:8c08:a5e6 with SMTP id a19-20020a0ce393000000b0045a8c08a5e6mr15743504qvl.115.1651742157203; Thu, 05 May 2022 02:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651742157; cv=none; d=google.com; s=arc-20160816; b=fRWTCfe0pteCN3RuhephUVWNHIVKvkHFFrdrkVjbGjqeGjGkIyYvgb8Wp8TploGZV9 HmbkxYMssj5tmMSXQCyu7cv6O5QM6Cmkjcxw6I4gJewH/hfLIbvs201m+av4HJVthl1D kZYrTli2wzBnDsUH/Ssp3adyY3Ng/fmAdyqqLntBWdysvHOKVg7lN8sT/72z6Nrzw2gV 9K282puPfiwK34vf2zjcl4tuN8+cRWZ8T2PubKzbauHOvK1MdIQBSbCdgErku3RSPxrR XcW32/89VZf+X/6zIbsSu0SFOmHS2bxCR2viQmvf/d8wbmxJ20h5zknCwgqJY1akr9gU zQOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=qfuC15wVhgbtf/sFl4PEa+tcmWHsuyafqPjoww1w/hI=; b=upaYTLXGfV5rXVLqh/ykrd5XQevdYwujDipUtMtRG1DmHKzAS3tcdHOJElp9oYvm9c liB2RrZ173jqqR1qBdLTGKT96Bix1hjSX9XE8qDp77eXY3N6vuloSDrbxHRVvd6kTO0h 3zvXbDVwZ/gT3sVYlYT90nZRcRP66iTA0t1UcivZx0dLjAxNpkTpGcVz5G80/Rc+xWn6 AlkTKSEGKNI8LcsavIPVkFtNMkXzEMF0MyrJsYozmcZ5rn6jnL/scK7O2kffyuHAd3JF K8QolvKEgbtHE6Pld6flV/YI6eyIq0znu1aYpVMDKksY1mI1S66HqOqpfdIgsnL3F9sh 4PDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="dVV/E+Ru"; 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 c12-20020a05622a024c00b002f1fa1c23c2si517564qtx.155.2022.05.05.02.15.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 May 2022 02:15:57 -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="dVV/E+Ru"; 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]:57936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmXaW-0000RV-M7 for patch@linaro.org; Thu, 05 May 2022 05:15:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmXWc-0004nD-U5 for qemu-devel@nongnu.org; Thu, 05 May 2022 05:11:54 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:44699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nmXWa-00039c-7Z for qemu-devel@nongnu.org; Thu, 05 May 2022 05:11:54 -0400 Received: by mail-wr1-x42c.google.com with SMTP id b19so5210540wrh.11 for ; Thu, 05 May 2022 02:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=qfuC15wVhgbtf/sFl4PEa+tcmWHsuyafqPjoww1w/hI=; b=dVV/E+RuyBmbbozQCgqG39EvJV5ONedx5ZNcjcYqt1bu6pEXRzWzwcb5iAZin8KuNz zGTyj8GjHdzQ9z39ESlBP7QGKZe/D93O7aZokGkE7BfRdYAEu32RDnVpCg9aZDqFI9cM Ww4/+Y1DqXvrfBQZz+4CAX3iD4tGYg6zCLQp4SPWNJ+znFMj6wsBIRdxTYDa/8pm3001 94pD3T37VtL7tph0mcPs5RZMBkE/Fm1ZpEzc0ShC2v/tNMXaiqNKaak8/bV7rrzepQqP 54qYbud/cf6uVUaCjWOfd5fzfBNJnO5Sh9wLCz+36hlrPJmaehVjtv8xWEBbgqaqRFnX 7K3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qfuC15wVhgbtf/sFl4PEa+tcmWHsuyafqPjoww1w/hI=; b=t0iD/yGMDd0i3KNVex36oGNSAQfbKdZc19bJOAW5otZhJ+sIpHZTn2ig3d+xTGjrpD w7CtopteDS8uxA4151zx+GAZqsowDKHAkFccN+MKDY/MEm3VNo3lJllifB4c1HgqFRv9 JSbL8h11EvKTrTBOjqSRmuXdjwbt6ySBmuQqtRH86dDcaX0lQRVx+sbfntCW4mWhiQv9 wXjyVZYkK9p0ggoeLHBq3rxoPEJte6QlHKMtAmUYXpJezO3w/OgO/ZYc4z+YAMEaGp9N uRrILrEc+sZV85xVOPOonLSyoARUFyvwNQlSQ9PCdmrVh/mTyWwhiggA0ZLBgZdGqrSk 57bA== X-Gm-Message-State: AOAM5338WNSwugxp6bKPVSPt3uOPCsUrNkhiiadf+ZWsZ76C4Onshp9f yiCpHLESQI+XPWPDfQn0EtLrBA64Fewf7w== X-Received: by 2002:a5d:4ac2:0:b0:20c:7844:fb79 with SMTP id y2-20020a5d4ac2000000b0020c7844fb79mr8647245wrs.33.1651741910669; Thu, 05 May 2022 02:11:50 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id j14-20020adfe50e000000b0020c6a524fd5sm841612wrm.99.2022.05.05.02.11.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 02:11:50 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 01/23] target/arm: Enable SCTLR_EL1.BT0 for aarch64-linux-user Date: Thu, 5 May 2022 10:11:25 +0100 Message-Id: <20220505091147.2657652-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505091147.2657652-1-peter.maydell@linaro.org> References: <20220505091147.2657652-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.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=ham 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson 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 Message-id: 20220427042312.294300-1-richard.henderson@linaro.org [PMM: remove stray change to makefile comment] Signed-off-by: Peter Maydell --- target/arm/cpu.c | 2 ++ tests/tcg/aarch64/bti-3.c | 42 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 6 ++--- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 tests/tcg/aarch64/bti-3.c diff --git a/target/arm/cpu.c b/target/arm/cpu.c index e46a766d770..2b81b18351a 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 00000000000..a852856d9a6 --- /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 6ad0ad49f98..d6a74d24dc0 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -28,9 +28,9 @@ endif # BTI Tests # bti-1 tests 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