public inbox for linux-kselftest@vger.kernel.org
 help / color / mirror / Atom feed
From: "Nikunj A. Dadhania" <nikunj@amd.com>
To: "Pratik R. Sampat" <pratikrajesh.sampat@amd.com>, kvm@vger.kernel.org
Cc: seanjc@google.com, pbonzini@redhat.com, pgonda@google.com,
	thomas.lendacky@amd.com, michael.roth@amd.com, shuah@kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 4/8] KVM: selftests: Introduce SEV VM type check
Date: Mon, 13 Jan 2025 13:48:43 +0530	[thread overview]
Message-ID: <71ed4121-83dd-4b09-b1a0-1f0654512c2b@amd.com> (raw)
In-Reply-To: <20241114234104.128532-5-pratikrajesh.sampat@amd.com>



On 11/15/2024 5:11 AM, Pratik R. Sampat wrote:
> In preparation for SNP, declutter the vm type check by introducing a
> SEV-SNP VM type check as well a transitive set of helper functions.
> 
> The SNP VM type is the subset of SEV-ES. Similarly, the SEV-ES and SNP
> types are subset of the SEV VM type check.
> 
> Signed-off-by: Pratik R. Sampat <pratikrajesh.sampat@amd.com>
> ---
>  .../testing/selftests/kvm/include/x86_64/sev.h  |  4 ++++
>  .../selftests/kvm/lib/x86_64/processor.c        |  4 ++--
>  tools/testing/selftests/kvm/lib/x86_64/sev.c    | 17 +++++++++++++++++
>  .../selftests/kvm/x86_64/sev_smoke_test.c       |  2 +-
>  4 files changed, 24 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/include/x86_64/sev.h b/tools/testing/selftests/kvm/include/x86_64/sev.h
> index e7df5d0987f6..faed91435963 100644
> --- a/tools/testing/selftests/kvm/include/x86_64/sev.h
> +++ b/tools/testing/selftests/kvm/include/x86_64/sev.h
> @@ -29,6 +29,10 @@ enum sev_guest_state {
>  
>  #define VMGEXIT()		{ __asm__ __volatile__("rep; vmmcall"); }
>  
> +bool is_sev_vm(struct kvm_vm *vm);
> +bool is_sev_es_vm(struct kvm_vm *vm);
> +bool is_sev_snp_vm(struct kvm_vm *vm);
> +
>  void sev_vm_launch(struct kvm_vm *vm, uint32_t policy);
>  void sev_vm_launch_measure(struct kvm_vm *vm, uint8_t *measurement);
>  void sev_vm_launch_finish(struct kvm_vm *vm);
> diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> index 636b29ba8985..13f060748fc2 100644
> --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> @@ -641,7 +641,7 @@ void kvm_arch_vm_post_create(struct kvm_vm *vm)
>  	sync_global_to_guest(vm, host_cpu_is_amd);
>  	sync_global_to_guest(vm, is_forced_emulation_enabled);
>  
> -	if (vm->type == KVM_X86_SEV_VM || vm->type == KVM_X86_SEV_ES_VM) {
> +	if (is_sev_vm(vm)) {
>  		struct kvm_sev_init init = { 0 };
>  
>  		vm_sev_ioctl(vm, KVM_SEV_INIT2, &init);
> @@ -1158,7 +1158,7 @@ void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits)
>  
>  void kvm_init_vm_address_properties(struct kvm_vm *vm)
>  {
> -	if (vm->type == KVM_X86_SEV_VM || vm->type == KVM_X86_SEV_ES_VM) {
> +	if (is_sev_vm(vm)) {
>  		vm->arch.sev_fd = open_sev_dev_path_or_exit();
>  		vm->arch.c_bit = BIT_ULL(this_cpu_property(X86_PROPERTY_SEV_C_BIT));
>  		vm->gpa_tag_mask = vm->arch.c_bit;
> diff --git a/tools/testing/selftests/kvm/lib/x86_64/sev.c b/tools/testing/selftests/kvm/lib/x86_64/sev.c
> index e9535ee20b7f..d6e7a422b69d 100644
> --- a/tools/testing/selftests/kvm/lib/x86_64/sev.c
> +++ b/tools/testing/selftests/kvm/lib/x86_64/sev.c
> @@ -4,6 +4,23 @@
>  
>  #include "sev.h"
>  
> +bool is_sev_snp_vm(struct kvm_vm *vm)
> +{
> +	return vm->type == KVM_X86_SNP_VM;
> +}
> +
> +/* A SNP VM is also a SEV-ES VM */
> +bool is_sev_es_vm(struct kvm_vm *vm)
> +{
> +	return is_sev_snp_vm(vm) || vm->type == KVM_X86_SEV_ES_VM;
> +}
> +
> +/* A SEV-ES and SNP VM is also a SEV VM */
> +bool is_sev_vm(struct kvm_vm *vm)
> +{
> +	return is_sev_snp_vm(vm) || is_sev_es_vm(vm) || vm->type == KVM_X86_SEV_VM;

As is_sev_es_vm() already checks is_sev_snp_vm(), we can drop SNP VM check here, right ?

Regards
Nikunj


  reply	other threads:[~2025-01-13  8:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-14 23:40 [PATCH v4 0/8] Basic SEV-SNP Selftests Pratik R. Sampat
2024-11-14 23:40 ` [PATCH v4 1/8] KVM: SEV: Disable SEV-SNP on FW validation failure Pratik R. Sampat
2025-01-10  5:21   ` [sos-linux-ext-patches] " Nikunj A. Dadhania
2025-01-10 21:50     ` Pratik Rajesh Sampat
2025-01-13  4:10       ` Nikunj A. Dadhania
2024-11-14 23:40 ` [PATCH v4 2/8] KVM: selftests: SEV-SNP test for KVM_SEV_INIT2 Pratik R. Sampat
2025-01-10  5:52   ` [sos-linux-ext-patches] " Nikunj A. Dadhania
2025-01-10  6:07     ` Nikunj A. Dadhania
2025-01-10 21:55     ` Pratik Rajesh Sampat
2024-11-14 23:40 ` [PATCH v4 3/8] KVM: selftests: Add VMGEXIT helper Pratik R. Sampat
2024-11-14 23:41 ` [PATCH v4 4/8] KVM: selftests: Introduce SEV VM type check Pratik R. Sampat
2025-01-13  8:18   ` Nikunj A. Dadhania [this message]
2025-01-13 20:10     ` Pratik Rajesh Sampat
2024-11-14 23:41 ` [PATCH v4 5/8] KVM: selftests: Add library support for interacting with SNP Pratik R. Sampat
2025-01-13  8:32   ` Nikunj A. Dadhania
2025-01-13 20:10     ` Pratik Rajesh Sampat
2024-11-14 23:41 ` [PATCH v4 6/8] KVM: selftests: Force GUEST_MEMFD flag for SNP VM type Pratik R. Sampat
2024-11-14 23:41 ` [PATCH v4 7/8] KVM: selftests: Abstractions for SEV to decouple policy from type Pratik R. Sampat
2024-11-14 23:41 ` [PATCH v4 8/8] KVM: selftests: Add a basic SEV-SNP smoke test Pratik R. Sampat
2024-11-15  6:15 ` [PATCH v4 0/8] Basic SEV-SNP Selftests Aithal, Srikanth
2025-01-07 15:32 ` Pratik Rajesh Sampat

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=71ed4121-83dd-4b09-b1a0-1f0654512c2b@amd.com \
    --to=nikunj@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=pgonda@google.com \
    --cc=pratikrajesh.sampat@amd.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=thomas.lendacky@amd.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