From: Andres Lagar-Cavilla <andres@lagarcavilla.org>
To: xen-devel@lists.xensource.com
Cc: ian.campbell@citrix.com, andres@gridcentric.ca, tim@xen.org,
keir.xen@gmail.com, JBeulich@suse.com, ian.jackson@citrix.com,
adin@gridcentric.ca
Subject: [PATCH 06 of 12] x86/mm: New domctl: add a shared page to the physmap
Date: Sun, 15 Jan 2012 21:56:26 -0500 [thread overview]
Message-ID: <da6576b82e1636f264b4.1326682586@xdev.gridcentric.ca> (raw)
In-Reply-To: <patchbomb.1326682580@xdev.gridcentric.ca>
xen/arch/x86/mm/mem_sharing.c | 104 ++++++++++++++++++++++++++++++++++++++++++
xen/include/public/domctl.h | 3 +-
2 files changed, 106 insertions(+), 1 deletions(-)
This domctl is useful to, for example, populate parts of a domain's physmap
with shared frames, directly.
Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
Signed-off-by: Adin Scannell <adin@scannell.ca>
diff -r b0c70c156920 -r da6576b82e16 xen/arch/x86/mm/mem_sharing.c
--- a/xen/arch/x86/mm/mem_sharing.c
+++ b/xen/arch/x86/mm/mem_sharing.c
@@ -830,6 +830,74 @@ err_out:
return ret;
}
+int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, shr_handle_t sh,
+ struct domain *cd, unsigned long cgfn)
+{
+ struct page_info *spage;
+ int ret = -EINVAL;
+ mfn_t smfn, cmfn;
+ p2m_type_t smfn_type, cmfn_type;
+ struct gfn_info *gfn_info;
+ struct p2m_domain *p2m = p2m_get_hostp2m(cd);
+ p2m_access_t a;
+ DECLARE_PG_LOCK_DATA(pld);
+
+ /* XXX if sd == cd handle potential deadlock by ordering
+ * the get_ and put_gfn's */
+ smfn = get_gfn_query(sd, sgfn, &smfn_type);
+ cmfn = get_gfn_type_access(p2m, cgfn, &cmfn_type, &a, p2m_query, NULL);
+
+ /* Get the source shared page, check and lock */
+ ret = XEN_DOMCTL_MEM_SHARING_S_HANDLE_INVALID;
+ spage = __grab_shared_page(smfn, &pld);
+ if ( spage == NULL )
+ goto err_out;
+ ASSERT(smfn_type == p2m_ram_shared);
+
+ /* Check that the handles match */
+ if ( spage->shared_info->handle != sh )
+ goto err_unlock;
+
+ /* Make sure the target page is a hole in the physmap */
+ if ( mfn_valid(cmfn) ||
+ (!(p2m_is_ram(cmfn_type))) )
+ {
+ ret = XEN_DOMCTL_MEM_SHARING_C_HANDLE_INVALID;
+ goto err_unlock;
+ }
+
+ /* This is simpler than regular sharing */
+ BUG_ON(!get_page_and_type(spage, dom_cow, PGT_shared_page));
+ if ( (gfn_info = mem_sharing_gfn_alloc(spage, cd, cgfn)) == NULL )
+ {
+ put_page_and_type(spage);
+ ret = -ENOMEM;
+ goto err_unlock;
+ }
+
+ p2m_lock(p2m);
+ ret = set_p2m_entry(p2m, cgfn, smfn, PAGE_ORDER_4K, p2m_ram_shared, a);
+ p2m_unlock(p2m);
+
+ /* Tempted to turn this into an assert */
+ if ( !ret )
+ {
+ ret = -ENOENT;
+ mem_sharing_gfn_destroy(cd, gfn_info);
+ put_page_and_type(spage);
+ } else
+ ret = 0;
+
+ atomic_inc(&nr_saved_mfns);
+
+err_unlock:
+ mem_sharing_page_unlock(spage, &pld);
+err_out:
+ put_gfn(cd, cgfn);
+ put_gfn(sd, sgfn);
+ return ret;
+}
+
int mem_sharing_unshare_page(struct domain *d,
unsigned long gfn,
uint16_t flags)
@@ -1053,6 +1121,42 @@ int mem_sharing_domctl(struct domain *d,
}
break;
+ case XEN_DOMCTL_MEM_EVENT_OP_SHARING_ADD_PHYSMAP:
+ {
+ unsigned long sgfn, cgfn;
+ struct domain *cd;
+ shr_handle_t sh;
+
+ if ( !mem_sharing_enabled(d) )
+ return -EINVAL;
+
+ cd = get_domain_by_id(mec->u.share.client_domain);
+ if ( !cd )
+ return -ESRCH;
+
+ if ( !mem_sharing_enabled(cd) )
+ {
+ put_domain(cd);
+ return -EINVAL;
+ }
+
+ if ( XEN_DOMCTL_MEM_SHARING_FIELD_IS_GREF(mec->u.share.source_gfn) )
+ {
+ /* Cannot add a gref to the physmap */
+ put_domain(cd);
+ return -EINVAL;
+ }
+
+ sgfn = mec->u.share.source_gfn;
+ sh = mec->u.share.source_handle;
+ cgfn = mec->u.share.client_gfn;
+
+ rc = mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn);
+
+ put_domain(cd);
+ }
+ break;
+
case XEN_DOMCTL_MEM_EVENT_OP_SHARING_RESUME:
{
if ( !mem_sharing_enabled(d) )
diff -r b0c70c156920 -r da6576b82e16 xen/include/public/domctl.h
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -771,6 +771,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_mem_e
#define XEN_DOMCTL_MEM_EVENT_OP_SHARING_DEBUG_GFN 5
#define XEN_DOMCTL_MEM_EVENT_OP_SHARING_DEBUG_MFN 6
#define XEN_DOMCTL_MEM_EVENT_OP_SHARING_DEBUG_GREF 7
+#define XEN_DOMCTL_MEM_EVENT_OP_SHARING_ADD_PHYSMAP 8
#define XEN_DOMCTL_MEM_SHARING_S_HANDLE_INVALID (-10)
#define XEN_DOMCTL_MEM_SHARING_C_HANDLE_INVALID (-9)
@@ -797,7 +798,7 @@ struct xen_domctl_mem_sharing_op {
} u;
uint64_aligned_t handle; /* OUT: the handle */
} nominate;
- struct mem_sharing_op_share { /* OP_SHARE */
+ struct mem_sharing_op_share { /* OP_SHARE/ADD_PHYSMAP */
uint64_aligned_t source_gfn; /* IN: the gfn of the source page */
uint64_aligned_t source_handle; /* IN: handle to the source page */
domid_t client_domain; /* IN: the client domain id */
next prev parent reply other threads:[~2012-01-16 2:56 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-16 2:56 [PATCH 00 of 12] Sharing overhaul Andres Lagar-Cavilla
2012-01-16 2:56 ` [PATCH 01 of 12] x86/mm: Eliminate hash table in sharing code as index of shared mfns Andres Lagar-Cavilla
2012-01-19 11:39 ` Tim Deegan
2012-01-19 13:12 ` Andres Lagar-Cavilla
2012-01-16 2:56 ` [PATCH 02 of 12] x86/mm: Update mem sharing interface to (re)allow sharing of grants Andres Lagar-Cavilla
2012-01-19 11:56 ` Tim Deegan
2012-01-16 2:56 ` [PATCH 03 of 12] x86/mm: Add per-page locking for memory sharing, when audits are disabled Andres Lagar-Cavilla
2012-01-19 12:13 ` Tim Deegan
2012-01-19 13:02 ` Tim Deegan
2012-01-19 13:06 ` Andres Lagar-Cavilla
2012-01-19 13:13 ` Tim Deegan
2012-01-16 2:56 ` [PATCH 04 of 12] x86/mm: Enforce lock ordering for sharing page locks Andres Lagar-Cavilla
2012-01-19 12:18 ` Tim Deegan
2012-01-16 2:56 ` [PATCH 05 of 12] x86/mm: Check how many mfns are shared, in addition to how many are saved Andres Lagar-Cavilla
2012-01-16 2:56 ` Andres Lagar-Cavilla [this message]
2012-01-19 13:04 ` [PATCH 06 of 12] x86/mm: New domctl: add a shared page to the physmap Tim Deegan
2012-01-19 13:09 ` Andres Lagar-Cavilla
2012-01-16 2:56 ` [PATCH 07 of 12] Add the ability to poll stats about shared memory via the console Andres Lagar-Cavilla
2012-01-19 12:53 ` Tim Deegan
2012-01-16 2:56 ` [PATCH 08 of 12] x86/mm: use RCU in mem sharing audit list, eliminate global lock completely Andres Lagar-Cavilla
2012-01-19 12:59 ` Tim Deegan
2012-01-19 13:03 ` Andres Lagar-Cavilla
2012-01-19 13:14 ` Tim Deegan
2012-01-16 2:56 ` [PATCH 09 of 12] Update memshr API and tools Andres Lagar-Cavilla
2012-01-23 15:14 ` Ian Campbell
2012-01-16 2:56 ` [PATCH 10 of 12] Tools: Expose to libxc the total number of shared frames and space saved Andres Lagar-Cavilla
2012-01-16 2:56 ` [PATCH 11 of 12] Tools: Add a sharing command to xl for information about shared pages Andres Lagar-Cavilla
2012-01-19 12:14 ` Ian Campbell
2012-01-16 2:56 ` [PATCH 12 of 12] Memshrtool: tool to test and exercise the sharing subsystem Andres Lagar-Cavilla
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=da6576b82e1636f264b4.1326682586@xdev.gridcentric.ca \
--to=andres@lagarcavilla.org \
--cc=JBeulich@suse.com \
--cc=adin@gridcentric.ca \
--cc=andres@gridcentric.ca \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@citrix.com \
--cc=keir.xen@gmail.com \
--cc=tim@xen.org \
--cc=xen-devel@lists.xensource.com \
/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.