Skip to contentSkip to conversation

tests/resource: Fix HVM guest in !SHADOW builds

PATCH Superseded Andrew Cooper 2 participants 3 messages Feb 29, 2024 – Mar 1, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/resource: Fix HVM guest in !SHADOW builds

Right now, test-resource always creates HVM Shadow guests. But if Xen has SHADOW compiled out, running the test yields:

$./test-resource
XENMEM_acquire_resource tests
Test x86 PV
Created d1
Test grant table
Test x86 PVH
Skip: 95 - Operation not supported

and doesn't really test HVM guests, but doesn't fail either.

There's nothing paging-mode-specific about this test, so default to HAP if possible and provide a more specific message if neither HAP or Shadow are available.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 tools/tests/resource/test-resource.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/tests/resource/test-resource.c +25 -0
index 7ae88ea34807..2796053588d3 100644
@@ -20,6 +20,8 @@ static xc_interface *xch;
 static xenforeignmemory_handle *fh;
 static xengnttab_handle *gh;
 
+static xc_physinfo_t physinfo;
+
 static void test_gnttab(uint32_t domid, unsigned int nr_frames,
                         unsigned long gfn)
 {
@@ -172,6 +174,23 @@ static void test_domain_configurations(void)
 
         printf("Test %s\n", t->name);
 
+#if defined(__x86_64__) || defined(__i386__)
+        /*
+         * On x86, use HAP guests if possible, but skip if neither HAP nor
+         * SHADOW is available.
+         */
+        if ( t->create.flags & XEN_DOMCTL_CDF_hvm )
+        {
+            if ( physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hap )
+                t->create.flags |= XEN_DOMCTL_CDF_hap;
+            else if ( !(physinfo.capabilities & XEN_SYSCTL_PHYSCAP_shadow) )
+            {
+                printf("  Skip: Neither HAP or SHADOW available\n");
+                continue;
+            }
+        }
+#endif
+
         rc = xc_domain_create(xch, &domid, &t->create);
         if ( rc )
         {
@@ -214,6 +233,8 @@ static void test_domain_configurations(void)
 
 int main(int argc, char **argv)
 {
+    int rc;
+
     printf("XENMEM_acquire_resource tests\n");
 
     xch = xc_interface_open(NULL, NULL, 0);
@@ -227,6 +248,10 @@ int main(int argc, char **argv)
     if ( !gh )
         err(1, "xengnttab_open");
 
+    rc = xc_physinfo(xch, &physinfo);
+    if ( rc )
+        err(1, "Failed to obtain physinfo");
+
     test_domain_configurations();
 
     return !!nr_failures;

base-commit: 635dd1120a01961a39dce6ad3f09692681379378
prerequisite-patch-id: 1fddefae616fa9a57ddc85bbf770e3c5bdb47b1f
prerequisite-patch-id: 50c4a201d8fa10c1797a1b17f3f2729b5787da84
prerequisite-patch-id: 4b4799fae62b5f41b9b0d2078e8b081605341a0a

Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Andrew Cooper

Right now, test-resource always creates HVM Shadow guests. But if Xen has SHADOW compiled out, running the test yields:

$./test-resource
XENMEM_acquire_resource tests
Test x86 PV
Created d1
Test grant table
Test x86 PVH
Skip: 95 - Operation not supported

Quoted 7 lines

and doesn't really test HVM guests, but doesn't fail either.

There's nothing paging-mode-specific about this test, so default to HAP if possible and provide a more specific message if neither HAP or Shadow are available.

One comment below.

Quoted 30 lines

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 tools/tests/resource/test-resource.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/tests/resource/test-resource.c +7 -0
index 7ae88ea34807..2796053588d3 100644
@@ -20,6 +20,8 @@ static xc_interface *xch;
 static xenforeignmemory_handle *fh;
 static xengnttab_handle *gh;
 
+static xc_physinfo_t physinfo;
+
 static void test_gnttab(uint32_t domid, unsigned int nr_frames,
                         unsigned long gfn)
 {
@@ -172,6 +174,23 @@ static void test_domain_configurations(void)
 
         printf("Test %s\n", t->name);
 
+#if defined(__x86_64__) || defined(__i386__)
+        /*
+         * On x86, use HAP guests if possible, but skip if neither HAP nor
+         * SHADOW is available.
+         */

tools/tests/resource/test-resource.c static void test_domain_configurations(void) · line 191

Quoted 10 lines
tools/tests/resource/test-resource.c +10 -0
+        if ( t->create.flags & XEN_DOMCTL_CDF_hvm )
+        {
+            if ( physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hap )
+                t->create.flags |= XEN_DOMCTL_CDF_hap;
+            else if ( !(physinfo.capabilities & XEN_SYSCTL_PHYSCAP_shadow) )
+            {
+                printf("  Skip: Neither HAP or SHADOW available\n");
+                continue;
+            }
+        }

Provided that you are already checking, might also be worth to keep in mind that at some point we might want to also check for XEN_SYSCTL_PHYSCAP_{hvm,pv} and skip those tests if the requested domain type is not available.

Thanks, Roger.

#2 lore raw
Quoted 59 lines · Roger Pau Monné
Quoted 11 lines · Andrew Cooper

Right now, test-resource always creates HVM Shadow guests. But if Xen has SHADOW compiled out, running the test yields:

$./test-resource
XENMEM_acquire_resource tests
Test x86 PV
Created d1
Test grant table
Test x86 PVH
Skip: 95 - Operation not supported

Quoted 7 lines

and doesn't really test HVM guests, but doesn't fail either.

There's nothing paging-mode-specific about this test, so default to HAP if possible and provide a more specific message if neither HAP or Shadow are available.

One comment below.

Quoted 36 lines

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 tools/tests/resource/test-resource.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/tests/resource/test-resource.c +13 -0
index 7ae88ea34807..2796053588d3 100644
@@ -20,6 +20,8 @@ static xc_interface *xch;
 static xenforeignmemory_handle *fh;
 static xengnttab_handle *gh;
 
+static xc_physinfo_t physinfo;
+
 static void test_gnttab(uint32_t domid, unsigned int nr_frames,
                         unsigned long gfn)
 {
@@ -172,6 +174,23 @@ static void test_domain_configurations(void)
 
         printf("Test %s\n", t->name);
 
+#if defined(__x86_64__) || defined(__i386__)
+        /*
+         * On x86, use HAP guests if possible, but skip if neither HAP nor
+         * SHADOW is available.
+         */
+        if ( t->create.flags & XEN_DOMCTL_CDF_hvm )
+        {
+            if ( physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hap )
+                t->create.flags |= XEN_DOMCTL_CDF_hap;
+            else if ( !(physinfo.capabilities & XEN_SYSCTL_PHYSCAP_shadow) )
+            {
Quoted 8 lines

tools/tests/resource/test-resource.c static void test_domain_configurations(void) · line 191

Quoted 4 lines
tools/tests/resource/test-resource.c +4 -0
+                printf("  Skip: Neither HAP or SHADOW available\n");
+                continue;
+            }
+        }

Provided that you are already checking, might also be worth to keep in mind that at some point we might want to also check for XEN_SYSCTL_PHYSCAP_{hvm,pv} and skip those tests if the requested domain type is not available.

Fair point.  Lemme do a v2.

~Andrew