From patchwork Mon Oct 14 10:58:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13834676 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 0573CD1A43B for ; Mon, 14 Oct 2024 10:59:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FFDE6B0092; Mon, 14 Oct 2024 06:59:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B1D16B0093; Mon, 14 Oct 2024 06:59:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 778446B0095; Mon, 14 Oct 2024 06:59:55 -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 5CC306B0092 for ; Mon, 14 Oct 2024 06:59:55 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CCBE9C0D43 for ; Mon, 14 Oct 2024 10:59:46 +0000 (UTC) X-FDA: 82671912666.29.F0E4F18 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf28.hostedemail.com (Postfix) with ESMTP id 5B20EC0009 for ; Mon, 14 Oct 2024 10:59:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf28.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728903547; a=rsa-sha256; cv=none; b=E0MrBsrsB4ukwC0jdeDcwlVJ9isM1tGdrijQ5Dl+JJSeWJ6xygfr5GtFNa65tySiGXRIad W0sOYEJZYQgmViwiaQimqy1amoiiG6M6naq0QgtvCMTE6WqLmoTgWCbpNogW/26mfClk7W YJWq9k/mKa/MRB73vcXaWyMw6rNMD0o= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf28.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728903547; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dafiuhHFBOL0KU3UgDvSqFL+BWETMThHwzJyb2+CQGw=; b=TVaSU9Ozh3J2L+BA+pwDjSm0NTrS3Sy+RcUP88TcI/hD0wp9PM4s3F7MA31vLlPwcz8BJ1 88yyzj1/Ap5AQ43t7kVR7QEY78vgZpZeObXY3w5LwITiJSyZE5wbPCM7LWi5fEijj/8VSZ pMOKghNBRBCYAw+adr3guQPV/ciYmlw= 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 1FE2A1688; Mon, 14 Oct 2024 04:00:22 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B86113F51B; Mon, 14 Oct 2024 03:59:49 -0700 (PDT) From: Ryan Roberts To: Alexander Viro , Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , Christian Brauner , David Hildenbrand , Greg Marsden , Ivan Ivanov , Kalesh Singh , Marc Zyngier , Mark Rutland , Matthias Brugger , Miroslav Benes , Will Deacon Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1 08/57] fs: Remove PAGE_SIZE compile-time constant assumption Date: Mon, 14 Oct 2024 11:58:15 +0100 Message-ID: <20241014105912.3207374-8-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241014105912.3207374-1-ryan.roberts@arm.com> References: <20241014105514.3206191-1-ryan.roberts@arm.com> <20241014105912.3207374-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 5B20EC0009 X-Rspamd-Server: rspam01 X-Stat-Signature: n9ucenmxzf96i3csbyijn55acizczpa6 X-HE-Tag: 1728903587-520758 X-HE-Meta: U2FsdGVkX1/O4Fy1DQIQzz6ZwRqD48DzR77iUazOhkQCnQACJFFxb0VAU4hLMmMJ2o3iUPMCRSy7em0V+B+zkN4JTM9LVoG/FL02RcjSPtCqvREZHafL56R6CMPDTq76McPm25q937QcXSqfFGjdRo+jdy9coKB26aU/Ly13+gLI2e6DfAujrT7NBrdeeuD3dhb1wJa3d4n7U/pZs0NJZYd4OodS0T9GghhxJPbrIXJ8TRHYcGFe3YGHpjLfuDybNasZdjmdxZb+h7od3OFQ/DAfPefue424AhEIwQJOw1OOOcr1/9h/T6sruhrEoixVhX0aoYICPFKU5cl+BsxeeyOs1pee/yRwdR8ih26Kr9kbaE8d5KPgWuc0HQpyqmQaWvuHX74PmoHkxir147k9EP8ULn22ce2qyIKLcaT16qF4OVE/Y4EYeXzwrymRcNKtM1Fieq2apxSfgdRjurQegs5Oh9cfLE6Z4p8NBEa+6UdozXojb3UKltLtY2F5/LWP9HFArVj9g95Ss9VlS3YkRpJc42vFFVXeAu5JjvMSn9hsKHO8dsLuuJNSFJs28FYZSON6cWPJ/+wXthMQQoFFusVk2XnPhpIcWIUYTFOTvv9/4/+zcTp8oPDzGtZK3EDsrHAm5x4Fl9LklfAlvXDtuiV0RwviWT0qCGn7e0asgLAD86I68GrqyNSRZyJpYBcSFTkG5MHQnwA/c3KWccBc0peS0ipDiXtwgVEnSwAOafCJnfsLt7dNXggHpidX3ELwG4ezHWWSKqH2Od8IFMd1GeZu91TAa7jyiRmnB2md4+fhe4J7JJNhzbMDjSt6wt+X1BMEa8hxXnlBdBcLTyF5w3OeY5WAgoaP08BRTVQxHQmuVJwGXZ05TV+qTSeDTv3zAtqmku8ncx1NriVnM6rVO0H5VcYuSXlzfF596/CpHywkixfoLf/imNKufK3ydz+RqS+QRscEZJkef+72mHl C1PtIfZh OoKAwmywTyda/reD22oE4cn1L86boj537MUVjZFkrFsHf+8T57r9oY4ZpmEPe0YnrCTmGqPKG1IlDK1/IDpPCb5eu3KdSKkkVMRJbLULaoIdOat8lfOOrGmF+5s4ug9q93R6gj9AcwnS6euySQbUGX5iS1tQCbDQ0EoliELKqdXiW1HP3kE3RGc9oPAXr5E8IQeqoeMCbxUN0QfVwxzaTGFDriAGj6W9KIUlG 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: To prepare for supporting boot-time page size selection, refactor code to remove assumptions about PAGE_SIZE being compile-time constant. Code intended to be equivalent when compile-time page size is active. In binfmt_elf, convert CPP conditional to C ternary operator; this will be folded to the same code by the compiler when in compile-time page size mode, but will also work for runtime evaluation in boot-time page size mode. In coredump, modify __dump_skip() to emit zeros in blocks of PAGE_SIZE_MIN. This resolves to the previous PAGE_SIZE for compile-time page size, but that doesn't work for boot-time page size. PAGE_SIZE_MIN is preferred here over PAGE_SIZE_MAX to save memory. Wrap global variables that are initialized with PAGE_SIZE derived values using DEFINE_GLOBAL_PAGE_SIZE_VAR() so their initialization can be deferred for boot-time page size builds. Signed-off-by: Ryan Roberts --- ***NOTE*** Any confused maintainers may want to read the cover note here for context: https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/ fs/binfmt_elf.c | 11 ++++------- fs/coredump.c | 8 ++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 19fa49cd9907f..e439d36c43c7e 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -84,11 +84,8 @@ static int elf_core_dump(struct coredump_params *cprm); #define elf_core_dump NULL #endif -#if ELF_EXEC_PAGESIZE > PAGE_SIZE -#define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE -#else -#define ELF_MIN_ALIGN PAGE_SIZE -#endif +#define ELF_MIN_ALIGN \ + (ELF_EXEC_PAGESIZE > PAGE_SIZE ? ELF_EXEC_PAGESIZE : PAGE_SIZE) #ifndef ELF_CORE_EFLAGS #define ELF_CORE_EFLAGS 0 @@ -98,7 +95,7 @@ static int elf_core_dump(struct coredump_params *cprm); #define ELF_PAGEOFFSET(_v) ((_v) & (ELF_MIN_ALIGN-1)) #define ELF_PAGEALIGN(_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1)) -static struct linux_binfmt elf_format = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR(struct linux_binfmt, elf_format, { .module = THIS_MODULE, .load_binary = load_elf_binary, .load_shlib = load_elf_library, @@ -106,7 +103,7 @@ static struct linux_binfmt elf_format = { .core_dump = elf_core_dump, .min_coredump = ELF_EXEC_PAGESIZE, #endif -}; +}); #define BAD_ADDR(x) (unlikely((unsigned long)(x) >= TASK_SIZE)) diff --git a/fs/coredump.c b/fs/coredump.c index 7f12ff6ad1d3e..203f2a158246e 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -825,7 +825,7 @@ static int __dump_emit(struct coredump_params *cprm, const void *addr, int nr) static int __dump_skip(struct coredump_params *cprm, size_t nr) { - static char zeroes[PAGE_SIZE]; + static char zeroes[PAGE_SIZE_MIN]; struct file *file = cprm->file; if (file->f_mode & FMODE_LSEEK) { if (dump_interrupted() || @@ -834,10 +834,10 @@ static int __dump_skip(struct coredump_params *cprm, size_t nr) cprm->pos += nr; return 1; } else { - while (nr > PAGE_SIZE) { - if (!__dump_emit(cprm, zeroes, PAGE_SIZE)) + while (nr > PAGE_SIZE_MIN) { + if (!__dump_emit(cprm, zeroes, PAGE_SIZE_MIN)) return 0; - nr -= PAGE_SIZE; + nr -= PAGE_SIZE_MIN; } return __dump_emit(cprm, zeroes, nr); }