Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9471200ybi; Wed, 24 Jul 2019 04:44:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqyb9QDdxsodRAe15mZwtpd3PGj0TE7YQX9fYrDjn9LuzH3fruIFjkI0Jf9n7sOTnIz6WGwV X-Received: by 2002:a65:500a:: with SMTP id f10mr50259712pgo.105.1563968668450; Wed, 24 Jul 2019 04:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563968668; cv=none; d=google.com; s=arc-20160816; b=Tn/CRGUijTn9kDqU3hSWLQJfkxxjWFlJo/Yl4TVQhlP+4VWFNEs/P6MAeGWQzkCSmh QVdBuHPZEpkwY3zBRVV/hYW52htIizqNNI8c8whZcF2+2APXRvhHW269buzhLd2h4wT9 9Ra3X0dG4aNDPo2L3I2Gr7mpOQ0AzYfBAGl5Yi8/H54u2LAKJBHQPDYoBdW4AAUSWlkM Xc9qwws771+laWZCxmXCoOg+/iUSylpfry9ooedI0P7szsMktiLn9wV/YWf5WiffVLRf lkZWyFL27DxWJGwygM3JRveONwwwnJKOPCbvGXdHS9LmZHPbq8+Qm7Iixy5jkW0kE7BF klZQ== 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=3/B7iS7twoHuFiN2Sq9UrpmOirWTgDsR38WI+eokeIw=; b=uATg53oTHfGkWY9CrTUhgHlfvdBQ7Ny4LuzpipjuujnhMREmH67gkrUMArR/dU3LlZ N0IVdDpzS8gIFOHtxtH2r7vYJIDTnc2tgjn9li5o+dgfsUMiCqTEcQfOyJksVZ4rqes0 K50BkHvDU98O72ole5sT8yclX+0Fcn0wyvpuVFSgR6cWoDyIrn2saxdHZh3cljk3yL6J QU34IIdBgi3dilk+b9Q3Dl57/n2oovErRroVJ1A7tOQme8D1h88o8R2PV1SZWEc/OOzE PU44/box5aSHSLM+nsP57SdU8jtUvvW+J4+na475/kEMN/M9RyZVhzL5XW+mStwLxbQE aSiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nuwmBoyk; 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 a13si14242498pgt.217.2019.07.24.04.44.13; Wed, 24 Jul 2019 04:44:28 -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=nuwmBoyk; 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 S1727719AbfGXLlp (ORCPT + 99 others); Wed, 24 Jul 2019 07:41:45 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:35992 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727378AbfGXLlp (ORCPT ); Wed, 24 Jul 2019 07:41:45 -0400 Received: by mail-pg1-f195.google.com with SMTP id l21so21104501pgm.3 for ; Wed, 24 Jul 2019 04:41:44 -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=3/B7iS7twoHuFiN2Sq9UrpmOirWTgDsR38WI+eokeIw=; b=nuwmBoyk/4mjKCCvHAMVDXxEHZeOXfghybqdlk45TABHI4NUxhZ7qZwTt4dgyuKVLk FdDuimPLodOe8X9r/jmApQ7hICQ2IjRf0du84YnIZK7DyFIncOglG/om0sL0N3Q7irou odpU3/NHnGVesgsh+LUJ3gU2qlBu0HUuj0dB/IVHsAQSalNpQstuQw9Rj9a+ibPlb8Mq 4zCr9nj3e5eppuywNhUaSody/+rxS7Fyt1hQWYs+9lfgebNTWkb9Xg+m8jf9qQBUoUSI mhSFVpXKlTKpoVv/wQOx20JWHfTeApoEsLMG3H2PcnTnUqr5PMtCAprlqC0JQeu2QWu9 7MhA== 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=3/B7iS7twoHuFiN2Sq9UrpmOirWTgDsR38WI+eokeIw=; b=c4LuzY+IxFqwnrpMx8sJAZceftqD0y7QV9SfP16sDFHoWWr+dKYi1pIendkZ1yHBBg f052Y/7mOq29l3REHrITm3Zn+HCcFCAPL+lBaIxJK0ODFfSsBofAHioxMFFfukXKuTYm 6h4Md2skNguQV7/7BjppcWqqAzsk1tyJsqP+yuUH7rgi+FGFMRlVjDBPoh0aNljOJ8Iu L79DR3XNCs78+7hFdsUpXxJkiYyUx8UiKxYt8426fuPLy0ti4OmpS52/SPLb5IyVZNKC Fa1nnmZrj/Nqw1IPBMj2Lvc6zhNWceUVcboVXlZKqBvVN/nQzqZOY4IACIa9ERTgJH0u 7JxA== X-Gm-Message-State: APjAAAVUtC3jequmzxcwVD7sGyDBtaCw63G1COSF812Z27EGu8NI53qu TtxNrDxZ5L15OX6VH9tlxDc= X-Received: by 2002:aa7:957c:: with SMTP id x28mr10859669pfq.42.1563968504581; Wed, 24 Jul 2019 04:41:44 -0700 (PDT) Received: from bharath12345-Inspiron-5559 ([103.110.42.34]) by smtp.gmail.com with ESMTPSA id o14sm46177906pjp.29.2019.07.24.04.41.43 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 Jul 2019 04:41:44 -0700 (PDT) From: Bharath Vedartham To: sivanich@sgi.com, arnd@arndb.de, jhubbard@nvidia.com Cc: ira.weiny@intel.com, jglisse@redhat.com, gregkh@linuxfoundation.org, william.kucharski@oracle.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bharath Vedartham Subject: [PATCH v2 3/3] sgi-gru: Use __get_user_pages_fast in atomic_pte_lookup Date: Wed, 24 Jul 2019 17:11:16 +0530 Message-Id: <1563968476-12785-4-git-send-email-linux.bhar@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1563968476-12785-1-git-send-email-linux.bhar@gmail.com> References: <1563968476-12785-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 *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. Also, the function atomic_pte_lookup's return value has been changed to boolean. The callsites have been appropriately modified. 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: William Kucharski Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Reviewed-by: Ira Weiny Signed-off-by: Bharath Vedartham --- Changes since v2 - Modified the return value of atomic_pte_lookup to use booleans rather than numeric values. This was suggested by John Hubbard. --- drivers/misc/sgi-gru/grufault.c | 56 +++++++++++------------------------------ 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c index bce47af..da2d2cc 100644 --- a/drivers/misc/sgi-gru/grufault.c +++ b/drivers/misc/sgi-gru/grufault.c @@ -193,9 +193,11 @@ static int non_atomic_pte_lookup(struct vm_area_struct *vma, } /* - * atomic_pte_lookup + * atomic_pte_lookup() - Convert a user virtual address + * to a physical address. + * @Return: true for success, false for failure. Failure means that + * the page could not be pinned via gup fast. * - * Convert a user virtual address to a physical address * Only supports Intel large pages (2MB only) on x86_64. * ZZZ - hugepage support is incomplete * @@ -205,49 +207,20 @@ 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; - - 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; + struct page *page; if (unlikely(is_vm_hugetlb_page(vma))) *pageshift = HPAGE_SHIFT; else *pageshift = PAGE_SHIFT; - return 0; + if (!__get_user_pages_fast(vaddr, 1, write, &page)) + return false; -err: - return 1; + *paddr = page_to_phys(page); + put_user_page(page); + + return true; } static int gru_vtop(struct gru_thread_state *gts, unsigned long vaddr, @@ -256,7 +229,8 @@ static int gru_vtop(struct gru_thread_state *gts, unsigned long vaddr, struct mm_struct *mm = gts->ts_mm; struct vm_area_struct *vma; unsigned long paddr; - int ret, ps; + int ps; + bool success; vma = find_vma(mm, vaddr); if (!vma) @@ -267,8 +241,8 @@ static int gru_vtop(struct gru_thread_state *gts, unsigned long vaddr, * context. */ rmb(); /* Must/check ms_range_active before loading PTEs */ - ret = atomic_pte_lookup(vma, vaddr, write, &paddr, &ps); - if (ret) { + success = atomic_pte_lookup(vma, vaddr, write, &paddr, &ps); + if (!success) { if (atomic) goto upm; if (non_atomic_pte_lookup(vma, vaddr, write, &paddr, &ps)) -- 2.7.4