* [PATCH 0/3] KVM: selftests: Delete three pieces of dead library code
@ 2026-09-18 11:36 Gokul K
2026-09-18 11:36 ` [PATCH 1/3] KVM: selftests: Delete the unused sparsebit copy and count helpers Gokul K
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Gokul K @ 2026-09-18 11:36 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, kvm
Cc: Shuah Khan, linux-kselftest, linux-kernel
Three unused things in the selftest library, found by asking the linker
rather than by reading: build the selftests, then look for global symbols
in lib/ that no object refers to, and check each survivor against the
whole source tree by hand.
1/3 sparsebit_copy() and sparsebit_num_set(), neither called
2/3 the declaration of vcpu_set_cpuid_maxphyaddr(), which has no
definition anywhere
3/3 guest_snprintf(), a varargs wrapper nobody calls
Each is independent and they can be taken in any order.
A note on what is deliberately *not* here, because the same scan turns it
up and the obvious next step is wrong. sparsebit.c still exports nine more
functions that no caller outside the file uses - sparsebit_all_set(),
sparsebit_is_clear(), sparsebit_validate_internal() and friends. They are
not dead: they are called from inside sparsebit.c, mostly from the
assertions in sparsebit_validate_internal() and from asserts in live
functions, so deleting them would not build. Making them static and
dropping their declarations is a defensible follow-up, but it is a change
of intent about what the library exposes rather than a removal of dead
code, so it does not belong in this series.
No functional change intended. Built with and without -Wextra, and a
sample of twelve x86 selftests gives identical results before and after;
kvm_binary_stats_test and the rest still pass. The two that fail here fail
identically without the series, because this host's kernel is older than
the tree.
Gokul K (3):
KVM: selftests: Delete the unused sparsebit copy and count helpers
KVM: selftests: Delete the declaration of vcpu_set_cpuid_maxphyaddr()
KVM: selftests: Delete the unused guest_snprintf()
tools/testing/selftests/kvm/include/sparsebit.h | 2 -
tools/testing/selftests/kvm/include/test_util.h | 1 -
.../testing/selftests/kvm/include/x86/processor.h | 1 -
tools/testing/selftests/kvm/lib/guest_sprintf.c | 12 -----
tools/testing/selftests/kvm/lib/sparsebit.c | 63 +---------------------
5 files changed, 1 insertion(+), 78 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/3] KVM: selftests: Delete the unused sparsebit copy and count helpers 2026-09-18 11:36 [PATCH 0/3] KVM: selftests: Delete three pieces of dead library code Gokul K @ 2026-09-18 11:36 ` 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 2 siblings, 1 reply; 6+ messages in thread From: Gokul K @ 2026-09-18 11:36 UTC (permalink / raw) To: Sean Christopherson, Paolo Bonzini, kvm Cc: Shuah Khan, linux-kselftest, linux-kernel sparsebit_copy() and sparsebit_num_set() have no callers. Nor does the FUZZ harness at the bottom of lib/sparsebit.c, which exercises most of the rest of the API and still builds and links with both removed. sparsebit_copy() was the only non-recursive caller of node_copy_subtree(), which leaves that unreachable too. It is static, so keeping it would trip -Wunused-function; delete it as well. The comment on the num_set member gives sparsebit_num_set() as the reason the count is maintained. The member stays - it is what lets sparsebit_all_set() answer in O(1), and the dump path prints it - so point the comment at what still uses it. No functional change intended. Signed-off-by: Gokul K <gokul02k@gmail.com> --- .../testing/selftests/kvm/include/sparsebit.h | 2 - tools/testing/selftests/kvm/lib/sparsebit.c | 63 +------------------ 2 files changed, 1 insertion(+), 64 deletions(-) diff --git a/tools/testing/selftests/kvm/include/sparsebit.h b/tools/testing/selftests/kvm/include/sparsebit.h index e027e5790946..8a2ab11dae6f 100644 --- a/tools/testing/selftests/kvm/include/sparsebit.h +++ b/tools/testing/selftests/kvm/include/sparsebit.h @@ -30,7 +30,6 @@ typedef u64 sparsebit_num_t; struct sparsebit *sparsebit_alloc(void); void sparsebit_free(struct sparsebit **sbitp); -void sparsebit_copy(struct sparsebit *dstp, const struct sparsebit *src); bool sparsebit_is_set(const struct sparsebit *sbit, sparsebit_idx_t idx); bool sparsebit_is_set_num(const struct sparsebit *sbit, @@ -38,7 +37,6 @@ bool sparsebit_is_set_num(const struct sparsebit *sbit, bool sparsebit_is_clear(const struct sparsebit *sbit, sparsebit_idx_t idx); bool sparsebit_is_clear_num(const struct sparsebit *sbit, sparsebit_idx_t idx, sparsebit_num_t num); -sparsebit_num_t sparsebit_num_set(const struct sparsebit *sbit); bool sparsebit_any_set(const struct sparsebit *sbit); bool sparsebit_any_clear(const struct sparsebit *sbit); bool sparsebit_all_set(const struct sparsebit *sbit); diff --git a/tools/testing/selftests/kvm/lib/sparsebit.c b/tools/testing/selftests/kvm/lib/sparsebit.c index 4d845000de15..8ce230af4f14 100644 --- a/tools/testing/selftests/kvm/lib/sparsebit.c +++ b/tools/testing/selftests/kvm/lib/sparsebit.c @@ -184,8 +184,7 @@ struct sparsebit { /* * A redundant count of the total number of bits set. Used for - * diagnostic purposes and to change the time complexity of - * sparsebit_num_set() from O(n) to O(1). + * diagnostic purposes and to answer sparsebit_all_set() in O(1). * Note: Due to overflow, a value of 0 means none or all set. */ sparsebit_num_t num_set; @@ -269,39 +268,6 @@ static struct node *node_prev(const struct sparsebit *s, struct node *np) } -/* Allocates space to hold a copy of the node sub-tree pointed to by - * subtree and duplicates the bit settings to the newly allocated nodes. - * Returns the newly allocated copy of subtree. - */ -static struct node *node_copy_subtree(const struct node *subtree) -{ - struct node *root; - - /* Duplicate the node at the root of the subtree */ - root = calloc(1, sizeof(*root)); - if (!root) { - perror("calloc"); - abort(); - } - - root->idx = subtree->idx; - root->mask = subtree->mask; - root->num_after = subtree->num_after; - - /* As needed, recursively duplicate the left and right subtrees */ - if (subtree->left) { - root->left = node_copy_subtree(subtree->left); - root->left->parent = root; - } - - if (subtree->right) { - root->right = node_copy_subtree(subtree->right); - root->right->parent = root; - } - - return root; -} - /* Searches for and returns a pointer to the node that describes the setting * of the bit given by idx. A node describes the setting of a bit if its * index is within the bits described by the mask bits or the number of @@ -964,22 +930,6 @@ void sparsebit_free(struct sparsebit **sbitp) *sbitp = NULL; } -/* Makes a copy of the sparsebit array given by s, to the sparsebit - * array given by d. Note, d must have already been allocated via - * sparsebit_alloc(). It can though already have bits set, which - * if different from src will be cleared. - */ -void sparsebit_copy(struct sparsebit *d, const struct sparsebit *s) -{ - /* First clear any bits already set in the destination */ - sparsebit_clear_all(d); - - if (s->root) { - d->root = node_copy_subtree(s->root); - d->num_set = s->num_set; - } -} - /* Returns whether num consecutive bits starting at idx are all set. */ bool sparsebit_is_set_num(const struct sparsebit *s, sparsebit_idx_t idx, sparsebit_num_t num) @@ -1035,17 +985,6 @@ bool sparsebit_is_clear_num(const struct sparsebit *s, return next_set == 0 || next_set - idx >= num; } -/* Returns the total number of bits set. Note: 0 is also returned for - * the case of all bits set. This is because with all bits set, there - * is 1 additional bit set beyond what can be represented in the return - * value. Use sparsebit_any_set(), instead of sparsebit_num_set() > 0, - * to determine if the sparsebit array has any bits set. - */ -sparsebit_num_t sparsebit_num_set(const struct sparsebit *s) -{ - return s->num_set; -} - /* Returns whether any bit is set in the sparsebit array. */ bool sparsebit_any_set(const struct sparsebit *s) { -- 2.54.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] KVM: selftests: Delete the unused sparsebit copy and count helpers 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 0 siblings, 0 replies; 6+ messages in thread From: Sean Christopherson @ 2026-09-18 16:24 UTC (permalink / raw) To: Gokul K; +Cc: Paolo Bonzini, kvm, Shuah Khan, linux-kselftest, linux-kernel On Fri, Sep 18, 2026, Gokul K wrote: > sparsebit_copy() and sparsebit_num_set() have no callers. Nor does the > FUZZ harness at the bottom of lib/sparsebit.c, which exercises most of > the rest of the API and still builds and links with both removed. > > sparsebit_copy() was the only non-recursive caller of > node_copy_subtree(), which leaves that unreachable too. It is static, > so keeping it would trip -Wunused-function; delete it as well. > > The comment on the num_set member gives sparsebit_num_set() as the > reason the count is maintained. The member stays - it is what lets > sparsebit_all_set() answer in O(1), and the dump path prints it - so > point the comment at what still uses it. > > No functional change intended. > > Signed-off-by: Gokul K <gokul02k@gmail.com> > --- > .../testing/selftests/kvm/include/sparsebit.h | 2 - > tools/testing/selftests/kvm/lib/sparsebit.c | 63 +------------------ > 2 files changed, 1 insertion(+), 64 deletions(-) > > diff --git a/tools/testing/selftests/kvm/include/sparsebit.h b/tools/testing/selftests/kvm/include/sparsebit.h > index e027e5790946..8a2ab11dae6f 100644 > --- a/tools/testing/selftests/kvm/include/sparsebit.h > +++ b/tools/testing/selftests/kvm/include/sparsebit.h > @@ -30,7 +30,6 @@ typedef u64 sparsebit_num_t; > > struct sparsebit *sparsebit_alloc(void); > void sparsebit_free(struct sparsebit **sbitp); > -void sparsebit_copy(struct sparsebit *dstp, const struct sparsebit *src); I'm somewhat tempted to keep sparsebit_copy() even though there are no users. In the unlikely scenario someone wanted/needed to make a copy, it seems like a potentially painful waste of time to have to recreate this or hunt down its prior existence. Anyone else have an opinion? ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] KVM: selftests: Delete the declaration of vcpu_set_cpuid_maxphyaddr() 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 11:36 ` Gokul K 2026-09-18 11:36 ` [PATCH 3/3] KVM: selftests: Delete the unused guest_snprintf() Gokul K 2 siblings, 0 replies; 6+ messages in thread From: Gokul K @ 2026-09-18 11:36 UTC (permalink / raw) To: Sean Christopherson, Paolo Bonzini, kvm Cc: Shuah Khan, linux-kselftest, linux-kernel vcpu_set_cpuid_maxphyaddr() is declared in include/x86/processor.h and defined nowhere. The declaration is the only mention of the name in tools/testing/selftests, so nothing has ever been able to call it. No Fixes: tag: a prototype for a function that does not exist cannot have regressed anything, and there is nothing to backport. No functional change intended. Signed-off-by: Gokul K <gokul02k@gmail.com> --- tools/testing/selftests/kvm/include/x86/processor.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/testing/selftests/kvm/include/x86/processor.h index 7579e692bc2b..ffe95ce1ad49 100644 --- a/tools/testing/selftests/kvm/include/x86/processor.h +++ b/tools/testing/selftests/kvm/include/x86/processor.h @@ -1180,7 +1180,6 @@ static inline void vcpu_set_cpuid(struct kvm_vcpu *vcpu) void vcpu_set_cpuid_property(struct kvm_vcpu *vcpu, struct kvm_x86_cpu_property property, u32 value); -void vcpu_set_cpuid_maxphyaddr(struct kvm_vcpu *vcpu, u8 maxphyaddr); void vcpu_clear_cpuid_entry(struct kvm_vcpu *vcpu, u32 function); -- 2.54.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] KVM: selftests: Delete the unused guest_snprintf() 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 11:36 ` [PATCH 2/3] KVM: selftests: Delete the declaration of vcpu_set_cpuid_maxphyaddr() Gokul K @ 2026-09-18 11:36 ` Gokul K 2026-09-18 16:05 ` Sean Christopherson 2 siblings, 1 reply; 6+ messages in thread From: Gokul K @ 2026-09-18 11:36 UTC (permalink / raw) To: Sean Christopherson, Paolo Bonzini, kvm Cc: Shuah Khan, linux-kselftest, linux-kernel 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; -} -- 2.54.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] KVM: selftests: Delete the unused guest_snprintf() 2026-09-18 11:36 ` [PATCH 3/3] KVM: selftests: Delete the unused guest_snprintf() Gokul K @ 2026-09-18 16:05 ` Sean Christopherson 0 siblings, 0 replies; 6+ messages in thread From: Sean Christopherson @ 2026-09-18 16:05 UTC (permalink / raw) To: Gokul K; +Cc: Paolo Bonzini, kvm, Shuah Khan, linux-kselftest, linux-kernel 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 -- ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-09-18 16:24 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 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®