diff mbox series

[V2,08/30] m68k/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT

Message ID 1645425519-9034-9-git-send-email-anshuman.khandual@arm.com (mailing list archive)
State New
Headers show
Series mm/mmap: Drop protection_map[] and platform's __SXXX/__PXXX requirements | expand

Commit Message

Anshuman Khandual Feb. 21, 2022, 6:38 a.m. UTC
This defines and exports a platform specific custom vm_get_page_prot() via
subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX
macros can be dropped which are no longer needed.

Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: linux-m68k@lists.linux-m68k.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/m68k/Kconfig                        |   1 +
 arch/m68k/include/asm/mcf_pgtable.h      |  59 -------------
 arch/m68k/include/asm/motorola_pgtable.h |  22 -----
 arch/m68k/include/asm/sun3_pgtable.h     |  22 -----
 arch/m68k/mm/init.c                      | 104 +++++++++++++++++++++++
 arch/m68k/mm/motorola.c                  |  48 ++++++++++-
 6 files changed, 150 insertions(+), 106 deletions(-)

Comments

Geert Uytterhoeven Feb. 21, 2022, 11:54 a.m. UTC | #1
Hi Anshuman,

On Mon, Feb 21, 2022 at 9:45 AM Anshuman Khandual
<anshuman.khandual@arm.com> wrote:
> This defines and exports a platform specific custom vm_get_page_prot() via
> subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX
> macros can be dropped which are no longer needed.
>
> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> Cc: linux-m68k@lists.linux-m68k.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>

Thanks for your patch!

> --- a/arch/m68k/mm/init.c
> +++ b/arch/m68k/mm/init.c
> @@ -128,3 +128,107 @@ void __init mem_init(void)
>         memblock_free_all();
>         init_pointer_tables();
>  }
> +
> +#ifdef CONFIG_COLDFIRE
> +/*
> + * Page protections for initialising protection_map. See mm/mmap.c
> + * for use. In general, the bit positions are xwr, and P-items are
> + * private, the S-items are shared.
> + */
> +pgprot_t vm_get_page_prot(unsigned long vm_flags)

Wouldn't it make more sense to add this to arch/m68k/mm/mcfmmu.c?

> +{
> +       switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
> +       case VM_NONE:
> +               return PAGE_NONE;
> +       case VM_READ:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_READABLE);
> +       case VM_WRITE:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_WRITABLE);
> +       case VM_WRITE | VM_READ:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_READABLE | CF_PAGE_WRITABLE);
> +       case VM_EXEC:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_EXEC);
> +       case VM_EXEC | VM_READ:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_READABLE | CF_PAGE_EXEC);
> +       case VM_EXEC | VM_WRITE:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_WRITABLE | CF_PAGE_EXEC);
> +       case VM_EXEC | VM_WRITE | VM_READ:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_READABLE | CF_PAGE_WRITABLE |
> +                               CF_PAGE_EXEC);
> +       case VM_SHARED:
> +               return PAGE_NONE;
> +       case VM_SHARED | VM_READ:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_READABLE);

This is the same as the plain VM_READ case.
Perhaps they can be merged?

> +       case VM_SHARED | VM_WRITE:
> +               return PAGE_SHARED;
> +       case VM_SHARED | VM_WRITE | VM_READ:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_READABLE | CF_PAGE_SHARED);
> +       case VM_SHARED | VM_EXEC:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_EXEC);

Same as plain VM_EXEC.

> +       case VM_SHARED | VM_EXEC | VM_READ:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_READABLE | CF_PAGE_EXEC);

Same as plain VM_EXEC | VM_READ.

> +       case VM_SHARED | VM_EXEC | VM_WRITE:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_SHARED | CF_PAGE_EXEC);
> +       case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> +                               CF_PAGE_READABLE | CF_PAGE_SHARED |
> +                               CF_PAGE_EXEC);
> +       default:
> +               BUILD_BUG();
> +       }
> +}
> +#endif
> +
> +#ifdef CONFIG_SUN3
> +/*
> + * Page protections for initialising protection_map. The sun3 has only two
> + * protection settings, valid (implying read and execute) and writeable. These
> + * are as close as we can get...
> + */
> +pgprot_t vm_get_page_prot(unsigned long vm_flags)

Wouldn't it make more sense to add this to arch/m68k/mm/sun3mmu.c?

> +{
> +       switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
> +       case VM_NONE:
> +               return PAGE_NONE;
> +       case VM_READ:
> +               return PAGE_READONLY;
> +       case VM_WRITE:
> +       case VM_WRITE | VM_READ:

So you did merge some of them...

> +               return PAGE_COPY;
> +       case VM_EXEC:
> +       case VM_EXEC | VM_READ:
> +               return PAGE_READONLY;

But not all? More below...

> +       case VM_EXEC | VM_WRITE:
> +       case VM_EXEC | VM_WRITE | VM_READ:
> +               return PAGE_COPY;
> +       case VM_SHARED:
> +               return PAGE_NONE;
> +       case VM_SHARED | VM_READ:
> +               return PAGE_READONLY;
> +       case VM_SHARED | VM_WRITE:
> +       case VM_SHARED | VM_WRITE | VM_READ:
> +               return PAGE_SHARED;
> +       case VM_SHARED | VM_EXEC:
> +       case VM_SHARED | VM_EXEC | VM_READ:
> +               return PAGE_READONLY;
> +       case VM_SHARED | VM_EXEC | VM_WRITE:
> +       case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
> +               return PAGE_SHARED;
> +       default:
> +               BUILD_BUG();
> +       }
> +}
> +#endif
> +EXPORT_SYMBOL(vm_get_page_prot);
> diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
> index ecbe948f4c1a..495ba0ea083c 100644
> --- a/arch/m68k/mm/motorola.c
> +++ b/arch/m68k/mm/motorola.c
> @@ -400,12 +400,9 @@ void __init paging_init(void)
>
>         /* Fix the cache mode in the page descriptors for the 680[46]0.  */
>         if (CPU_IS_040_OR_060) {
> -               int i;
>  #ifndef mm_cachebits
>                 mm_cachebits = _PAGE_CACHE040;
>  #endif
> -               for (i = 0; i < 16; i++)
> -                       pgprot_val(protection_map[i]) |= _PAGE_CACHE040;
>         }
>
>         min_addr = m68k_memory[0].addr;
> @@ -483,3 +480,48 @@ void __init paging_init(void)
>         max_zone_pfn[ZONE_DMA] = memblock_end_of_DRAM();
>         free_area_init(max_zone_pfn);
>  }
> +
> +/*
> + * The m68k can't do page protection for execute, and considers that
> + * the same are read. Also, write permissions imply read permissions.
> + * This is the closest we can get..
> + */
> +pgprot_t vm_get_page_prot(unsigned long vm_flags)

