All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Jacopo Mondi <jacopo@jmondi.org>
Cc: linux-media@vger.kernel.org, sakari.ailus@linux.intel.com,
	Jacopo Mondi <jacopo+renesas@jmondi.org>,
	niklas.soderlund+renesas@ragnatech.se,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Pratyush Yadav <p.yadav@ti.com>
Subject: Re: [PATCH v10 02/38] media: subdev: add active state to struct v4l2_subdev
Date: Fri, 17 Dec 2021 10:00:18 +0200	[thread overview]
Message-ID: <a1ae9dfd-15d3-53a7-39a5-bc37d3df24a3@ideasonboard.com> (raw)
In-Reply-To: <YbtQHDGp0uDlbiZE@pendragon.ideasonboard.com>

On 16/12/2021 16:41, Laurent Pinchart wrote:

>>>>>>> 5) is currently unused and it still feels a bit ill-defined. If the state
>>>>>>> passed in as parameter is NULL then deflect it to sd->state, so I
>>>>>>> guess it assumes that the user is a state-aware subdev driver which
>>>>>>> needs to protect against in-kernel callers that do no pass in a valid state to
>>>>>>
>>>>>> Correct.
>>>>>>
>>>>>>> the operation call. This implies that if the caller passes in a NULL
>>>>>>> state for the TRY format, this gets deflected to the subdev's active
>>>>>>> state, something which should not happen, right ? I would be tempted
>>>>>>
>>>>>> Yes. That's an illegal call, isn't it? Or does it happen and we need to
>>>>>> protect against it?
>>>>>>
>>>>>>> to just fail loud if !state and assume if you're moving your subdev to
>>>>>>> use state you should be able to fix the caller as well.
>>>>>>
>>>>>> That would be nice, but I think it's not realistic. If you convert a sensor
>>>>>> driver to multiplexed streams, are you going to fix (convert to multiplexed
>>>>>> streams) all the bridges and SoC drivers that may use that sensor? How do
>>>>>> you even find all those bridges and SoCs...
>>>>>
>>>>> Of course no. You fix the one you're using. You're converting a sensor
>>>>> driver, you can fix the top driver too. Other users of the sensor
>>>>> driver will probably scream when moving to the next driver release
>>>>> that has been made state aware, so they'll hopefully fix their top driver
>>>>> too. After all, this applies equally to downstrems as well and
>>>>
>>>> Well, I'm not a maintainer in linux-media, but I would nack that approach
>>>> =). We can't just go breaking other platforms, and hoping other devs will
>>>> fix them.
>>
>> I'd love to agree with Jacopo here and break things all the time to get
>> other people to fix them, but I doubt that I'd make many friends while
>> doing so :-)
>>
>> This being said, the more we can push for conversions to happen quickly,
>> the better. For instance, new sensor drivers should rely on the active
>> state being passed to all subdev operations, so that any existing host
>> driver that wants to use them will need to be converted.
>> v4l2_subdev_lock_and_return_state() in subdev drivers should only be
>> used as a transition tool.
>>
>> Similarly, a way to enforce that new host drivers only work with sensor
>> drivers that have been converted would be good.
>>
>> We should aim for the removal of v4l2_subdev_lock_and_return_state(). A
>> WARN_ON() there will be useful at some point, but it's of course too
>> early. A bit of yak shaving may also help, by asking maintainers and
>> contributors to sensor and host drivers to migrate to the new API.
>>
>>>>> providing an helper to work around issues is not the best idea in my
>>>>> opinion. Also the helper should be used in the subdev driver in place
>>>>> of the regular v4l2_subdev_lock_state() to protect just in case
>>>>> against legacy callers. When will they be moved to use the regular
>>>>> v4l2_subdev_lock_state() ?
>>>>
>>>> Note that this is needed only when porting an existing and presumably in-use
>>>> subdev driver. You don't need this if you write a new driver.
>>>>
>>>> The users of v4l2_subdev_lock_and_return_state are easy to find and easy to
>>>> change to v4l2_subdev_lock_state when we decide a particular driver doesn't
>>>> need to support legacy subdevs.
>>>
>>> I'm just concerned that as long as we offer an helper to work this
>>> around (and the helper might introduce subtle issues like mixing
>>> try/active context) once we
>>> s/v4l2_subdev_lock_and_return_state/v4l2_subdev_lock_state we'll be
>>> anyway breaking users.
>>>
>>>> I don't like this at all but, afaics, we can't break the existing platforms.
>>>> This function is a very simple work-around for the time being, and easy to
>>>> drop later.
>>>>
>>>>> Once a subdev driver has been moved to be state aware callers that
>>>>> passes in a NULL state should be fixed. As we can't fix them all,
>>>>> screaming loud and clearly say what has to be done to move forward is
>>>>> in my opinion better than introducing a temporary function that
>>>>> replaces the regular API and that subdev should decide to use just in
>>>>> case (and which can lead to subtle errors like using the active state
>>>>> in a TRY context).
>>>>>
>>>>> If you want to protect against broken callers then what about
>>>>> doing the "state = state ? : sd->active_state;" dance in
>>>>> v4l2_subdev_lock_state() with a WARN_ONCE(!state) so that
>>>>> subdev drivers can use the regular API from day 0 ?
>>>>
>>>> Hmm, I think that is an option. I didn't implement "state = state ? :
>>>> sd->active_state;" in the v4l2_subdev_lock_state() as I didn't want
>>>> v4l2_subdev_lock_state() to hide an invalid NULL parameter. But adding
>>>> WARN_ONCE() would warn about it.
>>
>> As we can't WARN() unconditionally yet when encountering a driver that
>> hasn't been converted, we need to keep v4l2_subdev_lock_and_return_state()
>> as an alternative that won't WARN. Do I understand that adding
>> "state = state ? : sd->active_state;" + WARN_ON in
>> v4l2_subdev_lock_state() would then be used only to catch invalid
>> combinations with a warning instead of a crash ? What would it help with
>> ?
>>
>>>> I'm still undecided, though. The WARN_ONCE would come only once for the
>>>> whole kernel, per boot, wouldn't it? We could have a macro for
>>>> v4l2_subdev_lock_state, but then we'd get lots of warnings. And a full WARN
>>>> just because a driver hasn't been updated is a bit harsh. Maybe we can start
>>>> with just a normal warning print.
>>>
>>> There is a precendet I can think of: async matching on device or
>>> endpoints. Initially all async subdevs where matched on the remote end
>>> device node. For more complex setups this didn't scale, as the same
>>> remote can have multiple endpoints, and matching on the device node
>>> would have created false positives. So v4l2-async was moved to match on
>>> endpoints with some legacy compatibility code
>>>
>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/media/v4l2-core/v4l2-async.c#n69
>>>
>>> 	if (dev && dev->driver) {
>>> 		if (sd_fwnode_is_ep)
>>> 			dev_warn(dev, "Driver %s uses device fwnode, incorrect match may occur\n",
>>> 				 dev->driver->name);
>>> 		dev_notice(dev, "Consider updating driver %s to match on endpoints\n",
>>> 			   dev->driver->name);
>>> 	}
>>>
>>> Can't we have something like this in v4l2_subdev_lock_state() ?
>>
>> I think we need to start by being silent first, then move to dev_warn(),
>> then to WARN(), and finally drop the option. This can be done with
>> v4l2_subdev_lock_and_return_state() I believe, which would be used by
>> driver that have been converted but still need to support legacy
>> combinations. Drivers that don't want to support legacy combinations
>> would use v4l2_subdev_lock_state(). Usage of
>> v4l2_subdev_lock_and_return_state() in a driver would indicate more work
>> is needed, and would be a useful indication of how far we are in our
>> conversion effort.
> 
> I've discussed this a bit further with Jacopo on IRC. I understand his
> concern that silently using the active state when the state is NULL may
> cause issues that could be hard to debug. However, I believe we need a
> way to handle the transition, without being too harsh (otherwise the
> mob will call for a revert, with pitchforks) or too lenient (otherwise
> nothing will happen).
> 
> One option would be to keep both v4l2_subdev_lock_state() and
> v4l2_subdev_lock_and_return_state(), with both functions replacing a
> NULL state with subdev->active_state. The former would WARN(), and the
> latter would dev_warn(). This would allow a gradual transition from
> v4l2_subdev_lock_and_return_state() to v4l2_subdev_lock_state() when
> we're confident enough that it should be OK for a particular driver. In
> the occasional case where the WARN() would trigger, we could either
> revert and fix, or just fix directly (the latter would be my preferred
> option, as the incentive for the reporter of the issue to write a fix
> would be higher).
> 
> I however don't oppose returning NULL from v4l2_subdev_lock_state() when
> state is NULL (with a WARN_ON()). The caller would likely crash, but
> that's an issue in the caller :-)

