From: Dushyant Behl <myselfdushyantbehl@gmail.com>
To: xen-devel@lists.xen.org
Cc: David Scott <dave.scott@eu.citrix.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Andres Lagar Cavilla <andres.lagarcavilla@gmail.com>,
Dushyant Behl <myselfdushyantbehl@gmail.com>
Subject: [PATCH v3 3/3] tools/libxc/xc_mem_paging_setup.c: FIX- Race condition between initializing shared ring and mempaging.
Date: Fri, 8 Aug 2014 02:10:12 +0530 [thread overview]
Message-ID: <1407444012-31830-4-git-send-email-myselfdushyantbehl@gmail.com> (raw)
In-Reply-To: <1407444012-31830-1-git-send-email-myselfdushyantbehl@gmail.com>
This patch is meant to fix a known race condition bug in mempaging
ring setup routines. The race condition was between initializing
mem paging and initializing shared ring, earlier the code initialized
mem paging before removing the ring page from guest's physical map
which could enable the guest to interfere with the ring initialisation.
Now the code removes the page from the guest's physical map before
enabling mempaging so that the guest cannot clobber the ring after
we initialise it.
Signed-off-by: Dushyant Behl <myselfdushyantbehl@gmail.com>
Reviewed-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
tools/libxc/xc_mem_paging_setup.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/tools/libxc/xc_mem_paging_setup.c b/tools/libxc/xc_mem_paging_setup.c
index 9741dc9..12469b4 100644
--- a/tools/libxc/xc_mem_paging_setup.c
+++ b/tools/libxc/xc_mem_paging_setup.c
@@ -76,6 +76,22 @@ int xc_mem_paging_ring_setup(xc_interface *xch,
}
}
+ /* Clear the ring_pfn */
+ memset(ring_page, 0, PAGE_SIZE);
+
+ rc = xc_domain_pause(xch, domain_id);
+ if ( rc != 0 )
+ {
+ PERROR("Unable to pause domain");
+ return -1;
+ }
+ DPRINTF("Domain pause successful");
+
+ /* Initialise ring */
+ SHARED_RING_INIT((mem_event_sring_t *)ring_page);
+ BACK_RING_INIT(back_ring, (mem_event_sring_t *)ring_page, PAGE_SIZE);
+ DPRINTF("ininialized shared ring");
+
/* Initialise Xen */
rc = xc_mem_paging_enable(xch, domain_id, evtchn_port);
if ( rc != 0 )
@@ -99,6 +115,7 @@ int xc_mem_paging_ring_setup(xc_interface *xch,
}
return -1;
}
+ DPRINTF("enabled mempaging");
/* Bind event notification */
rc = xc_evtchn_bind_interdomain(xce_handle, domain_id, *evtchn_port);
@@ -109,10 +126,6 @@ int xc_mem_paging_ring_setup(xc_interface *xch,
}
*port = rc;
- /* Initialise ring */
- SHARED_RING_INIT((mem_event_sring_t *)ring_page);
- BACK_RING_INIT(back_ring, (mem_event_sring_t *)ring_page, PAGE_SIZE);
-
/* Now that the ring is set, remove it from the guest's physmap */
if ( xc_domain_decrease_reservation_exact(xch, domain_id, 1, 0, &ring_pfn) )
{
@@ -120,6 +133,14 @@ int xc_mem_paging_ring_setup(xc_interface *xch,
return -1;
}
+ rc = xc_domain_unpause(xch, domain_id);
+ if ( rc != 0 )
+ {
+ PERROR("Unable to unpause domain");
+ return -1;
+ }
+ DPRINTF("Domain unpause successful");
+
return 0;
}
--
1.9.1
next prev parent reply other threads:[~2014-08-07 20:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-07 20:40 Refactoring mempaging code from xenpaging to libxc and few updates Dushyant Behl
2014-08-07 20:40 ` [PATCH v3 1/3] tools/libxc: refactored mempaging code from xenpaging to libxc Dushyant Behl
2014-08-07 20:40 ` [PATCH v3 2/3] tools/libxc/xc_mem_paging_setup.c: replacing deprecated function calls Dushyant Behl
2014-08-07 20:40 ` Dushyant Behl [this message]
2014-08-08 2:37 ` [PATCH v3 3/3] tools/libxc/xc_mem_paging_setup.c: FIX- Race condition between initializing shared ring and mempaging Andres Lagar Cavilla
2014-08-13 16:28 ` Refactoring mempaging code from xenpaging to libxc and few updates Dushyant Behl
2014-08-13 20:54 ` Dushyant Behl
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=1407444012-31830-4-git-send-email-myselfdushyantbehl@gmail.com \
--to=myselfdushyantbehl@gmail.com \
--cc=andres.lagarcavilla@gmail.com \
--cc=andrew.cooper3@citrix.com \
--cc=dave.scott@eu.citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).