Good, this one is in arch/m68k/mm/motorola.c :-)

> +{
> +       unsigned long cachebits = 0;
> +
> +       if (CPU_IS_040_OR_060)
> +               cachebits = _PAGE_CACHE040;

If you would use the non-"_C"-variants (e.g. PAGE_NONE instead of
PAGE_NONE_C) below, you would get the cachebits handling for free!
After that, the "_C" variants are no longer used, and can be removed.
Cfr. arch/m68k/include/asm/motorola_pgtable.h:

    #define PAGE_NONE       __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED |
mm_cachebits)
    #define PAGE_SHARED     __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED |
mm_cachebits)
    #define PAGE_COPY       __pgprot(_PAGE_PRESENT | _PAGE_RONLY |
_PAGE_ACCESSED | mm_cachebits)
    #define PAGE_READONLY   __pgprot(_PAGE_PRESENT | _PAGE_RONLY |
_PAGE_ACCESSED | mm_cachebits)
    #define PAGE_KERNEL     __pgprot(_PAGE_PRESENT | _PAGE_DIRTY |
_PAGE_ACCESSED | mm_cachebits)

    /* Alternate definitions that are compile time constants, for
       initializing protection_map.  The cachebits are fixed later.  */
    #define PAGE_NONE_C     __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
    #define PAGE_SHARED_C   __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
    #define PAGE_COPY_C     __pgprot(_PAGE_PRESENT | _PAGE_RONLY |
_PAGE_ACCESSED)
    #define PAGE_READONLY_C __pgprot(_PAGE_PRESENT | _PAGE_RONLY |
_PAGE_ACCESSED)

BTW, this shows you left a reference in a comment to the now-gone
"protection_map".  There are several more across the tree.

> +
> +       switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
> +       case VM_NONE:
> +               return __pgprot(pgprot_val(PAGE_NONE_C) | cachebits);
> +       case VM_READ:
> +               return __pgprot(pgprot_val(PAGE_READONLY_C) | cachebits);
> +       case VM_WRITE:
> +       case VM_WRITE | VM_READ:
> +               return __pgprot(pgprot_val(PAGE_COPY_C) | cachebits);
> +       case VM_EXEC:
> +       case VM_EXEC | VM_READ:
> +               return __pgprot(pgprot_val(PAGE_READONLY_C) | cachebits);
> +       case VM_EXEC | VM_WRITE:
> +       case VM_EXEC | VM_WRITE | VM_READ:
> +               return __pgprot(pgprot_val(PAGE_COPY_C) | cachebits);
> +       case VM_SHARED:
> +               return __pgprot(pgprot_val(PAGE_NONE_C) | cachebits);

Same as the VM_NONE case.  More to be merged below...

> +       case VM_SHARED | VM_READ:
> +               return __pgprot(pgprot_val(PAGE_READONLY_C) | cachebits);
> +       case VM_SHARED | VM_WRITE:
> +       case VM_SHARED | VM_WRITE | VM_READ:
> +               return __pgprot(pgprot_val(PAGE_SHARED_C) | cachebits);
> +       case VM_SHARED | VM_EXEC:
> +       case VM_SHARED | VM_EXEC | VM_READ:
> +               return __pgprot(pgprot_val(PAGE_READONLY_C) | cachebits);
> +       case VM_SHARED | VM_EXEC | VM_WRITE:
> +       case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
> +               return __pgprot(pgprot_val(PAGE_SHARED_C) | cachebits);
> +       default:
> +               BUILD_BUG();
> +       }
> +}
> +EXPORT_SYMBOL(vm_get_page_prot);

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
Anshuman Khandual Feb. 22, 2022, 5:44 a.m. UTC | #2
On 2/21/22 5:24 PM, Geert Uytterhoeven wrote:
> Hi Anshuman,
> 
> On Mon, Feb 21, 2022 at 9:45 AM Anshuman Khandual
> <anshuman.khandual@arm.com> wrote:
>> This defines and exports a platform specific custom vm_get_page_prot() via
>> subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX
>> macros can be dropped which are no longer needed.
>>
>> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
>> Cc: linux-m68k@lists.linux-m68k.org
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> 
> Thanks for your patch!
> 
>> --- a/arch/m68k/mm/init.c
>> +++ b/arch/m68k/mm/init.c
>> @@ -128,3 +128,107 @@ void __init mem_init(void)
>>         memblock_free_all();
>>         init_pointer_tables();
>>  }
>> +
>> +#ifdef CONFIG_COLDFIRE
>> +/*
>> + * Page protections for initialising protection_map. See mm/mmap.c
>> + * for use. In general, the bit positions are xwr, and P-items are
>> + * private, the S-items are shared.
>> + */
>> +pgprot_t vm_get_page_prot(unsigned long vm_flags)
> 
> Wouldn't it make more sense to add this to arch/m68k/mm/mcfmmu.c?

