LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures
@ 2018-04-28  0:15 Luis R. Rodriguez
  2018-04-28  3:18 ` Matthew Wilcox
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Luis R. Rodriguez @ 2018-04-28  0:15 UTC (permalink / raw)
  To: arnd
  Cc: gregkh, linux-arch, linux-fsdevel, linux-mm, linux-kernel,
	Luis R. Rodriguez

Some architectures do not define PAGE_KERNEL_RO, best we can do
for them is to provide a fallback onto PAGE_KERNEL. Remove the
hack from the firmware loader and move it onto the asm-generic
header, and document while at it the affected architectures
which do not have a PAGE_KERNEL_RO:

  o alpha
  o ia64
  o m68k
  o mips
  o sparc64
  o sparc

Blessed-by: 0-day
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 drivers/base/firmware_loader/fallback.c |  5 -----
 include/asm-generic/pgtable.h           | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
index 31b5015b59fe..90f36be9e5ca 100644
--- a/drivers/base/firmware_loader/fallback.c
+++ b/drivers/base/firmware_loader/fallback.c
@@ -219,11 +219,6 @@ static ssize_t firmware_loading_show(struct device *dev,
 	return sprintf(buf, "%d\n", loading);
 }
 
-/* Some architectures don't have PAGE_KERNEL_RO */
-#ifndef PAGE_KERNEL_RO
-#define PAGE_KERNEL_RO PAGE_KERNEL
-#endif
-
 /* one pages buffer should be mapped/unmapped only once */
 static int map_fw_priv_pages(struct fw_priv *fw_priv)
 {
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index f59639afaa39..da47fe81df51 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -1083,6 +1083,21 @@ int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
 static inline void init_espfix_bsp(void) { }
 #endif
 
+/*
+ * Some architectures don't have PAGE_KERNEL_RO. This is the best
+ * we can do for them buggers for now. Currently known to not have it:
+ *
+ *  o alpha
+ *  o ia64
+ *  o m68k
+ *  o mips
+ *  o sparc64
+ *  o sparc
+ */
+#ifndef PAGE_KERNEL_RO
+#define PAGE_KERNEL_RO PAGE_KERNEL
+#endif
+
 #endif /* !__ASSEMBLY__ */
 
 #ifndef io_remap_pfn_range
-- 
2.13.2

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

* Re: [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures
  2018-04-28  0:15 [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures Luis R. Rodriguez
@ 2018-04-28  3:18 ` Matthew Wilcox
  2018-05-09  1:04   ` Luis R. Rodriguez
  2018-04-28  5:04 ` Greg KH
  2018-05-02 10:08 ` Geert Uytterhoeven
  2 siblings, 1 reply; 9+ messages in thread
From: Matthew Wilcox @ 2018-04-28  3:18 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: arnd, gregkh, linux-arch, linux-fsdevel, linux-mm, linux-kernel,
	Tony Luck, Fenghua Yu, linux-ia64

On Fri, Apr 27, 2018 at 05:15:26PM -0700, Luis R. Rodriguez wrote:
> Some architectures do not define PAGE_KERNEL_RO, best we can do
> for them is to provide a fallback onto PAGE_KERNEL. Remove the
> hack from the firmware loader and move it onto the asm-generic
> header, and document while at it the affected architectures
> which do not have a PAGE_KERNEL_RO:
> 
>   o alpha
>   o ia64
>   o m68k
>   o mips
>   o sparc64
>   o sparc

ia64 doesn't have it?

*fx: riffles through architecture book*

That seems like an oversight of the Linux port.  Tony, Fenghua, any thoughts?

(also, Luis, maybe move the PAGE_KERNEL_EXEC fallback the same way you
moved the PAGE_KERNEL_RO fallback?)

--- >8 ---

ia64: Add PAGE_KERNEL_RO and PAGE_KERNEL_EXEC

The rest of the kernel was falling back to simple PAGE_KERNEL pages; using
PAGE_KERNEL_RO and PAGE_KERNEL_EXEC provide better protection against
unintended writes.

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>

diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
index 165827774bea..041a32a7960d 100644
--- a/arch/ia64/include/asm/pgtable.h
+++ b/arch/ia64/include/asm/pgtable.h
@@ -23,7 +23,7 @@
 
 /*
  * First, define the various bits in a PTE.  Note that the PTE format
- * matches the VHPT short format, the firt doubleword of the VHPD long
+ * matches the VHPT short format, the first doubleword of the VHPD long
  * format, and the first doubleword of the TLB insertion format.
  */
 #define _PAGE_P_BIT		0
@@ -142,9 +142,11 @@
 #define PAGE_COPY_EXEC	__pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
 #define PAGE_GATE	__pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
 #define PAGE_KERNEL	__pgprot(__DIRTY_BITS  | _PAGE_PL_0 | _PAGE_AR_RWX)
-#define PAGE_KERNELRX	__pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
+#define PAGE_KERNEL_RO	__pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_R)
+#define PAGE_KERNEL_RX	__pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
 #define PAGE_KERNEL_UC	__pgprot(__DIRTY_BITS  | _PAGE_PL_0 | _PAGE_AR_RWX | \
 				 _PAGE_MA_UC)
+#define PAGE_KERNEL_EXEC	PAGE_KERNEL_RX
 
 # ifndef __ASSEMBLY__
 

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

* Re: [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures
  2018-04-28  0:15 [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures Luis R. Rodriguez
  2018-04-28  3:18 ` Matthew Wilcox
