linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: William Breathitt Gray <vilhelm.gray@gmail.com>
Cc: jic23@kernel.org, kamel.bouhara@bootlin.com,
	gwendal@chromium.org, alexandre.belloni@bootlin.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com,
	patrick.havelange@essensium.com, fabrice.gasnier@st.com,
	mcoquelin.stm32@gmail.com, alexandre.torgue@st.com
Subject: Re: [PATCH v5 3/5] counter: Add character device interface
Date: Tue, 20 Oct 2020 10:53:32 -0500	[thread overview]
Message-ID: <fe46666a-4b2f-31f4-b91d-50c33aba0e56@lechnology.com> (raw)
In-Reply-To: <20201018164905.GD231549@shinobu>


>>> +static long counter_chrdev_ioctl(struct file *filp, unsigned int cmd,
>>> +				 unsigned long arg)
>>> +{
>>> +	struct counter_device *const counter = filp->private_data;
>>> +	raw_spinlock_t *const events_lock = &counter->events_lock;
>>> +	unsigned long flags;
>>> +	struct list_head *const events_list = &counter->events_list;
>>> +	struct list_head *const next_events_list = &counter->next_events_list;
>>> +
>>> +	switch (cmd) {
>>> +	case COUNTER_CLEAR_WATCHES_IOCTL:
>>> +		raw_spin_lock_irqsave(events_lock, flags);
>>> +		counter_events_list_free(events_list);
>>> +		raw_spin_unlock_irqrestore(events_lock, flags);
>>> +		counter_events_list_free(next_events_list);
>>
>> I think this ioctl is doing too much. If we have to use it for both
>> stopping events and clearing the list accumulated by
>> COUNTER_SET_WATCH_IOCTL, then we have a race condition of no events
>> after clearing watches during the time we are adding new ones and
>> until we load the new ones.
>>
>> It would probably make more sense to call this ioctl
>> COUNTER_STOP_WATCHES_IOCTL and move counter_events_list_free(
>> next_events_list) to the end of COUNTER_LOAD_WATCHES_IOCTL.
> 
> I don't think we will necessarily have a race condition here.
> COUNTER_CLEAR_WATCHES_IOCTL is intended to just clear the watches; e.g.
> bring us back to a clear state when some sort of job has completely
> finished and the user is no longer going to watch events for a while
> (maybe they're adjusting the conveyor for the next job or some similar
> operation).
> 
> I think the scenario you're concerned about is when you need to swap
> watches in the middle of a job without losing events. In this case, you
> wouldn't need to use COUNTER_CLEAR_WATCHES_IOCTL at all. Instead, you
> would just set up the watches via COUNTER_SET_WATCH_IOCTL, and then use
> COUNTER_LOAD_WATCHES_IOCTL to perform the swap; after
> COUNTER_LOAD_WATCHES_IOCTL completes, next_events_list is empty (thanks
> to list_replace_init()) and you're ready for the next set of watches.
> 

Got it. I think I missed the fact that list_replace_init() clears
next_events_list.

>>> +
>>> +static int counter_chrdev_release(struct inode *inode, struct file *filp)
>>> +{
>>> +	struct counter_device *const counter = filp->private_data;
>>> +	unsigned long flags;
>>> +
>>> +	put_device(&counter->dev);
>>
>> put_device() should be at the end of the function in case it is the last
>> reference.
> 
> put_device() shouldn't affect the counter_device events members, so I
> don't think there's a difference in this case if it's called at the
> beginning or end of the counter_chrdev_release function.
> 

It isn't possible the some memory allocated with devm_kalloc() could be
be referenced after calling put_device() now or in the future?

>>> +}
>>> +EXPORT_SYMBOL_GPL(counter_push_event);
>>
>>
>>> diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c
>>> index e66ed99dd5ea..cefef61f170d 100644
>>> --- a/drivers/counter/counter-sysfs.c
>>> +++ b/drivers/counter/counter-sysfs.c
>>
>>
>> Not sure why sysfs changes are in the chrdev patch. Are these
>> changes related somehow?
> 
> Sorry, I forgot to explain this in the cover letter. The changes here
> are only useful for the character device interface. These changes
> introduce the extensionZ_name and extensionZ_width sysfs attributes.
> 
> In the character device interface, extensions are selected by their id
> number, and the value returned depends on the type of data. The new
> sysfs attributes introduced here allow users to match the id of an
> extension with its name, as well as the bit width of the value returned
> so that the user knows whether to use the value_u8 or value_u64 union
> member in struct counter_event.
> 

Are we sure that all value types will always be CPU-endian unsigned
integers? Or should we make an enum to describe the data type instead
of just the width?

  reply	other threads:[~2020-10-20 15:53 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-27  2:18 [PATCH v5 0/5] Introduce the Counter character device interface William Breathitt Gray
2020-09-27  2:18 ` [PATCH v5 1/5] counter: Internalize sysfs interface code William Breathitt Gray
2020-10-13  2:15   ` David Lechner
2020-10-18 14:49     ` William Breathitt Gray
2020-10-20 15:38       ` David Lechner
2020-10-23 13:12         ` William Breathitt Gray
2020-10-15  1:38   ` David Lechner
2020-10-18 17:00     ` William Breathitt Gray
2020-09-27  2:18 ` [PATCH v5 2/5] docs: counter: Update to reflect sysfs internalization William Breathitt Gray
2020-09-27  2:18 ` [PATCH v5 3/5] counter: Add character device interface William Breathitt Gray
2020-10-14  1:40   ` David Lechner
2020-10-18 16:49     ` William Breathitt Gray
2020-10-20 15:53       ` David Lechner [this message]
2020-10-25 12:55         ` William Breathitt Gray
2020-10-25 16:36           ` David Lechner
2020-10-14 17:43   ` David Lechner
2020-10-14 19:05     ` William Breathitt Gray
2020-10-14 22:32       ` David Lechner
2020-10-14 22:40   ` David Lechner
2020-10-18 16:58     ` William Breathitt Gray
2020-10-20 16:06       ` David Lechner
2020-10-25 13:18         ` William Breathitt Gray
2020-10-25 16:34           ` David Lechner
2020-10-25 17:53             ` William Breathitt Gray
2020-09-27  2:18 ` [PATCH v5 4/5] docs: counter: Document " William Breathitt Gray
2020-10-08  8:09   ` Pavel Machek
2020-10-08 12:28     ` William Breathitt Gray
2020-10-12 17:04       ` David Lechner
2020-10-13 18:58         ` William Breathitt Gray
2020-10-13 19:08           ` David Lechner
2020-10-13 19:27             ` William Breathitt Gray
2020-09-27  2:18 ` [PATCH v5 5/5] counter: 104-quad-8: Add IRQ support for the ACCES 104-QUAD-8 William Breathitt Gray
2020-10-14  0:13   ` David Lechner
2020-10-18 14:50     ` William Breathitt Gray
2020-10-13  0:35 ` [PATCH v5 0/5] Introduce the Counter character device interface David Lechner
2020-10-18 14:14   ` William Breathitt Gray

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=fe46666a-4b2f-31f4-b91d-50c33aba0e56@lechnology.com \
    --to=david@lechnology.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alexandre.torgue@st.com \
    --cc=fabrice.gasnier@st.com \
    --cc=gwendal@chromium.org \
    --cc=jic23@kernel.org \
    --cc=kamel.bouhara@bootlin.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=patrick.havelange@essensium.com \
    --cc=syednwaris@gmail.com \
    --cc=vilhelm.gray@gmail.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).