Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1603761yba; Thu, 4 Apr 2019 14:15:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGlXIQsgo+bGTFCwuEVPE7COQNwRQVBbQzproLhL0iCpgahItBnQQLxFzE9OCnMwGfrRhM X-Received: by 2002:a17:902:6b8c:: with SMTP id p12mr8529344plk.282.1554412527212; Thu, 04 Apr 2019 14:15:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554412527; cv=none; d=google.com; s=arc-20160816; b=K9j/VqDjTu5lNqASzzlwF6+/a2lpuoz+ggw4NGs5EO1q9xaT10cANsWHsJp+FKUZSk vTs1nbGQMAFmXt3UzNiOk0HA+Qj6IOI91a+27U9+FdVeRdhLWqLvn0tdspm7MPOQ8uDU aqnRHS1GORrq+QHothLhyH3Vy7kUkU+WILZrilpm7fXRRpYACaMdNnkEgyTVO+w+EstL S2CX4zkGzqtuN3F3La3zTbeR/Ivgby5Rjx36YYNQ5CcR2l3WRpICM8CWSMGVLV3iTB30 m2m8en8RR/JY/8GKjzECK8+lpKSSxTA7NWUl370AuSHnnWhie5XMd3mx00zHmdksc+bl k9wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=bQ0sQyIId1gc5GI/6sG0i+XMj4HgpGtF7leH+EhLTRc=; b=DNw9Hx1AYJbH63HsVCK2njfi2vdOEn9vepk0wSPRYiGyeZl2cCah2YWqlyuq/vo7Xm JF69hwiW6RDKBnJlOgt3Cutl9VcmbQ4tdHGWw4rbaPqHEAIzyeayg4QezKIYTnWlWHyc gQocJOdzasHTyWThfwg2kYXYHQpkZNu5PR+0DHKo4Eokyt26BaFoHkWV7FtVriUF3jil I3mDuNAcNmnE+kTzTOGNow3AhXxH2P/yGKs6OLLQ2oWfW5votJNwMFyJImn0Op6P390y suPvx39ptXq1HcYk8O9zmULLlE5YSixy5WPQXbx7Dgx7jnlc4W70j5BIwYusuqNqe7xc tCeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ijTFYlRo; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si16336607pgp.161.2019.04.04.14.15.09; Thu, 04 Apr 2019 14:15:27 -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=@google.com header.s=20161025 header.b=ijTFYlRo; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730849AbfDDUYH (ORCPT + 99 others); Thu, 4 Apr 2019 16:24:07 -0400 Received: from mail-qk1-f202.google.com ([209.85.222.202]:51016 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730826AbfDDUYF (ORCPT ); Thu, 4 Apr 2019 16:24:05 -0400 Received: by mail-qk1-f202.google.com with SMTP id d8so3153604qkk.17 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=f8YtcppxVtr6YuRtNvupYbSSVQDjQ8kB3Hth80SGo4FLYwBFyBsTz5zpqDPKjdqKat qHNx5MISIPQgHK2k/uBOUHk663o6Bf1yD6zmJOI87JGiYYiNd3S0IW3DD2OwqgFkE0cM 9EZciTX5LBXv5WTHfbkWMO2qxHCSR9GufXJI+hax0r3Xd0tyzMldeRPJ8v+0PzPtAswk EhheQ4pXiJ7iVeiygdRfGiWVmfHv4Nh6Cu1YjWtFILv1vk/VCzclDajmeemGVk9JhFR5 tSx+5piQgdOEEuOE6+SFy2To3iEBy648bQ8LT24kwnAKg2lotrtA6BjRcwRchqMeDJkz il8g== X-Gm-Message-State: APjAAAXcXSeMI8O7ZydiNhNJaiEiYzpNaaHotFlb/jTyco8EIxFUY5c0 bGmYLiIKd71WsXfpZhS4eVva91+O 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.21.0.392.gf8f6787159e-goog