Skip to contentSkip to conversation

xen: return a per-mapping error from XENMEM_add_to_physmap_range.

PATCH In review Ian Campbell 5 participants 8 messages Jan 4, 2013 – Jan 17, 2013

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: return a per-mapping error from XENMEM_add_to_physmap_range.

Since ARM and PVH dom0 kernel use this to map foreign domain pages they could in the future hit paged out or shared pages etc and therefore need to propagate which frames are -ENOENT and which failed for some other reason.

We have not yet released a version of Xen with this particular hypercall subop so we can change the interface without worrying about compatibility (I think/hope).

This would be used by the privcmd driver, in particular it relates to Mats' patch "improve performance of MMAPBATCH_V2."

NB I have only implemented the ARM side since the PVH side isn't in tree yet.

Cc Mats Petersson <[email protected]>
Cc Mukesh Rathor <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
---
 xen/arch/arm/mm.c           |    4 ++++
 xen/include/public/memory.h |    8 +++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
xen/arch/arm/mm.c +4 -0
index d97b3ea..945e7ac 100644
@@ -612,6 +612,10 @@ static int xenmem_add_to_physmap_range(struct domain *d,
                                        xatpr->foreign_domid,
                                        idx, gpfn);
 
+        rc = copy_to_guest_offset(xatpr->errs, xatpr->size-1, &rc, 1);
+        if ( rc < 0 )
+            goto out;
+
         xatpr->size--;
 
         /* Check for continuation if it's not the last interation */
xen/include/public/memory.h +7 -1
index 3ee2902..62acabd 100644
@@ -236,6 +236,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
 /* A batched version of add_to_physmap. */
 #define XENMEM_add_to_physmap_range 23
 struct xen_add_to_physmap_range {
+    /* IN */
     /* Which domain to change the mapping for. */
     domid_t domid;
     uint16_t space; /* => enum phys_map_space */
@@ -247,8 +248,13 @@ struct xen_add_to_physmap_range {
     /* Indexes into space being mapped. */
     XEN_GUEST_HANDLE(xen_ulong_t) idxs;
 
-    /* GPFN in domdwhere the source mapping page should appear. */
+    /* GPFN in domid where the source mapping page should appear. */
     XEN_GUEST_HANDLE(xen_pfn_t) gpfns;
+
+    /* OUT */
+
+    /* Per index error code. */
+    XEN_GUEST_HANDLE(int) errs;
 };
 typedef struct xen_add_to_physmap_range xen_add_to_physmap_range_t;
 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t);
Signature · 1 line
1.7.9.1
#1 lore raw
Quoted 4 lines · Ian Campbell

Since ARM and PVH dom0 kernel use this to map foreign domain pages they could in the future hit paged out or shared pages etc and therefore need to propagate which frames are -ENOENT and which failed for some other reason.

And the Linux side:

8<-----------------

Quoted 1 line

From ccf21a20c014e416f8cf747d284cf33492151da5 Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Fri, 4 Jan 2013 13:58:29 +0000
Subject: [PATCH] xen: implement updated XENMEM_add_to_physmap_range ABI

Allows for more fine grained error reporting. Only used by PVH and ARM both of which are marked EXPERIMENTAL precisely because the ABI is not yet stable

---
 arch/arm/xen/enlighten.c       |    8 +++++---
 arch/x86/xen/mmu.c             |    8 +++++---
 include/xen/interface/memory.h |    6 ++++++
 3 files changed, 16 insertions(+), 6 deletions(-)
arch/arm/xen/enlighten.c +5 -3
index f28fc1a..31e4ae3 100644
@@ -59,14 +59,16 @@ static int map_foreign_page(unsigned long lpfn, unsigned long fgmfn,
 	};
 	xen_ulong_t idx = fgmfn;
 	xen_pfn_t gpfn = lpfn;
+	int err = 0;
 
 	set_xen_guest_handle(xatp.idxs, &idx);
 	set_xen_guest_handle(xatp.gpfns, &gpfn);
+	set_xen_guest_handle(xatp.errs, &err);
 
 	rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap_range, &xatp);
-	if (rc) {
-		pr_warn("Failed to map pfn to mfn rc:%d pfn:%lx mfn:%lx\n",
-			rc, lpfn, fgmfn);
+	if (rc || err) {
+		pr_warn("Failed to map pfn to mfn rc:%d:%d pfn:%lx mfn:%lx\n",
+			rc, err, lpfn, fgmfn);
 		return 1;
 	}
 	return 0;
arch/x86/xen/mmu.c +5 -3
index fee34fe..41f6de4 100644
@@ -2508,14 +2508,16 @@ static int pvh_add_to_xen_p2m(unsigned long lpfn, unsigned long fgmfn,
 	};
 	xen_ulong_t idx = fgmfn;
 	xen_pfn_t gpfn = lpfn;
+	int err = 0;
 
 	set_xen_guest_handle(xatp.idxs, &idx);
 	set_xen_guest_handle(xatp.gpfns, &gpfn);
+	set_xen_guest_handle(xatp.errs, &err);
 
 	rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap_range, &xatp);
