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

virtio: add create_virtqueues and delete_virtqueues in virtio_dispatch #495

Merged
merged 1 commit into from
Jul 12, 2023

Conversation

CV-Bowen
Copy link
Contributor

@CV-Bowen CV-Bowen commented Jul 3, 2023

This is the first step to decoupling the virtio deivce and transport layer.

Related issue: #390 (comment)

@arnopo Could take a look?

Copy link
Collaborator

@arnopo arnopo left a comment

Choose a reason for hiding this comment

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

copy past issue in virtio.h + "deivce" to fix in commit message

lib/include/openamp/virtio.h Outdated Show resolved Hide resolved
@arnopo
Copy link
Collaborator

arnopo commented Jul 3, 2023

copy past issue in virtio.h + "deivce" to fix in commit message

you still need to fix the commit message :

./scripts/checkpatch.pl --strict -g HEAD
ec793415d92ab97232bdd32aba5b2c9845c2b5f0:7: WARNING:TYPO_SPELLING: 'deivce' may be misspelled - perhaps 'device'?
#7: 
This is the first step to decoupling the virtio deivce and transport
                                                ^^^^^^

ec793415d92ab97232bdd32aba5b2c9845c2b5f0 total: 0 errors, 1 warnings, 0 checks, 155 lines checked

@CV-Bowen
Copy link
Contributor Author

CV-Bowen commented Jul 4, 2023

@arnopo Done.

@arnopo arnopo added this to the Release V2023.10 milestone Jul 4, 2023
Copy link
Collaborator

@uLipe uLipe left a comment

Choose a reason for hiding this comment

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

Just a small question.

*/
static inline void virtio_delete_virtqueues(struct virtio_device *vdev)
{
return vdev->func->delete_virtqueues(vdev);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question, is guaranteed the func will be always valid here? It would not be good to check for availabillity of this function before calling, also making this way will obligate the implementor of the dispatch functions to provide this function, is this intended?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes the point is valid. Vdev , 'vdev->func' and 'vdev->func->delete_virtqueues' should be checked.
@CV-Bowen: It is acceptable for me to do it in a second step as here the main objective is to create the API. It can also be done by updating the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arnopo @uLipe OK, I will update this PR, another question is should I add this check in all the new virtio_xxx() apis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done.

The @uLipe comment is valid for all the func. with a return on "-ENXIO" when requestion a return value.

Copy link
Contributor Author

@CV-Bowen CV-Bowen Jul 10, 2023

Choose a reason for hiding this comment

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

@arnopo So I change all the virtio_xxx functions return type to int and call dispatch function in these functions ?
Like:

static inline int virtio_set_status(struct virtio_device *vdev, uint8_t status)
{
    if (!vdev->func->set_status)
        return -ENXIO;
    vdev->func->set_status(vdev, status);
    return 0;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

@CV-Bowen , yes this is the intention, the dispatch functions have a return type, when it is present just return the result of the dispatch functions, taking the example above slightly modified:

static inline int virtio_set_status(struct virtio_device *vdev, uint8_t status)
{
    if (!vdev->func->set_status)
        return -ENXIO;
    else 
       return vdev->func->set_status(vdev, status);
}

The idea is all the dispatch function templates have an return value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@uLipe Thanks, I found the vdev->func->set_status return value change to int (void for now) in your example code, should I change all the dispatch functions return type to int? This is a significant change.

static inline int virtio_set_status(struct virtio_device *vdev, uint8_t status)
{
if (!vdev->func->set_status)
return -ENXIO;
else
return vdev->func->set_status(vdev, status);
}

@arnopo
Copy link
Collaborator

arnopo commented Jul 6, 2023

@danmilea
Could you have a look to this PR to confirm that it compatible ( or not) with your implementation?
I would like to have your feedback before merging it.

@CV-Bowen CV-Bowen force-pushed the virtio-decouple-1 branch 3 times, most recently from 375fc2c to d70af8b Compare July 10, 2023 15:55
Copy link
Collaborator

@arnopo arnopo left a comment

Choose a reason for hiding this comment

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

few suggestions to increase the APi robustness, else LGTM

if (!vdev->func)
return -ENXIO;

if (vdev->func->create_virtqueues) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

to avoid regression on existing code
remove

	if (!vdev->func)
		return -ENXIO;

instead use if (vdev-> func && vdev->func->create_virtqueues) {

Please could you also add

if (!vdev || !src)
	return -EINVAL;

at the beginning of the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*/
static inline int virtio_get_status(struct virtio_device *vdev, uint8_t *status)
{
if (!status)
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (!vdev || !status)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

lib/include/openamp/virtio.h Show resolved Hide resolved
lib/include/openamp/virtio.h Show resolved Hide resolved
lib/include/openamp/virtio.h Show resolved Hide resolved
static inline int virtio_get_features(struct virtio_device *vdev,
uint32_t *features)
{
if (!features)
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (!vdev || !features)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

lib/include/openamp/virtio.h Show resolved Hide resolved
uint32_t features,
uint32_t *final_features)
{
if (!final_features)
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (!vdev || !final_features)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

lib/include/openamp/virtio.h Show resolved Hide resolved
This is the first step to decoupling the virtio device and transport
layer.

Signed-off-by: Bowen Wang <[email protected]>
@arnopo arnopo self-requested a review July 11, 2023 14:28
Copy link
Collaborator

@arnopo arnopo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@danmilea danmilea left a comment

Choose a reason for hiding this comment

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

Good to merge.

@arnopo arnopo merged commit 7f90610 into OpenAMP:main Jul 12, 2023
2 checks passed
@arnopo
Copy link
Collaborator

arnopo commented Jul 12, 2023

Merged, thanks for the contribution!

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.

6 participants