From patchwork Wed Jan 25 16:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamie Cunliffe X-Patchwork-Id: 13115849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EDC7FC54E94 for ; Wed, 25 Jan 2023 16:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jw/vHgCork4KUHlKU7g4sWX3epXZ1HTVvlikWQ4BLEw=; b=Pe4MOyQ9Wn1tkq F+XzcUOxisM0ZJYH2pT7PClF42D1kw1QYrTm8hkmX4xLJXQjwhOMHGD5adozi4haa2WyoZT4TRuUh GYAut/K3Tth1Msy3j3Tg9uA140SdwCpMtbyd9AjawTZUf2+6bFB9bREbcIHJBfT+/XhcY0LQnv3W7 c7XWJoLTLM9poE8lJT2EonFw57VycT5ttsj8teKwwcsk/2T6Y17qeC1ieh2i/l2fBY+qcMEnP1rkc VtRVfviQgmqHF7JGAw57RebaJn1ODvzdDsti0heAPcbT3fSkAA3gDrSjOxO23osjD5loLH/+WN0hh gm7UOQBIBB6cFNm7Ujug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKimq-007yBT-Si; Wed, 25 Jan 2023 16:38:12 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKimn-007yAr-RF for linux-arm-kernel@lists.infradead.org; Wed, 25 Jan 2023 16:38:11 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B11FB4B3; Wed, 25 Jan 2023 08:38:46 -0800 (PST) Received: from capper-ampere.manchester.arm.com (capper-ampere.manchester.arm.com [10.32.100.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 006E73F5A1; Wed, 25 Jan 2023 08:38:03 -0800 (PST) From: Jamie Cunliffe To: linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Catalin Marinas , Will Deacon , steve.capper@arm.com Subject: [PATCH 1/3] arm64: rust: Enable Rust support for AArch64 Date: Wed, 25 Jan 2023 16:37:37 +0000 Message-Id: <20230125163739.3798252-2-Jamie.Cunliffe@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230125163739.3798252-1-Jamie.Cunliffe@arm.com> References: <20230125163739.3798252-1-Jamie.Cunliffe@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230125_083809_952357_B6EA9E42 X-CRM114-Status: GOOD ( 12.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Miguel Ojeda This commit provides the build flags for Rust for AArch64. The core Rust support already in the kernel does the rest. The Rust samples have been tested with this commit. [jcunliffe: Arm specific parts taken from Miguel's upstream tree] Signed-off-by: Miguel Ojeda Co-developed-by: Jamie Cunliffe Signed-off-by: Jamie Cunliffe Signed-off-by: Vincenzo Palazzo Reviewed-by: Vincenzo Palazzo Reviewed-by: Gary Guo --- Documentation/rust/arch-support.rst | 1 + arch/arm64/Kconfig | 1 + scripts/generate_rust_target.rs | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst index 6982b63775da..3776059a385a 100644 --- a/Documentation/rust/arch-support.rst +++ b/Documentation/rust/arch-support.rst @@ -15,5 +15,6 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. ============ ================ ============================================== Architecture Level of support Constraints ============ ================ ============================================== +``arm64`` Maintained None. ``x86`` Maintained ``x86_64`` only. ============ ================ ============================================== diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 03934808b2ed..fc3800e82802 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -209,6 +209,7 @@ config ARM64 select HAVE_FUNCTION_ARG_ACCESS_API select MMU_GATHER_RCU_TABLE_FREE select HAVE_RSEQ + select HAVE_RUST select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 3c6cbe2b278d..fe0e4ba54492 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -148,7 +148,18 @@ fn main() { let mut ts = TargetSpec::new(); // `llvm-target`s are taken from `scripts/Makefile.clang`. - if cfg.has("X86_64") { + if cfg.has("ARM64") { + ts.push("arch", "aarch64"); + ts.push( + "data-layout", + "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", + ); + ts.push("disable-redzone", true); + ts.push("features", "+strict-align,+neon,+fp-armv8"); + ts.push("llvm-target", "aarch64-linux-gnu"); + ts.push("max-atomic-width", 128); + ts.push("target-pointer-width", "64"); + } else if cfg.has("X86_64") { ts.push("arch", "x86_64"); ts.push( "data-layout", From patchwork Wed Jan 25 16:37:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamie Cunliffe X-Patchwork-Id: 13115850 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 017D1C61D9D for ; Wed, 25 Jan 2023 16:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aAP398U16knx55zsjP3tL6vsnEtJ7vpCIt7V5UsqcNk=; b=kf2ZB+24XxlfBX dlPVmaT3OzjiNh5HAx7X6+5IVgCZVKuZhnC2AfHK/SOy1ZkHUXryUFfzPFM64iDcSEnv9UFlFxsgY MAOzybzbuLNBwLDsvmIrt5RapDRIyrY4spmhKlBM/3IvMl8Uf0Rus57oRzIaaT6AC6M0P24MYJtcd kppfqrsc34CQpz4jcxACdgJnw3ZMZx8QE14RnFlq9iG0BT1X6JtRkfsi4iEFWFyqAHcXKa+eEcJ5w 5bsiX9Xc0YEICWE0bRocJJb6diVY1iK7yyiHWb83SfB2H1YECOrIWM7/Nvx0iozjcpQod99s/kPGZ cTcPMiImGe0je19RTnzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKin0-007yDt-2d; Wed, 25 Jan 2023 16:38:22 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKims-007yBu-Ln for linux-arm-kernel@lists.infradead.org; Wed, 25 Jan 2023 16:38:16 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 34F7AC14; Wed, 25 Jan 2023 08:38:53 -0800 (PST) Received: from capper-ampere.manchester.arm.com (capper-ampere.manchester.arm.com [10.32.100.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 77CC73F5A1; Wed, 25 Jan 2023 08:38:10 -0800 (PST) From: Jamie Cunliffe To: linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Catalin Marinas , Will Deacon , steve.capper@arm.com Subject: [PATCH 2/3] arm64: rust: Enable PAC support for Rust. Date: Wed, 25 Jan 2023 16:37:38 +0000 Message-Id: <20230125163739.3798252-3-Jamie.Cunliffe@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230125163739.3798252-1-Jamie.Cunliffe@arm.com> References: <20230125163739.3798252-1-Jamie.Cunliffe@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230125_083814_788498_3FEDD90B X-CRM114-Status: UNSURE ( 9.08 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Enable the PAC ret and BTI options in the Rust build flags to match the options that are used when building C. Signed-off-by: Jamie Cunliffe Reviewed-by: Vincenzo Palazzo --- arch/arm64/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index d62bd221828f..b53ab6aa2dfe 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -85,8 +85,10 @@ PACRET-$(CONFIG_UNWIND_PATCH_PAC_INTO_SCS) := pac-ret ifeq ($(CONFIG_ARM64_BTI_KERNEL),y) branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET_BTI) := -mbranch-protection=$(PACRET-y)+bti +KBUILD_RUSTFLAGS += -Z branch-protection=bti,pac-ret,leaf else branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=$(PACRET-y) +KBUILD_RUSTFLAGS += -Z branch-protection=pac-ret,leaf endif # -march=armv8.3-a enables the non-nops instructions for PAC, to avoid the # compiler to generate them and consequently to break the single image contract From patchwork Wed Jan 25 16:37:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamie Cunliffe X-Patchwork-Id: 13115851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 978D1C27C76 for ; Wed, 25 Jan 2023 16:39:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r7D2OxL9YZDl7/oFOpJ0W389tejaJJEKRI1oPexesBw=; b=Y/tERD6lPSQqMs AfZQwwb4NaAIBvrP50bY5mjpCzylJVL/Yu49xEBrcZi/woRl5ZkYZC0l03ZxwoFE5XvNqtqX/jn4y 7Ixv8uoNox0Wn+IQsJXmiMLWcN/5C9PesYuzsPN6srAewW6PNQaGzHQ+SCmMxhVx9sPg3j2wb2Wap ld7dISSRBws2xtO2Xa0I0GcUDtEO1Pk7Dksr82fh6liML01v3A+bhBP6Gssz1oidUUcWNHGzFLDBM +Fk9v5l4sKC7c49oCRuuZ4+aW/7WnHPYKxpoZvovygJ++noTNCAxURR8TT5LQyAmcEfFpJWgC4Ttc GY7NJAdS/mi1uzLAvHdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKin8-007yGM-IX; Wed, 25 Jan 2023 16:38:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKimy-007yDR-Tk for linux-arm-kernel@lists.infradead.org; Wed, 25 Jan 2023 16:38:22 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0B4554B3; Wed, 25 Jan 2023 08:39:00 -0800 (PST) Received: from capper-ampere.manchester.arm.com (capper-ampere.manchester.arm.com [10.32.100.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4D0993F5A1; Wed, 25 Jan 2023 08:38:17 -0800 (PST) From: Jamie Cunliffe To: linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Catalin Marinas , Will Deacon , steve.capper@arm.com Subject: [PATCH 3/3] arm64: rust: Disable neon and fp target features. Date: Wed, 25 Jan 2023 16:37:39 +0000 Message-Id: <20230125163739.3798252-4-Jamie.Cunliffe@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230125163739.3798252-1-Jamie.Cunliffe@arm.com> References: <20230125163739.3798252-1-Jamie.Cunliffe@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230125_083821_020049_5F6D6DE1 X-CRM114-Status: UNSURE ( 8.30 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Disable the neon and fp target features to avoid fp & simd registers. The use of fp-armv8 will cause a warning from rustc about an unknown feature that is specified. The target feature is still passed through to LLVM, this behaviour is documented as part of the warning. This will be fixed in a future version of the rustc toolchain. Signed-off-by: Jamie Cunliffe Reviewed-by: Vincenzo Palazzo --- arch/arm64/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index b53ab6aa2dfe..33ae20fc3f56 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -41,6 +41,8 @@ KBUILD_CFLAGS += -mgeneral-regs-only \ KBUILD_CFLAGS += $(call cc-disable-warning, psabi) KBUILD_AFLAGS += $(compat_vdso) +KBUILD_RUSTFLAGS += -C target-feature="-neon,-fp-armv8" + KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)