mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Gokul K <gokul02k@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, Shuah Khan <shuah@kernel.org>,
	 linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] KVM: selftests: Delete the unused guest_snprintf()
Date: Fri, 18 Sep 2026 09:05:18 -0700	[thread overview]
Message-ID: <aq1hPuxq2yIeflyH@google.com> (raw)
In-Reply-To: <20260918113631.634233-4-gokul02k@gmail.com>

On Fri, Sep 18, 2026, Gokul K wrote:
> guest_snprintf() is a varargs wrapper around guest_vsnprintf() that nothing
> calls. Its declaration in test_util.h and its definition in
> lib/guest_sprintf.c are the only two mentions anywhere under
> tools/testing/selftests.
> 
> The rest of the family is alive: guest_vsnprintf() does the work and
> ucall_common.c calls it, so this deletes the wrapper and nothing else.
> 
> No functional change intended.
> 
> Signed-off-by: Gokul K <gokul02k@gmail.com>
> ---
>  tools/testing/selftests/kvm/include/test_util.h |  1 -
>  tools/testing/selftests/kvm/lib/guest_sprintf.c | 12 ------------
>  2 files changed, 13 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
> index a6a3e1657895..fbdf0e0c15d1 100644
> --- a/tools/testing/selftests/kvm/include/test_util.h
> +++ b/tools/testing/selftests/kvm/include/test_util.h
> @@ -238,7 +238,6 @@ static inline u32 atoi_non_negative(const char *name, const char *num_str)
>  }
>  
>  int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args);
> -__printf(3, 4) int guest_snprintf(char *buf, int n, const char *fmt, ...);
>  
>  char *strdup_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2), nonnull(1)));
>  
> diff --git a/tools/testing/selftests/kvm/lib/guest_sprintf.c b/tools/testing/selftests/kvm/lib/guest_sprintf.c
> index 7a33965349a7..6caebb456f3d 100644
> --- a/tools/testing/selftests/kvm/lib/guest_sprintf.c
> +++ b/tools/testing/selftests/kvm/lib/guest_sprintf.c
> @@ -300,15 +300,3 @@ int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args)
>  	*str = '\0';
>  	return str - buf;
>  }
> -
> -int guest_snprintf(char *buf, int n, const char *fmt, ...)
> -{
> -	va_list va;
> -	int len;
> -
> -	va_start(va, fmt);
> -	len = guest_vsnprintf(buf, n, fmt, va);
> -	va_end(va);
> -
> -	return len;
> -}

Hmm, I would rather turn guest_snprintf() into a macro so that it can be used in
variadic functions.  I can't think of any reason why this wouldn't work (and
emperically, guest printing works as expected).

---

From: Sean Christopherson <seanjc@google.com>
Date: Fri, 18 Sep 2026 08:57:37 -0700
Subject: [PATCH] KVM: selftests: Make guest_snprintf() a macro and use it as
 appropriate

Turn guest_snprintf() into a macro so that it can be used by variadic
functions, and use it in the ucall APIs instead of open coding the VA goo.

Reported-by: Gokul K <gokul02k@gmail.com>
Closes: https://lore.kernel.org/all/20260918113631.634233-4-gokul02k@gmail.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 tools/testing/selftests/kvm/include/test_util.h | 12 +++++++++++-
 tools/testing/selftests/kvm/lib/guest_sprintf.c | 12 ------------
 tools/testing/selftests/kvm/lib/ucall_common.c  | 10 ++--------
 3 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
index a6a3e1657895..817d4d5ca7cc 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -238,7 +238,17 @@ static inline u32 atoi_non_negative(const char *name, const char *num_str)
 }
 
 int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args);
-__printf(3, 4) int guest_snprintf(char *buf, int n, const char *fmt, ...);
+
+#define guest_snprintf(__buf, __n, __fmt)		\
+({							\
+	va_list va;					\
+	int len;					\
+							\
+	va_start(va, __fmt);				\
+	len = guest_vsnprintf(__buf, __n, __fmt, va);	\
+	va_end(va);					\
+	len;						\
+})
 
 char *strdup_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2), nonnull(1)));
 
diff --git a/tools/testing/selftests/kvm/lib/guest_sprintf.c b/tools/testing/selftests/kvm/lib/guest_sprintf.c
index 7a33965349a7..6caebb456f3d 100644
--- a/tools/testing/selftests/kvm/lib/guest_sprintf.c
+++ b/tools/testing/selftests/kvm/lib/guest_sprintf.c
@@ -300,15 +300,3 @@ int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args)
 	*str = '\0';
 	return str - buf;
 }
-
-int guest_snprintf(char *buf, int n, const char *fmt, ...)
-{
-	va_list va;
-	int len;
-
-	va_start(va, fmt);
-	len = guest_vsnprintf(buf, n, fmt, va);
-	va_end(va);
-
-	return len;
-}
diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c
index 029ce21f9f2f..e9df71197367 100644
--- a/tools/testing/selftests/kvm/lib/ucall_common.c
+++ b/tools/testing/selftests/kvm/lib/ucall_common.c
@@ -83,7 +83,6 @@ void ucall_assert(u64 cmd, const char *exp, const char *file,
 		  unsigned int line, const char *fmt, ...)
 {
 	struct ucall *uc;
-	va_list va;
 
 	uc = ucall_alloc();
 	uc->cmd = cmd;
@@ -92,9 +91,7 @@ void ucall_assert(u64 cmd, const char *exp, const char *file,
 	WRITE_ONCE(uc->args[GUEST_FILE], (u64)(file));
 	WRITE_ONCE(uc->args[GUEST_LINE], line);
 
-	va_start(va, fmt);
-	guest_vsnprintf(uc->buffer, UCALL_BUFFER_LEN, fmt, va);
-	va_end(va);
+	guest_snprintf(uc->buffer, UCALL_BUFFER_LEN, fmt);
 
 	ucall_arch_do_ucall((gva_t)uc->hva);
 
@@ -104,14 +101,11 @@ void ucall_assert(u64 cmd, const char *exp, const char *file,
 void ucall_fmt(u64 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);
+	guest_snprintf(uc->buffer, UCALL_BUFFER_LEN, fmt);
 
 	ucall_arch_do_ucall((gva_t)uc->hva);
 

base-commit: 70c944caf570fda2d79baa71435589a8db39f048
-- 


      reply	other threads:[~2026-09-18 16:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 11:36 [PATCH 0/3] KVM: selftests: Delete three pieces of dead library code Gokul K
2026-09-18 11:36 ` [PATCH 1/3] KVM: selftests: Delete the unused sparsebit copy and count helpers Gokul K
2026-09-18 16:24   ` Sean Christopherson
2026-09-18 11:36 ` [PATCH 2/3] KVM: selftests: Delete the declaration of vcpu_set_cpuid_maxphyaddr() Gokul K
2026-09-18 11:36 ` [PATCH 3/3] KVM: selftests: Delete the unused guest_snprintf() Gokul K
2026-09-18 16:05   ` Sean Christopherson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aq1hPuxq2yIeflyH@google.com \
    --to=seanjc@google.com \
    --cc=gokul02k@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®