From patchwork Fri Nov 7 00:40:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Smarduch X-Patchwork-Id: 407912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 8D2F11400B8 for ; Fri, 7 Nov 2014 11:42:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751121AbaKGAmq (ORCPT ); Thu, 6 Nov 2014 19:42:46 -0500 Received: from mailout3.w2.samsung.com ([211.189.100.13]:62598 "EHLO usmailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750846AbaKGAmp (ORCPT ); Thu, 6 Nov 2014 19:42:45 -0500 Received: from uscpsbgex4.samsung.com (u125.gpu85.samsung.co.kr [203.254.195.125]) by usmailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NEN00H538N8MFB0@usmailout3.samsung.com>; Thu, 06 Nov 2014 19:42:44 -0500 (EST) X-AuditID: cbfec37d-b7f3b6d000005695-09-545c15840501 Received: from usmmp2.samsung.com ( [203.254.195.78]) by uscpsbgex4.samsung.com (USCPEXMTA) with SMTP id BA.15.22165.4851C545; Thu, 06 Nov 2014 19:42:44 -0500 (EST) Received: from sisasmtp.sisa.samsung.com ([105.144.21.116]) by usmmp2.samsung.com (Oracle Communications Messaging Server 7u4-27.01(7.0.4.27.0) 64bit (built Aug 30 2012)) with ESMTP id <0NEN007OC8N8BL80@usmmp2.samsung.com>; Thu, 06 Nov 2014 19:42:44 -0500 (EST) Received: from mjsmard-530U3C-530U4C-532U3C.sisa.samsung.com (105.144.129.79) by SISAEX02SJ.sisa.samsung.com (105.144.21.116) with Microsoft SMTP Server (TLS) id 14.3.123.3; Thu, 06 Nov 2014 16:42:43 -0800 From: Mario Smarduch To: pbonzini@redhat.com, james.hogan@imgtec.com, christoffer.dall@linaro.org, agraf@suse.de, marc.zyngier@arm.com, cornelia.huck@de.ibm.com, borntraeger@de.ibm.com, catalin.marinas@arm.com Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-ia64@vger.kernel.org, linux-arm-kernel@lists.infradead.org, steve.capper@arm.com, peter.maydell@linaro.org, Mario Smarduch Subject: [PATCH v13 3/7] KVM: x86: flush TLBs last before returning from KVM_GET_DIRTY_LOG Date: Thu, 06 Nov 2014 16:40:44 -0800 Message-id: <1415320848-13813-4-git-send-email-m.smarduch@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1415320848-13813-1-git-send-email-m.smarduch@samsung.com> References: <1415320848-13813-1-git-send-email-m.smarduch@samsung.com> MIME-version: 1.0 Content-type: text/plain X-Originating-IP: [105.144.129.79] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpikeLIzCtJLcpLzFFi42I5/e+wn26LaEyIwdVZahYnrvxjtJi+YjuL xftlPYwWL14DufObGxkt3s17wWzR/ayZ0eLNJ22LOVMLLT6eOs5usenxNVaLv3f+sVns3/aP 1WLOmQcsFpPebGNy4PdYM28No8fBR4fYPHp2nmH0uHNtD5vH+U1rmD02L6n3eL/vKpvH5tPV Hp83yQVwRnHZpKTmZJalFunbJXBlrPu3kangtGBFb0tCA+MEvi5GTg4JAROJ21Mfs0LYYhIX 7q1n62Lk4hASWMYocfhTAyuE08sk0f/0OzuEc5FRYvqyLSwgLWwCuhL7720ES4gIHGCUOLHx FxOIwyzwllFix8k/TCBVwgIxEsvP72cDsVkEVCU2nOhnBLF5BdwkllybBDSJA2i5gsScSTYg YU4Bd4nNO3Ywg9hCQCV3H/5ghSgXlPgx+R5YObOAhMTzz0oQJaoS224+Z4R4QUli2uGr7BMY hWYh6ZiF0LGAkWkVo1hpcXJBcVJ6aoWJXnFibnFpXrpecn7uJkZIvNXuYLz/1eYQowAHoxIP 7w3emBAh1sSy4srcQ4wSHMxKIrw27EAh3pTEyqrUovz4otKc1OJDjEwcnFINjBXFX05ecZCL 8rlz/KTwhxO6oZfS32a9alLM3bTYl7czI/uAa+WmB07payOfvA98o3onyPbbvjCHhuJMSwWj edNO2t6sevL0w9vpfE/OdsxhSj36yfji1sevfHfN5v+UfdS/ZfWXvQe2TmdkdT1z1n9V8wSx 17K5OdOSpM0On+D169VRvOX7/I4SS3FGoqEWc1FxIgAIoItRlQIAAA== Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org In the next patches, we will move parts of x86's kvm_vm_ioctl_get_dirty_log implementation to generic code; leave the arch-specific code at the end, similar to the existing generic function kvm_get_dirty_log. Reviewed-by: Mario Smarduch Signed-off-by: Paolo Bonzini --- arch/x86/kvm/x86.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8f1e22d..dc8e66b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3606,13 +3606,13 @@ static int kvm_vm_ioctl_reinject(struct kvm *kvm, * * 1. Take a snapshot of the bit and clear it if needed. * 2. Write protect the corresponding page. - * 3. Flush TLB's if needed. - * 4. Copy the snapshot to the userspace. + * 3. Copy the snapshot to the userspace. + * 4. Flush TLB's if needed. * - * Between 2 and 3, the guest may write to the page using the remaining TLB - * entry. This is not a problem because the page will be reported dirty at - * step 4 using the snapshot taken before and step 3 ensures that successive - * writes will be logged for the next call. + * Between 2 and 4, the guest may write to the page using the remaining TLB + * entry. This is not a problem because the page is reported dirty using + * the snapshot taken before and step 4 ensures that writes done after + * exiting to userspace will be logged for the next call. */ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) { @@ -3661,6 +3661,10 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) spin_unlock(&kvm->mmu_lock); + r = 0; + if (copy_to_user(log->dirty_bitmap, dirty_bitmap_buffer, n)) + r = -EFAULT; + /* See the comments in kvm_mmu_slot_remove_write_access(). */ lockdep_assert_held(&kvm->slots_lock); @@ -3670,12 +3674,6 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) */ if (is_dirty) kvm_flush_remote_tlbs(kvm); - - r = -EFAULT; - if (copy_to_user(log->dirty_bitmap, dirty_bitmap_buffer, n)) - goto out; - - r = 0; out: mutex_unlock(&kvm->slots_lock); return r;