[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 10/11] TESTING dom0


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 22 Sep 2020 19:24:43 +0100
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Tue, 22 Sep 2020 18:34:46 +0000
  • Ironport-sdr: Z8DvEV+6vNjn7RLEMRYOHAc7l24LwDXDKsbrRRhi0mubwKZDtGyT7jT7yMq/bowjp45yGZq+sU bTy14CI8+P08ftLmuCqL9TN4qkCY3PUarm1eKZzUXI0hyM/EwNjh+slc8IgMIi8krkML2CRwtq m5gf8JckQrKJ/LyCQm5sAV/8LisVOoJmGWul76a5kCE363JN4G3vRrLMO3ydG+Da/UMEpoJV5v QGumYmA2y0mUHo94M2XpHKfsW6d4RwoqJBk6c/2UcYt5H6Yu4Ndp67cFKTIa53fmA2p51DbE20 w3o=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Poke xenforeignmemory_map_resource() from userspace.  Confirm that all 40
grant frames can be mapped.

Do not apply.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 tools/misc/Makefile       |   4 ++
 tools/misc/xen-resource.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)
 create mode 100644 tools/misc/xen-resource.c

diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index 7d37f297a9..c1d262c329 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -76,6 +76,10 @@ distclean: clean
 xen-cpuid: xen-cpuid.o
        $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) 
$(APPEND_LDFLAGS)
 
+xen-resource.o: APPEND_CFLAGS += -Wno-declaration-after-statement
+xen-resource: xen-resource.o
+       $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) 
$(LDLIBS_libxenforeignmemory) $(LDLIBS_libxendevicemodel) $(APPEND_LDFLAGS)
+
 xen-hvmctx: xen-hvmctx.o
        $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
diff --git a/tools/misc/xen-resource.c b/tools/misc/xen-resource.c
new file mode 100644
index 0000000000..3c29d43a35
--- /dev/null
+++ b/tools/misc/xen-resource.c
@@ -0,0 +1,106 @@
+#include <err.h>
+#include <error.h>
+#include <errno.h>
+#include <stdio.h>
+#include <sys/mman.h>
+
+#include <xenctrl.h>
+#include <xenforeignmemory.h>
+#include <xendevicemodel.h>
+#include <xen-tools/libs.h>
+
+static xc_interface *xch;
+static xenforeignmemory_handle *fh;
+static xendevicemodel_handle *dh;
+
+static void test(unsigned int domid, unsigned int type, unsigned int id)
+{
+    unsigned long nr = ~0;
+
+    printf("Testing d%u, type %u, id %u\n", domid, type, id);
+
+    int rc = xenforeignmemory_resource_size(fh, domid, type, id, &nr);
+    if ( rc )
+    {
+        printf("  failed %d\n", -errno);
+        return;
+    }
+    else
+        printf("  %lu frames\n", nr);
+
+    printf("  Trying to map\n");
+    void *addr = NULL;
+    xenforeignmemory_resource_handle *res =
+        xenforeignmemory_map_resource(fh, domid, type, id, 0, nr,
+                                      &addr, PROT_READ | PROT_WRITE, 0);
+    if ( !res )
+    {
+        perror("  failed");
+        return;
+    }
+
+    printf("  Success\n");
+    xenforeignmemory_unmap_resource(fh, res);
+}
+
+int main(int argc, char **argv)
+{
+    int rc;
+
+    xch = xc_interface_open(NULL, NULL, 0);
+    fh = xenforeignmemory_open(NULL, 0);
+    dh = xendevicemodel_open(NULL, 0);
+
+    if ( !xch )
+        err(1, "xc_interface_open");
+    if ( !fh )
+        err(1, "xenforeignmemory_open");
+    if ( !dh )
+        err(1, "xendevicemodel_open");
+
+    uint32_t domid = 0;
+    struct xen_domctl_createdomain dom = {
+        .flags = XEN_DOMCTL_CDF_hvm,
+        .max_vcpus = 8,
+        .max_grant_frames = 40,
+
+        .arch = {
+            .emulation_flags = XEN_X86_EMU_LAPIC,
+        },
+    };
+
+    rc = xc_domain_create(xch, &domid, &dom);
+    if ( rc )
+    {
+        perror("xc_domain_create()");
+        goto out;
+    }
+    printf("Created d%u\n", domid);
+
+    ioservid_t id = -1;
+    rc = xendevicemodel_create_ioreq_server(dh, domid, 1, &id);
+    if ( rc )
+    {
+        perror("xendevicemodel_create_ioreq_server()");
+        goto out;
+    }
+    printf("Created ioreq server %u\n", id);
+
+
+    test(domid, XENMEM_resource_ioreq_server, id);
+
+    test(domid, XENMEM_resource_grant_table,
+         XENMEM_resource_grant_table_id_shared);
+    test(domid, XENMEM_resource_grant_table,
+         XENMEM_resource_grant_table_id_status);
+
+    test(domid, 2, 0);
+
+out:
+    if ( id >= 0 )
+        xendevicemodel_destroy_ioreq_server(dh, domid, id);
+    if ( domid )
+        xc_domain_destroy(xch, domid);
+
+    return 0;
+}
-- 
2.11.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.