From patchwork Mon Apr 25 08:41:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 66567 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp915423qge; Mon, 25 Apr 2016 01:40:17 -0700 (PDT) X-Received: by 10.98.92.135 with SMTP id q129mr46412912pfb.71.1461573617660; Mon, 25 Apr 2016 01:40:17 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id b26si5533760pfj.138.2016.04.25.01.40.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Apr 2016 01:40:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1auc2d-0003eJ-D3; Mon, 25 Apr 2016 08:38:51 +0000 Received: from mail-pa0-x231.google.com ([2607:f8b0:400e:c03::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1auc2Z-0003cR-Vk for linux-arm-kernel@lists.infradead.org; Mon, 25 Apr 2016 08:38:49 +0000 Received: by mail-pa0-x231.google.com with SMTP id r5so55910992pag.1 for ; Mon, 25 Apr 2016 01:38:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=3/9vQ8G5oajcnx3B7W0WmSH6giaRgFz9CS05Rm+Fm0o=; b=fA28eq57FkPQJv1k+Keb1OFpVFrFApHwHk/2aRgDxmFbGGqGAuyFPXZGKfrNwB6YtG QEoftxGsG0eYBUEL71B+j4IwIfXzCCeNBAkwFj0K1j2cqCqbry/CGqOxK17W3Zt3sov/ K/vVEEoas7ovZLZljUZH07lRK6FeLoVDKq/pA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=3/9vQ8G5oajcnx3B7W0WmSH6giaRgFz9CS05Rm+Fm0o=; b=PeiMlqIzzWgFaedVF4gTao3qh4mE0ETWHPWDll6u4suVaeVhdmU5QWg1eVYpqVoZS7 USmTN9pUMLeVYaBzsXI19jtBfYB8CaKVqTqMtt7L07H1/kX5OhwPK7VTsEofqTYk+kd6 XY6TbC+Jv/063w4jwppMJkmU0DIaRxslroqFbklVudbeMfEcItweO1xJuekajsFht3/L QD2jqVtCxb0Buw/q98SwCMujXgI7a5cZndn7PSmvBJceC0cRw456rFviKsePJgyYEbL5 kE01oyaaj4MyI17KxEkfRY7kZWn15GEBF83uWwBa6Pxt4AqTAFdEe5Jf82XLfIV9li3P f3SA== X-Gm-Message-State: AOPr4FV0Jor6OaSTvJOiYwVzRK4IuIGwTtgMow1NwaVJTevwuI3YmIIxFgdkViwnXwrjTId4 X-Received: by 10.66.26.110 with SMTP id k14mr47101674pag.66.1461573505235; Mon, 25 Apr 2016 01:38:25 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s197sm26496077pfs.62.2016.04.25.01.38.22 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Apr 2016 01:38:24 -0700 (PDT) Date: Mon, 25 Apr 2016 17:41:11 +0900 From: AKASHI Takahiro To: James Morse Subject: Re: [PATCH v7 07/16] arm64: kvm: allows kvm cpu hotplug Message-ID: <20160425084111.GA19515@linaro.org> Mail-Followup-To: AKASHI Takahiro , James Morse , Marc Zyngier , linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , Geoff Levand , Catalin Marinas , Will Deacon References: <1459529620-22150-1-git-send-email-james.morse@arm.com> <1459529620-22150-8-git-send-email-james.morse@arm.com> <571656E9.5050402@arm.com> <57166CC9.4030804@arm.com> <57175BD7.30902@arm.com> <571765D1.9070207@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <571765D1.9070207@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160425_013848_222986_90557715 X-CRM114-Status: GOOD ( 27.42 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:400e:c03:0:0:0:231 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , Marc Zyngier , Catalin Marinas , Will Deacon , Geoff Levand , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org On Wed, Apr 20, 2016 at 12:19:45PM +0100, James Morse wrote: > Hi Marc, > > On 20/04/16 11:37, Marc Zyngier wrote: > > On 19/04/16 18:37, James Morse wrote: > >> It looks like x86 uses the extable to work around this, their vmx_vcpu_run() has: > >>> __ex(ASM_VMX_VMLAUNCH) "\n\t" > >> Where __ex ends up calling ____kvm_handle_fault_on_reboot(), with a nearby comment: > >>> * Hardware virtualization extension instructions may fault if a > >>> * reboot turns off virtualization while processes are running. > >>> * Trap the fault and ignore the instruction if that happens. > > > > I very much like that approach, to be honest. Tearing down a CPU is > > something exceptional, so let's make it an actual exception. > > > > It is now pretty easy to discriminate between KVM functions and stub > > functions thanks to your earlier patch, so if we end up calling the > > hyp-stub because we've torn down KVM's EL2, let's just return an > > appropriate error code (ARM_EXCEPTION_HYP_GONE), and handle it at EL1. > > Okay. kexec uses kvm_call_hyp() against the hyp-stub to do the kernel-copy and > hand over to purgatory, but we could change that to a new 'special' builtin > call, something like HVC_KEXEC_CALL_HYP. It never calls it with kvm loaded, so > there is no reason the calls have to be same. > > Given hibernate doesn't hit this issue, I will drop this hunk from this version > of the patch, and repost hibernate incorporating the feedback so far. I will > provide a patch for kexec to do the above. Thanks, but you don' have to. If the fix below is acceptable, we will merge it to our next kexec/kdump patch series. -Takahiro AKASHI > Thanks, > > James >From d70cf5d3202d819bd7f8c9072c61da783bf07b40 Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Mon, 25 Apr 2016 17:29:55 +0900 Subject: [PATCH] arm64: kvm: (experimental) fix kexec exception due to kexec reoot --- arch/arm/kvm/arm.c | 8 +------- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/virt.h | 5 +++++ arch/arm64/kernel/cpu-reset.S | 5 +---- arch/arm64/kernel/hyp-stub.S | 14 ++++++++++++-- arch/arm64/kvm/handle_exit.c | 4 ++++ 6 files changed, 24 insertions(+), 13 deletions(-) -- 2.8.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 962904a..0e92787 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -587,13 +587,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) /* * Re-check atomic conditions */ - if (unlikely(!__this_cpu_read(kvm_arm_hardware_enabled))) { - /* cpu has been torn down */ - ret = 0; - run->exit_reason = KVM_EXIT_FAIL_ENTRY; - run->fail_entry.hardware_entry_failure_reason - = (u64)-ENOEXEC; - } else if (signal_pending(current)) { + if (signal_pending(current)) { ret = -EINTR; run->exit_reason = KVM_EXIT_INTR; } diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index ebc8d0e..7f653ad 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -22,6 +22,7 @@ #define ARM_EXCEPTION_IRQ 0 #define ARM_EXCEPTION_TRAP 1 +#define ARM_EXCEPTION_HYP_GONE 2 #define KVM_ARM64_DEBUG_DIRTY_SHIFT 0 #define KVM_ARM64_DEBUG_DIRTY (1 << KVM_ARM64_DEBUG_DIRTY_SHIFT) diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index d406d2e..9079661 100644 --- a/arch/arm64/include/asm/virt.h +++ b/arch/arm64/include/asm/virt.h @@ -34,6 +34,11 @@ */ #define HVC_SET_VECTORS 1 +/* + * HVC_KEXEC_RESTART + */ +#define HVC_KEXEC_RESTART 2 + #define BOOT_CPU_MODE_EL1 (0xe11) #define BOOT_CPU_MODE_EL2 (0xe12) diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S index 11a5bc6..4d35331 100644 --- a/arch/arm64/kernel/cpu-reset.S +++ b/arch/arm64/kernel/cpu-reset.S @@ -41,10 +41,7 @@ ENTRY(__cpu_soft_restart) isb cbz x0, 1f // el2_switch? - mov x0, x1 // entry - mov x1, x2 // arg0 - mov x2, x3 // arg1 - mov x3, x4 // arg2 + mov x0, #HVC_KEXEC_RESTART hvc #0 // no return 1: mov x18, x1 // entry diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S index 6bba25c..7fad129 100644 --- a/arch/arm64/kernel/hyp-stub.S +++ b/arch/arm64/kernel/hyp-stub.S @@ -22,7 +22,8 @@ #include #include -#include +#include +#include #include #include @@ -70,7 +71,16 @@ el1_sync: msr vbar_el2, x1 b 9f -2: do_el2_call +2: cmp x0, #HVC_KEXEC_RESTART + b.eq 3f + mov x0, #ARM_EXCEPTION_HYP_GONE + b 9f + +3: mov lr, x1 + mov x0, x2 + mov x1, x3 + mov x2, x4 + blr lr 9: eret ENDPROC(el1_sync) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index eba89e4..31b5224 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -186,6 +186,10 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, exit_handler = kvm_get_exit_handler(vcpu); return exit_handler(vcpu, run); + case ARM_EXCEPTION_HYP_GONE: + /* due to kexec reboot */ + run->exit_reason = KVM_EXIT_SHUTDOWN; + return 0; default: kvm_pr_unimpl("Unsupported exception type: %d", exception_index);