Re: [PATCH v2 4/6] KVM: selftests: Add string formatting options to ucall

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 24, 2023, Aaron Lewis wrote:
> Add more flexibility to guest debugging and testing by adding
> GUEST_PRINTF() and GUEST_ASSERT_FMT() to the ucall framework.
> 
> A buffer to hold the formatted string was added to the ucall struct.
> That allows the guest/host to avoid the problem of passing an
> arbitrary number of parameters between themselves when resolving the
> string.  Instead, the string is resolved in the guest then passed
> back to the host to be logged.
> 
> The formatted buffer is set to 1024 bytes which increases the size
> of the ucall struct.  As a result, this will increase the number of
> pages requested for the guest.
> 
> The buffer size was chosen to accommodate most use cases, and based on
> similar usage.  E.g. printf() uses the same size buffer in
> arch/x86/boot/printf.c.

...
>  #define UCALL_MAX_ARGS 7
> +#define UCALL_BUFFER_LEN 1024
>  
>  struct ucall {
>  	uint64_t cmd;
>  	uint64_t args[UCALL_MAX_ARGS];
> +	char buffer[UCALL_BUFFER_LEN];

...

> diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c
> index 77ada362273d..c09e57c8ef77 100644
> --- a/tools/testing/selftests/kvm/lib/ucall_common.c
> +++ b/tools/testing/selftests/kvm/lib/ucall_common.c
> @@ -55,6 +55,7 @@ static struct ucall *ucall_alloc(void)
>  		if (!test_and_set_bit(i, ucall_pool->in_use)) {
>  			uc = &ucall_pool->ucalls[i];
>  			memset(uc->args, 0, sizeof(uc->args));
> +			memset(uc->buffer, 0, sizeof(uc->buffer));

The use in boot/printf.c isn't a great reference point.  That "allocation" is
on-stack and effectively free, whereas the use here "requires" zeroing the buffer
during allocation.  I usually tell people to not worry about selftests performance,
but zeroing 1KiB on every ucall seems a bit excessive.

However, that's more of an argument to not zero than it is to try and squeak by
with a smaller size.  The guest really should explicitly tell the host how much
of the buffer.  And with that, there should be no need to zero the buffer because
the host isn't relying on the memory being zeroed.

On a somehwat related topic, this patch should also introduce a macro/helper to
retrieve and print the buffer on the backend.  Partly to reduce copy+paste, partly
to make it easier to review (i.e. show the end-to-end), and partly so that the
ucall code can craft a more explicit contract.



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux