From patchwork Mon Aug 22 13:00:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 12950651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7873CC28D13 for ; Mon, 22 Aug 2022 13:55:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F11136B0074; Mon, 22 Aug 2022 09:55:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC0506B0075; Mon, 22 Aug 2022 09:55:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAFB48D0001; Mon, 22 Aug 2022 09:55:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CBEE76B0074 for ; Mon, 22 Aug 2022 09:55:03 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9212F12065F for ; Mon, 22 Aug 2022 13:55:03 +0000 (UTC) X-FDA: 79827374886.11.4CC7484 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by imf09.hostedemail.com (Postfix) with ESMTP id 4D80D142B36 for ; Mon, 22 Aug 2022 13:34:00 +0000 (UTC) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 575EF601A4; Mon, 22 Aug 2022 15:04:37 +0200 (CEST) From: Rolf Eike Beer To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] mm: pagewalk: don't check vma in walk_page_range_novma() Date: Mon, 22 Aug 2022 15:00:47 +0200 Message-ID: <21585888.EfDdHjke4D@devpool047> Organization: emlix GmbH In-Reply-To: <3200642.44csPzL39Z@devpool047> References: <3200642.44csPzL39Z@devpool047> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661175240; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n8m+V1Y6XrK9pILF4D7rSTVPemA+QVsVgB6jRS23avA=; b=nXE0MSYbJR9lNx29dEP6W4CbQZgC4R/TuE47vO6SrOVqWJlnz28sJXWoT5G8RFuhYUv9Ht yXzVcLMpxqecl756hajirS9RI9Teubtc2ZcUylu0eQ9a4HoLm6rDX6t3jv61QcJXKK40GD pKi37GIGeVZ6/WiAKuI7D2AvhM09T7s= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661175240; a=rsa-sha256; cv=none; b=3xRG3ttl4s6L4X+6ISz1Thf8FM2+PUZ2vCNHIl3vi5M2UYO+9E8NLzJ4itO7cngi2ViQvl 5t/8pfg6rjyAKWoke3YOm5DRYPz134EzBUVkyU0GAzLtzzTe2M0MifDsxI7B8sGvcrzJAv W1h5s4rWdpms4YCghqzrQf3baKviz7E= X-Stat-Signature: eaasbepp74ds4rzok4mt5quu914fdgn7 Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com; dmarc=none X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4D80D142B36 X-Rspam-User: X-HE-Tag: 1661175240-803969 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: Directly call walk_pgd_range() as that is everything that will actually happen in __walk_page_range() besides checking if the vma is set. Signed-off-by: Rolf Eike Beer --- mm/pagewalk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index c67b2532db8f..a06eb100fe4e 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -517,7 +517,7 @@ int walk_page_range_novma(struct mm_struct *mm, unsigned long start, mmap_assert_locked(walk.mm); - return __walk_page_range(start, end, &walk); + return walk_pgd_range(start, end, &walk); } int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops, From patchwork Mon Aug 22 13:01:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 12950639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D84CC28D13 for ; Mon, 22 Aug 2022 13:36:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9A0D8D0001; Mon, 22 Aug 2022 09:36:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C490E6B0075; Mon, 22 Aug 2022 09:36:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B38248D0001; Mon, 22 Aug 2022 09:36:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A57436B0074 for ; Mon, 22 Aug 2022 09:36:36 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 715C141275 for ; Mon, 22 Aug 2022 13:36:36 +0000 (UTC) X-FDA: 79827328392.18.F5D95D6 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by imf03.hostedemail.com (Postfix) with ESMTP id E860C20767 for ; Mon, 22 Aug 2022 13:19:45 +0000 (UTC) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 5DDBD601AF; Mon, 22 Aug 2022 15:04:37 +0200 (CEST) From: Rolf Eike Beer To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] mm: pagewalk: fix documentation of PTE hole handling Date: Mon, 22 Aug 2022 15:01:32 +0200 Message-ID: <3695521.kQq0lBPeGt@devpool047> Organization: emlix GmbH In-Reply-To: <3200642.44csPzL39Z@devpool047> References: <3200642.44csPzL39Z@devpool047> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661174388; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RYPzkUAHjPg3UFO8RCR1zQmCsaoRnDrTZFvsWwLi9HM=; b=n8/qTwU0ydEgm1UN23ndctuVfKBvj7qpqKGhjN5dhctdLfwQG0ROQcdSXwh/vk/DcE3Jbh 8rynPjf/6SQt74K5H5wcukjAmGz8z5CpYfEKxwpjJollM+x4BXXWJU3UzmFo1D8v8DSiQs Hk/NDPfcyaZkymHud7UCH9eSONSAWMI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661174388; a=rsa-sha256; cv=none; b=uSbfFG9bNgSuYJNMWsYZtCj/Yg5NJXV7BUT78TMnQgFQyh/ei0/trawne7UBsyXUPcAJ8q xZpxfKytbuLYGlB2JslJafk9HVGuUxneM7jEiWQz6fQa0k2riMqqqcIKqvISsQ6WGbrhNW A3CosO1E3fG5iRDvDrtan7g3Gd8eAcw= X-Rspamd-Queue-Id: E860C20767 X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com X-Rspamd-Server: rspam03 X-Stat-Signature: hhax7kstixxd9zh6dcbjscrk4w8j4ipo X-HE-Tag: 1661174385-288471 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: Empty PTEs are passed to the pte_entry callback, not to pte_hole. Signed-off-by: Rolf Eike Beer --- include/linux/pagewalk.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/pagewalk.h b/include/linux/pagewalk.h index ac7b38ad5903..f3fafb731ffd 100644 --- a/include/linux/pagewalk.h +++ b/include/linux/pagewalk.h @@ -15,12 +15,12 @@ struct mm_walk; * this handler is required to be able to handle * pmd_trans_huge() pmds. They may simply choose to * split_huge_page() instead of handling it explicitly. - * @pte_entry: if set, called for each non-empty PTE (lowest-level) - * entry + * @pte_entry: if set, called for each PTE (lowest-level) entry, + * including empty ones * @pte_hole: if set, called for each hole at all levels, - * depth is -1 if not known, 0:PGD, 1:P4D, 2:PUD, 3:PMD - * 4:PTE. Any folded depths (where PTRS_PER_P?D is equal - * to 1) are skipped. + * depth is -1 if not known, 0:PGD, 1:P4D, 2:PUD, 3:PMD. + * Any folded depths (where PTRS_PER_P?D is equal to 1) + * are skipped. * @hugetlb_entry: if set, called for each hugetlb entry * @test_walk: caller specific callback function to determine whether * we walk over the current vma or not. Returning 0 means From patchwork Mon Aug 22 13:02:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 12950637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 948E2C28D13 for ; Mon, 22 Aug 2022 13:33:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F7E26B0074; Mon, 22 Aug 2022 09:33:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A7B28D0001; Mon, 22 Aug 2022 09:33:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3708B6B0078; Mon, 22 Aug 2022 09:33:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 286A16B0074 for ; Mon, 22 Aug 2022 09:33:29 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E40B61412CD for ; Mon, 22 Aug 2022 13:33:28 +0000 (UTC) X-FDA: 79827320496.15.C7CB768 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by imf07.hostedemail.com (Postfix) with ESMTP id 0CB50417F5 for ; Mon, 22 Aug 2022 13:29:26 +0000 (UTC) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 47F045FD66; Mon, 22 Aug 2022 15:04:37 +0200 (CEST) From: Rolf Eike Beer To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/6] mm: pagewalk: add api documentation for walk_page_range_novma() Date: Mon, 22 Aug 2022 15:02:36 +0200 Message-ID: <8991525.CDJkKcVGEf@devpool047> Organization: emlix GmbH In-Reply-To: <3200642.44csPzL39Z@devpool047> References: <3200642.44csPzL39Z@devpool047> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661174969; a=rsa-sha256; cv=none; b=ChnGRvGR7xYjeWT1055X9WfrJJ6AuKFd8jnamyxtUoPr7SeFvNVSe+duJymYl9vmxGJgNz 8XazE23piY6wfLhIBmhevaxaayQKd/a7CRX1w0IuSLLCoeGiQfwMcVoXyznzKIKgXGZkSi ZaeDHEdLy2ABPn8MQ0oH1NdaLqJuSBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661174969; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e9mCPQzaBZvz/Jcy6Z8FadLXJubHrstfD9yd734LYp4=; b=bUKpjMmXu+Lmx4HvmE4f9kSTrrfrFgqZPXpuaQNvTP+SwdtP+hhTyIT8gFqJ+ZKG5So5k/ W0ZLlBxA3ydaQW8gCeAbdQP8laZ8roZIcyK67gPVFjtyLpqnD4YRPVwA3trRo1MGRaSZL6 xNG/qhpsZhObqnQikmQbdtl60sW3vPs= Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0CB50417F5 X-Stat-Signature: cgn58wmogw3k68c58jw93uwxzmde6fos X-HE-Tag: 1661174966-955245 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: Signed-off-by: Rolf Eike Beer --- mm/pagewalk.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index a06eb100fe4e..dc3c850cd148 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -493,7 +493,15 @@ int walk_page_range(struct mm_struct *mm, unsigned long start, return 0; } -/* +/** + * walk_page_range_novma - walk a range of pagetables not backed by a vma + * @mm: mm_struct representing the target process of page table walk + * @start: start address of the virtual address range + * @end: end address of the virtual address range + * @ops: operation to call during the walk + * @pgd: pgd to walk if different from mm->pgd + * @private: private data for callbacks' usage + * * Similar to walk_page_range() but can walk any page tables even if they are * not backed by VMAs. Because 'unusual' entries may be walked this function * will also not lock the PTEs for the pte_entry() callback. This is useful for From patchwork Mon Aug 22 13:03:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 12950645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 819AAC28D13 for ; Mon, 22 Aug 2022 13:37:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 102048D0002; Mon, 22 Aug 2022 09:37:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 063376B0075; Mon, 22 Aug 2022 09:37:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1F448D0002; Mon, 22 Aug 2022 09:37:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D0F486B0074 for ; Mon, 22 Aug 2022 09:37:02 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AD83C141215 for ; Mon, 22 Aug 2022 13:37:02 +0000 (UTC) X-FDA: 79827329484.26.C824905 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by imf31.hostedemail.com (Postfix) with ESMTP id CBEF9205CC for ; Mon, 22 Aug 2022 13:13:16 +0000 (UTC) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 413A15FCA6; Mon, 22 Aug 2022 15:04:37 +0200 (CEST) From: Rolf Eike Beer To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] mm: pagewalk: allow walk_page_range_novma() without mm Date: Mon, 22 Aug 2022 15:03:29 +0200 Message-ID: <5760214.MhkbZ0Pkbq@devpool047> Organization: emlix GmbH In-Reply-To: <3200642.44csPzL39Z@devpool047> References: <3200642.44csPzL39Z@devpool047> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=none; spf=pass (imf31.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661174003; a=rsa-sha256; cv=none; b=eGy4FVsXATwYLBMGU9am20Au4kokNRAsPSF/DVXGXwl6CxZnbF4ptURY2MBxAZCovRnDLA x8dpWshAmy4aoCSm8ceZ4VCQCJlluLfw9losHZ83vRV7QROQVdJRyGVZpMqjlO6clDVPI/ YWD9/PB2anktv/ctoR12L8VlDDxiSWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661174003; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PAXCkJPKenih2vU+TRVjoSatHzMt2lPVXb8q62GmQrM=; b=cYics8YZwi65f+zqNzNMR66cuHvF1IRdQcYvKxcyyFszQR+PCYp9mf4hojQzul8U89ie8t ky9mpkDvwq+8T7oBWXYPXWHgM2z27ZkOUaxY3d1cHBRRg0KjC9/UC6S5Knam6ml6Rb7H2c OJ3s1B/uvV19rFnPkDXLYy4rh+xJp5Q= Authentication-Results: imf31.hostedemail.com; dkim=none; spf=pass (imf31.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com; dmarc=none X-Stat-Signature: u1a66odigpz9r8q5dsmwy4pckt4aphbc X-Rspamd-Queue-Id: CBEF9205CC X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1661173996-242421 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: Since e47690d756a7 ("x86: mm: avoid allocating struct mm_struct on the stack") a pgd can be passed to walk_page_range_novma(). In case it is set no place in the pagewalk code use the walk.mm anymore, so permit to pass a NULL mm instead. It is up to the caller to ensure proper locking on the pgd in this case. Signed-off-by: Rolf Eike Beer --- mm/pagewalk.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index dc3c850cd148..f816f86588be 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -506,6 +506,8 @@ int walk_page_range(struct mm_struct *mm, unsigned long start, * not backed by VMAs. Because 'unusual' entries may be walked this function * will also not lock the PTEs for the pte_entry() callback. This is useful for * walking the kernel pages tables or page tables for firmware. + * + * Either mm or pgd may be NULL, but not both. */ int walk_page_range_novma(struct mm_struct *mm, unsigned long start, unsigned long end, const struct mm_walk_ops *ops, @@ -520,10 +522,11 @@ int walk_page_range_novma(struct mm_struct *mm, unsigned long start, .no_vma = true }; - if (start >= end || !walk.mm) + if (start >= end || (!walk.mm && !walk.pgd)) return -EINVAL; - mmap_assert_locked(walk.mm); + if (walk.mm) + mmap_assert_locked(walk.mm); return walk_pgd_range(start, end, &walk); } From patchwork Mon Aug 22 13:04:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 12950638 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFB56C28D13 for ; Mon, 22 Aug 2022 13:33:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D8F46B0075; Mon, 22 Aug 2022 09:33:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 089146B0078; Mon, 22 Aug 2022 09:33:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E94438D0001; Mon, 22 Aug 2022 09:33:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D993C6B0075 for ; Mon, 22 Aug 2022 09:33:48 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B47821412C8 for ; Mon, 22 Aug 2022 13:33:48 +0000 (UTC) X-FDA: 79827321336.30.198D9D1 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by imf04.hostedemail.com (Postfix) with ESMTP id 840B041113 for ; Mon, 22 Aug 2022 13:24:04 +0000 (UTC) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 3BB495FB1D; Mon, 22 Aug 2022 15:04:37 +0200 (CEST) From: Rolf Eike Beer To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] mm: pagewalk: move variables to more local scope, tweak loops Date: Mon, 22 Aug 2022 15:04:12 +0200 Message-ID: <8155217.NyiUUSuA9g@devpool047> Organization: emlix GmbH In-Reply-To: <3200642.44csPzL39Z@devpool047> References: <3200642.44csPzL39Z@devpool047> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661174648; a=rsa-sha256; cv=none; b=Hb8CSWvNpKBfOfG1PvbIh9xlU1zVmgirRhDxe+yCWMcr0X7haag9sqgP/xWDeXOAMGGfMT 7cKwZusgQPTJBqHHE10VmrvOFfcITBNTd3BhR6ZCkpuoizI6yybsc50vYgleLyaOMwnMD7 I4ht3AHTaDC8UOCnAFdYtsIrYX9V0SA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661174648; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L1UehnZMiqaXktQM1WRXMn/xqd1kme/gnP9JtMR89OE=; b=1zOe2jik+5NN3SPo6X0hfvSAzJzLOEMAWS8J4T1r2MMZ/71m0RcyG0SZpziAlKWSOUrpJ8 yC8xaOwUtDHOuxOv/cgVtE54RcX+QNwkv+6Gozgsg56OBWjvLtOwmEeyFcZJNyaUngWkyM Up5S4klYw1V7vi02xL+WccRDOG3+pNg= Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com; dmarc=none X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 840B041113 X-Stat-Signature: b55ac88yzqnmqcgyxs97whugz5h7to4b X-Rspam-User: X-HE-Tag: 1661174644-921376 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: Move some variables to more local scopes to make it obvious that they don't carry state. Put the end additions into the for loop instructions to make them easier to read. Signed-off-by: Rolf Eike Beer --- mm/pagewalk.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index f816f86588be..d8be8a30b272 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -25,14 +25,12 @@ static int walk_pte_range_inner(pte_t *pte, unsigned long addr, { const struct mm_walk_ops *ops = walk->ops; - for (;;) { + for (;; addr += PAGE_SIZE, pte++) { int err = ops->pte_entry(pte, addr, addr + PAGE_SIZE, walk); if (err) return err; if (addr >= end - PAGE_SIZE) break; - addr += PAGE_SIZE; - pte++; } return 0; } @@ -42,13 +40,14 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, { pte_t *pte; int err; - spinlock_t *ptl; if (walk->no_vma) { pte = pte_offset_map(pmd, addr); err = walk_pte_range_inner(pte, addr, end, walk); pte_unmap(pte); } else { + spinlock_t *ptl; + pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); err = walk_pte_range_inner(pte, addr, end, walk); pte_unmap_unlock(pte, ptl); @@ -71,7 +70,7 @@ static int walk_hugepd_range(hugepd_t *phpd, unsigned long addr, if (addr & (page_size - 1)) return 0; - for (;;) { + for (;; addr += page_size) { pte_t *pte; int err; @@ -84,7 +83,6 @@ static int walk_hugepd_range(hugepd_t *phpd, unsigned long addr, return err; if (addr >= end - page_size) break; - addr += page_size; } return 0; } @@ -307,14 +305,13 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end, unsigned long next; unsigned long hmask = huge_page_mask(h); unsigned long sz = huge_page_size(h); - pte_t *pte; const struct mm_walk_ops *ops = walk->ops; - do { + for (; addr < end; addr = next) { int err; + pte_t *pte = huge_pte_offset(walk->mm, addr & hmask, sz); next = hugetlb_entry_end(h, addr, end); - pte = huge_pte_offset(walk->mm, addr & hmask, sz); if (pte) err = ops->hugetlb_entry(pte, hmask, addr, next, walk); @@ -323,7 +320,7 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end, if (err) return err; - } while (addr = next, addr != end); + } return 0; } @@ -461,14 +458,13 @@ int walk_page_range(struct mm_struct *mm, unsigned long start, do { int err; + walk.vma = vma; if (!vma) { /* after the last vma */ - walk.vma = NULL; next = end; } else if (start < vma->vm_start) { /* outside vma */ walk.vma = NULL; next = min(end, vma->vm_start); } else { /* inside vma */ - walk.vma = vma; next = min(end, vma->vm_end); vma = vma->vm_next; @@ -595,11 +591,11 @@ int walk_page_mapping(struct address_space *mapping, pgoff_t first_index, }; struct vm_area_struct *vma; pgoff_t vba, vea, cba, cea; - unsigned long start_addr, end_addr; lockdep_assert_held(&mapping->i_mmap_rwsem); vma_interval_tree_foreach(vma, &mapping->i_mmap, first_index, first_index + nr - 1) { + unsigned long start_addr, end_addr; int err; /* Clip to the vma */ From patchwork Wed Aug 24 11:00:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 12953277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0ED34C00140 for ; Wed, 24 Aug 2022 11:00:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C0DC6B0073; Wed, 24 Aug 2022 07:00:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76FE1940008; Wed, 24 Aug 2022 07:00:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65FD7940007; Wed, 24 Aug 2022 07:00:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 56FF26B0073 for ; Wed, 24 Aug 2022 07:00:15 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 31EAB40351 for ; Wed, 24 Aug 2022 11:00:15 +0000 (UTC) X-FDA: 79834191990.21.ECF4025 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by imf30.hostedemail.com (Postfix) with ESMTP id 7E46580035 for ; Wed, 24 Aug 2022 11:00:14 +0000 (UTC) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id E35F85FB51; Wed, 24 Aug 2022 13:00:12 +0200 (CEST) From: Rolf Eike Beer To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dan Carpenter , Nathan Chancellor Subject: [PATCH 7/6] mm: pagewalk: add back missing variable initializations Date: Wed, 24 Aug 2022 13:00:11 +0200 Message-ID: <2123960.ggj6I0NvhH@mobilepool36.emlix.com> In-Reply-To: <3200642.44csPzL39Z@devpool047> References: <3200642.44csPzL39Z@devpool047> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661338814; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bg7HFqGF/tbdAvHTlkJ1ZcBogoedl/BWhemBk/TCEHc=; b=LUDU1CHG/sN79pNsAEVfzS5ca7Owekun65gKW+yQXLe8wSsnLu1W1kmn8Ntnt6QrTbI5Cd Bx7EzTf4g0ZFYV3PrlMWF+eLuF1yeLupkfbGSb/UWyMvrBXmbLtedc7+DU/ApsQu9/nVBZ I275tnnaltvO8YefSyhwcgDc3WQpHAo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661338814; a=rsa-sha256; cv=none; b=r2+q/6ZSK/Y3QRA4qJWYzqXuubJrlVBJaBskQ458TAcEWORVLvWjoemt1GGbrlFgNWPLlR GciZaY+yqReT4BqQrrjY5+EeUOiKJl6F0S/S4WXmX8CZ+nMx6glp9tp6CSRBp+3aDqyEzv B/GNud/mjGBu36QRx/Ptp37YCHwDzIY= Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com X-Rspam-User: X-Stat-Signature: t837gofh3f3jk6f3jftiz5itx6bp7dgn X-Rspamd-Queue-Id: 7E46580035 X-Rspamd-Server: rspam10 X-HE-Tag: 1661338814-257144 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: These initializations accidentially got lost during refactoring. The first one can't actually be used without initialization, because walk_p4d_range() is only called when one of the 4 callbacks is set, but relying on this seems fragile. Reported-by: Linux Kernel Functional Testing Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Rolf Eike Beer Reviewed-by: Nathan Chancellor --- mm/pagewalk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) Looks like my testing had just the right callbacks set so I never hit this. In case you want to have this squashed into the original one just drop me a note and I'll redo the whole series. diff --git a/mm/pagewalk.c b/mm/pagewalk.c index d8be8a30b272..22e4bcca9bee 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -223,7 +223,7 @@ static int walk_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end, p4d = p4d_offset(pgd, addr); do { - int err; + int err = 0; next = p4d_addr_end(addr, end); if (p4d_none_or_clear_bad(p4d)) { @@ -262,7 +262,7 @@ static int walk_pgd_range(unsigned long addr, unsigned long end, else pgd = pgd_offset(walk->mm, addr); do { - int err; + int err = 0; next = pgd_addr_end(addr, end); if (pgd_none_or_clear_bad(pgd)) { @@ -308,7 +308,7 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end, const struct mm_walk_ops *ops = walk->ops; for (; addr < end; addr = next) { - int err; + int err = 0; pte_t *pte = huge_pte_offset(walk->mm, addr & hmask, sz); next = hugetlb_entry_end(h, addr, end);