All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4.14,4.19] mips,s390,sh,sparc: gup: Work around the "COW can break either way" issue
@ 2022-01-24 15:11 Ben Hutchings
  2022-01-24 15:23 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Ben Hutchings @ 2022-01-24 15:11 UTC (permalink / raw)
  To: stable; +Cc: Suren Baghdasaryan

[-- Attachment #1: Type: text/plain, Size: 3818 bytes --]

In Linux 4.14 and 4.19 these architectures still have their own
implementations of get_user_pages_fast().  These also need to force
the write flag on when taking the fast path.

Fixes: 407faed92b4a ("gup: document and work around "COW can break either way" issue")
Fixes: 5e24029791e8 ("gup: document and work around "COW can break either way" issue")
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 arch/mips/mm/gup.c  | 9 ++++++++-
 arch/s390/mm/gup.c  | 9 ++++++++-
 arch/sh/mm/gup.c    | 9 ++++++++-
 arch/sparc/mm/gup.c | 9 ++++++++-
 4 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/arch/mips/mm/gup.c b/arch/mips/mm/gup.c
index 5a4875cac1ec..2e7a0d201c09 100644
--- a/arch/mips/mm/gup.c
+++ b/arch/mips/mm/gup.c
@@ -274,7 +274,14 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
 		next = pgd_addr_end(addr, end);
 		if (pgd_none(pgd))
 			goto slow;
-		if (!gup_pud_range(pgd, addr, next, write, pages, &nr))
+		/*
+		 * The FAST_GUP case requires FOLL_WRITE even for pure reads,
+		 * because get_user_pages() may need to cause an early COW in
+		 * order to avoid confusing the normal COW routines. So only
+		 * targets that are already writable are safe to do by just
+		 * looking at the page tables.
+		 */
+		if (!gup_pud_range(pgd, addr, next, 1, pages, &nr))
 			goto slow;
 	} while (pgdp++, addr = next, addr != end);
 	local_irq_enable();
diff --git a/arch/s390/mm/gup.c b/arch/s390/mm/gup.c
index 9b5b866d8adf..5389bf5bc828 100644
--- a/arch/s390/mm/gup.c
+++ b/arch/s390/mm/gup.c
@@ -287,7 +287,14 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
 
 	might_sleep();
 	start &= PAGE_MASK;
-	nr = __get_user_pages_fast(start, nr_pages, write, pages);
+	/*
+	 * The FAST_GUP case requires FOLL_WRITE even for pure reads,
+	 * because get_user_pages() may need to cause an early COW in
+	 * order to avoid confusing the normal COW routines. So only
+	 * targets that are already writable are safe to do by just
+	 * looking at the page tables.
+	 */
+	nr = __get_user_pages_fast(start, nr_pages, 1, pages);
 	if (nr == nr_pages)
 		return nr;
 
diff --git a/arch/sh/mm/gup.c b/arch/sh/mm/gup.c
index 56c86ca98ecf..23fa2fc8aabc 100644
--- a/arch/sh/mm/gup.c
+++ b/arch/sh/mm/gup.c
@@ -242,7 +242,14 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
 		next = pgd_addr_end(addr, end);
 		if (pgd_none(pgd))
 			goto slow;
-		if (!gup_pud_range(pgd, addr, next, write, pages, &nr))
+		/*
+		 * The FAST_GUP case requires FOLL_WRITE even for pure reads,
+		 * because get_user_pages() may need to cause an early COW in
+		 * order to avoid confusing the normal COW routines. So only
+		 * targets that are already writable are safe to do by just
+		 * looking at the page tables.
+		 */
+		if (!gup_pud_range(pgd, addr, next, 1, pages, &nr))
 			goto slow;
 	} while (pgdp++, addr = next, addr != end);
 	local_irq_enable();
diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
index aee6dba83d0e..f291d34a1cd5 100644
--- a/arch/sparc/mm/gup.c
+++ b/arch/sparc/mm/gup.c
@@ -303,7 +303,14 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
 		next = pgd_addr_end(addr, end);
 		if (pgd_none(pgd))
 			goto slow;
-		if (!gup_pud_range(pgd, addr, next, write, pages, &nr))
+		/*
+		 * The FAST_GUP case requires FOLL_WRITE even for pure reads,
+		 * because get_user_pages() may need to cause an early COW in
+		 * order to avoid confusing the normal COW routines. So only
+		 * targets that are already writable are safe to do by just
+		 * looking at the page tables.
+		 */
+		if (!gup_pud_range(pgd, addr, next, 1, pages, &nr))
 			goto slow;
 	} while (pgdp++, addr = next, addr != end);
 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 4.14,4.19] mips,s390,sh,sparc: gup: Work around the "COW can break either way" issue
  2022-01-24 15:11 [PATCH 4.14,4.19] mips,s390,sh,sparc: gup: Work around the "COW can break either way" issue Ben Hutchings
@ 2022-01-24 15:23 ` Greg KH
  2022-01-24 16:46   ` Suren Baghdasaryan
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2022-01-24 15:23 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: stable, Suren Baghdasaryan

On Mon, Jan 24, 2022 at 04:11:18PM +0100, Ben Hutchings wrote:
> In Linux 4.14 and 4.19 these architectures still have their own
> implementations of get_user_pages_fast().  These also need to force
> the write flag on when taking the fast path.
> 
> Fixes: 407faed92b4a ("gup: document and work around "COW can break either way" issue")
> Fixes: 5e24029791e8 ("gup: document and work around "COW can break either way" issue")
> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
> ---
>  arch/mips/mm/gup.c  | 9 ++++++++-
>  arch/s390/mm/gup.c  | 9 ++++++++-
>  arch/sh/mm/gup.c    | 9 ++++++++-
>  arch/sparc/mm/gup.c | 9 ++++++++-
>  4 files changed, 32 insertions(+), 4 deletions(-)

Thanks, now queued up.

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 4.14,4.19] mips,s390,sh,sparc: gup: Work around the "COW can break either way" issue
  2022-01-24 15:23 ` Greg KH
@ 2022-01-24 16:46   ` Suren Baghdasaryan
  0 siblings, 0 replies; 3+ messages in thread
From: Suren Baghdasaryan @ 2022-01-24 16:46 UTC (permalink / raw)
  To: Greg KH; +Cc: Ben Hutchings, stable

On Mon, Jan 24, 2022 at 7:23 AM Greg KH <greg@kroah.com> wrote:
>
> On Mon, Jan 24, 2022 at 04:11:18PM +0100, Ben Hutchings wrote:
> > In Linux 4.14 and 4.19 these architectures still have their own
> > implementations of get_user_pages_fast().  These also need to force
> > the write flag on when taking the fast path.
> >
> > Fixes: 407faed92b4a ("gup: document and work around "COW can break either way" issue")
> > Fixes: 5e24029791e8 ("gup: document and work around "COW can break either way" issue")
> > Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
> > ---
> >  arch/mips/mm/gup.c  | 9 ++++++++-
> >  arch/s390/mm/gup.c  | 9 ++++++++-
> >  arch/sh/mm/gup.c    | 9 ++++++++-
> >  arch/sparc/mm/gup.c | 9 ++++++++-
> >  4 files changed, 32 insertions(+), 4 deletions(-)
>
> Thanks, now queued up.

Thanks for catching this. I completely missed the extra uses in the
previous versions.

>
> greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-24 16:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 15:11 [PATCH 4.14,4.19] mips,s390,sh,sparc: gup: Work around the "COW can break either way" issue Ben Hutchings
2022-01-24 15:23 ` Greg KH
2022-01-24 16:46   ` Suren Baghdasaryan

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.