Skip to content

Enhance rpmsg buf config - #684

Open
tnmysh wants to merge 1 commit into
OpenAMP:mainfrom
tnmysh:enhance_rpmsg_buf_config
Open

tnmysh wants to merge 1 commit into
OpenAMP:mainfrom
tnmysh:enhance_rpmsg_buf_config

Conversation

@tnmysh

@tnmysh tnmysh commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

@tnmysh

tnmysh commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

@arnopo

we can review this one after the release.

@tnmysh
tnmysh force-pushed the enhance_rpmsg_buf_config branch 2 times, most recently from 7310369 to 3474c42 Compare May 29, 2026 20:12
@tnmysh
tnmysh marked this pull request as ready for review May 29, 2026 20:13
@tnmysh
tnmysh requested a review from wmamills May 29, 2026 20:13
@tnmysh
tnmysh force-pushed the enhance_rpmsg_buf_config branch 2 times, most recently from 6ddcf11 to 7c0b658 Compare May 30, 2026 02:47
Comment thread lib/rpmsg/rpmsg_virtio.c Outdated
return status;

if (features & (1 << VIRTIO_RPMSG_F_BUFSZ))
rvdev->config = *config;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here you should use virtio_read_config to retrieve the config from the transport layer
Did you have a look to @xiaoxiang781216 work in #155 ?
Seems to me the good approach

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@arnopo done in latest push.

@arnopo
arnopo requested a review from edmooring June 2, 2026 09:06
@tnmysh
tnmysh force-pushed the enhance_rpmsg_buf_config branch 3 times, most recently from 8289cfd to a361586 Compare June 16, 2026 15:28

@edmooring edmooring left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to go.

@wmamills
wmamills requested a review from iuliana-prodan June 17, 2026 16:53
Comment thread lib/rpmsg/rpmsg_virtio.c Outdated

if (features & (1 << VIRTIO_RPMSG_F_BUFSZ))
virtio_write_config(rvdev->vdev, 0, (void *)config,
sizeof(*config));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The config could be read by the virtio driver before this code is executed. For instance the Linux probes the rpmsg in parallel of the start of the remoteproc firmware based on the resource table that should contain the config.
For my here we should only read the config if VIRTIO_RPMSG_F_BUFSZ feature bit is set else we should rely on *config.
One question is: should we also mange the config write or should we consider that it is part of the resource table.

I propose to discuss this in next OpenAMP meeting

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

7/1 OpenAMP System Reference call:

  • Arnaud to confirm it is a standard pattern w/ MMIO
  • Tanmay to confirm would work to have read instead of write for current use case & update accordingly.

Allow write only for use case when it is compiled as driver.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Extracted from virtio spec 1 .4:

2.5.2 Device Requirements: Device Configuration Space
The device MUST allow reading of any device-specific configuration field before FEATURES_OK is set by the driver. This includes fields which are conditional on feature bits, as long as those feature bits are offered by the device.
3.2 Device Operation
When operating the device, each field in the device configuration space can be changed by either the driver or the device.

Whenever such a configuration change is triggered by the device, driver is notified. This makes it possible for drivers to cache device configuration, avoiding expensive configuration reads unless notified.

So it seems that having a static configuration as first step is quite simple and reliable

  1. the device provides a static configuration space (in the resource table).
  2. the driver can update it until FEATURES_OK is set
  3. the device read the configuration space when DRIVER_OK is set

*/
METAL_PACKED_BEGIN
struct rpmsg_virtio_config {
/** version of this struct */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This needs an update, right?
Because it doesn't match the Linux v5 header which dropped the reserved fields, so every field after version is now at a different offset.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. same as mentioned in: OpenAMP/openamp-system-reference#106

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Getting the whole picture with the Linux implementation. I wonder if updating this structure would not add confusion and extra management:

  • split_shpool field
  • updating rpmsg_virtio_config could break the API

what about introducing struct rpmsg_virtio_config_space structure?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@arnopo It's better if we introduce new PR for that. This PR is only to modify the default buffer size via vdev config space. So, for now I prefer to keep it as it is.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@arnopo It's better if we introduce new PR for that. This PR is only to modify the default buffer size via vdev config space. So, for now I prefer to keep it as it is.

As this also impacts the API, I would prefer not to implement it in two steps, especially if we introduce it in this release. In its current state, this would likely introduce regressions, for instance in NuttX:
https://github.com/apache/nuttx/blob/master/drivers/rpmsg/rpmsg_virtio_lite.c#L697

Comment thread lib/rpmsg/rpmsg_virtio.c Outdated
*/
size = (int)virtqueue_get_desc_size(rvdev->rvq) -
sizeof(struct rpmsg_hdr);
features = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Redundant, is already zero-initialized at declaration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ack.

Comment thread lib/rpmsg/rpmsg_virtio.c Outdated
return RPMSG_ERR_DEV_STATE;
}

