From mboxrd@z Thu Jan 1 00:00:00 1970 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 80FD9D77882 for ; Fri, 23 Jan 2026 17:00:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E3A5710EB6B; Fri, 23 Jan 2026 17:00:48 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="a9KXvr3w"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id A1B3410EB6B for ; Fri, 23 Jan 2026 17:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769187646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oYRZQtOI+KB8tYFyNN3GRXz5SFLWYG0fejboN/bZV20=; b=a9KXvr3wE2NshJFHab11VoEFst7r7IXLuEcCt9Bp+2fRePP1tdL2gWRBkv5gPBJ8i64vJJ E+F0aUqjIN/lalgjYeVSvE/UTRtSkKVXOZK1bWck1yF1exCxLVUJ4MD5KCGg7WKx55LsZJ Q0iKngE8GSiz04Z/Qe8R7grzmfH4tas= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-269-fSYT52XVP76idCB4iZ4pBg-1; Fri, 23 Jan 2026 12:00:45 -0500 X-MC-Unique: fSYT52XVP76idCB4iZ4pBg-1 X-Mimecast-MFC-AGG-ID: fSYT52XVP76idCB4iZ4pBg_1769187645 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8c538971a16so661850285a.1 for ; Fri, 23 Jan 2026 09:00:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769187645; x=1769792445; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oYRZQtOI+KB8tYFyNN3GRXz5SFLWYG0fejboN/bZV20=; b=tUDRSnWsEVcbWxQGbRm10NqB3EOC0q5EkwlQd3Rqt0uKaP3VU6upBiddMLkyQTtkg+ dg9+bUbDHFPq30U2+cl2/p0HjNwJcts25JnEEeVQUt0x67qSaQn4CWLy2oMJWLQB8/Zv pp98W+I76ZNTCw4TI51+MpSjjvPlH/lE8M5tSRCmCWuNWg2tvgXByueD2DOwMwBM4GDP 17qjhYzM8bcbl4YSx1DE1p5PCi51v5D8ZuXX/lQp9kiJSKVVpqAqa09+yd5oRmeNwgOe tZkREoZktrLYe/1hBKXphbuXfpb79XEutsxu4SR+4S3rFOo4lKv3C/KzMshkLaYC/gn3 bnTw== X-Forwarded-Encrypted: i=1; AJvYcCUvoHphHODgHsLxIIsIW7hEibCcbtccLy/NLQa0E/Y+kCtDR2o3KFsJmX+sucu75YR0V5TCl8Op54w=@lists.freedesktop.org X-Gm-Message-State: AOJu0YynqN2P4vpJFZpjUxc0LK78MKTwDoa8c5xarr2dY/SO4ZmY7znt KqdQEgRlXbDjpWNsUwwPUnO0BU6ChoN11G0dedYSJmv2cPVyjRTi53W1bvn6C1Dmu3kwJqE/Gpe K6eBFk7CY6tvTEbDPeVV4Ek0zr/PnrVF/Tl6Zipg3D6sePOaiYSIlAzQedRuIVqOLkKXc7Q== X-Gm-Gg: AZuq6aKFWQ/Bv26uJtKFdmXn+S2N4DCsf7HGuEnsGIUasuw4o3JqkEUfFA2dFdBymro wS5XQMhypjLf2y/5RDTtlpbdxDH34sz8YUo85Zur1AkVmLoeRh1c1Ln9WV0l1iQLEVuV4Pwp0vw d3GiNjFVtuHB8TQXQ+5MieL+ztolHlUDn2Bz8C4pS5njd4UVa2HV0Az5UPUCzEY5s+xLnt7sU3P 3ZrtuSlyeEXeg4ruBNbuSmEZegY63CBPKeF0HIGMMcJvUEHRcs5qCj7IyyFSZd9ub7Iw08W174l TIfHGl+SFDWtw2mTZiuLFLzY58y53rJ4SeHhe/awIyHd0e056RPWlxkQQkqBv7vkQMwn2bVFG5I lKieArQ== X-Received: by 2002:a05:620a:40cd:b0:8c5:38b3:fefa with SMTP id af79cd13be357-8c6e2e4c7cbmr393961285a.79.1769187637961; Fri, 23 Jan 2026 09:00:37 -0800 (PST) X-Received: by 2002:a05:620a:40cd:b0:8c5:38b3:fefa with SMTP id af79cd13be357-8c6e2e4c7cbmr393887885a.79.1769187633428; Fri, 23 Jan 2026 09:00:33 -0800 (PST) Received: from [192.168.8.4] ([100.0.180.93]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8949193add8sm22302406d6.45.2026.01.23.09.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jan 2026 09:00:31 -0800 (PST) Message-ID: <47cbb2bb4462331e5ffa56da488d8ffab9a5fcd7.camel@redhat.com> Subject: Re: [PATCH v3 2/3] rust/drm: Don't setup private driver data until registration From: lyude@redhat.com To: Daniel Almeida Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, Danilo Krummrich , nouveau@lists.freedesktop.org, Miguel Ojeda , Simona Vetter , Alice Ryhl , Shankari Anand , David Airlie , Benno Lossin , Asahi Lina Date: Fri, 23 Jan 2026 12:00:28 -0500 In-Reply-To: References: <20260122225057.3589500-1-lyude@redhat.com> <20260122225057.3589500-3-lyude@redhat.com> User-Agent: Evolution 3.58.2 (3.58.2-1.fc43) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: pBdcIz7nOOyXSiN3FNJboxVOvRPh0RNG1_lqw7L6NRc_1769187645 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Thu, 2026-01-22 at 22:52 -0300, Daniel Almeida wrote: > > @@ -254,7 +240,15 @@ pub fn new(dev: &device::Device, data: impl > > PinInit) -> Result > #[repr(C)] > > pub struct Device { > > =C2=A0=C2=A0=C2=A0=C2=A0 dev: Opaque, > > -=C2=A0=C2=A0=C2=A0 data: T::Data, > > + > > +=C2=A0=C2=A0=C2=A0 /// Keeps track of whether we've initialized the de= vice data > > yet. > > +=C2=A0=C2=A0=C2=A0 pub(crate) data_is_init: AtomicBool, >=20 > Why don=E2=80=99t we make the data a member of the Registered context? A couple of different reasons. For one: not having it embedded as part of Device would complicate trying to go from the device's private data using container_of! to the actual Device struct, which isn't great for workqueues. The other much more important reason is that Registered isn't going to be the only typestate that has access to the driver's private data in the future.=C2=A0With KMS, nearly all of the modesetting callbacks for a driver can be invoked before userspace registration. E.g. consider a modesetting driver that needs to perform a modeset pre-registration so that the hardware is in a known good state before being exposed to userspace. To clarify what this looks like: you'll recall that I made a diagram showing a high-level overview of the DRM initialization process for the documentation for DeviceContext. The second stage in that diagram, which I'm currently calling Init, is the context that we're going to need to eventually add a typestate for. FWIW, this is more or less what the flow will look like with this new context. Indenting indicates calling down to a function from within the function above * UnregisteredDevice::new(d: device::Device) -> UnregisteredDevice - // Creates Crtcs, Connectors, etc. KmsDriver::probe(d: &UninitializedKmsDevice) * // The driver sets stuff up * Registration::new_foreign_owned( =C2=A0 dev: UnregisteredDevice, =C2=A0 data: impl PinInit ): - // Initialize `data`, so driver data is ready at this point - KmsDriver::pre_registration_init(d: &Device) - // Perform actual userspace registration If it wasn't clear too: this means tyr won't really need to do anything when we add the new DeviceContext typestate :) >=20 > > + > > +=C2=A0=C2=A0=C2=A0 /// The Driver's private data. > > +=C2=A0=C2=A0=C2=A0 /// > > +=C2=A0=C2=A0=C2=A0 /// This must only be written to from > > [`drm::Registration::new`]. > > +=C2=A0=C2=A0=C2=A0 pub(crate) data: UnsafeCell>, > > + > > =C2=A0=C2=A0=C2=A0=C2=A0 _ctx: PhantomData,