All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
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
Date: Mon, 12 Apr 2021 10:00:15 +0200	[thread overview]
Message-ID: <20210412080611.702979288@infradead.org> (raw)
In-Reply-To: 20210412080012.357146277@infradead.org

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) <peterz@infradead.org>
---
 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 <xen/gntdev.h>
+#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())



WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: akpm@linux-foundation.org
Cc: jgross@suse.com, sstabellini@kernel.org, keescook@chromium.org,
	peterz@infradead.org, intel-gfx@lists.freedesktop.org,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	chris@chris-wilson.co.uk, linux-mm@kvack.org,
	boris.ostrovsky@oracle.com, hch@lst.de
Subject: [Intel-gfx] [PATCH 3/7] xen/gntdev: Remove apply_to_page_range() use from module
Date: Mon, 12 Apr 2021 10:00:15 +0200	[thread overview]
Message-ID: <20210412080611.702979288@infradead.org> (raw)
In-Reply-To: 20210412080012.357146277@infradead.org

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) <peterz@infradead.org>
---
 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 <xen/gntdev.h>
+#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())


_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2021-04-12  8:09 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12  8:00 [PATCH 0/7] mm: Unexport apply_to_page_range() Peter Zijlstra
2021-04-12  8:00 ` [Intel-gfx] " Peter Zijlstra
2021-04-12  8:00 ` [PATCH 1/7] mm: Unexport apply_to_existing_page_range() Peter Zijlstra
2021-04-12  8:00   ` [Intel-gfx] " Peter Zijlstra
2021-04-12  8:13   ` Christoph Hellwig
2021-04-12  8:13     ` [Intel-gfx] " Christoph Hellwig
2021-04-12  8:00 ` [PATCH 2/7] xen/gntdev,x86: Remove apply_to_page_range() use from module Peter Zijlstra
2021-04-12  8:00   ` [Intel-gfx] [PATCH 2/7] xen/gntdev, x86: " Peter Zijlstra
2021-04-12  8:26   ` [PATCH 2/7] xen/gntdev,x86: " Christoph Hellwig
2021-04-12  8:26     ` [Intel-gfx] [PATCH 2/7] xen/gntdev, x86: " Christoph Hellwig
2021-04-12  9:20     ` [PATCH 2/7] xen/gntdev,x86: " Peter Zijlstra
2021-04-12  9:20       ` [Intel-gfx] [PATCH 2/7] xen/gntdev, x86: " Peter Zijlstra
2021-04-12  9:26     ` [PATCH 2/7] xen/gntdev,x86: " Juergen Gross
2021-04-12  9:26       ` [Intel-gfx] [PATCH 2/7] xen/gntdev, x86: " Juergen Gross
2021-04-12  8:00 ` Peter Zijlstra [this message]
2021-04-12  8:00   ` [Intel-gfx] [PATCH 3/7] xen/gntdev: " Peter Zijlstra
2021-04-12  8:27   ` Christoph Hellwig
2021-04-12  8:27     ` [Intel-gfx] " Christoph Hellwig
2021-04-12  9:02     ` Peter Zijlstra
2021-04-12  9:02       ` [Intel-gfx] " Peter Zijlstra
2021-04-12  8:00 ` [PATCH 4/7] mm: Introduce verify_page_range() Peter Zijlstra
2021-04-12  8:00   ` [Intel-gfx] " Peter Zijlstra
2021-04-12  8:28   ` Christoph Hellwig
2021-04-12  8:28     ` [Intel-gfx] " Christoph Hellwig
2021-04-12  9:17     ` Peter Zijlstra
2021-04-12  9:17       ` [Intel-gfx] " Peter Zijlstra
2021-04-12 20:05   ` Kees Cook
2021-04-12 20:05     ` [Intel-gfx] " Kees Cook
2021-04-13  6:54     ` Peter Zijlstra
2021-04-13  6:54       ` [Intel-gfx] " Peter Zijlstra
2021-04-19 23:36       ` Kees Cook
2021-04-19 23:36         ` [Intel-gfx] " Kees Cook
2021-04-13  7:36     ` Peter Zijlstra
2021-04-13  7:36       ` [Intel-gfx] " Peter Zijlstra
2021-04-14  3:01       ` Kees Cook
2021-04-14  3:01         ` [Intel-gfx] " Kees Cook
2021-04-14  7:00         ` Peter Zijlstra
2021-04-14  7:00           ` [Intel-gfx] " Peter Zijlstra
2021-04-12  8:00 ` [PATCH 5/7] xen/privcmd: Use verify_page_range() Peter Zijlstra
2021-04-12  8:00   ` [Intel-gfx] " Peter Zijlstra
2021-04-12  8:28   ` Christoph Hellwig
2021-04-12  8:28     ` [Intel-gfx] " Christoph Hellwig
2021-04-12  8:00 ` [PATCH 6/7] i915: Convert to verify_page_range() Peter Zijlstra
2021-04-12  8:00   ` [Intel-gfx] " Peter Zijlstra
2021-04-12  8:28   ` Christoph Hellwig
2021-04-12  8:28     ` [Intel-gfx] " Christoph Hellwig
2021-04-12 20:08   ` Kees Cook
2021-04-12 20:08     ` [Intel-gfx] " Kees Cook
2021-04-13  6:54     ` Peter Zijlstra
2021-04-13  6:54       ` [Intel-gfx] " Peter Zijlstra
2021-04-14  3:04   ` Kees Cook
2021-04-14  3:04     ` [Intel-gfx] " Kees Cook
2021-04-12  8:00 ` [PATCH 7/7] mm: Unexport apply_to_page_range() Peter Zijlstra
2021-04-12  8:00   ` [Intel-gfx] " Peter Zijlstra
2021-04-12  8:28   ` Christoph Hellwig
2021-04-12  8:28     ` [Intel-gfx] " Christoph Hellwig
2021-04-12  9:00 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for " Patchwork
2021-04-12  9:23   ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210412080611.702979288@infradead.org \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=boris.ostrovsky@oracle.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=hch@lst.de \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jgross@suse.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=sstabellini@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.