Uh oh!
There was an error while loading. Please reload this page.
dmic: fix dmic and volume configuration ipc - #721
Conversation
dabekjakub
commented
Dec 14, 2018
7ec223f to
ea8df73Comparelgirdwood
commented
Dec 14, 2018
@dabekjakub since you are still online the fix is to pass _ipc->comp_data to dai_config() directly and to other calls that take variable length flex arrays. |
dabekjakub
commented
Dec 14, 2018
Yes we found it just after pr was created. I am in the process of submitting new one. |
ranj063
commented
Dec 14, 2018
@lgirdwood yes that is indeed a good catch. DMIC does has a variable length array and it needs to be handled carefully especially now that 4ch capture is the requirement. |
lgirdwood
commented
Dec 14, 2018
@dabekjakub great, I think it's only dai_config() and comp_cmd() that use the var flex arrays. |
ea8df73 to
4beac78CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
0b25c76 to
a844db7Compare| /* get component values */ | ||
| ret = ipc_comp_cmd(comp_dev->cd, cmd, &data); | ||
| ret = ipc_comp_cmd(comp_dev->cd, cmd, _ipc->comp_data); |
There was a problem hiding this comment.
@dabekjakub it seems like we dont really need the data variable at here right? can we just remove it?
There was a problem hiding this comment.
it is used later down the line in
component.h:286 static inline int comp_cmd(struct comp_dev *dev, int cmd, void *data)
There was a problem hiding this comment.
I guess it must be removed in all the places to avoid stop-on-warning when using another compiler.
There was a problem hiding this comment.
Right, it is used indeed but the original request content stays in the data buffer on stack. If you need a quick fix to the existing version that uses copy, perhaps IPC_COPY_CMD should be called after return from the handler to make sure potential error codes are propagated if there are any.
There was a problem hiding this comment.
There might be another issue, if there are var-size data indicated by the (_ipc->comp_data).rhdr.hdr.size > fixed sizeof(data), there might be OOB here:
/* write component values to the outbox */mailbox_hostbox_write(0, &data, data.rhdr.hdr.size);There was a problem hiding this comment.
May be relevant to other functions as well. Need to analyze it on Monday.
There was a problem hiding this comment.
Agreed, I think we need
struct sof_ipc_ctrl_data *out_data = NULL;
/* get component values */
ret = ipc_comp_cmd(comp_dev->cd, cmd, _ipc->comp_data, &out_data);
if (ret < 0) {
trace_ipc_error("ipc: comp %d cmd %u failed %d", data.comp_id,
data.cmd, ret);
return ret;
}
/* write component values to the outbox */
mailbox_hostbox_write(0, out_data, out_data.rhdr.hdr.size);
rfree(out_data);
Where out_data is allocated in the component but freed here.
a844db7 to
902a6d1CompareFixed ipc data size not beeing corectly passed to dmic. Fix actualy reverts some of ABI changes that could not work in curent setup. Signed-off-by: Jakub Dabek <jakub.dabek@linux.intel.com>
902a6d1 to
7f1f197Comparedabekjakub
commented
Dec 14, 2018
Moved to position after data is handled. |
ranj063
commented
Dec 14, 2018
@dabekjakub sorry I think this would still cause problems. The best thing to do is remove data and just usr _ipc->comp_data everywhere. But we need to find a more graceful fix that changing every single function in handler like we talked about today. |
@lgirdwood
Even if it somehow works now it will cause problems in the future. 3rd issue is literally like casting always to top level type in OO languages - because we use type of variable that is passed by value and the fact that it may be kind of 'subclass' doesn't matter for macro. We need better way of 'masking', because that's what we do now we kinda mask what we get from driver to what FW may understand, problem is that our mask is only general type (or lacks flexarrays/is extended by unions). |
@jajanusz agree with your opinion. We do need to fix IPC_CMD_COPY. |
jajanusz
commented
Dec 14, 2018
We can limit problem with api compatibility to 2 cases - when drvier is ahead of FW or otherwise. When driver is ahead - just cut to size of what FW can process. That's what
I think we need something more than 1 simple macro to handle this. |
ranj063
commented
Dec 14, 2018
|
jajanusz
commented
Dec 14, 2018
@ranj063 |
jajanusz
commented
Dec 14, 2018
@lgirdwood @dabekjakub |
dabekjakub
commented
Dec 14, 2018
Change made as per @mmaka1 request to ensure that the two way ipc works correctly (example: host asking for volume value). We could change the mailbox to and delete data entirely but @mmaka1 had an argument for keeping it. @mmaka1 could You elaborate on this. I don't want to spread misleading info here since conversation took place off github. @jajanusz@ranj063 @mmaka1 suggested a buffer specifically for ipc handling. In the end we need to decide if we even want this temporary fix on master or do we scrap it and move on directly to end result. |
plbossart
commented
Dec 14, 2018
via email
On 12/14/18 3:57 PM, Jakub Dabek wrote:
@jajanusz <https://github.com/jajanusz> @ranj063
<https://github.com/ranj063> @lgirdwood <https://github.com/lgirdwood>
@dabekjakub <https://github.com/dabekjakub> sorry I think this
would still cause problems. The best thing to do is remove data
and just usr _ipc->comp_data everywhere. But we need to find a
more graceful fix that changing every single function in handler
like we talked about today.
Change made as per @mmaka1 <https://github.com/mmaka1> request to
ensure that the two way ipc works correctly (example: host asking for
volume value). We could change the mailbox to
|mailbox_hostbox_write(0, _ipc->comp_data, ((struct sof_ipc_ctrl_data
*)_ipc->comp_data)->rhdr.hdr.size); |
and delete data entirely but @mmaka1 <https://github.com/mmaka1> had
an argument for keeping it. @mmaka1 <https://github.com/mmaka1> could
You elaborate on this. I don't want to spread misleading info here
since conversation took place off github.
@jajanusz <https://github.com/jajanusz> @ranj063
<https://github.com/ranj063>
We know ipc size since host sends it every time in ipc_cmd_header, so
we do not have to relay on anything else if host calculates what it
sends. We need to allocate enough memory for structs in handler.c for
that matter. Just as i sugested:
|struct sof_ipc_ctrl_data *data =
rmalock(RZONE_RUNTIME,SOF_MEM_CAPS_RAM, ((struct sof_ipc_cmd_hdr
*)_ipc->comp_data)->size); |
@mmaka1 <https://github.com/mmaka1> suggested a buffer specifically
for ipc handling.
In the end we need to decide if we even want this temporary fix on
master or do we scrap it and move on directly to end result.
You guys have exactly 4 days to agree and close this. the ABI3 will be
frozen when I send the next batch of Linux patches upstream. I've waited
and waited for ABI updates since I came back, sorry folks, nothing
personal, but time is up. Tick Tock. |
michalgrodzicki
commented
Dec 14, 2018
@plbossart I see that you don't want to help, but please don't disturb people. |
plbossart
commented
Dec 14, 2018
via email
On 12/14/18 4:36 PM, michalgrodzicki wrote:
@plbossart <https://github.com/plbossart> I see that you don't want to
help, but please don't disturb people.
I've been around for longer than you did, and I want to avoid having to
maintain code like this:
https://github.com/thesofproject/linux/blob/b8db053ebce3636f5d3eca2c25b544cd15ee14ef/sound/soc/intel/skylake/skl-topology.c#L2912
You may not like what I state but without progress we will have to live
with the existing solution as legacy. This happened for Skylake/cAVS and
is about to happen again. You may chose to ignore the need to close on
the ABI, but it'll hit your planning next year when we have to deal with
backwards compatibility.
Over and out. |
ranj063
commented
Dec 14, 2018
@plbossart I think the discussion on this thread is not proposing any changes to the ABI. So we should be good for ABI3. It is purely a discussion on how to fix the problem being addressed for dmic and volume today more widely. |
lgirdwood
commented
Dec 15, 2018
@dabekjakub@jajanusz The IPC_COPY_CMD macro is only meant for introspection at the handler level (and to guarantee that introspection will work regardless if new fields are added). The _ipc->comp_data should be passed by handler into client APIs (since clients will deal with the unions/flex arrays). Same goes for opposite data copy direction too from DSP to host. @dabekjakub I'll be back on later tonight, and will do a PR if I don't see an update from you today. |
lgirdwood
commented
Dec 15, 2018
@dabekjakub I have something cooking now. Will post in a few hours. |
jajanusz
commented
Dec 15, 2018
Ok, it makes sense. Just intention wasn't clear, cos of misuse of that macro looked like it was meant to be used everywhere, not just at the handler level. |
dabekjakub
commented
Dec 15, 2018
I am in a position where @mmaka1 asked for one change and @jajanusz@ranj063 for other. In my opinion we should merge this as is at the moment or work on good solution right away. @lgirdwood if You need any help or action on my side i have a setup at home i can get to work with in 3 hours. |
ranj063
commented
Dec 15, 2018
@dabekjakub I think it would be better to just wait for @lgirdwood 's update rather than merging this as is. I can test Liam's solution tonight too. |
dabekjakub
commented
Dec 15, 2018
Agreed |
lgirdwood
commented
Dec 15, 2018
@ranj063@dabekjakub@jajanusz Please see #730 compile tested only atm. @mengdonglin can someone test this Monday morning PRC time and make any fixes if needed. Going forward a stream based IPC where every structure has a header with size, type, version and no substructures or flex arrays would be easiest for ABI changes going forward, but this is just too invasive for v1.3, maybe something for v1.4+.... |
mmaka1
commented
Dec 17, 2018
This is exactly what was mentioned in the thesofproject/linux#414. |
Fixed ipc data size not beeing corectly passed to dmic and volume.
Signed-off-by: Jakub Dabek jakub.dabek@linux.intel.com