-
Notifications
You must be signed in to change notification settings - Fork 349
[RFC]ext_man: fix size issue for ext_man_config_data elem #3527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
enum config_elem_type is not start at 0, use a new enum EXT_MAN_CONFIG_FIRST_ELEM to get correct config_elem array size. Signed-off-by: Pan Xiuli <xiuli.pan@linux.intel.com>
|
find during review and debug with thesofproject/linux#2459 |
| struct ext_man_elem_header hdr; | ||
|
|
||
| struct config_elem elems[EXT_MAN_CONFIG_LAST_ELEM]; | ||
| struct config_elem elems[EXT_MAN_CONFIG_LAST_ELEM - EXT_MAN_CONFIG_FIRST_ELEM]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, starts to be a convoluted to me. I didn't pay attention when the "LAST_ELEM" was added, so without context of the prior discussions, I'd say simple "struct config_elem elems[EXT_MAN_CONFIG_LAST_ELEM - 1];" would be simple enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kv2019i This would be easy for view and later change. You will no longer need to update the 1 to other values if you change the ENUM or add some comments here to say: "the enum starts at 1"
|
There are many ideas, EMPTY, FIRST, LAST, MAX etc to get correct size of config_elem. FW and kenel header mismatch is not accepted and ABI update concern also was discussed. |
FYI to @ktrzcinx and @lyakh as well. We have 5-6 PRs (in both linux and sof) that are now somehow dependent on this: We did have an effort to remove flexible arrays from IPC message. SOF patches like: And so forth. The root cause was a bug in xtensa compiler that lead to wrong sizeof calculations (and also at least one case where flexible arrays caused problems with embedding IPC struct within IPC struct with flexible arrays at multiple levels). As @fredoh9 has pointed out, proposals to use a different definition on kernel side have been rejected (as the definitions should be the same). Both @lgirdwood and @ktrzcinx have stated kernel should use flexible arrays, but this is now becoming impossible to meet all constraints, so we have to compromise somehow. So either we allow different definitions (flexible in kernel, fixed size in fw), or we agree to use fixed sizes (even though parsing really has to use the header, not the fixed size). To me, I'd actually prefer to define "struct config_elem elems" as a flexible array, and add a note to FW side this is only defined as a fixed-length variable to avoid a compiler bug. If we do this, then we can just ignore the complexities of getting SOF_EXT_MAN_CONFIG_LAST_ELEM right, on the kernel side and just parse the header. Apologies if this is not helping, but I'm having a really hard time to follow the multiple PRs. |
In my opinion it's only possible solution to keep array extension as non-braking change (from kernel side), so I fully agree with it. It is implemented in this way in PR thesofproject/linux#2459, which one is gathering more approvals than request changes. I think we need to merge one version soon, to end up this diverge. |
|
@kv2019i Agreed with the proposal. We can add inline comments in FW header to say this is only workaround for XCC compiler/linker.
PS: To my understand and test result, the issue comes with the real structure size in ELF file. If we used flexible structure define, |
|
Does this file need to be built with XCC at all ? Isn't it manifest only and not executed. ? |
|
@fredoh9 @kv2019i @ktrzcinx Ping for more discussion here. Will @lgirdwood's suggestion workable here? Can we build ext_manifest in different way or have some workaroud to solve the header mismatch issue. |
It could work, but demanding another toolchain to compile just one file doesn't feel comfortable for me. To be honest, we had problem with flex array containing string, there was problem with null terminating zero when zero would need one more word for a whole string, so it was quite specific example of flex array (extra compiler effort with implicit NULL terminator handling). Here we are storing flex array of structures, which one consist only u32 fields, so there is any implicit terminator or data align problem. Keeping standard flex array (compiled with XCC or GCC) will need some hack to define proper |
|
So XCC is broken and we will need to work around it. @ktrzcinx can you confirm if XCC will work with the hdr.size for each elem (like GCC does )i.e. the kermel would have rely on hdr.size of each elem (even though they can be different sizes with GCC and XCC) ? |
I have tried solution like this: xtensa didn't send any warning, objdump seems to be ok. Any mismatch between hdr.size and section size (because of wrong CONFIG_ELEM_CNT value) will be notice by rimage BUT ONLY when size mismatch will be bigger than |
|
@lgirdwood there wasn't any problem with ALIGN macro functionality, root cause of original problem with CC_DESC handled as flex string array, was lack of null termination in output section memory layout (null termination has been taken into account in size/ALIGN calculation). |
|
@ktrzcinx thanks for the reminder - got you - so your the solution above fixes this issue, but is there impact on the kernel ? and can I confirm does it need an rimage update ? |
Neither solution needs kernel update.
Both will work as it is without rimage update. |
|
close via new solution #3691 |
enum config_elem_type is not start at 0, use a new
enum EXT_MAN_CONFIG_FIRST_ELEM to get correct config_elem
array size.
Signed-off-by: Pan Xiuli xiuli.pan@linux.intel.com