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: 108161 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp6154398obm; Tue, 18 Jul 2017 10:04:46 -0700 (PDT) X-Received: by 10.84.191.131 with SMTP id a3mr2744944pld.279.1500397486008; Tue, 18 Jul 2017 10:04:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500397486; cv=none; d=google.com; s=arc-20160816; b=FJTwORNkfNceNHzzEu0O1oiUlmF+onsx9Bi8zAYLOKRXhPXF0UOA6YKePqJ7e+KIO5 zdK3l0FAB0nAd01ca8HCoA+25bveY/Rgfu7OQrzx9Y9G9lnNJGM6DJVOO0C8mAEsw9gY TTHvXGunV9wuJGqg37BD+JaHOhJFOm82p7EDCRwmSP6+e1n42vo6pJNqPYIdfd1UPFU3 fMzhKdvZd7i/IUuBl+lNh3vxsVaNGXJ/6eTkn+pQfwYJnzEC68XWmvWDLkrr0TCbD+EV eBA1dGlvIrwOzv2l/57ThecsdGc3oLXaThibu6vpLZANe7g1jaeOaOoyTw195iESk6Ub 5nxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=wzOSyQMrKTDK4dX0Too1hK5ddjKST2O3EkJkca+aWQM=; b=filx9kqaJ7eFE7+ltfOsMSUskqv8zoP/VtLhnbfv9ci7FLnOdz7YocUSnUOLfLaU6t 37k8azF2gAad423DzLRwdzIJ0nYKxSiRUYALLA9fQ4p48iYFSEiziKDM60Mqfd9YgB03 q4lpaPuFYoZdPO/opm8r2vhAkbT6zoh9sh3bP5ttzOrK1qTLK3koW+StqFqoVkKnJkMd 65/TQiiMk8ze3jC0tV76ZkCB9r/eDLeKUcEVbqTLcld+6dhMWLH9n4krnfO0Blutc6Nf eIB7GhnalZSVJd/crdQroxwPQUcbuCNoO2t1XlrFc5EG0E4LoCSHUn0G0l0ZevFpWarI X+Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=fUKpFGRD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9si2154321pfd.54.2017.07.18.10.04.45; Tue, 18 Jul 2017 10:04:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=fUKpFGRD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752681AbdGRRE2 (ORCPT + 25 others); Tue, 18 Jul 2017 13:04:28 -0400 Received: from mail-io0-f182.google.com ([209.85.223.182]:35586 "EHLO mail-io0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752366AbdGRRAW (ORCPT ); Tue, 18 Jul 2017 13:00:22 -0400 Received: by mail-io0-f182.google.com with SMTP id k71so16786653iod.2 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=Rh1VkbuYps/8ZA3czNZttlTBTopdLTuOB9MQj9VtoTsQMuxbtexvtJhIHBlwZNE/um HHG8mChuutlr3E7LzrlZ3CnPys9gFeElx1oqGWf204c7ysVzcP07mQtMcE/ItpnogMz0 bL7LF8H42N+GgoFJlqm1+3Yf9OajSnyO7u7ZIWLVygAbp89FDAeEeur6GyeJ09NMmp73 pTYhriKl1DbYkKl5OqfEpI9DAnM7SjcKv798km4bQ/CtYqBRnksgxEDfRHcZm1goaoc1 cdKfGbumJkAHT+jgrCKH2A4H1J0X0ngMhcVrpvZXFz3XGPDxhIAOp8f0fVr/ubdFUWN3 34iw== X-Gm-Message-State: AIVw1122V7fydkcaWbH+XWWfSP3gBkJlFl5ml/tDyJHbPasnitvvQ4cQ NNzLDgnR7/8ORA/j 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(+) -- 1.9.1 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;