if (features & (1 << VIRTIO_RPMSG_F_BUFSZ)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nitpick: 1U << for feature masks (here and in rpmsg_init_vdev_with_config).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ack.

Comment thread lib/rpmsg/rpmsg_virtio.c Outdated
return status;

if (features & (1 << VIRTIO_RPMSG_F_BUFSZ))
virtio_write_config(rvdev->vdev, 0, (void *)config,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Return value ignored, the same happens for virtio_read_config above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ack, I will fix in next rev.

Comment thread lib/rpmsg/rpmsg_virtio.c Outdated
return status;

if (features & (1 << VIRTIO_RPMSG_F_BUFSZ))
virtio_write_config(rvdev->vdev, 0, (void *)config,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

sizeof(*config) writes the full struct including split_shpool, inconsistent with the advertised size field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ack, I will fix in next rev.

@nathalie-ckc

Copy link
Copy Markdown

2026-07-15 System Reference Call:
Tanmay to address Iulia's comments, but will make update to PR once the Linux kernel side is finalized. Tanmay has sent latest revision in Linux kernel.

@tnmysh
tnmysh force-pushed the enhance_rpmsg_buf_config branch from a361586 to 8211ae2 Compare August 17, 2026 14:17
@nathalie-ckc

Copy link
Copy Markdown

8/26/26 System Reference call:
Tanmay updated based on V7 on Linux side. A few small items to address in Mathieu's most recent feedback. open-amp reviewers can wait until Linux side is complete before reviewing.

@nathalie-ckc

Copy link
Copy Markdown

9/8/26: Mathieu merged the Linux part. Tanmay will rebase, then it will be ready for OpenAMP review

@tnmysh
tnmysh force-pushed the enhance_rpmsg_buf_config branch from 8211ae2 to 9a39a75 Compare September 17, 2026 19:33
@tnmysh

tnmysh commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

This PR is ready for review. @arnopo

Comment thread lib/rpmsg/rpmsg_virtio.c Outdated
if (ret)
return RPMSG_ERR_DEV_STATE;

if (config.size < RPMSG_VIRTIO_CONFIG_SIZE ||

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Check on the config version seems missing here and in rpmsg_virtio_write_config

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree - check version == 1 like linux does and reject sizes <= sizeof(struct rpmsg_hdr)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ack.

Comment thread lib/rpmsg/rpmsg_virtio.c Outdated

if (VIRTIO_ROLE_IS_DRIVER(vdev)) {
if (features & (1U << VIRTIO_RPMSG_F_BUFSZ)) {
status = rpmsg_virtio_write_config(rvdev);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This part seems to me not valid. The driver should only read the config. It must not update it.

it seems that something is also wrong in rproc_virtio_write_config

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this part is redundant. I will remove it.

Comment thread lib/rpmsg/rpmsg_virtio.c Outdated
if (status)
return status;
rdev->support_ns = !!(features & (1 << VIRTIO_RPMSG_F_NS));
rdev->support_ns = !!(features & (1U << VIRTIO_RPMSG_F_NS));

@arnopo arnopo Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please move this in a separate Commit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ack.

uint16_t size;

/** The size of the buffer used to send data from host to remote */
uint32_t h2r_buf_size;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if it would be more obvious to talk about a driver and a device. What about drv2dev_buf_size?

@tnmysh tnmysh Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@arnopo If we want to rename the structures field, can we do it in a different commit?
This name exists before this change, and irrelevant to the functionality being introduced in the PR.

Comment thread lib/rpmsg/rpmsg_virtio.c Outdated
if (ret)
return RPMSG_ERR_DEV_STATE;

if (config.size < RPMSG_VIRTIO_CONFIG_SIZE ||

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree - check version == 1 like linux does and reject sizes <= sizeof(struct rpmsg_hdr)

@tnmysh
tnmysh force-pushed the enhance_rpmsg_buf_config branch from 9a39a75 to c54c7e8 Compare September 24, 2026 20:17
Comment thread lib/rpmsg/rpmsg_virtio.c
rdev->support_ns = !!(features & (1 << VIRTIO_RPMSG_F_NS));

if (VIRTIO_ROLE_IS_DRIVER(vdev)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To remove useless additional blank lines.

*/
METAL_PACKED_BEGIN
struct rpmsg_virtio_config {
/** version of this struct */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Getting the whole picture with the Linux implementation. I wonder if updating this structure would not add confusion and extra management:

  • split_shpool field
  • updating rpmsg_virtio_config could break the API

what about introducing struct rpmsg_virtio_config_space structure?

Comment thread lib/rpmsg/rpmsg_virtio.c
}

if (VIRTIO_ROLE_IS_DEVICE(vdev)) {
if (features & (1U << VIRTIO_RPMSG_F_BUFSZ)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems to me that this commit needs more rework

Legacy code provides struct rpmsg_virtio_config as argument of rpmsg_init_vdev_with_config function. This APi should still work if VIRTIO_RPMSG_F_BUFSZ is not set.

What about following algorithms

  1. For the driver role:
if (features & (1U << VIRTIO_RPMSG_F_BUFSZ))
  get the config from the rpmsg_virtio_config_space  in shared memory
else
  get the config from the rpmsg_virtio_config input argument

Notice that split_shpool should still be get from rpmsg_virtio_config

  1. For the device role:
    Current implementation should work and seems to me more flexible.
	if (VIRTIO_ROLE_IS_DEVICE(rvdev->vdev)) {
		/*
		 * If other core is host then buffers are provided by it,
		 * so get the buffer size from the virtqueue.
		 */
		size = (int)virtqueue_get_desc_size(rvdev->rvq) -
		       sizeof(struct rpmsg_hdr);
	}

@tnmysh tnmysh Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@arnopo, I prefer this algorithm:

For the driver role:

If input param is provided to the API, then use it to override the one in the resource table,
and then use resource table's parameters everywhere.

If the input param is not provided, then assume it is provided by the resource table
and use it directly from there.

Let me know your view.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

your proposal makes sense but will imply more update as the config argument is never null in our API regarding rpmsg_init_vdev function

Introduce new feature bit that allows rpmsg buffer size via virtio
device config space. If the feature is available then, driver will set
single rpmsg buffer size from virtio device config space in the resource
table.

Signed-off-by: Tanmay Shah <tanmay.shah@amd.com>
@tnmysh
tnmysh force-pushed the enhance_rpmsg_buf_config branch from c54c7e8 to 46bfee4 Compare September 29, 2026 20:49
@tnmysh

tnmysh commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

@arnopo addressed all the comments.

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