From patchwork Thu Apr 4 20:23:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barret Rhoden X-Patchwork-Id: 10886259 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97879922 for ; Thu, 4 Apr 2019 20:24:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 826A828AE3 for ; Thu, 4 Apr 2019 20:24:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76BC428AF2; Thu, 4 Apr 2019 20:24:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 020D728AE3 for ; Thu, 4 Apr 2019 20:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730835AbfDDUYG (ORCPT ); Thu, 4 Apr 2019 16:24:06 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:54963 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729433AbfDDUYF (ORCPT ); Thu, 4 Apr 2019 16:24:05 -0400 Received: by mail-qk1-f201.google.com with SMTP id v2so3148231qkf.21 for ; Thu, 04 Apr 2019 13:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=bQ0sQyIId1gc5GI/6sG0i+XMj4HgpGtF7leH+EhLTRc=; b=ijTFYlRoW4d47hWxBRHQLu/ateNtiTcTZ+8xQ0HbOLuEwCH9dLLlDdCkYuyztCMp2o mXNiyTtABt6twjeB+s9nV2Kdw8ly+2WDriO4gnJLLcnKCqFMxb5ga5GT1835KhFx8SnY 7qa/VMYbhRGXltNIg9YdtfqW4UaIs2gyv2C3qVSjTb0YTPr3kFtkrLulCjYuPj8L9Lfx Lht/51UA74SPfHmlvFZmQwVHKnwA7GBODxFpS4EfsmMiyDj7+oajwvNvXRGvJaMq+oSA tmn6M7u/c3vwhUIHuMggwT1WToIBTF4OXiUJ1xYG+jbhchiANICU0GXr5ku6Fyt+6048 cXUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=bQ0sQyIId1gc5GI/6sG0i+XMj4HgpGtF7leH+EhLTRc=; b=qiUdjLGWJcpg1NdTFl2GgQU3nkK0vibTz72/9cUQTDz35LVWA0Hgw7Xq1aerp1vgXJ +5Ii1OKPfK9ddapctro1pYJC9E6+DWAdSwHSBQZhflr7SIQBq2DV5wqXVZ94ySKUUX9t xOgrptnwHBdOEVVQpUpxS2h3M+X6g58R3LOcn3/V2IA66wh0ZZDVZYtsGwZcHOBqbKmK 27QUi+2JxAU637s8Y8wyK3WeD18rM9U2mGQwpG8Mpu9aakP7RDXjmVOuukxmaSYWg4hK sf5u1jYlsXDGT4hdrK45LcDwua5ZVXLcQg07QI3DaQYOLI+9G6+EmL37mG7UHuhT+MQU +TLQ== X-Gm-Message-State: APjAAAVAokYpLCkd7Ofet7ZFRWEyGgWaC12a/zmacid3XC6U1YVPc5jB +9rlpLOv5FcUa/m+nWlCJTT6Y6yW X-Google-Smtp-Source: APXvYqweExkGubWO86xzjg+OVs3wkuGafcUO9nmeR10fv77Ltl1p85rnr+gCrj0y4oMZjzw64K7LVGog X-Received: by 2002:ac8:2e7a:: with SMTP id s55mr1261618qta.34.1554409444323; Thu, 04 Apr 2019 13:24:04 -0700 (PDT) Date: Thu, 4 Apr 2019 16:23:43 -0400 In-Reply-To: <20190404202345.133553-1-brho@google.com> Message-Id: <20190404202345.133553-2-brho@google.com> Mime-Version: 1.0 References: <20190404202345.133553-1-brho@google.com> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog Subject: [PATCH v3 1/3] mm: make dev_pagemap_mapping_shift() externally visible From: Barret Rhoden To: Paolo Bonzini , Dan Williams , David Hildenbrand , Dave Jiang , Alexander Duyck Cc: linux-nvdimm@lists.01.org, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, yu.c.zhang@intel.com, yi.z.zhang@intel.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP KVM has a use case for determining the size of a dax mapping. The KVM code has easy access to the address and the mm; hence the change in parameters. Signed-off-by: Barret Rhoden Reviewed-by: David Hildenbrand Acked-by: Dan Williams --- include/linux/mm.h | 3 +++ mm/memory-failure.c | 38 +++----------------------------------- mm/util.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index fe52e266016e..c09e2f4c9bac 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -963,6 +963,9 @@ static inline bool is_pci_p2pdma_page(const struct page *page) } #endif /* CONFIG_DEV_PAGEMAP_OPS */ +unsigned long dev_pagemap_mapping_shift(unsigned long address, + struct mm_struct *mm); + static inline void get_page(struct page *page) { page = compound_head(page); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index fc8b51744579..6779c163c4f4 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -265,40 +265,6 @@ void shake_page(struct page *p, int access) } EXPORT_SYMBOL_GPL(shake_page); -static unsigned long dev_pagemap_mapping_shift(struct page *page, - struct vm_area_struct *vma) -{ - unsigned long address = vma_address(page, vma); - pgd_t *pgd; - p4d_t *p4d; - pud_t *pud; - pmd_t *pmd; - pte_t *pte; - - pgd = pgd_offset(vma->vm_mm, address); - if (!pgd_present(*pgd)) - return 0; - p4d = p4d_offset(pgd, address); - if (!p4d_present(*p4d)) - return 0; - pud = pud_offset(p4d, address); - if (!pud_present(*pud)) - return 0; - if (pud_devmap(*pud)) - return PUD_SHIFT; - pmd = pmd_offset(pud, address); - if (!pmd_present(*pmd)) - return 0; - if (pmd_devmap(*pmd)) - return PMD_SHIFT; - pte = pte_offset_map(pmd, address); - if (!pte_present(*pte)) - return 0; - if (pte_devmap(*pte)) - return PAGE_SHIFT; - return 0; -} - /* * Failure handling: if we can't find or can't kill a process there's * not much we can do. We just print a message and ignore otherwise. @@ -329,7 +295,9 @@ static void add_to_kill(struct task_struct *tsk, struct page *p, tk->addr = page_address_in_vma(p, vma); tk->addr_valid = 1; if (is_zone_device_page(p)) - tk->size_shift = dev_pagemap_mapping_shift(p, vma); + tk->size_shift = + dev_pagemap_mapping_shift(vma_address(page, vma), + vma->vm_mm); else tk->size_shift = compound_order(compound_head(p)) + PAGE_SHIFT; diff --git a/mm/util.c b/mm/util.c index f94a1ac09cd8..24444e35a7ed 100644 --- a/mm/util.c +++ b/mm/util.c @@ -795,3 +795,37 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen) out: return res; } + +unsigned long dev_pagemap_mapping_shift(unsigned long address, + struct mm_struct *mm) +{ + pgd_t *pgd; + p4d_t *p4d; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + + pgd = pgd_offset(mm, address); + if (!pgd_present(*pgd)) + return 0; + p4d = p4d_offset(pgd, address); + if (!p4d_present(*p4d)) + return 0; + pud = pud_offset(p4d, address); + if (!pud_present(*pud)) + return 0; + if (pud_devmap(*pud)) + return PUD_SHIFT; + pmd = pmd_offset(pud, address); + if (!pmd_present(*pmd)) + return 0; + if (pmd_devmap(*pmd)) + return PMD_SHIFT; + pte = pte_offset_map(pmd, address); + if (!pte_present(*pte)) + return 0; + if (pte_devmap(*pte)) + return PAGE_SHIFT; + return 0; +} +EXPORT_SYMBOL_GPL(dev_pagemap_mapping_shift);