Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 66615F01825 for ; Fri, 6 Mar 2026 11:03:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6EBD210ECDA; Fri, 6 Mar 2026 11:03:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="jqR0YdSW"; dkim-atps=neutral Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010059.outbound.protection.outlook.com [52.101.61.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id BD38310ECDA for ; Fri, 6 Mar 2026 11:03:26 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b+Pg9wyQ/M8CcG5Pc2djSTuhGiBRPllWMTOda4MiF6EgSBaR832vxvIkHkb3KT9s4TwoXIMLcKphSw37nObAOMMEyVmDC/VQ6J7Xsh1sFXpjgOYbY8U0hZo293OfAv5BMWTASRZTGywYWwOPANZVxdmBzRiH8dVuvAGzMtoiuydQ3kVxH5usQAohQhuyJOyDHn4boGpbStJBVmCZH7zeFipBSGZ0DhLtYJ6kBtdpX2GkTWC8sAh/cofA1Sn3LHnz0qUKK6lEgXZLfeXrjDQMTYVD24CLyDr4VF7MW6VDFz9bPWPqku/FcZrJONm433DCnTR/rCuukFFMhIpD5IF6Tw== 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=n4QgQIx/Qru/4/X/Wvoduyud1wQ13adkPFofmyD/Q20=; b=HH1NnGUKmkVx6l/VYoONDWJeuVTjLp8bQzVkoO+0TQFvnEC0Vbx163WIwl8dDOusSUJvXeELmrU+60qQAYgCtuWJKmlWdGVZzJLbQnp+VvsJCG6m1jqI1MTZXb74Uv8YxvrMDydh+DfZDATpktAFsi9aKjFXXA7dbWcpR2/9/tShp4k/ZZ+rNHPLPsvd6HfJQCthnbrNYu2NKBS89L5HeiyXEPTWwV/ldcjjq4tjh6bJxex4kFQ/OJEat41kdsxgv/QiwBzbEQdaMumYqSLNNpgK5Oifpy2mp1ff/2gCCbGbM7l+49n5/hSxpvu4Hb15P9RhyGmh4k2SVbN8cbcM4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n4QgQIx/Qru/4/X/Wvoduyud1wQ13adkPFofmyD/Q20=; b=jqR0YdSWi0tpT6PoLQpJhAwgF9UReNng1ZFAcvFFHCW+cNcn1S+0EUpMppOE8/qj6UFmMwdg1WCHBa4hiizU0eiNPn9Aqgwp9qWkOplyiSqNGl8QqJFp+zz+5Tvmz0TV9VzvD0hGLXtvHBZOq4boiSLwGJxCqJV3+8Gv/ksbsR4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) by SJ2PR12MB8009.namprd12.prod.outlook.com (2603:10b6:a03:4c7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9678.18; Fri, 6 Mar 2026 11:03:23 +0000 Received: from PH7PR12MB5685.namprd12.prod.outlook.com ([fe80::ce69:cfae:774d:a65c]) by PH7PR12MB5685.namprd12.prod.outlook.com ([fe80::ce69:cfae:774d:a65c%5]) with mapi id 15.20.9700.003; Fri, 6 Mar 2026 11:03:23 +0000 Message-ID: Date: Fri, 6 Mar 2026 12:03:19 +0100 User-Agent: Mozilla Thunderbird Subject: Re: dma_fence: force users to take the lock manually To: Boris Brezillon Cc: phasta@kernel.org, dakr@kernel.org, Tvrtko Ursulin , dri-devel References: <080395923c92ef758ca6062f1e01392186413015.camel@mailbox.org> <718ad034-8fc2-4b43-9b04-729c5befc3ca@amd.com> <20260305161212.7dfbadbd@fedora> <20260306104646.36319162@fedora> <9718fa34-95f7-4461-9d01-2ad4eed60b14@amd.com> <20260306113723.1f13010c@fedora> Content-Language: en-US From: =?UTF-8?Q?Christian_K=C3=B6nig?= In-Reply-To: <20260306113723.1f13010c@fedora> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR4P281CA0268.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:e8::13) To PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR12MB5685:EE_|SJ2PR12MB8009:EE_ X-MS-Office365-Filtering-Correlation-Id: add1064b-e276-4f48-e8f9-08de7b6ffbf2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: O60kZnyoVC/kECe8U7y02vkUwG0N3tuF5Gq4G+nG/omFp7TY7dGWPAXOPIfFwbvuwOxlppigI2EQuvKRVAEdmE7GTuwBehBrfgaLOV2ANCfgKLVpmMb4QrO1NEhDwG7u/clMPekUIXa0eMlpiP1vHxyzlAROsJLkxCUEHLjZe6gYwvJ/oPj7ADkATf3EIpEUzD0aSa6F+tgMMDFSsnyDwy9nqPHS5jKGdHitfmuv983LJ3jgyIR350Ub1HiUFdzya4B7au/pAmDW1PpxIfL1YPf7eAEz6IkLUts+7acll5P9/pfoLQFq+90yI68/xgfYhOH/DTlh552GXEUb6fLOqruw/waMI1KkY6b6LXHay0BTcDomniBBaVTrmT0MlcN0BQEPl4S37wGVceNE1FwzpUeXQgBrebhS7ysJQkA0hePdTVuVtxHTsgjn1zERhtsIW/ITdRb8DLLPD8FBq7LE8TiaYgpBN3L4aF9rBppUc2CQM7YWZCtHr2Q7OYfkSCuN6+ITF9kRaLj5q2UtOP3Lmpg5d+piwzFLCKFuWPF3kfI8BDxnxyj6grqsNuseTtID5SdNSqg4xJb5AfHT1AAxuWtzjtP4wWBe+NMzu229/vtcC/Oom5krg+CBF6QlCJ/ZSCL7yEQzk0cqPSl7TP72O6dD0sLGu1DAhVTTlRWgWOSsoNvHq+YNawVSyIHiKcTm6gfi/WOoxPVhvQPGwhf9+8Yfq+VUA4c4eYGR0UHsQOY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH7PR12MB5685.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eEw4ZWI0ZWF1ODVjV05UM1dHWVZQdFdXZ21tdVRtUU5EMjZ6SEpvK1FYYlh0?= =?utf-8?B?Mk9xUWtuVmppeFZRWVh2YXJLTnloREdOL1lneUhzanBHcXhhVkpiVUNjOU51?= =?utf-8?B?S0FkTnBlTXJadUVBYlp2NEtzU0VSL1JYQVQ1NG9ocXZhVlF3QVdCb0pJdGFH?= =?utf-8?B?YlpDcG4wSmNMbVpBdDYwOU1YSEZRMi9NUC8xMkZyUys0WmhQeDkreEg2NlR2?= =?ut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xVGh1WlJLUzRHUlJxaUFmcW5L?= =?utf-8?B?dlJTaUppS2ZqL05uSXhtWEYzWUk3dlRLWDErRGNJeTloOWs3cGNEazN5RjV6?= =?utf-8?B?TkpRTWpOWWczWm9mckJXLzFjRXl1TlA3TlYxcVVzWXJHYjRJTUdxUkRRWFpT?= =?utf-8?B?MzIzSHdJcWl0bWNzQkpUczVFV0hzdEllVjY4ZkprQi83aCtOQVFNR1RkU3p6?= =?utf-8?B?N3RrcnhmTHBWeDVrZmZiYmdhRmhsSC9TK1JYdXdPSkorSTN4cm5rUlRIKzAv?= =?utf-8?Q?6MT1dJKHrEZEy0s4r/?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: add1064b-e276-4f48-e8f9-08de7b6ffbf2 X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB5685.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2026 11:03:23.3097 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Uk9LbVR5pgFDq9jI3YHevbohWxk46+qiiiGr0O4sOLcaXWuzuCp7UsWmXifai5PT X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8009 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On 3/6/26 11:37, Boris Brezillon wrote: > On Fri, 6 Mar 2026 10:58:07 +0100 > Christian König wrote: > >> On 3/6/26 10:46, Boris Brezillon wrote: >>> On Fri, 6 Mar 2026 09:10:52 +0100 >>> Christian König wrote: >>>> Well as I wrote above you either have super reliable locking in your signaling path or you will need that for error handling. >>> >>> Not really. With rust's ownership model, you can make it so only one >>> thread gets to own the DriverFence (the signal-able fence object), and >>> the DriverFence::signal() method consumes this object. This implies >>> that only one path gets to signal the DriverFence, and after that it >>> vanishes, so no one else can signal it anymore. Just to clarify, by >>> vanishes, I mean that the signal-able view disappears, but the >>> observable object (Fence) can stay around, so it can be monitored (and >>> only monitored) by others. With this model, it doesn't matter that >>> _set_error() is set under a dma_fence locked section or not, because >>> the concurrency is addressed at a higher level. >> >> That whole approach won't work. You have at least the IRQ handler which signals completion and the timeout handler which signals completion with an error. > > From a pure rust standpoint, and assuming both path (IRQ handler and > timeout handler) are written in rust, the compiler won't let you signal > concurrently if we design the thing properly, that's what I'm trying to > say. Just to be clear, it doesn't mean you can't have one worker (in a > workqueue context) that can signal a fence and an IRQ handler that can > signal the same fence. It just means that rust won't let you do that > unless you have proper locking in place, and rust will also guarantee > you won't be able to signal a fence that has already been signaled, > because as soon as it's signaled, the signal-able fence should be > consumed. Ah got it! I've worked a lot with OCaml in the past which has some similarities, but doesn't push things that far. >> >> We have documented that this handling is mandatory for DMA-fences since so many driver implementations got it wrong. > > Again, I'm just talking about the rust implementation we're aiming for. > If you start mixing C and rust in the same driver, you're back to the > original problem you described. The key point is the Rust implementation should not repeat the mistakes we made in the C implementation. For example blocking that multiple threads can't signal a DMA-fence is completely irrelevant. What we need to guarantee is correct timeout handling and that DMA-fence can only signal from something delivered from a HW event, e.g. a HW interrupt or interrupt worker or similar. A DMA-fence should *never* signal because of an IOCTL or because some object runs out of scope. E.g. when you cleanup a HW ring buffer, FW queue, etc... Regards, Christian. > >> >> That's why Philips patch set removed the return value from dma_fence_signal(). > > I don't mind that. Just saying that's hopefully a non-issue in the rust > abstraction.