From patchwork Mon Jan 9 06:24:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9503999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E967C60757 for ; Mon, 9 Jan 2017 06:36:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9D1E27FA8 for ; Mon, 9 Jan 2017 06:36:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE4EF2811C; Mon, 9 Jan 2017 06:36:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4526C27FA8 for ; Mon, 9 Jan 2017 06:36:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760569AbdAIGgO (ORCPT ); Mon, 9 Jan 2017 01:36:14 -0500 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]:53148 "EHLO outprodmail02.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759197AbdAIGeo (ORCPT ); Mon, 9 Jan 2017 01:34:44 -0500 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail02.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096X4j0008216 for ; Mon, 9 Jan 2017 01:34:43 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 516E46D for ; Mon, 9 Jan 2017 01:34:43 -0500 (EST) Received: from sendprodmail01.cc.columbia.edu (sendprodmail01.cc.columbia.edu [128.59.72.13]) by hazelnut (Postfix) with ESMTP id 38D986D for ; Mon, 9 Jan 2017 01:34:43 -0500 (EST) Received: from mail-qk0-f198.google.com (mail-qk0-f198.google.com [209.85.220.198]) by sendprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096Yhiu044335 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:34:43 -0500 Received: by mail-qk0-f198.google.com with SMTP id a195so63360922qkg.3 for ; Sun, 08 Jan 2017 22:34:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4Rr96zZ+eSX+6trb2Fcxr1YK5jMIDtoWEsrCNKGfkPw=; b=ErYUyK6B4Nw7XXSO7xFqx8tszhSeURBCtcjOwcBEIpCwX0c2mGP3vTmY+ZS8Vhe8mb boogRp8H/aTOJUiGnaeGb7zGODAxAGQKsHvzcc2wtPwIu1m151h/IaVvBHJcMZqinjT1 sfpYFbyMwRx//zSfFNj65jTfV5Ney6JweI9UWejzYlrz1D8MuFdPMpMNJqJ3sNqa+4Ou RMEAobcTJM7lqRQJpsLIfwHtmvpIf5zbmJI/HFTb8MCVrntmFYAhkBrLLoV+ma76X5Lh 2t2DMIJM8DpQ2x7/nRQHjsbYKF8aYalQoJm54/l7Kcl/GzypSGoy9/EpTNY2cRVaJ23Y Tu0g== X-Gm-Message-State: AIkVDXIkaytIlVGLTPzJGYm07sHRLte3vuGdWevpzkN7ytB4kgCTGCkUxG89hgT7sfUpQahcT0EJjbF6nEOq38+MudO8InvKKSTg8y/z9sp98vxNRu2b6lFgRzGh95aDlyj2Q07jDqklZiA= X-Received: by 10.200.44.236 with SMTP id 41mr3863288qtx.267.1483943172362; Sun, 08 Jan 2017 22:26:12 -0800 (PST) X-Received: by 10.200.44.236 with SMTP id 41mr3862948qtx.267.1483943163154; Sun, 08 Jan 2017 22:26:03 -0800 (PST) Received: from jintack.cs.columbia.edu ([2001:18d8:ffff:16:21a:4aff:feaa:f900]) by smtp.gmail.com with ESMTPSA id h3sm8623257qtc.6.2017.01.08.22.26.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:26:02 -0800 (PST) From: Jintack Lim To: christoffer.dall@linaro.org, marc.zyngier@arm.com, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, vladimir.murzin@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, james.morse@arm.com, lorenzo.pieralisi@arm.com, kevin.brodsky@arm.com, wcohen@redhat.com, shankerd@codeaurora.org, geoff@infradead.org, andre.przywara@arm.com, eric.auger@redhat.com, anna-maria@linutronix.de, shihwei@cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jintack@cs.columbia.edu Subject: [RFC 24/55] KVM: arm64: Forward FP exceptions to the guest hypervisor Date: Mon, 9 Jan 2017 01:24:20 -0500 Message-Id: <1483943091-1364-25-git-send-email-jintack@cs.columbia.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> References: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.78 on 128.59.72.13 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Forward exceptions due to floating-point register accesses to the guest hypervisor if it has set CPTR_EL2.TFP bit. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_nested.h | 1 + arch/arm64/kernel/asm-offsets.c | 1 + arch/arm64/kvm/handle_exit.c | 3 +++ arch/arm64/kvm/handle_exit_nested.c | 6 ++++++ arch/arm64/kvm/hyp/entry.S | 14 ++++++++++++++ arch/arm64/kvm/hyp/hyp-entry.S | 2 +- 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h index 8d36935..54c5ce5 100644 --- a/arch/arm64/include/asm/kvm_nested.h +++ b/arch/arm64/include/asm/kvm_nested.h @@ -3,4 +3,5 @@ int handle_hvc_nested(struct kvm_vcpu *vcpu); int handle_wfx_nested(struct kvm_vcpu *vcpu, bool is_wfe); +int kvm_handle_fp_asimd(struct kvm_vcpu *vcpu, struct kvm_run *run); #endif diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 4a2f0f0..b635f1a 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -131,6 +131,7 @@ int main(void) DEFINE(CPU_FP_REGS, offsetof(struct kvm_regs, fp_regs)); DEFINE(VCPU_FPEXC32_EL2, offsetof(struct kvm_vcpu, arch.ctxt.sys_regs[FPEXC32_EL2])); DEFINE(VCPU_HOST_CONTEXT, offsetof(struct kvm_vcpu, arch.host_cpu_context)); + DEFINE(VIRTUAL_CPTR_EL2, offsetof(struct kvm_vcpu, arch.ctxt.el2_regs[CPTR_EL2])); #endif #ifdef CONFIG_CPU_PM DEFINE(CPU_SUSPEND_SZ, sizeof(struct cpu_suspend_ctx)); diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 046fdf8..308f5c5 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -195,6 +195,9 @@ static int kvm_handle_eret(struct kvm_vcpu *vcpu, struct kvm_run *run) [ESR_ELx_EC_BREAKPT_LOW]= kvm_handle_guest_debug, [ESR_ELx_EC_BKPT32] = kvm_handle_guest_debug, [ESR_ELx_EC_BRK64] = kvm_handle_guest_debug, +#ifdef CONFIG_KVM_ARM_NESTED_HYP + [ESR_ELx_EC_FP_ASIMD] = kvm_handle_fp_asimd, +#endif }; static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) diff --git a/arch/arm64/kvm/handle_exit_nested.c b/arch/arm64/kvm/handle_exit_nested.c index 871ecfc..7544c6d 100644 --- a/arch/arm64/kvm/handle_exit_nested.c +++ b/arch/arm64/kvm/handle_exit_nested.c @@ -43,3 +43,9 @@ int handle_wfx_nested(struct kvm_vcpu *vcpu, bool is_wfe) return -EINVAL; } + +/* This is only called when virtual CPTR_EL2.TFP bit is set. */ +int kvm_handle_fp_asimd(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); +} diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S index 12ee62d..a76f102 100644 --- a/arch/arm64/kvm/hyp/entry.S +++ b/arch/arm64/kvm/hyp/entry.S @@ -158,6 +158,20 @@ abort_guest_exit_end: 1: ret ENDPROC(__guest_exit) +ENTRY(__fpsimd_guest_trap) +#ifdef CONFIG_KVM_ARM_NESTED_HYP +// If virtual CPTR_EL2.TFP is set, then foward it to the nested hyp. + mrs x1, tpidr_el2 + ldr x0, [x1, #VIRTUAL_CPTR_EL2] + and x0, x0, #CPTR_EL2_TFP + cbnz x0, 1f +#endif + b __fpsimd_guest_restore +1: + mov x0, #ARM_EXCEPTION_TRAP + b __guest_exit +ENDPROC(__fpsimd_guest_trap) + ENTRY(__fpsimd_guest_restore) stp x2, x3, [sp, #-16]! stp x4, lr, [sp, #-16]! diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S index 4e92399..d83494b 100644 --- a/arch/arm64/kvm/hyp/hyp-entry.S +++ b/arch/arm64/kvm/hyp/hyp-entry.S @@ -108,7 +108,7 @@ el1_trap: /* Guest accessed VFP/SIMD registers, save host, restore Guest */ cmp x0, #ESR_ELx_EC_FP_ASIMD - b.eq __fpsimd_guest_restore + b.eq __fpsimd_guest_trap mrs x1, tpidr_el2 mov x0, #ARM_EXCEPTION_TRAP