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); }