rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Lyude Paul" <lyude@redhat.com>
Cc: "Daniel Almeida" <daniel.almeida@collabora.com>,
	nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	rust-for-linux@vger.kernel.org,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Asahi Lina" <lina+kernel@asahilina.net>,
	"Alyssa Rosenzweig" <alyssa@rosenzweig.io>,
	"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Partially revert "rust: drm: gem: Implement AlwaysRefCounted for all gem objects automatically"
Date: Mon, 28 Jul 2025 18:59:21 +0200	[thread overview]
Message-ID: <DBNUJUSYG465.7YE1YER8B9K@kernel.org> (raw)
In-Reply-To: <2d4f0bb1f23f89e4e5bedf6346a6c21f8b6bb29b.camel@redhat.com>

On Fri Jul 25, 2025 at 9:41 PM CEST, Lyude Paul wrote:
> a-ha, ok. I made a mistake here with misremembering where the compilation
> issue I saw here really was.
>
> It's not that multiple gem object implementations are triggering it, it's that
> it immediately breaks compilation if any other type tries to do a blanket
> implementation with AlwaysRefCounted like this.
>
> Here's a properly compiling example with rvkms:
>
> https://gitlab.freedesktop.org/lyudess/linux/-/commits/rvkms-slim
>
> This builds fine because IntoGEMObject is the only one with a blanket
> implementation of AlwaysRefCounted, and we implement AlwaysRefCounted using a
> macro for refcounted Kms objects.
>
> But if we apply this patch which adds the second blanket impl:
>
> https://gitlab.freedesktop.org/lyudess/linux/-/commit/ec094d4fc209a7122b00168e7293f365fe7fc16c
>
> Then compilation fails:
>
>    ➜  nouveau-gsp git:(rvkms-slim) ✗ nice make -j20
>      DESCEND objtool
>      DESCEND bpf/resolve_btfids
>      CALL    scripts/checksyscalls.sh
>      INSTALL libsubcmd_headers
>      INSTALL libsubcmd_headers
>      RUSTC L rust/kernel.o
>    warning: unused import: `pin_init`
>      --> rust/kernel/drm/driver.rs:18:5
>       |
>    18 | use pin_init;
>       |     ^^^^^^^^
>       |
>       = note: `#[warn(unused_imports)]` on by default
>    
>    warning: unused import: `prelude::*`
>     --> rust/kernel/drm/kms/modes.rs:4:13
>      |
>    4 | use crate::{prelude::*, types::Opaque};
>      |             ^^^^^^^^^^
>    
>    error[E0119]: conflicting implementations of trait `types::AlwaysRefCounted`
>       --> rust/kernel/drm/kms.rs:504:1
>        |
>    504 | unsafe impl<T: RcModeObject> AlwaysRefCounted for T {
>        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
>        |
>       ::: rust/kernel/drm/gem/mod.rs:97:1
>        |
>    97  | unsafe impl<T: IntoGEMObject> AlwaysRefCounted for T {
>        | ---------------------------------------------------- first implementation here
>    
>    warning: unused import: `Sealed`
>     --> rust/kernel/drm/kms/vblank.rs:7:44
>      |
>    7 | use super::{crtc::*, ModeObject, modes::*, Sealed};
>      |                                            ^^^^^^
>    
>    error: aborting due to 1 previous error; 3 warnings emitted
>    
>    For more information about this error, try `rustc --explain E0119`.
>    make[2]: *** [rust/Makefile:538: rust/kernel.o] Error 1
>    make[1]: *** [/home/lyudess/Projects/linux/worktrees/nouveau-gsp/Makefile:1280: prepare] Error 2
>    make: *** [Makefile:248: __sub-make] Error 2
>
> This is definitely part of the reason I didn't notice this problem until later
> too. My understanding is that this is a result of rust's orphan rule, which
> basically just disallows trait impls where it would be ambiguous which impl
> applies to a specific type. Here, the issue is that there's nothing stopping a
> type from implementing both RcModeObject and IntoGEMObject.

Yeah, this is pretty annoying. I don't think it's related to the orphan rule
though; see also the example in [1].

I think in this case we should just keep the generic
impl<T: IntoGEMObject> AlwaysRefCounted for T and not introduce the blanket one
for T: RcModeObject.

In theory it doesn't matter which one to drop, but I'd rather avoid the revert
and I think there's no reason for both to have the less nice macro solution.

[1] https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=23593da0e5e0ca0d9d2aa654e0c9bde6

      reply	other threads:[~2025-07-28 16:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-24 19:15 [PATCH] Partially revert "rust: drm: gem: Implement AlwaysRefCounted for all gem objects automatically" Lyude Paul
2025-07-24 20:03 ` Danilo Krummrich
2025-07-24 21:06   ` Lyude Paul
2025-07-24 22:27     ` Danilo Krummrich
2025-07-24 23:13       ` Daniel Almeida
2025-07-25 19:41         ` Lyude Paul
2025-07-28 16:59           ` Danilo Krummrich [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DBNUJUSYG465.7YE1YER8B9K@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=alyssa@rosenzweig.io \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=lina+kernel@asahilina.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).