From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABE65C07E9B for ; Fri, 9 Jul 2021 10:31:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 89D94613D3 for ; Fri, 9 Jul 2021 10:31:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232208AbhGIKei (ORCPT ); Fri, 9 Jul 2021 06:34:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232113AbhGIKei (ORCPT ); Fri, 9 Jul 2021 06:34:38 -0400 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E7FCC0613DD for ; Fri, 9 Jul 2021 03:31:54 -0700 (PDT) Received: by mail-ot1-x333.google.com with SMTP id i12-20020a05683033ecb02903346fa0f74dso8937367otu.10 for ; Fri, 09 Jul 2021 03:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+Ag9cLTRzEt3rLWB36U/GaTidnQngHz1mFDbPHdbYJM=; b=sy+60CShYu2+iBbLulb6BXcdNl+YIgSb+jajYjDZa4zuiim9DZxtK88a9BSEKRhPbe 2149xKE135XoG+YMIvJKNw6ZCj+Hh+EyWUQfK08pHq86IYtTdGJTm+svEvs37g5Uc5aC xngQeJK55dnd2ThJlBq5eYZYae9d0PV6/iYXED9E2qqxOYHyQkUpxQ8hj9KF/zDuFrT9 tgJPN39rPw0sSVwFi7t4ZBZBflf0sauWKsDv5fafUbt1gGs3lfO03jiHBYX5NnqsSVoi /ujWD+DqEO4PATTm5/8r52LotGJ0RL6BBjZ8Ui/OZxRKJiFG0Xe11t+2cPco8FTtPijx 5Rtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+Ag9cLTRzEt3rLWB36U/GaTidnQngHz1mFDbPHdbYJM=; b=El5K2rjQjf0ByrAw0dMOJUQaYVlxYaIDdEID5G/8KpKKQzm4AuUZocI1IaW9pghtaF r7x85LYKP7F6S5AIIN8sa6+rDHTzzpo7gQKR6OtU8tScFV314+FKLUEF1TSHs+3I/4Rq JLd8i6hW0EaooWzCg346HXYqiZiGkK7DkSb5Qo3ZE93VN1CcWkp/x21iyA3OvyJ0pnXu 7uzDT+pYttwMAg+0t2gnBWUob6kcdWYaXU7Eok3FzcifaSIiuQz+4KIknN+/jXjJlryX VFksw3R+qDbvximuoC/zVK721PSJt4PK/CYnsZDq63dhXoYXtCphMd5/bqpjMGyAhUg5 o14Q== X-Gm-Message-State: AOAM533SqyhCQ+t2tSWGzh1LDUQUbXnt1DMbxlsLR4Qy+qKGRObaaB0p Lsz8iebdC6CMDzg1Meej4Suf9pxnFqqHxJMRYSJ5og== X-Google-Smtp-Source: ABdhPJzZsHc3H6ZMG5NBT8zSvR+UmJMGAQPOW7Oty1uNxYZb5VbOU1cqW4degb+Ls5Psx+gb8Y7wOEkrsU6h6jHMP2U= X-Received: by 2002:a9d:d04:: with SMTP id 4mr29227829oti.251.1625826713387; Fri, 09 Jul 2021 03:31:53 -0700 (PDT) MIME-Version: 1.0 References: <20210704202756.29107-1-ojeda@kernel.org> <20210704202756.29107-6-ojeda@kernel.org> In-Reply-To: From: Marco Elver Date: Fri, 9 Jul 2021 12:31:41 +0200 Message-ID: Subject: Re: [PATCH 05/17] rust: add C helpers To: ojeda@kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho , Boqun Feng , Sumera Priyadarsini , Michael Ellerman , Sven Van Asbroeck , Gary Guo , Boris-Chengbiao Zhou , Fox Chen , Ayaan Zaidi , Douglas Su , Yuki Okushi , clang-built-linux@googlegroups.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: rust-for-linux@vger.kernel.org On Wed, 7 Jul 2021 at 12:19, Marco Elver wrote: > On Sun, Jul 04, 2021 at 10:27PM +0200, ojeda@kernel.org wrote: > > From: Miguel Ojeda > > > > This source file contains forwarders to C macros and inlined > > functions. > > What is the story with Rust and LTO? Intuitively, I would expect Rust > code to only perform optimally if the kernel is built with LTO > (currently only supported via Clang). I'll answer my own question: it looks like Linux Rust code currently does _not_ generate LLVM-LTO compatible object files, but only native object files (which still link fine if LTO is enabled, but doesn't permit the optimizations below we'd want). rustc already supports playing nicely with LLVM LTO via `-C linker-plugin-lto`: https://doc.rust-lang.org/rustc/linker-plugin-lto.html So, hopefully it should only require kernel work to make it play nicely with CONFIG_LTO_CLANG. > Because if calls to every one of these helpers are real calls, I would > expect performance to be pretty poor. There's probably a reason these > are macros or inlinable functions. > > I would almost go so far and suggest that CONFIG_RUST be modified as > follows: > > --- a/init/Kconfig > +++ b/init/Kconfig > @@ -2028,6 +2028,7 @@ config RUST > depends on HAS_RUST > depends on !COMPILE_TEST > depends on !MODVERSIONS > + depends on LTO || EXPERT > default n > help > Enables Rust support in the kernel. > > [ I'm sure there are configs that don't yet work with LTO, but could be > useful to enable for debugging or testing purposes, and therefore would > make it conditional on CONFIG_EXPERT as well. ] > > [...] > > +unsigned long rust_helper_copy_from_user(void *to, const void __user *from, unsigned long n) > > +{ > > + return copy_from_user(to, from, n); > > +} > > + > [...] > > From some local tests, it looks like simply attaching > __attribute__((always_inline)) will do what one would expect when > compiling with Clang LTO (I checked -flto=thin). > > If you confirm this also works across C and Rust TUs when enabling LTO, > I would then suggested adding __attribute__((always_inline)) to all > these helpers. > > Thanks, > -- Marco