Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp762882ybl; Fri, 6 Dec 2019 05:56:30 -0800 (PST) X-Google-Smtp-Source: APXvYqxgEga0R6YBKu3HgjM1/2sRwIb8coKEj7+l849L4p86jLnJNBB74a0fVIhQqXyl8qJ2Rgdj X-Received: by 2002:a05:6830:1f28:: with SMTP id e8mr10144891oth.173.1575640590823; Fri, 06 Dec 2019 05:56:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575640590; cv=none; d=google.com; s=arc-20160816; b=HLl8H1l8xxolVP/wox78zahOCHECOux3MAaLGbDfz9PIn2nMHx82aXa7qCj+Qv8Itg p4GIBEr4TBEz16bQmx7/IiTGMPfKovKgUN6I0YbOAhat3Eoxms7iw+d/9IdZjJPlNy0p ch4fjca5h9URl8OgizGGWNUHRFkMB3oKmnb1AF2E35KjW2vtlaL5lKP1N88voWOCS5yH z/u0TWvMPEK+N4AJZ4GpKV8Rw5yLZM5CZxFx6x7iOoD+3iWJcONHOmH9sHNU69JvDn6r 4T8atzXSkJYdBb0b7jeLzTnVCx800gMY9nv2jzJCP3jFbqvqv1QTHS0pQC6/zKEP4oa2 l80Q== 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=CMv+PiC/TGoaH7Pl9u7ART8JlqxkTtWc2Xh1lnhe6iY=; b=C9ZG0lgU7mVJd3G7TCz3tXLbjTDXXXRiGK4/NbuO5bCSSrGWtpDXZI1KBv4pVP6G5w zo09nsNiqVbljQrsdAZdQT9o5GtVQ67tRBGQ3YSWDhpSCRpd2sV0AcKdQFzp7OGls+hq yU3jRGWBYVWjVmxwnQcTTHJcsddQZU0qlxgXmgrTUIo8db1oYLXbXPHIArBvQptFZYfA fUjxc73tnDy2kVhJDPzSF/F4ipiStaF889ShecpBvCzTCLCXTwv3Lr2e2GiGdSZSGaTL lx1PZWAGCFHk6nCDWg48USGsvpZVsZ2sic8CuK4MznuBOKgD63/XwxFYq6Xq0W0NJ8C4 9efQ== 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 d23si5971854oti.158.2019.12.06.05.56.19; Fri, 06 Dec 2019 05:56:30 -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 S1726834AbfLFNyb (ORCPT + 99 others); Fri, 6 Dec 2019 08:54:31 -0500 Received: from foss.arm.com ([217.140.110.172]:44850 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726812AbfLFNy1 (ORCPT ); Fri, 6 Dec 2019 08:54:27 -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 7078411D4; Fri, 6 Dec 2019 05:54:27 -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 CA94D3F718; Fri, 6 Dec 2019 05:54:24 -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" , Zong Li Subject: [PATCH v16 15/25] mm: pagewalk: Add test_p?d callbacks Date: Fri, 6 Dec 2019 13:53:06 +0000 Message-Id: <20191206135316.47703-16-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 It is useful to be able to skip parts of the page table tree even when walking without VMAs. Add test_p?d callbacks similar to test_walk but which are called just before a table at that level is walked. If the callback returns non-zero then the entire table is skipped. Tested-by: Zong Li Signed-off-by: Steven Price --- include/linux/pagewalk.h | 11 +++++++++++ mm/pagewalk.c | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/pagewalk.h b/include/linux/pagewalk.h index 2c9725bdcf1f..84ac77620bfc 100644 --- a/include/linux/pagewalk.h +++ b/include/linux/pagewalk.h @@ -24,6 +24,11 @@ struct mm_walk; * "do page table walk over the current vma", returning * a negative value means "abort current page table walk * right now" and returning 1 means "skip the current vma" + * @test_pmd: similar to test_walk(), but called for every pmd. + * @test_pud: similar to test_walk(), but called for every pud. + * @test_p4d: similar to test_walk(), but called for every p4d. + * Returning 0 means walk this part of the page tables, + * returning 1 means to skip this range. * @pre_vma: if set, called before starting walk on a non-null vma. * @post_vma: if set, called after a walk on a non-null vma, provided * that @pre_vma and the vma walk succeeded. @@ -49,6 +54,12 @@ struct mm_walk_ops { struct mm_walk *walk); int (*test_walk)(unsigned long addr, unsigned long next, struct mm_walk *walk); + int (*test_pmd)(unsigned long addr, unsigned long next, + pmd_t *pmd_start, struct mm_walk *walk); + int (*test_pud)(unsigned long addr, unsigned long next, + pud_t *pud_start, struct mm_walk *walk); + int (*test_p4d)(unsigned long addr, unsigned long next, + p4d_t *p4d_start, struct mm_walk *walk); int (*pre_vma)(unsigned long start, unsigned long end, struct mm_walk *walk); void (*post_vma)(struct mm_walk *walk); diff --git a/mm/pagewalk.c b/mm/pagewalk.c index 88104ab00a97..83ab6c1ebf9b 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -38,6 +38,14 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, const struct mm_walk_ops *ops = walk->ops; int err = 0; + if (ops->test_pmd) { + err = ops->test_pmd(addr, end, pmd_offset(pud, 0UL), walk); + if (err < 0) + return err; + if (err > 0) + return 0; + } + pmd = pmd_offset(pud, addr); do { again: @@ -89,6 +97,14 @@ static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end, const struct mm_walk_ops *ops = walk->ops; int err = 0; + if (ops->test_pud) { + err = ops->test_pud(addr, end, pud_offset(p4d, 0UL), walk); + if (err < 0) + return err; + if (err > 0) + return 0; + } + pud = pud_offset(p4d, addr); do { again: @@ -132,6 +148,14 @@ static int walk_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end, const struct mm_walk_ops *ops = walk->ops; int err = 0; + if (ops->test_p4d) { + err = ops->test_p4d(addr, end, p4d_offset(pgd, 0UL), walk); + if (err < 0) + return err; + if (err > 0) + return 0; + } + p4d = p4d_offset(pgd, addr); do { next = p4d_addr_end(addr, end); -- 2.20.1