-	if (rc)
-		pr_warn("d0: Failed to map pfn (0x%lx) to mfn (0x%lx) rc:%d\n",
-			lpfn, fgmfn, rc);
+	if (rc || err)
+		pr_warn("d0: Failed to map pfn (0x%lx) to mfn (0x%lx) rc:%d:%d\n",
+			lpfn, fgmfn, rc, err);
 	return rc;
 }
 
include/xen/interface/memory.h +6 -0
index b40a431..2ecfe4f 100644
@@ -190,6 +190,7 @@ DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap);
 
 #define XENMEM_add_to_physmap_range 23
 struct xen_add_to_physmap_range {
+    /* IN */
     /* Which domain to change the mapping for. */
     domid_t domid;
     uint16_t space; /* => enum phys_map_space */
@@ -203,6 +204,11 @@ struct xen_add_to_physmap_range {
 
     /* GPFN in domid where the source mapping page should appear. */
     GUEST_HANDLE(xen_pfn_t) gpfns;
+
+    /* OUT */
+
+    /* Per index error code. */
+    GUEST_HANDLE(int) errs;
 };
 DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap_range);
 
Signature · 1 line
1.7.2.5
#2 lore raw
In reply to Ian Campbell

Any Acks/Nacks?

This touches both ARM and x86 (although x86 only notionally until the PVH stuff is merged).

Quoted 70 lines · Ian Campbell

Since ARM and PVH dom0 kernel use this to map foreign domain pages they could in the future hit paged out or shared pages etc and therefore need to propagate which frames are -ENOENT and which failed for some other reason.

We have not yet released a version of Xen with this particular hypercall subop so we can change the interface without worrying about compatibility (I think/hope).

This would be used by the privcmd driver, in particular it relates to Mats' patch "improve performance of MMAPBATCH_V2."

NB I have only implemented the ARM side since the PVH side isn't in tree yet.

Cc Mats Petersson <[email protected]>
Cc Mukesh Rathor <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
---
 xen/arch/arm/mm.c           |    4 ++++
 xen/include/public/memory.h |    8 +++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
xen/arch/arm/mm.c +4 -0
index d97b3ea..945e7ac 100644
@@ -612,6 +612,10 @@ static int xenmem_add_to_physmap_range(struct domain *d,
                                        xatpr->foreign_domid,
                                        idx, gpfn);
 
+        rc = copy_to_guest_offset(xatpr->errs, xatpr->size-1, &rc, 1);
+        if ( rc < 0 )
+            goto out;
+
         xatpr->size--;
 
         /* Check for continuation if it's not the last interation */
xen/include/public/memory.h +7 -1
index 3ee2902..62acabd 100644
@@ -236,6 +236,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
 /* A batched version of add_to_physmap. */
 #define XENMEM_add_to_physmap_range 23
 struct xen_add_to_physmap_range {
+    /* IN */
     /* Which domain to change the mapping for. */
     domid_t domid;
     uint16_t space; /* => enum phys_map_space */
@@ -247,8 +248,13 @@ struct xen_add_to_physmap_range {
     /* Indexes into space being mapped. */
     XEN_GUEST_HANDLE(xen_ulong_t) idxs;
 
-    /* GPFN in domdwhere the source mapping page should appear. */
+    /* GPFN in domid where the source mapping page should appear. */
     XEN_GUEST_HANDLE(xen_pfn_t) gpfns;
+
+    /* OUT */
+
+    /* Per index error code. */
+    XEN_GUEST_HANDLE(int) errs;
 };
 typedef struct xen_add_to_physmap_range xen_add_to_physmap_range_t;
 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t);
#3 lore raw
Quoted 79 lines · Ian Campbell

Any Acks/Nacks?

This touches both ARM and x86 (although x86 only notionally until the PVH stuff is merged).

Quoted 70 lines · Ian Campbell

Since ARM and PVH dom0 kernel use this to map foreign domain pages they could in the future hit paged out or shared pages etc and therefore need to propagate which frames are -ENOENT and which failed for some other reason.

We have not yet released a version of Xen with this particular hypercall subop so we can change the interface without worrying about compatibility (I think/hope).

This would be used by the privcmd driver, in particular it relates to Mats' patch "improve performance of MMAPBATCH_V2."

NB I have only implemented the ARM side since the PVH side isn't in tree yet.

