Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp762032ybl; Fri, 6 Dec 2019 05:55:45 -0800 (PST) X-Google-Smtp-Source: APXvYqx4ccCk5lGzYJ9Fp7jV3MIvOsVHw7ulT/ZAdjODTamsxhRlN2LJqDq8fWAVy9LridF+3hI/ X-Received: by 2002:aca:503:: with SMTP id 3mr6384728oif.24.1575640545616; Fri, 06 Dec 2019 05:55:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575640545; cv=none; d=google.com; s=arc-20160816; b=0eCiPjdK6h6r2DgG7T8c18K7lVkZG+AB3U4GUQBmYQvnf9f047J/3LBlsjbg/w73cv D68W9Xemii3bydnISzTGddKCXwQ5ENXIegxPsvvA0We+RTKVxLpBkzp5ME77ytyb0naV UaKUUh+kYjo3iHpuCds4e/ndwyr3uEO60DHO489tI0gSH9ci2AJXxYTsuanc6HNtt4Ja wTSoWErdfctJOu9kmt2aAe+z5tsHxDuBH+7bSORNJcgSrbAF+oPk75sNl5kf5+iHh7c7 06bwoFMtcQJNP2YDBDolc2e39eKm/rkd+3pRBxx5thNEXevZFwgfSY3A7KHy+sv78C89 6IeA== 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; bh=m2llfM0CVNdiCeyYYJ4lD0ypz6mQ1xzAhiw9z+tMcRI=; b=tkFW41hWfTShgMSTQpY0iP8whcZQiTk3WoIFyWhsUWG5mJaBnCTwleQ+kY2IH3Qn1Y EyWjYUXIZDB2zIvb7C60p4IgFx/UYHZ3EXt3pXCHzBeFu70Iy1kRlnWHAHspNtkBy24r wLDa2ncjPqxKWkaOf4Zh227wkvANYMWoAOExnNYxPIiFWaT6lyh8aLwlgpr+DLvGC35G rJrdkc6E0FlYUnDHRfxiwsSGe+zC2bK49IQXYRB+GFPfQg5+dRKAd7TedML1WxDdeJRu dbvPNj4Ydk4PPFDojdRJrNJFp5i2n3HqNYtYWJRXS9kAhAbPRJfuhYiIlojTCEu96dA8 JpkA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y198si7136238oia.163.2019.12.06.05.55.33; Fri, 06 Dec 2019 05:55:45 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726795AbfLFNyY (ORCPT + 99 others); Fri, 6 Dec 2019 08:54:24 -0500 Received: from foss.arm.com ([217.140.110.172]:44752 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726720AbfLFNyT (ORCPT ); Fri, 6 Dec 2019 08:54:19 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1EC3D11D4; Fri, 6 Dec 2019 05:54:19 -0800 (PST) Received: from e112269-lin.cambridge.arm.com (e112269-lin.cambridge.arm.com [10.1.194.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 928503F718; Fri, 6 Dec 2019 05:54:16 -0800 (PST) From: Steven Price To: Andrew Morton , linux-mm@kvack.org Cc: Steven Price , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Dave Hansen , Ingo Molnar , James Morse , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Peter Zijlstra , Thomas Gleixner , Will Deacon , x86@kernel.org, "H. Peter Anvin" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Rutland , "Liang, Kan" Subject: [PATCH v16 12/25] mm: pagewalk: Allow walking without vma Date: Fri, 6 Dec 2019 13:53:03 +0000 Message-Id: <20191206135316.47703-13-steven.price@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191206135316.47703-1-steven.price@arm.com> References: <20191206135316.47703-1-steven.price@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since 48684a65b4e3: "mm: pagewalk: fix misbehavior of walk_page_range for vma(VM_PFNMAP)", page_table_walk() will report any kernel area as a hole, because it lacks a vma. This means each arch has re-implemented page table walking when needed, for example in the per-arch ptdump walker. Remove the requirement to have a vma in the generic code and add a new function walk_page_range_novma() which ignores the VMAs and simply walks the page tables. Signed-off-by: Steven Price --- include/linux/pagewalk.h | 5 +++++ mm/pagewalk.c | 44 ++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/include/linux/pagewalk.h b/include/linux/pagewalk.h index 06790f23957f..2c9725bdcf1f 100644 --- a/include/linux/pagewalk.h +++ b/include/linux/pagewalk.h @@ -59,6 +59,7 @@ struct mm_walk_ops { * @ops: operation to call during the walk * @mm: mm_struct representing the target process of page table walk * @vma: vma currently walked (NULL if walking outside vmas) + * @no_vma: walk ignoring vmas (vma will always be NULL) * @private: private data for callbacks' usage * * (see the comment on walk_page_range() for more details) @@ -67,12 +68,16 @@ struct mm_walk { const struct mm_walk_ops *ops; struct mm_struct *mm; struct vm_area_struct *vma; + bool no_vma; void *private; }; int walk_page_range(struct mm_struct *mm, unsigned long start, unsigned long end, const struct mm_walk_ops *ops, void *private); +int walk_page_range_novma(struct mm_struct *mm, unsigned long start, + unsigned long end, const struct mm_walk_ops *ops, + void *private); int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops, void *private); int walk_page_mapping(struct address_space *mapping, pgoff_t first_index, diff --git a/mm/pagewalk.c b/mm/pagewalk.c index c089786e7a7f..efa464cf079b 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -39,7 +39,7 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, do { again: next = pmd_addr_end(addr, end); - if (pmd_none(*pmd) || !walk->vma) { + if (pmd_none(*pmd) || (!walk->vma && !walk->no_vma)) { if (ops->pte_hole) err = ops->pte_hole(addr, next, walk); if (err) @@ -62,9 +62,14 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, if (!ops->pte_entry) continue; - split_huge_pmd(walk->vma, pmd, addr); - if (pmd_trans_unstable(pmd)) - goto again; + if (walk->vma) { + split_huge_pmd(walk->vma, pmd, addr); + if (pmd_trans_unstable(pmd)) + goto again; + } else if (pmd_leaf(*pmd) || !pmd_present(*pmd)) { + continue; + } + err = walk_pte_range(pmd, addr, next, walk); if (err) break; @@ -85,7 +90,7 @@ static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end, do { again: next = pud_addr_end(addr, end); - if (pud_none(*pud) || !walk->vma) { + if (pud_none(*pud) || (!walk->vma && !walk->no_vma)) { if (ops->pte_hole) err = ops->pte_hole(addr, next, walk); if (err) @@ -99,9 +104,13 @@ static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end, break; } - split_huge_pud(walk->vma, pud, addr); - if (pud_none(*pud)) - goto again; + if (walk->vma) { + split_huge_pud(walk->vma, pud, addr); + if (pud_none(*pud)) + goto again; + } else if (pud_leaf(*pud) || !pud_present(*pud)) { + continue; + } if (ops->pmd_entry || ops->pte_entry) err = walk_pmd_range(pud, addr, next, walk); @@ -374,6 +383,25 @@ int walk_page_range(struct mm_struct *mm, unsigned long start, return err; } +int walk_page_range_novma(struct mm_struct *mm, unsigned long start, + unsigned long end, const struct mm_walk_ops *ops, + void *private) +{ + struct mm_walk walk = { + .ops = ops, + .mm = mm, + .private = private, + .no_vma = true + }; + + if (start >= end || !walk.mm) + return -EINVAL; + + lockdep_assert_held(&walk.mm->mmap_sem); + + return __walk_page_range(start, end, &walk); +} + int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops, void *private) { -- 2.20.1