Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4567235rwl; Mon, 3 Apr 2023 06:52:05 -0700 (PDT) X-Google-Smtp-Source: AKy350b/7DFqDfKUX1CCVkRUUsl2mRHAXGfh6SY7gdl0QUB/opEreY/k7oR5G+REpgisxK7vOdOd X-Received: by 2002:a17:906:19c3:b0:93e:3194:99cd with SMTP id h3-20020a17090619c300b0093e319499cdmr35924236ejd.12.1680529925504; Mon, 03 Apr 2023 06:52:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680529925; cv=none; d=google.com; s=arc-20160816; b=w4r1+EDXa/2HH/gAW5qISv9u8Za0orXKuyBKXSp95bAQZYdFfJv/o59KrpuXspfGJi jwnHp9+zBheNVvO7+fkzcDXuXFJ07P4RV4OVhu7IRh4HNkM8ZbTbjF7Cm3CcF2g4ab1Q 680GNvk8Eu1GI8cmMsatzDEBeBxGd90e7if1unTp28wMHgxl1gq1IKHCVjXWM3ekTnac tcEqfstxtfwd4eIBCqslWEAzMJD1RzH3pBtDzUlPOJWnDfVFUw4xrWqdFc/SW7OXry7x d2CHXB5dXspEutsQc2/YohkGFXlwiTvC5eHsrezJsuJ5x5fHnIayo5cM+tqa3wr0C3Tv RjRw== 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=InpwIkfzMfFKvnUynZiDQ4EYC27ogHEpEwT6lD5JTZU=; b=bKOjMiwzMdvqGdJ0U6Lja/Dl0suHsZrS7U9yJyV99IPtEfCWTkFt4jDP2c2yGgUPhC 85pxu9Hk5njMHJGjENrbcFiVDRCTGNGnvoJJ/xWFOzvtaiZALHq5G/AN8xqCrXXQ3hXv 3X4WO6Ojju1XorNRcKLZ6b1A/pZXdyJgCCedxC8i35ZgO7UM7QqGuYTLtpZZU78mDHT7 QmiD4sHNe/1oZKOqyDcbYGcKzeway8B+AH0k3djJQZqAe1gsLxEoVQZJqCARiqH1dEUs FFXeoT7phALfiEW2mjv4+WOCDt9wr2lcMSqPJ28PCSjRoWeGXBCXM9RgkrtusQl+OnqR 75Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Q8xv2xnI; 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 d21-20020a1709067f1500b0093346a7bf34si627126ejr.406.2023.04.03.06.51.40; Mon, 03 Apr 2023 06:52:05 -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=Q8xv2xnI; 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 S231897AbjDCNu6 (ORCPT + 99 others); Mon, 3 Apr 2023 09:50:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231634AbjDCNu5 (ORCPT ); Mon, 3 Apr 2023 09:50:57 -0400 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 170EB1DF80; Mon, 3 Apr 2023 06:50:20 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id w13so10368655oik.2; Mon, 03 Apr 2023 06:50:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680529818; 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=InpwIkfzMfFKvnUynZiDQ4EYC27ogHEpEwT6lD5JTZU=; b=Q8xv2xnIMER0v9Il8wiCe/yWjZjrBQRXMgoZmxz+BNRL+naN1f34yfFTXhhqEUZo0n 97mHDkYMAfPIQEilTAnjRqS/PBbBG8y9Htnoq/FqIG9G2Ocydmi7IALhiSSvK6PQ1/O0 C5W+eUG/X9zXQiwklc5OY8vueJp6IirvRkL9gPrwlRPcUYPJtMaWLPlSN+v9TkkIGmU8 yHkaZiX5nCsM5v8igTmMzPUSb0V+r+orKDy4/ak9c1+4o+8rr24WpHLeElYygqCHLpub uZ0JQlIt3Be8NtcU8EniYPhrpIXMOx5K1VN6+ck/EKqnnkCRD4FKtiBx1Dr7otugrHNV R/cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680529818; 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=InpwIkfzMfFKvnUynZiDQ4EYC27ogHEpEwT6lD5JTZU=; b=Sp0DD1PSnJtjbfTi6YaAP6+GsXABSUvVqYO6hGVZBBrGPZrrVgOwhWRmVbjiRMmPgw ItiEEawg3F+owaKG8lVaJKveazjSIn9qKbmbzH6s1hiLIzcDn7AZJ4rgQtz63hHrmSOE 76+fSl1w4DdJS88nMH+DkgtvhnowatmtDw3457Y/AKzPTrAcBPm7u+BTpmYflKgaU3/o rsW7xWO1TlnqyVC9y4Y2ku2oSHfp7G/+zwXXwYrP9IqSgo4OxQunx+sO7VmcXYFCx9jG nj8RsZbhzVbyO6ZCIfYB6tDFGJ0QZegazjy7sLGE6+EUcSPZUlY2A4KD8vblqS1544cC f7DA== X-Gm-Message-State: AAQBX9dc6nXHV3CXEBuDwPY5EqZsqNzr768QWmjnGh2Ml9P4ouHHktjW iMO5UmFrdkLE4wAAw9sU/uc= X-Received: by 2002:a54:4d01:0:b0:389:93da:f533 with SMTP id v1-20020a544d01000000b0038993daf533mr4847055oix.40.1680529818512; Mon, 03 Apr 2023 06:50:18 -0700 (PDT) Received: from wedsonaf-dev ([189.124.190.154]) by smtp.gmail.com with ESMTPSA id p20-20020a4a8e94000000b0049fd5c02d25sm4019354ook.12.2023.04.03.06.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 06:50:18 -0700 (PDT) Date: Mon, 3 Apr 2023 10:50:09 -0300 From: Wedson Almeida Filho To: Peter Zijlstra Cc: Boqun Feng , rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , 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 03/13] rust: lock: introduce `Mutex` Message-ID: References: <20230330043954.562237-1-wedsonaf@gmail.com> <20230330043954.562237-3-wedsonaf@gmail.com> <20230330130108.GE124812@hirez.programming.kicks-ass.net> <20230403082052.GR4253@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230403082052.GR4253@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 Mon, Apr 03, 2023 at 10:20:52AM +0200, Peter Zijlstra wrote: > On Thu, Mar 30, 2023 at 11:47:12AM -0700, Boqun Feng wrote: > > On Thu, Mar 30, 2023 at 03:01:08PM +0200, Peter Zijlstra wrote: > > > On Thu, Mar 30, 2023 at 01:39:44AM -0300, Wedson Almeida Filho wrote: > > > > From: Wedson Almeida Filho > > > > > > > > This is the `struct mutex` lock backend and allows Rust code to use the > > > > kernel mutex idiomatically. > > > > > > What, if anything, are the plans to support the various lockdep > > > annotations? Idem for the spinlock thing in the other patch I suppose. > > > > FWIW: > > > > * At the init stage, SpinLock and Mutex in Rust use initializers > > that are aware of the lockdep, so everything (lockdep_map and > > lock_class) is all set up. > > > > * At acquire or release time, Rust locks just use ffi to call C > > functions that have lockdep annotations in them, so lockdep > > should just work. > > > > ffi is what the C++ world calls RAII ? No, ffi is 'foreign function interface', it just means that the caller will use the same ABI as the callee. > But yes, I got that far, but I wondered about things like > spin_lock_nested(&foo, SINGLE_DEPTH_NESTING) and other such 'advanced' > annotations. > > Surely we're going to be needing them at some point. I suppose you can > do the single depth nesting one with a special guard type (or whatever > you call that in the rust world) ? I haven't looked at all the advanced annotations, but something like spin_lock_nested/mutex_lock_nested can be exposed as a lock_nested() associated function of the `Lock` type, so one would do: let guard = my_mutex.lock_nested(SINGLE_DEPTH_NESTING); // Do something with data protected by my_mutex.