Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8843763rwl; Sat, 31 Dec 2022 13:12:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXvpFBU4QRDFMxCOwggvZ4dXh3a6G6ELd9w0eJv4t5tOa4LzgfTMbNjYZl4xgU9fUuxIkdwB X-Received: by 2002:a05:6a20:3a96:b0:ad:f155:7b47 with SMTP id d22-20020a056a203a9600b000adf1557b47mr42650404pzh.22.1672521128971; Sat, 31 Dec 2022 13:12:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1672521128; cv=pass; d=google.com; s=arc-20160816; b=jz//3lo57wax9yUZQs4xbnRHPzVMyKZWeIUA0XpurfUPGIzluAkV1Yx+g+6O3FXYJp GBvHmzRlFV5jF44eJRKRGxPjlv0uh+Fr7yCTqimfAHIJ/nf7B1ZbiegdorlPNIlz5BYi CuJLmHYRdnC1o+LbHP0zS5hlLcstd3YqN0lRPpxrhjSpyhQY06G60/8WYo8e5KpLT48F HLGL/FWA3m5UUyxIranH46K43ei196yg7MdbOoEo3W7ZHXxnTxp7UkHBw13U57MIihWN ZgI7LQjcRaN4W0Op85VDaPhYfxN02zGS1YGL+5Bx/oBRZVZ0W0WG4TWP1vMvOKxMEU4G 5LEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=JExMLOBN/jhFiWvi8h4YJPfejO0l0aDNrIYf8AH2nQs=; b=SS9VaWRqo6mcpxaYJM+9Od+EQp98S7imEfjQvolriLHey29tPcBBCTpU6N0QkELOE4 dO6KvHfJW6usDdwhFkglby2DKszIbK61CRIjbSqbha8Bmrej3tyxNhjqx+g8RXKxlyfm ciTZqqXJLURBPYdkCzx/T37otjUmIK8h2AuSlcHcRVfaFq0Fr1pewnjzlXmcTNxob7nA y6TkTF0mReqj/tPhMP6PPs5lznZBj8NE2U1qyyf6rJtzCFCQMKrbMmlGFQyDi2IWwand OUBNheqz6dgCvBLbV4wZUppxGg35LZfZmOxFsPXyn1K4yMtrFkxSJwnFdsA48k9NqUbq S21w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@garyguo.net header.s=selector1 header.b=uAKvXuL6; arc=pass (i=1 spf=pass spfdomain=garyguo.net dkim=pass dkdomain=garyguo.net dmarc=pass fromdomain=garyguo.net); 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 j8-20020a056a00174800b005397c4ad9e1si21765377pfc.134.2022.12.31.13.12.00; Sat, 31 Dec 2022 13:12:08 -0800 (PST) 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=@garyguo.net header.s=selector1 header.b=uAKvXuL6; arc=pass (i=1 spf=pass spfdomain=garyguo.net dkim=pass dkdomain=garyguo.net dmarc=pass fromdomain=garyguo.net); 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 S231610AbiLaTw1 (ORCPT + 62 others); Sat, 31 Dec 2022 14:52:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbiLaTwY (ORCPT ); Sat, 31 Dec 2022 14:52:24 -0500 Received: from GBR01-LO2-obe.outbound.protection.outlook.com (mail-lo2gbr01on2134.outbound.protection.outlook.com [40.107.10.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 097726243; Sat, 31 Dec 2022 11:52:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fWQkBgw8YR85bJKWhdBc5aYzQ9sVXhaq0cJC9AJa+tcvrUzzgJhIgKG9G4/kdlgli7cQdRrgRHGnk78kzlWxFyj+HHYO8g3bKtYW9WenjYyAfPrlnmhH2A6nPFp8Pq2vN2KlK/Bl3u5b3wilUBCx+WSxtGZe8xvTbk6P36iJiVzLljYLvcY3hmKxjQ6xjlq91tDAEig8hwqAYu98DE7C7qxI57PzZnMUSA9CD9JuBe7br1YAMoeJ+cfnOEZem1CNEFoQodP1mG4+Bpxfk3I5ovt7/fettDgTAtLK2+RmeXU62SUq+db7PN3O0ndH/Sas0vwWUJCwDUU3dnK5/IkTyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JExMLOBN/jhFiWvi8h4YJPfejO0l0aDNrIYf8AH2nQs=; b=kXcB5mBfkcJ8DAmG9WBVXlswu0jnuXhKuOFh5vQObb2/q1mSh1UG7Nx0aDSnZt4WNe2+Y88XyU2TIsjOniZ3tzVWbs2IMMz+j5Jj1jI1chRQoIbDzTV0RyACUuGpHHVUPXM16Xplz+r7C8a3bYPCBgZ7bo3eCoith9IuLZT3qi5HaITbOKYfJLU1UDFQ7Qb6QkQbM41HdbOv7B3wD6d9ARRDj/Vqo4sw1awmTjjwYk+BBy78iI+MVtUJEU3OYabz4xHblD8kGf/HhoFNQpzGBqRJZFqJJNnnl0+eqf6MVntu4mF9BVX6Kcci9ZN1IXtUVOQU/4lqctMNC0ucBhcFvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JExMLOBN/jhFiWvi8h4YJPfejO0l0aDNrIYf8AH2nQs=; b=uAKvXuL6aGk7a6qt+SCgJShLkCJgSN9cxA2X/k3ggKaBwxCk/OhaXTs90BmWG5lSbevcAFIA/N1YWIZ8KhIFNTpWHQEMo4VgpOn7+xwSEiXfnKu3hhr0qz4+jRC9Ij8X/p2nrCo13fsB/+WqGaATFOvODpmOjbmzxF60NidyOC0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) by CWLP265MB5497.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:15c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.18; Sat, 31 Dec 2022 19:52:22 +0000 Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::2f24:8099:5588:8ba8]) by LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::2f24:8099:5588:8ba8%8]) with mapi id 15.20.5944.018; Sat, 31 Dec 2022 19:52:22 +0000 Date: Sat, 31 Dec 2022 19:52:20 +0000 From: Gary Guo To: Wedson Almeida Filho Cc: rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , =?UTF-8?B?QmrDtnJu?= Roy Baron , linux-kernel@vger.kernel.org Subject: Re: [PATCH 7/7] rust: sync: add support for dispatching on Arc and ArcBorrow. Message-ID: <20221231195220.42e0893d.gary@garyguo.net> In-Reply-To: <20221228060346.352362-7-wedsonaf@gmail.com> References: <20221228060346.352362-1-wedsonaf@gmail.com> <20221228060346.352362-7-wedsonaf@gmail.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P265CA0071.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2af::13) To LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO2P265MB5183:EE_|CWLP265MB5497:EE_ X-MS-Office365-Filtering-Correlation-Id: 48eb0ea6-b9ae-4334-abbf-08daeb688827 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0abpd1OJZCc5dHuYqp77Qb1u9U0ZPDomwbuwuIY6nrN3LEoMEGHJqPDnJCXgDUTlhNL9k2hPjhEq6aMHxcpYs3+ggXxwF0QYSIzTUNE8rKh7Yxy5wSaIQTkWsBkOCXk2Eg+UcLkT2+0uwCZmpBTW/pLzX24CsCT8OTM2DESEmJ5+uEY1mTQYLJxj5zfKRHJuIXCNoLAYe6QjaVsuXPDZLoXMBOdYxgWHjYaANZDuHk7SuarL70eNFcGsH8uYTzC4nhLJ3orFIUeKKP2oNxRh95prNZmPzzRcJ8rLGhc05PKdr1gcI5+XPNhWze07FwvhMM2U8xcihdQ4LWKeB0ynNHgGL/VIUWOjm2mdc4VgYDJurwKHZODqjFm5jaQ3aU6qaMmNNbd0v0vKKSZuoPK4jZ9/42MTScL1DyRkCUPVBRduyMEZnqfNEOmChZA4sYZ6mMM5sg+PCa/68Ka/gGzaWLae2Wpltylz/8/msLEycQxs0LEDEkrEeJPUfmWeOBfwrehkUcdvcOswm+QxVPa4Bkl3F9sk4s8MHrlYqI5dAgFu1y23kakItUZpqavQPcfPpq+MsDlPEnWdsAD0xXHktzhlYTyLKg+jdyca3UstR3Gdobf/N0PoParAhuSKQWgWN40dhUaSZpucUVuNibvl5g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(366004)(39830400003)(346002)(376002)(396003)(136003)(451199015)(6486002)(55236004)(478600001)(6506007)(2616005)(8936002)(186003)(6512007)(26005)(5660300002)(83380400001)(36756003)(38100700002)(86362001)(316002)(6916009)(54906003)(2906002)(41300700001)(1076003)(8676002)(66476007)(4326008)(66946007)(66556008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?k+85HwF3eM1bpzLPzabTgeuQAuXNWVU8pC13UTQeFbP0NUOHYhyeaVXwdqx7?= =?us-ascii?Q?lMFTDTzxZK1S2gmFXlV9bNsKedMK0nLEoHilLUb7/YsB/KBIk9Dgx5/I8Qdo?= =?us-ascii?Q?ckPC128NVt5ervga3IMRBPkuuoyFivIUwAOGy6jUEwdMAlLDWpvMfK9Sb3Go?= =?us-ascii?Q?Xj6EoBrksc3G9RW3+iYSFdwPmKH/x/X+jqgm4J3cQCqv0zNqFKkVT3FqEcMX?= =?us-ascii?Q?5y7WVX42zgKSnDQPCsis5dYIhuQ3LlE0Kx840AZhtxqzAm3ochpa60uukQYr?= =?us-ascii?Q?P5rXdi6eQs1N4Z+YvApPHTpjSEdjsh7cGvpqKvtC2UH/ii7fPmoTmI0UNg+q?= =?us-ascii?Q?dmGNJPJlmcKcnErvwkw0ml2Kl+0fyOB+Jj7wJNzkxLDoFP0YpMWyIWFktCSx?= =?us-ascii?Q?bBGrKPwjfeJVXkoi406KuHmHSw46QmM5XQ8hTERBtmyiPMa5IQC1t9iyjwGV?= =?us-ascii?Q?hXXH15lB0AfzCIJf3kyX8jhXf0r6f5DiLZQgS6jsAqmQ3ZKpvykMO1L7ZmS+?= =?us-ascii?Q?EMij3gRrCl0R5NBRL5nKBDyGyHJSIDyyfQ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wEQnUPjCX6mB7/7Q9yXvlgNR3pd+y8aBnzPlFvWcspg6Pxhdrf+nK3GpKB?= =?us-ascii?Q?K42WlJSuFWGfMvud8UVBBamSiZFKni91fA8VGQTXVNx1FK4tJRoP3gf40oo7?= =?us-ascii?Q?/Cp57n39ojzgeAiTGGs=3D?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 48eb0ea6-b9ae-4334-abbf-08daeb688827 X-MS-Exchange-CrossTenant-AuthSource: LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Dec 2022 19:52:22.1023 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: g4P/xp+JRCzxfdcaZizbqqghEraOgLwsgflUEtvzlUxszVi6QTXyC3JE5DrSklHc6mo5ZMdjiUzZvNe93HJ84w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB5497 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham 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, 28 Dec 2022 06:03:46 +0000 Wedson Almeida Filho wrote: > Trait objects (`dyn T`) require trait `T` to be "object safe". One of > the requirements for "object safety" is that the receiver have one of > the allowed types. This commit adds `Arc` and `ArcBorrow<'_, T>` to > the list of allowed types. > > Signed-off-by: Wedson Almeida Filho Reviewed-by: Gary Guo > --- > rust/kernel/lib.rs | 1 + > rust/kernel/sync/arc.rs | 20 ++++++++++++++++++-- > 2 files changed, 19 insertions(+), 2 deletions(-) > > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index 4bde65e7b06b..e0b0e953907d 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -15,6 +15,7 @@ > #![feature(allocator_api)] > #![feature(coerce_unsized)] > #![feature(core_ffi_c)] > +#![feature(dispatch_from_dyn)] > #![feature(receiver_trait)] > #![feature(unsize)] > > diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs > index 832bafc74a90..ff73f9240ca1 100644 > --- a/rust/kernel/sync/arc.rs > +++ b/rust/kernel/sync/arc.rs > @@ -92,9 +92,15 @@ use core::{ > /// Coercion from `Arc` to `Arc`: > /// > /// ``` > -/// use kernel::sync::Arc; > +/// use kernel::sync::{Arc, ArcBorrow}; > +/// > +/// trait MyTrait { > +/// // Trait has a function whose `self` type is `Arc`. > +/// fn example1(self: Arc) {} > /// > -/// trait MyTrait {} > +/// // Trait has a function whose `self` type is `ArcBorrow<'_, Self>`. > +/// fn example2(self: ArcBorrow<'_, Self>) {} > +/// } > /// > /// struct Example; > /// impl MyTrait for Example {} > @@ -123,6 +129,9 @@ impl core::ops::Receiver for Arc {} > // dynamically-sized type (DST) `U`. > impl, U: ?Sized> core::ops::CoerceUnsized> for Arc {} > > +// This is to allow `Arc` to be dispatched on when `Arc` can be coerced into `Arc`. > +impl, U: ?Sized> core::ops::DispatchFromDyn> for Arc {} > + > // SAFETY: It is safe to send `Arc` to another thread when the underlying `T` is `Sync` because > // it effectively means sharing `&T` (which is safe because `T` is `Sync`); additionally, it needs > // `T` to be `Send` because any thread that has an `Arc` may ultimately access `T` directly, for > @@ -297,6 +306,13 @@ pub struct ArcBorrow<'a, T: ?Sized + 'a> { > // This is to allow [`ArcBorrow`] (and variants) to be used as the type of `self`. > impl core::ops::Receiver for ArcBorrow<'_, T> {} > > +// This is to allow `ArcBorrow` to be dispatched on when `ArcBorrow` can be coerced into > +// `ArcBorrow`. > +impl, U: ?Sized> core::ops::DispatchFromDyn> > + for ArcBorrow<'_, T> > +{ > +} > + > impl Clone for ArcBorrow<'_, T> { > fn clone(&self) -> Self { > *self