Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7471729imu; Thu, 31 Jan 2019 10:37:59 -0800 (PST) X-Google-Smtp-Source: ALg8bN5y8vALaD9P1C5ZJh+6+fuKoawWHZwebMYxYABBwTiP2rn84YQjwSbymWI4TmldszF8v5G9 X-Received: by 2002:a63:c42:: with SMTP id 2mr32568637pgm.372.1548959879751; Thu, 31 Jan 2019 10:37:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548959879; cv=none; d=google.com; s=arc-20160816; b=Wqu277rzdVQr2aGQg3e6Thf9OM+HjlXTa+zKi4MKosUnKOBqVK7hBWwqj/EbQmNkhw l/ku4znrKjux0H+9Nxq4EoJ8f54JDaIc/XnQ5w5qibNix2TohbQoUhzd/R9pEtSbk3KP w6DqQnkVtJjFHfgPaSSA/U4IOBOPlEYa/qcErOSfvftAcsfOJnEOxUNTMlx2HXk1B9dY BssXwKYFAou3BFKJJUvPtfyLTTztxONsQ1WRIaDJAjJ/e7B4Ma+BU7zbzniiUpccDMED xibRP7gRNmWSPG03Vx0roqN/jfwkAjXzYAoD6yqjA/ofg0k4TEicbO2z5P7I4OeJmxXG auAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=8tiJVUoyMizFoUbRG/0d46To2uc9w1MUhAWOmZ5Ruc8=; b=c0dSmFZSj32lkxM6eXDgVrt4WFPL4Mo7OBmATBvXZ+r4S6QiZWW5Zww35H4wlhl2qp xpI+QxKSy2sWYgwwchKqxEvBeaut4BDEbEpBHgWSTuWq+M/hr8c9t0pqdOiLyxDQeatD RrwFH3sjfjWvHc3nxjjoMU+Us2oUs7nmHUQhLvezwt5cmXKUxSX9SaW7aMXbh5ruA//H VlWVa+x2KWXYehahBgTBLUR4/TCF0S7YlDvpZx9eSKPb0JneKJ3jzMvuqj5AjoVaPD78 Ok+oexF4ZlwuZ/SLOkzWuaJ6oAlY4Fb1mruMgmabhFpHRrayB+DzH0bWt2AHYu+T88PU VMTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg7si5010162plb.149.2019.01.31.10.37.44; Thu, 31 Jan 2019 10:37:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727989AbfAaShZ (ORCPT + 99 others); Thu, 31 Jan 2019 13:37:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44030 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727947AbfAaShU (ORCPT ); Thu, 31 Jan 2019 13:37:20 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F27F3D09; Thu, 31 Jan 2019 18:37:20 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.20.6.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id A757217F7D; Thu, 31 Jan 2019 18:37:19 +0000 (UTC) From: jglisse@redhat.com To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Andrea Arcangeli , Peter Xu , Andrew Morton , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org Subject: [RFC PATCH 4/4] kvm/mmu_notifier: re-enable the change_pte() optimization. Date: Thu, 31 Jan 2019 13:37:06 -0500 Message-Id: <20190131183706.20980-5-jglisse@redhat.com> In-Reply-To: <20190131183706.20980-1-jglisse@redhat.com> References: <20190131183706.20980-1-jglisse@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 31 Jan 2019 18:37:20 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jérôme Glisse Since changes to mmu notifier the change_pte() optimization was lost for kvm. This re-enable it, when ever a pte is going from read and write to read only with same pfn, or from read only to read and write with different pfn. It is safe to update the secondary MMUs, because the primary MMU pte invalidate must have already happened with a ptep_clear_flush() before set_pte_at_notify() is invoked (and thus before change_pte() callback). Signed-off-by: Jérôme Glisse Cc: Andrea Arcangeli Cc: Peter Xu Cc: Andrew Morton Cc: Paolo Bonzini Cc: Radim Krčmář Cc: kvm@vger.kernel.org --- virt/kvm/kvm_main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 5ecea812cb6a..fec155c2d7b8 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -369,6 +369,14 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, int need_tlb_flush = 0, idx; int ret; + /* + * Nothing to do when MMU_NOTIFIER_USE_CHANGE_PTE is set as it means + * that change_pte() will be call and it is a situation in which we + * allow to only rely on change_pte(). + */ + if (range->event & MMU_NOTIFIER_USE_CHANGE_PTE) + return 0; + idx = srcu_read_lock(&kvm->srcu); spin_lock(&kvm->mmu_lock); /* @@ -398,6 +406,14 @@ static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn, { struct kvm *kvm = mmu_notifier_to_kvm(mn); + /* + * Nothing to do when MMU_NOTIFIER_USE_CHANGE_PTE is set as it means + * that change_pte() will be call and it is a situation in which we + * allow to only rely on change_pte(). + */ + if (range->event & MMU_NOTIFIER_USE_CHANGE_PTE) + return; + spin_lock(&kvm->mmu_lock); /* * This sequence increase will notify the kvm page fault that -- 2.17.1