Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1247866rwl; Wed, 5 Apr 2023 14:07:54 -0700 (PDT) X-Google-Smtp-Source: AKy350bD0GrypgKNDGy2T+ojtxhoR7HHXv1DMr6dSPTb/fEOdTZNoafIgzOm12o36zCy3uVBmrXC X-Received: by 2002:a17:90b:4d81:b0:23b:4376:f8cb with SMTP id oj1-20020a17090b4d8100b0023b4376f8cbmr8285024pjb.26.1680728874680; Wed, 05 Apr 2023 14:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680728874; cv=none; d=google.com; s=arc-20160816; b=ChR9S9Us/9zgmTy1QFHqjpd466aOlM52ddY2QoeaFD4k2S/mFIIqWRzP2fKwoXgZb0 PIBZnm0tmyz+yGEW5dunV9X9dYajbliptgY4qYg71xx5a5rM2xbSME3qU8J5yVUK1WuZ dvnZd0ZDS33bjsx3kafdDRcva48/eISiwMpoejCm3Bi8Iw9KfNhZg29ytJNhQD9rE8IU AjtqFJHRgB+meEUkKjDNctQIK7sVDWjDK7WGI+HDCOtJ/JnTPiUGNNGwu3l4tnRFVaRd 3+J60V+fpadkP8uuvkcsJvbg2Rq8JOLzdFcJitFqlD20wHEkGvALrnxKEpnI62Mv3Q8d 0hvw== 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=IKKsnS3MuUIvRxMy4gZqz2HRi+ZqkC38lFixxuuqyM0=; b=Fe9MrOpxVFjaXCxVB4hBXzDRgfMgHqKjKPYhHgORDXrt5uhBMzeTBXsFbjpaGk2h+3 vDNQ5BeAj8VMLyOX7fiuJhSZCVfsLNGLVuY3UApYqHT+yVWYGP34arKWs77EtFoHjKF4 SWufbbZ/eH9De2w9coyvkkGYErzMixOiYhfUtxfiueMEbDFyoQGSB+qb5vIJBUTiSLf+ BZ1K8dU2N6RIHAGJITYYZA2R8QEsOq+XAz8M5uKochzpt+KCGcMw1tierhOsPHgRS6Cj vH1NmkaSTmW1plMiTIX4ZTAsodpNwrSuM4QZGsNL4WEGErGqP+6KRZ42FCM+1EoYqPyV h4GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=fE14ROxc; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 127-20020a630185000000b005132381cfb9si12812126pgb.614.2023.04.05.14.07.38; Wed, 05 Apr 2023 14:07:54 -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=@infradead.org header.s=casper.20170209 header.b=fE14ROxc; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234222AbjDEUuB (ORCPT + 99 others); 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: X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 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.