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=ham 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 87FC8C07E99 for ; Fri, 9 Jul 2021 10:31:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A71B613DC for ; Fri, 9 Jul 2021 10:31:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232202AbhGIKeh (ORCPT ); Fri, 9 Jul 2021 06:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232113AbhGIKeh (ORCPT ); Fri, 9 Jul 2021 06:34:37 -0400 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 518B7C0613E5 for ; Fri, 9 Jul 2021 03:31:54 -0700 (PDT) Received: by mail-ot1-x32b.google.com with SMTP id w15-20020a056830144fb02904af2a0d96f3so8969271otp.6 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=ndhvafA9HC+icqyyDzFGRFfs5PzaU0jdF1V1oWma0euB+spbFhcNY49T/Isvfsd20k 135ZS4sKzaVQ+IkGiKQzPY8Vdxgt9C0Ez0tdA/v6dh3oKqcbYD30/T2xfoLx/5XUmWJa 3TYXRsH3yu1TWSuFgfk4V+SL6i6xlGEG1+2OH6D1F/Ihi+J4uznB+pE7iIXJguvATpKO 6u5L9eRRnbwNYGhl9C+061O/bh5TR/8Er5R3qww9CyIbNdMkOq4f3ZYpyvnPWCdxrrgX ZnpPYbUsOFLnnX8Ge0IQdKcoUbuhmgHokRf3xPCBQX4hCbvHb1Thnx4YTHQsNJUgzzDC +hQQ== X-Gm-Message-State: AOAM531uLT/Vy8Fqq8JONx1ZnIk881wGi/0KY6bSNUfBRuNyJl9NeH7R EBn7xQtNmKAJguHCEnuH6dceKkB+yZslCIK+jzPyk8ksEGizBw== 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: linux-doc@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