From patchwork Tue Oct 3 03:10:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9981555 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 9BC8D602B8 for ; Tue, 3 Oct 2017 03:17:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EA672887F for ; Tue, 3 Oct 2017 03:17:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8398128885; Tue, 3 Oct 2017 03:17:31 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable 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 165792887F for ; Tue, 3 Oct 2017 03:17:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751318AbdJCDRT (ORCPT ); Mon, 2 Oct 2017 23:17:19 -0400 Received: from mail-it0-f44.google.com ([209.85.214.44]:55829 "EHLO mail-it0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751905AbdJCDLy (ORCPT ); Mon, 2 Oct 2017 23:11:54 -0400 Received: by mail-it0-f44.google.com with SMTP id 4so9725469itv.4 for ; Mon, 02 Oct 2017 20:11:54 -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=8pHfRnT3Ca2lCPhMaDfK5riO0YKJi4Xl6ZAuana/B4Y=; b=B2aCHyWw5gmSrK6M/Kha/Ukrre6yUlffBR+hBZGE61IW07VdnZmMRr9Rv4zWlxrOeh g30txjIrSO50QZxy+eljEV4imxwvO0IxCmGGM5gpk/iBZ7Cb3S7naHWnWOYLJZNXqi3X /qwk7KbLPsefBgPbYjqIkHMq33RnJiIJOP5+k= 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=8pHfRnT3Ca2lCPhMaDfK5riO0YKJi4Xl6ZAuana/B4Y=; b=WcNOR+jsBrnWl33bSVwnNK1e4octSo5mARXcbywtk1AVOaePAbZtjykdtoBmaOaNP0 ysOhyGRa2nJ9Oe/XhVdsTlVic20EtX04oVyiCkuaF62VY55lUCvGKkdpaEEGgQ6sReeb +GTS3WitzXAQI/vdaGuMpSvO3PwRcVabLSmyTB9+WK3XsGZ38j4xx/mG/WN9YhHO/jsG Qcxb1xLLM4kT0833JDJn3zZ6NLq49Lc26nokqV1S/wBVo22I1tjA0E+YiqQgkPOoSfMr 0IwEDhbrcKNe6PhBdf2hL9lWz2whByNbjHP7GmEYIrNMBsIFTgVS8TwcZQSX2NiwCRks MgtA== X-Gm-Message-State: AMCzsaUz2r5kveNGrTTiDJedWou5ImF+5s85wXRnl+Xg0nOii2rEWRix u+gcYuj8EMkfKl6I5dH3jcZZag== X-Google-Smtp-Source: AOwi7QCOD66O7K6UPWs+EeraEyE50orMOq/y7o9+ZMMi/1lx/gcTjeGIImUXclR2+0JKPAG+BpkrVg== X-Received: by 10.36.84.82 with SMTP id t79mr22627575ita.98.1507000314041; Mon, 02 Oct 2017 20:11:54 -0700 (PDT) Received: from node.jintackl-qv28633.kvmarm-pg0.wisc.cloudlab.us (c220g1-031126.wisc.cloudlab.us. [128.104.222.76]) by smtp.gmail.com with ESMTPSA id h84sm5367193iod.72.2017.10.02.20.11.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Oct 2017 20:11:53 -0700 (PDT) From: Jintack Lim To: christoffer.dall@linaro.org, marc.zyngier@arm.com, kvmarm@lists.cs.columbia.edu Cc: jintack@cs.columbia.edu, pbonzini@redhat.com, rkrcmar@redhat.com, catalin.marinas@arm.com, will.deacon@arm.com, linux@armlinux.org.uk, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jintack Lim Subject: [RFC PATCH v2 14/31] KVM: arm/arm64: Forward the guest hypervisor's stage 2 permission faults Date: Mon, 2 Oct 2017 22:10:56 -0500 Message-Id: <1507000273-3735-12-git-send-email-jintack.lim@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507000273-3735-1-git-send-email-jintack.lim@linaro.org> References: <1507000273-3735-1-git-send-email-jintack.lim@linaro.org> 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 We can have discrepancies between the nested stage 2 page table and the shadow one in a couple of cases. For example, the guest hypervisor can mark a page writable but the host hypervisor maps the page read-only in the shadow page table, if using something like KSM on the host level. In this case, a write fault is handled directly by the host hypervisor. But we could also simply have a read-only page mapped read-only in both tables, in which case the host hypervisor cannot do anything else than telling the guest hypervisor about the fault. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_mmu.h | 7 +++++++ arch/arm64/include/asm/kvm_mmu.h | 2 ++ arch/arm64/kvm/mmu-nested.c | 22 ++++++++++++++++++++++ virt/kvm/arm/mmu.c | 7 +++++++ 4 files changed, 38 insertions(+) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index 6a22846..1c5b652 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -237,6 +237,13 @@ static inline int kvm_walk_nested_s2(struct kvm_vcpu *vcpu, phys_addr_t gipa, return 0; } +static inline int kvm_s2_handle_perm_fault(struct kvm_vcpu *vcpu, + phys_addr_t fault_ipa, + struct kvm_s2_trans *trans) +{ + return 0; +} + static inline void kvm_nested_s2_unmap(struct kvm_vcpu *vcpu) { } static inline void kvm_nested_s2_free(struct kvm *kvm) { } static inline void kvm_nested_s2_wp(struct kvm *kvm) { } diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 425e4a2..239bb89 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -337,6 +337,8 @@ struct kvm_s2_trans { void update_nested_s2_mmu(struct kvm_vcpu *vcpu); int kvm_walk_nested_s2(struct kvm_vcpu *vcpu, phys_addr_t gipa, struct kvm_s2_trans *result); +int kvm_s2_handle_perm_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, + struct kvm_s2_trans *trans); void kvm_nested_s2_unmap(struct kvm_vcpu *vcpu); void kvm_nested_s2_free(struct kvm *kvm); void kvm_nested_s2_wp(struct kvm *kvm); diff --git a/arch/arm64/kvm/mmu-nested.c b/arch/arm64/kvm/mmu-nested.c index 75570cc..a440d7b 100644 --- a/arch/arm64/kvm/mmu-nested.c +++ b/arch/arm64/kvm/mmu-nested.c @@ -271,6 +271,28 @@ int kvm_walk_nested_s2(struct kvm_vcpu *vcpu, phys_addr_t gipa, return walk_nested_s2_pgd(vcpu, gipa, &wi, result); } +/* + * Returns non-zero if permission fault is handled by injecting it to the next + * level hypervisor. + */ +int kvm_s2_handle_perm_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, + struct kvm_s2_trans *trans) +{ + unsigned long fault_status = kvm_vcpu_trap_get_fault_type(vcpu); + bool write_fault = kvm_is_write_fault(vcpu); + + if (fault_status != FSC_PERM) + return 0; + + if ((write_fault && !trans->writable) || + (!write_fault && !trans->readable)) { + trans->esr = esr_s2_fault(vcpu, trans->level, ESR_ELx_FSC_PERM); + return 1; + } + + return 0; +} + /* expects kvm->mmu_lock to be held */ void kvm_nested_s2_wp(struct kvm *kvm) { diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index 74941ad..4fb7b3b 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1591,6 +1591,13 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) if (ret) goto out_unlock; + nested_trans.esr = 0; + ret = kvm_s2_handle_perm_fault(vcpu, fault_ipa, &nested_trans); + if (nested_trans.esr) + kvm_inject_s2_fault(vcpu, nested_trans.esr); + if (ret) + goto out_unlock; + ipa = nested_trans.output; }