From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 C0AE8C4363D for ; Wed, 30 Sep 2020 21:39:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8378920789 for ; Wed, 30 Sep 2020 21:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601501997; bh=mqLXoq1XPAlQntCiujBdXi7cXpMPP60yJ1FQV7iBA8Y=; h=Date:From:To:Subject:Reply-To:List-ID:From; b=o8FbQ9ohN13tX8UoC64Rm0I9bl6IgmpM+ZUaRM1rVGfvHkRWHpO5mrNoqNQlDeCxI WIFVMJOk1nxy9xoa3N1hndGp7aiYSAE8X+GLAdMshlTlB4KvBrEVsKPliHl0sdvOFc 2xbNUz9Ow4fZ2VbxLpcSsa3z+TgKT4Q0IHXUn26I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730770AbgI3Vj5 (ORCPT ); Wed, 30 Sep 2020 17:39:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:34520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730457AbgI3Vj5 (ORCPT ); Wed, 30 Sep 2020 17:39:57 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F28DD2076A; Wed, 30 Sep 2020 21:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601501996; bh=mqLXoq1XPAlQntCiujBdXi7cXpMPP60yJ1FQV7iBA8Y=; h=Date:From:To:Subject:From; b=WZ2PLihhwX/ZAmJiBDIGSv5GCHP4XoB8HLJRFFsdgJ9FniD8+Y4EHjFqUwgUcgxfO EQPgIQjBsUG4lbunjMyqaJcNNx7CMOjYtWKmaOi3JKPCQUsSAhp2dLyBegAORReoCz Z30e0Xgd3wjvo8ertlJit0ceJTuvQ5PEGpOli6v4= Date: Wed, 30 Sep 2020 14:39:55 -0700 From: akpm@linux-foundation.org To: boris.ostrovsky@oracle.com, chris@chris-wilson.co.uk, hch@lst.de, jani.nikula@linux.intel.com, jgross@suse.com, joonas.lahtinen@linux.intel.com, matthew.auld@intel.com, minchan@kernel.org, mm-commits@vger.kernel.org, ngupta@vflare.org, peterz@infradead.org, rodrigo.vivi@intel.com, sstabellini@kernel.org, tvrtko.ursulin@intel.com, willy@infradead.org Subject: + mm-add-a-vmap_pfn-function.patch added to -mm tree Message-ID: <20200930213955.6zP0RBfcW%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The patch titled Subject: mm: add a vmap_pfn function has been added to the -mm tree. Its filename is mm-add-a-vmap_pfn-function.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-add-a-vmap_pfn-function.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-add-a-vmap_pfn-function.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Christoph Hellwig Subject: mm: add a vmap_pfn function Add a proper helper to remap PFNs into kernel virtual space so that drivers don't have to abuse alloc_vm_area and open coded PTE manipulation for it. Link: https://lkml.kernel.org/r/20200930175133.1252382-4-hch@lst.de Signed-off-by: Christoph Hellwig Cc: Boris Ostrovsky Cc: Chris Wilson Cc: Jani Nikula Cc: Joonas Lahtinen Cc: Juergen Gross Cc: Matthew Auld Cc: "Matthew Wilcox (Oracle)" Cc: Minchan Kim Cc: Nitin Gupta Cc: Peter Zijlstra Cc: Rodrigo Vivi Cc: Stefano Stabellini Cc: Tvrtko Ursulin Signed-off-by: Andrew Morton --- include/linux/vmalloc.h | 1 mm/Kconfig | 3 ++ mm/vmalloc.c | 45 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) --- a/include/linux/vmalloc.h~mm-add-a-vmap_pfn-function +++ a/include/linux/vmalloc.h @@ -122,6 +122,7 @@ extern void vfree_atomic(const void *add extern void *vmap(struct page **pages, unsigned int count, unsigned long flags, pgprot_t prot); +void *vmap_pfn(unsigned long *pfns, unsigned int count, pgprot_t prot); extern void vunmap(const void *addr); extern int remap_vmalloc_range_partial(struct vm_area_struct *vma, --- a/mm/Kconfig~mm-add-a-vmap_pfn-function +++ a/mm/Kconfig @@ -816,6 +816,9 @@ config DEVICE_PRIVATE memory; i.e., memory that is only accessible from the device (or group of devices). You likely also want to select HMM_MIRROR. +config VMAP_PFN + bool + config FRAME_VECTOR bool --- a/mm/vmalloc.c~mm-add-a-vmap_pfn-function +++ a/mm/vmalloc.c @@ -2413,6 +2413,51 @@ void *vmap(struct page **pages, unsigned } EXPORT_SYMBOL(vmap); +#ifdef CONFIG_VMAP_PFN +struct vmap_pfn_data { + unsigned long *pfns; + pgprot_t prot; + unsigned int idx; +}; + +static int vmap_pfn_apply(pte_t *pte, unsigned long addr, void *private) +{ + struct vmap_pfn_data *data = private; + + if (WARN_ON_ONCE(pfn_valid(data->pfns[data->idx]))) + return -EINVAL; + *pte = pte_mkspecial(pfn_pte(data->pfns[data->idx++], data->prot)); + return 0; +} + +/** + * vmap_pfn - map an array of PFNs into virtually contiguous space + * @pfns: array of PFNs + * @count: number of pages to map + * @prot: page protection for the mapping + * + * Maps @count PFNs from @pfns into contiguous kernel virtual space and returns + * the start address of the mapping. + */ +void *vmap_pfn(unsigned long *pfns, unsigned int count, pgprot_t prot) +{ + struct vmap_pfn_data data = { .pfns = pfns, .prot = pgprot_nx(prot) }; + struct vm_struct *area; + + area = get_vm_area_caller(count * PAGE_SIZE, VM_IOREMAP, + __builtin_return_address(0)); + if (!area) + return NULL; + if (apply_to_page_range(&init_mm, (unsigned long)area->addr, + count * PAGE_SIZE, vmap_pfn_apply, &data)) { + free_vm_area(area); + return NULL; + } + return area->addr; +} +EXPORT_SYMBOL_GPL(vmap_pfn); +#endif /* CONFIG_VMAP_PFN */ + static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, pgprot_t prot, int node) { _ Patches currently in -mm which might be from hch@lst.de are mm-add-a-vm_map_put_pages-flag-for-vmap.patch mm-add-a-vmap_pfn-function.patch mm-allow-a-null-fn-callback-in-apply_to_page_range.patch zsmalloc-switch-from-alloc_vm_area-to-get_vm_area.patch drm-i915-use-vmap-in-shmem_pin_map.patch drm-i915-use-vmap-in-i915_gem_object_map.patch xen-xenbus-use-apply_to_page_range-directly-in-xenbus_map_ring_pv.patch x86-xen-open-code-alloc_vm_area-in-arch_gnttab_valloc.patch mm-remove-alloc_vm_area.patch