diff mbox series

[kvm-unit-tests,2/5] x86: nVMX: Pre-check EPT requirement for unrestricted guest

Message ID 20190221022445.3873-3-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series x86: nVMX: Address feedback on EPT series | expand

Commit Message

Sean Christopherson Feb. 21, 2019, 2:24 a.m. UTC
...and abort the test if configuring a dummy EPT fails now that all
users pre-check EPT support.  There are additional checks in the common
EPT setup code, e.g. for EPT memtype compatibility, but the checks in
question should never fail because they query capabilities that KVM
always bundles with EPT, hence the abort.

Cc: Marc Orr <marcorr@google.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 x86/vmx_tests.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Marc Orr Feb. 21, 2019, 7:19 p.m. UTC | #1
On Wed, Feb 20, 2019 at 6:24 PM Sean Christopherson
<sean.j.christopherson@intel.com> wrote:
>
> ...and abort the test if configuring a dummy EPT fails now that all
> users pre-check EPT support.  There are additional checks in the common
> EPT setup code, e.g. for EPT memtype compatibility, but the checks in
> question should never fail because they query capabilities that KVM
> always bundles with EPT, hence the abort.
>
> Cc: Marc Orr <marcorr@google.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  x86/vmx_tests.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
> index 66fde33..bd17088 100644
> --- a/x86/vmx_tests.c
> +++ b/x86/vmx_tests.c
> @@ -1063,19 +1063,20 @@ static int setup_ept(bool enable_ad)
>         return 0;
>  }
>
> -static int enable_ept(void)
> +static void enable_ept(void)
>  {
> -       return setup_eptp(0, false);
> +       if (setup_eptp(0, false))
> +               report_abort("EPT setup unexpectedly failed");
>  }
>
>  static int enable_unrestricted_guest(void)
>  {
>         if (!(ctrl_cpu_rev[0].clr & CPU_SECONDARY) ||
> -           !(ctrl_cpu_rev[1].clr & CPU_URG))
> +           !(ctrl_cpu_rev[1].clr & CPU_URG) ||
> +           !(ctrl_cpu_rev[1].clr & CPU_EPT))
>                 return 1;
>
> -       if (enable_ept())
> -               return 1;
> +       enable_ept();
>
>         vmcs_write(CPU_EXEC_CTRL0, vmcs_read(CPU_EXEC_CTRL0) | CPU_SECONDARY);
>         vmcs_write(CPU_EXEC_CTRL1, vmcs_read(CPU_EXEC_CTRL1) | CPU_URG);
> --
> 2.20.1
>

Reviewed-by: Marc Orr <marcorr@google.com>
diff mbox series

Patch

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 66fde33..bd17088 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -1063,19 +1063,20 @@  static int setup_ept(bool enable_ad)
 	return 0;
 }
 
-static int enable_ept(void)
+static void enable_ept(void)
 {
-	return setup_eptp(0, false);
+	if (setup_eptp(0, false))
+		report_abort("EPT setup unexpectedly failed");
 }
 
 static int enable_unrestricted_guest(void)
 {
 	if (!(ctrl_cpu_rev[0].clr & CPU_SECONDARY) ||
-	    !(ctrl_cpu_rev[1].clr & CPU_URG))
+	    !(ctrl_cpu_rev[1].clr & CPU_URG) ||
+	    !(ctrl_cpu_rev[1].clr & CPU_EPT))
 		return 1;
 
-	if (enable_ept())
-		return 1;
+	enable_ept();
 
 	vmcs_write(CPU_EXEC_CTRL0, vmcs_read(CPU_EXEC_CTRL0) | CPU_SECONDARY);
 	vmcs_write(CPU_EXEC_CTRL1, vmcs_read(CPU_EXEC_CTRL1) | CPU_URG);