Sure, will move (#ifdef CONFIG_COLDFIRE will not be required anymore).

> 
>> +{
>> +       switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
>> +       case VM_NONE:
>> +               return PAGE_NONE;
>> +       case VM_READ:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_READABLE);
>> +       case VM_WRITE:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_WRITABLE);
>> +       case VM_WRITE | VM_READ:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_READABLE | CF_PAGE_WRITABLE);
>> +       case VM_EXEC:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_EXEC);
>> +       case VM_EXEC | VM_READ:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_READABLE | CF_PAGE_EXEC);
>> +       case VM_EXEC | VM_WRITE:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_WRITABLE | CF_PAGE_EXEC);
>> +       case VM_EXEC | VM_WRITE | VM_READ:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_READABLE | CF_PAGE_WRITABLE |
>> +                               CF_PAGE_EXEC);
>> +       case VM_SHARED:
>> +               return PAGE_NONE;
>> +       case VM_SHARED | VM_READ:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_READABLE);
> 
> This is the same as the plain VM_READ case.
> Perhaps they can be merged?

IMHO, it is worth preserving the existing switch case sequence as vm_flags
moves linearly from VM_NONE to (VM_SHARED|VM_EXEC|VM_WRITE|VM_READ). This
proposal did not attempt to further optimize any common page prot values
for various vm_flags combinations even on other platforms.

> 
>> +       case VM_SHARED | VM_WRITE:
>> +               return PAGE_SHARED;
>> +       case VM_SHARED | VM_WRITE | VM_READ:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_READABLE | CF_PAGE_SHARED);
>> +       case VM_SHARED | VM_EXEC:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_EXEC);
> 
> Same as plain VM_EXEC.
> 
>> +       case VM_SHARED | VM_EXEC | VM_READ:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_READABLE | CF_PAGE_EXEC);
> 
> Same as plain VM_EXEC | VM_READ.
> 
>> +       case VM_SHARED | VM_EXEC | VM_WRITE:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_SHARED | CF_PAGE_EXEC);
>> +       case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
>> +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
>> +                               CF_PAGE_READABLE | CF_PAGE_SHARED |
>> +                               CF_PAGE_EXEC);
>> +       default:
>> +               BUILD_BUG();
>> +       }
>> +}
>> +#endif
>> +
>> +#ifdef CONFIG_SUN3
>> +/*
>> + * Page protections for initialising protection_map. The sun3 has only two
>> + * protection settings, valid (implying read and execute) and writeable. These
>> + * are as close as we can get...
>> + */
>> +pgprot_t vm_get_page_prot(unsigned long vm_flags)
> 
> Wouldn't it make more sense to add this to arch/m68k/mm/sun3mmu.c?

Sure, will move (#ifdef CONFIG_SUN3 will not be required anymore).

> 
>> +{
>> +       switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
>> +       case VM_NONE:
>> +               return PAGE_NONE;
>> +       case VM_READ:
>> +               return PAGE_READONLY;
>> +       case VM_WRITE:
>> +       case VM_WRITE | VM_READ:
> 
> So you did merge some of them...

Only when they follow vm_flags linear sequence.

> 
>> +               return PAGE_COPY;
>> +       case VM_EXEC:
>> +       case VM_EXEC | VM_READ:
>> +               return PAGE_READONLY;
> 
> But not all? More below...

Right, because did not want to shuffle up vm_flags linear sequence.

> 
>> +       case VM_EXEC | VM_WRITE:
>> +       case VM_EXEC | VM_WRITE | VM_READ:
>> +               return PAGE_COPY;
>> +       case VM_SHARED:
>> +               return PAGE_NONE;
>> +       case VM_SHARED | VM_READ:
>> +               return PAGE_READONLY;
>> +       case VM_SHARED | VM_WRITE:
>> +       case VM_SHARED | VM_WRITE | VM_READ:
>> +               return PAGE_SHARED;
>> +       case VM_SHARED | VM_EXEC:
>> +       case VM_SHARED | VM_EXEC | VM_READ:
>> +               return PAGE_READONLY;
>> +       case VM_SHARED | VM_EXEC | VM_WRITE:
>> +       case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
>> +               return PAGE_SHARED;
>> +       default:
>> +               BUILD_BUG();
>> +       }
>> +}
>> +#endif
>> +EXPORT_SYMBOL(vm_get_page_prot);
>> diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
>> index ecbe948f4c1a..495ba0ea083c 100644
>> --- a/arch/m68k/mm/motorola.c
>> +++ b/arch/m68k/mm/motorola.c
>> @@ -400,12 +400,9 @@ void __init paging_init(void)
>>
>>         /* Fix the cache mode in the page descriptors for the 680[46]0.  */
>>         if (CPU_IS_040_OR_060) {
>> -               int i;
>>  #ifndef mm_cachebits
>>                 mm_cachebits = _PAGE_CACHE040;
>>  #endif
>> -               for (i = 0; i < 16; i++)
>> -                       pgprot_val(protection_map[i]) |= _PAGE_CACHE040;
>>         }
>>
>>         min_addr = m68k_memory[0].addr;
>> @@ -483,3 +480,48 @@ void __init paging_init(void)
>>         max_zone_pfn[ZONE_DMA] = memblock_end_of_DRAM();
>>         free_area_init(max_zone_pfn);
>>  }
>> +
>> +/*
>> + * The m68k can't do page protection for execute, and considers that
>> + * the same are read. Also, write permissions imply read permissions.
>> + * This is the closest we can get..
>> + */
>> +pgprot_t vm_get_page_prot(unsigned long vm_flags)
> 
> Good, this one is in arch/m68k/mm/motorola.c :-)
> 
>> +{
>> +       unsigned long cachebits = 0;
>> +
>> +       if (CPU_IS_040_OR_060)
>> +               cachebits = _PAGE_CACHE040;
> 
> If you would use the non-"_C"-variants (e.g. PAGE_NONE instead of
> PAGE_NONE_C) below, you would get the cachebits handling for free!
> After that, the "_C" variants are no longer used, and can be removed.
> Cfr. arch/m68k/include/asm/motorola_pgtable.h:

Right.

> 
>     #define PAGE_NONE       __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED |
> mm_cachebits)
>     #define PAGE_SHARED     __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED |
> mm_cachebits)
>     #define PAGE_COPY       __pgprot(_PAGE_PRESENT | _PAGE_RONLY |
> _PAGE_ACCESSED | mm_cachebits)
>     #define PAGE_READONLY   __pgprot(_PAGE_PRESENT | _PAGE_RONLY |
> _PAGE_ACCESSED | mm_cachebits)
>     #define PAGE_KERNEL     __pgprot(_PAGE_PRESENT | _PAGE_DIRTY |
> _PAGE_ACCESSED | mm_cachebits)
> 
>     /* Alternate definitions that are compile time constants, for
>        initializing protection_map.  The cachebits are fixed later.  */
>     #define PAGE_NONE_C     __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
>     #define PAGE_SHARED_C   __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
>     #define PAGE_COPY_C     __pgprot(_PAGE_PRESENT | _PAGE_RONLY |
> _PAGE_ACCESSED)
>     #define PAGE_READONLY_C __pgprot(_PAGE_PRESENT | _PAGE_RONLY |
> _PAGE_ACCESSED)

