All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: peter.maydell@linaro.org, stefanha@gmail.com
Cc: sstabellini@kernel.org, stefanha@redhat.com,
	anthony.perard@citrix.com, xen-devel@lists.xenproject.org,
	qemu-devel@nongnu.org, Paul Durrant <paul.durrant@citrix.com>
Subject: [Qemu-devel] [PULL 11/15] xen_backend: add an emulation of grant copy
Date: Mon, 21 May 2018 12:35:00 -0700	[thread overview]
Message-ID: <1526931304-7289-11-git-send-email-sstabellini@kernel.org> (raw)
In-Reply-To: <alpine.DEB.2.10.1805211229070.4520@sstabellini-ThinkPad-X260>

From: Paul Durrant <paul.durrant@citrix.com>

Not all Xen environments support the xengnttab_grant_copy() operation.
E.g. where the OS is FreeBSD or Xen is older than 4.8.0.

This patch introduces an emulation of that operation using
xengnttab_map_domain_grant_refs() and memcpy() for those environments.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
---
 hw/xen/xen_backend.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index 50412d6..3c3fc2c 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -146,6 +146,55 @@ void xen_be_unmap_grant_refs(struct XenDevice *xendev, void *ptr,
     }
 }
 
+static int compat_copy_grant_refs(struct XenDevice *xendev,
+                                  bool to_domain,
+                                  XenGrantCopySegment segs[],
+                                  unsigned int nr_segs)
+{
+    uint32_t *refs = g_new(uint32_t, nr_segs);
+    int prot = to_domain ? PROT_WRITE : PROT_READ;
+    void *pages;
+    unsigned int i;
+
+    for (i = 0; i < nr_segs; i++) {
+        XenGrantCopySegment *seg = &segs[i];
+
+        refs[i] = to_domain ?
+            seg->dest.foreign.ref : seg->source.foreign.ref;
+    }
+
+    pages = xengnttab_map_domain_grant_refs(xendev->gnttabdev, nr_segs,
+                                            xen_domid, refs, prot);
+    if (!pages) {
+        xen_pv_printf(xendev, 0,
+                      "xengnttab_map_domain_grant_refs failed: %s\n",
+                      strerror(errno));
+        g_free(refs);
+        return -1;
+    }
+
+    for (i = 0; i < nr_segs; i++) {
+        XenGrantCopySegment *seg = &segs[i];
+        void *page = pages + (i * XC_PAGE_SIZE);
+
+        if (to_domain) {
+            memcpy(page + seg->dest.foreign.offset, seg->source.virt,
+                   seg->len);
+        } else {
+            memcpy(seg->dest.virt, page + seg->source.foreign.offset,
+                   seg->len);
+        }
+    }
+
+    if (xengnttab_unmap(xendev->gnttabdev, pages, nr_segs)) {
+        xen_pv_printf(xendev, 0, "xengnttab_unmap failed: %s\n",
+                      strerror(errno));
+    }
+
+    g_free(refs);
+    return 0;
+}
+
 int xen_be_copy_grant_refs(struct XenDevice *xendev,
                            bool to_domain,
                            XenGrantCopySegment segs[],
@@ -157,6 +206,10 @@ int xen_be_copy_grant_refs(struct XenDevice *xendev,
 
     assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV);
 
+    if (!xen_feature_grant_copy) {
+        return compat_copy_grant_refs(xendev, to_domain, segs, nr_segs);
+    }
+
     xengnttab_segs = g_new0(xengnttab_grant_copy_segment_t, nr_segs);
 
     for (i = 0; i < nr_segs; i++) {
-- 
1.9.1

WARNING: multiple messages have this Message-ID (diff)
From: Stefano Stabellini <sstabellini@kernel.org>
To: peter.maydell@linaro.org, stefanha@gmail.com
Cc: sstabellini@kernel.org, qemu-devel@nongnu.org,
	Paul Durrant <paul.durrant@citrix.com>,
	stefanha@redhat.com, anthony.perard@citrix.com,
	xen-devel@lists.xenproject.org
Subject: [PULL 11/15] xen_backend: add an emulation of grant copy
Date: Mon, 21 May 2018 12:35:00 -0700	[thread overview]
Message-ID: <1526931304-7289-11-git-send-email-sstabellini@kernel.org> (raw)
In-Reply-To: <alpine.DEB.2.10.1805211229070.4520@sstabellini-ThinkPad-X260>

From: Paul Durrant <paul.durrant@citrix.com>

Not all Xen environments support the xengnttab_grant_copy() operation.
E.g. where the OS is FreeBSD or Xen is older than 4.8.0.

This patch introduces an emulation of that operation using
xengnttab_map_domain_grant_refs() and memcpy() for those environments.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
---
 hw/xen/xen_backend.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index 50412d6..3c3fc2c 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -146,6 +146,55 @@ void xen_be_unmap_grant_refs(struct XenDevice *xendev, void *ptr,
     }
 }
 
+static int compat_copy_grant_refs(struct XenDevice *xendev,
+                                  bool to_domain,
+                                  XenGrantCopySegment segs[],
+                                  unsigned int nr_segs)
+{
+    uint32_t *refs = g_new(uint32_t, nr_segs);
+    int prot = to_domain ? PROT_WRITE : PROT_READ;
+    void *pages;
+    unsigned int i;
+
+    for (i = 0; i < nr_segs; i++) {
+        XenGrantCopySegment *seg = &segs[i];
+
+        refs[i] = to_domain ?
+            seg->dest.foreign.ref : seg->source.foreign.ref;
+    }
+
+    pages = xengnttab_map_domain_grant_refs(xendev->gnttabdev, nr_segs,
+                                            xen_domid, refs, prot);
+    if (!pages) {
+        xen_pv_printf(xendev, 0,
+                      "xengnttab_map_domain_grant_refs failed: %s\n",
+                      strerror(errno));
+        g_free(refs);
+        return -1;
+    }
+
+    for (i = 0; i < nr_segs; i++) {
+        XenGrantCopySegment *seg = &segs[i];
+        void *page = pages + (i * XC_PAGE_SIZE);
+
+        if (to_domain) {
+            memcpy(page + seg->dest.foreign.offset, seg->source.virt,
+                   seg->len);
+        } else {
+            memcpy(seg->dest.virt, page + seg->source.foreign.offset,
+                   seg->len);
+        }
+    }
+
+    if (xengnttab_unmap(xendev->gnttabdev, pages, nr_segs)) {
+        xen_pv_printf(xendev, 0, "xengnttab_unmap failed: %s\n",
+                      strerror(errno));
+    }
+
+    g_free(refs);
+    return 0;
+}
+
 int xen_be_copy_grant_refs(struct XenDevice *xendev,
                            bool to_domain,
                            XenGrantCopySegment segs[],
@@ -157,6 +206,10 @@ int xen_be_copy_grant_refs(struct XenDevice *xendev,
 
     assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV);
 
+    if (!xen_feature_grant_copy) {
+        return compat_copy_grant_refs(xendev, to_domain, segs, nr_segs);
+    }
+
     xengnttab_segs = g_new0(xengnttab_grant_copy_segment_t, nr_segs);
 
     for (i = 0; i < nr_segs; i++) {
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-05-21 19:35 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-21 19:34 [Qemu-devel] [PULL 00/15] xen-20180521-tag Stefano Stabellini
2018-05-21 19:34 ` Stefano Stabellini
2018-05-21 19:34 ` [Qemu-devel] [PULL 01/15] xen-pvdevice: Introduce a simplistic xen-pvdevice save state Stefano Stabellini
2018-05-21 19:34   ` Stefano Stabellini
2018-05-21 19:34 ` [Qemu-devel] [PULL 02/15] xen/pt: use address_space_memory object for memory region hooks Stefano Stabellini
2018-05-21 19:34   ` Stefano Stabellini
2018-05-21 19:34 ` [Qemu-devel] [PULL 03/15] configure: Add explanation for --enable-xen-pci-passthrough Stefano Stabellini
2018-05-21 19:34   ` Stefano Stabellini
2018-05-21 19:34 ` [Qemu-devel] [PULL 04/15] xen_pt: Present the size of 64 bit BARs correctly Stefano Stabellini
2018-05-21 19:34   ` Stefano Stabellini
2018-05-21 19:34 ` [Qemu-devel] [PULL 05/15] xen-hvm: create separate function for ioreq server initialization Stefano Stabellini
2018-05-21 19:34   ` Stefano Stabellini
2018-05-21 19:34 ` [Qemu-devel] [PULL 06/15] All the xen stable APIs define handle types of the form: Stefano Stabellini
2018-05-21 19:34   ` Stefano Stabellini
2018-05-21 19:34 ` [Qemu-devel] [PULL 07/15] xen: add a meaningful declaration of grant_copy_segment into xen_common.h Stefano Stabellini
2018-05-21 19:34   ` Stefano Stabellini
2018-05-21 19:34 ` [Qemu-devel] [PULL 08/15] xen_backend: add grant table helpers Stefano Stabellini
2018-05-21 19:34   ` Stefano Stabellini
2018-05-21 19:34 ` [Qemu-devel] [PULL 09/15] xen_disk: remove open-coded use of libxengnttab Stefano Stabellini
2018-05-21 19:34   ` Stefano Stabellini
2018-05-21 19:34 ` [Qemu-devel] [PULL 10/15] xen: remove other " Stefano Stabellini
2018-05-21 19:34   ` Stefano Stabellini
2018-05-21 19:35 ` Stefano Stabellini [this message]
2018-05-21 19:35   ` [PULL 11/15] xen_backend: add an emulation of grant copy Stefano Stabellini
2018-05-21 19:35 ` [Qemu-devel] [PULL 12/15] xen_disk: remove use of grant map/unmap Stefano Stabellini
2018-05-21 19:35   ` Stefano Stabellini
2018-05-21 19:35 ` [Qemu-devel] [PULL 13/15] xen_backend: make the xen_feature_grant_copy flag private Stefano Stabellini
2018-05-21 19:35   ` Stefano Stabellini
2018-05-21 19:35 ` [Qemu-devel] [PULL 14/15] xen_disk: use a single entry iovec Stefano Stabellini
2018-05-21 19:35   ` Stefano Stabellini
2018-05-21 19:35 ` [Qemu-devel] [PULL 15/15] xen_disk: be consistent with use of xendev and blkdev->xendev Stefano Stabellini
2018-05-21 19:35   ` Stefano Stabellini
2018-05-21 19:57 ` [Qemu-devel] [PULL 00/15] xen-20180521-tag no-reply
2018-05-21 19:57   ` no-reply
2018-05-22 10:11 ` Peter Maydell
2018-05-22 10:11   ` Peter Maydell
2018-05-22 18:35   ` Stefano Stabellini
2018-05-22 18:35   ` [Qemu-devel] " Stefano Stabellini

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=1526931304-7289-11-git-send-email-sstabellini@kernel.org \
    --to=sstabellini@kernel.org \
    --cc=anthony.perard@citrix.com \
    --cc=paul.durrant@citrix.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=stefanha@redhat.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.