Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751918AbcCHTyC (ORCPT ); Tue, 8 Mar 2016 14:54:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53834 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751307AbcCHTrF (ORCPT ); Tue, 8 Mar 2016 14:47:05 -0500 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= To: akpm@linux-foundation.org, , linux-mm@kvack.org Cc: Linus Torvalds , , Mel Gorman , "H. Peter Anvin" , Peter Zijlstra , Andrea Arcangeli , Johannes Weiner , Larry Woodman , Rik van Riel , Dave Airlie , Brendan Conoboy , Joe Donohue , Christophe Harle , Duncan Poole , Sherry Cheung , Subhash Gutti , John Hubbard , Mark Hairgrove , Lucien Dunning , Cameron Buschardt , Arvind Gopalakrishnan , Haggai Eran , Shachar Raindel , Liran Liss , Roland Dreier , Ben Sander , Greg Stoner , John Bridgman , Michael Mantor , Paul Blinzer , Leonid Shamis , Laurent Morichetti , Alexander Deucher , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= Subject: [PATCH v12 12/29] HMM: add dirty range helper (toggle dirty bit inside mirror page table) v2. Date: Tue, 8 Mar 2016 15:43:05 -0500 Message-Id: <1457469802-11850-13-git-send-email-jglisse@redhat.com> In-Reply-To: <1457469802-11850-1-git-send-email-jglisse@redhat.com> References: <1457469802-11850-1-git-send-email-jglisse@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 08 Mar 2016 19:47:05 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2564 Lines: 78 Device driver must properly toggle the dirty inside the mirror page table so dirtyness is properly accounted when core mm code needs to know. Provide a simple helper to toggle that bit for a range of address. Changed since v1: - Adapt to HMM page table changes. Signed-off-by: Jérôme Glisse --- include/linux/hmm.h | 3 +++ mm/hmm.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/linux/hmm.h b/include/linux/hmm.h index 10e1558..4bc132a 100644 --- a/include/linux/hmm.h +++ b/include/linux/hmm.h @@ -268,6 +268,9 @@ int hmm_mirror_fault(struct hmm_mirror *mirror, struct hmm_event *event); void hmm_mirror_range_discard(struct hmm_mirror *mirror, unsigned long start, unsigned long end); +void hmm_mirror_range_dirty(struct hmm_mirror *mirror, + unsigned long start, + unsigned long end); #endif /* CONFIG_HMM */ diff --git a/mm/hmm.c b/mm/hmm.c index 548f0c5..dc37e49 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -945,6 +945,44 @@ void hmm_mirror_range_discard(struct hmm_mirror *mirror, } EXPORT_SYMBOL(hmm_mirror_range_discard); +/* hmm_mirror_range_dirty() - toggle dirty bit for a range of address. + * + * @mirror: The mirror struct. + * @start: Start address of the range to discard (inclusive). + * @end: End address of the range to discard (exclusive). + * + * Call when device driver want to toggle the dirty bit for a range of address. + * Useful when the device driver just want to toggle the bit for whole range + * without walking the mirror page table itself. + * + * Note this function does not directly dirty the page behind an address, but + * this will happen once address is invalidated or discard by device driver or + * core mm code. + */ +void hmm_mirror_range_dirty(struct hmm_mirror *mirror, + unsigned long start, + unsigned long end) +{ + struct hmm_pt_iter iter; + unsigned long addr; + + hmm_pt_iter_init(&iter, &mirror->pt); + for (addr = start; addr != end;) { + unsigned long next = end; + dma_addr_t *hmm_pte; + + hmm_pte = hmm_pt_iter_walk(&iter, &addr, &next); + for (; hmm_pte && addr != next; hmm_pte++, addr += PAGE_SIZE) { + if (!hmm_pte_test_valid_pfn(hmm_pte) || + !hmm_pte_test_write(hmm_pte)) + continue; + hmm_pte_set_dirty(hmm_pte); + } + } + hmm_pt_iter_fini(&iter); +} +EXPORT_SYMBOL(hmm_mirror_range_dirty); + /* hmm_mirror_register() - register mirror against current process for a device. * * @mirror: The mirror struct being registered. -- 2.4.3