Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Manali Shukla <manali.shukla@amd.com>
To: Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
	pbonzini@redhat.com, shuah@kernel.org, nikunj@amd.com,
	thomas.lendacky@amd.com, vkuznets@redhat.com, bp@alien8.de,
	ajones@ventanamicro.com
Subject: Re: [PATCH v3 4/5] KVM: selftests: Add an interface to read the data of named vcpu stat
Date: Tue, 22 Oct 2024 11:19:36 +0530	[thread overview]
Message-ID: <9d7c43a6-b385-4ec7-b8bd-5378e43a6aaf@amd.com> (raw)
In-Reply-To: <ZruLwp54itwpCPk-@google.com>

Hi Sean,

Thank you for reviewing my patches. Sorry for the delay in response.

On 8/13/2024 10:07 PM, Sean Christopherson wrote:
> On Tue, May 28, 2024, Manali Shukla wrote:
>> From: Manali Shukla <Manali.Shukla@amd.com>
>>
>> The interface is used to read the data values of a specified vcpu stat
>> from the currenly available binary stats interface.
>>
>> Signed-off-by: Manali Shukla <Manali.Shukla@amd.com>
>> ---
>>  .../kvm/include/kvm_arch_vcpu_states.h        | 49 +++++++++++++++++++
>>  .../testing/selftests/kvm/include/kvm_util.h  | 34 +++++++++++++
>>  tools/testing/selftests/kvm/lib/kvm_util.c    | 32 ++++++++++++
>>  3 files changed, 115 insertions(+)
>>  create mode 100644 tools/testing/selftests/kvm/include/kvm_arch_vcpu_states.h
>>
>> diff --git a/tools/testing/selftests/kvm/include/kvm_arch_vcpu_states.h b/tools/testing/selftests/kvm/include/kvm_arch_vcpu_states.h
>> new file mode 100644
>> index 000000000000..755ff7de53d9
>> --- /dev/null
>> +++ b/tools/testing/selftests/kvm/include/kvm_arch_vcpu_states.h
>> @@ -0,0 +1,49 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +
>> +/*
>> + * Arch-specific stats are added to the kvm_arch_vcpu_states.h. Sequence
>> + * of arch-specific vcpu_stat_type should be same as they are declared in
>> + * arch-specific kvm_vcpu_stat.
>> + */
>> +#ifdef __x86_64__
> 
> This is backwards.  If you want arch specific stats, put it them in an arch specific
> header.
> 
>> +#define KVM_X86_VCPU_STATE(x) KVM_VCPU_STATE(x)
>> +
>> +KVM_X86_VCPU_STATE(PF_TAKEN)
> 
> I'm pretty sure you want KVM_VCPU_STAT, KVM_X86_VCPU_STAT, kvm_arch_vcpu_states.h,
> etc.
> 
>> +KVM_X86_VCPU_STATE(PF_FIXED)
> 
> ...
> 
>> +/*
>> + * Ensure that the sequence of the enum vcpu_stat_types matches the order of
>> + * kvm_vcpu_stats_desc[].  Otherwise, vcpu_get_stat() may return incorrect data
>> + * because __vcpu_get_stat() uses the enum type as an index to get the
>> + * descriptor for a given stat and then uses read_stat_data() to get the stats
>> + * from the descriptor.
> 
> This isn't maintainable.  Unless I'm missing something, the _order_ of KVM's stats
> isn't ABI, and blindly reading an entry and hoping its the right one is doomed to
> fail.
> 
> I don't see any reason whatsoever to diverge from the core functionality of
> __vm_get_stat().  The only difference should be the origin of the stats file and
> header.
> 
> I do see a lot of room for improvement, but that can and should be done for both
> VM and vCPU stats.  E.g. provide an API (and a container/struct?) to get a direct
> pointer to stat so that selftests don't have to walk all descriptors when they're
> reading the same stat over and over.
> 
> And to detect typos at compile time, {vcpu,vm}_get_stat() could either play macro
> games or use enums and array to detect usage of a stat that doesn't exist.  E.g.
> 
> static inline uint64_t vm_get_stat(struct kvm_vm *vm, int stat)
> {
> 	uint64_t data;
> 
> 	__vm_get_stat(vm, kvm_vm_stats[stat], &data, 1);
> 	return data;
> }
> 
> or 
> 
> #define vm_get_stat(vm, stat)			\
> ({						\
> 	uin64_t __data;				\
> 						\
> 	<concatenation trickery to trigger compiler error if the stat doesn't exit>
> 	__vm_get_stat(vm, #stat, &data, 1);	\
> 	data;					\
> })
> 
> I'd probably vote for macro games, e.g. so that it's all but impossible to pass
> a per-VM stat into vcpu_get_stat(), and vice versa.

All the review comments from this patch are taken care in [1].

[1] https://lore.kernel.org/kvm/20241021062226.108657-1-manali.shukla@amd.com/T/#t

- Manali

  reply	other threads:[~2024-10-22  5:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-28  4:19 [PATCH v3 0/5] Add support for the Idle HLT intercept feature Manali Shukla
2024-05-28  4:19 ` [PATCH v3 1/5] x86/cpufeatures: Add CPUID feature bit for Idle HLT intercept Manali Shukla
2024-05-28  7:42   ` Borislav Petkov
2024-05-28  4:19 ` [PATCH v3 2/5] KVM: SVM: Add Idle HLT intercept support Manali Shukla
2024-05-28  4:19 ` [PATCH v3 3/5] KVM: selftests: Add safe_halt() and cli() helpers to common code Manali Shukla
2024-05-28  4:19 ` [PATCH v3 4/5] KVM: selftests: Add an interface to read the data of named vcpu stat Manali Shukla
2024-08-13 16:37   ` Sean Christopherson
2024-10-22  5:49     ` Manali Shukla [this message]
2024-05-28  4:19 ` [PATCH v3 5/5] KVM: selftests: KVM: SVM: Add Idle HLT intercept test Manali Shukla
2024-05-28  7:46   ` Chao Gao
2024-05-30 13:19     ` Manali Shukla
2024-05-31  6:49       ` Chao Gao
2024-06-19 17:09         ` Manali Shukla
2024-08-13 15:38         ` Sean Christopherson
2024-08-13 16:03           ` Sean Christopherson
2024-05-28 10:22 ` [PATCH v3 0/5] Add support for the Idle HLT intercept feature Paolo Bonzini
2024-06-04  0:47   ` Sean Christopherson
2024-06-04 13:21     ` Manali Shukla
2024-06-04 12:23   ` Manali Shukla
2024-08-13 16:19     ` Sean Christopherson
2024-10-22 10:35       ` Manali Shukla

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=9d7c43a6-b385-4ec7-b8bd-5378e43a6aaf@amd.com \
    --to=manali.shukla@amd.com \
    --cc=ajones@ventanamicro.com \
    --cc=bp@alien8.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=nikunj@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=thomas.lendacky@amd.com \
    --cc=vkuznets@redhat.com \
    /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