From patchwork Mon May 11 11:16:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 48262 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 098BF21550 for ; Mon, 11 May 2015 11:20:16 +0000 (UTC) Received: by laat2 with SMTP id t2sf40818029laa.2 for ; Mon, 11 May 2015 04:20:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=7zRJKG3MOfFMraHqcgfMdCChu9OEzQqrBRS0h+KzUDI=; b=Q5IqHE+OavDQY/I40K8IEdPLma3hcD09rysdSmAmdNGXvnswuru2gSo3T1XabMxUuU 3ylLlids6faBGNY04JxvmFcCeZ4ap5qGZl2AHjHPU+TeGJYXJ+YBLGOHTAVIsnkKRB3M JW7FSZ4/hA06s5fJSPzj/LaBkUHzFRFRHYq7kVV3fTlHTonWSKa+Ft1l6VEwAJHfZQRD 5qs1EsIOl8rauxV2a/Mr6gwKGB9nEWaV8wly/g+BOYHpQlGVpHB4SQVD5VDKfN8hFirW 3wV095h2Rx3PonHMdHumlTxbMUDtCugkOsaW+kTSDdGY6Kde+3RjRSr2Hw4iwRakRulR 1a1g== X-Gm-Message-State: ALoCoQml+DobxkMzf//zUTU6k1GqQuBp7AECGR9IVAr29Y1Bb3GW5fwQbEPrbNXao616fn89g1nO X-Received: by 10.180.211.168 with SMTP id nd8mr7317348wic.4.1431343214976; Mon, 11 May 2015 04:20:14 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.196 with SMTP id a4ls649559lak.30.gmail; Mon, 11 May 2015 04:20:14 -0700 (PDT) X-Received: by 10.152.179.195 with SMTP id di3mr7718908lac.15.1431343214841; Mon, 11 May 2015 04:20:14 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id ca5si8191885lad.28.2015.05.11.04.20.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 May 2015 04:20:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbbuc2 with SMTP id uc2so91240731lbb.2 for ; Mon, 11 May 2015 04:20:14 -0700 (PDT) X-Received: by 10.152.29.161 with SMTP id l1mr7512713lah.76.1431343214736; Mon, 11 May 2015 04:20:14 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1444803lbb; Mon, 11 May 2015 04:20:13 -0700 (PDT) X-Received: by 10.66.119.174 with SMTP id kv14mr4492165pab.5.1431343197664; Mon, 11 May 2015 04:19:57 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11si17550607pas.160.2015.05.11.04.19.56; Mon, 11 May 2015 04:19:57 -0700 (PDT) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753997AbbEKLTy (ORCPT + 2 others); Mon, 11 May 2015 07:19:54 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:35614 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753960AbbEKLTc (ORCPT ); Mon, 11 May 2015 07:19:32 -0400 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t4BBJORp010206 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 11 May 2015 11:19:24 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t4BBJOf3018762 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 11 May 2015 11:19:24 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t4BBJOOG004241; Mon, 11 May 2015 11:19:24 GMT Received: from lappy.hsd1.nh.comcast.net (/10.159.243.153) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 11 May 2015 04:19:23 -0700 From: Sasha Levin To: stable@vger.kernel.org, stable-commits@vger.kernel.org Cc: Ard Biesheuvel , Marc Zyngier , Shannon Zhao , Sasha Levin Subject: [added to the 3.18 stable tree] arm, arm64: KVM: handle potential incoherency of readonly memslots Date: Mon, 11 May 2015 07:16:24 -0400 Message-Id: <1431343152-19437-3-git-send-email-sasha.levin@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1431343152-19437-1-git-send-email-sasha.levin@oracle.com> References: <1431343152-19437-1-git-send-email-sasha.levin@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Ard Biesheuvel commit 849260c72c6b8bd53850cb00b80027db3a273c2c upstream. Readonly memslots are often used to implement emulation of ROMs and NOR flashes, in which case the guest may legally map these regions as uncached. To deal with the incoherency associated with uncached guest mappings, treat all readonly memslots as incoherent, and ensure that pages that belong to regions tagged as such are flushed to DRAM before being passed to the guest. Signed-off-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Shannon Zhao Signed-off-by: Sasha Levin --- arch/arm/kvm/mmu.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 8038e52..16ae5f0 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -920,7 +920,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, if (!hugetlb && !force_pte) hugetlb = transparent_hugepage_adjust(&pfn, &fault_ipa); - fault_ipa_uncached = false; + fault_ipa_uncached = memslot->flags & KVM_MEMSLOT_INCOHERENT; if (hugetlb) { pmd_t new_pmd = pfn_pmd(pfn, mem_type); @@ -1299,11 +1299,12 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, hva = vm_end; } while (hva < reg_end); - if (ret) { - spin_lock(&kvm->mmu_lock); + spin_lock(&kvm->mmu_lock); + if (ret) unmap_stage2_range(kvm, mem->guest_phys_addr, mem->memory_size); - spin_unlock(&kvm->mmu_lock); - } + else + stage2_flush_memslot(kvm, memslot); + spin_unlock(&kvm->mmu_lock); return ret; } @@ -1315,6 +1316,15 @@ void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free, int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot, unsigned long npages) { + /* + * Readonly memslots are not incoherent with the caches by definition, + * but in practice, they are used mostly to emulate ROMs or NOR flashes + * that the guest may consider devices and hence map as uncached. + * To prevent incoherency issues in these cases, tag all readonly + * regions as incoherent. + */ + if (slot->flags & KVM_MEM_READONLY) + slot->flags |= KVM_MEMSLOT_INCOHERENT; return 0; }