From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Daniel Kiper <daniel.kiper@oracle.com>
Cc: kexec@list.infradead.org, Keir Fraser <keir@xen.org>,
David Vrabel <david.vrabel@citrix.com>,
Jan Beulich <jbeulich@suse.com>,
xen-devel@lists.xen.org
Subject: Re: [PATCH 4/9] kexec: extend hypercall with improved load/unload ops
Date: Sun, 6 Oct 2013 19:16:16 +0100 [thread overview]
Message-ID: <5251A8F0.4090800@citrix.com> (raw)
In-Reply-To: <20131004212300.GH3626@debian70-amd64.local.net-space.pl>
On 04/10/2013 22:23, Daniel Kiper wrote:
> On Fri, Sep 20, 2013 at 02:10:50PM +0100, David Vrabel wrote:
>> From: David Vrabel <david.vrabel@citrix.com>
>>
>> In the existing kexec hypercall, the load and unload ops depend on
>> internals of the Linux kernel (the page list and code page provided by
>> the kernel). The code page is used to transition between Xen context
>> and the image so using kernel code doesn't make sense and will not
>> work for PVH guests.
>>
>> Add replacement KEXEC_CMD_kexec_load and KEXEC_CMD_kexec_unload ops
>> that no longer require a code page to be provided by the guest -- Xen
>> now provides the code for calling the image directly.
>>
>> The new load op looks similar to the Linux kexec_load system call and
>> allows the guest to provide the image data to be loaded. The guest
>> specifies the architecture of the image which may be a 32-bit subarch
>> of the hypervisor's architecture (i.e., an EM_386 image on an
>> EM_X86_64 hypervisor).
>>
>> The toolstack can now load images without kernel involvement. This is
>> required for supporting kexec when using a dom0 with an upstream
>> kernel.
>>
>> Crash images are copied directly into the crash region on load.
>> Default images are copied into domheap pages and a list of source and
>> destination machine addresses is created. This is list is used in
>> kexec_reloc() to relocate the image to its destination.
>>
>> The old load and unload sub-ops are still available (as
>> KEXEC_CMD_load_v1 and KEXEC_CMD_unload_v1) and are implemented on top
>> of the new infrastructure.
>>
>> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
> [...]
>
>> diff --git a/xen/arch/x86/x86_64/kexec_reloc.S b/xen/arch/x86/x86_64/kexec_reloc.S
>> new file mode 100644
>> index 0000000..41dd27b
>> --- /dev/null
>> +++ b/xen/arch/x86/x86_64/kexec_reloc.S
>> @@ -0,0 +1,208 @@
>> +/*
>> + * Relocate a kexec_image to its destination and call it.
>> + *
>> + * Copyright (C) 2013 Citrix Systems R&D Ltd.
>> + *
>> + * Portions derived from Linux's arch/x86/kernel/relocate_kernel_64.S.
>> + *
>> + * Copyright (C) 2002-2005 Eric Biederman <ebiederm@xmission.com>
>> + *
>> + * This source code is licensed under the GNU General Public License,
>> + * Version 2. See the file COPYING for more details.
>> + */
>> +#include <xen/config.h>
>> +#include <xen/kimage.h>
>> +
>> +#include <asm/asm_defns.h>
>> +#include <asm/msr.h>
>> +#include <asm/page.h>
>> +#include <asm/machine_kexec.h>
>> +
>> + .text
>> + .align PAGE_SIZE
>> + .code64
>> +
>> +ENTRY(kexec_reloc)
>> + /* %rdi - code page maddr */
>> + /* %rsi - page table maddr */
>> + /* %rdx - indirection page maddr */
>> + /* %rcx - entry maddr */
>> + /* %r8 - flags */
>> +
>> + movq %rdx, %rbx
> Delete movq %rdx, %rbx
>
>> + /* Setup stack. */
>> + leaq (reloc_stack - kexec_reloc)(%rdi), %rsp
>> +
>> + /* Load reloc page table. */
>> + movq %rsi, %cr3
>> +
>> + /* Jump to identity mapped code. */
>> + leaq (identity_mapped - kexec_reloc)(%rdi), %rax
>> + jmpq *%rax
>> +
>> +identity_mapped:
>> + pushq %rcx
>> + pushq %rbx
>> + pushq %rsi
>> + pushq %rdi
> Delete pushq %rbx, pushq %rsi, pushq %rdi
>
>> + /*
>> + * Set cr0 to a known state:
>> + * - Paging enabled
>> + * - Alignment check disabled
>> + * - Write protect disabled
>> + * - No task switch
>> + * - Don't do FP software emulation.
>> + * - Proctected mode enabled
>> + */
>> + movq %cr0, %rax
>> + andl $~(X86_CR0_AM | X86_CR0_WP | X86_CR0_TS | X86_CR0_EM), %eax
>> + orl $(X86_CR0_PG | X86_CR0_PE), %eax
>> + movq %rax, %cr0
>> +
>> + /*
>> + * Set cr4 to a known state:
>> + * - physical address extension enabled
>> + */
>> + movl $X86_CR4_PAE, %eax
>> + movq %rax, %cr4
>> +
>> + movq %rbx, %rdi
> movq %rdx, %rdi
>
>> + call relocate_pages
>> +
>> + popq %rdi
>> + popq %rsi
>> + popq %rbx
>> + popq %rcx
> Delete popq %rdi, popq %rsi, popq %rbx
>
>> + /* Need to switch to 32-bit mode? */
>> + testq $KEXEC_RELOC_FLAG_COMPAT, %r8
>> + jnz call_32_bit
>> +
>> +call_64_bit:
>> + /* Call the image entry point. This should never return. */
> I think that all general purpose registers (including %rsi, %rdi, %rbp
> and %rsp) should be zeroed here. We should leave as little as possible
> info about previous system. Especially in kexec case. Just in case.
> Please look into linux/arch/x86/kernel/relocate_kernel_64.S
> for more details.
In the kexec case, we are specifically trying to leak the state of the
entire system outside of the crash area so something can investigate.
Zeroing the registers for the sake of it is pointless. Any author of
kexec image expecting all GPRs to be 0 on entry deserves the debugging
problems they are asking for.
>
>> + callq *%rcx
> Maybe we should use retq to jump into image entry point. If not
> I think that we should store image entry point address in %rax
> (just to the order).
retq with a zeroed %rsp ?
This code was derived from the linux code which allows a kexec image to
pass parameters (which is also why the registers are pushed/poped above)
and return back to the originator. (Although I have to admit to being
curious to how someone would go about trying to justify using this
feature in a real usecase.)
It might be reasonable to replace "callq *%rcx; ud2" with "jmp *%rcx",
but all of this does feel like nitpicking on a codepath which
(hopefully) will never be executed.
If we decide here and now that Xen shall never support passing arguments
to the kexec image, and never support the kexec image returning back to
us then perhaps we can go ahead and change things, although I would
argue that consistency with the other implementation is more important.
~Andrew
next prev parent reply other threads:[~2013-10-06 18:16 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-20 13:10 [PATCHv8 0/9] Xen: extend kexec hypercall for use with pv-ops kernels David Vrabel
2013-09-20 13:10 ` [PATCH 1/9] x86: give FIX_EFI_MPF its own fixmap entry David Vrabel
2013-09-20 13:10 ` [PATCH 2/9] kexec: add public interface for improved load/unload sub-ops David Vrabel
2013-09-24 15:23 ` Jan Beulich
2013-09-20 13:10 ` [PATCH 3/9] kexec: add infrastructure for handling kexec images David Vrabel
2013-09-20 13:10 ` [PATCH 4/9] kexec: extend hypercall with improved load/unload ops David Vrabel
2013-10-04 21:23 ` Daniel Kiper
2013-10-06 18:16 ` Andrew Cooper [this message]
2013-10-07 7:47 ` Daniel Kiper
2013-10-07 9:23 ` David Vrabel
2013-10-07 10:39 ` Daniel Kiper
2013-10-07 10:55 ` David Vrabel
2013-10-07 14:49 ` Daniel Kiper
2013-10-07 17:44 ` David Vrabel
2013-10-07 20:21 ` Daniel Kiper
2013-09-20 13:10 ` [PATCH 5/9] xen: kexec crash image when dom0 crashes David Vrabel
2013-09-20 13:10 ` [PATCH 6/9] libxc: add hypercall buffer arrays David Vrabel
2013-09-20 13:10 ` [PATCH 7/9] libxc: add API for kexec hypercall David Vrabel
2013-09-20 13:10 ` [PATCH 8/9] x86: check kexec relocation code fits in a page David Vrabel
2013-09-20 13:10 ` [PATCH 9/9] MAINTAINERS: Add KEXEC maintainer David Vrabel
2013-09-22 20:20 ` [PATCHv8 0/9] Xen: extend kexec hypercall for use with pv-ops kernels Daniel Kiper
2013-10-04 11:50 ` David Vrabel
2013-09-22 20:27 ` Daniel Kiper
2013-10-04 21:40 ` Daniel Kiper
[not found] <1383749386-11891-1-git-send-email-david.vrabel@citrix.com>
2013-11-06 14:49 ` [PATCH 4/9] kexec: extend hypercall with improved load/unload ops David Vrabel
2013-11-07 20:56 ` Don Slutz
-- strict thread matches above, loose matches on Subject: below --
2013-10-08 16:55 [PATCHv9 0/9] Xen: extend kexec hypercall for use with pv-ops kernels David Vrabel
2013-10-08 16:55 ` [PATCH 4/9] kexec: extend hypercall with improved load/unload ops David Vrabel
2013-11-05 22:43 ` Don Slutz
[not found] <1379015347-21653-1-git-send-email-david.vrabel@citrix.com>
2013-09-12 19:49 ` David Vrabel
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=5251A8F0.4090800@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=daniel.kiper@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=jbeulich@suse.com \
--cc=keir@xen.org \
--cc=kexec@list.infradead.org \
--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).