From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 8AA192264C0 for ; Fri, 23 Jan 2026 17:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769187649; cv=none; b=ftRTPYFYnb9f4exidE+hwxOwoPhP7aRZdaFLazuKu2L/9COmX6+++kY0bjVtYUgNB1cRpwp0eb4YR5Qb3Whvg4T1gDmIsSzS7zaVWLtsFhIVz0DrPkjlFGWM6CPjYsMNM/+tYxsy29v2TGiHDaWLLwfy0KVByp/4plpvT5iNVIQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769187649; c=relaxed/simple; bh=DijAIRvrqnHXdfVzYnWWMhE2olDPZM678iAAtRN9RNI=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=sCtsjOmyW+bvIsZO88z41jGoUDQ4PNfSp2+/xPEEqcrBr2yTSWI4JzzLgcbvaxg3CYSSeyEYwrBvAQjmY8czhi113Uk+7Z5iwFWEQ0KenGIPqYFrsdoJBisKkr6AbAy/e5RHRDKztAv78yWeNA1jKJFPy6YBlgnUxtBObWqCEMY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=a9KXvr3w; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=IFu4gpRK; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a9KXvr3w"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="IFu4gpRK" 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-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-14-U9noAzrNPJa6Fg6EBm_nWg-1; Fri, 23 Jan 2026 12:00:39 -0500 X-MC-Unique: U9noAzrNPJa6Fg6EBm_nWg-1 X-Mimecast-MFC-AGG-ID: U9noAzrNPJa6Fg6EBm_nWg_1769187638 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8c6a341ac9fso600946285a.3 for ; Fri, 23 Jan 2026 09:00:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1769187638; x=1769792438; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=oYRZQtOI+KB8tYFyNN3GRXz5SFLWYG0fejboN/bZV20=; b=IFu4gpRKKyka9mGZm6PU63uM+uwTAYrPvNd6DUSdjDtMauZoQrRzUcuhf7gFFhAwcY KTr6EU0zwxMqFwr1KApXuZcQPqg9uCWhGw7Uhi8PEzdez/W7aLr8zCk47Dv1xHOS1FCh EnosjG0H23CTkBLM4tD7JPwJO0GbrBq4k1fnKiEGmkmyUKSCNhIhK67+Wz667MMelTiE XYAcTh+s7Rlaa3d2HTxkmSaGllTD6mxR/CUltYnRk9qVMkAylyxrdeaThfXxf4qpMl02 rPlVnoRDyUncRc5HbuovuYNTHYxspWrlMrHpngA7bnBj23QmH6UFu05B7HAjj5p8q7jf pYPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769187638; x=1769792438; 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=Hj+EobCIbIlBwGFIfpvHYCRSUlArZdT4pk1nrjcxwDf2BOYSo9YNkCj5NOIZk0oUwK d+sobAEpZp0FbR3IGAoiXw+f3hXZU/4XICsR4y5q3cGIC7E9AyGWWVArbks2zliPLmO9 8KVjNeF1BW7CskmrTjhpqjhD8lcj244YkiqS8SJ2qUKFZFEAl6SvAPcviNaK7OiKV2UH bB26YOoE0NU1bAn0RbQ+/4fj95DxGPNkZdDIepiBBL1sLmoR1uGkCej/tLJUptLA2mef DukyQT1cPMr4KUtCQ36uD6YqPv6rCy5fdLwZgA/CPoHvwQgfxtz6rHnSO3Xblvp04SoY ZYIw== X-Gm-Message-State: AOJu0YyDijTGNwIBNKMGFdUjNgvXJT0JKAE/hc4tUMLQS7W+0hI9TL0c ZRyRme3YKklLRL/q5EgpO5AXeBF+BZboBhRJudP+lRVUoLNbw12QeepQkEQOc0eim9WBu9osekS XWe7b1MvLYQXzQjT3YRaHq0sktsUvuVfmBii3DkfHEFjx6IMbW2qEJmrG6xD+ryGcf0Vx40rKiw == X-Gm-Gg: AZuq6aIut0s6lDUJYPqNtpRxsd2KMya2rXtb3buHS1Kz7dYdoUTNcJreEdLeIS1KtYu MxFo/JpKw/M05T2drBpeG7J3cVBkRbHVzF1luYAiW7LvtzWYP9jZcHNYIktMMjuEHrsALn+HEBp kJ2nS+LQ0pmdfYDmknf8E+sfUKCEdai42xqiWherjQms40II53sDJg/gBDIWVTQAH00xx/bU665 s597V7AnCppIy0yllaKGaaLwpmMLRE4yv9An/1ngxE1mYTKTHKJm2vTvdPvxoFXTkb19Cd+Qh2Z ZAShw3ZFTVPRruX/eLHLHs7C8kTkwPpcydsCKL07pMd1s2tuA2wncEaxhqm7YD/SKWpMqB53BeP 9E56y8g== X-Received: by 2002:a05:620a:40cd:b0:8c5:38b3:fefa with SMTP id af79cd13be357-8c6e2e4c7cbmr393924685a.79.1769187635842; Fri, 23 Jan 2026 09:00:35 -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> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.2 (3.58.2-1.fc43) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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,