Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7582039ybi; Mon, 22 Jul 2019 16:10:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqw2wg9M53x7D/2XeQqC7MHiCraAKiHZcCQErE5kYp0ll46yz3vpy+ohw6KEC6hpKwRWBwfr X-Received: by 2002:a17:902:e512:: with SMTP id ck18mr73630778plb.53.1563837044137; Mon, 22 Jul 2019 16:10:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563837044; cv=none; d=google.com; s=arc-20160816; b=tHIZv13cNEEJrCFcz3UFC5y1YIi13GnbmZ3XxeIljP3fQw3FG4K66mo7lBJDz2/iMA sUZ+DpEu8Dvl/p1CGJyzJg6sVHkL6Kz6CsXYEDc5fbsZpp9Mw2rK6Un2Z7oUsss170o2 6Hw/hv/MGfiB6UJaw37QKk2sjkNi2A12veqaKmK9E6gb0J/2bzwUqkUwMDM7eW9R1aP1 +r0yUW4pvAyAAlBVKCrVt48BPx2IqtZd9LdxIyArQ4/R8gMqIreZBuzCv4Iar9sIx3Ee bl1+Ei4l8lKoR/8bs9cqPc0698fEGr0PSPfF4FRSGtvgFc+4X5l9czDQG9agb0Smo3mA YxLA== 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=H7q9PajozpPfkURyyrCsIMllw+YfN7PAIvmTYKCRDl4=; b=CAKlNO/zBGJg2Cu1iizKQz4r33I+AKEM2I4/JWlTRZpzyrbiL+A4RMbyPCMf7Jw213 6D2WkbcKCbqldK9Xbl4tFe4AZnNhpoYzslNcCDb3h9kUw9e8PQ9/vRyunHrp5CE/t1Ea sNNz65vnAe0R29J4BaXFjRUeYJfblBGjHLMMYxaaLGQasr3/fgGeDA+td7cThjAyw2jh FH1RJNPUJDWuPyBE5v65cuHtyF8lNmFhOHF2KeZ58Nlw7sQFuJ72NiD/cfzX170L39J7 f0G8iCd4hLsiUbjm/6WCt64wMidnf3yRh795PQ36inhJQBO6vdjCsFcfmMfJ+UY13PeT TGNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=O5IXMDx+; 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 f5si10085377pgb.461.2019.07.22.16.10.10; Mon, 22 Jul 2019 16:10:44 -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=O5IXMDx+; 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 S1730549AbfGVRxT (ORCPT + 99 others); Mon, 22 Jul 2019 13:53:19 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:43008 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727021AbfGVRxS (ORCPT ); Mon, 22 Jul 2019 13:53:18 -0400 Received: by mail-pf1-f196.google.com with SMTP id i189so17734330pfg.10 for ; Mon, 22 Jul 2019 10:53:18 -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=H7q9PajozpPfkURyyrCsIMllw+YfN7PAIvmTYKCRDl4=; b=O5IXMDx+fn5jEyxDTI2ZTQIepWM+5O99gQOJBV67iOa2Z6dMIo0zZ5+UuKXsmhlRa+ ULSFQxQ5bIai8gmpxq0U+srcKiwWISbz1BGbisQqP703jECx36HB8Eju2SO8EAJIr3Qc JgZPfdvGZLrupJZ9uhyc615Hv0tA8tPlpu4tuk6Ls9zrFrniJ7ctktuI5y3qfNisEoFK qcWln97M/Ch+fjtfkNH8yCIBRqHF0hqY9geXTvNdjsr/dhfhBDfeJSWF97mF+M2eI051 F6laRFUzgnsMU/WUtHJqgDlkDjOxVq5Yg3SFPULHYiMa56P99awl35VVu4t9xarXe/2N S98Q== 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=H7q9PajozpPfkURyyrCsIMllw+YfN7PAIvmTYKCRDl4=; b=ZMAL90idWRgzuJuy2XG9GXlTvxKcUIrw2cLPDmdWEwgqr478KDEE18xIfmXrBle5ts vRpgtfHoF27q1RvmC125Nk4Z1WXRDmwPAf5cN/B5fSEO8q69x1HKIgyWYntTM05oC1QP 0nXyeS62Zcw8Xvbb4e2bhwjKJE0pM2vYVrWE7FC67PVb+1RwDmI2YTblDPlO3JLni8pD iDemc19/Im4WwzhD5DtG82wo4+V4A/z3oITJrLyWqYu7zq81s7R2N8m1MTmj4sXLniyc vlyS2Usl8GL3v4f/LQ2tZdxl2z5trbANtlyrfLyBZhia/qOZnyYC/QQP8UEYwWQVPMZW x6tw== X-Gm-Message-State: APjAAAVhRgTNC5+fi/gojP2hzWqA+kHQGpmXxNr+AeI/LqG+EWTKHDDG hhFR5NxZiHTb972/lbM2ZpU= X-Received: by 2002:a65:6546:: with SMTP id a6mr18008344pgw.220.1563817997653; Mon, 22 Jul 2019 10:53:17 -0700 (PDT) Received: from bharath12345-Inspiron-5559 ([103.110.42.34]) by smtp.gmail.com with ESMTPSA id z4sm60980856pfg.166.2019.07.22.10.53.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jul 2019 10:53:17 -0700 (PDT) Date: Mon, 22 Jul 2019 23:23:11 +0530 From: Bharath Vedartham To: John Hubbard Cc: arnd@arndb.de, sivanich@sgi.com, gregkh@linuxfoundation.org, ira.weiny@intel.com, jglisse@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 3/3] sgi-gru: Use __get_user_pages_fast in atomic_pte_lookup Message-ID: <20190722175310.GC12278@bharath12345-Inspiron-5559> References: <1563724685-6540-1-git-send-email-linux.bhar@gmail.com> <1563724685-6540-4-git-send-email-linux.bhar@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Sun, Jul 21, 2019 at 07:32:36PM -0700, John Hubbard wrote: > On 7/21/19 8:58 AM, Bharath Vedartham wrote: > > *pte_lookup functions get the physical address for a given virtual > > address by getting a physical page using gup and use page_to_phys to get > > the physical address. > > > > Currently, atomic_pte_lookup manually walks the page tables. If this > > function fails to get a physical page, it will fall back too > > non_atomic_pte_lookup to get a physical page which uses the slow gup > > path to get the physical page. > > > > Instead of manually walking the page tables use __get_user_pages_fast > > which does the same thing and it does not fall back to the slow gup > > path. > > > > This is largely inspired from kvm code. kvm uses __get_user_pages_fast > > in hva_to_pfn_fast function which can run in an atomic context. > > > > Cc: Ira Weiny > > Cc: John Hubbard > > Cc: J?r?me Glisse > > Cc: Greg Kroah-Hartman > > Cc: Dimitri Sivanich > > Cc: Arnd Bergmann > > Cc: linux-kernel@vger.kernel.org > > Cc: linux-mm@kvack.org > > Signed-off-by: Bharath Vedartham > > --- > > drivers/misc/sgi-gru/grufault.c | 39 +++++---------------------------------- > > 1 file changed, 5 insertions(+), 34 deletions(-) > > > > diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c > > index 75108d2..121c9a4 100644 > > --- a/drivers/misc/sgi-gru/grufault.c > > +++ b/drivers/misc/sgi-gru/grufault.c > > @@ -202,46 +202,17 @@ static int non_atomic_pte_lookup(struct vm_area_struct *vma, > > 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; > > + struct page *page; > > > > - 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); > > + *pageshift = is_vm_hugetlb_page(vma) ? HPAGE_SHIFT : PAGE_SHIFT; > > > > - if (unlikely(!pte_present(pte) || > > - (write && (!pte_write(pte) || !pte_dirty(pte))))) > > + if (!__get_user_pages_fast(vaddr, 1, write, &page)) > > return 1; > > Let's please use numeric, not boolean comparison, for the return value of > gup. Alright then! I ll resubmit it! > Also, optional: as long as you're there, atomic_pte_lookup() ought to > either return a bool (true == success) or an errno, rather than a > numeric zero or one. That makes sense. But the code which uses atomic_pte_lookup uses the return value of 1 for success and failure value of 0 in gru_vtop. That's why I did not mess with the return values in this code. It would require some change in the driver functionality which I am not ready to do :( > Other than that, this looks like a good cleanup, I wonder how many > open-coded gup implementations are floating around like this. I ll be on the lookout! > thanks, > -- > John Hubbard > NVIDIA > > > > > - *paddr = pte_pfn(pte) << PAGE_SHIFT; > > - > > - *pageshift = is_vm_hugetlb_page(vma) ? HPAGE_SHIFT : PAGE_SHIFT; > > + *paddr = page_to_phys(page); > > + put_user_page(page); > > > > return 0; > > - > > -err: > > - return 1; > > } > > > > static int gru_vtop(struct gru_thread_state *gts, unsigned long vaddr, > >