Cc Mats Petersson <[email protected]>
Cc Mukesh Rathor <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
---
 xen/arch/arm/mm.c           |    4 ++++
 xen/include/public/memory.h |    8 +++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
xen/arch/arm/mm.c +4 -0
index d97b3ea..945e7ac 100644
@@ -612,6 +612,10 @@ static int xenmem_add_to_physmap_range(struct domain *d,
                                        xatpr->foreign_domid,
                                        idx, gpfn);
 
+        rc = copy_to_guest_offset(xatpr->errs, xatpr->size-1, &rc, 1);
+        if ( rc < 0 )
+            goto out;
+
         xatpr->size--;
 
         /* Check for continuation if it's not the last interation */
xen/include/public/memory.h +7 -1
index 3ee2902..62acabd 100644
@@ -236,6 +236,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
 /* A batched version of add_to_physmap. */
 #define XENMEM_add_to_physmap_range 23
 struct xen_add_to_physmap_range {
+    /* IN */
     /* Which domain to change the mapping for. */
     domid_t domid;
     uint16_t space; /* => enum phys_map_space */
@@ -247,8 +248,13 @@ struct xen_add_to_physmap_range {
     /* Indexes into space being mapped. */
     XEN_GUEST_HANDLE(xen_ulong_t) idxs;
 
-    /* GPFN in domdwhere the source mapping page should appear. */
+    /* GPFN in domid where the source mapping page should appear. */
     XEN_GUEST_HANDLE(xen_pfn_t) gpfns;
+
+    /* OUT */
+
+    /* Per index error code. */
+    XEN_GUEST_HANDLE(int) errs;
 };
 typedef struct xen_add_to_physmap_range xen_add_to_physmap_range_t;
 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t);
Acked-by
#4 lore raw
Quoted 83 lines · Stefano Stabellini
Quoted 80 lines · Ian Campbell

Any Acks/Nacks?

This touches both ARM and x86 (although x86 only notionally until the PVH stuff is merged).

Quoted 71 lines · Ian Campbell

Since ARM and PVH dom0 kernel use this to map foreign domain pages they could in the future hit paged out or shared pages etc and therefore need to propagate which frames are -ENOENT and which failed for some other reason.

We have not yet released a version of Xen with this particular hypercall subop so we can change the interface without worrying about compatibility (I think/hope).

This would be used by the privcmd driver, in particular it relates to Mats' patch "improve performance of MMAPBATCH_V2."

NB I have only implemented the ARM side since the PVH side isn't in tree yet.

Cc Mats Petersson <[email protected]>
Cc Mukesh Rathor <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
---
 xen/arch/arm/mm.c           |    4 ++++
 xen/include/public/memory.h |    8 +++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
xen/arch/arm/mm.c +4 -0
index d97b3ea..945e7ac 100644
@@ -612,6 +612,10 @@ static int xenmem_add_to_physmap_range(struct domain
 *d,
                                        xatpr->foreign_domid,
                                        idx, gpfn);
 
+        rc = copy_to_guest_offset(xatpr->errs, xatpr->size-1, &rc, 1);
+        if ( rc < 0 )
+            goto out;
+
         xatpr->size--;
 
         /* Check for continuation if it's not the last interation */
xen/include/public/memory.h +7 -1
index 3ee2902..62acabd 100644
@@ -236,6 +236,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
 /* A batched version of add_to_physmap. */
 #define XENMEM_add_to_physmap_range 23
 struct xen_add_to_physmap_range {
+    /* IN */
     /* Which domain to change the mapping for. */
     domid_t domid;
     uint16_t space; /* => enum phys_map_space */
@@ -247,8 +248,13 @@ struct xen_add_to_physmap_range {
     /* Indexes into space being mapped. */
     XEN_GUEST_HANDLE(xen_ulong_t) idxs;
 
-    /* GPFN in domdwhere the source mapping page should appear. */
+    /* GPFN in domid where the source mapping page should appear. */
     XEN_GUEST_HANDLE(xen_pfn_t) gpfns;
+
+    /* OUT */
+
+    /* Per index error code. */
+    XEN_GUEST_HANDLE(int) errs;
 };
 typedef struct xen_add_to_physmap_range xen_add_to_physmap_range_t;
 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t);
#5 lore raw
In reply to Ian Campbell
Quoted 4 lines · Ian Campbell

Any Acks/Nacks?

This touches both ARM and x86 (although x86 only notionally until the PVH stuff is merged).

Quoted 73 lines · Ian Campbell
Quoted 70 lines

Since ARM and PVH dom0 kernel use this to map foreign domain pages they could in the future hit paged out or shared pages etc and therefore need to propagate which frames are -ENOENT and which failed for some other reason.

We have not yet released a version of Xen with this particular hypercall subop so we can change the interface without worrying about compatibility (I think/hope).

