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: 10683145 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 886B31759 for ; Wed, 14 Nov 2018 21:53:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CCB72C0FD for ; Wed, 14 Nov 2018 21:53:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 711A82C105; Wed, 14 Nov 2018 21:53:07 +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=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B346D2C0FD for ; Wed, 14 Nov 2018 21:53:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACB596B0003; Wed, 14 Nov 2018 16:53:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AA2AD6B0005; Wed, 14 Nov 2018 16:53:05 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 993B36B0006; Wed, 14 Nov 2018 16:53:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by kanga.kvack.org (Postfix) with ESMTP id 6DDAD6B0003 for ; Wed, 14 Nov 2018 16:53:05 -0500 (EST) Received: by mail-yb1-f200.google.com with SMTP id w13-v6so13555652ybm.11 for ; Wed, 14 Nov 2018 13:53:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=Swrg/Ql+aoXKDVqM4rUHKdjFWS7RdD4POWqk40vnoJ0=; b=SMqYSaT7Y0fnxDTm/lHsvZObk/w+XBVJdC1BgsxdzPMwVbo6azbI6m/AEYcqJWtGlw 7uzbd4Sa0c+v67zgBOqWwXUG9t6AV7xIMYhxEQheZG0D5o9M+NQCIQJgx0KtMJqrVa9n a38RNJLkQwALIVEPWVx4JUox4AqJRWwbHbv48q4QZLRuOL/oHCFg00I+55/plDsAhFpQ pCl1Dex8Fuu1mk8KIfYblWV40bRLhOt/CZLLXvtjjKiMgyESwcvVVK1VpvLk8Zu9180T nban9pFv3T8n2gAYLg061UnAWDK3wO9eCnKcanuMrg7bksJ4FTiXd9kPYf+jsjRDAKSI 0MWg== X-Gm-Message-State: AGRZ1gIT2Pcf058IcV4fcgCGMG8jusiGF+ngk5bScKcMs7VtjK5smgag rwlWN3iS+y44PU91a5eewhP26ZLTtCEFdo2+GagvnDfSL+L4yVi6wG2wkTIEj4p+cDa9eq7pI+l pYTAe7xlfDeTxrMz/atB8c+ivOp1qEottEapDmeEZbbL4OGxs8tT+hD1RSJdx+ais13slunuShN 9nufWbrm6ahyDI/dqFarrwoOwYqeTSsmWgPoXPtuE7kOd8V/P+caN0f0TCNfoPt9xUDMVeCmzDB ulPGCei7Ppmq7UeeR5VEi/sqrcI3axkf1qNih7Wqj0Dnm7lgeEQYf0UCNOFJY4qIKfQLylkKE6K awB+L7H3ABaZ9hxDBiOoA1cwXnkFonSGU6GXqXLU0on73XObQ3YJozMyxZnYrnIqqFndLrzhjHB 0 X-Received: by 2002:a25:fc25:: with SMTP id v37-v6mr3379950ybd.190.1542232385058; Wed, 14 Nov 2018 13:53:05 -0800 (PST) X-Received: by 2002:a25:fc25:: with SMTP id v37-v6mr3379897ybd.190.1542232384116; Wed, 14 Nov 2018 13:53:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542232384; cv=none; d=google.com; s=arc-20160816; b=EQjeOFuNXW91uqxtZHQ7XfQ7GCuzmkxv3LnWf3eBcjERDmoGFyksFqYZPZIsZt8Rn/ 8WvzaqN9ENT97nR6lQaGmXc6klXZtiHkR/9RqhzMT6W2veHwaYbqwKZYZDLw9yyN00ie 3z+M8XfNwUcD6T2J180mqHL7bpnzHW//pAVjDxKoV+pUebd2dyuFwqt3461WHkPYuStt 9bHpoClk1zeCcV8b6SML3Xcx1VZgINY9GJiNApmuQNAAHxXsQnDyBbLbaKhrt07aGLQY xqouGhrT97mK/zG8PhTiVmqiyZvmXM6Wiz6lnRhwqHqNqJEXiNiiROwghmYz48OdviCn mzeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=Swrg/Ql+aoXKDVqM4rUHKdjFWS7RdD4POWqk40vnoJ0=; b=gpbJxjKB7atL74ZMsxDS82Vk4SxALcn358Zl6tHD5zWKy5MC/hdMD9eOBOrjyis0/q VhBktPVxyJoB8JRnxyr4SK9ePndxziVftntmAhraaC/y2x89dxehQjUsYvTiIy/IpbeH EnIBl84UHKphFfQrLYmIOToXQBanIbDuFPrS+ygz4OAI6XDmkjUW2a+TP71Fu8Ermruy ppjm3tvqjYv+X9Emt41i7aJ6Zmve0y6yNNTjX/KfgtUxNLPwD7phMbuaUK8h9nD82qIJ kAXtGcmw+ByjpKMApKsOdVEFUB5uYGiI/nBaB+08TY3oqkCUKHNuaILsOnoARrGqODYH tC9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jnaaG0Km; spf=pass (google.com: domain of 3p5nswwqkcaol1ryqyyqvo.mywvsx47-wwu5kmu.y1q@flex--brho.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3P5nsWwQKCAol1ryqyyqvo.mywvsx47-wwu5kmu.y1q@flex--brho.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id i4-v6sor12392135ybj.85.2018.11.14.13.53.04 for (Google Transport Security); Wed, 14 Nov 2018 13:53:04 -0800 (PST) Received-SPF: pass (google.com: domain of 3p5nswwqkcaol1ryqyyqvo.mywvsx47-wwu5kmu.y1q@flex--brho.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jnaaG0Km; spf=pass (google.com: domain of 3p5nswwqkcaol1ryqyyqvo.mywvsx47-wwu5kmu.y1q@flex--brho.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3P5nsWwQKCAol1ryqyyqvo.mywvsx47-wwu5kmu.y1q@flex--brho.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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-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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);