From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2043.outbound.protection.outlook.com [40.107.236.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E69618FC84; Thu, 27 Feb 2025 22:00:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.43 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693621; cv=fail; b=ZQRNt1m7WAGS65RLloDPjE9KTv8C2CC948dIwlzUVBxCnz8g0iAym6W2ILa3PWCKD/6ebyFDK7g8OSXFKJvbcKkSO0XxxKbwu/w7hmrk8HvMHFyrd2ta6FwbwN8Hhv58wwbudtvEQALSmDb6KF69Sx5HKfSBhMvN0u/XBcIOOVY= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693621; c=relaxed/simple; bh=Mrx//iY5PcExO7721lki4qmfKsYBvgGOYZYyuubYzAQ=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=qAd10tRo1//eqRjdAyLSee0d1+62wwFB5tbhBh0+F6/aR1hqBniBO/7bzV8qYTu9ZAVE2ewkL7qqTOGu8nXZtWY8tbOuk+sunFG3BO3tGK2y9Bmw3JCnyF71Hkbyu+gsyMbmFwaygHjPkvvNzVZ9TWK0z0ruIoOs6mXR1N50M/g= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=mjOtz/Bh; arc=fail smtp.client-ip=40.107.236.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="mjOtz/Bh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZOxNqnF9w7hsNUfxA0n4KX9Bciq87dg47N9hoXMUwhnes4OwXMeF7L/6wiEJu0L4gBfgAKOuqDm3+2jzI+Si0WpL0OATwDZ6ZtmYQD5bR2YWIl6NgcJUq5C9fKQdcaz+2I2p45cGM+L9rcKpF/j6cKGgEi+RNh7H9CmxpUEC9EGsB7dL+YryUi3QGFsCujQ22bX6nmxyRPupVA2dT6OtixgZEE476mFBddhlIR2bxGZEsjSRIPGxmD14uODIhy9/PNLyiChNvHJqzRYNobz4AeYATzR9Kt6YWZE0voJ014tLjz92mecUygdd+Mvm3VKUtIDLo/jaWS5C3MGYtXgWdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=owgkmLZotW/mkb0oBXTI5xKcJ6KEWmqBQGIV7p+IHF0=; b=NoiFEVFK5Z4B3A4/tPY+cdBHvRvWDs4+/eN46Z0JrDniIHcEupxosyOTWA97hlMrZYcEFrF3gka671KeD9Kx9zwNKRktMkaaY6HzNavxM3ZRHbiWmVyQJ1uTYc+R1pUG5OOoU5UCUYY6Z7wcK979BHi0VvvphK+Hdb3BGos61+CpFKTdusHdHqTWOzxeNorNyUsaP75LnfXTDA8f1TwIjaGiUqVkhRici63PZZfH/LZyVcBR7frCajcGucKy6flZ0jmDe3Mg3Kzt4Ft85OHm682EdSZqya5ijnSfxoP3K4u0bOi/Yt9ciPOy+O7SgMuWYhM8lkehse3nPOZGN4DGeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=owgkmLZotW/mkb0oBXTI5xKcJ6KEWmqBQGIV7p+IHF0=; b=mjOtz/BhCQzceu8yaS6V4VpNZ/T8juzLvOF8l75n3eImGYRkI7X472dey0/4qw/+UdIe1szCHPjDJLAeIlbL7keo6eaQXI2F/NvMOeAF7vw0oKIWRBlB+/MFsR1Ja8Fn8/pH3Qghbb+QXnV0Y3hcPXgFiDnbWEYGqKz4RXuXCN1yTzBe8bwNN0xAkyw964VYW2t1RQ0PI77BdqlZ49qgRZEC7GkWTWxuea2Gt0hnhi2yRPSvoS4DkUicwJzLG5doleqOw7etlOXfQRFiCaghle+vQY5NZ0QRMWIP4tfC1QowJcyifoeZ2FUeTqThwWC8gi3+FtHxceRedNAVFjvEIg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MW6PR12MB8663.namprd12.prod.outlook.com (2603:10b6:303:240::9) by DM4PR12MB6638.namprd12.prod.outlook.com (2603:10b6:8:b5::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8466.22; Thu, 27 Feb 2025 22:00:16 +0000 Received: from MW6PR12MB8663.namprd12.prod.outlook.com ([fe80::594:5be3:34d:77f]) by MW6PR12MB8663.namprd12.prod.outlook.com ([fe80::594:5be3:34d:77f%2]) with mapi id 15.20.8489.018; Thu, 27 Feb 2025 22:00:16 +0000 Date: Thu, 27 Feb 2025 18:00:13 -0400 From: Jason Gunthorpe To: Boqun Feng Cc: Danilo Krummrich , Joel Fernandes , Alexandre Courbot , Dave Airlie , Gary Guo , Joel Fernandes , John Hubbard , Ben Skeggs , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, paulmck@kernel.org Subject: Re: [RFC PATCH 0/3] gpu: nova-core: add basic timer subdevice implementation Message-ID: <20250227220013.GQ39591@nvidia.com> References: <20250226234730.GC39591@nvidia.com> <20250227144618.GE39591@nvidia.com> <20250227161733.GH39591@nvidia.com> <20250227192321.GA67615@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: BN9PR03CA0660.namprd03.prod.outlook.com (2603:10b6:408:13b::35) To MW6PR12MB8663.namprd12.prod.outlook.com (2603:10b6:303:240::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW6PR12MB8663:EE_|DM4PR12MB6638:EE_ X-MS-Office365-Filtering-Correlation-Id: 081d4146-ff11-4ff2-6b88-08dd577a1e09 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?4FPIEh17SLbvctkgpXOU6xD4BhpFU6AciO/MCCbV8uoNyEn5iRhzU8Q0gXyW?= =?us-ascii?Q?iqIfomZEnv1M+q2X9h1MxINXPdseRtkHbFRscxs4F+p1gddu80Qv/q3JpvsO?= =?us-ascii?Q?g9I1hQS2LrmYo3BDqEAS6GK2TWyGFrOOQU5NTohjRPh1MM+4KSZY/440RXni?= =?us-ascii?Q?gJwwB2lywV1k8jy6g6l68+1wRCCcRabrjOwAy9WPeg1zJ+Mufft+87vIb0w3?= =?us-ascii?Q?ysUJuHvusjUJaH9WN+o8Wi/fgq06NljqZKzceLaFsUM4pVnKhaQIT4WUou1w?= =?us-ascii?Q?+ERRRWtwPgVtw+PH+fS9Ykj8troIT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qPmtJ+Rnvjpq0yaDq2zi/UBtjnE/uJuskdcMHG+ppDevatjvvY?= =?us-ascii?Q?3wFSzqcT/YkdyB4qhx5/wgOwqiM55BLOoOQYoQizR64EvNUMmBCvVvJwCJ8o?= =?us-ascii?Q?yRAmL5FR6U3vZ0a0DByzIn9ipuwQbm8+rHZn1sm8iu2D76nPUb4JqlMXNd1z?= =?us-ascii?Q?TzntnCAQYic1JfmWbpSRYsDUV1XY?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW6PR12MB8663.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(7416014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?jpO65VMjpuIwlqG+PRv2c6OUHE4WKjRINetGojbFFBKOG6/cRYo8J+Cu2Q6V?= =?us-ascii?Q?zS4UzwiDoMk49oQ2gAYOXxWY/E4KsW4WzyTDpkFsWxzl4btDW03IkmGY3pZa?= =?us-ascii?Q?4qJ/lKDw1eHOcqQ+IiWFlK8MOIaLbPDkHJKhd6fbcGn4+hJilDMpEOhvKj77?= =?us-ascii?Q?T56zNG3LpttJb0xFgFFHNJX51XHO/of6Is6BDndnSRTD+nf2e2YIm480+S/C?= =?us-ascii?Q?ZhslYksZMWYx0C7BpCkOUmzlhwcln9ZAGQEZ3PBZGMnIhj2tA+9Pl5mHjN/9?= =?us-ascii?Q?fch4Im2MAKXSXUJk93DM+uCw7i04Ax9Tlf/1tdhkOOXvKyJIqbMUFLYdxu9r?= =?us-ascii?Q?fYioftrlLFOa3DGHv1CSZpQGtj4xlV8Vp2py08IPI9f3S5pv/qJGnfx+sfMf?= =?us-ascii?Q?Rpb8r090Ea1h4+YWWLeVIf+VV0xTuS7sPfJ3kUR+wpP3ENRx6MZBsFYhfFHG?= =?us-ascii?Q?klYu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zT+92J/98AJCOV?= =?us-ascii?Q?9hoFzwxsnIAuWCyTZqFja3Eup0Ylkey0735YVp3T0nbuqsDKloOtUMfaQFQH?= =?us-ascii?Q?mQZJKsUD8wgOPxX/BzoxqLiVlfA9IP3L3A97HknQ6ZfZZCX7oQ4KJ+PMGYbU?= =?us-ascii?Q?ugj0skvTUerSeCmfSZ9dJHoPMNE5LVcMWXVedHnoYtZPQiQg5V1I6B4gvFga?= =?us-ascii?Q?vKZP3Q/gHzq3q8Fkt1o=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 081d4146-ff11-4ff2-6b88-08dd577a1e09 X-MS-Exchange-CrossTenant-AuthSource: MW6PR12MB8663.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2025 22:00:16.2081 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: O2y2gJxn/77NAMkS3AS+mHY/Ku+HKsN/lamOuVvkz7Q0rHDYVUblnX34nlDomuw1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6638 On Thu, Feb 27, 2025 at 01:25:10PM -0800, Boqun Feng wrote: > > The design pattern says that 'share it with the rest of the world' is > > a bug. A driver following the pattern cannot do that, it must contain > > the driver objects within the driver scope and free them. In C we > > I cannot speak for Danilo, but IIUC, the 'share it with the rest of the > world' things are the ones that drivers can share, for example, I > suppose (not a network expert) a NIC driver can share the packet object > with the upper layer of netowrk. I'm having a bit of trouble parsing this sentence.. In your example a NIC driver passing a packet into the network stack would still be within the world of the driver. Outside the world would be assigning the packet to a global variable. It is a very similar idea to what you explained about the module lifetime, just instead of module __exit being the terminal point, it is driver remove(). > > It appears to me that the main issue here is that nobody has figured > > out how to make rust have rules that can enforce that design pattern. > > Most of the cases, it should be naturally achieved, because you already > bind the objects into your module or driver, otherwise they would be > already cancelled and freed. I'm getting the feeling you can probably naturally achieve the required destructors, but I think Danillo is concerned that since it isn't *mandatory* it isn't safe/sound. > So I think in Rust you can have the "design pattern", the difference is > instead of putting cancel/free functions carefully in some remove() > function, you will need to (still!) carefully arrange the fields in your > driver/module data structure, and you can have more fine grained control > by writting the drop() function for the driver/module data structure. That all makes sense, but again, the challenge seems to be making that mandatory so it is all safe. If you can show people a sketch how you think that could work it would probably help. > I feel I'm still missing some contexts why Devres is related to the > "design pattern", so I will just skip this part for now... Hope we are > on the same page of the "design pattern" in Rust? There is a requirement that a certain C destructor function be *guaranteed* to be called during remove(). Ie if I told you that the C functions *required* hrtimer_cancel() be called in the device_driver remove for correctness, how could you accomplish this? And avoid an UAF of the hrtimer from other threads? And do it without adding new locks. And prevent the driver author from escaping these requirements. Then you have the design pattern I'm talking about. Is it clearer? Jason