This would be used by the privcmd driver, in particular it relates to Mats' patch "improve performance of MMAPBATCH_V2."

NB I have only implemented the ARM side since the PVH side isn't in tree yet.

Cc Mats Petersson <[email protected]>
Cc Mukesh Rathor <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
---
  xen/arch/arm/mm.c           |    4 ++++
  xen/include/public/memory.h |    8 +++++++-
  2 files changed, 11 insertions(+), 1 deletions(-)
xen/arch/arm/mm.c +4 -0
index d97b3ea..945e7ac 100644
@@ -612,6 +612,10 @@ static int xenmem_add_to_physmap_range(struct domain *d,
                                         xatpr->foreign_domid,
                                         idx, gpfn);
 
+        rc = copy_to_guest_offset(xatpr->errs, xatpr->size-1, &rc, 1);
+        if ( rc < 0 )
+            goto out;
+
          xatpr->size--;
 
          /* Check for continuation if it's not the last interation */
xen/include/public/memory.h +7 -1
index 3ee2902..62acabd 100644
@@ -236,6 +236,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
  /* A batched version of add_to_physmap. */
  #define XENMEM_add_to_physmap_range 23
  struct xen_add_to_physmap_range {
+    /* IN */
      /* Which domain to change the mapping for. */
      domid_t domid;
      uint16_t space; /* => enum phys_map_space */
@@ -247,8 +248,13 @@ struct xen_add_to_physmap_range {
      /* Indexes into space being mapped. */
      XEN_GUEST_HANDLE(xen_ulong_t) idxs;
 
-    /* GPFN in domdwhere the source mapping page should appear. */
+    /* GPFN in domid where the source mapping page should appear. */
      XEN_GUEST_HANDLE(xen_pfn_t) gpfns;
+
+    /* OUT */
+
+    /* Per index error code. */
+    XEN_GUEST_HANDLE(int) errs;
  };
  typedef struct xen_add_to_physmap_range xen_add_to_physmap_range_t;
  DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t);
#6 lore raw
In reply to Ian Campbell
Quoted 1 line · Ian Campbell

Any Acks/Nacks?

I took the Linux patch and applied it to my stable/pvh... something already.

Quoted 77 lines

This touches both ARM and x86 (although x86 only notionally until the PVH stuff is merged).

Quoted 70 lines · Ian Campbell

Since ARM and PVH dom0 kernel use this to map foreign domain pages they could in the future hit paged out or shared pages etc and therefore need to propagate which frames are -ENOENT and which failed for some other reason.

We have not yet released a version of Xen with this particular hypercall subop so we can change the interface without worrying about compatibility (I think/hope).

This would be used by the privcmd driver, in particular it relates to Mats' patch "improve performance of MMAPBATCH_V2."

NB I have only implemented the ARM side since the PVH side isn't in tree yet.

Cc Mats Petersson <[email protected]>
Cc Mukesh Rathor <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
---
 xen/arch/arm/mm.c           |    4 ++++
 xen/include/public/memory.h |    8 +++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
xen/arch/arm/mm.c +4 -0
index d97b3ea..945e7ac 100644
@@ -612,6 +612,10 @@ static int xenmem_add_to_physmap_range(struct domain *d,
                                        xatpr->foreign_domid,
                                        idx, gpfn);
 
+        rc = copy_to_guest_offset(xatpr->errs, xatpr->size-1, &rc, 1);
+        if ( rc < 0 )
+            goto out;
+
         xatpr->size--;
 
         /* Check for continuation if it's not the last interation */
xen/include/public/memory.h +7 -1
index 3ee2902..62acabd 100644
@@ -236,6 +236,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
 /* A batched version of add_to_physmap. */
 #define XENMEM_add_to_physmap_range 23
 struct xen_add_to_physmap_range {
+    /* IN */
     /* Which domain to change the mapping for. */
     domid_t domid;
     uint16_t space; /* => enum phys_map_space */
@@ -247,8 +248,13 @@ struct xen_add_to_physmap_range {
     /* Indexes into space being mapped. */
     XEN_GUEST_HANDLE(xen_ulong_t) idxs;
 
-    /* GPFN in domdwhere the source mapping page should appear. */
+    /* GPFN in domid where the source mapping page should appear. */
     XEN_GUEST_HANDLE(xen_pfn_t) gpfns;
+
+    /* OUT */
+
+    /* Per index error code. */
+    XEN_GUEST_HANDLE(int) errs;
 };
 typedef struct xen_add_to_physmap_range xen_add_to_physmap_range_t;
 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t);
#7 lore raw
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Ian Campbell

Any Acks/Nacks?

I took the Linux patch and applied it to my stable/pvh... something already.

Thanks. I've applied the Xen side with the various acks.