Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp965899rwb; Tue, 27 Sep 2022 06:53:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7r9Nbk8e/Y455OY0eYZ6XuQEhpbFKwrZw7ItmGIIlVmJ0nSm6nhR1r+XaY1MCWAN+ppuM4 X-Received: by 2002:a17:90b:2785:b0:203:6279:f03a with SMTP id pw5-20020a17090b278500b002036279f03amr4792960pjb.36.1664286817374; Tue, 27 Sep 2022 06:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664286817; cv=none; d=google.com; s=arc-20160816; b=npph+08mcChdLDaQjlJYYgT3LT0tYFh19gmAZQhjxvmtWq+CGDVhkT2Wz7n6B0igre ekYO4A9sEgEDlHOKhvSQuUnuIMSqpazSD7ylzgaOVblhrIB5TyZePcYVX3QbqkOy2qZc 0m8QrIiVi/Qc9oJ7gf5geVbLO2jUPr4QrGr0NH9oO9w1rudNc9vEal0cb41h2M1JAX4t 3+jt0zyOnCh9H4vwWe+gKVVjOIsBWnx7KxLWTCe35d8jMLKbO6qGLkTSY27YzIxk7B4T FgzwJLE/QdC5Q/aDN06gYAmYPVByUbzShqGv/x5FO39hWEsqX2qklu91bUkOb3KMIdQM uK5g== 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=t3UxD/cp20zftII7eOFc3wjs1eeCKOJJh7ymJxgL2xQ=; b=qlnVWYKnDeVLpk2vkBWcU1B2SYJxDccufgG0Jh04kQmjD5R3f+stYI/UzYmUGFTY2I f3g7HBEk+ja+ZmPbpApeNgAMDyuWKba8hpCyBSABT0stUH5NKJ+A5rxNXj70pPOln0NQ 3zhAvHnLR87PH7J5ZXmWwQ7W6VosnatJoeL5N3xcX4/JcaQMWpxRyebQRPZmOkx2vzxs 155VLTkQg1tkDvwZyaFAe5ZqmHIk0EAXvcoy5T3HcXG7SJLjRRjyxiOKq8NjWGvXkVJG 4JIhG3tBsgL7/lS9PyS29cx3tJaHyeydex+iTczvwDVRDJYVARN0np12e19nsrZbMNyZ hquA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RhazsGhH; 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 v4-20020a63b644000000b00434e297a5ccsi1911112pgt.142.2022.09.27.06.53.25; Tue, 27 Sep 2022 06:53:37 -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=RhazsGhH; 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 S232881AbiI0NWu (ORCPT + 99 others); Tue, 27 Sep 2022 09:22:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232721AbiI0NV3 (ORCPT ); Tue, 27 Sep 2022 09:21:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8EBE1B14EF; Tue, 27 Sep 2022 06:18:31 -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 0542EB81BEA; Tue, 27 Sep 2022 13:17:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC298C433D6; Tue, 27 Sep 2022 13:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664284676; bh=5pDV+1IeylvfkCFNfGNAvhddDJ6vUthK0D0dKmZmb+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RhazsGhH0AKSFvhKsq/twtVvwPXEbvpVumnhHseP8p8MkU+c/ChI4R4vcMMRa5IIE 5X0SU043Tk53MpcPsHfmyXRYYIi8CKfoH6uFSOB4E4g6Tr65muwWPn3x8gbmrvYCeW CGNFqHN5wlgFIyFo1zNkarZcFsEIHeLgDHcssAdHjUjRnmAMcVCMeMjERyxbsb+pwC jBLrQ5ATr7+0GiSctXch8pOWyJ1yAa9UW1e+zxvQcxLgGXwZ7TImFBTSkHp8bbcvjs +F/ylRmIsC5N/h7UZaFDyfLBHf9c0uZE0AwMtWqxCMwiOZ3DL/dNgnVmdB64DpGWr3 0moYdgUKAo88Q== 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 , Kees Cook , 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 v10 25/27] x86: enable initial Rust support Date: Tue, 27 Sep 2022 15:14:56 +0200 Message-Id: <20220927131518.30000-26-ojeda@kernel.org> In-Reply-To: <20220927131518.30000-1-ojeda@kernel.org> References: <20220927131518.30000-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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 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. Reviewed-by: Kees Cook 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 f9920f1341c8..3ca198742b10 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -257,6 +257,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 bafbd905e6e7..2d7e640674c6 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.3