From patchwork Mon Jul 28 06:09:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 374089 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 959F514013F for ; Mon, 28 Jul 2014 16:06:16 +1000 (EST) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id 80A1B1A0A8D for ; Mon, 28 Jul 2014 16:06:16 +1000 (EST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pa0-x22d.google.com (mail-pa0-x22d.google.com [IPv6:2607:f8b0:400e:c03::22d]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id B0D4D1A032A for ; Mon, 28 Jul 2014 16:05:36 +1000 (EST) Received: by mail-pa0-f45.google.com with SMTP id eu11so9817799pac.18 for ; Sun, 27 Jul 2014 23:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=BMEHPunRbgGp+Zv3FDEXaUEuFbqkeuzB+ccF/nUNfus=; b=cpUGFH6phlgldCh6gWynJZNVjIT8E0nQwGWPgDKeH6vJfiWHw0K4u7/ZarOCnY5uW6 b69DTgzMD6SPuenCOSGKvxOFk1CBrh0c0jGNlkTmmmtpGv7YsGi/OMHFcHaNKxbY+ADG Sb/rZxkmLW6ux0Xn7LdrdIT6AcwH8UQZxu+OjreFFx0HqtSPCZyNmH2hzz9riaPIGnJd H5pc/VPldF1Qf3qKFnL+u8PSbDiRI/96qVDoRIm3e2Ad1oHkAHxd+47j5UjHIgz/uJQf tFmt/kRET3Ii45NDNY1hOdHuwoE0bTpISfdjJtwPgx0i/wtTORJKyqo5yQYYxk60yld5 zZVA== X-Received: by 10.66.178.231 with SMTP id db7mr21359113pac.63.1406527534304; Sun, 27 Jul 2014 23:05:34 -0700 (PDT) Received: from localhost ([202.108.130.177]) by mx.google.com with ESMTPSA id t3sm15671469pdf.54.2014.07.27.23.05.31 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 27 Jul 2014 23:05:33 -0700 (PDT) From: Liu Ping Fan X-Google-Original-From: Liu Ping Fan To: linuxppc-dev@lists.ozlabs.org, kvm-ppc@vger.kernel.org Subject: [PATCH] powerpc: kvm: make the setup of hpte under the protection of KVMPPC_RMAP_LOCK_BIT Date: Mon, 28 Jul 2014 14:09:04 +0800 Message-Id: <1406527744-25316-1-git-send-email-pingfank@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.1.4 Cc: Paul Mackerras , Alexander Graf X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" In current code, the setup of hpte is under the risk of race with mmu_notifier_invalidate, i.e we may setup a hpte with a invalid pfn. Resolve this issue by sync the two actions by KVMPPC_RMAP_LOCK_BIT. Signed-off-by: Liu Ping Fan --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index 8056107..e6dcff4 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -754,19 +754,24 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu, if (hptep[0] & HPTE_V_VALID) { /* HPTE was previously valid, so we need to invalidate it */ - unlock_rmap(rmap); hptep[0] |= HPTE_V_ABSENT; kvmppc_invalidate_hpte(kvm, hptep, index); /* don't lose previous R and C bits */ r |= hptep[1] & (HPTE_R_R | HPTE_R_C); + + hptep[1] = r; + eieio(); + hptep[0] = hpte[0]; + asm volatile("ptesync" : : : "memory"); + unlock_rmap(rmap); } else { + hptep[1] = r; + eieio(); + hptep[0] = hpte[0]; + asm volatile("ptesync" : : : "memory"); kvmppc_add_revmap_chain(kvm, rev, rmap, index, 0); } - hptep[1] = r; - eieio(); - hptep[0] = hpte[0]; - asm volatile("ptesync" : : : "memory"); preempt_enable(); if (page && hpte_is_writable(r)) SetPageDirty(page);