From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 B4E8B346A0C; Tue, 24 Feb 2026 22:44:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771973100; cv=none; b=kjL78sngoU3zZltHy6YTQO4Odh1fq0oD6dAWyWhyT9/lkM8DHE1zAqkJ+ttMcdKe1KtcXVPgWmfekV4ZId4xh7nJZLrxMAVcHNbV7epLWKWmUmRge48j/8GpOmRM2ZVz/PFQ/BCiDaOwxi+bLEOE4HTLfpLQo0H5lmPczEkp2cM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771973100; c=relaxed/simple; bh=fTxdFyrs1FQ3whu25eWjIsMqrsvQxM/455bEq9ul9Ww=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mcFFaRWXN8pr3fmTTmm68ZQnuJivfJLWuG0VU7FgrKHyaPsEySLB97JOAJlT0ffl0/gKbCwlcuIaVKj2FjGuTxKU02yEdzp+fmzKO32nQ5p09rVFZ6RaQ1BMFhOpRd5Ue4uuP/dXZZd4/IoholMNf5lHXTAVgyBbI28rmnKn5t8= 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=14BWjMDC; arc=none smtp.client-ip=185.246.85.4 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="14BWjMDC" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 08E884E410C2; Tue, 24 Feb 2026 22:44:55 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id B441E5FDE5; Tue, 24 Feb 2026 22:44:54 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id F22111036907A; Tue, 24 Feb 2026 23:44:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1771973093; h=from:subject:date:message-id:to:cc:mime-version:content-type: in-reply-to:references; bh=LN908gwoG2M5Xm0QMpbWHhbAFrLqaTiRskdJj1nsIFI=; b=14BWjMDC52p3hGZnhCXD5mJQSdvgBLJE9A6yn3LlhMMmMjbs8WupH2hZc+NGeBU+WpsyWe g7s87y9gzmwIgE3Qtd7WGMNnU7Tlj60nxqi5RBoGPdjHnIMCIoK2q63CdBcIgOjVhbQIuC 0xEYd/afPYRDk/ahIvA7pf9w72qO3Hokcg7fIEZRDc0xwT0/JSD5wpIL9T2rgxkcNAtr3c DtMCPK3CO4072rrvF4hS+V/NRMByZoljfw6DJPKXqFJKn7c3yWGFEB4y/lDN8eOwkKtM3e zVXacI68WzvI7yg1yPzyXzsgHbLq1sMRX3SsnyEcUGdGzs2Ko8legpVXWlaNYg== Date: Tue, 24 Feb 2026 23:44:49 +0100 From: Alexandre Belloni To: Danilo Krummrich Cc: "Rafael J. Wysocki" , Alvin Sun , Miguel Ojeda , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , linux-rtc@vger.kernel.org, rust-for-linux@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [RFC PATCH v3 1/5] rtc: add device selector for rtc_class_ops callbacks Message-ID: <20260224224449f141e366@mail.local> References: <20260222000556ea1938c0@mail.local> <2026022415010804e28202@mail.local> <20260224172822de7f4569@mail.local> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Last-TLS-Session-Version: TLSv1.3 On 24/02/2026 23:23:29+0100, Danilo Krummrich wrote: > On Tue Feb 24, 2026 at 6:28 PM CET, Alexandre Belloni wrote: > > On 24/02/2026 17:35:23+0100, Danilo Krummrich wrote: > >> (I did not have any specific hardware in mind when sketching this up (e.g. an > >> IRQ could also only be needed in bus device callbacks, e.g. for loading firmware > >> etc.). But for RTC it obviously is common that it is relevant to the class > >> device too.) > >> > >> So, I assume you mean because there could already be an ioctl before the IRQ has > >> been successfully registered, and this ioctl may wait for an IRQ? > >> > >> In this case the irq::Registration should go into rtc_data instead to account > >> for this dependency. Unfortunately, this is a semantic dependency that we can't > >> always catch at compile time. > >> > >> The reason we sometimes can is because, if you would need access to the > >> irq::Registration from ioctls (e.g. for calling synchronize(), enable(), > >> disable() etc.) it would be caught, because you couldn't access it without it > >> being in rtc_data in the first place, and being forced to have it in rtc_data > >> guarantees that the ordering can't be wrong. > > > > No, once you register the rtc, the character device will appear in > > userspace and may be opened, at this point, probe is not allowed to fail > > anymore which you are allowing by trying to register the IRQ so late. > > This does not seem to correspond to my previous reply -- may I kindly ask you to > read it again? > > Here's also some sketched up code for what I wrote above: > > fn probe(pdev: &pci::Device, info: &Self::IdInfo) -> impl PinInit { > let dev = pdev.as_ref(); > > let rtc_data = impl_pin_init!(SampleRtcData { > io: pdev.iomap_region_sized::(0, c"my_rtc/bar0")?, > hw_variant: VendorVariant::StV1, > irq <- irq::Registration::new(...), > }); > > let rtc = rtc::Device::new(dev, rtc_data)?; > > rtc::Registration::register(rtc)?; > > Ok(Self { rtc }) > } > > Note that if any of the RTC callbacks would ever need to call irq.synchronize(), > irq.disable(), etc. the compiler would enforce correct ordering, as there would > not be any other possibility to put the irq::Registration other than into the > rtc_data that goes into rtc::Device::new(). Right but again, the issue is not about the irq or resource allocation ordering, it is about probe failing after the character device creation. > > Besides that, you above mentioned "probe is not allowed to fail anymore" after > the RTC device is registered and the corresponding character device becomes > visible to userspace. > > While there most likely isn't any good reason for probe() to fail afterwards for > RTC devices, it is not the case that this isn't allowed. We generally can unwind > from a class device registration. In fact, this is not different to remove() > being called (immediately). It is actually different, this was the race back then: CPU0: CPU1: sys_load_module() do_init_module() do_one_initcall() cmos_do_probe() rtc_device_register() __register_chrdev() cdev->owner = struct module* open("/dev/rtc0") rtc_device_unregister() module_put() free_module() module_free(mod->module_core) /* struct module *module is now freed */ chrdev_open() spin_lock(cdev_lock) cdev_get() try_module_get() module_is_live() /* dereferences already freed struct module* */ I don't think it has been solved since then. > > Imagine a case where a driver registers multiple class devices, or a class > device and an auxiliary device, etc. > > (But I assume your point was more that for an RTC device specifically this would > be odd or uncommon.) -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com