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: 9503831 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 1C2B060757 for ; Mon, 9 Jan 2017 06:28:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09A2D281D2 for ; Mon, 9 Jan 2017 06:28:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F16082823E; Mon, 9 Jan 2017 06:28:06 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6CFAC280D0 for ; Mon, 9 Jan 2017 06:28:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cQTR5-000538-Ol; Mon, 09 Jan 2017 06:28:03 +0000 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cQTPK-00022D-3J for linux-arm-kernel@lists.infradead.org; Mon, 09 Jan 2017 06:26:17 +0000 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 v096P4xe005194 for ; Mon, 9 Jan 2017 01:25:54 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 07B0888 for ; Mon, 9 Jan 2017 01:25:54 -0500 (EST) Received: from sendprodmail04.cc.columbia.edu (sendprodmail04.cc.columbia.edu [128.59.72.16]) by hazelnut (Postfix) with ESMTP id C8A0C8A 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 sendprodmail04.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PrBU004802 (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 f4so58595127qte.1 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=dEUmjmgnuDQfPzG7ZpdsU+nyJRXNuROnDIB6XrHH49FrA48fOCPZSWk4t/BrGwLPoS bujoFWhkjqPORw1L5svAB73EFf5ymuAexib2/Mhea7SvWsNItgKdHrlOhPn8pmA6+c1W BU2KsrinGM+ODAhIFe+UXg6UsNtsyHFIJbxFOgemhJpqXPGfkelhc1irBZzlloG2v6Z0 x6cVb0KAvx918X7RHdjW4HCvo4adK4f2qS2D5Jg0JmHmFIJaI3F3/2vcbODf1jIYNSpx aIqOtKIq9+SudMFaeqE5FvCXzQcJ+fRuZCkTMnjk2K2KA1FBMfvsrxRnyeu6LdstkkZm O3yQ== X-Gm-Message-State: AIkVDXKPmloPZOskv01ZXf+Mh8MOdm9hIlmXjfiwWbQj+ZAwNDTRzNBCtFVgiQPvf9g3ItNhOYLhaDO86l0y7WN1+A/fdUXN2Qe6qeUjH7JOwmpnYP0cbm33N6B0CW50bEvc1n6Y4yFyZblLArBe8lotNbYSb+M7oKwhpw== X-Received: by 10.55.163.17 with SMTP id m17mr73356750qke.285.1483943153448; 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 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.16 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170108_222614_649650_74056422 X-CRM114-Status: GOOD ( 12.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jintack@cs.columbia.edu MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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) {