Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4544350rwd; Tue, 23 May 2023 09:03:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4BZMEVeOzZYAj0xWjYSl7z0brzgjVWR4aCP85GOPdp06K6yCi2IAZxytbTc/dnFabBLxLI X-Received: by 2002:a05:6a00:2288:b0:643:aa8d:8cd7 with SMTP id f8-20020a056a00228800b00643aa8d8cd7mr22046643pfe.32.1684857810323; Tue, 23 May 2023 09:03:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1684857810; cv=pass; d=google.com; s=arc-20160816; b=zSXjqvK8oZpzguUlkMC3WsL197oNafVx5uTtJrZfgAFEPd54QVzuVkRiwBmsaboYO/ jPRkw2NeAO3AtFYv/LITkzZIzAkpsBQJ85+/0mwtoElqV4HsgegFo4aBktHU/H4xhPGX u79ptAVfyo1F3LSKrdch9dA30hqaI1kP9ce2Ou61WPEuO2Z/1BS9KM6ki5HcE/uJe3iX FYWlOSG9ej3ngVc6iPsUT1AM0bYB7ZEN+2gMh7fuiKm+QxiodtnMQJwG5AES3wfPlSQC LmpEMJ+kLAmsW+8h4tkRmbD6sAmNfpbNUZnd6m3m7C2WRXN+VRbcf/TUzPD7UcCYMekN ow9w== 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=tTy2E6iayPsGuZQw4h2Ilv81k8Fnsx/36G4adnjITy8=; b=CycebTCUkXOTAajOkeCPKEantniPMOscN+z0qVTE9uORgRrEmsOJ+ZngQ1LPQylGA8 gNJer+HUz3uL7R6ClNPwYGL1C+GjzKwjDu25JOKRuTtCi0P0VEygQIRjxiBzWbNwYB/T 0LC/zEs0dz1e3QgleB+7YrH69n4277oMC+boEhpEC8mPGvBZRa2xgQWYK9udjOD940Wz krpDYo81K499P+okPXHoWuNwOePdvyMQptzgQw8GjWju3CDUn7DIlia1LilTGBCdPkmu iWcdEGStfzDSLKfCGxgwMAMtib57CgF/WCC9F8D8CZGmr9aXWhGybQj2UStKHiRBGS65 Ay2w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@garyguo.net header.s=selector1 header.b="F/8UwaPp"; 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 m20-20020a638c14000000b005343a5a52cdsi6682268pgd.121.2023.05.23.09.03.00; Tue, 23 May 2023 09:03:30 -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=@garyguo.net header.s=selector1 header.b="F/8UwaPp"; 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 S236488AbjEWP4g (ORCPT + 99 others); Tue, 23 May 2023 11:56:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235212AbjEWP4f (ORCPT ); Tue, 23 May 2023 11:56:35 -0400 Received: from GBR01-LO2-obe.outbound.protection.outlook.com (mail-lo2gbr01on2137.outbound.protection.outlook.com [40.107.10.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4898DD; Tue, 23 May 2023 08:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B4NmIVmeUvWhzH7FjDVEJBTU593XS8x8r7H+Sj9cuFDf3BdBhokPmoRKbQLoBBsAryj8mnKcGp3AksFeup+PkWHO2kdPCsof2AAyiXrWTNmcoUWxsuF3QaVxGsbexUbpZiPJsCAjPpUOseW9j5aqJfKPu986z8mpsFhvTsciYmebhcoGMuZtEWyiShaqYcyGNJfSkYpp9umCykytD5dPNTKObDP/N3Df5xcSJhif4EPtHDmmDQzG/lGd7M7sO8iOOCzcPVbCM+Eg5w0w4DPjkD4tIlIJru/IlZ2N3YWB29qtejniKgd4Hwoznd8Uzjc0qVAr3whHIGfYB0zsCTXO9g== 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=tTy2E6iayPsGuZQw4h2Ilv81k8Fnsx/36G4adnjITy8=; b=f8JNcmTFwjbSy77N5JCCYqEnZh6W1yXAU6ialSq+xNyjXDpsxKg2Qz6FVpRpFFuBIifJnUXzsztAk9s0yoQvW8+agiqA0c8Ca+2Ipnztdbe1z247hoajbX0bNXZeXZacQbEMucqi/U3mJ1IWSC7hWy3Pq1CutZ4aCIwbVtrPYkZpJHBtwedv+Tcsw4Ag/E+EiFBlsa2pTkur4t1Bsv/D0W/8ZesenmutdaTbjezo+oMUwzcLc7pMgKbl1uC4qA3A6R82ueYtlQHCmFZW/SU6rCb3G4qo470qN1pa9ROvrPCPpoHrAcd5WcaFIo9PtORNfBFL6XcSVtOlvHvyHL4y1w== 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=tTy2E6iayPsGuZQw4h2Ilv81k8Fnsx/36G4adnjITy8=; b=F/8UwaPpc5DPBOTHaCtEeYwPD5bIW6NbF4LReNFKyjuCXxVemx6++5+lijPMw/O5L77AkDZDUNGKHlry0SPmF1KgxmkpZiG+c288TUDJ66bhqQMBdiKS2C9bKeNisV0JbHPPuUeFjrR4H3IMQ4oeshEip7xhINP0rjPRFYWIPNI= 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 LOYP265MB2096.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:117::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.14; Tue, 23 May 2023 15:56:31 +0000 Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::1d51:d482:270c:7daf]) by LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::1d51:d482:270c:7daf%4]) with mapi id 15.20.6433.013; Tue, 23 May 2023 15:56:31 +0000 Date: Tue, 23 May 2023 16:56:29 +0100 From: Gary Guo To: Alice Ryhl Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , "=?UTF-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Ingo Molnar , Peter Zijlstra , Will Deacon , Mark Rutland , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Andreas Hindborg Subject: Re: [PATCH v2 4/4] rust: task: add `Send` marker to `Task` Message-ID: <20230523165629.0b092b08.gary@garyguo.net> In-Reply-To: <20230523144418.1250547-5-aliceryhl@google.com> References: <20230523144418.1250547-1-aliceryhl@google.com> <20230523144418.1250547-5-aliceryhl@google.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: LO2P265CA0202.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::22) To LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO2P265MB5183:EE_|LOYP265MB2096:EE_ X-MS-Office365-Filtering-Correlation-Id: 069747aa-427e-4ed2-e437-08db5ba646d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tMD+onxjflx9WLf5HUVbK61MAf6ZzSfN0mv5iKTLxMS8KVH/SXEvGjUWYSUSVVbKOtnhRkXCEltXg3OyFLA/jsvN+qGG5MZJbWUdtBxP84X2JHyz/SULbm9L+fbSx+TVZxjtDWlEuKLeTCUslIU/rxwisFuNV0OkNPxerYm59bt7Goz8iM89Pg932muPbDmnz8dtFvC8FlxoGZobF0aEV5Z0FKDxtK2Qg0P9d6W0tyW8ks4xnEiFcxdIbb0bK3oWrw81Z8tujEAvsQJOaidNCI9lQxCohBZ6CC0+gEUjh6WZWNUUdj1fO/VFtS/FeqDKpdcvmFlgpniqCkEvE7FMb+hslKGbUAdQZDIpsjBsDv4oLcuyvW5HX+QeqMuxb+7letWULBTEU1Huz135flfZC3BkWFNae2qYXl3JnjA1PxxCM5/3YvYhfMxH+9GgBHFYljFgcqpUPxkynjWSLRi/fLwAIU0tDwMYBfBD58fPnQDAjS9cKao1GyTtaxuKMoKAnK2WvYmgxNgtpgO3vqsT4/7RTpf4XxSa/CWb7FqPPDeEp4DuhzhxEimnefwfVVAQNnlGEqdXAbEBnrLI7RjnGKgna1PGZ0pBEnZ5ynOjf6g= 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:(13230028)(39830400003)(346002)(136003)(396003)(366004)(376002)(451199021)(4326008)(66476007)(6916009)(66556008)(83380400001)(66946007)(86362001)(38100700002)(36756003)(54906003)(7416002)(478600001)(2906002)(6486002)(8936002)(8676002)(186003)(6512007)(41300700001)(6506007)(26005)(1076003)(2616005)(316002)(5660300002)(81973001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?IskT1XD8FyiWaHe95zQiRDJZ+O6jCf2ST/93zzh2N7zWuzshZpUZZmGF+RRt?= =?us-ascii?Q?9BdBfEhBAhLzZuEpDtlhGAxVFTNrermHKCy0lETxTjfIPOeFSASF108XxH6S?= =?us-ascii?Q?zPGBLb4ObEJCd9OMFoqGf3oTLJPlQY/qx0gGz/joNDBOZd+t9Hsjn0K76tiT?= =?us-ascii?Q?fg6F0s2U20y9uvGseIeMwRBRe+RjP9cAtZ74TFNYzMqW05PhaJSW8e2A/YkN?= =?us-ascii?Q?vAcYxTj99pqbnUcETtpifeRZO+HKcY4Gs5fQ+IIpfRq3ttD+byN7O/+hknNt?= =?us-ascii?Q?wNVPLoXa1659bDFUmueZehhcXiFb2B5etOSRvi9q/qC+VXSqXlracpWDGyIU?= =?us-ascii?Q?yQNsLNsPYPenfMgkOwAHKxyws+P3OvLFz/yl2A66RJzY0Qv49EUQBglOAVrl?= =?us-ascii?Q?FVSFgyzJV1ygIj8hkqQkqgbK6wHXBp8SmBeqQGezj+uly+9ISOepHbcmHgN4?= =?us-ascii?Q?MF+aEdJ0QoTByMIWZkwKVnQ+O7r539oRamL16gsJpHRRwd7SKybLlsjay3NH?= =?us-ascii?Q?ewZNzDM3jeKMFCrz1zKE5jmlVM8HXqo046IyZkRbojFS0TNjR6O1sx5EDmGb?= =?us-ascii?Q?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DPmU1YCuFHYNjnTzzWgAKopZ?= =?us-ascii?Q?BVEqY+s0buqFQ7xJE0KmpIbiNTyQ8Pt/xKm/0+guCgR9pPbV1AVq8iRsoJb/?= =?us-ascii?Q?y6mRRIyKuPttiXzA0/AIwnW3ggMcey9WgXv+juck?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 069747aa-427e-4ed2-e437-08db5ba646d8 X-MS-Exchange-CrossTenant-AuthSource: LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2023 15:56:31.5753 (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: 4OO8NmRQ0zVRUWxv2Ii/AZjWZJ1v490xvUjrcggj3Ines8db9MXNyOnssfP59nmkXZslRShh5wGmxXwMjoAcUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LOYP265MB2096 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,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 Tue, 23 May 2023 14:44:18 +0000 Alice Ryhl wrote: > When a type also implements `Sync`, the meaning of `Send` is just "this > type may be accessed mutably from threads other than the one it is > created on". That's ok for this type. > > Signed-off-by: Alice Ryhl > Reviewed-by: Andreas Hindborg Reviewed-by: Gary Guo > --- > rust/kernel/task.rs | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs > index 526d29a0ae27..7eda15e5f1b3 100644 > --- a/rust/kernel/task.rs > +++ b/rust/kernel/task.rs > @@ -64,8 +64,14 @@ macro_rules! current { > #[repr(transparent)] > pub struct Task(pub(crate) Opaque); > > -// SAFETY: It's OK to access `Task` through references from other threads because we're either > -// accessing properties that don't change (e.g., `pid`, `group_leader`) or that are properly > +// SAFETY: By design, the only way to access a `Task` is via the `current` function or via an > +// `ARef` obtained through the `AlwaysRefCounted` impl. This means that the only situation in > +// which a `Task` can be accessed mutably is when the refcount drops to zero and the destructor > +// runs. It is safe for that to happen on any thread, so it is ok for this type to be `Send`. > +unsafe impl Send for Task {} > + > +// SAFETY: It's OK to access `Task` through shared references from other threads because we're > +// either accessing properties that don't change (e.g., `pid`, `group_leader`) or that are properly > // synchronised by C code (e.g., `signal_pending`). > unsafe impl Sync for Task {} >