Skip to content
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

module_adapter: return error if get_conf is not implemented #9045

Merged

Conversation

johnylin76
Copy link
Contributor

At present, if get_configuration is not implemented by internal module, module_adapter will return 0 directly on config read commands. Under the circumstances, the host will suppose the reading is succeeded, but in fact the ata in IPC buffer is unwanted.

This commit changes the return code to non-zero for such cases, which prevents the host getting the unwanted config data.

Copy link
Contributor

@LaurentiuM1234 LaurentiuM1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change makes sense. Need to watch out for modules (such as cadence.c) which don't have get_configuration() and set_configuration() both implemented as this seems to cause errors such as:

[ 2834.159757] sof-audio-of-imx8 596e8000.dsp: ipc tx error for 0x50040000 (msg/reply size: 160/160): -5
[ 2834.169077] sof-audio-of-imx8 596e8000.dsp: kcontrol 1 read failed for widget CODEC_ADAPTER1.0

(extract is from a cplay run w/ cadence.c module and this patch)

src/audio/module_adapter/module_adapter_ipc3.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a good addition. The one warn-to-err log message change might potentially be good before merge, but no showstoppers, so leaving my +1 here.

@@ -207,7 +207,7 @@ static int module_adapter_get_set_params(struct comp_dev *dev, struct sof_ipc_ct

comp_warn(dev, "module_adapter_get_set_params(): no configuration op set for %d",
dev_comp_id(dev));
return 0;
return -EIO; /* non-implemented error */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized this leads to a special case that by calling this -EIO will be returned for CMD_SET_DATA if set_configuration is not implemented. It's beyond my purpose that returning -EIO for CMD_GET_DATA only.

Hi @LaurentiuM1234 , I just saw your comment saying that cadence.c doesn't implement both get_configuration and set_configuration, is that correct? If the non-implemented set_configuration is intentional, I think this line should be fixed to keep CMD_SET_DATA behavior as is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized this leads to a special case that by calling this -EIO will be returned for CMD_SET_DATA if set_configuration is not implemented. It's beyond my purpose that returning -EIO for CMD_GET_DATA only.

ACK, so now get_configuration() becomes mandatory and set_configuration() remains optional. Might be out of scope for this, but did you consider adding all the interface->set/get_configuration() logic into some wrapper functions?

i.e: something like:

static inline int module_set_configuration(struct processing_module *mod, uint32_t config_id
                                                                   enum module_cfg_fragment_position pos, uint32_t data_offset_size,
                                                                   const uint8_t *fragment, size_t fragment_size, uint8_t *response,
                                                                   size_t response_size)
{
    const struct module_interface *const ops = mod->dev->drv->adapter_ops;

    if (ops->set_configuration) {
       // call set_configuration
    }

    // optional operation
    return 0;
}

static inline int module_get_configuration(struct processing_module *mod, uint32_t config_id
                                                                   enum module_cfg_fragment_position pos, uint32_t data_offset_size,
                                                                   const uint8_t *fragment, size_t fragment_size, uint8_t *response,
                                                                   size_t response_size)
{
    const struct module_interface *const ops = mod->dev->drv->adapter_ops;

    // this is not optional
    if (!ops->get_configuration)
        return -EIO;

    // some more code here
}

Since this is also used by the IPC4 stuff, having a centralized view showing which operation is optional and which isn't might be helpful?

Hi @LaurentiuM1234 , I just saw your comment saying that cadence.c doesn't implement both get_configuration and set_configuration, is that correct? If the non-implemented set_configuration is intentional, I think this line should be fixed to keep CMD_SET_DATA behavior as is.

The cadence module doesn't implement the get_configuration() stuff so if we make it mandatory the issue will still persist. Can't really tell you why it's not implemented but we can probably get around the issue by just implementing a dummy get_configuration() if we really don't need a proper one. Anyways, IMO not a blocker for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Some contexts below for clearer statement:

The commit doesn't mean to make get_configuration mandatory (in a literal manner). Instead, the intention is to fix the use case of SOF build which integrates the instance without get_configuration in module_adapter.

Consider a host running the IPC command to read blob data from the module_adapter bytes control, if module_adapter doesn't return error while the instance doesn't implement get_configuration, the host will consider the blob data is read back successfully, leading to problems on wrong (or illegal) data blob access. As a consequence, it should be better to return error than zero, provided that the host has no clue whether get_configuration is implemented by instance or not.

At present, if get_configuration is not implemented by internal module,
module_adapter will return 0 directly on config read commands. Under
the circumstances, the host will suppose the reading is succeeded, but
in fact the ata in IPC buffer is unwanted.

This commit changes the return code to non-zero for such cases, which
prevents the host getting the unwanted config data.

Signed-off-by: Johny Lin <johnylin@google.com>
@johnylin76 johnylin76 force-pushed the main-module-adapter-get-bytes branch from b31a8b6 to 8f78eac Compare April 16, 2024 08:09
@johnylin76
Copy link
Contributor Author

Change makes sense. Need to watch out for modules (such as cadence.c) which don't have get_configuration() and set_configuration() both implemented as this seems to cause errors such as:

[ 2834.159757] sof-audio-of-imx8 596e8000.dsp: ipc tx error for 0x50040000 (msg/reply size: 160/160): -5
[ 2834.169077] sof-audio-of-imx8 596e8000.dsp: kcontrol 1 read failed for widget CODEC_ADAPTER1.0

(extract is from a cplay run w/ cadence.c module and this patch)

Thanks for catching this. I suppose the cause is as my last comment #9045 (comment)
I just updated the patch. PTAL, thanks.

@kv2019i
Copy link
Collaborator

kv2019i commented Apr 17, 2024

@wszypelt Here's one more to check. I checked test job 13872687 and seems test terminates midway and does seem to be linked to this PR.

@kv2019i kv2019i merged commit 58f141c into thesofproject:main Apr 18, 2024
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants