From patchwork Mon May 4 01:25:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47919 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 74A7520553 for ; Mon, 4 May 2015 01:26:58 +0000 (UTC) Received: by labgx2 with SMTP id gx2sf42518677lab.1 for ; Sun, 03 May 2015 18:26:57 -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=tVa2GayKn9LG17Dw3qqySIMid4NyQMqxvddydEEdT8A=; b=UU6Y6l0VB0/A4YqCI9SxLE7VF0g5cmxJGzS9SCz5YHdUSkrOtwt8pSnmFLo+Kahp2I DWxf46QRmlpNURYTNJwHGthGFMWk+iRkthhE0LZPzNzbsEVVaRnyEMv4ivoP6gKQ/ruW jef3UnC9qAxUOgJbgAktwf+La89pwYx1SBaGwiczohaEFwo47dzFdQJjoT5lQm3CqmzZ koB3kTNZUQr2+BnMk6A7ISe3a9z6TKgno6Lpnw+sK+/WamW1xPeRthRH4qE3pXewnwaj NmoLF5mOu7uJk7cYc2fqNaV5O5oYCI713zhGr6qBADfW4+nBXBGYlKFPBS/AxZhxX3lo Ym9g== X-Gm-Message-State: ALoCoQmZgpnUoryw/AgLMBTEvIQP+rb7QyB3k0JYAnNHTraGroti4MOWt+ktRCY/nNUPF8TaB9ZJ X-Received: by 10.194.240.164 with SMTP id wb4mr16884063wjc.1.1430702817203; Sun, 03 May 2015 18:26:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.30.74 with SMTP id q10ls702558lah.35.gmail; Sun, 03 May 2015 18:26:57 -0700 (PDT) X-Received: by 10.152.4.72 with SMTP id i8mr18059057lai.32.1430702817044; Sun, 03 May 2015 18:26:57 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id l16si9058494lab.64.2015.05.03.18.26.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 May 2015 18:26:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbbqq2 with SMTP id qq2so95355579lbb.3 for ; Sun, 03 May 2015 18:26:57 -0700 (PDT) X-Received: by 10.152.2.227 with SMTP id 3mr17350135lax.73.1430702816905; Sun, 03 May 2015 18:26:56 -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.67.65 with SMTP id l1csp1405774lbt; Sun, 3 May 2015 18:26:56 -0700 (PDT) X-Received: by 10.68.227.42 with SMTP id rx10mr32845410pbc.28.1430702815108; Sun, 03 May 2015 18:26:55 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id es7si17680936pbd.123.2015.05.03.18.26.54; Sun, 03 May 2015 18:26:55 -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 S1751537AbbEDB0x (ORCPT + 2 others); Sun, 3 May 2015 21:26:53 -0400 Received: from mail-pd0-f173.google.com ([209.85.192.173]:35897 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751036AbbEDB0x (ORCPT ); Sun, 3 May 2015 21:26:53 -0400 Received: by pdea3 with SMTP id a3so149597609pde.3 for ; Sun, 03 May 2015 18:26:53 -0700 (PDT) X-Received: by 10.70.138.8 with SMTP id qm8mr37633114pdb.96.1430702812965; Sun, 03 May 2015 18:26:52 -0700 (PDT) Received: from localhost ([180.150.153.1]) by mx.google.com with ESMTPSA id ym6sm11029301pac.32.2015.05.03.18.26.51 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 03 May 2015 18:26:51 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: sasha.levin@oracle.com, christoffer.dall@linaro.org, shannon.zhao@linaro.org, Ard Biesheuvel , Marc Zyngier Subject: [PATCH for 3.18.y stable 03/22] arm, arm64: KVM: handle potential incoherency of readonly memslots Date: Mon, 4 May 2015 09:25:07 +0800 Message-Id: <1430702726-2056-4-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1430702726-2056-1-git-send-email-shannon.zhao@linaro.org> References: <1430702726-2056-1-git-send-email-shannon.zhao@linaro.org> 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: shannon.zhao@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.178 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 --- 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; }