From patchwork Tue Jul 18 16:58:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9849035 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 EB6D3600CC for ; Tue, 18 Jul 2017 17:05:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2D5B20602 for ; Tue, 18 Jul 2017 17:05:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6E9723B23; Tue, 18 Jul 2017 17:05:08 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 51F3F20602 for ; Tue, 18 Jul 2017 17:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752649AbdGRRE0 (ORCPT ); Tue, 18 Jul 2017 13:04:26 -0400 Received: from mail-io0-f175.google.com ([209.85.223.175]:33619 "EHLO mail-io0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752364AbdGRRAV (ORCPT ); Tue, 18 Jul 2017 13:00:21 -0400 Received: by mail-io0-f175.google.com with SMTP id 5so16508014iow.0 for ; Tue, 18 Jul 2017 10:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wzOSyQMrKTDK4dX0Too1hK5ddjKST2O3EkJkca+aWQM=; b=fUKpFGRDyiYqpLboL0wSocI5Vg4NvdCOEljPnTRYwiul/Ca1SOFuXz6JAUqustsd/K R3ZS241LNBUazWfwLVWRnSyxXuvZxm4NFQoR7yDD3nz8KZtFcIp74MxKuqS3dachUYt2 JKcEbkPQo0xl83Dh0b9A7dMBas1WzLsnTccwA= 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=wzOSyQMrKTDK4dX0Too1hK5ddjKST2O3EkJkca+aWQM=; b=kNcbxH6x2f8jDStZnelD+H12WSOgB+p3tNTicRpymuNH3F4An9NkFOqSvz8vKae3Uf MxDdS4I9SD6gbxeTJXTEWKm68+6jNBy5OR3af+853/aFooc+zDhQnNM80Ed3tqs1ty5T BwnOQ/A4bWEYGnjzKnzgGLu+xxqUGDwLc/EkTJAtphwgPGx0PlVqE43oXRI3RiH3hODl j5l+m4wV135Kj4elGlY1IlaEIHFV9gb3xBmX554rFmh922phd+wJ8vvVXPkHl07QVWCk eRCFz51ekI/VZZYC1JZfd7ZXExW+TBAh9NFiwvedRCETX8LNo7dULmX8eFiDl4KdWHFV Oorg== X-Gm-Message-State: AIVw110UfpEVmeXisA2HqN/wdb9ZXytBTNN0teOsEqAVqVWXoeXRTt12 VjB4yFH66QRfUkQj X-Received: by 10.107.205.136 with SMTP id d130mr2617552iog.109.1500397219927; Tue, 18 Jul 2017 10:00:19 -0700 (PDT) Received: from node.jintackl-qv26972.kvmarm-pg0.wisc.cloudlab.us (c220g1-030822.wisc.cloudlab.us. [128.104.222.82]) by smtp.gmail.com with ESMTPSA id j96sm1413075ioo.49.2017.07.18.10.00.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 10:00:19 -0700 (PDT) From: Jintack Lim To: kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Cc: corbet@lwn.net, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, akpm@linux-foundation.org, mchehab@kernel.org, cov@codeaurora.org, daniel.lezcano@linaro.org, david.daney@cavium.com, mark.rutland@arm.com, suzuki.poulose@arm.com, stefan@hello-penguin.com, andy.gross@linaro.org, wcohen@redhat.com, ard.biesheuvel@linaro.org, shankerd@codeaurora.org, vladimir.murzin@arm.com, james.morse@arm.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jintack Lim Subject: [RFC PATCH v2 26/38] KVM: arm64: Add macros to support the virtual EL2 with VHE Date: Tue, 18 Jul 2017 11:58:52 -0500 Message-Id: <1500397144-16232-27-git-send-email-jintack.lim@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> References: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP These macros will be used to support the virtual EL2 with VHE. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_emulate.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 3017234..68aafbd 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -173,6 +173,30 @@ static inline bool vcpu_mode_el2(const struct kvm_vcpu *vcpu) return mode == PSR_MODE_EL2h || mode == PSR_MODE_EL2t; } +static inline bool vcpu_el2_e2h_is_set(const struct kvm_vcpu *vcpu) +{ + return (vcpu_sys_reg(vcpu, HCR_EL2) & HCR_E2H); +} + +static inline bool vcpu_el2_tge_is_set(const struct kvm_vcpu *vcpu) +{ + return (vcpu_sys_reg(vcpu, HCR_EL2) & HCR_TGE); +} + +static inline bool is_hyp_ctxt(const struct kvm_vcpu *vcpu) +{ + /* + * We are in a hypervisor context if the vcpu mode is EL2 or + * E2H and TGE bits are set. The latter means we are in the user space + * of the VHE kernel. ARMv8.1 ARM describes this as 'InHost' + */ + if (vcpu_mode_el2(vcpu) || + (vcpu_el2_e2h_is_set(vcpu) && vcpu_el2_tge_is_set(vcpu))) + return true; + + return false; +} + static inline u32 kvm_vcpu_get_hsr(const struct kvm_vcpu *vcpu) { return vcpu->arch.fault.esr_el2;