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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFB73C76188 for ; Wed, 5 Apr 2023 20:50:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232640AbjDEUuB (ORCPT ); Wed, 5 Apr 2023 16:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232985AbjDEUuA (ORCPT ); Wed, 5 Apr 2023 16:50:00 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AF6A10E7; Wed, 5 Apr 2023 13:49:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=IKKsnS3MuUIvRxMy4gZqz2HRi+ZqkC38lFixxuuqyM0=; b=fE14ROxcsZyXXmo/B5pJ4W4N7Y BL9RtcBObIBQP/0sd7V5jWKBJCz8XJSFdaseUG5oekzFKVgjuSYzxKu6Uc9dXu+SJ3JppkqmcWjbH hM93rlw1sXbzoSMyDOYJYy5VyseTmP/h5f2BpVl8IzNhm5WEZ+ANtK4lggPZUFCc01Jy3CI7Lcr7o qSaC+u81xVk2+VP9FezUkzI1pt7zLW1h4TDhaZT6+ZubXunWdEUx20wDNw4+AjEdMeezAwbnbkjAx RVTo6TX23eHJWeBE948QSCg+cxyVX0aRK5iS3YHn0htgslwFijmbwaYqCAhDwkocw+qmqJbZBuvwC /B3+rYJA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pkA4d-00Gkcy-NU; Wed, 05 Apr 2023 20:49:43 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 0CE1C30036C; Wed, 5 Apr 2023 22:49:43 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E98FA26A19DBF; Wed, 5 Apr 2023 22:49:42 +0200 (CEST) Date: Wed, 5 Apr 2023 22:49:42 +0200 From: Peter Zijlstra To: Wedson Almeida Filho 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: <20230405204942.GH365912@hirez.programming.kicks-ass.net> 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: Precedence: bulk List-ID: X-Mailing-List: rust-for-linux@vger.kernel.org On Wed, Apr 05, 2023 at 05:40:39PM -0300, Wedson Almeida Filho wrote: > 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). Oh man, that's sad, I was hoping it would write the equivalent inline function in rust. > 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. But yeah, feel free to convert macros to inline functions where the difference is moot. There is indeed no real reason for mutex_lock() to not be an inline function in that case.