Re: [PATCH 2/5] mm/vma: Make vma_is_accessible() available for general use
csky: Acked-by: Guo Ren On Mon, Feb 17, 2020 at 1:04 PM Anshuman Khandual wrote: > > Lets move vma_is_accessible() helper to include/linux/mm.h which makes it > available for general use. While here, this replaces all remaining open > encodings for VMA access check with vma_is_accessible(). > > Cc: Guo Ren > Cc: Geert Uytterhoeven Cc: Ralf Baechle > Cc: Paul Burton > Cc: Benjamin Herrenschmidt > Cc: Paul Mackerras > Cc: Michael Ellerman > Cc: Yoshinori Sato > Cc: Rich Felker > Cc: Dave Hansen > Cc: Andy Lutomirski > Cc: Peter Zijlstra > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Andrew Morton > Cc: Steven Rostedt > Cc: Mel Gorman > Cc: linux-ker...@vger.kernel.org > Cc: linux-m...@lists.linux-m68k.org > Cc: linux-m...@vger.kernel.org > Cc: linuxppc-dev@lists.ozlabs.org > Cc: linux...@vger.kernel.org > Cc: linux...@kvack.org > Signed-off-by: Anshuman Khandual > --- > arch/csky/mm/fault.c| 2 +- > arch/m68k/mm/fault.c| 2 +- > arch/mips/mm/fault.c| 2 +- > arch/powerpc/mm/fault.c | 2 +- > arch/sh/mm/fault.c | 2 +- > arch/x86/mm/fault.c | 2 +- > include/linux/mm.h | 5 + > kernel/sched/fair.c | 2 +- > mm/gup.c| 2 +- > mm/memory.c | 5 - > mm/mempolicy.c | 3 +-- > 11 files changed, 14 insertions(+), 15 deletions(-) > > diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c > index f76618b630f9..4b3511b8298d 100644 > --- a/arch/csky/mm/fault.c > +++ b/arch/csky/mm/fault.c > @@ -137,7 +137,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, > unsigned long write, > if (!(vma->vm_flags & VM_WRITE)) > goto bad_area; > } else { > - if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))) > + if (!vma_is_accessible(vma)) > goto bad_area; > } > > diff --git a/arch/m68k/mm/fault.c b/arch/m68k/mm/fault.c > index e9b1d7585b43..d5131ec5d923 100644 > --- a/arch/m68k/mm/fault.c > +++ b/arch/m68k/mm/fault.c > @@ -125,7 +125,7 @@ int do_page_fault(struct pt_regs *regs, unsigned long > address, > case 1: /* read, present */ > goto acc_err; > case 0: /* read, not present */ > - if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))) > + if (!vma_is_accessible(vma)) > goto acc_err; > } > > diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c > index 1e8d00793784..5b9f947bfa32 100644 > --- a/arch/mips/mm/fault.c > +++ b/arch/mips/mm/fault.c > @@ -142,7 +142,7 @@ static void __kprobes __do_page_fault(struct pt_regs > *regs, unsigned long write, > goto bad_area; > } > } else { > - if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))) > + if (!vma_is_accessible(vma)) > goto bad_area; > } > } > diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c > index 8db0507619e2..71a3658c516b 100644 > --- a/arch/powerpc/mm/fault.c > +++ b/arch/powerpc/mm/fault.c > @@ -314,7 +314,7 @@ static bool access_error(bool is_write, bool is_exec, > return false; > } > > - if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE > + if (unlikely(!vma_is_accessible(vma))) > return true; > /* > * We should ideally do the vma pkey access check here. But in the > diff --git a/arch/sh/mm/fault.c b/arch/sh/mm/fault.c > index 5f51456f4fc7..a8c4253f37d7 100644 > --- a/arch/sh/mm/fault.c > +++ b/arch/sh/mm/fault.c > @@ -355,7 +355,7 @@ static inline int access_error(int error_code, struct > vm_area_struct *vma) > return 1; > > /* read, not present: */ > - if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE > + if (unlikely(!vma_is_accessible(vma))) > return 1; > > return 0; > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > index fa4ea09593ab..c461eaab0306 100644 > --- a/arch/x86/mm/fault.c > +++ b/arch/x86/mm/fault.c > @@ -1200,7 +1200,7 @@ access_error(unsigned long error_code, struct > vm_area_struct *vma) > return 1; > > /* read, not present: */ > - if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE > + if (unlikely(!vma_is_accessible(vma))) > return 1; > >
Re: [PATCH 05/15] csky: switch to generic version of pte allocation
On Sat, May 04, 2019 at 12:03:48AM +0800, Guo Ren wrote: > Hi Mike, > > Acked-by: Guo Ren > > On Thu, May 02, 2019 at 06:28:32PM +0300, Mike Rapoport wrote: > > The csky implementation pte_alloc_one(), pte_free_kernel() and pte_free() > > is identical to the generic except of lack of __GFP_ACCOUNT for the user > > PTEs allocation. > > > > Switch csky to use generic version of these functions. > Ok. > > > > > The csky implementation of pte_alloc_one_kernel() is not replaced because > > it does not clear the allocated page but rather sets each PTE in it to a > > non-zero value. > Yes, we must set each PTE to _PAGE_GLOBAL because hardware refill the > MMU TLB entry with two PTEs and it use the result of pte0.global | > pte1.global. ^ correct: pte0.global & pte1.global > If pte0 is valid and pte1 is invalid, we must set _PAGE_GLOBAL in > invalid pte entry. Fortunately, there is no performance issue. > > > > > The pte_free_kernel() and pte_free() versions on csky are identical to the > > generic ones and can be simply dropped. > Ok. > > Best Regards > Guo Ren > > > > > Signed-off-by: Mike Rapoport > > --- > > arch/csky/include/asm/pgalloc.h | 30 +++--- > > 1 file changed, 3 insertions(+), 27 deletions(-) > > > > diff --git a/arch/csky/include/asm/pgalloc.h > > b/arch/csky/include/asm/pgalloc.h > > index d213bb4..98c571670 100644 > > --- a/arch/csky/include/asm/pgalloc.h > > +++ b/arch/csky/include/asm/pgalloc.h > > @@ -8,6 +8,9 @@ > > #include > > #include > > > > +#define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL > > +#include/* for pte_{alloc,free}_one */ > > + > > static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, > > pte_t *pte) > > { > > @@ -39,33 +42,6 @@ static inline pte_t *pte_alloc_one_kernel(struct > > mm_struct *mm) > > return pte; > > } > > > > -static inline struct page *pte_alloc_one(struct mm_struct *mm) > > -{ > > - struct page *pte; > > - > > - pte = alloc_pages(GFP_KERNEL | __GFP_ZERO, 0); > > - if (!pte) > > - return NULL; > > - > > - if (!pgtable_page_ctor(pte)) { > > - __free_page(pte); > > - return NULL; > > - } > > - > > - return pte; > > -} > > - > > -static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) > > -{ > > - free_pages((unsigned long)pte, PTE_ORDER); > > -} > > - > > -static inline void pte_free(struct mm_struct *mm, pgtable_t pte) > > -{ > > - pgtable_page_dtor(pte); > > - __free_pages(pte, PTE_ORDER); > > -} > > - > > static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) > > { > > free_pages((unsigned long)pgd, PGD_ORDER); > > -- > > 2.7.4 > > > > ___ > linux-riscv mailing list > linux-ri...@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH 05/15] csky: switch to generic version of pte allocation
Hi Mike, Acked-by: Guo Ren On Thu, May 02, 2019 at 06:28:32PM +0300, Mike Rapoport wrote: > The csky implementation pte_alloc_one(), pte_free_kernel() and pte_free() > is identical to the generic except of lack of __GFP_ACCOUNT for the user > PTEs allocation. > > Switch csky to use generic version of these functions. Ok. > > The csky implementation of pte_alloc_one_kernel() is not replaced because > it does not clear the allocated page but rather sets each PTE in it to a > non-zero value. Yes, we must set each PTE to _PAGE_GLOBAL because hardware refill the MMU TLB entry with two PTEs and it use the result of pte0.global | pte1.global. If pte0 is valid and pte1 is invalid, we must set _PAGE_GLOBAL in invalid pte entry. Fortunately, there is no performance issue. > > The pte_free_kernel() and pte_free() versions on csky are identical to the > generic ones and can be simply dropped. Ok. Best Regards Guo Ren > > Signed-off-by: Mike Rapoport > --- > arch/csky/include/asm/pgalloc.h | 30 +++--- > 1 file changed, 3 insertions(+), 27 deletions(-) > > diff --git a/arch/csky/include/asm/pgalloc.h b/arch/csky/include/asm/pgalloc.h > index d213bb4..98c571670 100644 > --- a/arch/csky/include/asm/pgalloc.h > +++ b/arch/csky/include/asm/pgalloc.h > @@ -8,6 +8,9 @@ > #include > #include > > +#define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL > +#include /* for pte_{alloc,free}_one */ > + > static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, > pte_t *pte) > { > @@ -39,33 +42,6 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct > *mm) > return pte; > } > > -static inline struct page *pte_alloc_one(struct mm_struct *mm) > -{ > - struct page *pte; > - > - pte = alloc_pages(GFP_KERNEL | __GFP_ZERO, 0); > - if (!pte) > - return NULL; > - > - if (!pgtable_page_ctor(pte)) { > - __free_page(pte); > - return NULL; > - } > - > - return pte; > -} > - > -static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) > -{ > - free_pages((unsigned long)pte, PTE_ORDER); > -} > - > -static inline void pte_free(struct mm_struct *mm, pgtable_t pte) > -{ > - pgtable_page_dtor(pte); > - __free_pages(pte, PTE_ORDER); > -} > - > static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) > { > free_pages((unsigned long)pgd, PGD_ORDER); > -- > 2.7.4 >
Re: [PATCH 19/21] treewide: add checks for the return value of memblock_alloc*()
On Wed, Jan 16, 2019 at 03:44:19PM +0200, Mike Rapoport wrote: > arch/csky/mm/highmem.c| 5 + ... > diff --git a/arch/csky/mm/highmem.c b/arch/csky/mm/highmem.c > index 53b1bfa..3317b774 100644 > --- a/arch/csky/mm/highmem.c > +++ b/arch/csky/mm/highmem.c > @@ -141,6 +141,11 @@ static void __init fixrange_init(unsigned long start, > unsigned long end, > for (; (k < PTRS_PER_PMD) && (vaddr != end); pmd++, > k++) { > if (pmd_none(*pmd)) { > pte = (pte_t *) > memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); > + if (!pte) > + panic("%s: Failed to allocate > %lu bytes align=%lx\n", > + __func__, PAGE_SIZE, > + PAGE_SIZE); > + > set_pmd(pmd, __pmd(__pa(pte))); > BUG_ON(pte != pte_offset_kernel(pmd, > 0)); > } Looks good for me and panic is ok. Reviewed-by: Guo Ren
Re: [PATCH] mm: convert totalram_pages, totalhigh_pages and managed_pages to atomic.
On Mon, Oct 22, 2018 at 10:53:22PM +0530, Arun KS wrote: > Remove managed_page_count_lock spinlock and instead use atomic > variables. > > Suggested-by: Michal Hocko > Suggested-by: Vlastimil Babka > Signed-off-by: Arun KS > > --- > As discussed here, > https://patchwork.kernel.org/patch/10627521/#22261253 > --- > --- > arch/csky/mm/init.c | 4 +- > arch/powerpc/platforms/pseries/cmm.c | 11 ++-- > arch/s390/mm/init.c | 2 +- > arch/um/kernel/mem.c | 4 +- > arch/x86/kernel/cpu/microcode/core.c | 5 +- > drivers/char/agp/backend.c| 4 +- > drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +- > drivers/gpu/drm/i915/i915_gem.c | 2 +- > drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 +- > drivers/hv/hv_balloon.c | 19 +++ > drivers/md/dm-bufio.c | 5 +- > drivers/md/dm-crypt.c | 4 +- > drivers/md/dm-integrity.c | 4 +- > drivers/md/dm-stats.c | 3 +- > drivers/media/platform/mtk-vpu/mtk_vpu.c | 3 +- > drivers/misc/vmw_balloon.c| 2 +- > drivers/parisc/ccio-dma.c | 5 +- > drivers/parisc/sba_iommu.c| 5 +- > drivers/staging/android/ion/ion_system_heap.c | 2 +- > drivers/xen/xen-selfballoon.c | 7 +-- > fs/ceph/super.h | 3 +- > fs/file_table.c | 9 ++-- > fs/fuse/inode.c | 4 +- > fs/nfs/write.c| 3 +- > fs/nfsd/nfscache.c| 3 +- > fs/ntfs/malloc.h | 2 +- > fs/proc/base.c| 3 +- > include/linux/highmem.h | 2 +- > include/linux/mm.h| 2 +- > include/linux/mmzone.h| 10 +--- > include/linux/swap.h | 2 +- > kernel/fork.c | 6 +-- > kernel/kexec_core.c | 5 +- > kernel/power/snapshot.c | 2 +- > lib/show_mem.c| 3 +- > mm/highmem.c | 2 +- > mm/huge_memory.c | 2 +- > mm/kasan/quarantine.c | 4 +- > mm/memblock.c | 6 +-- > mm/memory_hotplug.c | 4 +- > mm/mm_init.c | 3 +- > mm/oom_kill.c | 2 +- > mm/page_alloc.c | 75 > ++- > mm/shmem.c| 12 +++-- > mm/slab.c | 3 +- > mm/swap.c | 3 +- > mm/util.c | 2 +- > mm/vmalloc.c | 4 +- > mm/vmstat.c | 4 +- > mm/workingset.c | 2 +- > mm/zswap.c| 2 +- > net/dccp/proto.c | 6 +-- > net/decnet/dn_route.c | 2 +- > net/ipv4/tcp_metrics.c| 2 +- > net/netfilter/nf_conntrack_core.c | 6 +-- > net/netfilter/xt_hashlimit.c | 4 +- > net/sctp/protocol.c | 6 +-- > security/integrity/ima/ima_kexec.c| 2 +- > 58 files changed, 171 insertions(+), 143 deletions(-) > > diff --git a/arch/csky/mm/init.c b/arch/csky/mm/init.c > index dc07c07..3f4d35e 100644 > --- a/arch/csky/mm/init.c > +++ b/arch/csky/mm/init.c > @@ -71,7 +71,7 @@ void free_initrd_mem(unsigned long start, unsigned long end) > ClearPageReserved(virt_to_page(start)); > init_page_count(virt_to_page(start)); > free_page(start); > - totalram_pages++; > + atomic_long_inc(_pages); > } > } > #endif > @@ -88,7 +88,7 @@ void free_initmem(void) > ClearPageReserved(virt_to_page(addr)); > init_page_count(virt_to_page(addr)); > free_page(addr); > - totalram_pages++; > + atomic_long_inc(_pages); > addr += PAGE_SIZE; > } For csky part, it's OK. Guo Ren