From: Alexander Holler <holler@ahsoftware.de>
To: rtc-linux@googlegroups.com
Cc: Greg KH <gregkh@linuxfoundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Alessandro Zummo <a.zummo@towertech.it>,
Jiri Kosina <jkosina@suse.cz>
Subject: Re: [rtc-linux] Re: [PATCH 3/9 v2] rtc: rtc-hid-sensor-time: delay registering as rtc into a work
Date: Sat, 06 Jul 2013 10:55:10 +0200 [thread overview]
Message-ID: <51D7DB6E.9010004@ahsoftware.de> (raw)
In-Reply-To: <51CB7E88.6000704@ahsoftware.de>
Am 27.06.2013 01:51, schrieb Alexander Holler:
> Am 27.06.2013 00:07, schrieb Greg KH:
>> On Wed, Jun 26, 2013 at 11:34:35PM +0200, Alexander Holler wrote:
>>>>> + /*
>>>>> + * The HID device has to be registered to read the clock.
>>>>> + * Because rtc_device_register() might read the time, we have to delay
>>>>> + * rtc_device_register() to a work in order to finish the probe before.
>>>>> + */
>>>>> + time_state->workts = kmalloc(sizeof(struct hid_time_workts),
>>>>> + GFP_KERNEL);
>>>>> + if (time_state->workts == NULL) {
>>>>> + sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
>>>>> + return -ENOMEM;
>>>>> }
>>>>> + time_state->workts->time_state = time_state;
>>>>> + INIT_WORK(&time_state->workts->work,
>>>>> + hid_time_register_rtc_work);
>>>>> + schedule_work(&time_state->workts->work);
>>>>
>>>> This seems unreliable. The scheduled work can run one nanosecond
>>>> later, on this or a different CPU. What guarantees that the HID device
>>>> will then be fully registered?
>>>
>>> Nothing, but schedule_delayed_work() is as unreliable as without delay
>>> and I don't know of any callback after registration has happened. I have
>>> to dig through the hid-(sensor-)code, maybe I will find a callback I can
>>> (mis)use to register the rtc driver after the hid driver was registered.
>>
>> Why not use the deferred_probe code, which is there just for this type
>> of thing (i.e. your other drivers/devices aren't present/initialized
>> yet.)? Just return -EPROBE_DEFER from your probe function if you don't
>> find everything already set up properly, the driver core will call you
>> again later after it has initialized everything it has found.
>
> Hmm, didn't know about the deferred_probe stuff. Thanks.
>
> Unfortunately I currently don't see how this might help here. The
> rtc-device will not be probed, so it can't be deferred. And even if I
> will find or implement a way to add a probe for the rtc device, I still
> have to search how to find out if the HID device is registered.
>
> Anyway, back to reading to sources. Maybe there already is some callback
> from hid-sensor-hub or the hid-subsystem I can use. I haven't searched
> in deep for such because using a work worked just fine here on several
> machines (besides that it was a quick hack which got only necessary with
> the changed hctosys which reads the time in rtc_device_register()).
>
> I already wondered why using a work (even without delay) did work, but I
> explained it with some (maybe imaginary) locality of works, such that
> they get called after the scheduling thread gives up his timeslice which
> happily happened after the hid-device was registered. So I hoped (hope
> dies last ;) ) to only have to fix it, if it actually doesn't work
> somewhere or sometimes after the foreseen discussion about hctosys has
> come to an end.
>
I've now traced down why the above patch _really_ is needed: it's
because of how the locking is done in the hid-subsystem. So my intuition
to use a work was ok, but my assumption that it's because the HID device
driver wasn't registered before probe() finished was wrong.
What happens without using a work is the following (shortened a lot):
hid_device_probe() // hid subsystem locks hdev->driver_input_lock
hid_time_probe()
devm_rtc_device_register() // wants to read the clock
hid_rtc_read_time() // submits GET_REPORT and waits for the answer
// (the timestamp from the clock)
hid_input_report()
And there we have something like a deadlock situation because
hid_input_report() needs hdev->driver_input_lock to submit the report to
the HID driver.
So in short, it's currently impossible for a HID driver to read input
from a HID device from inside it's probe function.
That means the patch is fine, but the comment is wrong.
Because I think it would be better to change the locking inside the HID
subsystem (drivers/hid/hid-core.c) in order to allow the probe function
of HID drivers to read input, I will first have a look if I see a way to
change the locking in hid-core.c, before I will post an update to the
above patch with a corrected comment. But this might need some time as
I'm not familiar with the locking in the HID subsystem and my motivation
currently isn't very high.
Regards,
Alexander Holler
next prev parent reply other threads:[~2013-07-06 8:56 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-19 15:14 [PATCH 0/3] rtc: rtc-hid-sensor-time Alexander Holler
2013-04-19 15:14 ` [PATCH 1/3 RESEND] rtc: rtc-hid-sensor-time: allow full years (16bit) in HID reports Alexander Holler
2013-04-19 15:14 ` [PATCH 2/3] rtc: rtc-hid-sensor-time: allow 16 and 32 bit values for all attributes Alexander Holler
2013-04-19 15:14 ` [PATCH 3/3] rtc: rtc-hid-sensor-time; add option hctosys to set time at boot Alexander Holler
2013-04-22 23:38 ` Andrew Morton
2013-04-23 8:51 ` Alexander Holler
2013-04-23 10:08 ` Alexander Holler
2013-04-23 10:13 ` Alexander Holler
2013-04-23 10:17 ` Alexander Holler
2013-04-23 15:47 ` Alexander Holler
2013-04-24 21:14 ` Andrew Morton
2013-04-25 6:55 ` Alexander Holler
2013-05-05 11:21 ` [PATCH 0/4] rtc: rtc-hid-sensor-time: some changes Alexander Holler
2013-05-05 11:21 ` [PATCH 1/4] rtc: rtc-hid-sensor-time: allow full years (16bit) in HID reports Alexander Holler
2013-05-05 11:21 ` [PATCH 2/4] rtc: rtc-hid-sensor-time: allow 16 and 32 bit values for all attributes Alexander Holler
2013-05-05 11:21 ` [PATCH 3/4] rtc: rtc-hid-sensor-time: add option hctosys to set time at boot Alexander Holler
2013-05-21 21:42 ` Andrew Morton
2013-05-21 22:02 ` John Stultz
2013-05-21 23:15 ` Alexander Holler
2013-05-28 19:37 ` John Stultz
2013-05-29 4:42 ` Alexander Holler
2013-06-04 13:41 ` Alexander Holler
2013-06-05 17:15 ` [PATCH 0/3] RFC: timekeeping: rtc: change hctosys mechanism Alexander Holler
2013-06-05 17:15 ` [PATCH 1/3] RFC: timekeeping: introduce flag systime_was_set Alexander Holler
2013-06-05 17:15 ` [PATCH 2/3] RFC: timekeeping: rtc: Introduce new kernel parameter hctosys Alexander Holler
2013-06-05 17:15 ` [PATCH 3/3] RFC: timekeeping: rtc: remove CONFIG_RTC_HCTOSYS and RTC_HCTOSYS_DEVICE Alexander Holler
2013-06-06 10:51 ` [PATCH 0/3 v2] RFC: timekeeping: rtc: change hctosys mechanism Alexander Holler
2013-06-06 10:51 ` [PATCH 1/3 RESEND] RFC: timekeeping: introduce flag systime_was_set Alexander Holler
2013-06-06 10:51 ` [PATCH 2/3 v2] RFC: timekeeping: rtc: Introduce new kernel parameter hctosys Alexander Holler
2013-06-13 19:39 ` Alexander Holler
2013-06-14 16:52 ` [PATCH 0/9 v3] RFC: timekeeping: rtc: change hctosys mechanism Alexander Holler
2013-06-14 16:52 ` [PATCH 1/9 RESEND] rtc: rtc-hid-sensor-time: allow full years (16bit) in HID reports Alexander Holler
2013-06-14 16:52 ` [PATCH 2/9 RESEND] rtc: rtc-hid-sensor-time: allow 16 and 32 bit values for all attributes Alexander Holler
2013-06-14 16:52 ` [PATCH 3/9] rtc: rtc-hid-sensor-time: delay registering as rtc into a work Alexander Holler
2013-06-20 10:39 ` [PATCH 3/9 v2] " Alexander Holler
2013-06-26 19:55 ` Andrew Morton
2013-06-26 21:34 ` [rtc-linux] " Alexander Holler
2013-06-26 22:07 ` Greg KH
2013-06-26 23:51 ` Alexander Holler
2013-07-06 8:55 ` Alexander Holler [this message]
2013-07-06 18:21 ` Jiri Kosina
2013-07-07 7:35 ` Alexander Holler
2013-07-08 9:12 ` [PATCH 0/2] rtc: rtc-hid-sensor-time: enable HID input processing early Alexander Holler
2013-07-08 9:12 ` [PATCH 1/2] rtc: rtc-hid-sensor-time: improve error handling when rtc register fails Alexander Holler
2013-07-08 9:12 ` [PATCH 2/2] rtc: rtc-hid-sensor-time: enable HID input processing early Alexander Holler
2013-06-28 1:29 ` [rtc-linux] Re: [PATCH 3/9 v2] rtc: rtc-hid-sensor-time: delay registering as rtc into a work Alexander Holler
2013-06-14 16:52 ` [PATCH 4/9 RESEND] RFC: timekeeping: introduce flag systime_was_set Alexander Holler
2013-06-14 17:41 ` John Stultz
2013-06-14 18:05 ` [rtc-linux] " Alexander Holler
2013-06-14 18:28 ` John Stultz
2013-06-15 6:01 ` Alexander Holler
2013-06-17 18:10 ` John Stultz
2013-06-20 10:15 ` Alexander Holler
2013-06-20 17:27 ` John Stultz
2013-06-20 18:45 ` Alexander Holler
2013-06-20 19:28 ` John Stultz
2013-06-20 23:10 ` Alexander Holler
2013-06-14 16:52 ` [PATCH 5/9 v3] RFC: timekeeping: rtc: Introduce new kernel parameter hctosys Alexander Holler
2013-06-14 19:24 ` John Stultz
2013-06-14 16:52 ` [PATCH 6/9 v3] RFC: timekeeping: rtc: remove CONFIG_RTC_HCTOSYS and RTC_HCTOSYS_DEVICE Alexander Holler
2013-06-14 19:11 ` John Stultz
2013-06-22 8:00 ` Alexander Holler
2013-06-14 16:52 ` [PATCH 7/9] RFC: rtc: implement rtc_read_timeval() Alexander Holler
2013-06-14 17:23 ` John Stultz
2013-06-14 17:43 ` Alexander Holler
2013-06-14 19:18 ` John Stultz
2013-06-14 17:28 ` John Stultz
2013-06-14 16:52 ` [PATCH 8/9] RFC: rtc: hctosys: support rtc_read_timeval() for high precision clocks Alexander Holler
2013-06-14 19:20 ` John Stultz
2013-06-14 16:52 ` [PATCH 9/9] RFC: rtc: rtc-hid-sensor-time: add support for rtc_read_timeval() Alexander Holler
2013-06-14 17:27 ` [PATCH 0/9 v3] RFC: timekeeping: rtc: change hctosys mechanism John Stultz
2013-06-06 10:51 ` [PATCH 3/3 v2] RFC: timekeeping: rtc: remove CONFIG_RTC_HCTOSYS and RTC_HCTOSYS_DEVICE Alexander Holler
2013-06-04 9:38 ` [PATCH] rtc: rtc-hid-sensor-time: fix possible bug on driver_remove Alexander Holler
2013-06-08 8:56 ` Alexander Holler
2013-05-05 11:21 ` [PATCH 4/4] rtc: rtc-hid-sensor-time: add support for milliseconds Alexander Holler
2013-04-20 23:46 ` [PATCH 0/3] rtc: rtc-hid-sensor-time Jiri Kosina
2013-04-21 6:38 ` Alexander Holler
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=51D7DB6E.9010004@ahsoftware.de \
--to=holler@ahsoftware.de \
--cc=a.zummo@towertech.it \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=jkosina@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=rtc-linux@googlegroups.com \
/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).