Add a second ucall_fmt() function that takes two format strings instead of one. This provides more flexibility because the string format in GUEST_ASSERT_FMT() is no linger limited to only using literals. This provides better consistency between GUEST_PRINTF() and GUEST_ASSERT_FMT() as GUEST_PRINTF() is not limited to only using literals either. Signed-off-by: Aaron Lewis <aaronlewis@xxxxxxxxxx> --- .../selftests/kvm/include/ucall_common.h | 13 +++++----- .../testing/selftests/kvm/lib/ucall_common.c | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h index 7281a6892779..3e8135aaa812 100644 --- a/tools/testing/selftests/kvm/include/ucall_common.h +++ b/tools/testing/selftests/kvm/include/ucall_common.h @@ -36,6 +36,7 @@ void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu); void ucall(uint64_t cmd, int nargs, ...); void ucall_fmt(uint64_t cmd, const char *fmt, ...); +void ucall_fmt2(uint64_t cmd, const char *fmt1, const char *fmt2, ...); uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa); int ucall_nr_pages_required(uint64_t page_size); @@ -61,12 +62,12 @@ enum guest_assert_builtin_args { GUEST_ASSERT_BUILTIN_NARGS }; -#define __GUEST_ASSERT_FMT(_condition, _condstr, _fmt, _args...) \ -do { \ - if (!(_condition)) \ - ucall_fmt(UCALL_ABORT, \ - "Failed guest assert: " _condstr " at %s:%ld\n " _fmt, \ - , __FILE__, __LINE__, ##_args); \ +#define __GUEST_ASSERT_FMT(_condition, _condstr, _fmt, _args...) \ +do { \ + if (!(_condition)) \ + ucall_fmt2(UCALL_ABORT, \ + "Failed guest assert: " _condstr " at %s:%ld\n ",\ + _fmt, __FILE__, __LINE__, ##_args); \ } while (0) #define GUEST_ASSERT_FMT(_condition, _fmt, _args...) \ diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c index c09e57c8ef77..d0f1ad6c0c44 100644 --- a/tools/testing/selftests/kvm/lib/ucall_common.c +++ b/tools/testing/selftests/kvm/lib/ucall_common.c @@ -76,6 +76,30 @@ static void ucall_free(struct ucall *uc) clear_bit(uc - ucall_pool->ucalls, ucall_pool->in_use); } +void ucall_fmt2(uint64_t cmd, const char *fmt1, const char *fmt2, ...) +{ + const int fmt_len = 128; + char fmt[fmt_len]; + struct ucall *uc; + va_list va; + int len; + + len = kvm_snprintf(fmt, fmt_len, "%s%s", fmt1, fmt2); + if (len > fmt_len) + ucall_arch_do_ucall(GUEST_UCALL_FAILED); + + uc = ucall_alloc(); + uc->cmd = cmd; + + va_start(va, fmt2); + kvm_vsnprintf(uc->buffer, UCALL_BUFFER_LEN, fmt, va); + va_end(va); + + ucall_arch_do_ucall((vm_vaddr_t)uc->hva); + + ucall_free(uc); +} + void ucall_fmt(uint64_t cmd, const char *fmt, ...) { struct ucall *uc; -- 2.40.0.634.g4ca3ef3211-goog