Will drop all _C definitions and change switch case as mentioned above.

> 
> BTW, this shows you left a reference in a comment to the now-gone
> "protection_map".  There are several more across the tree.

Right, will remove them all.

> 
>> +
>> +       switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
>> +       case VM_NONE:
>> +               return __pgprot(pgprot_val(PAGE_NONE_C) | cachebits);
>> +       case VM_READ:
>> +               return __pgprot(pgprot_val(PAGE_READONLY_C) | cachebits);
>> +       case VM_WRITE:
>> +       case VM_WRITE | VM_READ:
>> +               return __pgprot(pgprot_val(PAGE_COPY_C) | cachebits);
>> +       case VM_EXEC:
>> +       case VM_EXEC | VM_READ:
>> +               return __pgprot(pgprot_val(PAGE_READONLY_C) | cachebits);
>> +       case VM_EXEC | VM_WRITE:
>> +       case VM_EXEC | VM_WRITE | VM_READ:
>> +               return __pgprot(pgprot_val(PAGE_COPY_C) | cachebits);
>> +       case VM_SHARED:
>> +               return __pgprot(pgprot_val(PAGE_NONE_C) | cachebits);
> 
> Same as the VM_NONE case.  More to be merged below...

As explained earlier.
Geert Uytterhoeven Feb. 25, 2022, 9:02 a.m. UTC | #3
Hi Anshuman, Andrew,

On Mon, Feb 21, 2022 at 12:54 PM Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> On Mon, Feb 21, 2022 at 9:45 AM Anshuman Khandual
> <anshuman.khandual@arm.com> wrote:
> > This defines and exports a platform specific custom vm_get_page_prot() via
> > subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX
> > macros can be dropped which are no longer needed.
> >
> > Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> > Cc: linux-m68k@lists.linux-m68k.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>
> Thanks for your patch!
>
> > --- a/arch/m68k/mm/init.c
> > +++ b/arch/m68k/mm/init.c
> > @@ -128,3 +128,107 @@ void __init mem_init(void)
> >         memblock_free_all();
> >         init_pointer_tables();
> >  }
> > +
> > +#ifdef CONFIG_COLDFIRE
> > +/*
> > + * Page protections for initialising protection_map. See mm/mmap.c
> > + * for use. In general, the bit positions are xwr, and P-items are
> > + * private, the S-items are shared.
> > + */
> > +pgprot_t vm_get_page_prot(unsigned long vm_flags)
>
> Wouldn't it make more sense to add this to arch/m68k/mm/mcfmmu.c?

It's not just about sense, but also about correctness.
The CF_PAGE_* definitions below exist only if CONFIG_MMU=y,
thus causing breakage for cfnommu in today's linux-next.
http://kisskb.ellerman.id.au/kisskb/buildresult/14701640/

>
> > +{
> > +       switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
> > +       case VM_NONE:
> > +               return PAGE_NONE;
> > +       case VM_READ:
> > +               return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
> > +                               CF_PAGE_READABLE);

> > +               BUILD_BUG();
> > +       }
> > +}
> > +#endif
> > +EXPORT_SYMBOL(vm_get_page_prot);

Having this outside the #ifdef means we now get ...

> > --- a/arch/m68k/mm/motorola.c
> > +++ b/arch/m68k/mm/motorola.c

> > +}
> > +EXPORT_SYMBOL(vm_get_page_prot);

... two of them in normal m68k builds.

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
Anshuman Khandual Feb. 25, 2022, 9:35 a.m. UTC | #4
On 2/25/22 2:32 PM, Geert Uytterhoeven wrote:
> Hi Anshuman, Andrew,
> 
> On Mon, Feb 21, 2022 at 12:54 PM Geert Uytterhoeven
> <geert@linux-m68k.org> wrote:
>> On Mon, Feb 21, 2022 at 9:45 AM Anshuman Khandual
>> <anshuman.khandual@arm.com> wrote:
>>> This defines and exports a platform specific custom vm_get_page_prot() via
>>> subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX
>>> macros can be dropped which are no longer needed.
>>>
>>> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
>>> Cc: linux-m68k@lists.linux-m68k.org
>>> Cc: linux-kernel@vger.kernel.org
>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>>
>> Thanks for your patch!
>>
>>> --- a/arch/m68k/mm/init.c
>>> +++ b/arch/m68k/mm/init.c
>>> @@ -128,3 +128,107 @@ void __init mem_init(void)
>>>         memblock_free_all();
>>>         init_pointer_tables();
>>>  }
>>> +
>>> +#ifdef CONFIG_COLDFIRE
>>> +/*
>>> + * Page protections for initialising protection_map. See mm/mmap.c
>>> + * for use. In general, the bit positions are xwr, and P-items are
>>> + * private, the S-items are shared.
>>> + */
>>> +pgprot_t vm_get_page_prot(unsigned long vm_flags)
>>
>> Wouldn't it make more sense to add this to arch/m68k/mm/mcfmmu.c?
> 
> It's not just about sense, but also about correctness.
> The CF_PAGE_* definitions below exist only if CONFIG_MMU=y,
> thus causing breakage for cfnommu in today's linux-next.
> http://kisskb.ellerman.id.au/kisskb/buildresult/14701640/

As mentioned before, will do all these necessary changes in the next
version probably sometime earlier next week. I was waiting for other
reviews (if any) till now.
kernel test robot April 22, 2022, 6:55 a.m. UTC | #5
Hi Anshuman,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on hnaz-mm/master]

