From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Ross Lagerwall <ross.lagerwall@citrix.com>
Cc: elena.ufimtseva@oracle.com, hanweidong@huawei.com,
jbeulich@suse.com, john.liuqiming@huawei.com,
paul.voccio@rackspace.com, kurt.hackel@oracle.com,
daniel.kiper@oracle.com, major.hayden@rackspace.com,
liuyingdong@huawei.com, aliguori@amazon.com,
xen-devel@lists.xenproject.org, lars.kurth@citrix.com,
steven.wilson@rackspace.com, ian.campbell@citrix.com,
peter.huangpeng@huawei.com, msw@amazon.com,
xiantao.zxt@alibaba-inc.com, rick.harris@rackspace.com,
boris.ostrovsky@oracle.com, jinsong.liu@alibaba-inc.com,
amesserl@rackspace.com, mpohlack@amazon.com, dslutz@verizon.com,
fanhenglong@huawei.com, andrew.cooper3@citrix.com
Subject: Re: xSplice prototype
Date: Fri, 23 Oct 2015 12:23:41 -0400 [thread overview]
Message-ID: <20151023162341.GA11162@l.oracle.com> (raw)
In-Reply-To: <562A5219.4000004@citrix.com>
On Fri, Oct 23, 2015 at 04:28:25PM +0100, Ross Lagerwall wrote:
> Hi all,
>
> I've gone ahead and implemented a bunch of xSplice stuff based on Konrad's
> xsplice branch. It is sitting in my github repository:
> https://github.com/rosslagerwall/xen tagged prototype-v1
> This is obviously prototype code, but please try it out. You'll also need
> this tool to build patches: https://github.com/rosslagerwall/xsplice-build
> tagged prototype-v1
>
Fantastic!!!
I should take vacation more often :-)
>
> Much of the work is implementing a basic version of the Linux kernel module
> loader. So the code does:
> * Loading of xsplice modules.
> * Copying allocated sections into a new executable region of memory.
> * Resolving symbols.
> * Applying relocations.
> * Patching of altinstructions.
> * Special handling of bug frames and exception tables.
> * Unloading of xsplice modules.
>
> The other main bit of this work is applying and reverting the patches
> safely. As implemented, the code is patched with each CPU waiting in the
> return-to-guest path (i.e. with no stack) which appears to be the safest way
> of patching. It should mean that stack checking is not required.
>
> All of the following should work:
> * Applying patches safely.
> * Reverting patches safely.
> * Replacing patches safely (e.g. reverting any applied patches and applying
> a new patch).
> * Bug frames as part of modules. This means adding or changing WARN, ASSERT,
> BUG, and run_in_exception_handler works correctly. Line number only changes
> _are ignored_.
> * Exception tables as part of modules. E.g. wrmsr_safe and copy_to_user work
> correctly when used in a patch module.
> * Hook load and unload functions which run at patch apply and revert time
> respectively.
OK, we (me) should then also update the design document to mention that.
> * Shadow variables. A minimal bit of infrastructure to attach a new variable
> to an existing data structure.
>
>
> Limitations
> ===========
> The above is enough to fully implement an update system where multiple
> source patches are combined (using combinediff) and built into a single
> binary which then atomically replaces any existing loaded patches (this is
> why I added a REPLACE operation). This is the approach used by kPatch and
> kGraft. Multiple completely independent patches can also be loaded but
> unexpected interactions may occur.
>
> As it stands, the patches are statically linked which means that independent
> patches cannot be linked against one another (e.g. if one introduces a new
> symbol). Using the combinediff approach above fixes this.
>
> Backtraces containing functions from a patch module do not show the symbol
> name.
>
> There is no checking that a patch which is loaded is built for the correct
> hypervisor.
Hehe.. bugs? What bugs!?
>
> Binary patching works at the function level.
>
>
> Design thoughts
> ===============
> Combining patches at the source level is relatively easy. Multiple binary
> patches applied at runtime is tricky. I'm not convinced that it is
> necessarily a good idea. Based on the discussion so far, the sanest way of
> doing this that I can think of is:
> * Each hypervisor has an embedded build id.
> * Each binary patch has an embedded build id.
> * The hypervisor should expose its build id and the build id of every loaded
> binary patch.
> * Each binary patch specifies one or more build ids on which it depends.
> These build ids can be either a hypervisor build id or another patch build
> id. The dependencies could either identified automatically or by a
> developer.
> * The userspace tool enforces dependency management (user can optionally
> force patch apply). I don't see any reason to involve the
> hypervisor for dependency management.
> Implementing this scheme will require dynamically linking the binary
> patches.
>
> The CHECK phase seems unnecessary to me. I would think that any safety
> checking that needs to be done would be done atomically at the point of
> patch apply (or revert). Given the implemented system of applying patches,
> I'm not sure if any safety checking need be done at all.
It was added as a way to do signature checking and any other type
of checking that needed to be done. And which may take quite a while
to get done - hence doing it asynchronously.
We have a meeting this Monday (Oct 26th) @ 10AM on the #xsplice channel.
And in which we can disucss the 'combining patches' part, the build-id, the
logging mechanism, and other things you had encountered and have thoughts on.
Again, thank you for doing this!
>
>
> Testing
> =======
> In case it's not clear what the workflow is, here is a sample transcript:
>
> $ mkdir ~/work
> $ cd ~/work
> $ git clone git://github.com/rosslagerwall/xen.git
> $ cd xen
> $ git checkout prototype-v1
> $ # Build a debug Xen and tools (including misc/xen-xsplice), install on a
> host and reboot
>
> $ # Write a patch
> $ git diff > ~/work/test1.patch
> $ git reset --hard
> $ # Write another patch
> $ git diff > ~/work/test2.patch
> $ git reset --hard
> $ # Write another patch
> $ git diff > ~/work/test3.patch
> $ git reset --hard
>
> $ cd ~/work
> $ git clone git://github.com/rosslagerwall/xsplice-build.git
> $ cd xsplice-build
> $ git checkout prototype-v1
> $ make
> $ ./xsplice-build -s ~/work/xen -p ~/work/test1.patch -o out1 --xen-debug
> --debug
> $ ./xsplice-build -s ~/work/xen -p ~/work/test2.patch -o out2 --xen-debug
> --debug
> $ ./xsplice-build -s ~/work/xen -p ~/work/test3.patch -o out3 --xen-debug
> --debug
> $ # copy out*/test*.xsplice onto the host
>
>
> On the host:
> # xen-xsplice upload test1 test1.xsplice
> # xen-xsplice upload test2 test2.xsplice
> # xen-xsplice upload test3 test3.xsplice
> # xen-xsplice check test1
> # xen-xsplice check test2
> # xen-xsplice check test3
>
> # xen-xsplice apply test1
> # # Verify test1 is applied
> # xen-xsplice apply test2
> # # Verify test2 is also applied
> # xen-xsplice replace test3
> # # Verify test3 is applied and test1 and test2 are not
> # xen-xsplice revert test3
> # # Verify test3 is not applied
>
> # xen-xsplice unload test1
> # xen-xsplice unload test2
> # xen-xsplice unload test3
>
> Thanks,
> --
> Ross Lagerwall
next prev parent reply other threads:[~2015-10-23 19:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-23 15:28 xSplice prototype Ross Lagerwall
2015-10-23 16:23 ` Konrad Rzeszutek Wilk [this message]
2015-10-26 8:35 ` Ross Lagerwall
2015-10-26 15:03 ` Konrad Rzeszutek Wilk
2015-10-26 17:03 ` Ross Lagerwall
2015-10-26 19:50 ` Boos, Robert
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=20151023162341.GA11162@l.oracle.com \
--to=konrad.wilk@oracle.com \
--cc=aliguori@amazon.com \
--cc=amesserl@rackspace.com \
--cc=andrew.cooper3@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=daniel.kiper@oracle.com \
--cc=dslutz@verizon.com \
--cc=elena.ufimtseva@oracle.com \
--cc=fanhenglong@huawei.com \
--cc=hanweidong@huawei.com \
--cc=ian.campbell@citrix.com \
--cc=jbeulich@suse.com \
--cc=jinsong.liu@alibaba-inc.com \
--cc=john.liuqiming@huawei.com \
--cc=kurt.hackel@oracle.com \
--cc=lars.kurth@citrix.com \
--cc=liuyingdong@huawei.com \
--cc=major.hayden@rackspace.com \
--cc=mpohlack@amazon.com \
--cc=msw@amazon.com \
--cc=paul.voccio@rackspace.com \
--cc=peter.huangpeng@huawei.com \
--cc=rick.harris@rackspace.com \
--cc=ross.lagerwall@citrix.com \
--cc=steven.wilson@rackspace.com \
--cc=xen-devel@lists.xenproject.org \
--cc=xiantao.zxt@alibaba-inc.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.