linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Peter Gonda <pgonda@google.com>
Cc: kvm@vger.kernel.org, Marc Orr <marcorr@google.com>,
	David Rientjes <rientjes@google.com>,
	Brijesh Singh <brijesh.singh@amd.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH V11 4/5] selftest: KVM: Add open sev dev helper
Date: Fri, 5 Nov 2021 22:47:04 +0000	[thread overview]
Message-ID: <YYW0aPKZLT6FyUnT@google.com> (raw)
In-Reply-To: <20211021174303.385706-5-pgonda@google.com>

On Thu, Oct 21, 2021, Peter Gonda wrote:
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 10a8ed691c66..06a6c04010fb 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -31,6 +31,19 @@ static void *align(void *x, size_t size)
>  	return (void *) (((size_t) x + mask) & ~mask);
>  }
>  
> +int open_path_or_exit(const char *path, int flags)
> +{
> +	int fd;
> +
> +	fd = open(path, flags);
> +	if (fd < 0) {
> +		print_skip("%s not available (errno: %d)", path, errno);

While you're here, can you add the strerror(errno) as well?  There are some other
enhancements I'd like to make as some failure modes are really annoying, e.g. if
the max vCPUs test fails/skips due to ulimits, but printing the human friendly
version is an easy one to pick off.

> +		exit(KSFT_SKIP);
> +	}
> +
> +	return fd;
> +}
> +
>  /*
>   * Open KVM_DEV_PATH if available, otherwise exit the entire program.
>   *
> @@ -42,16 +55,7 @@ static void *align(void *x, size_t size)
>   */
>  static int _open_kvm_dev_path_or_exit(int flags)
>  {
> -	int fd;
> -
> -	fd = open(KVM_DEV_PATH, flags);
> -	if (fd < 0) {
> -		print_skip("%s not available, is KVM loaded? (errno: %d)",
> -			   KVM_DEV_PATH, errno);
> -		exit(KSFT_SKIP);
> -	}
> -
> -	return fd;
> +	return open_path_or_exit(KVM_DEV_PATH, flags);
>  }
>  
>  int open_kvm_dev_path_or_exit(void)
> diff --git a/tools/testing/selftests/kvm/lib/x86_64/svm.c b/tools/testing/selftests/kvm/lib/x86_64/svm.c
> index 2ac98d70d02b..14a8618efa9c 100644
> --- a/tools/testing/selftests/kvm/lib/x86_64/svm.c
> +++ b/tools/testing/selftests/kvm/lib/x86_64/svm.c
> @@ -13,6 +13,8 @@
>  #include "processor.h"
>  #include "svm_util.h"
>  
> +#define SEV_DEV_PATH "/dev/sev"
> +
>  struct gpr64_regs guest_regs;
>  u64 rflags;
>  
> @@ -160,3 +162,14 @@ void nested_svm_check_supported(void)
>  		exit(KSFT_SKIP);
>  	}
>  }
> +
> +/*
> + * Open SEV_DEV_PATH if available, otherwise exit the entire program.
> + *
> + * Return:
> + *   The opened file descriptor of /dev/sev.
> + */
> +int open_sev_dev_path_or_exit(void)
> +{
> +	return open_path_or_exit(SEV_DEV_PATH, 0);
> +}
> -- 
> 2.33.0.1079.g6e70778dc9-goog
> 

  reply	other threads:[~2021-11-05 22:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 17:42 [PATCH 0/5 V11] Add AMD SEV and SEV-ES intra host migration support Peter Gonda
2021-10-21 17:42 ` [PATCH 1/5 V11] KVM: SEV: Refactor out sev_es_state struct Peter Gonda
2021-11-04 20:06   ` Sean Christopherson
2021-10-21 17:43 ` [PATCH V11 2/5] KVM: SEV: Add support for SEV intra host migration Peter Gonda
2021-11-04 22:07   ` Sean Christopherson
2021-11-04 23:04     ` Sean Christopherson
2021-11-09 15:19     ` Peter Gonda
2021-11-11 15:17     ` Paolo Bonzini
2021-11-11 15:18     ` Paolo Bonzini
2021-10-21 17:43 ` [PATCH V11 3/5] KVM: SEV: Add support for SEV-ES " Peter Gonda
2021-11-04 23:33   ` Sean Christopherson
2021-10-21 17:43 ` [PATCH V11 4/5] selftest: KVM: Add open sev dev helper Peter Gonda
2021-11-05 22:47   ` Sean Christopherson [this message]
2021-10-21 17:43 ` [PATCH V11 5/5] selftest: KVM: Add intra host migration tests Peter Gonda

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=YYW0aPKZLT6FyUnT@google.com \
    --to=seanjc@google.com \
    --cc=brijesh.singh@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcorr@google.com \
    --cc=pbonzini@redhat.com \
    --cc=pgonda@google.com \
    --cc=rientjes@google.com \
    --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;
as well as URLs for NNTP newsgroup(s).