[PATCH v6 13/41] mm: Make pte_mkwrite() take a VMA
David Hildenbrand
david at redhat.com
Mon Feb 20 03:23:28 PST 2023
On 18.02.23 22:14, Rick Edgecombe wrote:
> The x86 Control-flow Enforcement Technology (CET) feature includes a new
> type of memory called shadow stack. This shadow stack memory has some
> unusual properties, which requires some core mm changes to function
> properly.
>
> One of these unusual properties is that shadow stack memory is writable,
> but only in limited ways. These limits are applied via a specific PTE
> bit combination. Nevertheless, the memory is writable, and core mm code
> will need to apply the writable permissions in the typical paths that
> call pte_mkwrite().
>
> In addition to VM_WRITE, the shadow stack VMA's will have a flag denoting
> that they are special shadow stack flavor of writable memory. So make
> pte_mkwrite() take a VMA, so that the x86 implementation of it can know to
> create regular writable memory or shadow stack memory.
>
> Apply the same changes for pmd_mkwrite() and huge_pte_mkwrite().
>
> No functional change.
>
> Cc: linux-doc at vger.kernel.org
> Cc: linux-kernel at vger.kernel.org
> Cc: linux-alpha at vger.kernel.org
> Cc: linux-snps-arc at lists.infradead.org
> Cc: linux-arm-kernel at lists.infradead.org
> Cc: linux-csky at vger.kernel.org
> Cc: linux-hexagon at vger.kernel.org
> Cc: linux-ia64 at vger.kernel.org
> Cc: loongarch at lists.linux.dev
> Cc: linux-m68k at lists.linux-m68k.org
> Cc: Michal Simek <monstr at monstr.eu>
> Cc: Dinh Nguyen <dinguyen at kernel.org>
> Cc: linux-mips at vger.kernel.org
> Cc: openrisc at lists.librecores.org
> Cc: linux-parisc at vger.kernel.org
> Cc: linuxppc-dev at lists.ozlabs.org
> Cc: linux-riscv at lists.infradead.org
> Cc: linux-s390 at vger.kernel.org
> Cc: linux-sh at vger.kernel.org
> Cc: sparclinux at vger.kernel.org
> Cc: linux-um at lists.infradead.org
> Cc: xen-devel at lists.xenproject.org
> Cc: linux-arch at vger.kernel.org
> Cc: linux-mm at kvack.org
> Tested-by: Pengfei Xu <pengfei.xu at intel.com>
> Suggested-by: David Hildenbrand <david at redhat.com>
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe at intel.com>
>
> ---
> Hi Non-x86 Arch’s,
>
> x86 has a feature that allows for the creation of a special type of
> writable memory (shadow stack) that is only writable in limited specific
> ways. Previously, changes were proposed to core MM code to teach it to
> decide when to create normally writable memory or the special shadow stack
> writable memory, but David Hildenbrand suggested[0] to change
> pXX_mkwrite() to take a VMA, so awareness of shadow stack memory can be
> moved into x86 code.
>
> Since pXX_mkwrite() is defined in every arch, it requires some tree-wide
> changes. So that is why you are seeing some patches out of a big x86
> series pop up in your arch mailing list. There is no functional change.
> After this refactor, the shadow stack series goes on to use the arch
> helpers to push shadow stack memory details inside arch/x86.
>
> Testing was just 0-day build testing.
>
> Hopefully that is enough context. Thanks!
>
> [0] https://lore.kernel.org/lkml/0e29a2d0-08d8-bcd6-ff26-4bea0e4037b0@redhat.com/#t
>
> v6:
> - New patch
> ---
> Documentation/mm/arch_pgtable_helpers.rst | 9 ++++++---
> arch/alpha/include/asm/pgtable.h | 6 +++++-
> arch/arc/include/asm/hugepage.h | 2 +-
> arch/arc/include/asm/pgtable-bits-arcv2.h | 7 ++++++-
> arch/arm/include/asm/pgtable-3level.h | 7 ++++++-
> arch/arm/include/asm/pgtable.h | 2 +-
> arch/arm64/include/asm/pgtable.h | 4 ++--
> arch/csky/include/asm/pgtable.h | 2 +-
> arch/hexagon/include/asm/pgtable.h | 2 +-
> arch/ia64/include/asm/pgtable.h | 2 +-
> arch/loongarch/include/asm/pgtable.h | 4 ++--
> arch/m68k/include/asm/mcf_pgtable.h | 2 +-
> arch/m68k/include/asm/motorola_pgtable.h | 6 +++++-
> arch/m68k/include/asm/sun3_pgtable.h | 6 +++++-
> arch/microblaze/include/asm/pgtable.h | 2 +-
> arch/mips/include/asm/pgtable.h | 6 +++---
> arch/nios2/include/asm/pgtable.h | 2 +-
> arch/openrisc/include/asm/pgtable.h | 2 +-
> arch/parisc/include/asm/pgtable.h | 6 +++++-
> arch/powerpc/include/asm/book3s/32/pgtable.h | 2 +-
> arch/powerpc/include/asm/book3s/64/pgtable.h | 4 ++--
> arch/powerpc/include/asm/nohash/32/pgtable.h | 2 +-
> arch/powerpc/include/asm/nohash/32/pte-8xx.h | 2 +-
> arch/powerpc/include/asm/nohash/64/pgtable.h | 2 +-
> arch/riscv/include/asm/pgtable.h | 6 +++---
> arch/s390/include/asm/hugetlb.h | 4 ++--
> arch/s390/include/asm/pgtable.h | 4 ++--
> arch/sh/include/asm/pgtable_32.h | 10 ++++++++--
> arch/sparc/include/asm/pgtable_32.h | 2 +-
> arch/sparc/include/asm/pgtable_64.h | 6 +++---
> arch/um/include/asm/pgtable.h | 2 +-
> arch/x86/include/asm/pgtable.h | 6 ++++--
> arch/xtensa/include/asm/pgtable.h | 2 +-
> include/asm-generic/hugetlb.h | 4 ++--
> include/linux/mm.h | 2 +-
> mm/debug_vm_pgtable.c | 16 ++++++++--------
> mm/huge_memory.c | 6 +++---
> mm/hugetlb.c | 4 ++--
> mm/memory.c | 4 ++--
> mm/migrate_device.c | 2 +-
> mm/mprotect.c | 2 +-
> mm/userfaultfd.c | 2 +-
> 42 files changed, 106 insertions(+), 69 deletions(-)
That looks painful but IMHO worth it :)
Acked-by: David Hildenbrand <david at redhat.com>
--
Thanks,
David / dhildenb
More information about the linux-riscv
mailing list