Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1308311ybl; Tue, 13 Aug 2019 10:24:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOJ+UPL92UxVYcvxPiEMtDMFteGuRBn7W4TU3VglFxY8nzxb8ZGhBVb+37tu1PT7ehfK/E X-Received: by 2002:a63:b346:: with SMTP id x6mr35660869pgt.218.1565717092346; Tue, 13 Aug 2019 10:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565717092; cv=none; d=google.com; s=arc-20160816; b=bQrmb8gAo8IJ6GhbA+Cik7kRolS6grlidawv/w/bynG+XMGUBhjQ6VTK5TTnnFGemf 7JZzv3mnW70bu5lubEu94oxkNPyociRC4ewMCLuXYv9oTaF1kMr2VSdV6xFXT1zxOTJX Slnyi8hn40rhhoi1gCeDVm9seYEQFzewLSyhTAx+aqbQEybiInEYH3BHBJ2H9xeV6s/n moWf9Vm4pWSik/i94I08/vOXLzZsqsPeaYtlUUfJISfZz60SCWGLeXxA6afC9B9apxjt G1wsNXsk/OZFVOuN1yggmSQrpjj7H6bKQ7ilnIYNWci3LMqVmUtyndEV2EeBQ1fMOH69 Xuxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=if9i7zh0Qit/yKhgw7AU3xUn9wMFS6+DPvFYQ9IzgUM=; b=lCf4CmUtiXor9mubHwOlxlGx4t7+ckmAli8GAOkNukPHo7BUXFqTGjJLYGv8SmoeDa l/X4/BAwe4N8E33NBAhp8WG5VYr5JFcNmUhzFibkX8iWMnBGPMArSU23mPu7rZH5XYfA Dlk0S5hmWgPGUGJs2hph8XSuYbMCOu0QsniMpkZER/xlN+4le2hGqLxgtMFAUk7LtvMi HkbFeu82QQ+m2Oc7IzfctEFkI2qk9Vzf7hAovF1Ez3n+6rNP3k79lOXZ8t0kD3F/Fwnj FB6nYt2mIT49v57j5rPK/X/hoUVSS6AOSVxgB7i1ZNOz9H+W7JIndjcndv09dxP9BOuV IXsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VtwUJ1g0; 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 c7si1309418pjn.50.2019.08.13.10.24.34; Tue, 13 Aug 2019 10:24:52 -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=VtwUJ1g0; 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 S1727070AbfHMRXO (ORCPT + 99 others); Tue, 13 Aug 2019 13:23:14 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:36097 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726094AbfHMRXN (ORCPT ); Tue, 13 Aug 2019 13:23:13 -0400 Received: by mail-pf1-f195.google.com with SMTP id w2so1160036pfi.3 for ; Tue, 13 Aug 2019 10:23:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=if9i7zh0Qit/yKhgw7AU3xUn9wMFS6+DPvFYQ9IzgUM=; b=VtwUJ1g07ZQGByWFKuFyL++/c5nvno1F4aqLKJsYQmfBbQ5MTGe71PomB52/lhGyX8 uFNnn55FnmpYekD06mwP82wA498ldCCstGkbdaamkBCd03VpR1Cdf2g9o8C8AXT+lK7Z KUOTBBk75tdbOXLAxSmE6tNsIAiAQzMozIj7Z/sRUFBSmEPytowcgm7Cd5wsbJtckLvU rgOGzjR2hjix3JREkZz33D+kHPb8P1RCjZ2aWsn2x+8x8s6ABhsu7kssG9ScCIDr9Xlr 34Ox28ouhz+EwKjuBgKJ6btSZssQtWmp/y4Qmguw5rovtIF0DD/I4NiGpogBjG0bDnzA Y1sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=if9i7zh0Qit/yKhgw7AU3xUn9wMFS6+DPvFYQ9IzgUM=; b=J/DR+70OonQeLi2q7iMcDRcZIhCiEHrg4bnz/u781arNdPWzFDTe3waA6KfahefH0t W3g/E/6Fnw+RlKWBqFmgggLFc4Cgl96Z5BJYivXb2KpktVwDgCReId9zhl0DSBLIT6oA eWnylVLYAZt3PFT4IswrxHggC65sE1MF7UbVoG79di6YzsGRhKTWGZgOFS3A5LL2koJA EtQ4BtDEZYfhaRzsEk6dLeVfap2VZjXYSCpdMjQXbGmFEpNrBlXI1m82mamyHqLs5biU 1crgxgpE97NvOH4lU1PS9kXaj6luozMW2Nnd0LdppVYYPqYUVn0KV3hF40PMBm1jwJP+ 2SEQ== X-Gm-Message-State: APjAAAUCYgs8YVBCY9t6HMFo/huzyODnmGiyRNxrRx5x2A0iykybC1lQ ACyKJ7fhaydvGX4hAvCEu7I= X-Received: by 2002:a17:90a:71ca:: with SMTP id m10mr3264191pjs.27.1565716992214; Tue, 13 Aug 2019 10:23:12 -0700 (PDT) Received: from bharath12345-Inspiron-5559 ([103.110.42.34]) by smtp.gmail.com with ESMTPSA id 203sm15071517pfz.107.2019.08.13.10.23.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Aug 2019 10:23:11 -0700 (PDT) Date: Tue, 13 Aug 2019 22:53:01 +0530 From: Bharath Vedartham To: Dimitri Sivanich Cc: jhubbard@nvidia.com, gregkh@linuxfoundation.org, arnd@arndb.de, 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 Subject: Re: [Linux-kernel-mentees][PATCH v5 1/1] sgi-gru: Remove *pte_lookup functions, Convert to get_user_page*() Message-ID: <20190813172301.GA10228@bharath12345-Inspiron-5559> References: <1565379497-29266-1-git-send-email-linux.bhar@gmail.com> <1565379497-29266-2-git-send-email-linux.bhar@gmail.com> <20190813145029.GA32451@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190813145029.GA32451@hpe.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 13, 2019 at 09:50:29AM -0500, Dimitri Sivanich wrote: > Bharath, > > I do not believe that __get_user_pages_fast will work for the atomic case, as > there is no guarantee that the 'current->mm' will be the correct one for the > process in question, as the process might have moved away from the cpu that is > handling interrupts for it's context. So what your saying is, there may be cases where current->mm != gts->ts_mm right? __get_user_pages_fast and get_user_pages do assume current->mm. These changes were inspired a bit from kvm. In kvm/kvm_main.c, hva_to_pfn_fast uses __get_user_pages_fast. THe comment above the function states it runs in atomic context. Just curious, get_user_pages also uses current->mm. Do you think that is also an issue? Do you feel using get_user_pages_remote would be a better idea? We can specify the mm_struct in get_user_pages_remote? Thank you Bharath > On Sat, Aug 10, 2019 at 01:08:17AM +0530, Bharath Vedartham wrote: > > For pages that were retained via get_user_pages*(), release those pages > > via the new put_user_page*() routines, instead of via put_page() or > > release_pages(). > > > > This is part a tree-wide conversion, as described in commit fc1d8e7cca2d > > ("mm: introduce put_user_page*(), placeholder versions"). > > > > As part of this conversion, 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, because it does not fall > > back to the slow path: get_user_pages(). get_user_pages_fast(), on the other > > hand, first calls __get_user_pages_fast(), but then falls back to the > > slow path if __get_user_pages_fast() fails. > > > > Also: remove unnecessary CONFIG_HUGETLB ifdefs. > > > > 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. > > Changes since v4 > > - Updated changelog according to John Hubbard. > > --- > > 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 > >