Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1727488ybg; Sat, 19 Oct 2019 01:11:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7VfobER+dNeRuN/+75jCiAbgPa+HBi9XbWzOva5XoAuBNP6LvlJL8ZmpPwjLg1SfjasIP X-Received: by 2002:a50:a781:: with SMTP id i1mr13962107edc.17.1571472703806; Sat, 19 Oct 2019 01:11:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571472703; cv=none; d=google.com; s=arc-20160816; b=g1uJzDGqQDvAv7j1H3L1EB623A9YCdG840cwUBr0qgMPbZU9SW1ZycuzIKuEZY98+V W4ynh5FViOtNF8aSpBd3nArvg0vIDuLv8bC7jfmQiZkIvrNfFQUxo4doRPDRrzqCv/vq i1j2/wOiJAMt1BA7qafTSLSQkssl0b8ez2GxWh7dbdnSxu8Q4bzLAaccdb8ZFUKp9Ekj wxi4cVboIt/FH2yjKfln6Cv/6qZvmjyd5AI4JWgdXE3cEhAbMz+haaA0Xx0lghyB64BN HD+LmV0GO6sUudjshe5eopeQ7Ko1xXqgMtD0U6DoqGSeZBTx+yC9tZ9OlQ1xIZNZ52PM aYmA== 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=mHYc/ApG+aEhiOFHaQhYigTZUXl63yna6waEUt4df8M=; b=kcXrIaiRfff9LAcIBB+OkP4Ej8RiAJoaeeX65JNtMfl4U/74mHlyG81SLKbashHq9V gIVbis1sg9J3FiS/mSNANFxoRadfoOshFdEX5Ie2gZ7+Lw08ejPcmKHvjJmDyF8gY63h z9gFGQxhcmhaN+RlulKqJIhVU1G+JISRRu191u2KyUU+vEbY+6c8Oy/SPChooKZ7DFvh EAY8ebisui0hLWXJ1X7i/h3DgzQvcwzgxdmTNYZqfuYebad933PZizww8/yqeH9QS3Pu Xewg3P2BFJ2CX2y8VMk9hMkzbSo6A7D3yoA2G1u28dg+h00xkgveBz6+hV4moPgGm/Tg Lmuw== 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 n11si4872228ejb.240.2019.10.19.01.11.20; Sat, 19 Oct 2019 01:11:43 -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 S2633432AbfJRKN7 (ORCPT + 99 others); Fri, 18 Oct 2019 06:13:59 -0400 Received: from [217.140.110.172] ([217.140.110.172]:32928 "EHLO foss.arm.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S2633421AbfJRKN5 (ORCPT ); Fri, 18 Oct 2019 06:13:57 -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 B45967B9; Fri, 18 Oct 2019 03:13:39 -0700 (PDT) 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 2ADEE3F6C4; Fri, 18 Oct 2019 03:13:37 -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 v12 13/22] mm: pagewalk: Add test_p?d callbacks Date: Fri, 18 Oct 2019 11:12:39 +0100 Message-Id: <20191018101248.33727-14-steven.price@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191018101248.33727-1-steven.price@arm.com> References: <20191018101248.33727-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/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 12004b097eae..df424197a25a 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. * * p?d_entry callbacks are called even if those levels are folded on a * particular architecture/configuration. @@ -46,6 +51,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); }; /** diff --git a/mm/pagewalk.c b/mm/pagewalk.c index 4139e9163aee..43acffefd43f 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -34,6 +34,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: @@ -85,6 +93,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: @@ -128,6 +144,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