url:    https://github.com/0day-ci/linux/commits/Anshuman-Khandual/mm-mmap-Drop-protection_map-and-platform-s-__SXXX-__PXXX-requirements/20220221-144133
base:   https://github.com/hnaz/linux-mm master
config: m68k-randconfig-r033-20220221 (https://download.01.org/0day-ci/archive/20220221/202202211826.rxBv4dl1-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/e75c29d8b212cfab904914acdd5a027fb15d2f16
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Anshuman-Khandual/mm-mmap-Drop-protection_map-and-platform-s-__SXXX-__PXXX-requirements/20220221-144133
        git checkout e75c29d8b212cfab904914acdd5a027fb15d2f16
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=m68k SHELL=/bin/bash arch/m68k/mm/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> arch/m68k/mm/init.c:138:10: error: redefinition of 'vm_get_page_prot'
     138 | pgprot_t vm_get_page_prot(unsigned long vm_flags)
         |          ^~~~~~~~~~~~~~~~
   In file included from arch/m68k/mm/init.c:14:
   include/linux/mm.h:2801:24: note: previous definition of 'vm_get_page_prot' with type 'pgprot_t(long unsigned int)'
    2801 | static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
         |                        ^~~~~~~~~~~~~~~~
   In file included from arch/m68k/include/asm/thread_info.h:6,
                    from include/linux/thread_info.h:60,
                    from include/asm-generic/preempt.h:5,
                    from ./arch/m68k/include/generated/asm/preempt.h:1,
                    from include/linux/preempt.h:78,
                    from arch/m68k/include/asm/irqflags.h:6,
                    from include/linux/irqflags.h:16,
                    from arch/m68k/include/asm/atomic.h:6,
                    from include/linux/atomic.h:7,
                    from include/linux/mm_types_task.h:13,
                    from include/linux/mm_types.h:5,
                    from include/linux/buildid.h:5,
                    from include/linux/module.h:14,
                    from arch/m68k/mm/init.c:11:
   arch/m68k/mm/init.c: In function 'vm_get_page_prot':
>> arch/m68k/mm/init.c:144:33: error: 'CF_PAGE_VALID' undeclared (first use in this function)
     144 |                 return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
         |                                 ^~~~~~~~~~~~~
   arch/m68k/include/asm/page.h:51:40: note: in definition of macro '__pgprot'
      51 | #define __pgprot(x)     ((pgprot_t) { (x) } )
         |                                        ^
   arch/m68k/mm/init.c:144:33: note: each undeclared identifier is reported only once for each function it appears in
     144 |                 return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
         |                                 ^~~~~~~~~~~~~
   arch/m68k/include/asm/page.h:51:40: note: in definition of macro '__pgprot'
      51 | #define __pgprot(x)     ((pgprot_t) { (x) } )
         |                                        ^
>> arch/m68k/mm/init.c:144:49: error: 'CF_PAGE_ACCESSED' undeclared (first use in this function); did you mean 'FGP_ACCESSED'?
     144 |                 return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
         |                                                 ^~~~~~~~~~~~~~~~
   arch/m68k/include/asm/page.h:51:40: note: in definition of macro '__pgprot'
      51 | #define __pgprot(x)     ((pgprot_t) { (x) } )
         |                                        ^
>> arch/m68k/mm/init.c:145:33: error: 'CF_PAGE_READABLE' undeclared (first use in this function); did you mean 'PAGE_READONLY'?
     145 |                                 CF_PAGE_READABLE);
         |                                 ^~~~~~~~~~~~~~~~
   arch/m68k/include/asm/page.h:51:40: note: in definition of macro '__pgprot'
      51 | #define __pgprot(x)     ((pgprot_t) { (x) } )
         |                                        ^
>> arch/m68k/mm/init.c:148:33: error: 'CF_PAGE_WRITABLE' undeclared (first use in this function); did you mean 'NR_PAGETABLE'?
     148 |                                 CF_PAGE_WRITABLE);
         |                                 ^~~~~~~~~~~~~~~~
   arch/m68k/include/asm/page.h:51:40: note: in definition of macro '__pgprot'
      51 | #define __pgprot(x)     ((pgprot_t) { (x) } )
         |                                        ^
>> arch/m68k/mm/init.c:154:33: error: 'CF_PAGE_EXEC' undeclared (first use in this function)
     154 |                                 CF_PAGE_EXEC);
         |                                 ^~~~~~~~~~~~
   arch/m68k/include/asm/page.h:51:40: note: in definition of macro '__pgprot'
      51 | #define __pgprot(x)     ((pgprot_t) { (x) } )
         |                                        ^
>> arch/m68k/mm/init.c:174:52: error: 'CF_PAGE_SHARED' undeclared (first use in this function); did you mean 'PAGE_SHARED'?
     174 |                                 CF_PAGE_READABLE | CF_PAGE_SHARED);
         |                                                    ^~~~~~~~~~~~~~
   arch/m68k/include/asm/page.h:51:40: note: in definition of macro '__pgprot'
      51 | #define __pgprot(x)     ((pgprot_t) { (x) } )
         |                                        ^


