Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp7215424ybh; Thu, 8 Aug 2019 11:58:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1/1FQqH1bxThS44MWvUQuXVS1mO10rYLyLyyo4z+E1P3kJG4TlqM5SmAiu3KEjLwQ52o3 X-Received: by 2002:a63:5648:: with SMTP id g8mr13747461pgm.81.1565290702258; Thu, 08 Aug 2019 11:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565290702; cv=none; d=google.com; s=arc-20160816; b=iUh6xC0UsbFiW6IQTwfl/NR5D/Gmei0cGTfRVZsknBPWXakTg5vgQ7OXNQL/oYD4Sl r0q+W6X3+psTuQr3i4wpfSZZNdJKeiFp6PVsHs70yhtKre/kEluw95qcO4xdJW3WHRaw WZ6VsbcOjNDlLuBCwQHvo4u9Id0n7G0aXLecAvHimcvcuRJX1d45w8Eabkbx2e7lWLe6 9+r9H8Wwt7+KPOB1jPu853/Q4EUWxEDr9L52qY6MVVuLuruzuSouj0P0BIXI1TVuP6LH k0Qd56Hwb/XLq6arK4mXR8btuCKTGMhHaHUycH9Rt0wkmudxExYORZU3Ev4d9VzFIYJT QcUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VL69OhOnAwL0XYVUd4iryHVhyGAPtRV3TIOYsddsZuM=; b=juWudNrO5pOfK0080XBzU+iNUY9iDFc1e2hQMwCkn4GLh2uHLfrEFTiR0EzeppizjH 5K1iqh6lXOtSvB81RB6gw7dTesS8rphauf7gBDc2arybU7BeqrXYJYandus6AYP3Ez5r FJ2iu9TSss3RQGwNvKkG0q0XrfAS90vQTJdwLaRvHIuNNXGDmA3RhIMAlAWPovtVPAyH 5hS5y+y+1jHUrAT3LTLQPn76D8EsE40j1ssJj5K42x7XNxc7RS8u7mbKDpipZrnRmNJL UGdHb25iF9bPFffQlKCG03Jyyq73LEVEuwMtCObTsytMUQBfvh7PqzZH8SF3dHJYMuWj wv3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f+6juk5f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t17si41880895pgv.54.2019.08.08.11.58.07; Thu, 08 Aug 2019 11:58:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f+6juk5f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404240AbfHHS4J (ORCPT + 99 others); Thu, 8 Aug 2019 14:56:09 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35293 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403901AbfHHS4I (ORCPT ); Thu, 8 Aug 2019 14:56:08 -0400 Received: by mail-pg1-f193.google.com with SMTP id n4so2793407pgv.2 for ; Thu, 08 Aug 2019 11:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VL69OhOnAwL0XYVUd4iryHVhyGAPtRV3TIOYsddsZuM=; b=f+6juk5fgHqCxIRZWOOX36n2xL+/ppYo6Qbp1wljaKvVZnxFO820pyEsxKJ+vzEohX iKEFP7KQmuYg8BHp7MrWIhekF3jI8lUXgLsJmLTkSUtsl3554ZtFb7tEBGT1ThcC0eYv +sj6KHPxY975ct1rBh22CFOoH8Ij/fIXgEyUGWCnTga/tYRdZyZ82980RC7Z9OVAllzz 3xMch/mpGq/SqoHlTvQggN2YjjIb/OnUdvYEmmAwiU4DDFqSASHsjEwlGYgIDFiNWItF JsP4Bv+hLGBF+6/jSYP6NeVuB/YQ2s7w9XD+YORSAIH92rnZPf6SPMm6TCToigz79AUY cFlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VL69OhOnAwL0XYVUd4iryHVhyGAPtRV3TIOYsddsZuM=; b=tCnx/Twq/3h2r23/0txUowkYqRexgICbddVhRmFRqOHa0vroiJl8K9wXDr83NgsZHj c/n9Wp5EjXc6Xj9YbOXtaPh1bEmQAVuOI8evBNzVOhMADHuCHhvabPLJLKXjN4fDfuN1 5fxwz0nx73J2HotLh0HtKttWYSIZbg10zHMCQLH72W3/CkqzkHo6NkBon38JVk0K1Inm vLa10GaU+GBRuRRK/5+Qs4s5fAD9UbuZmRWUW9CP/8mIX39HAJWpGC5LxXM1rF7eEodg zfJZn1H8KFCK4Qp0qvWKmWf2uKyehikhLiS4K0WW49AAjYw74El7FAdfdMvf0AI1gaUy LnKg== X-Gm-Message-State: APjAAAWNkWcPUNU9jbli2tHkcDS2l3Zfn2GLjf896QNsm3QS9pxvDpzy IZBLvpvLyETzvrDFWjEHn3E= X-Received: by 2002:a63:d002:: with SMTP id z2mr14374376pgf.364.1565290568086; Thu, 08 Aug 2019 11:56:08 -0700 (PDT) Received: from bharath12345-Inspiron-5559 ([103.110.42.33]) by smtp.gmail.com with ESMTPSA id p2sm135451554pfb.118.2019.08.08.11.56.06 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Aug 2019 11:56:07 -0700 (PDT) From: Bharath Vedartham To: arnd@arndb.de, gregkh@linuxfoundation.org, sivanich@sgi.com, jhubbard@nvidia.com Cc: ira.weiny@intel.com, jglisse@redhat.com, william.kucharski@oracle.com, hch@lst.de, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kernel-mentees@lists.linuxfoundation.org, Bharath Vedartham Subject: [Linux-kernel-mentees][PATCH v4 1/1] sgi-gru: Remove *pte_lookup functions Date: Fri, 9 Aug 2019 00:25:55 +0530 Message-Id: <1565290555-14126-2-git-send-email-linux.bhar@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1565290555-14126-1-git-send-email-linux.bhar@gmail.com> References: <1565290555-14126-1-git-send-email-linux.bhar@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: John Hubbard Cc: Jérôme Glisse Cc: Greg Kroah-Hartman Cc: Dimitri Sivanich Cc: Arnd Bergmann Cc: William Kucharski Cc: Christoph Hellwig Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-kernel-mentees@lists.linuxfoundation.org Reviewed-by: Ira Weiny Reviewed-by: John Hubbard Reviewed-by: William Kucharski Signed-off-by: Bharath Vedartham --- This is a fold of the 3 patches in the v2 patch series. The review tags were given to the individual patches. Changes since v3 - Used gup flags in get_user_pages_fast rather than boolean flags. --- drivers/misc/sgi-gru/grufault.c | 112 +++++++++------------------------------- 1 file changed, 24 insertions(+), 88 deletions(-) diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c index 4b713a8..304e9c5 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 ? FOLL_WRITE : 0, &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); + paddr = paddr & ~((1UL << *pageshift) - 1); *gpa = uv_soc_phys_ram_to_gpa(paddr); - *pageshift = ps; + return VTOP_SUCCESS; inval: -- 2.7.4