All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [PATCH v2 10/11] TESTING dom0
Date: Tue, 22 Sep 2020 19:24:43 +0100	[thread overview]
Message-ID: <20200922182444.12350-11-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <20200922182444.12350-1-andrew.cooper3@citrix.com>

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@citrix.com>
---
 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



  parent reply	other threads:[~2020-09-22 18:34 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22 18:24 [PATCH v2 00/11] Multiple fixes to XENMEM_acquire_resource Andrew Cooper
2020-09-22 18:24 ` [PATCH v2 01/11] xen/memory: Introduce CONFIG_ARCH_ACQUIRE_RESOURCE Andrew Cooper
2020-09-22 18:24 ` [PATCH v2 02/11] xen/gnttab: Rework resource acquisition Andrew Cooper
2020-09-24  9:51   ` Paul Durrant
2021-01-11 21:22     ` Andrew Cooper
2021-01-12  8:23       ` Jan Beulich
2021-01-12 20:06         ` Andrew Cooper
2021-01-12  8:29       ` Paul Durrant
2020-09-25 13:17   ` Jan Beulich
2021-01-11 21:22     ` Andrew Cooper
2021-01-12  8:15       ` Jan Beulich
2021-01-12 18:11         ` Andrew Cooper
2020-09-22 18:24 ` [PATCH v2 03/11] xen/memory: Fix compat XENMEM_acquire_resource for size requests Andrew Cooper
2020-09-22 18:24 ` [PATCH v2 04/11] xen/memory: Fix acquire_resource size semantics Andrew Cooper
2020-09-24 10:06   ` Paul Durrant
2020-09-24 10:57     ` Andrew Cooper
2020-09-24 11:04       ` Paul Durrant
2020-09-25 15:56   ` Jan Beulich
2020-09-22 18:24 ` [PATCH v2 05/11] tools/foreignmem: Support querying the size of a resource Andrew Cooper
2021-01-08 17:52   ` Andrew Cooper
2021-01-11 10:50     ` Roger Pau Monné
2021-01-11 15:00       ` Andrew Cooper
2021-01-11 15:26   ` [PATCH v3 " Andrew Cooper
2021-01-11 15:54     ` Roger Pau Monné
2020-09-22 18:24 ` [PATCH v2 06/11] xen/memory: Clarify the XENMEM_acquire_resource ABI description Andrew Cooper
2020-09-24 10:08   ` Paul Durrant
2020-09-22 18:24 ` [PATCH v2 07/11] xen/memory: Improve compat XENMEM_acquire_resource handling Andrew Cooper
2020-09-24 10:16   ` Paul Durrant
2020-09-28  9:09   ` Jan Beulich
2021-01-08 18:57     ` Andrew Cooper
2021-01-11 14:25       ` Jan Beulich
2020-09-22 18:24 ` [PATCH v2 08/11] xen/memory: Indent part of acquire_resource() Andrew Cooper
2020-09-24 10:36   ` Paul Durrant
2020-09-22 18:24 ` [PATCH v2 09/11] xen/memory: Fix mapping grant tables with XENMEM_acquire_resource Andrew Cooper
2020-09-24 10:47   ` Paul Durrant
2021-01-08 19:36     ` Andrew Cooper
2020-09-28  9:37   ` Jan Beulich
2021-01-11 20:05     ` Andrew Cooper
2021-01-11 22:36       ` Andrew Cooper
2021-01-12  8:39       ` Jan Beulich
2020-09-22 18:24 ` Andrew Cooper [this message]
2020-09-22 18:24 ` [PATCH v2 11/11] TESTING XTF Andrew Cooper

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=20200922182444.12350-11-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.