vim +/vm_get_page_prot +138 arch/m68k/mm/init.c

  > 11	#include <linux/module.h>
    12	#include <linux/signal.h>
    13	#include <linux/sched.h>
    14	#include <linux/mm.h>
    15	#include <linux/swap.h>
    16	#include <linux/kernel.h>
    17	#include <linux/string.h>
    18	#include <linux/types.h>
    19	#include <linux/init.h>
    20	#include <linux/memblock.h>
    21	#include <linux/gfp.h>
    22	
    23	#include <asm/setup.h>
    24	#include <linux/uaccess.h>
    25	#include <asm/page.h>
    26	#include <asm/pgalloc.h>
    27	#include <asm/traps.h>
    28	#include <asm/machdep.h>
    29	#include <asm/io.h>
    30	#ifdef CONFIG_ATARI
    31	#include <asm/atari_stram.h>
    32	#endif
    33	#include <asm/sections.h>
    34	#include <asm/tlb.h>
    35	
    36	/*
    37	 * ZERO_PAGE is a special page that is used for zero-initialized
    38	 * data and COW.
    39	 */
    40	void *empty_zero_page;
    41	EXPORT_SYMBOL(empty_zero_page);
    42	
    43	#ifdef CONFIG_MMU
    44	
    45	int m68k_virt_to_node_shift;
    46	
    47	void __init m68k_setup_node(int node)
    48	{
    49		node_set_online(node);
    50	}
    51	
    52	#else /* CONFIG_MMU */
    53	
    54	/*
    55	 * paging_init() continues the virtual memory environment setup which
    56	 * was begun by the code in arch/head.S.
    57	 * The parameters are pointers to where to stick the starting and ending
    58	 * addresses of available kernel virtual memory.
    59	 */
    60	void __init paging_init(void)
    61	{
    62		/*
    63		 * Make sure start_mem is page aligned, otherwise bootmem and
    64		 * page_alloc get different views of the world.
    65		 */
    66		unsigned long end_mem = memory_end & PAGE_MASK;
    67		unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0, };
    68	
    69		high_memory = (void *) end_mem;
    70	
    71		empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
    72		if (!empty_zero_page)
    73			panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
    74			      __func__, PAGE_SIZE, PAGE_SIZE);
    75		max_zone_pfn[ZONE_DMA] = end_mem >> PAGE_SHIFT;
    76		free_area_init(max_zone_pfn);
    77	}
    78	
    79	#endif /* CONFIG_MMU */
    80	
    81	void free_initmem(void)
    82	{
    83	#ifndef CONFIG_MMU_SUN3
    84		free_initmem_default(-1);
    85	#endif /* CONFIG_MMU_SUN3 */
    86	}
    87	
    88	#if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE)
    89	#define VECTORS	&vectors[0]
    90	#else
    91	#define VECTORS	_ramvec
    92	#endif
    93	
    94	static inline void init_pointer_tables(void)
    95	{
    96	#if defined(CONFIG_MMU) && !defined(CONFIG_SUN3) && !defined(CONFIG_COLDFIRE)
    97		int i, j;
    98	
    99		/* insert pointer tables allocated so far into the tablelist */
   100		init_pointer_table(kernel_pg_dir, TABLE_PGD);
   101		for (i = 0; i < PTRS_PER_PGD; i++) {
   102			pud_t *pud = (pud_t *)&kernel_pg_dir[i];
   103			pmd_t *pmd_dir;
   104	
   105			if (!pud_present(*pud))
   106				continue;
   107	
   108			pmd_dir = (pmd_t *)pgd_page_vaddr(kernel_pg_dir[i]);
   109			init_pointer_table(pmd_dir, TABLE_PMD);
   110	
   111			for (j = 0; j < PTRS_PER_PMD; j++) {
   112				pmd_t *pmd = &pmd_dir[j];
   113				pte_t *pte_dir;
   114	
   115				if (!pmd_present(*pmd))
   116					continue;
   117	
   118				pte_dir = (pte_t *)pmd_page_vaddr(*pmd);
   119				init_pointer_table(pte_dir, TABLE_PTE);
   120			}
   121		}
   122	#endif
   123	}
   124	
   125	void __init mem_init(void)
   126	{
   127		/* this will put all memory onto the freelists */
   128		memblock_free_all();
   129		init_pointer_tables();
   130	}
   131	
   132	#ifdef CONFIG_COLDFIRE
   133	/*
   134	 * Page protections for initialising protection_map. See mm/mmap.c
   135	 * for use. In general, the bit positions are xwr, and P-items are
   136	 * private, the S-items are shared.
   137	 */
 > 138	pgprot_t vm_get_page_prot(unsigned long vm_flags)
   139	{
   140		switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
   141		case VM_NONE:
   142			return PAGE_NONE;
   143		case VM_READ:
 > 144			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
 > 145					CF_PAGE_READABLE);
   146		case VM_WRITE:
   147			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
 > 148					CF_PAGE_WRITABLE);
   149		case VM_WRITE | VM_READ:
   150			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
   151					CF_PAGE_READABLE | CF_PAGE_WRITABLE);
   152		case VM_EXEC:
   153			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
 > 154					CF_PAGE_EXEC);
   155		case VM_EXEC | VM_READ:
   156			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
   157					CF_PAGE_READABLE | CF_PAGE_EXEC);
   158		case VM_EXEC | VM_WRITE:
   159			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
   160					CF_PAGE_WRITABLE | CF_PAGE_EXEC);
   161		case VM_EXEC | VM_WRITE | VM_READ:
   162			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
   163					CF_PAGE_READABLE | CF_PAGE_WRITABLE |
   164					CF_PAGE_EXEC);
   165		case VM_SHARED:
   166			return PAGE_NONE;
   167		case VM_SHARED | VM_READ:
   168			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
   169					CF_PAGE_READABLE);
   170		case VM_SHARED | VM_WRITE:
   171			return PAGE_SHARED;
   172		case VM_SHARED | VM_WRITE | VM_READ:
   173			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
 > 174					CF_PAGE_READABLE | CF_PAGE_SHARED);
   175		case VM_SHARED | VM_EXEC:
   176			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
   177					CF_PAGE_EXEC);
   178		case VM_SHARED | VM_EXEC | VM_READ:
   179			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
   180					CF_PAGE_READABLE | CF_PAGE_EXEC);
   181		case VM_SHARED | VM_EXEC | VM_WRITE:
   182			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
   183					CF_PAGE_SHARED | CF_PAGE_EXEC);
   184		case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
   185			return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
   186					CF_PAGE_READABLE | CF_PAGE_SHARED |
   187					CF_PAGE_EXEC);
   188		default:
   189			BUILD_BUG();
   190		}
   191	}
   192	#endif
   193	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 936e1803c7c7..114e65164692 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -11,6 +11,7 @@  config M68K
 	select ARCH_NO_PREEMPT if !COLDFIRE
 	select ARCH_USE_MEMTEST if MMU_MOTOROLA
 	select ARCH_WANT_IPC_PARSE_VERSION
