From patchwork Mon Jan 9 06:24:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9504005 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 9669360757 for ; Mon, 9 Jan 2017 06:37:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84E4D2817F for ; Mon, 9 Jan 2017 06:37:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79BBF281D2; Mon, 9 Jan 2017 06:37:03 +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 19E2A28112 for ; Mon, 9 Jan 2017 06:37:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163778AbdAIGgl (ORCPT ); Mon, 9 Jan 2017 01:36:41 -0500 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]:51953 "EHLO outprodmail02.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939508AbdAIGZy (ORCPT ); Mon, 9 Jan 2017 01:25:54 -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 v096P4xg005194 for ; Mon, 9 Jan 2017 01:25:54 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 1ADF082 for ; Mon, 9 Jan 2017 01:25:54 -0500 (EST) Received: from sendprodmail02.cc.columbia.edu (sendprodmail02.cc.columbia.edu [128.59.72.14]) by hazelnut (Postfix) with ESMTP id CA9038D for ; Mon, 9 Jan 2017 01:25:53 -0500 (EST) Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by sendprodmail02.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PrNN042049 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:25:53 -0500 Received: by mail-qt0-f200.google.com with SMTP id l7so63075836qtd.2 for ; Sun, 08 Jan 2017 22:25:53 -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=5h7d2X4DsoC1aps32MkQQY1FrrTjgXIxQRKH5CsTBSo=; b=aqsUWyvuBEvzXO5O8H6+xeqfAdRBV2/KJ2/jdrySCV1FCuDgVSKoGRjzzhdlQ7Smva YqtfvM7IDyKU+T4Y3FxxeFX0wqKKOM3/AxmwZQyDoCH/0MFnYgggb1PUsq+dCSGzNGsW 15OvMpQhCNlLGWJ/IRnPfLmieoWt+4eHtGXPbmofCiQVh0ybtWAM6NikshkLx9UjTMZs 4EihJHPgHy3yDgs9Y3sXrQYIsDNWAxUzqGcf7niF07GiyxAsu/AJRUpN8aTAqmTAbCAr 7MLAKC6Y8prHG9lbUQv12SfDbisrf99fEqU2CljR1cRf+cs4dKZrSJ6/H7JDOrZ3xeIr sEig== X-Gm-Message-State: AIkVDXKuackzQblm5EguDw4enaiJZlq0l60zB6+rhhzMl00oZrQJsaGX5Mnr2X3OkXEKv1P0Xv9bc8vKAI3bNARJ1z6R4WjrRjQ/B4FLEPDvOWSly7+XB724/OzSiuhgKuaUKidE9/rce6c= X-Received: by 10.55.163.17 with SMTP id m17mr73356756qke.285.1483943153449; Sun, 08 Jan 2017 22:25:53 -0800 (PST) X-Received: by 10.55.163.17 with SMTP id m17mr73356738qke.285.1483943153306; Sun, 08 Jan 2017 22:25:53 -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.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:25:52 -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 16/55] KVM: arm64: Forward VM reg traps to the guest hypervisor Date: Mon, 9 Jan 2017 01:24:12 -0500 Message-Id: <1483943091-1364-17-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.14 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Forward virtual memory register traps to the guest hypervisor if it has set corresponding bits to the virtual HCR_EL2. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index b8e993a..0f5d21b 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -90,6 +90,23 @@ static bool access_dcsw(struct kvm_vcpu *vcpu, return true; } +static bool forward_vm_traps(struct kvm_vcpu *vcpu, struct sys_reg_params *p) +{ + u64 hcr_el2 = vcpu_el2_reg(vcpu, HCR_EL2); + + /* If this is a trap from the virtual EL2, the host handles */ + if (vcpu_mode_el2(vcpu)) + return false; + + /* If the guest wants to trap on R/W operation, forward this trap */ + if ((hcr_el2 & HCR_TVM) && p->is_write) + return true; + else if ((hcr_el2 & HCR_TRVM) && !p->is_write) + return true; + + return false; +} + /* * Generic accessor for VM registers. Only called as long as HCR_TVM * is set. If the guest enables the MMU, we stop trapping the VM @@ -101,6 +118,9 @@ static bool access_vm_reg(struct kvm_vcpu *vcpu, { bool was_enabled = vcpu_has_cache_enabled(vcpu); + if (forward_vm_traps(vcpu, p)) + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); + BUG_ON(!vcpu_mode_el2(vcpu) && !p->is_write); if (!p->is_write) {