From patchwork Wed Apr 2 20:18:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 14036431 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 5108CC36018 for ; Wed, 2 Apr 2025 20:18:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39F1A280004; Wed, 2 Apr 2025 16:18:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 328DF280003; Wed, 2 Apr 2025 16:18:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A172280004; Wed, 2 Apr 2025 16:18:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E8A75280001 for ; Wed, 2 Apr 2025 16:18:56 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F3B2F1607EF for ; Wed, 2 Apr 2025 20:18:56 +0000 (UTC) X-FDA: 83290217472.25.5DC1214 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf27.hostedemail.com (Postfix) with ESMTP id 04EA840007 for ; Wed, 2 Apr 2025 20:18:54 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=Nfrz3ROG; spf=none (imf27.hostedemail.com: domain of BATV+e93bdb537aa03e43b1bc+7892+infradead.org+dwmw2@desiato.srs.infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=BATV+e93bdb537aa03e43b1bc+7892+infradead.org+dwmw2@desiato.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743625135; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QLbPJRlyqVSx0cIJ3mGyFLKANvzzRuV5I+YYDBn/Qb0=; b=oNCaM6SDnzwuHenzMuVtccRGVYE98nNfu9+5izKliSarXMaHEXQkduHDDCYdkQa7yVLUew s4N1a010g52nDPXqTevWumDLRq9qUyGkaukj4zFE2PlRUFih8mKZ9G+0rbDM8RnIYcjYPx JzVuMISdmM1LfPhRnCqZJl0J2EWC3E0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=Nfrz3ROG; spf=none (imf27.hostedemail.com: domain of BATV+e93bdb537aa03e43b1bc+7892+infradead.org+dwmw2@desiato.srs.infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=BATV+e93bdb537aa03e43b1bc+7892+infradead.org+dwmw2@desiato.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743625135; a=rsa-sha256; cv=none; b=lyQkI9mbT83mqqB1rLNUA96bxD37Y7c4FEAylr1gVjkyDdOLZvLAf5Zot2h3DvKhBTogsT FaGUqFl/yJ9YedQufDB0Ll04/Et6cJoMZVAraw5Zv2li3yqCrO68N/0Vxwf6BpwGQSMIje x5TN38xnItlBYVIAePwA/PlOoqfXxh4= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=QLbPJRlyqVSx0cIJ3mGyFLKANvzzRuV5I+YYDBn/Qb0=; b=Nfrz3ROGXN0O80DToFCDxfu6XG yoyUyBkZqiwBQIjSx0CUpkS7l7FsHD3njuvDumbfUaGa2zSt7S3oisW9uQx3hTFhvpXaN/ObTk1Ow gQYkewg0TLVGgufwQ78yCM45XNjHzaEJAtcCOXjNSF0I0vubrHOQdr9/G43iAC1nHsMByQhY9dP3w XKK0ICk6AId5UHnCNKEAMKtzPshdkmLVAE4G9El40B82ioTzorcncoc3p8Uq/idZY3MdIIQxeeCtd HbfA5xi6ZzxM42IQRE/iQIBKVE7I+/KmNBg30BWFZRouqfIlIM7+NAQU01c3e+5geZbpIasnFrSaN nfD3oIvw==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.98.1 #2 (Red Hat Linux)) id 1u04Xr-0000000759n-0W23; Wed, 02 Apr 2025 20:18:43 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1u04Xp-0000000DcH8-2kho; Wed, 02 Apr 2025 21:18:41 +0100 From: David Woodhouse To: Mike Rapoport Cc: Andrew Morton , "Sauerwein, David" , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , David Hildenbrand , Marc Zyngier , Mark Rutland , Mike Rapoport , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 2/3] mm: Implement for_each_valid_pfn() for CONFIG_FLATMEM Date: Wed, 2 Apr 2025 21:18:40 +0100 Message-ID: <20250402201841.3245371-2-dwmw2@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402201841.3245371-1-dwmw2@infradead.org> References: <20250402201841.3245371-1-dwmw2@infradead.org> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 04EA840007 X-Stat-Signature: 1n7695z99wbb1ioqzdk68qmxz86y7zqy X-Rspam-User: X-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9at5OQQHM4IaM/ramJg+laZ9rEB1vkvWZN75F3fJOdS1nIKACohxQ4iCezLsb+dixsd0k3sd7Cwc9tl4I2xRoz2rF0QupfD3/bDxbWkOJBXnMdWeu35hmkjI5FtGOCBcU4+ey2/PaNwN8aME9qd4DF8D7MbcWrJ9ywNHqIB4ts4w/1KxdExIl2vNBiC9i4lVm2MDn8YpEQ4an2rvYKGibXA3GlX+Ps1Y9D1hvuPIq1jph2RaexD5PT0FvfqILlGjBaLqSFsiHSmvwueB0lrTqh1NCv5h/ACyp/AtI49WhgWOwNXLMknBRjr9/LZysdJJdYNWotoK4AtnbJv26JZ5m2muDRVkj4yzv8SW9io3L1kdjnGDebSdL7cEPifoY4YHiRl/pcpmG6xcwMN8SLGppjPnNg6/YWbzH8AhOWGJ63uDmEZVOLk1hrDf6ZNrXd6UKiLa+mhInHLyw57gcKK5PpgIWEZ9jM8NvFS26IhcF1EiQr9JBiWP+06zcjwTejCkL1ppUa 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: List-Subscribe: List-Unsubscribe: From: David Woodhouse In the FLATMEM case, the default pfn_valid() just checks that the PFN is within the range [ ARCH_PFN_OFFSET .. ARCH_PFN_OFFSET + max_mapnr ). The for_each_valid_pfn() function can therefore be a simple for() loop using those as min/max respectively. Signed-off-by: David Woodhouse Reviewed-by: Mike Rapoport (Microsoft) --- include/asm-generic/memory_model.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/memory_model.h b/include/asm-generic/memory_model.h index a3b5029aebbd..4fe7dd3bc09c 100644 --- a/include/asm-generic/memory_model.h +++ b/include/asm-generic/memory_model.h @@ -30,7 +30,31 @@ static inline int pfn_valid(unsigned long pfn) return pfn >= pfn_offset && (pfn - pfn_offset) < max_mapnr; } #define pfn_valid pfn_valid -#endif + +static inline bool first_valid_pfn(unsigned long *pfn) +{ + /* avoid include hell */ + extern unsigned long max_mapnr; + unsigned long pfn_offset = ARCH_PFN_OFFSET; + + if (*pfn < pfn_offset) { + *pfn = pfn_offset; + return true; + } + + if ((*pfn - pfn_offset) < max_mapnr) + return true; + + return false; +} + +#ifndef for_each_valid_pfn +#define for_each_valid_pfn(pfn, start_pfn, end_pfn) \ + for (pfn = max_t(unsigned long start_pfn, ARCH_PFN_OFFSET); \ + pfn < min_t(unsigned long, end_pfn, ARCH_PFN_OFFSET + max_mapnr); \ + pfn++) +#endif /* for_each_valid_pfn */ +#endif /* valid_pfn */ #elif defined(CONFIG_SPARSEMEM_VMEMMAP)