Note that v4l2_subdev_lock_state() doesn't return a value. We can't use 
that function to pick up the active state for the caller if the passed 
state is NULL.

We could change v4l2_subdev_lock_state() to return a value, or we could 
change v4l2_subdev_lock_state() to a macro and do magics there, but I 
think both options are very bad.

I think v4l2_subdev_lock_and_return_state() is the best way forward.

I can add a dev_warn there, though.

  Tomi

  reply	other threads:[~2021-12-17  8:00 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30 14:14 [PATCH v10 00/38] v4l: subdev internal routing and streams Tomi Valkeinen
2021-11-30 14:14 ` [PATCH v10 01/38] media: subdev: rename subdev-state alloc & free Tomi Valkeinen
2021-12-13 21:28   ` Jacopo Mondi
2021-11-30 14:15 ` [PATCH v10 02/38] media: subdev: add active state to struct v4l2_subdev Tomi Valkeinen
2021-12-13 21:30   ` Jacopo Mondi
2021-12-15  8:06     ` Tomi Valkeinen
2021-12-15  9:38       ` Jacopo Mondi
2021-12-15 15:35         ` Tomi Valkeinen
2021-12-15 16:25           ` Jacopo Mondi
2021-12-16 14:14             ` Laurent Pinchart
2021-12-16 14:41               ` Laurent Pinchart
2021-12-17  8:00                 ` Tomi Valkeinen [this message]
2021-12-17 10:12   ` Hans Verkuil
2021-11-30 14:15 ` [PATCH v10 03/38] media: subdev: pass also the active state to subdevs from ioctls Tomi Valkeinen
2021-12-14  7:13   ` Jacopo Mondi
2021-12-15  8:13     ` Tomi Valkeinen
2021-12-16 13:47   ` Laurent Pinchart
2021-11-30 14:15 ` [PATCH v10 04/38] media: subdev: add subdev state locking Tomi Valkeinen
2021-12-14  7:42   ` Jacopo Mondi
2021-12-15  8:18     ` Tomi Valkeinen
2021-12-16 13:39   ` Laurent Pinchart
2021-12-17 11:23   ` Hans Verkuil
2021-11-30 14:15 ` [PATCH v10 05/38] media: subdev: Add v4l2_subdev_lock_and_return_state() Tomi Valkeinen
2021-12-16 14:34   ` Laurent Pinchart
2021-12-17 17:43     ` Sakari Ailus
2021-12-17 17:54       ` Laurent Pinchart
2021-12-20 11:48         ` Sakari Ailus
2021-12-17 11:48   ` Hans Verkuil
2021-12-17 17:55     ` Laurent Pinchart
2021-11-30 14:15 ` [PATCH v10 06/38] media: Documentation: add documentation about subdev state Tomi Valkeinen
2021-12-14  8:31   ` Jacopo Mondi
2021-12-16 14:50     ` Laurent Pinchart
2021-12-17  9:22     ` Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 07/38] media: entity: Use pad as a starting point for graph walk Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 08/38] media: entity: Use pads instead of entities in the media graph walk stack Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 09/38] media: entity: Walk the graph based on pads Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 10/38] media: mc: Start walk from a specific pad in use count calculation Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 11/38] media: entity: Add iterator helper for entity pads Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 12/38] media: entity: Move the pipeline from entity to pads Tomi Valkeinen
2022-01-07 19:52   ` Laurent Pinchart
2022-01-09  0:58     ` Laurent Pinchart
2021-11-30 14:15 ` [PATCH v10 13/38] media: entity: Use pad as the starting point for a pipeline Tomi Valkeinen
2022-01-11 23:39   ` Laurent Pinchart
2021-11-30 14:15 ` [PATCH v10 14/38] media: entity: Add has_route entity operation Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 15/38] media: entity: Add media_entity_has_route() function Tomi Valkeinen
2022-01-08 23:31   ` Laurent Pinchart
2022-01-10  7:18     ` Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 16/38] media: entity: Use routing information during graph traversal Tomi Valkeinen
2022-01-17 23:13   ` Laurent Pinchart
2021-11-30 14:15 ` [PATCH v10 17/38] media: entity: Skip link validation for pads to which there is no route Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 18/38] media: entity: Add an iterator helper for connected pads Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 19/38] media: entity: Add only connected pads to the pipeline Tomi Valkeinen
2022-01-07 19:57   ` Laurent Pinchart
2021-11-30 14:15 ` [PATCH v10 20/38] media: entity: Add debug information in graph walk route check Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 21/38] media: Add bus type to frame descriptors Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 22/38] media: Add CSI-2 bus configuration " Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 23/38] media: Add stream to frame descriptor Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 24/38] media: subdev: increase V4L2_FRAME_DESC_ENTRY_MAX to 8 Tomi Valkeinen
2021-12-14  8:35   ` Jacopo Mondi
2021-11-30 14:15 ` [PATCH v10 25/38] media: add V4L2_SUBDEV_FL_MULTIPLEXED Tomi Valkeinen
2021-12-14  8:41   ` Jacopo Mondi
2021-12-15  8:23     ` Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 26/38] media: add V4L2_SUBDEV_CAP_MPLEXED Tomi Valkeinen
2021-12-14  8:39   ` Jacopo Mondi
2021-12-21 18:07     ` Laurent Pinchart
2021-11-30 14:15 ` [PATCH v10 27/38] media: Documentation: Add GS_ROUTING documentation Tomi Valkeinen
2022-02-03 10:55   ` Kieran Bingham
2022-02-03 10:58     ` Kieran Bingham
2021-11-30 14:15 ` [PATCH v10 28/38] media: subdev: Add [GS]_ROUTING subdev ioctls and operations Tomi Valkeinen
2021-12-17  3:31   ` Laurent Pinchart
2021-12-21 17:37   ` Dave Stevenson
2021-11-30 14:15 ` [PATCH v10 29/38] media: subdev: add v4l2_subdev_has_route() Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 30/38] media: subdev: add v4l2_subdev_set_routing helper() Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 31/38] media: Documentation: add multiplexed streams documentation Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 32/38] media: subdev: add stream based configuration Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 33/38] media: subdev: use streams in v4l2_subdev_link_validate() Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 34/38] media: subdev: add "opposite" stream helper funcs Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 35/38] media: subdev: add v4l2_subdev_get_fmt() helper function Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 36/38] media: subdev: add v4l2_subdev_set_routing_with_fmt() helper Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 37/38] media: subdev: add v4l2_subdev_routing_validate_1_to_1 helper Tomi Valkeinen
2021-11-30 14:15 ` [PATCH v10 38/38] media: subdev: Add for_each_active_route() macro Tomi Valkeinen
2021-12-01  6:26 ` [PATCH v10 00/38] v4l: subdev internal routing and streams Tomi Valkeinen

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=a1ae9dfd-15d3-53a7-39a5-bc37d3df24a3@ideasonboard.com \
    --to=tomi.valkeinen@ideasonboard.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jacopo+renesas@jmondi.org \
    --cc=jacopo@jmondi.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=p.yadav@ti.com \
    --cc=sakari.ailus@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.