Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp1909086rwb; Fri, 5 Aug 2022 09:42:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR7TMjVD8adl8jqel6DK2LbwKpPkJ+KKT/DNQ97rjpXuOEBopmkAVVMK9sPhDjjHMyNvujVz X-Received: by 2002:a05:6402:270d:b0:43a:67b9:6eea with SMTP id y13-20020a056402270d00b0043a67b96eeamr7425549edd.94.1659717773069; Fri, 05 Aug 2022 09:42:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659717773; cv=none; d=google.com; s=arc-20160816; b=IuJyoEag8FK/FTRZ3vwdW7YGNLNPKRctWE5ctrEYmZHf/YOaxLZ2zWCfaqxCkKBNKz uq8CvPkPtvBI8Tb7ZQ54i1PXHlG6GD6VJDOTO6iv2e2USrapCF91cdzwOlZbYv80aidn mlsWSQrlCEE4R49UhdHS0ceYSzulZwsf3SARrTpGmK06H/OCmZJ4/0e1HAuPoevbDLUV RwhrBvZUafwIyyS65eY/qvE3q5iqZyN/fodGYzs71PC55i0suRmVMhCYLuncOxHOb5HL 5ppoNAWdhR7gQV2w6ViIQkmWJ+IbQ/hXjMpnDE5SE+8CQqoeQsIvfO/WsdTBalSMh1pw ZGbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1XX2Hv0AP0JbtgBfmTfgxsb03iTGJjbPaXMsW9p4bbM=; b=aq8I6nN9WBP5aTbzvWoQkvanaJmmSgJ6eyCqScbDlOob5DYFMnrrD+QASBhD18tn5p gsdBP1oLBGJ8b3UApGFT07LIE+dO1kWGg5h91jkRsw7KRn/rMYtUXhemfrcB4EL7Hj7b UgrO5QpuycLLNtQufgIPfm2327Ruk1EhcnWfJF8rT43ZxA/hta0FAtnjinmul968okcE syMabt1PSZy5KW7XXXqrME8XwkDuUuxdDJ3JulZ3ISZVngeiS6HIkH9uoFQwexIpbSxA E0VfQ3DRVPCjJrITbl2rvqJMOZb4Mob+8ZOUwiZdDSDhty9pwbFKLx/tI0oWUZA/Xd59 cKJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W4nnSD3f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gw3-20020a170906f14300b006feb18c72bfsi1820382ejb.126.2022.08.05.09.42.27; Fri, 05 Aug 2022 09:42:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W4nnSD3f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241310AbiHEPry (ORCPT + 99 others); Fri, 5 Aug 2022 11:47:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241395AbiHEPp4 (ORCPT ); Fri, 5 Aug 2022 11:45:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D4975394; Fri, 5 Aug 2022 08:44:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6FFE2B82987; Fri, 5 Aug 2022 15:44:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 840FEC433D6; Fri, 5 Aug 2022 15:44:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659714293; bh=snCTpO1KjSoGMCbd2ZibVgNCeCXJ9RI/0mMCRcFphkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W4nnSD3fqKq1mlqKZ6GyHb+mnfKbt968O+PZyBC1A1yMQ7NdczRxYugrnMnFWRWVG GX7jAZQsLo+uXtg1eHmwWk8wy13sieWXO1aTMU71MzO5ib0UStwzzWL73JtYF7E3N0 YUBpiOmZhHPNSLVb41Bba9/NOv4Fj9ALy7R0r+0CAKIPaq/27XCRtuI3dHIWRDWLJW aQqULu6ghI2tz1v01ZcHAk21cfJJ9tMTNQa4++7IhhRISJ1kzb2qRRl9lOe4UePjf7 LGmuQdscSj35rzRTn6ma5QBIYh8FRquvhnD3U4ZNk7TiCSEnrVz9n62XChPQ8w6UXE pOtXf8X0mgcuQ== From: Miguel Ojeda To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, patches@lists.linux.dev, Jarkko Sakkinen , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , David Gow , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-doc@vger.kernel.org Subject: [PATCH v9 25/27] x86: enable initial Rust support Date: Fri, 5 Aug 2022 17:42:10 +0200 Message-Id: <20220805154231.31257-26-ojeda@kernel.org> In-Reply-To: <20220805154231.31257-1-ojeda@kernel.org> References: <20220805154231.31257-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Note that only x86_64 is covered and not all features nor mitigations are handled, but it is enough as a starting point and showcases the basics needed to add Rust support for a new architecture. Co-developed-by: Alex Gaynor Signed-off-by: Alex Gaynor Co-developed-by: Wedson Almeida Filho Signed-off-by: Wedson Almeida Filho Co-developed-by: David Gow Signed-off-by: David Gow Signed-off-by: Miguel Ojeda --- Documentation/rust/arch-support.rst | 1 + arch/x86/Kconfig | 1 + arch/x86/Makefile | 10 ++++++++++ scripts/generate_rust_target.rs | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst index 1152e0fbdad0..6982b63775da 100644 --- a/Documentation/rust/arch-support.rst +++ b/Documentation/rust/arch-support.rst @@ -15,4 +15,5 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. ============ ================ ============================================== Architecture Level of support Constraints ============ ================ ============================================== +``x86`` Maintained ``x86_64`` only. ============ ================ ============================================== diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 52a7f91527fe..4d5a3f256cbc 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -258,6 +258,7 @@ config X86 select HAVE_STATIC_CALL_INLINE if HAVE_OBJTOOL select HAVE_PREEMPT_DYNAMIC_CALL select HAVE_RSEQ + select HAVE_RUST if X86_64 select HAVE_SYSCALL_TRACEPOINTS select HAVE_UACCESS_VALIDATION if HAVE_OBJTOOL select HAVE_UNSTABLE_SCHED_CLOCK diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 7854685c5f25..bab595003f07 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -68,6 +68,7 @@ export BITS # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383 # KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx +KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2 ifeq ($(CONFIG_X86_KERNEL_IBT),y) # @@ -155,8 +156,17 @@ else cflags-$(CONFIG_GENERIC_CPU) += -mtune=generic KBUILD_CFLAGS += $(cflags-y) + rustflags-$(CONFIG_MK8) += -Ctarget-cpu=k8 + rustflags-$(CONFIG_MPSC) += -Ctarget-cpu=nocona + rustflags-$(CONFIG_MCORE2) += -Ctarget-cpu=core2 + rustflags-$(CONFIG_MATOM) += -Ctarget-cpu=atom + rustflags-$(CONFIG_GENERIC_CPU) += -Ztune-cpu=generic + KBUILD_RUSTFLAGS += $(rustflags-y) + KBUILD_CFLAGS += -mno-red-zone KBUILD_CFLAGS += -mcmodel=kernel + KBUILD_RUSTFLAGS += -Cno-redzone=y + KBUILD_RUSTFLAGS += -Ccode-model=kernel endif # diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 7256c9606cf0..3c6cbe2b278d 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -148,8 +148,19 @@ fn main() { let mut ts = TargetSpec::new(); // `llvm-target`s are taken from `scripts/Makefile.clang`. - if cfg.has("DUMMY_ARCH") { - ts.push("arch", "dummy_arch"); + if cfg.has("X86_64") { + ts.push("arch", "x86_64"); + ts.push( + "data-layout", + "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", + ); + let mut features = "-3dnow,-3dnowa,-mmx,+soft-float".to_string(); + if cfg.has("RETPOLINE") { + features += ",+retpoline-external-thunk"; + } + ts.push("features", features); + ts.push("llvm-target", "x86_64-linux-gnu"); + ts.push("target-pointer-width", "64"); } else { panic!("Unsupported architecture"); } -- 2.37.1