Skip to content

kernel/virtio: avoid zeroing and extra copying the destination buffer#782

Merged
joergroedel merged 1 commit intococonut-svsm:mainfrom
stefano-garzarella:mmio-read-avoid-copy
Sep 10, 2025
Merged

kernel/virtio: avoid zeroing and extra copying the destination buffer#782
joergroedel merged 1 commit intococonut-svsm:mainfrom
stefano-garzarella:mmio-read-avoid-copy

Conversation

@stefano-garzarella
Copy link
Member

While reviewing #775 I figured out that SvsmHal::mmio_read() could be improved a bit.

SvsmHal::mmio_read() currently allocates the destination buffer, zeros it, and then copies its value. Avoid all this by allocating MaybeUninit::<T> on the stack and passing a pointer to SVSM_PLATFORM.mmio_read().

Cascade the changes to the functions to use a pointer, since the destination buffer may be uninitialized.

@joergroedel joergroedel added the in-review PR is under active review and not yet approved label Aug 22, 2025
@joergroedel joergroedel self-requested a review August 22, 2025 10:10
@stefano-garzarella
Copy link
Member Author

@joergroedel done, the results it's much better, thanks for the idea!

I don't like much the MaybeUninit::<T> -> [MaybeUninit<u8>] cast I did. With MaybeUninit::as_bytes_mut() is much cleaner, but it's still unstable.

`SvsmHal::mmio_read()` currently allocates the destination buffer,
zeros it, and then copies its value. Avoid all this by allocating
`MaybeUninit::<T>` on the stack and passing a `[MaybeUninit<u8>]`
reference to `SVSM_PLATFORM.mmio_read()`.

Cascade the changes to the functions to use `[MaybeUninit<u8>]`,
since the destination buffer may be uninitialized.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
@joergroedel joergroedel merged commit 1cb3bfe into coconut-svsm:main Sep 10, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in-review PR is under active review and not yet approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants