* [PATCH v3 0/1] get_user_pages changes @ 2019-07-26 19:41 Bharath Vedartham 2019-07-26 19:42 ` [PATCH v3 1/1] sgi-gru: Remove *pte_lookup functions Bharath Vedartham 0 siblings, 1 reply; 5+ messages in thread From: Bharath Vedartham @ 2019-07-26 19:41 UTC (permalink / raw) To: sivanich, arnd Cc: ira.weiny, jhubbard, jglisse, gregkh, william.kucharski, hch, linux-kernel, linux-mm, Bharath Vedartham In this 3rd version of the patch series, I have compressed the patches of the previous patch series into one patch. This was suggested by Christoph Hellwig. The suggestion was to remove the pte_lookup functions and use the g et_user_pages* functions directly instead of the pte_lookup functions. There is nothing different in this series compared to the previous series, It essentially compresses the 3 patches of the original series into one patch. Bharath Vedartham (1): sgi-gru: Remove *pte_lookup functions drivers/misc/sgi-gru/grufault.c | 114 +++++++++------------------------------- 1 file changed, 25 insertions(+), 89 deletions(-) -- 2.7.4 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/1] sgi-gru: Remove *pte_lookup functions 2019-07-26 19:41 [PATCH v3 0/1] get_user_pages changes Bharath Vedartham @ 2019-07-26 19:42 ` Bharath Vedartham 2019-07-28 17:56 ` Bharath Vedartham 2019-07-29 6:48 ` Christoph Hellwig 0 siblings, 2 replies; 5+ messages in thread From: Bharath Vedartham @ 2019-07-26 19:42 UTC (permalink / raw) To: sivanich, arnd Cc: ira.weiny, jhubbard, jglisse, gregkh, william.kucharski, hch, linux-kernel, linux-mm, Bharath Vedartham The *pte_lookup functions can be removed and be easily replaced with get_user_pages_fast functions. In the case of atomic lookup, __get_user_pages_fast is used which does not fall back to slow get_user_pages. get_user_pages_fast on the other hand tries to use __get_user_pages_fast but fallbacks to slow get_user_pages if __get_user_pages_fast fails. Also unnecessary ifdefs to check for CONFIG_HUGETLB is removed as the check is redundant. Cc: Ira Weiny <ira.weiny@intel.com> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Jérôme Glisse <jglisse@redhat.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Dimitri Sivanich <sivanich@sgi.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: William Kucharski <william.kucharski@oracle.com> Cc: Christoph Hellwig <hch@lst.de> Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Reviewed-by: William Kucharski <william.kucharski@oracle.com> Signed-off-by: Bharath Vedartham <linux.bhar@gmail.com> --- This is a fold of the 3 patches in the previous patch series. The review tags were given to the individual patches. --- drivers/misc/sgi-gru/grufault.c | 114 +++++++++------------------------------- 1 file changed, 25 insertions(+), 89 deletions(-) diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c index 4b713a8..c1258ea 100644 --- a/drivers/misc/sgi-gru/grufault.c +++ b/drivers/misc/sgi-gru/grufault.c @@ -166,96 +166,20 @@ static void get_clear_fault_map(struct gru_state *gru, } /* - * Atomic (interrupt context) & non-atomic (user context) functions to - * convert a vaddr into a physical address. The size of the page - * is returned in pageshift. - * returns: - * 0 - successful - * < 0 - error code - * 1 - (atomic only) try again in non-atomic context - */ -static int non_atomic_pte_lookup(struct vm_area_struct *vma, - unsigned long vaddr, int write, - unsigned long *paddr, int *pageshift) -{ - struct page *page; - -#ifdef CONFIG_HUGETLB_PAGE - *pageshift = is_vm_hugetlb_page(vma) ? HPAGE_SHIFT : PAGE_SHIFT; -#else - *pageshift = PAGE_SHIFT; -#endif - if (get_user_pages(vaddr, 1, write ? FOLL_WRITE : 0, &page, NULL) <= 0) - return -EFAULT; - *paddr = page_to_phys(page); - put_page(page); - return 0; -} - -/* - * atomic_pte_lookup + * mmap_sem is already helod on entry to this function. This guarantees + * existence of the page tables. * - * Convert a user virtual address to a physical address * Only supports Intel large pages (2MB only) on x86_64. - * ZZZ - hugepage support is incomplete - * - * NOTE: mmap_sem is already held on entry to this function. This - * guarantees existence of the page tables. + * ZZZ - hugepage support is incomplete. */ -static int atomic_pte_lookup(struct vm_area_struct *vma, unsigned long vaddr, - int write, unsigned long *paddr, int *pageshift) -{ - pgd_t *pgdp; - p4d_t *p4dp; - pud_t *pudp; - pmd_t *pmdp; - pte_t pte; - - pgdp = pgd_offset(vma->vm_mm, vaddr); - if (unlikely(pgd_none(*pgdp))) - goto err; - - p4dp = p4d_offset(pgdp, vaddr); - if (unlikely(p4d_none(*p4dp))) - goto err; - - pudp = pud_offset(p4dp, vaddr); - if (unlikely(pud_none(*pudp))) - goto err; - - pmdp = pmd_offset(pudp, vaddr); - if (unlikely(pmd_none(*pmdp))) - goto err; -#ifdef CONFIG_X86_64 - if (unlikely(pmd_large(*pmdp))) - pte = *(pte_t *) pmdp; - else -#endif - pte = *pte_offset_kernel(pmdp, vaddr); - - if (unlikely(!pte_present(pte) || - (write && (!pte_write(pte) || !pte_dirty(pte))))) - return 1; - - *paddr = pte_pfn(pte) << PAGE_SHIFT; -#ifdef CONFIG_HUGETLB_PAGE - *pageshift = is_vm_hugetlb_page(vma) ? HPAGE_SHIFT : PAGE_SHIFT; -#else - *pageshift = PAGE_SHIFT; -#endif - return 0; - -err: - return 1; -} - static int gru_vtop(struct gru_thread_state *gts, unsigned long vaddr, int write, int atomic, unsigned long *gpa, int *pageshift) { struct mm_struct *mm = gts->ts_mm; struct vm_area_struct *vma; unsigned long paddr; - int ret, ps; + int ret; + struct page *page; vma = find_vma(mm, vaddr); if (!vma) @@ -263,21 +187,33 @@ static int gru_vtop(struct gru_thread_state *gts, unsigned long vaddr, /* * Atomic lookup is faster & usually works even if called in non-atomic - * context. + * context. get_user_pages_fast does atomic lookup before falling back to + * slow gup. */ rmb(); /* Must/check ms_range_active before loading PTEs */ - ret = atomic_pte_lookup(vma, vaddr, write, &paddr, &ps); - if (ret) { - if (atomic) + if (atomic) { + ret = __get_user_pages_fast(vaddr, 1, write, &page); + if (!ret) goto upm; - if (non_atomic_pte_lookup(vma, vaddr, write, &paddr, &ps)) + } else { + ret = get_user_pages_fast(vaddr, 1, write, &page); + if (!ret) goto inval; } + + paddr = page_to_phys(page); + put_user_page(page); + + if (unlikely(is_vm_hugetlb_page(vma))) + *pageshift = HPAGE_SHIFT; + else + *pageshift = PAGE_SHIFT; + if (is_gru_paddr(paddr)) goto inval; - paddr = paddr & ~((1UL << ps) - 1); - *gpa = uv_soc_phys_ram_to_gpa(paddr); - *pageshift = ps; + paddr = paddr & ~((1UL << *pageshift) - 1); + *gpa = uv_soc_phys_ram_to_gpa(paddr); + return VTOP_SUCCESS; inval: -- 2.7.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/1] sgi-gru: Remove *pte_lookup functions 2019-07-26 19:42 ` [PATCH v3 1/1] sgi-gru: Remove *pte_lookup functions Bharath Vedartham @ 2019-07-28 17:56 ` Bharath Vedartham 2019-07-29 6:48 ` Christoph Hellwig 1 sibling, 0 replies; 5+ messages in thread From: Bharath Vedartham @ 2019-07-28 17:56 UTC (permalink / raw) To: Hillf Danton Cc: sivanich, arnd, ira.weiny, jhubbard, jglisse, gregkh, william.kucharski, hch, linux-kernel, linux-mm On Sat, Jul 27, 2019 at 05:22:28PM +0800, Hillf Danton wrote: > > On Fri, 26 Jul 2019 12:42:26 -0700 (PDT) Bharath Vedartham wrote: > > > > static int gru_vtop(struct gru_thread_state *gts, unsigned long vaddr, > > int write, int atomic, unsigned long *gpa, int *pageshift) > > { > > struct mm_struct *mm = gts->ts_mm; > > struct vm_area_struct *vma; > > unsigned long paddr; > > - int ret, ps; > > + int ret; > > + struct page *page; > > > > vma = find_vma(mm, vaddr); > > if (!vma) > > @@ -263,21 +187,33 @@ static int gru_vtop(struct gru_thread_state *gts, unsigned long vaddr, > > > > /* > > * Atomic lookup is faster & usually works even if called in non-atomic > > - * context. > > + * context. get_user_pages_fast does atomic lookup before falling back to > > + * slow gup. > > */ > > rmb(); /* Must/check ms_range_active before loading PTEs */ > > - ret = atomic_pte_lookup(vma, vaddr, write, &paddr, &ps); > > - if (ret) { > > - if (atomic) > > + if (atomic) { > > + ret = __get_user_pages_fast(vaddr, 1, write, &page); > > + if (!ret) > > goto upm; > > - if (non_atomic_pte_lookup(vma, vaddr, write, &paddr, &ps)) > > + } else { > > + ret = get_user_pages_fast(vaddr, 1, write, &page); > > + if (!ret) > > goto inval; > > } > > + > > + paddr = page_to_phys(page); > > You may drop find_vma() above if PageHuge(page) makes sense here. I don't think it does. Hugepage support is still incomplete for this driver. Thank you Bharath > > + put_user_page(page); > > + > > + if (unlikely(is_vm_hugetlb_page(vma))) > > + *pageshift = HPAGE_SHIFT; > > + else > > + *pageshift = PAGE_SHIFT; > > + > > if (is_gru_paddr(paddr)) > > goto inval; > > - paddr = paddr & ~((1UL << ps) - 1); > > - *gpa = uv_soc_phys_ram_to_gpa(paddr); > > - *pageshift = ps; > > + paddr = paddr & ~((1UL << *pageshift) - 1); > > + *gpa = uv_soc_phys_ram_to_gpa(paddr); > > + > > return VTOP_SUCCESS; > > > > inval: > > -- > > 2.7.4 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/1] sgi-gru: Remove *pte_lookup functions 2019-07-26 19:42 ` [PATCH v3 1/1] sgi-gru: Remove *pte_lookup functions Bharath Vedartham 2019-07-28 17:56 ` Bharath Vedartham @ 2019-07-29 6:48 ` Christoph Hellwig 2019-07-30 10:26 ` Bharath Vedartham 1 sibling, 1 reply; 5+ messages in thread From: Christoph Hellwig @ 2019-07-29 6:48 UTC (permalink / raw) To: Bharath Vedartham Cc: sivanich, arnd, ira.weiny, jhubbard, jglisse, gregkh, william.kucharski, hch, linux-kernel, linux-mm On Sat, Jul 27, 2019 at 01:12:00AM +0530, Bharath Vedartham wrote: > + ret = get_user_pages_fast(vaddr, 1, write, &page); I think you want to pass "write ? FOLL_WRITE : 0" here, as get_user_pages_fast takes a gup_flags argument, not a boolean write flag. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/1] sgi-gru: Remove *pte_lookup functions 2019-07-29 6:48 ` Christoph Hellwig @ 2019-07-30 10:26 ` Bharath Vedartham 0 siblings, 0 replies; 5+ messages in thread From: Bharath Vedartham @ 2019-07-30 10:26 UTC (permalink / raw) To: Christoph Hellwig Cc: sivanich, arnd, ira.weiny, jhubbard, jglisse, gregkh, william.kucharski, linux-kernel, linux-mm On Mon, Jul 29, 2019 at 08:48:42AM +0200, Christoph Hellwig wrote: > On Sat, Jul 27, 2019 at 01:12:00AM +0530, Bharath Vedartham wrote: > > + ret = get_user_pages_fast(vaddr, 1, write, &page); > > I think you want to pass "write ? FOLL_WRITE : 0" here, as > get_user_pages_fast takes a gup_flags argument, not a boolean > write flag. You are right there! I ll send another version correcting this. Thank you Bharath ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-07-30 10:26 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-07-26 19:41 [PATCH v3 0/1] get_user_pages changes Bharath Vedartham 2019-07-26 19:42 ` [PATCH v3 1/1] sgi-gru: Remove *pte_lookup functions Bharath Vedartham 2019-07-28 17:56 ` Bharath Vedartham 2019-07-29 6:48 ` Christoph Hellwig 2019-07-30 10:26 ` Bharath Vedartham
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).