+	select ARCH_HAS_VM_GET_PAGE_PROT
 	select BINFMT_FLAT_ARGVP_ENVP_ON_STACK
 	select DMA_DIRECT_REMAP if HAS_DMA && MMU && !COLDFIRE
 	select GENERIC_ATOMIC64
diff --git a/arch/m68k/include/asm/mcf_pgtable.h b/arch/m68k/include/asm/mcf_pgtable.h
index 6f2b87d7a50d..dc5c8ab6aa57 100644
--- a/arch/m68k/include/asm/mcf_pgtable.h
+++ b/arch/m68k/include/asm/mcf_pgtable.h
@@ -86,65 +86,6 @@ 
 				 | CF_PAGE_READABLE \
 				 | CF_PAGE_DIRTY)
 
-/*
- * Page protections for initialising protection_map. See mm/mmap.c
- * for use. In general, the bit positions are xwr, and P-items are
- * private, the S-items are shared.
- */
-#define __P000		PAGE_NONE
-#define __P001		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_READABLE)
-#define __P010		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_WRITABLE)
-#define __P011		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_READABLE \
-				 | CF_PAGE_WRITABLE)
-#define __P100		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_EXEC)
-#define __P101		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_READABLE \
-				 | CF_PAGE_EXEC)
-#define __P110		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_WRITABLE \
-				 | CF_PAGE_EXEC)
-#define __P111		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_READABLE \
-				 | CF_PAGE_WRITABLE \
-				 | CF_PAGE_EXEC)
-
-#define __S000		PAGE_NONE
-#define __S001		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_READABLE)
-#define __S010		PAGE_SHARED
-#define __S011		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_SHARED \
-				 | CF_PAGE_READABLE)
-#define __S100		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_EXEC)
-#define __S101		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_READABLE \
-				 | CF_PAGE_EXEC)
-#define __S110		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_SHARED \
-				 | CF_PAGE_EXEC)
-#define __S111		__pgprot(CF_PAGE_VALID \
-				 | CF_PAGE_ACCESSED \
-				 | CF_PAGE_SHARED \
-				 | CF_PAGE_READABLE \
-				 | CF_PAGE_EXEC)
-
 #define PTE_MASK	PAGE_MASK
 #define CF_PAGE_CHG_MASK (PTE_MASK | CF_PAGE_ACCESSED | CF_PAGE_DIRTY)
 
diff --git a/arch/m68k/include/asm/motorola_pgtable.h b/arch/m68k/include/asm/motorola_pgtable.h
index 022c3abc280d..4ea1bb57deee 100644
--- a/arch/m68k/include/asm/motorola_pgtable.h
+++ b/arch/m68k/include/asm/motorola_pgtable.h
@@ -83,28 +83,6 @@  extern unsigned long mm_cachebits;
 #define PAGE_COPY_C	__pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED)
 #define PAGE_READONLY_C	__pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED)
 
-/*
- * The m68k can't do page protection for execute, and considers that the same are read.
- * Also, write permissions imply read permissions. This is the closest we can get..
- */
-#define __P000	PAGE_NONE_C
-#define __P001	PAGE_READONLY_C
-#define __P010	PAGE_COPY_C
-#define __P011	PAGE_COPY_C
-#define __P100	PAGE_READONLY_C
-#define __P101	PAGE_READONLY_C
-#define __P110	PAGE_COPY_C
-#define __P111	PAGE_COPY_C
-
-#define __S000	PAGE_NONE_C
-#define __S001	PAGE_READONLY_C
-#define __S010	PAGE_SHARED_C
-#define __S011	PAGE_SHARED_C
-#define __S100	PAGE_READONLY_C
-#define __S101	PAGE_READONLY_C
-#define __S110	PAGE_SHARED_C
-#define __S111	PAGE_SHARED_C
-
 #define pmd_pgtable(pmd) ((pgtable_t)pmd_page_vaddr(pmd))
 
 /*
diff --git a/arch/m68k/include/asm/sun3_pgtable.h b/arch/m68k/include/asm/sun3_pgtable.h
index 5b24283a0a42..086fabdd8d4c 100644
--- a/arch/m68k/include/asm/sun3_pgtable.h
+++ b/arch/m68k/include/asm/sun3_pgtable.h
@@ -66,28 +66,6 @@ 
 				 | SUN3_PAGE_SYSTEM \
 				 | SUN3_PAGE_NOCACHE)
 
-/*
- * Page protections for initialising protection_map. The sun3 has only two
- * protection settings, valid (implying read and execute) and writeable. These
- * are as close as we can get...
- */
-#define __P000	PAGE_NONE
-#define __P001	PAGE_READONLY
-#define __P010	PAGE_COPY
-#define __P011	PAGE_COPY
-#define __P100	PAGE_READONLY
-#define __P101	PAGE_READONLY
-#define __P110	PAGE_COPY
-#define __P111	PAGE_COPY
-
-#define __S000	PAGE_NONE
-#define __S001	PAGE_READONLY
-#define __S010	PAGE_SHARED
-#define __S011	PAGE_SHARED
-#define __S100	PAGE_READONLY
-#define __S101	PAGE_READONLY
-#define __S110	PAGE_SHARED
-#define __S111	PAGE_SHARED
 
 /* Use these fake page-protections on PMDs. */
 #define SUN3_PMD_VALID	(0x00000001)
diff --git a/arch/m68k/mm/init.c b/arch/m68k/mm/init.c
index 1b47bec15832..b6ef2c6f4e85 100644
--- a/arch/m68k/mm/init.c
+++ b/arch/m68k/mm/init.c
@@ -128,3 +128,107 @@  void __init mem_init(void)
 	memblock_free_all();
 	init_pointer_tables();
 }