@ 2018-04-28  5:04 ` Greg KH
  2018-05-02 10:08 ` Geert Uytterhoeven
  2 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2018-04-28  5:04 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: arnd, linux-arch, linux-fsdevel, linux-mm, linux-kernel

On Fri, Apr 27, 2018 at 05:15:26PM -0700, Luis R. Rodriguez wrote:
> Some architectures do not define PAGE_KERNEL_RO, best we can do
> for them is to provide a fallback onto PAGE_KERNEL. Remove the
> hack from the firmware loader and move it onto the asm-generic
> header, and document while at it the affected architectures
> which do not have a PAGE_KERNEL_RO:
> 
>   o alpha
>   o ia64
>   o m68k
>   o mips
>   o sparc64
>   o sparc
> 
> Blessed-by: 0-day

New tag?  :)

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

* Re: [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures
  2018-04-28  0:15 [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures Luis R. Rodriguez
  2018-04-28  3:18 ` Matthew Wilcox
  2018-04-28  5:04 ` Greg KH
@ 2018-05-02 10:08 ` Geert Uytterhoeven
  2018-05-02 15:11   ` Luis R. Rodriguez
  2 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2018-05-02 10:08 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Arnd Bergmann, Greg KH, Linux-Arch, Linux FS Devel, Linux MM,
	Linux Kernel Mailing List, linux-m68k

Hi Luis,

On Sat, Apr 28, 2018 at 2:15 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote:
> Some architectures do not define PAGE_KERNEL_RO, best we can do
> for them is to provide a fallback onto PAGE_KERNEL. Remove the
> hack from the firmware loader and move it onto the asm-generic
> header, and document while at it the affected architectures
> which do not have a PAGE_KERNEL_RO:
>
>   o alpha
>   o ia64
>   o m68k
>   o mips
>   o sparc64
>   o sparc
>
> Blessed-by: 0-day
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>

I believe the "best we can do" is to add the missing definitions for the
architectures where the hardware does support it?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures
  2018-05-02 10:08 ` Geert Uytterhoeven
@ 2018-05-02 15:11   ` Luis R. Rodriguez
  2018-05-10  1:24     ` Luis R. Rodriguez
  0 siblings, 1 reply; 9+ messages in thread
From: Luis R. Rodriguez @ 2018-05-02 15:11 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Luis R. Rodriguez, Arnd Bergmann, Matthew Wilcox, Greg KH,
	Linux-Arch, Linux FS Devel, Linux MM, Linux Kernel Mailing List,
	linux-m68k

On Wed, May 02, 2018 at 12:08:57PM +0200, Geert Uytterhoeven wrote:
> Hi Luis,
> 
> On Sat, Apr 28, 2018 at 2:15 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote:
> > Some architectures do not define PAGE_KERNEL_RO, best we can do
> > for them is to provide a fallback onto PAGE_KERNEL. Remove the
> > hack from the firmware loader and move it onto the asm-generic
> > header, and document while at it the affected architectures
> > which do not have a PAGE_KERNEL_RO:
> >
> >   o alpha
> >   o ia64
> >   o m68k
> >   o mips
> >   o sparc64
> >   o sparc
> >
> > Blessed-by: 0-day
> > Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> 
> I believe the "best we can do" is to add the missing definitions for the
> architectures where the hardware does support it?

True, but we cannot wait for every architecture to implement a feature to then
such generics upstream, specially when we have common places which use that.
Matthew did send a patch to add ia64 support for PAGE_KERNEL_RO, so I'll
respin the patch to add that and also move the other define he suggested.

At least we'd now have a list of documented archs which need further work too.

  Luis

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

* Re: [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures
  2018-04-28  3:18 ` Matthew Wilcox
@ 2018-05-09  1:04   ` Luis R. Rodriguez
  2018-05-09  1:39     ` Matthew Wilcox
  0 siblings, 1 reply; 9+ messages in thread
From: Luis R. Rodriguez @ 2018-05-09  1:04 UTC (permalink / raw)
  To: Matthew Wilcox, Tony Luck
  Cc: Luis R. Rodriguez, arnd, gregkh, linux-arch, linux-fsdevel,
	linux-mm, linux-kernel, Fenghua Yu, linux-ia64

On Fri, Apr 27, 2018 at 08:18:10PM -0700, Matthew Wilcox wrote:
> On Fri, Apr 27, 2018 at 05:15:26PM -0700, Luis R. Rodriguez wrote:
> > Some architectures do not define PAGE_KERNEL_RO, best we can do
> > for them is to provide a fallback onto PAGE_KERNEL. Remove the
> > hack from the firmware loader and move it onto the asm-generic
> > header, and document while at it the affected architectures
> > which do not have a PAGE_KERNEL_RO:
> > 
> >   o alpha
> >   o ia64
> >   o m68k
> >   o mips
> >   o sparc64
> >   o sparc
> 
> ia64 doesn't have it?
> 
> *fx: riffles through architecture book*
> 
> That seems like an oversight of the Linux port.  Tony, Fenghua, any thoughts?

Poke *Tony, Fenghua* ?

> (also, Luis, maybe move the PAGE_KERNEL_EXEC fallback the same way you
> moved the PAGE_KERNEL_RO fallback?)

Done. Will queue in the generic PAGE_KERNEL_EXEC patch to my series.

> --- >8 ---
> 
> ia64: Add PAGE_KERNEL_RO and PAGE_KERNEL_EXEC
> 
> The rest of the kernel was falling back to simple PAGE_KERNEL pages; using
> PAGE_KERNEL_RO and PAGE_KERNEL_EXEC provide better protection against
> unintended writes.
> 
> Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>

Nice, should I queue this into my series as well?

  Luis

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

* Re: [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures
  2018-05-09  1:04   ` Luis R. Rodriguez
@ 2018-05-09  1:39     ` Matthew Wilcox
  2018-05-10  1:15       ` Luis R. Rodriguez
  0 siblings, 1 reply; 9+ messages in thread
From: Matthew Wilcox @ 2018-05-09  1:39 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Tony Luck, arnd, gregkh, linux-arch, linux-fsdevel, linux-mm,
	linux-kernel, Fenghua Yu, linux-ia64

On Wed, May 09, 2018 at 01:04:38AM +0000, Luis R. Rodriguez wrote:
> On Fri, Apr 27, 2018 at 08:18:10PM -0700, Matthew Wilcox wrote:
> > ia64: Add PAGE_KERNEL_RO and PAGE_KERNEL_EXEC
> > 
> > The rest of the kernel was falling back to simple PAGE_KERNEL pages; using
> > PAGE_KERNEL_RO and PAGE_KERNEL_EXEC provide better protection against
> > unintended writes.
> > 
> > Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
> 
> Nice, should I queue this into my series as well?

A little reluctant to queue it without anyone having tested it.  Heck,
I didn't even check it compiled ;-)

We used to just break architectures and let them fix it up for this kind
of thing.  That's not really acceptable nowadays, but I don't know how
we get arch maintainers to fix up their ports now.

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

* Re: [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures
  2018-05-09  1:39     ` Matthew Wilcox
@ 2018-05-10  1:15       ` Luis R. Rodriguez
  0 siblings, 0 replies; 9+ messages in thread
From: Luis R. Rodriguez @ 2018-05-10  1:15 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Luis R. Rodriguez, Tony Luck, arnd, gregkh, linux-arch,
	linux-fsdevel, linux-mm, linux-kernel, Fenghua Yu, linux-ia64

On Tue, May 08, 2018 at 06:39:35PM -0700, Matthew Wilcox wrote:
> On Wed, May 09, 2018 at 01:04:38AM +0000, Luis R. Rodriguez wrote:
> > On Fri, Apr 27, 2018 at 08:18:10PM -0700, Matthew Wilcox wrote:
> > > ia64: Add PAGE_KERNEL_RO and PAGE_KERNEL_EXEC
> > > 
> > > The rest of the kernel was falling back to simple PAGE_KERNEL pages; using
> > > PAGE_KERNEL_RO and PAGE_KERNEL_EXEC provide better protection against
> > > unintended writes.
> > > 
> > > Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
> > 
> > Nice, should I queue this into my series as well?
> 
> A little reluctant to queue it without anyone having tested it.  Heck,
> I didn't even check it compiled ;-)
> 
> We used to just break architectures and let them fix it up for this kind
> of thing.

History is wonderful.

> That's not really acceptable nowadays, but I don't know how
> we get arch maintainers to fix up their ports now.

OK then in that case I'll proceed with my patches for now and just
document they don't have it. Once and folks test the patch we can
consider it.

  Luis

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

* Re: [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures
  2018-05-02 15:11   ` Luis R. Rodriguez
@ 2018-05-10  1:24     ` Luis R. Rodriguez
  0 siblings, 0 replies; 9+ messages in thread
From: Luis R. Rodriguez @ 2018-05-10  1:24 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Geert Uytterhoeven, Arnd Bergmann, Matthew Wilcox, Greg KH,
	Linux-Arch, Linux FS Devel, Linux MM, Linux Kernel Mailing List,
	linux-m68k

On Wed, May 02, 2018 at 03:11:13PM +0000, Luis R. Rodriguez wrote:
> On Wed, May 02, 2018 at 12:08:57PM +0200, Geert Uytterhoeven wrote:
> > Hi Luis,
> > 
> > On Sat, Apr 28, 2018 at 2:15 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote:
> > > Some architectures do not define PAGE_KERNEL_RO, best we can do
> > > for them is to provide a fallback onto PAGE_KERNEL. Remove the
> > > hack from the firmware loader and move it onto the asm-generic
> > > header, and document while at it the affected architectures
> > > which do not have a PAGE_KERNEL_RO:
> > >
> > >   o alpha
> > >   o ia64
> > >   o m68k
> > >   o mips
> > >   o sparc64
> > >   o sparc
> > >
> > > Blessed-by: 0-day
> > > Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> > 
> > I believe the "best we can do" is to add the missing definitions for the
> > architectures where the hardware does support it?
> 
> True, but we cannot wait for every architecture to implement a feature to then
> such generics upstream, 

Come to think of it your point was the wording. I changed it to not be as misleading.

  Luis

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

end of thread, other threads:[~2018-05-10  1:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-28  0:15 [PATCH] mm: provide a fallback for PAGE_KERNEL_RO for architectures Luis R. Rodriguez
2018-04-28  3:18 ` Matthew Wilcox
2018-05-09  1:04   ` Luis R. Rodriguez
2018-05-09  1:39     ` Matthew Wilcox
2018-05-10  1:15       ` Luis R. Rodriguez
2018-04-28  5:04 ` Greg KH
2018-05-02 10:08 ` Geert Uytterhoeven
2018-05-02 15:11   ` Luis R. Rodriguez
2018-05-10  1:24     ` Luis R. Rodriguez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).