From patchwork Tue Feb 18 15:27:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 24912 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f199.google.com (mail-ig0-f199.google.com [209.85.213.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4D821203BE for ; Tue, 18 Feb 2014 18:13:48 +0000 (UTC) Received: by mail-ig0-f199.google.com with SMTP id c10sf20006410igq.2 for ; Tue, 18 Feb 2014 10:13:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=FI/4x8QfDOLfSPX+zI5QF/vODRxuPg07l9z0BVZAP0g=; b=A4hZ7z7zrRqaG0LH2iI7ZSqr6Q/e98+lbp7t6l3sluLICkb8iZjue6O2+tvfBIfECB 8nO/Bz+XFAxRY45y1nIw6bXOSdZshW3wAD1UIXi3ezTDVozOMSZkYsZT4oYOLWV3/fjx mtr7rRY0SROc0xWU6X+PjDt4CC2+7Jc/aGOQNMDXjcQRQ8xFoxbEkDpd+bKiVSi7QXg1 c3/wzWe5gj5dliZiyp6xdZvO0YaYNhzPm/2U8ML2Ebg66wJ+0nwpcFKeoPDiP7WPE4aP 9PT2+MhUgjj8rmQ5hH9WofdYgTWXb/iH3+Q7QX/aHholu0pCXCw63iXYT9dvc8BqdzVo y5Gg== X-Gm-Message-State: ALoCoQkGX9S23FOOXzpLq0aabSkwH127HEI9smx1MhDEk2q+gw4HdJ9PcfY4k9e0ch6gInzfCBho X-Received: by 10.182.24.134 with SMTP id u6mr13162306obf.24.1392747227505; Tue, 18 Feb 2014 10:13:47 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.73 with SMTP id i67ls1426023qgf.3.gmail; Tue, 18 Feb 2014 10:13:47 -0800 (PST) X-Received: by 10.52.135.65 with SMTP id pq1mr3623981vdb.13.1392747227394; Tue, 18 Feb 2014 10:13:47 -0800 (PST) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id ls10si5743357vec.19.2014.02.18.10.13.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Feb 2014 10:13:47 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id pa12so13566419veb.5 for ; Tue, 18 Feb 2014 10:13:47 -0800 (PST) X-Received: by 10.52.246.42 with SMTP id xt10mr18495982vdc.9.1392747227235; Tue, 18 Feb 2014 10:13:47 -0800 (PST) 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.220.174.196 with SMTP id u4csp236777vcz; Tue, 18 Feb 2014 10:13:46 -0800 (PST) X-Received: by 10.180.98.35 with SMTP id ef3mr19388928wib.39.1392747225904; Tue, 18 Feb 2014 10:13:45 -0800 (PST) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id lr5si15523149wjb.138.2014.02.18.10.13.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Feb 2014 10:13:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFmd5-0006j2-Bw; Tue, 18 Feb 2014 15:30:41 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFmcK-0001XF-BN; Tue, 18 Feb 2014 15:29:52 +0000 Received: from fw-tnat.austin.arm.com ([217.140.110.23] helo=collaborate-mta1.arm.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFmaw-0001M6-D5 for linux-arm-kernel@lists.infradead.org; Tue, 18 Feb 2014 15:28:30 +0000 Received: from e102391-lin.cambridge.arm.com (e102391-lin.cambridge.arm.com [10.1.209.166]) by collaborate-mta1.arm.com (Postfix) with ESMTP id BFA7B1401C7; Tue, 18 Feb 2014 09:27:39 -0600 (CST) From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH v4 06/12] ARM: KVM: force cache clean on page fault when caches are off Date: Tue, 18 Feb 2014 15:27:27 +0000 Message-Id: <1392737253-10480-7-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1392737253-10480-1-git-send-email-marc.zyngier@arm.com> References: <1392737253-10480-1-git-send-email-marc.zyngier@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140218_102826_561556_9FEC4456 X-CRM114-Status: GOOD ( 10.84 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.6 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Catalin Marinas , Christoffer Dall X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: marc.zyngier@arm.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 In order for a guest with caches disabled to observe data written contained in a given page, we need to make sure that page is committed to memory, and not just hanging in the cache (as guest accesses are completely bypassing the cache until it decides to enable it). For this purpose, hook into the coherent_cache_guest_page function and flush the region if the guest SCTLR register doesn't show the MMU and caches as being enabled. Signed-off-by: Marc Zyngier Reviewed-by: Christoffer Dall Reviewed-by: Catalin Marinas --- arch/arm/include/asm/kvm_mmu.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index e2a8df4..64cb440d 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -129,9 +129,19 @@ static inline void kvm_set_s2pmd_writable(pmd_t *pmd) struct kvm; +#define kvm_flush_dcache_to_poc(a,l) __cpuc_flush_dcache_area((a), (l)) + +static inline bool vcpu_has_cache_enabled(struct kvm_vcpu *vcpu) +{ + return (vcpu->arch.cp15[c1_SCTLR] & 0b101) == 0b101; +} + static inline void coherent_cache_guest_page(struct kvm_vcpu *vcpu, hva_t hva, unsigned long size) { + if (!vcpu_has_cache_enabled(vcpu)) + kvm_flush_dcache_to_poc((void *)hva, size); + /* * If we are going to insert an instruction page and the icache is * either VIPT or PIPT, there is a potential problem where the host @@ -152,8 +162,6 @@ static inline void coherent_cache_guest_page(struct kvm_vcpu *vcpu, hva_t hva, } } -#define kvm_flush_dcache_to_poc(a,l) __cpuc_flush_dcache_area((a), (l)) - void stage2_flush_vm(struct kvm *kvm); #endif /* !__ASSEMBLY__ */