Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3191919rwl; Sun, 9 Apr 2023 09:48:56 -0700 (PDT) X-Google-Smtp-Source: AKy350ZiyiDFZFxgKROJVdaglbu5bPayd3w2nofP6YczuIPdIcHHYQXDoEiFxAA0fGXsoV8wxkYQ X-Received: by 2002:a05:6402:1209:b0:4fd:2140:5cc6 with SMTP id c9-20020a056402120900b004fd21405cc6mr7603520edw.17.1681058936430; Sun, 09 Apr 2023 09:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681058936; cv=none; d=google.com; s=arc-20160816; b=Lido+jvlOY8rLtW6M5+ZQvpS93gUw1jk1Uldmrn+xEjwiPk40WpCMUKwCCABDu6usG D7KKV55SUCx3mM6oz7+DCW5ShFx9T+Mki58BFiX+oTsqEQ18us/Vy13qqNq9pT07n0GE KWGInvJKzizQZNCwdPtUFn3owJ6jpssmvesS3S6BCnXu8CQAWvvzwlJcNy46Yku2UIQs ffJzqXeJl0bfUPdpg9j6FscordJTIzkfxI+VSfYChaLkAGFXnrSAl4kDckei6muElJIR CSIl39HM7iL5e5IUyA6Ynu/NroF5m7clNM/OWzWXT0N0OBe60bQGdHyXnJ4HDNwUv/yW 7HSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id:dkim-signature; bh=D0fvQTuLJsVSiFX0VfZzC1s/vcxQ1CsvIC212LbqATs=; b=0sEaHQgSAatM8VyDpQr8sJQ78fN5LsnIc72TvkWGnM5h7fm7+NBPy/6QgOc7shOD4h 5/uiuODxjQpynJ+jE6dbfubXaHRzT1E9Hsuo3ywJYIKJ5MDUyI1BMWT/EPOITsElYddy 2RU6TnAlcX7V8AvzqmcSlOM4tsa6i1anWFP5QfRVZ2aZxcOwaCrrA02qXcG80xVv2Qn8 TrQc8fLqJ1nHTppENRoFVCkM2k2Zhr70Hps6TIPH7P16GAnPeyUilKGZ2ZIm2j1ApacQ xU1Dt3UrZnowuzvXj7QSVn3iICDaQTPBeQEF7PepryDmZtsMs5i48AScsKSlbMO9OIuh kV9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=BnoqgldE; 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 t23-20020a05640203d700b005048d1f1e3csi3507216edw.158.2023.04.09.09.48.30; Sun, 09 Apr 2023 09:48:56 -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=BnoqgldE; 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 S229545AbjDIQrC (ORCPT + 99 others); Sun, 9 Apr 2023 12:47:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjDIQrB (ORCPT ); Sun, 9 Apr 2023 12:47:01 -0400 Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 616FC10FF; Sun, 9 Apr 2023 09:46:59 -0700 (PDT) Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-1842eb46746so3634988fac.4; Sun, 09 Apr 2023 09:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1681058818; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=D0fvQTuLJsVSiFX0VfZzC1s/vcxQ1CsvIC212LbqATs=; b=BnoqgldEeo+cxrUrAWRyB4iXpq4/C943w1Pgx0RQTKd4ZmfM3yv6Nyg9M2WMx+InEw QxcvAajpxc1BTaF88kSwB4ECERGQ6lAL9mnEZy/79cM45P0dmX1tpIK4nQhnakxE38TF y9ybNbJwS5Q3zlS/RF253igrRBXoSNn33Qqs2k6gnzDoonP/wYMaGdB/xpdpEkX4B4t0 yMvPeKtHQkPu+3VEXrORSL5/4BMvB3sIcDq3GjmwRP3aviAz+El54JjvmLMaJxV0EGMc vyTJ/5eOOdzNQ4dtKCaQQKw2gDCb4Un4tLJa5x0oiYuSS5GQZllUZAOhl4dq9DxWsLNr jsvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681058818; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D0fvQTuLJsVSiFX0VfZzC1s/vcxQ1CsvIC212LbqATs=; b=wg3ktzw4ZmGW2M9kVf9Yk/oxH+7NDqYNMBSADmo8JxohdrUFfzBLL7H1Hh/VX+SV7U /ZH4TgKB/84ImASGIUMg9DR6um4S5FYDHfz2XWIR6mWpLgHvtHHuDXa1kybXNQ4V5aWB RYngSsvYVPVxJDrBvfhFMN2Sl7hrbBBZlVhrxJJTi2lbwNkP32DlYLs1va6G9wrXO/jX bTRI3DJ+hqqjkl9hLAi73a+Ys1UQeexosUOWWLgNkx6RneUJBCOpz9V6pRaq190LbwRR CAHlS91ggvYd0q5MnGA3RpkWrLTdk60umXRyVmK7tnEeCeesdq4WP7J6dc3gnzlU1/5P lyyw== X-Gm-Message-State: AAQBX9eIt8GE5ArAj4HXIJ4Tw2mrP/LSbkFTdMD/ONvtT1nXO+EoRETY Bkh2Md19kyiWuAp3FIRFQ7w= X-Received: by 2002:a05:6870:9a0e:b0:180:9124:850e with SMTP id fo14-20020a0568709a0e00b001809124850emr3980301oab.20.1681058817843; Sun, 09 Apr 2023 09:46:57 -0700 (PDT) Received: from [192.168.54.90] (static.220.238.itcsa.net. [190.15.220.238]) by smtp.gmail.com with ESMTPSA id p12-20020a9d744c000000b0069dc250cb24sm3567715otk.3.2023.04.09.09.46.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 Apr 2023 09:46:57 -0700 (PDT) Message-ID: <301a83e1-0df9-7dbc-4737-0b18e87e6661@gmail.com> Date: Sun, 9 Apr 2023 13:46:52 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 From: Martin Rodriguez Reboredo Subject: Re: [PATCH v3 01/13] rust: sync: introduce `LockClassKey` To: Wedson Almeida Filho , rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=c3=b6rn_Roy_Baron?= , linux-kernel@vger.kernel.org, Wedson Almeida Filho , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long References: <20230408075340.25237-1-wedsonaf@gmail.com> Content-Language: en-US In-Reply-To: <20230408075340.25237-1-wedsonaf@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, 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 4/8/23 04:53, Wedson Almeida Filho wrote: > From: Wedson Almeida Filho > > It is a wrapper around C's `lock_class_key`, which is used by the > synchronisation primitives that are checked with lockdep. This is in > preparation for introducing Rust abstractions for these primitives. > > Cc: Peter Zijlstra > Cc: Ingo Molnar > Cc: Will Deacon > Cc: Waiman Long > Co-developed-by: Boqun Feng > Signed-off-by: Boqun Feng > Signed-off-by: Wedson Almeida Filho > --- > v1 -> v2: Fixed a typo in comment > v2 -> v3: Replaced `core` with `::core` in macro > > rust/kernel/sync.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 45 insertions(+) > > diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs > index 33da23e3076d..541d235ffbeb 100644 > --- a/rust/kernel/sync.rs > +++ b/rust/kernel/sync.rs > @@ -5,6 +5,51 @@ > //! This module contains the kernel APIs related to synchronisation that have been ported or > //! wrapped for usage by Rust code in the kernel. > > +use crate::types::Opaque; > + > mod arc; > > pub use arc::{Arc, ArcBorrow, UniqueArc}; > + > +/// Represents a lockdep class. It's a wrapper around C's `lock_class_key`. > +#[repr(transparent)] > +pub struct LockClassKey(Opaque); > + > +// SAFETY: `bindings::lock_class_key` is designed to be used concurrently from multiple threads and > +// provides its own synchronization. > +unsafe impl Sync for LockClassKey {} > + > +impl LockClassKey { > + /// Creates a new lock class key. > + pub const fn new() -> Self { > + Self(Opaque::uninit()) > + } > + > + #[allow(dead_code)] > + pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key { > + self.0.get() > + } > +} > + > +/// Defines a new static lock class and returns a pointer to it. > +#[doc(hidden)] > +#[macro_export] > +macro_rules! static_lock_class { > + () => {{ > + static CLASS: $crate::sync::LockClassKey = $crate::sync::LockClassKey::new(); > + &CLASS > + }}; > +} > + > +/// Returns the given string, if one is provided, otherwise generates one based on the source code > +/// location. > +#[doc(hidden)] > +#[macro_export] > +macro_rules! optional_name { > + () => { > + $crate::c_str!(::core::concat!(::core::file!(), ":", ::core::line!())) > + }; > + ($name:literal) => { > + $crate::c_str!($name) > + }; > +} Reviewed-by: Martin Rodriguez Reboredo