From patchwork Mon Jan 9 06:24:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9504057 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 C926C60757 for ; Mon, 9 Jan 2017 06:40:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA175280DE for ; Mon, 9 Jan 2017 06:40:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AECEB2811C; Mon, 9 Jan 2017 06:40:22 +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=ham 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 09DEB28112 for ; Mon, 9 Jan 2017 06:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761029AbdAIGkA (ORCPT ); Mon, 9 Jan 2017 01:40:00 -0500 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]:51800 "EHLO outprodmail02.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760657AbdAIGZi (ORCPT ); Mon, 9 Jan 2017 01:25:38 -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 v096Odx3005146 for ; Mon, 9 Jan 2017 01:25:37 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id CFBD986 for ; Mon, 9 Jan 2017 01:25:37 -0500 (EST) Received: from sendprodmail01.cc.columbia.edu (sendprodmail01.cc.columbia.edu [128.59.72.13]) by hazelnut (Postfix) with ESMTP id 9B37C89 for ; Mon, 9 Jan 2017 01:25:37 -0500 (EST) Received: from mail-qk0-f199.google.com (mail-qk0-f199.google.com [209.85.220.199]) by sendprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PbUx040522 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:25:37 -0500 Received: by mail-qk0-f199.google.com with SMTP id d75so52974445qkc.0 for ; Sun, 08 Jan 2017 22:25:37 -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=pfM71ARpcDc3ZCBShi5EFDn7jzS4wweUy/DuNvuGAHM=; b=TK4vn1hYz7FJTYijH65qvwEepxmBWBd537MO2qd+xYzNuBV6zEVo3UgxCPKdtNNUXQ VM0WzncBOuYqonqNUumH1cH7lqfJUjpMFquTxvgdnhve/Bsk5WaPu8oNvDHuDnVx2QQp LfSC+WcS0QDgR3x1ZKrfJnr0juNdYGKSsgQi4M8/2cTz7l2f3RQtDnDWJoDIuIsCQ7p/ gXlgVn8n36skFa2KPTvecKwCMtLxcrv3kT6eqWevoJCQ4AGcLeVtiZEF2xt4Q2IsJ+Df APe122U5ZBfWSi6E5KuzA4/Gax+HlzzzhWzEAoXYmnvoIyDfQl5CE8HqkB8O60qazMte OC0A== X-Gm-Message-State: AIkVDXJANWWrulNUOHz40KDVigoiPr5IJWulR3uQS1Jl6Xpp3w8UW2JoyIQY0cQWcv7VAjsom30o07GYljfcvZvKkqRswbmoPKIug+uYdVa1/9Z5jKGzBz5zSbQp+X5L5oqXFgI931pt3WU= X-Received: by 10.200.50.2 with SMTP id x2mr12023207qta.291.1483943137256; Sun, 08 Jan 2017 22:25:37 -0800 (PST) X-Received: by 10.200.50.2 with SMTP id x2mr12023185qta.291.1483943137110; Sun, 08 Jan 2017 22:25:37 -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.25.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:25:36 -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 05/55] KVM: arm64: Add vcpu_mode_el2 primitive to support nesting Date: Mon, 9 Jan 2017 01:24:01 -0500 Message-Id: <1483943091-1364-6-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 From: Christoffer Dall When running a nested hypervisor we occasionally have to figure out if the mode we are switching into is the virtual EL2 mode or a regular EL0/1 mode. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_emulate.h | 6 ++++++ arch/arm64/include/asm/kvm_emulate.h | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/arch/arm/include/asm/kvm_emulate.h b/arch/arm/include/asm/kvm_emulate.h index 9a8a45a..399cd75e 100644 --- a/arch/arm/include/asm/kvm_emulate.h +++ b/arch/arm/include/asm/kvm_emulate.h @@ -77,6 +77,12 @@ static inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu) return 1; } +/* We don't support nesting on arm */ +static inline bool vcpu_mode_el2(const struct kvm_vcpu *vcpu) +{ + return false; +} + static inline unsigned long *vcpu_pc(struct kvm_vcpu *vcpu) { return &vcpu->arch.ctxt.gp_regs.usr_regs.ARM_pc; diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index f5ea0ba..830be2e 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -143,6 +143,18 @@ static inline bool vcpu_mode_priv(const struct kvm_vcpu *vcpu) return mode != PSR_MODE_EL0t; } +static inline bool vcpu_mode_el2(const struct kvm_vcpu *vcpu) +{ + u32 mode; + + if (vcpu_mode_is_32bit(vcpu)) + return false; + + mode = *vcpu_cpsr(vcpu) & PSR_MODE_MASK; + + return mode == PSR_MODE_EL2h || mode == PSR_MODE_EL2t; +} + static inline u32 kvm_vcpu_get_hsr(const struct kvm_vcpu *vcpu) { return vcpu->arch.fault.esr_el2;