From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (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 E56C41662EF; Thu, 27 Feb 2025 13:06:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740661593; cv=none; b=T5OkArBB5oZ4aGkO1Si4YXwaDhbEORpCiiEfnAN69cyJTih51aM34gqDHFt4cJ/EfiUYb/q4WkTiAu5f3CD56x46lWNT7NwZ7pBCs+1X3LHzrAnbyrSjTFYoBxSTtza2yT0n9hUKhmlU59z+6m6EnHiyYghXhntljhKg+AIgvbA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740661593; c=relaxed/simple; bh=gehwLQH/F0EbzXWjJA5bmN6veVCSiRGzWa9NpQ7Foho=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KvgQRwb8rigf00VgmVBVsTPjlHpnTWKp+cGWpEF7Kj6vcmPXNbNUF/PMLQTZRds/Vr3I4iKUshcLJ992VYfBiSFXeVAHrYPNTighe4FOkF/IDKZSLqeA8i7nbW8hTv7ZVKH8cHhkLbQXjOiV1y8jjutr+cn7v2pX4GlvRVTIaMU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=YQZn4FaJ; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="YQZn4FaJ" Received: by mail.gandi.net (Postfix) with ESMTPSA id 05B2F433D6; Thu, 27 Feb 2025 13:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1740661587; 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:autocrypt:autocrypt; bh=0jurlLBNXfGd9DqDpI41umHtPOLvrCM/YL4keN35dP4=; b=YQZn4FaJmdglmiMSVbEuKnBrJAFELHRX1nhF48UX+WMCEibHQEd3UdSSticOgQ91WWHjeJ DQ8CpwXxJCTA/0r1BV14ekk2Nk2J1+rT8ztwsjUJK0MEyPcs/7z/a4ksZnzaAUiX2iCRbh oABVymmTy4kWJD/rF+VLV59ijZd1W7skFplXpH1bObyWKY/kYM1Jqt3ZLh3mX8MPGCtF+H WLrjwvPbk1aUA8rSumHJVYuAaZA2+kCzAH+3LDVR7P13iY5+B6tJ1JzkHwHXncspiJIuPw e3F2k1Becmy8iGr7WKAzsgsO8ZOCd18q+M2uOmbNDDHe5g5c+JwJqdAnFDMw4w== Message-ID: <7d196a91-220a-41a5-8577-198b436d8440@bootlin.com> Date: Thu, 27 Feb 2025 14:06:21 +0100 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 0/9] Driver core: Add faux bus devices To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Lyude Paul , "Rafael J. Wysocki" , Danilo Krummrich Cc: Alexander Lobakin , Andy Shevchenko , Bjorn Helgaas , Jonathan Cameron , Liam Girdwood , Lukas Wunner , Mark Brown , =?UTF-8?Q?Ma=C3=ADra_Canal?= , Robin Murphy , Simona Vetter , Zijun Hu , linux-usb@vger.kernel.org, rust-for-linux@vger.kernel.org, =?UTF-8?B?Sm9zw6kgRXhww7NzaXRv?= References: <2025021023-sandstorm-precise-9f5d@gregkh> Content-Language: en-US From: Louis Chauvet Autocrypt: addr=louis.chauvet@bootlin.com; keydata= xsFNBGCG5KEBEAD1yQ5C7eS4rxD0Wj7JRYZ07UhWTbBpbSjHjYJQWx/qupQdzzxe6sdrxYSY 5K81kIWbtQX91pD/wH5UapRF4kwMXTAqof8+m3XfYcEDVG31Kf8QkJTG/gLBi1UfJgGBahbY hjP40kuUR/mr7M7bKoBP9Uh0uaEM+DuKl6bSXMSrJ6fOtEPOtnfBY0xVPmqIKfLFEkjh800v jD1fdwWKtAIXf+cQtC9QWvcdzAmQIwmyFBmbg+ccqao1OIXTgu+qMAHfgKDjYctESvo+Szmb DFBZudPbyTAlf2mVKpoHKMGy3ndPZ19RboKUP0wjrF+Snif6zRFisHK7D/mqpgUftoV4HjEH bQO9bTJZXIoPJMSb+Lyds0m83/LYfjcWP8w889bNyD4Lzzzu+hWIu/OObJeGEQqY01etOLMh deuSuCG9tFr0DY6l37d4VK4dqq4Snmm87IRCb3AHAEMJ5SsO8WmRYF8ReLIk0tJJPrALv8DD lnLnwadBJ9H8djZMj24+GC6MJjN8dDNWctpBXgGZKuCM7Ggaex+RLHP/+14Vl+lSLdFiUb3U ljBXuc9v5/9+D8fWlH03q+NCa1dVgUtsP2lpolOV3EE85q1HdMyt5K91oB0hLNFdTFYwn1bW WJ2FaRhiC1yV4kn/z8g7fAp57VyIb6lQfS1Wwuj5/53XYjdipQARAQABzSlMb3VpcyBDaGF1 dmV0IDxsb3Vpcy5jaGF1dmV0QGJvb3RsaW4uY29tPsLBlAQTAQgAPgIbAwULCQgHAgYVCgkI CwIEFgIDAQIeAQIXgBYhBItxBK6aJy1mk/Un8uwYg/VeC0ClBQJmlnw+BQkH8MsdAAoJEOwY g/VeC0ClyhwP/Ra6H+5F2NEW6/IMVHeXmhuly8CcZ3k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bMGMERMmb96Cua9z1ROviGA1He2gbHOcp6qmLNu3nprleG8PL ZRNdEAC0iZapoyiXlVCKLFIwUPnxUz5iarqIfQU8sa1VXYYd/AAAFI6Wv3zfNtGicjgHP8rN CIegqm2Av1939XXGZJVI9f3hEoUn04rvxCgcDcUvn7I0WTZ4JB9G5qAGvQLXeXK6Byu77qTx eC7PUIIEKN3X47e8xTSj2reVTlanDr8yeqZhxpKHaS0laF8RbD85geZtAK67qEByX2KC9DUo eHBFuXpYMzGQnf2SG105ePI2f4h5iAfbTW9VWH989fx4f2hVlDwTe08/NhPdwq/Houov9f/+ uPpYEMlHCNwE8GRV7aEjd/dvu87PQPm4zFtC3jgQaUKCbYYlHmYYRlrLQenX3QSorrQNPbfz uQkNLDVcjgD2fxBpemT7EhHYBz+ugsfbtdsH+4jVCo5WLb/HxE6o5zvSIkXknWh1DhFj/qe9 Zb9PGmfp8T8Ty+c/hjE5x6SrkRCX8qPXIvfSWLlb8M0lpcpFK+tB+kZlu5I3ycQDNLTk3qmf PdjUMWb5Ld21PSyCrtGc/hTKwxMoHsOZPy6UB8YJ5omZdsavcjKMrDpybguOfxUmGYs2H3MJ ghIUQMMOe0267uQcmMNDPRueGWTLXcuyz0Tpe62Whekc3gNMl0JrNz6Gty8OBb/ETijfSHPE qGHYuyAZJo9A/IazHuJ+4n+gm4kQl1WLfxoRMzYHCA== In-Reply-To: <2025021023-sandstorm-precise-9f5d@gregkh> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdekjeehgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpefnohhuihhsucevhhgruhhvvghtuceolhhouhhishdrtghhrghuvhgvthessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepudfggeegueffjeffteetteehjefhiedtkedvffettddthedthefhvddvlefgleevnecuffhomhgrihhnpehfrhgvvgguvghskhhtohhprdhorhhgpdhkvghrnhgvlhdrohhrghdpsghoohhtlhhinhdrtghomhenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrddtrddvtdgnpdhmrghilhhfrhhomheplhhouhhishdrtghhrghuvhgvthessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepudelpdhrtghpthhtohepghhrvghgkhhhsehlihhnuhigfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhihuhguvgesrhgvughhrghtrdgtohhmpdhrtghpt hhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghkrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprghlvghkshgrnhguvghrrdhlohgsrghkihhnsehinhhtvghlrdgtohhmpdhrtghpthhtoheprghnughrihihrdhshhgvvhgthhgvnhhkoheslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopegshhgvlhhgrggrshesghhoohhglhgvrdgtohhm X-GND-Sasl: louis.chauvet@bootlin.com Le 10/02/2025 à 13:30, Greg Kroah-Hartman a écrit : > For years/decades now, I've been complaining when I see people use > platform devices for things that are obviously NOT platform devices. > To finally fix this up, here is a "faux bus" that should be used instead > of a platform device for these tiny and "fake" devices that people > create all over the place. > > The api is even simpler than the normal platform device api, just two > functions, one to create a device and one to remove it. When a device > is created, if a probe/release callback is offered, they will be called > at the proper time in the device's lifecycle. When finished with the > device, just destroy it and all should be good. > > This simple api should also hopefully provide for a simple rust binding > to it given the simple rules and lifecycle of the pointer passed back > from the creation function (i.e. it is alive and valid for as long as > you have not called destroy on it.) > > I've also converted four different examples of platform device abuse, the > dummy regulator driver, the USB phy code, the x86 microcode dvice, and > the "regulator" device that wifi uses to load the firmware tables, to > use this api. In all cases, the logic either was identical, or became > simpler, than before, a good sign (side note, a bug was fixed in the usb > phy code that no one ever noticed before). > > Note, unless there are major objections, I'm leaning toward getting > patch 1 and 2 of this series merged during this -rc cycle so that all of > the individual driver subsystem cleanups can go through those subsystems > as needed, as well as allowing the rust developers to create a binding > and get that merged easier. Having patch 1 merged on its own isn't > going to cause any changes if no one uses it, so that should be fine. Hi all, I have a maybe dumb question regarding the patches 3..9: do they break the UAPI? With a platform device, the drivers appear under /sys/bus/platform, but with faux device, they appear under /sys/bus/faux. I ask because I found out that one (see my reply to [2]) of the main drm library expects to find all the devices under pci, usb, platform, virtio and host1x buses [1], so at least for the vgem and vkms driver, this library will be broken (it will not crash, but previously detected devices will suddenly disappear). I don't know what are the rules for /sys/bus, but changing a device from one bus to another seems to break userspace programs. How should we handle this situation? Should we fix the existing drivers? Or only new drivers should use it? +CC: José Expósito Thanks, Louis Chauvet [1]:https://gitlab.freedesktop.org/mesa/drm/-/blob/main/xf86drm.c#L4460-4515 [2]:https://lore.kernel.org/all/20250218165011.9123-21-jose.exposito89@gmail.com/ > Changes from v4: > - really dropped the internal name structure, remanants were left over > from the last patch series > - added the rust binding patch from Lyude (is this one of the first > patch series that adds a new kernel api AND the rust binding at the > same time?) > - added a parent pointer to the api so the devices can be in the tree > if the caller wants them > - made probe synchronous to prevent race when using the api (when the > create call returns the device is fully ready to go.) Thanks to > testing of the drm driver change to find this issue. > - documentation tweaks > - #include finally added to faux.h > > > Changes from v3: > - Dropped the USB phy porting, turned out to be incorrect, it really > did need a platform device > - converted more drivers to the faux_device api (tlclk, lis3lv02d, > vgem, and vkms) > - collected some reviewed-by > - lots of minor tweaks of the faux.c api, and documentation based on > review, see the changelog in patch 1 for details. > > Changes from v2: > - lots of cleanups to faux.c based on reviews, see patch 1 for details > - actually tested the destroy device path, it worked first try! > - added 3 more example drivers > > > > Greg Kroah-Hartman (8): > driver core: add a faux bus for use when a simple device/bus is needed > regulator: dummy: convert to use the faux device interface > x86/microcode: move away from using a fake platform device > wifi: cfg80211: move away from using a fake platform device > tlclk: convert to use faux_device > misc: lis3lv02d: convert to use faux_device > drm/vgem/vgem_drv convert to use faux_device > drm/vkms: convert to use faux_device > > Lyude Paul (1): > rust/kernel: Add faux device bindings > > Documentation/driver-api/infrastructure.rst | 6 + > MAINTAINERS | 2 + > arch/x86/kernel/cpu/microcode/core.c | 14 +- > drivers/base/Makefile | 2 +- > drivers/base/base.h | 1 + > drivers/base/faux.c | 232 ++++++++++++++++++++ > drivers/base/init.c | 1 + > drivers/char/tlclk.c | 32 +-- > drivers/gpu/drm/vgem/vgem_drv.c | 30 +-- > drivers/gpu/drm/vkms/vkms_drv.c | 28 +-- > drivers/gpu/drm/vkms/vkms_drv.h | 4 +- > drivers/misc/lis3lv02d/lis3lv02d.c | 26 +-- > drivers/misc/lis3lv02d/lis3lv02d.h | 4 +- > drivers/regulator/dummy.c | 37 +--- > include/linux/device/faux.h | 69 ++++++ > net/wireless/reg.c | 28 +-- > rust/bindings/bindings_helper.h | 1 + > rust/kernel/faux.rs | 67 ++++++ > rust/kernel/lib.rs | 1 + > samples/rust/Kconfig | 10 + > samples/rust/Makefile | 1 + > samples/rust/rust_driver_faux.rs | 29 +++ > 22 files changed, 502 insertions(+), 123 deletions(-) > create mode 100644 drivers/base/faux.c > create mode 100644 include/linux/device/faux.h > create mode 100644 rust/kernel/faux.rs > create mode 100644 samples/rust/rust_driver_faux.rs > -- Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com