Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp527110qtg; Wed, 5 Apr 2023 13:44:41 -0700 (PDT) X-Google-Smtp-Source: AKy350Y5BztAOGP8EGsVIjUgNXBhOwyjuNyC5SGZFofoD+U+fpKtfS1fSC/vto2Sz7+SFELqCg5t X-Received: by 2002:a17:906:c9c7:b0:8b1:7fa:6588 with SMTP id hk7-20020a170906c9c700b008b107fa6588mr4047026ejb.12.1680727460637; Wed, 05 Apr 2023 13:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680727460; cv=none; d=google.com; s=arc-20160816; b=wBXao1w6nTzp21DQ4ejy6tsCYhDMTmNdbTCTcnyIyxcucENwHWEal9U8RVYu008ogX a78v7zRqXa0buj2naR+ZsLiKheGKKWuhYGPrMhFGsQZ5xfhjbAMaUZlC208woDQEUO3s nxV3J0QpVxlj2+OFcNEeQEbYjuQRoMh6HkjDpE/omglZiFfp6pcgB7crsu9AcQT9Tert 3N99+7why/DkHgWCW6fJVS1SuK7sIKPevGNXNofRf1i2lL8zNlD+7GayHG5JuKB6JK2x DWAT0+8PnJiH8E3+0cNsEsdVBaVk859uKW3tqyYyehfV8BHrhRSG30zlcSxoSU7/7AJb 03uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=AfCjLWvZIUyrgKze4xPpxcziixhKFGAgi7gT/eIT+U8=; b=G4ikgJFjLlDo4sBX2XVvl159DyHSYDatT/Qq904IcilYJYxfHgWoeucDCWGJpQ/HoF TaFqn/WSN2t3YXYU0dtgn8usVrwzssyrnE7rZRfxsCpPJmd9iqDeGM7f6YRhbdvrPOwE GZK8x7rmlTjc0QHWS/G5L/JN+yoHm9NJdwhctF9xWwaAvjeld4MIc8uR2Hz+cR+jm0ZO G1JCnv/0oRMtdRJRhQ7o6Gf5o1xpkyOj6aKTCOQFHDDrdceFCPo4+y5o3y1JC8w/PV4J I9BtoHJu+05un8K0/Is4tSl+6pTfCV4KzMbcrureHJQJoO5sRbeq87IsAN/klyNzmSAb YJVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Le7L6+VD; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020a1709062a4d00b009314c7ae06csi13498482eje.191.2023.04.05.13.43.55; Wed, 05 Apr 2023 13:44:20 -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=@gmail.com header.s=20210112 header.b=Le7L6+VD; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234504AbjDEUmC (ORCPT + 99 others); Wed, 5 Apr 2023 16:42:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232447AbjDEUlq (ORCPT ); Wed, 5 Apr 2023 16:41:46 -0400 Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 235938A6B; Wed, 5 Apr 2023 13:40:58 -0700 (PDT) Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-17ab3a48158so39997974fac.1; Wed, 05 Apr 2023 13:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680727246; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=AfCjLWvZIUyrgKze4xPpxcziixhKFGAgi7gT/eIT+U8=; b=Le7L6+VD0Sv7hAIrRqgQlJc6ChQGeWIYqtkZd2fflXlmHFZnyUlwL6zmbHpm/0mTGs nTpqfWAwXZ2LnlsheP7fuSbRETmvyxctIKmMqez8E1GnGyUqEIknJiv8wV34TUNmzTQo aa/BZRwkZSFDC6DoUsuhDsRXbA4LENTp7kgPuBAdDAPbnfIBRsifpEi8bL0/lZUy4i1L YH6WyPULBzQfWedumPha366T2Px4ttbX6t5mmR4YDK9wbLcEFJXfz0jiLS4gR/C6GSv7 8AJeVfYLuFE1o4Huk+Zy7aBrtZwceDvjIToR9Je7UMsHXcbpwvDudS5OzMpeVdq9Rei1 MV2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680727246; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AfCjLWvZIUyrgKze4xPpxcziixhKFGAgi7gT/eIT+U8=; b=2Vzdfv2jO/YjdBJ7b4DrUtOHq39OWml0kkBfGgV2KIjYHkzAw7K09rHKpS9rXpl/uu vkQp5Ab6d9nYCIEQYEcmv60FHGM9m1GpxWjP4U7mBWUw6YpgycALV6RWiyol3/dDObbw CmetyosiHhgpTbDOTYX/4ryfxvnKxZBqzPcfzEdsNhzP/APXETntygB94nHUKziTV3Uf UrQKPAE9+tpBRBeAudmhsVeb5XVQgvbJ16UkZxAiZXvzD9Jdg25lJouygONIcG1jQ535 pmmXezb5FqMEVjDXH2ZTEQ2TeVPo0XYOpltP7T57vc9+1iDB50dXpIWZHiajQtOgN1pk LnAg== X-Gm-Message-State: AAQBX9cwmGtEJxrYjRthgctJ0Zhv6Mz4gmL2vIX60eAqtEnTmNB5osln slNWq0IRILCTmAO9ingDogo= X-Received: by 2002:a05:6870:b68e:b0:17a:c83d:8f9d with SMTP id cy14-20020a056870b68e00b0017ac83d8f9dmr3925311oab.19.1680727246300; Wed, 05 Apr 2023 13:40:46 -0700 (PDT) Received: from wedsonaf-dev ([189.124.190.154]) by smtp.gmail.com with ESMTPSA id uq11-20020a056870df0b00b00176d49bb898sm6273610oab.44.2023.04.05.13.40.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 13:40:46 -0700 (PDT) Date: Wed, 5 Apr 2023 17:40:39 -0300 From: Wedson Almeida Filho To: Peter Zijlstra Cc: Greg KH , rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , linux-kernel@vger.kernel.org, Wedson Almeida Filho , Ingo Molnar , Will Deacon , Waiman Long Subject: Re: [PATCH v2 03/13] rust: lock: introduce `Mutex` Message-ID: References: <20230405175111.5974-1-wedsonaf@gmail.com> <20230405175111.5974-3-wedsonaf@gmail.com> <2023040554-promoter-chevron-10b2@gregkh> <2023040509-tamer-clinic-c14c@gregkh> <20230405191826.GA365912@hirez.programming.kicks-ass.net> <20230405202932.GG365912@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230405202932.GG365912@hirez.programming.kicks-ass.net> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On Wed, Apr 05, 2023 at 10:29:32PM +0200, Peter Zijlstra wrote: > On Wed, Apr 05, 2023 at 05:21:44PM -0300, Wedson Almeida Filho wrote: > > On Wed, Apr 05, 2023 at 09:18:26PM +0200, Peter Zijlstra wrote: > > > On Wed, Apr 05, 2023 at 08:04:22PM +0200, Greg KH wrote: > > > > On Wed, Apr 05, 2023 at 08:03:11PM +0200, Greg KH wrote: > > > > > On Wed, Apr 05, 2023 at 02:51:01PM -0300, Wedson Almeida Filho wrote: > > > > > > +void rust_helper_mutex_lock(struct mutex *lock) > > > > > > +{ > > > > > > + mutex_lock(lock); > > > > > > +} > > > > > > +EXPORT_SYMBOL_GPL(rust_helper_mutex_lock); > > > > > > + > > > > > > > > > > No need to ever unlock a mutex? > > > > > > > > Oh nevermind, mutex_lock() is a macro, mutex_unlock() is not... > > > > > > Yeah, so I despise all these stupid helpers... but I suppose it's the > > > best they could come up with to interface the languages :/ > > > > > > The only hope is that the thing can do cross-language LTO or something > > > to re-inline stuff. > > > > One thing we could to do improve the situation is to convert some of the > > existing macros into inline functions on the header files. > > > > We can't do it for all cases (e.g., cases like mutex_init that declare a new > > static variable when lockdep is enabled) but mutex_lock is just a function > > when lockdep is disabled, and just calls mutex_lock_nested() when it is enabled. > > > > How do you feel about this? > > > > -#define mutex_lock(lock) mutex_lock_nested(lock, 0) > > +static inline void mutex_lock(struct mutex *lock) > > +{ > > + mutex_lock_nested(lock, 0); > > +} > > Can rust actually parse C headers and inline C functions ? I thought the > whole problem was that it can only call C ABI symbols (which inline > functions are not). Rust can't. We use a tool called bindgen to read C header files and generate equivalent Rust (extern "C") declarations for functions. The tool has been enhanced recently (https://github.com/rust-lang/rust-bindgen/pull/2335) to handle static inline functions by automatically generating helpers like the one above (in addition to the Rust decls). So the situation is improved in that we don't need to manually write (and commit) the helpers. It may improve further in the future if we get better integration of the languages.