Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7414206ybi; Mon, 22 Jul 2019 12:45:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpMkQCxenWjvqlKUci7GD1oU5u/wse9YAs4n6TovzMEX4mY98KDVXejrpOnCZD3ix8zOEp X-Received: by 2002:a17:902:44f:: with SMTP id 73mr77696740ple.192.1563824707994; Mon, 22 Jul 2019 12:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563824707; cv=none; d=google.com; s=arc-20160816; b=LKJSEM8eY2RiqjQ9MfnR2kR9Navww212QcOk6GNCe3Njx4ZAjLz9GlZ4LYkftSEYTP RO79cGgrgY7B7Moxw2qLZWqyKoJV1VMnS7mWVBYWr8sz4pbP8PaMYY2Kjof1w0fGh2YN 36kl4uENI6IKxwo7N9ZxgM9164ci9Tq4i3cFgQD8t3tgwGj2qBI55RmhjCNekoMMik3Q BvhCzqyj2bjN8i5lwnfScuzOhT6dLcutuf9hlQB4N0jJa0BCHRJcRSUVXlokgAlbLKv8 KuG+2G3DdZkxiQPlLQPhxGIFtLyOaXbUQYtfTyrPTbBnElYeUftj0rBBroBxACathiN8 cymQ== 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=krhSst1Rr/sUlZpo7CKXyP+sWCPROlf89rJ0GXnJMfE=; b=ERRnkvfZny8QLMflwdkyxFHimw1gZkW+g97lhVpyiEiF4o6MDKvIfsjb49m45il1Nx M98BdYODpQbuhqDtR8iGLRTdZvsPhCj98bZZ7YV+6C26FeiscmXRz76OJ93zAt9Y3RjU 1UIzeut+ShVvHrjzRf9kff7glNLnANBSh9nVo7B1zFYLZxyMg5VtnYLldnzUJ0iiGaZ/ Xxi9X1tFeO/OLwJgSuCElsp1hVwfGASH8OdAgiRgLQjP4aFumbGyJoKGcxjtStkxXl7I afFARY21P81vHZ5eZeQmRoreMyLrvlx1owOjyLclvuWjRtlBDDN7INtZwPOFHrF1cd0R MIow== 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 s192si9976569pgc.68.2019.07.22.12.44.52; Mon, 22 Jul 2019 12:45:07 -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; 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 S1729959AbfGVPnE (ORCPT + 99 others); Mon, 22 Jul 2019 11:43:04 -0400 Received: from foss.arm.com ([217.140.110.172]:40384 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729886AbfGVPnC (ORCPT ); Mon, 22 Jul 2019 11:43:02 -0400 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 EFE9E1509; Mon, 22 Jul 2019 08:43:01 -0700 (PDT) Received: from e112269-lin.arm.com (e112269-lin.cambridge.arm.com [10.1.196.133]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 66A7A3F694; Mon, 22 Jul 2019 08:42:59 -0700 (PDT) From: Steven Price To: 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" , Andrew Morton Subject: [PATCH v9 13/21] mm: pagewalk: Add test_p?d callbacks Date: Mon, 22 Jul 2019 16:42:02 +0100 Message-Id: <20190722154210.42799-14-steven.price@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190722154210.42799-1-steven.price@arm.com> References: <20190722154210.42799-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. Signed-off-by: Steven Price --- include/linux/mm.h | 11 +++++++++++ mm/pagewalk.c | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index b22799129128..325a1ca6f820 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1447,6 +1447,11 @@ void unmap_vmas(struct mmu_gather *tlb, struct vm_area_struct *start_vma, * value means "do page table walk over the current vma," * and a negative one means "abort current page table walk * right now." 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. * @mm: mm_struct representing the target process of page table walk * @vma: vma currently walked (NULL if walking outside vmas) * @private: private data for callbacks' usage @@ -1471,6 +1476,12 @@ struct mm_walk { 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); struct mm_struct *mm; struct vm_area_struct *vma; void *private; diff --git a/mm/pagewalk.c b/mm/pagewalk.c index 1cbef99e9258..6bea79b95be3 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -32,6 +32,14 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, unsigned long next; int err = 0; + if (walk->test_pmd) { + err = walk->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: @@ -82,6 +90,14 @@ static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end, unsigned long next; int err = 0; + if (walk->test_pud) { + err = walk->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: @@ -124,6 +140,14 @@ static int walk_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end, unsigned long next; int err = 0; + if (walk->test_p4d) { + err = walk->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