Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751561AbcCHTr6 (ORCPT ); Tue, 8 Mar 2016 14:47:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34801 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751010AbcCHTrB (ORCPT ); Tue, 8 Mar 2016 14:47:01 -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 11/29] HMM: add discard range helper (to clear and free resources for a range). Date: Tue, 8 Mar 2016 15:43:04 -0500 Message-Id: <1457469802-11850-12-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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2275 Lines: 65 A common use case is for device driver to stop caring for a range of address long before said range is munmapped by userspace program. To avoid keeping track of such range provide an helper function that will free HMM resources for a range of address. NOTE THAT DEVICE DRIVER MUST MAKE SURE THE HARDWARE WILL NO LONGER ACCESS THE RANGE BECAUSE CALLING THIS HELPER ! Signed-off-by: Jérôme Glisse --- include/linux/hmm.h | 3 +++ mm/hmm.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/hmm.h b/include/linux/hmm.h index d819ec9..10e1558 100644 --- a/include/linux/hmm.h +++ b/include/linux/hmm.h @@ -265,6 +265,9 @@ void hmm_mirror_unregister(struct hmm_mirror *mirror); struct hmm_mirror *hmm_mirror_ref(struct hmm_mirror *mirror); void hmm_mirror_unref(struct hmm_mirror **mirror); 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); #endif /* CONFIG_HMM */ diff --git a/mm/hmm.c b/mm/hmm.c index 7b6ba6a..548f0c5 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -921,6 +921,30 @@ out: } EXPORT_SYMBOL(hmm_mirror_fault); +/* hmm_mirror_range_discard() - discard 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 stop mirroring a range of address and free + * any HMM resources associated with that range (including dma mapping if any). + * + * THIS FUNCTION ASSUME THAT DRIVER ALREADY STOPPED USING THE RANGE OF ADDRESS + * AND THUS DO NOT PERFORM ANY SYNCHRONIZATION OR UPDATE WITH THE DRIVER TO + * INVALIDATE SAID RANGE. + */ +void hmm_mirror_range_discard(struct hmm_mirror *mirror, + unsigned long start, + unsigned long end) +{ + struct hmm_event event; + + hmm_event_init(&event, mirror->hmm, start, end, HMM_MUNMAP); + hmm_mirror_update_pt(mirror, &event, NULL); +} +EXPORT_SYMBOL(hmm_mirror_range_discard); + /* hmm_mirror_register() - register mirror against current process for a device. * * @mirror: The mirror struct being registered. -- 2.4.3