linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: takahiro.akashi@linaro.org (AKASHI Takahiro)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 10/19] arm64: kvm: allows kvm cpu hotplug
Date: Wed, 27 Jan 2016 16:37:36 +0900	[thread overview]
Message-ID: <56A873C0.6090406@linaro.org> (raw)
In-Reply-To: <56A7B018.7050900@arm.com>

On 01/27/2016 02:42 AM, James Morse wrote:
> Hi!
>
> On 15/01/16 19:18, Geoff Levand wrote:
>> From: AKASHI Takahiro <takahiro.akashi@linaro.org>
>>
>> The current kvm implementation on arm64 does cpu-specific initialization
>> at system boot, and has no way to gracefully shutdown a core in terms of
>> kvm. This prevents, especially, kexec from rebooting the system on a boot
>> core in EL2.
>>
>> This patch adds a cpu tear-down function and also puts an existing cpu-init
>> code into a separate function, kvm_arch_hardware_disable() and
>> kvm_arch_hardware_enable() respectively.
>> We don't need arm64-specific cpu hotplug hook any more.
>>
>> Since this patch modifies common part of code between arm and arm64, one
>> stub definition, __cpu_reset_hyp_mode(), is added on arm side to avoid
>> compiling errors.
>>
>> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
>
>> diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
>> index e06fd29..e91f80e 100644
>> --- a/arch/arm/kvm/arm.c
>> +++ b/arch/arm/kvm/arm.c
>
>>   #ifdef CONFIG_CPU_PM
>>   static int hyp_init_cpu_pm_notifier(struct notifier_block *self,
>>   				    unsigned long cmd,
>>   				    void *v)
>>   {
>> -	if (cmd == CPU_PM_EXIT &&
>> -	    __hyp_get_vectors() == hyp_default_vectors) {
>> -		cpu_init_hyp_mode(NULL);
>> +	switch (cmd) {
>> +	case CPU_PM_ENTER:
>> +		if (__this_cpu_read(kvm_arm_hardware_enabled))
>> +			cpu_reset_hyp_mode();
>> +
>>   		return NOTIFY_OK;
>> -	}
>> +	case CPU_PM_EXIT:
>> +		if (__this_cpu_read(kvm_arm_hardware_enabled))
>> +			cpu_init_hyp_mode();
>
> I read this as:
> 		if (enabled)
> 			enable();
>
> What am I missing? Is there a missing '!'?
>
> [/me thinks some more]
>
> I suspect this is trying to be clever: leaving the flag set over a
> deep-sleep, to indicate that the hardware should be re-enabled when we
> resume... if so, a comment to that effect would be good.

Yep, I meant so. Will add some comment.

>
>>
>> -	return NOTIFY_DONE;
>> +		return NOTIFY_OK;
>> +
>> +	default:
>> +		return NOTIFY_DONE;
>> +	}
>>   }
>>
>>   static struct notifier_block hyp_init_cpu_pm_nb = {
>
>> diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h
>> index 3070096..bca79f9 100644
>> --- a/arch/arm64/include/asm/virt.h
>> +++ b/arch/arm64/include/asm/virt.h
>> @@ -58,9 +58,18 @@
>>
>>   #define HVC_CALL_FUNC 3
>>
>> +/*
>> + * HVC_RESET_CPU - Reset cpu in EL2 to initial state.
>> + *
>> + * @x0: entry address in trampoline code in va
>> + * @x1: identical mapping page table in pa
>> + */
>> +
>>   #define BOOT_CPU_MODE_EL1	(0xe11)
>>   #define BOOT_CPU_MODE_EL2	(0xe12)
>>
>> +#define HVC_RESET_CPU 4
>> +
>
> Patch 5 added a fancy new way to call arbitrary functions at el2, why
> not use that? (it would save beating up el1_sync again).

Let me think. I need to detangle some header files.

> I agree the trampoline stuff is complicated - I will try and cook-up a
> version of this patch for hibernate that does this. (... and comment
> what I think is happening above while I'm at it)
>
>
>>   #ifndef __ASSEMBLY__
>>
>>   /*
>> diff --git a/arch/arm64/kvm/hyp-init.S b/arch/arm64/kvm/hyp-init.S
>> index 1d7e502..d909ce2 100644
>> --- a/arch/arm64/kvm/hyp-init.S
>> +++ b/arch/arm64/kvm/hyp-init.S
>> @@ -140,6 +140,39 @@ merged:
>>   	eret
>>   ENDPROC(__kvm_hyp_init)
>>
>> +	/*
>> +	 * x0: HYP boot pgd
>> +	 * x1: HYP phys_idmap_start
>> +	 */
>> +ENTRY(__kvm_hyp_reset)
>> +	/* We're in trampoline code in VA, switch back to boot page tables */
>> +	msr	ttbr0_el2, x0
>> +	isb
>> +
>> +	/* Invalidate the old TLBs */
>> +	tlbi	alle2
>> +	dsb	sy
>> +
>> +	/* Branch into PA space */
>> +	adr	x0, 1f
>> +	bfi	x1, x0, #0, #PAGE_SHIFT
>> +	br	x1
>> +
>> +	/* We're now in idmap, disable MMU */
>> +1:	mrs	x0, sctlr_el2
>> +	ldr	x1, =SCTLR_ELx_FLAGS
>> +	bic	x0, x0, x1		// Clear SCTL_M and etc
>> +	msr	sctlr_el2, x0
>> +	isb
>> +
>> +	/* Install stub vectors */
>> +	adrp	x0, __hyp_stub_vectors
>> +	add	x0, x0, #:lo12:__hyp_stub_vectors
>
> adr_l ?

OK.

Thanks,
-Takahiro AKASHI

>> +	msr	vbar_el2, x0
>> +
>> +	eret
>> +ENDPROC(__kvm_hyp_reset)
>> +
>>   	.ltorg
>>
>>   	.popsection
>> diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
>> index 15b1ef9..ed82dc2 100644
>> --- a/arch/arm64/kvm/hyp.S
>> +++ b/arch/arm64/kvm/hyp.S
>> @@ -986,10 +991,27 @@ el1_sync:					// Guest trapped into EL2
>>   	cmp	x18, #HVC_GET_VECTORS
>>   	b.ne	1f
>>   	mrs	x0, vbar_el2
>> -	b	2f
>> -
>> -1:	/* Default to HVC_CALL_HYP. */
>> +	b	do_eret
>>
>> +	/* jump into trampoline code */
>> +1:	cmp	x18, #HVC_RESET_CPU
>> +	b.ne	2f
>> +	/*
>> +	 * Entry point is:
>> +	 *	TRAMPOLINE_VA
>> +	 *	+ (__kvm_hyp_reset - (__hyp_idmap_text_start & PAGE_MASK))
>> +	 */
>> +	adrp	x2, __kvm_hyp_reset
>> +	add	x2, x2, #:lo12:__kvm_hyp_reset
>> +	adrp	x3, __hyp_idmap_text_start
>> +	add	x3, x3, #:lo12:__hyp_idmap_text_start
>
> adr_l ?
>
>> +	and	x3, x3, PAGE_MASK
>> +	sub	x2, x2, x3
>> +	ldr	x3, =TRAMPOLINE_VA
>> +	add	x2, x2, x3
>> +	br	x2				// no return
>> +
>> +2:	/* Default to HVC_CALL_HYP. */
>>   	push	lr, xzr
>>
>>   	/*
>
>
> Thanks,
>
> James
>

  reply	other threads:[~2016-01-27  7:37 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-15 19:18 [PATCH 00/19] arm64 kexec kernel patches v13 Geoff Levand
2016-01-15 19:18 ` [PATCH 05/19] arm64: Convert hcalls to use HVC immediate value Geoff Levand
2016-01-15 19:18 ` [PATCH 03/19] arm64: Add new asm macro copy_page Geoff Levand
2016-01-20 14:01   ` James Morse
2016-01-15 19:18 ` [PATCH 09/19] Revert "arm64: remove dead code" Geoff Levand
2016-01-15 19:55   ` Mark Rutland
2016-01-20 21:18     ` Geoff Levand
2016-01-15 19:18 ` [PATCH 06/19] arm64: Add new hcall HVC_CALL_FUNC Geoff Levand
2016-01-15 19:18 ` [PATCH 07/19] arm64: Add back cpu_reset routines Geoff Levand
2016-01-15 19:18 ` [PATCH 04/19] arm64: Cleanup SCTLR flags Geoff Levand
2016-01-15 20:07   ` Mark Rutland
2016-01-18 10:12     ` Marc Zyngier
2016-01-19 11:59       ` Dave Martin
2016-01-25 15:09   ` James Morse
2016-01-15 19:18 ` [PATCH 01/19] arm64: Fold proc-macros.S into assembler.h Geoff Levand
2016-01-15 19:18 ` [PATCH 08/19] Revert "arm64: mm: remove unused cpu_set_idmap_tcr_t0sz function" Geoff Levand
2016-01-15 19:18 ` [PATCH 02/19] arm64: kernel: Include _AC definition in page.h Geoff Levand
2016-01-18 10:05   ` Mark Rutland
2016-01-15 19:18 ` [PATCH 13/19] arm64/kexec: Add pr_debug output Geoff Levand
2016-01-15 19:18 ` [PATCH 16/19] arm64: kdump: add kdump support Geoff Levand
2016-01-21 14:17   ` James Morse
2016-01-22  4:50     ` AKASHI Takahiro
2016-01-15 19:18 ` [PATCH 19/19] arm64: kdump: relax BUG_ON() if more than one cpus are still active Geoff Levand
2016-01-15 19:18 ` [PATCH 10/19] arm64: kvm: allows kvm cpu hotplug Geoff Levand
2016-01-26 17:42   ` James Morse
2016-01-27  7:37     ` AKASHI Takahiro [this message]
2016-01-15 19:18 ` [PATCH 14/19] arm64: kdump: reserve memory for crash dump kernel Geoff Levand
2016-01-15 19:18 ` [PATCH 15/19] arm64: kdump: implement machine_crash_shutdown() Geoff Levand
2016-01-15 19:18 ` [PATCH 17/19] arm64: kdump: enable kdump in the arm64 defconfig Geoff Levand
2016-01-15 19:18 ` [PATCH 12/19] arm64/kexec: Enable kexec " Geoff Levand
2016-01-15 19:18 ` [PATCH 11/19] arm64/kexec: Add core kexec support Geoff Levand
2016-01-15 19:18 ` [PATCH 18/19] arm64: kdump: update a kernel doc Geoff Levand
2016-01-15 20:16   ` Mark Rutland
2016-01-18 10:26     ` AKASHI Takahiro
2016-01-18 11:29       ` Mark Rutland
2016-01-19  5:31         ` AKASHI Takahiro
2016-01-19 12:10           ` Mark Rutland
2016-01-20  4:34             ` AKASHI Takahiro
2016-01-19  1:43       ` Dave Young
2016-01-19  1:50         ` Dave Young
2016-01-19  5:35         ` AKASHI Takahiro
2016-01-19 12:28           ` Dave Young
2016-01-19 12:51             ` Mark Rutland
2016-01-19 13:45               ` Dave Young
2016-01-19 14:01                 ` Mark Rutland
2016-01-20  2:49                   ` Dave Young
2016-01-20  6:07                     ` AKASHI Takahiro
2016-01-20  6:38                       ` Dave Young
2016-01-20  7:00                         ` Dave Young
2016-01-20  8:01                           ` AKASHI Takahiro
2016-01-20  8:26                             ` Dave Young
2016-01-20 11:54                         ` Mark Rutland
2016-01-21  2:57                           ` Dave Young
2016-01-21  3:03                           ` Dave Young
2016-01-20 11:49                       ` Mark Rutland
2016-01-21  6:53                         ` AKASHI Takahiro
2016-01-21 12:02                           ` Mark Rutland
2016-01-22  6:23                             ` AKASHI Takahiro
2016-01-22 11:13                               ` Mark Rutland
2016-02-02  5:18                                 ` AKASHI Takahiro
2016-01-25  3:19                               ` Dave Young
2016-01-25  4:23                                 ` Dave Young
2016-01-20 11:28                     ` Mark Rutland
2016-01-21  2:54                       ` Dave Young
2016-01-20  5:25                   ` AKASHI Takahiro
2016-01-20 12:02                     ` Mark Rutland
2016-01-20 12:36                       ` Mark Rutland
2016-01-20 14:59                         ` Ard Biesheuvel
2016-01-20 15:04                           ` Mark Rutland
2016-01-21  5:43                           ` AKASHI Takahiro
2016-01-21 13:02                             ` Mark Rutland
2016-01-19 12:17         ` Mark Rutland
2016-01-19 13:52           ` Dave Young
2016-01-19 14:05             ` Mark Rutland
2016-01-20  2:54               ` Dave Young
2016-01-19 12:32 ` [PATCH 00/19] arm64 kexec kernel patches v13 Dave Young
2016-01-20  0:15   ` Geoff Levand
2016-01-20  2:56     ` Dave Young
2016-01-20 21:15       ` Geoff Levand
2016-01-21 12:11       ` Mark Rutland
     [not found] ` <c7575f853ccc491bb0212e025aab1cc9@NASANEXM01H.na.qualcomm.com>
2016-03-01 17:54   ` Azriel Samson
2016-03-02  1:17     ` Geoff Levand
2016-03-02  1:38       ` Will Deacon
2016-03-02  2:28         ` AKASHI Takahiro
2016-03-02  8:07       ` Marc Zyngier
2016-03-02 12:33     ` Pratyush Anand
2016-03-02 16:51       ` Azriel Samson

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=56A873C0.6090406@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.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).