From patchwork Wed Nov 14 21:51:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barret Rhoden X-Patchwork-Id: 10683235 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 BB317109C for ; Wed, 14 Nov 2018 22:34:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD2FE2B9F9 for ; Wed, 14 Nov 2018 22:34:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DCF32BE96; Wed, 14 Nov 2018 22:34:57 +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 7D9D42B9F9 for ; Wed, 14 Nov 2018 22:34:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388485AbeKOIkB (ORCPT ); Thu, 15 Nov 2018 03:40:01 -0500 Received: from mail-yb1-f201.google.com ([209.85.219.201]:33137 "EHLO mail-yb1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732896AbeKOI3z (ORCPT ); Thu, 15 Nov 2018 03:29:55 -0500 Received: by mail-yb1-f201.google.com with SMTP id r145-v6so13826798ybc.0 for ; Wed, 14 Nov 2018 14:24:51 -0800 (PST) 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=Swrg/Ql+aoXKDVqM4rUHKdjFWS7RdD4POWqk40vnoJ0=; b=jnaaG0KmPOtIngqfLHs7bFlfg63KFl/U07rJ2rlJdTOgtRPOkzSQrjiKwuWtic29wg Adla+90Mfzw6DYeictWdIx/CtriY3V2yAC3N/4sDyJ1z5kQaboGKHOlDEDJmvVI9usSq Wu90dimuVYQSWXVklUzKdX5gxRhFKmSGS646EGQMALfcaaJelGmUfaPGKjDC7Q4WTZur wqYCHPrF6S+DrYv9fpg7DBSrDW6zW7/kYR+0xTyiy2iD1Sh8eZO46z6E8JbR+NHD0iX4 AYw+y0vHCs4rGmJNpZhwOyqKF0OHSJbMsEZrAQslEd7SEvArL27n2/+OkcRxQuHZjtVn grfQ== 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=Swrg/Ql+aoXKDVqM4rUHKdjFWS7RdD4POWqk40vnoJ0=; b=AgaMJvY0s6g+7aJ8U1gmX7pCv0XYyyZZyyVXO1Ot/80NH7ZlW1RC9Ssbse2fQbJ74u Xjbnbb//bgMptRDap/jkUtiHtt46gmIuOxYxe6/uosYX0LfjA1agod5Ub04McYnPz262 OZIlahmHD8RGJlB8RBzIKWtqrdOFWbgfpUND7yTMSxTlnZQcnZQqaluSg1xhOd7/nmd7 bx5YyC/pJROQTsqxHL5ZXXi5MH3RUlUB6PVMtISLJTTtK9UOejEjDxkkvi+ogFoNtNJi i4HaHQJ0ToDyW+ES8x5iHjJDI5ola29cn7ksVFroM7rIOQt3YStG9kfHr7Ixctj7ssbH rxZA== X-Gm-Message-State: AGRZ1gLcmTIDvrJzKe1bwjhPoib9AzJ91Xi+8r68sdeu+y6h6eOf4dby NXnI9VSrkCk3fEvEo4WVSxboFojA X-Google-Smtp-Source: AJdET5cydhrPOQA/wDgBNBMiRvM6xC5Bw1OO7w1/3WOMNTH68+Tk7ymaB2i9Hz2qGH2RLHvnvDmsz8w5 X-Received: by 2002:a25:3a03:: with SMTP id h3-v6mr1580605yba.77.1542232383861; Wed, 14 Nov 2018 13:53:03 -0800 (PST) Date: Wed, 14 Nov 2018 16:51:53 -0500 In-Reply-To: <20181114215155.259978-1-brho@google.com> Message-Id: <20181114215155.259978-2-brho@google.com> Mime-Version: 1.0 References: <20181109203921.178363-1-brho@google.com> <20181114215155.259978-1-brho@google.com> X-Mailer: git-send-email 2.19.1.1215.g8438c0b245-goog Subject: [PATCH v2 1/3] mm: make dev_pagemap_mapping_shift() externally visible From: Barret Rhoden To: Dan Williams , Dave Jiang , Ross Zwisler , Vishal Verma , Paolo Bonzini , " =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= " , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Naoya Horiguchi Cc: linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, yu.c.zhang@intel.com, yi.z.zhang@intel.com, linux-mm@kvack.org, David Hildenbrand 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 5411de93a363..51215d695753 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -935,6 +935,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 0cd3de3550f0..c3f2c6a8607e 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 8bf08b5b5760..61bc9bab931d 100644 --- a/mm/util.c +++ b/mm/util.c @@ -780,3 +780,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);