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

rpmsg: let rpmsg_virtio_get_tx_buffer() always return idx in host side #520

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

CV-Bowen
Copy link
Contributor

@CV-Bowen CV-Bowen commented Oct 16, 2023

In rpmsg host side, the tx buffer index is not assigned when this buffer is obtained from the reclaimer list, this commit let rpmsg_virtio_get_tx_buffer() always gets correct idx.

Note: the idx in rpmsg host side is not used, so this commit is just an improvement and not fix any issue.

@arnopo arnopo requested review from edmooring and tnmysh October 16, 2023 15:42
@arnopo arnopo added this to the Release V2023.10 milestone Oct 16, 2023
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.

Something is bad in my test , if such error has not been detected :(
I need to understand the issue, but I plan to get it for the release as a fix

A minor comment

lib/rpmsg/rpmsg_virtio.c Outdated Show resolved Hide resolved
@arnopo
Copy link
Collaborator

arnopo commented Oct 16, 2023

I crosschecked the behavior. In rpmsg_virtio_return_buffer, we don't use the index for host side. So in theory not need to set it.

Do you have a concrete use case for which your are facing an issue?

@CV-Bowen
Copy link
Contributor Author

@arnopo The index will be used in rpmsg_virtio_release_tx_buffer(): idx = rp_hdr->reserved;

static int rpmsg_virtio_release_tx_buffer(struct rpmsg_device *rdev, void *txbuf)
{
	struct rpmsg_virtio_device *rvdev;
	struct rpmsg_hdr *rp_hdr = RPMSG_LOCATE_HDR(txbuf);
	void *vbuff = rp_hdr;  /* only used to avoid warning on the cast of a packed structure */
	struct vbuff_reclaimer_t *r_desc = (struct vbuff_reclaimer_t *)vbuff;
	uint16_t idx;

	/*
	 * Reuse the RPMsg buffer to temporary store the vbuff_reclaimer_t structure.
	 * Stores the index locally before overwriting the RPMsg header.
	 */
	idx = rp_hdr->reserved;

	rvdev = metal_container_of(rdev, struct rpmsg_virtio_device, rdev);

	metal_mutex_acquire(&rdev->lock);

	r_desc->idx = idx;
	metal_list_add_tail(&rvdev->reclaimer, &r_desc->node);

	metal_mutex_release(&rdev->lock);

	return RPMSG_SUCCESS;
}

And the rp_hdr->reserved is set to idx in rpmsg_virtio_get_tx_payload_buffer()

@arnopo
Copy link
Collaborator

arnopo commented Oct 17, 2023

@arnopo The index will be used in rpmsg_virtio_release_tx_buffer(): idx = rp_hdr->reserved;

static int rpmsg_virtio_release_tx_buffer(struct rpmsg_device *rdev, void *txbuf)
{
	struct rpmsg_virtio_device *rvdev;
	struct rpmsg_hdr *rp_hdr = RPMSG_LOCATE_HDR(txbuf);
	void *vbuff = rp_hdr;  /* only used to avoid warning on the cast of a packed structure */
	struct vbuff_reclaimer_t *r_desc = (struct vbuff_reclaimer_t *)vbuff;
	uint16_t idx;

	/*
	 * Reuse the RPMsg buffer to temporary store the vbuff_reclaimer_t structure.
	 * Stores the index locally before overwriting the RPMsg header.
	 */
	idx = rp_hdr->reserved;

	rvdev = metal_container_of(rdev, struct rpmsg_virtio_device, rdev);

	metal_mutex_acquire(&rdev->lock);

	r_desc->idx = idx;
	metal_list_add_tail(&rvdev->reclaimer, &r_desc->node);

	metal_mutex_release(&rdev->lock);

	return RPMSG_SUCCESS;
}

And the rp_hdr->reserved is set to idx in rpmsg_virtio_get_tx_payload_buffer()

What I would like to figure out is whether this fix is for an existing bug or if it is intended to prevent a potential bug. Upon looking into the code, when role == RPMSG_HOST, the index is not used.

In the end, I think that we should set the idx as you propose. However, what I am trying to determine first is whether this fix is for an existing bug or if it is an improvement to the code's robustness."

@CV-Bowen
Copy link
Contributor Author

@arnopo Yes, the index is not used in HOST side and after discussing with @GUIDINGLI, we confirm this commit is just an improvement to code's robustness.

@arnopo
Copy link
Collaborator

arnopo commented Oct 19, 2023

@arnopo Yes, the index is not used in HOST side and after discussing with @GUIDINGLI, we confirm this commit is just an improvement to code's robustness.

Thanks for the confirmation. Please update the commit in consequence, it is not a fix but an improvement

In rpmsg host side, the tx buffer index is not assigned when this buffer
is obtained from the reclaimer list, this commit let
rpmsg_virtio_get_tx_buffer() always get correct idx.

Note: the idx in rpmsg host side is not used, so this commit is just
an improvement and not fix any issue.

Signed-off-by: Guiding Li <[email protected]>
Signed-off-by: Bowen Wang <[email protected]>
@CV-Bowen CV-Bowen changed the title rpmsg: fix rpmsg_virtio_get_tx_buffer() no idx return in host side rpmsg: let rpmsg_virtio_get_tx_buffer() always return idx in host side Oct 19, 2023
@CV-Bowen
Copy link
Contributor Author

@arnopo Done

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

lib/rpmsg/rpmsg_virtio.c Outdated Show resolved Hide resolved
@arnopo
Copy link
Collaborator

arnopo commented Nov 20, 2023

@edmooring, @tnmysh ,

Please, could your review this PR?

Copy link
Collaborator

@tnmysh tnmysh left a comment

Choose a reason for hiding this comment

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

LGTM.

@arnopo arnopo merged commit 79b1a2c into OpenAMP:main Nov 22, 2023
2 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.

4 participants