From patchwork Mon Apr 12 08:00:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 12197113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D300C433ED for ; Mon, 12 Apr 2021 08:09:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C735261243 for ; Mon, 12 Apr 2021 08:09:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C735261243 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 967676B0073; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E0D46B007B; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B9406B0078; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0048.hostedemail.com [216.40.44.48]) by kanga.kvack.org (Postfix) with ESMTP id E1B7D6B0074 for ; Mon, 12 Apr 2021 04:09:03 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9846C180ACF0D for ; Mon, 12 Apr 2021 08:09:03 +0000 (UTC) X-FDA: 78022989366.13.EC483B7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id 4AC0B2000266 for ; Mon, 12 Apr 2021 08:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=TguJ2GPrgAOuTqINpCRxcU7hNVbLhj0fwULRtq3UU1o=; b=tXVKWgzFI9zH3GWTObAPMxRBO7 qW1DBUMrGFm+8Qwf/5f5kaJgjQbPbuZpcBeMgGrqDamtRBPvw1pTpVr2UJ4wkG7xmDe6Di8Yizw13 9GTs5P337jFcp1hh0+0w8DIuS2T1XcA/8X/8jZXO7LbqsXqd+cuSpUUH7XqRWZsrciuqpSa3T6ViU VHOH37AwdqrzYt8L/E5mcoFjehXgk/K7L0tv2LZGLuGVe+Usvs4yY8oqKCCGZ2mUiosLBOEzNf0su 6HIQYT4g52hXFae7hh3SOYBAdzsTIEwobt/9jEhPDphWTjWsOUGbej5uU3GqxaW17j9jeBURm2Uxm 3kRDFgFg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lVrcl-003yd8-5W; Mon, 12 Apr 2021 08:08:49 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7519D3001E1; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 3A78625F21530; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Message-ID: <20210412080611.702979288@infradead.org> User-Agent: quilt/0.66 Date: Mon, 12 Apr 2021 10:00:15 +0200 From: Peter Zijlstra To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, x86@kernel.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, keescook@chromium.org, hch@lst.de Subject: [PATCH 3/7] xen/gntdev: Remove apply_to_page_range() use from module References: <20210412080012.357146277@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4AC0B2000266 X-Stat-Signature: 4eb4eneb4e16fkeeii4o484mfdnida54 X-Rspamd-Server: rspam02 Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618214944-336898 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Instead of relying on apply_to_page_range() being available to modules, move its use into core kernel code and export it's application. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Christoph Hellwig --- drivers/xen/gntdev-common.h | 2 ++ drivers/xen/gntdev.c | 30 +----------------------------- drivers/xen/grant-table.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 29 deletions(-) --- a/drivers/xen/gntdev-common.h +++ b/drivers/xen/gntdev-common.h @@ -86,4 +86,6 @@ bool gntdev_test_page_count(unsigned int int gntdev_map_grant_pages(struct gntdev_grant_map *map); +int gnttab_use_ptemod(struct vm_area_struct *vma, struct gntdev_grant_map *map); + #endif --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -262,32 +262,6 @@ void gntdev_put_map(struct gntdev_priv * /* ------------------------------------------------------------------ */ -static int find_grant_ptes(pte_t *pte, unsigned long addr, void *data) -{ - struct gntdev_grant_map *map = data; - unsigned int pgnr = (addr - map->vma->vm_start) >> PAGE_SHIFT; - int flags = map->flags | GNTMAP_application_map | GNTMAP_contains_pte; - u64 pte_maddr; - - BUG_ON(pgnr >= map->count); - pte_maddr = arbitrary_virt_to_machine(pte).maddr; - - /* - * Set the PTE as special to force get_user_pages_fast() fall - * back to the slow path. If this is not supported as part of - * the grant map, it will be done afterwards. - */ - if (xen_feature(XENFEAT_gnttab_map_avail_bits)) - flags |= (1 << _GNTMAP_guest_avail0); - - gnttab_set_map_op(&map->map_ops[pgnr], pte_maddr, flags, - map->grants[pgnr].ref, - map->grants[pgnr].domid); - gnttab_set_unmap_op(&map->unmap_ops[pgnr], pte_maddr, flags, - INVALID_GRANT_HANDLE); - return 0; -} - int gntdev_map_grant_pages(struct gntdev_grant_map *map) { int i, err = 0; @@ -1028,9 +1002,7 @@ static int gntdev_mmap(struct file *flip mmu_interval_read_begin(&map->notifier); map->pages_vm_start = vma->vm_start; - err = apply_to_page_range(vma->vm_mm, vma->vm_start, - vma->vm_end - vma->vm_start, - find_grant_ptes, map); + err = gnttab_use_ptemod(vma, map); if (err) { pr_warn("find_grant_ptes() failure.\n"); goto out_put_map; --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -1591,6 +1591,43 @@ int gnttab_init(void) } EXPORT_SYMBOL_GPL(gnttab_init); +#include +#include "gntdev-common.h" + +static int find_grant_ptes(pte_t *pte, unsigned long addr, void *data) +{ + struct gntdev_grant_map *map = data; + unsigned int pgnr = (addr - map->vma->vm_start) >> PAGE_SHIFT; + int flags = map->flags | GNTMAP_application_map | GNTMAP_contains_pte; + u64 pte_maddr; + + BUG_ON(pgnr >= map->count); + pte_maddr = arbitrary_virt_to_machine(pte).maddr; + + /* + * Set the PTE as special to force get_user_pages_fast() fall + * back to the slow path. If this is not supported as part of + * the grant map, it will be done afterwards. + */ + if (xen_feature(XENFEAT_gnttab_map_avail_bits)) + flags |= (1 << _GNTMAP_guest_avail0); + + gnttab_set_map_op(&map->map_ops[pgnr], pte_maddr, flags, + map->grants[pgnr].ref, + map->grants[pgnr].domid); + gnttab_set_unmap_op(&map->unmap_ops[pgnr], pte_maddr, flags, + INVALID_GRANT_HANDLE); + return 0; +} + +int gnttab_use_ptemod(struct vm_area_struct *vma, struct gntdev_grant_map *map) +{ + return apply_to_page_range(vma->vm_mm, vma->vm_start, + vma->vm_end - vma->vm_start, + find_grant_ptes, map); +} +EXPORT_SYMBOL_GPL(gnttab_use_ptemod); + static int __gnttab_init(void) { if (!xen_domain())