diff mbox

[XTF,08/16] vvmx: test vmxon with invalidly wide VMXON region address

Message ID 20161216134348.16236-9-haozhong.zhang@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Haozhong Zhang Dec. 16, 2016, 1:43 p.m. UTC
VMfailInvalid is expected in this test.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
 tests/vvmx/vmxon.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

Comments

Andrew Cooper Dec. 16, 2016, 8:40 p.m. UTC | #1
On 16/12/16 13:43, Haozhong Zhang wrote:
> +static uint8_t get_cpu_paddr_bits(void)
> +{
> +    uint8_t paddr_bits = 36;
> +    uint32_t eax;
> +
> +    eax = cpuid_eax(0x80000000);
> +    if ( (eax >> 16) == 0x8000 && eax >= 0x80000008 )
> +    {
> +        eax = cpuid_eax(0x80000008);
> +        paddr_bits = eax & 0xff;
> +        if ( paddr_bits > 52 )
> +            paddr_bits = 52;
> +    }
> +
> +    return paddr_bits;

This is useful core functionality (and I can't believe I haven't
published a test which needs it yet).

Please extend collect_cpuid() and make maxphysaddr and maxvirtaddr
available globally along with the other vendor/family/feature
information, although I'd drop the clipping at 52 bits.

~Andrew
Haozhong Zhang Dec. 19, 2016, 3:36 a.m. UTC | #2
On 12/16/16 20:40 +0000, Andrew Cooper wrote:
>On 16/12/16 13:43, Haozhong Zhang wrote:
>> +static uint8_t get_cpu_paddr_bits(void)
>> +{
>> +    uint8_t paddr_bits = 36;
>> +    uint32_t eax;
>> +
>> +    eax = cpuid_eax(0x80000000);
>> +    if ( (eax >> 16) == 0x8000 && eax >= 0x80000008 )
>> +    {
>> +        eax = cpuid_eax(0x80000008);
>> +        paddr_bits = eax & 0xff;
>> +        if ( paddr_bits > 52 )
>> +            paddr_bits = 52;
>> +    }
>> +
>> +    return paddr_bits;
>
>This is useful core functionality (and I can't believe I haven't
>published a test which needs it yet).
>
>Please extend collect_cpuid() and make maxphysaddr and maxvirtaddr
>available globally along with the other vendor/family/feature
>information, although I'd drop the clipping at 52 bits.
>

Sure.

Haozhong
diff mbox

Patch

diff --git a/tests/vvmx/vmxon.c b/tests/vvmx/vmxon.c
index ca33b3c..8147679 100644
--- a/tests/vvmx/vmxon.c
+++ b/tests/vvmx/vmxon.c
@@ -53,6 +53,40 @@  static bool test_vmxon_in_user(void)
                               VMXERR_FAULT, EXINFO_SYM(GP, 0), 0);
 }
 
+static uint8_t get_cpu_paddr_bits(void)
+{
+    uint8_t paddr_bits = 36;
+    uint32_t eax;
+
+    eax = cpuid_eax(0x80000000);
+    if ( (eax >> 16) == 0x8000 && eax >= 0x80000008 )
+    {
+        eax = cpuid_eax(0x80000008);
+        paddr_bits = eax & 0xff;
+        if ( paddr_bits > 52 )
+            paddr_bits = 52;
+    }
+
+    return paddr_bits;
+}
+
+/**
+ * vmxon with VMXON region address that expires the maximum physical
+ * address width
+ *
+ * Expect: VMfailInvalid
+ */
+static bool test_vmxon_invalid_paddr_width(void)
+{
+    uint8_t paddr_bits = get_cpu_paddr_bits();
+    uint64_t invalid_vmxon_address = (1UL << paddr_bits);
+    exinfo_t fault;
+    uint8_t ret = vmxon(invalid_vmxon_address, &fault);
+
+    return handle_vmxinsn_err(__func__, ret, fault,
+                              VMXERR_VMFAIL_INVALID, 0, 0);
+}
+
 bool test_vmxon(void)
 {
     if ( !test_vmxon_novmxe() )
@@ -64,6 +98,9 @@  bool test_vmxon(void)
     if ( !test_vmxon_in_user() )
         return false;
 
+    if ( !test_vmxon_invalid_paddr_width() )
+        return false;
+
     return true;
 }