From patchwork Tue Jul 18 16:59:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 108152 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp6149967obm; Tue, 18 Jul 2017 10:01:19 -0700 (PDT) X-Received: by 10.99.8.129 with SMTP id 123mr2621121pgi.87.1500397279815; Tue, 18 Jul 2017 10:01:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500397279; cv=none; d=google.com; s=arc-20160816; b=iTd/B/t+RXyg2HVUG9202Y7kBhruKZStuYRKDdvWl3AHl4qVX5XKpLnw0sfDi3Ry/l WFQCIz8WNkA3ve4qBa5Z8ijFlJjmzHeRfxxCm3mujfOe3BTn7v89wBctRzijjanhGBS6 zHY+kU5Hp+0q5Ahqq/rU6AI0Zhuq7ib6ScR1lgrBWnXnoE0yTYqTLamLj5WL6F/d95+8 IPZzBl67yBcUHtY2VhhdBBsosqcvjeC5fglyDwYtVZU4fTa0u7+30gWmINQH9AZg9jUr RCqKiDEfXzFP3el4HvnNyEXJ7J8pQ5w9XxMyDoAXKfvGU7WdumusUWn/HQ+hl0PkGRPE Ky2g== 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=e+LwPpKMUEjdN4Ztkd8bGFQfsUcsPv+yKPP8eBpKm5Y=; b=ZjxEGh8vyIuSAVOMPhIddJm8an3eDPLsjw1qi08N5kwzJotSPuTZGh6Qzcn/Dngvaz P/a1v1/L2ieQFGTYW2STzWy8GfeMpQQ3IJAz5MA236xLkyx8LCaEh6JXGwcTjYtMLrJu 35Y2ZZWNj4n+VS9sxCV5SWnpDS0Aca+VxvtuHmA4OvjM5MUoDgom7x7/jcEbDeLTTErT 7fEAZqc2aoxxZ4uchoQzuqLwZkBu7gh3z7CF3lMDOueI1hF5G8fGayBDJkN3lRYd3TVs ngVO9/LlZWQOfo6+8zf2sRC7ni/siuDCCq5Fw6guehYikq6+rYSYFlG+GV1jIOV6wER3 Q26A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=X/bW+piw; 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 8si2124343pfs.181.2017.07.18.10.01.17; Tue, 18 Jul 2017 10:01:19 -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=X/bW+piw; 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 S1752564AbdGRRAo (ORCPT + 25 others); Tue, 18 Jul 2017 13:00:44 -0400 Received: from mail-it0-f54.google.com ([209.85.214.54]:36059 "EHLO mail-it0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752434AbdGRRAk (ORCPT ); Tue, 18 Jul 2017 13:00:40 -0400 Received: by mail-it0-f54.google.com with SMTP id a62so23805289itd.1 for ; Tue, 18 Jul 2017 10:00:39 -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=e+LwPpKMUEjdN4Ztkd8bGFQfsUcsPv+yKPP8eBpKm5Y=; b=X/bW+piw9cj4xkfjnWJWv7vYdxhpwh1iTU3stB37FXsmxQ8CpN0kRH6eo6UddYb7Hl n8ziqx4VrlCcma7keBezHBwp70w2ZFvFZ/O7fm+PZUG6KRBgDJ81Kc/v+Hhx6+vOeEKe VknUi7uDAbvoiBrdAjyKl72uC8RznX+C15hUk= 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=e+LwPpKMUEjdN4Ztkd8bGFQfsUcsPv+yKPP8eBpKm5Y=; b=eikBa/SopBd8AkGVyzDycnesjqevC9H5Vh878EMBgSC9jmK5mKdnGFFHqcSEd+Amjw 2+2c4Yj1xh7EKYmZoaz2Zm169coFvdK24LfQOvplqd3lgNRs5EjTsRSQYuJFiOt0Kq9U 3ADKmYqIL6cs2p4QpFnDWNOTs4IjVsunJ80PacnSDnVDBW5JiiMd+pBXbz9tG0F2TKoT wgJCp1wbuegn17YJxxo6EeiLrUYYkwe11IaJs34fDmMC/p+UNlzZ30Kol15jxJRNmGQw YqY88WImdx0nO0gx0pY8GEfM9e9MKxJRnQGr1qs2pKpH+jzLDV/pvITHyzP7rMY4Y5T9 EUQA== X-Gm-Message-State: AIVw111yE6jx2lTUeAkiTNTWOkf77G+v6XRHmF003FeWvxeRkb8xHiFX IEgDTv23RvXuWyts X-Received: by 10.36.135.204 with SMTP id f195mr3717286ite.91.1500397239178; Tue, 18 Jul 2017 10:00:39 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 10:00:38 -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 36/38] KVM: arm64: Respect virtual HCR_EL2.TVM and TRVM settings Date: Tue, 18 Jul 2017 11:59:02 -0500 Message-Id: <1500397144-16232-37-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 Forward the EL1 virtual memory register traps to the virtual EL2 if they are not coming from the virtual EL2 and the virtual HCR_EL2.TVM or TRVM bit is set. This is for recursive nested virtualization. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) -- 1.9.1 diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 3559cf7..3e4ec5e 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -135,6 +135,27 @@ static inline bool el12_reg(struct sys_reg_params *p) return (p->Op1 == 5); } +/* This function is to support the recursive nested virtualization */ +static bool forward_vm_traps(struct kvm_vcpu *vcpu, struct sys_reg_params *p) +{ + u64 hcr_el2 = vcpu_sys_reg(vcpu, HCR_EL2); + + /* If a trap comes from the virtual EL2, the host hypervisor handles. */ + if (vcpu_mode_el2(vcpu)) + return false; + + /* + * If the virtual HCR_EL2.TVM or TRVM bit is set, we need to foward + * this trap to the virtual EL2. + */ + 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 @@ -152,6 +173,9 @@ static bool access_vm_reg(struct kvm_vcpu *vcpu, if (el12_reg(p) && forward_nv_traps(vcpu)) return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); + if (!el12_reg(p) && forward_vm_traps(vcpu, p)) + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); + /* * Redirect EL1 register accesses to the corresponding EL2 registers if * they are meant to access EL2 registers.