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 C7B7631F986 for ; Thu, 4 Jun 2026 18:49:04 +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=1780598946; cv=none; b=sg3YUHpJdril6NXbg6E9NMb6Te4+0CgjtPXOkxdwYl5kHOVtqCyW0/5K9ff1j+MmkvwvdgruqbXl8c9TUpBl8Zc702adLoIYQldjXXrLhho+i9TAvEgRvKf8g0c+rqRtP6r2zQvE92Xa/AY7X8tsHz8nxDaNYCAKsmYYSnvGePg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780598946; c=relaxed/simple; bh=bSOB8kwgdkJuUcuvvGWTTy+0BwGIhrEyhn+sNY27Rlk=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=eSA59CJJFpIECXPOdbytZG8twGDyRHFvMI7ELA3VfdwPnm3ew2ktm0CWqDmXi7OzyHrMtvgzYalK1YtUq4LIbGpMYh+Wr8K4gk6J4LF39epCNmefbuR5Mtk2+fBmLHArlNSe6keYKj/lMf/QST7P0hCBmBRLxwdc9lu1XM8OlIM= 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=GcvyWR7i; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=nE4/14Nk; 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="GcvyWR7i"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="nE4/14Nk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780598943; 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=bSOB8kwgdkJuUcuvvGWTTy+0BwGIhrEyhn+sNY27Rlk=; b=GcvyWR7iFl75XWuSMj9LajJ257Fa55LDbeN3JMhhw60J43hcdjPz4Y/X7cABbtaG5vz7zO b+w+g/mkTIctKpaW4Cs9slu4F+dSNC8rw46HnAl9KnKa39yN9t4fVPXEfg4/pj+M1osGyw QGsL9GnP90+0kJs2AeDif4uxdVoPfTs= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-364-59cL4EQgO7qjxkV6et2xAA-1; Thu, 04 Jun 2026 14:49:02 -0400 X-MC-Unique: 59cL4EQgO7qjxkV6et2xAA-1 X-Mimecast-MFC-AGG-ID: 59cL4EQgO7qjxkV6et2xAA_1780598942 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-8ceba6ec0ccso5594186d6.1 for ; Thu, 04 Jun 2026 11:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780598942; x=1781203742; 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=bSOB8kwgdkJuUcuvvGWTTy+0BwGIhrEyhn+sNY27Rlk=; b=nE4/14Nk1qg1gnnL1qRaiOQCz58nWewDCXkHzYQNyJopyytnZoaHtTbgSqJE9SgoGt KhIL3iu+Q55prrKqwuV5R+BUUgLCt0PD3s1vxmkyb/Xp05NT18uTL95hbmc/C0U8jDih lONsI78s/AhNPirbA4HOLAHrQ6+VCci1iH/BZnQdIgfiYh9e3ir4/1M81M9BB+QKabD4 ozG+62rg26lI1ISjwaMcs2LxQ1tpML/dhk8B3Jk1CWUB7uqDUA8mRVM+E+eq48XGojvt MgHaxChK8uUT4lMFc7qV2/TdFqWoJmLQnCp7d6+2ndBh0pougKCL7DKC6RmX1kiXxyFg ADdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780598942; x=1781203742; 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=bSOB8kwgdkJuUcuvvGWTTy+0BwGIhrEyhn+sNY27Rlk=; b=Sr/fT2nHzpRVfVpiFBcMdiXhO4RUZsBnW14h7PBIE99zVKZ234zVJ3dB4TcexNPCYU VB64JQJA0Foxu4dapJCAYBhQT9TLRZA+Yte54igtjhynCYxg/vt/iVI39DCtdnd9cyp2 o50LAnY0w4+8cXacuTHNqNFpOyPYarDCIZYp2NoWJahInQY58PDf05P77dBd8mB0NK3q KTRCJM+2cVmlWnEaQex3ImT8Kk5IsQ7aPocEE5YZk/3JCg0PxbWFEcLy7467YNDV8Pst uCe6RHqyq8ZbNQlxk7qhe491++wMOUOsP2Ej+BcUGdiOmMR71W/yO6INQNUtFD6174xj iN3w== X-Forwarded-Encrypted: i=1; AFNElJ8wF1mTUOwp85bkVCU4iWz6YVTokWw2EQCidV5g7ed/ptjg7ZLAshxQRjLxBECDb8zlRVtcN4DsLkQ0Qxs=@vger.kernel.org X-Gm-Message-State: AOJu0Ywdr/7Y80CD9UIwY8OvdmugoaZe5kRq3QExKbfYhA2wQlDqn4Mv v9P5LUOYzAfVGm4qT6efHQull50uMwA5s7rbOdC14vI4FS7Rhf2ra1QfdQf4VfIPfFXGfG4irI1 9Ysgza4R+M+oSA2/QVZJEZAP5bgEvZV9MQBxGhtHFb4XgLL5cGrkk1NIV0F1YeX41Ug== X-Gm-Gg: Acq92OH7QZDfGXLvVvtarEaN5B9qGf1uB9E47ymgv7tE+VAKRioocweQ12dv2wz9u7I TPprON84qTECXyZKyicmzTCsbHGOPcEBMvS/mOjoxYMJHYuLXBKRcHnz4sXHVC0/0WUDRl1oueg mzwhupTgm4W6V5xULSFDizrLppYmnk3wT5gV0D6EASF8Qw8DDHgjI/J3FZU8zFzt4OVWnis4URC iqtqSnVF4ykjFJfxylApVNNd+8ZAb3UEAjTlmVZ36NYBAm2nzYDMuhjx/vOrgpqE+KFYzxrrZfj TMgliJqMibnfIdyC3H0HIpJAget9+5mZAogKEHC8OFY5BCbmPOdmW5jUdFcpMeuTEV61IzfHW5v rVlDhvLcQmIpfuxImL6GvgSwtDkA7 X-Received: by 2002:ad4:4e09:0:b0:8cc:dd12:a545 with SMTP id 6a1803df08f44-8cee5f9e8c3mr5117596d6.8.1780598941797; Thu, 04 Jun 2026 11:49:01 -0700 (PDT) X-Received: by 2002:ad4:4e09:0:b0:8cc:dd12:a545 with SMTP id 6a1803df08f44-8cee5f9e8c3mr5117046d6.8.1780598941090; Thu, 04 Jun 2026 11:49:01 -0700 (PDT) Received: from [192.168.8.4] ([100.0.180.93]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ceccd9fda2sm60367866d6.2.2026.06.04.11.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 11:49:00 -0700 (PDT) Message-ID: Subject: Re: [PATCH v17 4/6] rust: faux: Allow retrieving a bound Device From: lyude@redhat.com To: Danilo Krummrich Cc: dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, nouveau@lists.freedesktop.org, Alexandre Courbot , Gary Guo , Christian =?ISO-8859-1?Q?K=F6nig?= , driver-core@lists.linux.dev, Miguel Ojeda , Maarten Lankhorst , Alice Ryhl , Simona Vetter , linux-kernel@vger.kernel.org, Sumit Semwal , linux-media@vger.kernel.org, "Rafael J . Wysocki" , Thomas Zimmermann , Maxime Ripard , David Airlie , Benno Lossin , linaro-mm-sig@lists.linaro.org, Mukesh Kumar Chaurasiya , Asahi Lina , Daniel Almeida , Greg Kroah-Hartman Date: Thu, 04 Jun 2026 14:48:59 -0400 In-Reply-To: References: <20260603195210.693856-1-lyude@redhat.com> <20260603195210.693856-5-lyude@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.3 (3.58.3-1.fc43) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 I mentioned this already to Danilo via alternate channels, but to clarify - this patch -is- actually needed, as we make use of `AsRef>` in the kunit test for SGTable On Thu, 2026-06-04 at 15:25 +0200, Danilo Krummrich wrote: > On Wed Jun 3, 2026 at 9:42 PM CEST, Lyude Paul wrote: > > When writing up some rust code that used faux devices for unit > > testing, I > > noticed that we never actually added the Bound device context to > > faux::Registration's AsRef implementation. This > > being said: > > the Registration object itself is proof that a driver is bound to > > the > > device - so this should be safe. >=20 > Yes, it should be, but the reasons are non-trivial and should be part > of the > safety comment below. >=20 > =C2=A0 - faux_match() always returns 1, and probe runs synchronously > =C2=A0=C2=A0=C2=A0 (PROBE_FORCE_SYNCHRONOUS) >=20 > =C2=A0 - suppress_bind_attrs =3D true on faux_driver prevents userspace- > triggered > =C2=A0=C2=A0=C2=A0 unbind via sysfs >=20 > =C2=A0 - mem::forget(Registration) is not a problem; if the Registration > is leaked, > =C2=A0=C2=A0=C2=A0 the faux device stays bound forever >=20 > > Signed-off-by: Lyude Paul >=20 > I can pick this through the driver-core tree already, as it seems > this it not > needed by this series. Feel free to resend as individual patch for > thus purpose. >=20 > > --- > > =C2=A0rust/kernel/faux.rs | 7 ++++--- > > =C2=A01 file changed, 4 insertions(+), 3 deletions(-) > >=20 > > diff --git a/rust/kernel/faux.rs b/rust/kernel/faux.rs > > index 43b4974f48cd2..e0856b2964a2c 100644 > > --- a/rust/kernel/faux.rs > > +++ b/rust/kernel/faux.rs > > @@ -25,7 +25,8 @@ > > =C2=A0/// > > =C2=A0/// # Invariants > > =C2=A0/// > > -/// `self.0` always holds a valid pointer to an initialized and > > registered [`struct faux_device`]. > > +/// - `self.0` always holds a valid pointer to an initialized and > > registered [`struct faux_device`]. > > +/// - This object is proof that the object described by this > > `Registration` is bound to a device. > > =C2=A0/// > > =C2=A0/// [`struct faux_device`]: srctree/include/linux/device/faux.h > > =C2=A0pub struct Registration(NonNull); > > @@ -59,8 +60,8 @@ fn as_raw(&self) -> *mut bindings::faux_device { > > =C2=A0=C2=A0=C2=A0=C2=A0 } > > =C2=A0} > > =C2=A0 > > -impl AsRef for Registration { > > -=C2=A0=C2=A0=C2=A0 fn as_ref(&self) -> &device::Device { > > +impl AsRef> for Registration { > > +=C2=A0=C2=A0=C2=A0 fn as_ref(&self) -> &device::Device = { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // SAFETY: The underly= ing `device` in `faux_device` is > > guaranteed by the C API to be > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // a valid initialized= `device`. > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsafe { > > device::Device::from_raw(addr_of_mut!((*self.as_raw()).dev)) } > > --=20 > > 2.54.0