+
+#ifdef CONFIG_COLDFIRE
+/*
+ * Page protections for initialising protection_map. See mm/mmap.c
+ * for use. In general, the bit positions are xwr, and P-items are
+ * private, the S-items are shared.
+ */
+pgprot_t vm_get_page_prot(unsigned long vm_flags)
+{
+	switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
+	case VM_NONE:
+		return PAGE_NONE;
+	case VM_READ:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_READABLE);
+	case VM_WRITE:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_WRITABLE);
+	case VM_WRITE | VM_READ:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_READABLE | CF_PAGE_WRITABLE);
+	case VM_EXEC:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_EXEC);
+	case VM_EXEC | VM_READ:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_READABLE | CF_PAGE_EXEC);
+	case VM_EXEC | VM_WRITE:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_WRITABLE | CF_PAGE_EXEC);
+	case VM_EXEC | VM_WRITE | VM_READ:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_READABLE | CF_PAGE_WRITABLE |
+				CF_PAGE_EXEC);
+	case VM_SHARED:
+		return PAGE_NONE;
+	case VM_SHARED | VM_READ:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_READABLE);
+	case VM_SHARED | VM_WRITE:
+		return PAGE_SHARED;
+	case VM_SHARED | VM_WRITE | VM_READ:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_READABLE | CF_PAGE_SHARED);
+	case VM_SHARED | VM_EXEC:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_EXEC);
+	case VM_SHARED | VM_EXEC | VM_READ:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_READABLE | CF_PAGE_EXEC);
+	case VM_SHARED | VM_EXEC | VM_WRITE:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_SHARED | CF_PAGE_EXEC);
+	case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
+		return __pgprot(CF_PAGE_VALID | CF_PAGE_ACCESSED |
+				CF_PAGE_READABLE | CF_PAGE_SHARED |
+				CF_PAGE_EXEC);
+	default:
+		BUILD_BUG();
+	}
+}
+#endif
+
+#ifdef CONFIG_SUN3
+/*
+ * Page protections for initialising protection_map. The sun3 has only two
+ * protection settings, valid (implying read and execute) and writeable. These
+ * are as close as we can get...
+ */
+pgprot_t vm_get_page_prot(unsigned long vm_flags)
+{
+	switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
+	case VM_NONE:
+		return PAGE_NONE;
+	case VM_READ:
+		return PAGE_READONLY;
+	case VM_WRITE:
+	case VM_WRITE | VM_READ:
+		return PAGE_COPY;
+	case VM_EXEC:
+	case VM_EXEC | VM_READ:
+		return PAGE_READONLY;
+	case VM_EXEC | VM_WRITE:
+	case VM_EXEC | VM_WRITE | VM_READ:
+		return PAGE_COPY;
+	case VM_SHARED:
+		return PAGE_NONE;
+	case VM_SHARED | VM_READ:
+		return PAGE_READONLY;
+	case VM_SHARED | VM_WRITE:
+	case VM_SHARED | VM_WRITE | VM_READ:
+		return PAGE_SHARED;
+	case VM_SHARED | VM_EXEC:
+	case VM_SHARED | VM_EXEC | VM_READ:
+		return PAGE_READONLY;
+	case VM_SHARED | VM_EXEC | VM_WRITE:
+	case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
+		return PAGE_SHARED;
+	default:
+		BUILD_BUG();
+	}
+}
+#endif
+EXPORT_SYMBOL(vm_get_page_prot);
diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
index ecbe948f4c1a..495ba0ea083c 100644
--- a/arch/m68k/mm/motorola.c
+++ b/arch/m68k/mm/motorola.c
@@ -400,12 +400,9 @@  void __init paging_init(void)
 
 	/* Fix the cache mode in the page descriptors for the 680[46]0.  */
 	if (CPU_IS_040_OR_060) {
-		int i;
 #ifndef mm_cachebits
 		mm_cachebits = _PAGE_CACHE040;
 #endif
-		for (i = 0; i < 16; i++)
-			pgprot_val(protection_map[i]) |= _PAGE_CACHE040;
 	}
 
 	min_addr = m68k_memory[0].addr;
@@ -483,3 +480,48 @@  void __init paging_init(void)
 	max_zone_pfn[ZONE_DMA] = memblock_end_of_DRAM();
 	free_area_init(max_zone_pfn);
 }
+
+/*
+ * The m68k can't do page protection for execute, and considers that
+ * the same are read. Also, write permissions imply read permissions.
+ * This is the closest we can get..
+ */
+pgprot_t vm_get_page_prot(unsigned long vm_flags)
+{
+	unsigned long cachebits = 0;
+
+	if (CPU_IS_040_OR_060)
+		cachebits = _PAGE_CACHE040;
+
+	switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) {
+	case VM_NONE:
+		return __pgprot(pgprot_val(PAGE_NONE_C) | cachebits);
+	case VM_READ:
+		return __pgprot(pgprot_val(PAGE_READONLY_C) | cachebits);
+	case VM_WRITE:
+	case VM_WRITE | VM_READ:
+		return __pgprot(pgprot_val(PAGE_COPY_C) | cachebits);
+	case VM_EXEC:
+	case VM_EXEC | VM_READ:
+		return __pgprot(pgprot_val(PAGE_READONLY_C) | cachebits);
+	case VM_EXEC | VM_WRITE:
+	case VM_EXEC | VM_WRITE | VM_READ:
+		return __pgprot(pgprot_val(PAGE_COPY_C) | cachebits);
+	case VM_SHARED:
+		return __pgprot(pgprot_val(PAGE_NONE_C) | cachebits);
+	case VM_SHARED | VM_READ:
+		return __pgprot(pgprot_val(PAGE_READONLY_C) | cachebits);
+	case VM_SHARED | VM_WRITE:
+	case VM_SHARED | VM_WRITE | VM_READ:
+		return __pgprot(pgprot_val(PAGE_SHARED_C) | cachebits);
+	case VM_SHARED | VM_EXEC:
+	case VM_SHARED | VM_EXEC | VM_READ:
+		return __pgprot(pgprot_val(PAGE_READONLY_C) | cachebits);
+	case VM_SHARED | VM_EXEC | VM_WRITE:
+	case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
+		return __pgprot(pgprot_val(PAGE_SHARED_C) | cachebits);
+	default:
+		BUILD_BUG();
+	}
+}
+EXPORT_SYMBOL(vm_get_page_prot);