From patchwork Sat Jul 29 00:36:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13332799 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75DB2EB64DD for ; Sat, 29 Jul 2023 00:37:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zqh/Om6sfa4evVifZm4EM8985/ButMWXaT2pw5B0/Z8=; b=ppqeUAD/rbnn88 EqQEL7YPZelYjMitIxvGagwnmnYqFEpeOD+tGBiRpASAzNyoDyAtK9omepUJiauKHY4f0NR8St7uR n5Bktoq91C2Yf+kzWM1dUPTbu8Ca3e8LzxmXjJxFdUiLVXjZM+ZSDC+oVXIsmDazDCWJyVt1IxXM9 miO3FVOQSHyRZn0rOJ7VFCOl8/c6ok+vyCqsI9k4oxVBqZwzK0sTGzidABYZyb7j+7UmN/4sdb7NV YgHcrNxJf/9FP+Ea2ynVLaQUIyZqRcn6esYpk7n+NTYW8fLk4c8g5wtURT4egKUX4k562163q3GkK pW68fnRnFrkVyC1gwFMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qPXxF-005ci0-2K; Sat, 29 Jul 2023 00:37:09 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qPXx6-005cdG-20 for linux-arm-kernel@lists.infradead.org; Sat, 29 Jul 2023 00:37:01 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1bb982d2603so24254455ad.3 for ; Fri, 28 Jul 2023 17:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690591019; x=1691195819; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=ELXU1ozQzdRVu6Pw/o2mcwSfwjzxGjCFC9TkVEz9ZVQ=; b=JXtcg+1ByHrhsMnwuvWSktPaXMMguvcz07wHpELDSVv6jhZ3yrEl0JvsbHqBi5Lg2x OmX5Eimu/ODFnq3VaAjn8vXO1K17rz8y6EpesxllWzQRPUfsavJkfM4At0ImL4pderV8 fvgM9Bge1BI96MVbtQDXU+64v48qE3nq1HyrYE9zFRgPRHo+Wg2XKMo2Sc5iGJCqFUhY FPfQU4uIVpdGn2QFHpgCsDRaEnqFriANA72+NhczhR8B6xGQYtfwAurIWtQuSJ8qMWVA Ml4BO52nX87ezdWgvfx/qbYHGyhUaBoVsxUYpnpeEXRxWOxYM7y18KJ85RhTqqTsk3lN JNRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690591019; x=1691195819; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ELXU1ozQzdRVu6Pw/o2mcwSfwjzxGjCFC9TkVEz9ZVQ=; b=juBa3EoIZiff8bkbDgVuxk5IYG1lPZZSLAO5CppO6akaqfQGeBxlUJ3jCYX8yUx5aC yzoiuzW9KdI0gA+mV1UkIHUeb9lmcEaHEbMpSMm0v/+E1qiHEAjA2JmjEJvtAosniadD zTzAnF86vCGkfXs1YDHNv1Wcl0z9Bt8ZdL1e4mf7J5J0pIGhHJmq2Ssp4HTw3FNBCaJL WVVRrD45GPAtalq8orKnbpyClgqfdoHntHMo3DKD7qMeTPKwGETjul0lYsXMHjxs+W+L DffU0AeUP/Q2ZNMoS8XLLE4RD7QjNfNfojz1iG9O34smxsF0TbstbDyfQvn8NsAIlqao ZmCQ== X-Gm-Message-State: ABy/qLZa1B7otJMUL2pL5yegrq/qhywF6cGaRwiJoYV5wXK0gRZExRos 8YG6g9xw8vayTDHWLUMd1HKh73Vy2g0= X-Google-Smtp-Source: APBJJlFaQWpQ9EmvDFhoqjrlvd9ghhe4hfSspLAxYVt7vmgNKcaTBWdjzzZ7FvjaiMwdSLF+VQ/4xTSUS1M= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:fa0d:b0:1bb:a13a:c21e with SMTP id la13-20020a170902fa0d00b001bba13ac21emr11796plb.10.1690591019608; Fri, 28 Jul 2023 17:36:59 -0700 (PDT) Date: Fri, 28 Jul 2023 17:36:16 -0700 In-Reply-To: <20230729003643.1053367-1-seanjc@google.com> Mime-Version: 1.0 References: <20230729003643.1053367-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230729003643.1053367-8-seanjc@google.com> Subject: [PATCH v4 07/34] KVM: selftests: Add string formatting options to ucall From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Christian Borntraeger , Janosch Frank , Claudio Imbrenda Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , Thomas Huth , " =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= " , Aaron Lewis X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230728_173700_658843_BAD7DC91 X-CRM114-Status: GOOD ( 13.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Aaron Lewis Add more flexibility to guest debugging and testing by adding GUEST_PRINTF() and GUEST_ASSERT_FMT() to the ucall framework. Add a sized buffer to the ucall structure to hold the formatted string, i.e. to allow the guest to easily resolve the string, and thus avoid the ugly pattern of the host side having to make assumptions about the desired format, as well as having to pass around a large number of parameters. 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. And 1KiB ought to be enough for anybody. Signed-off-by: Aaron Lewis [sean: massage changelog, wrap macro param in ()] Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/ucall_common.h | 7 +++++++ tools/testing/selftests/kvm/lib/ucall_common.c | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h index bcbb362aa77f..b5548aeba9f0 100644 --- a/tools/testing/selftests/kvm/include/ucall_common.h +++ b/tools/testing/selftests/kvm/include/ucall_common.h @@ -13,15 +13,18 @@ enum { UCALL_NONE, UCALL_SYNC, UCALL_ABORT, + UCALL_PRINTF, UCALL_DONE, UCALL_UNHANDLED, }; #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]; /* Host virtual address of this struct. */ struct ucall *hva; @@ -32,6 +35,7 @@ void ucall_arch_do_ucall(vm_vaddr_t uc); 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, ...); 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); @@ -47,8 +51,11 @@ int ucall_nr_pages_required(uint64_t page_size); #define GUEST_SYNC_ARGS(stage, arg1, arg2, arg3, arg4) \ ucall(UCALL_SYNC, 6, "hello", stage, arg1, arg2, arg3, arg4) #define GUEST_SYNC(stage) ucall(UCALL_SYNC, 2, "hello", stage) +#define GUEST_PRINTF(_fmt, _args...) ucall_fmt(UCALL_PRINTF, _fmt, ##_args) #define GUEST_DONE() ucall(UCALL_DONE, 0) +#define REPORT_GUEST_PRINTF(ucall) pr_info("%s", (ucall).buffer) + enum guest_assert_builtin_args { GUEST_ERROR_STRING, GUEST_FILE, diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c index 77ada362273d..b507db91139b 100644 --- a/tools/testing/selftests/kvm/lib/ucall_common.c +++ b/tools/testing/selftests/kvm/lib/ucall_common.c @@ -75,6 +75,23 @@ static void ucall_free(struct ucall *uc) clear_bit(uc - ucall_pool->ucalls, ucall_pool->in_use); } +void ucall_fmt(uint64_t cmd, const char *fmt, ...) +{ + struct ucall *uc; + va_list va; + + uc = ucall_alloc(); + uc->cmd = cmd; + + va_start(va, fmt); + guest_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(uint64_t cmd, int nargs, ...) { struct ucall *uc;