From patchwork Mon Oct 14 10:58:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13834709 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 BD19BD1A45A for ; Mon, 14 Oct 2024 11:01:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B0846B00D1; Mon, 14 Oct 2024 07:01:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F12E6B00D2; Mon, 14 Oct 2024 07:01:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E33BD6B00D3; Mon, 14 Oct 2024 07:01:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BEC3D6B00D1 for ; Mon, 14 Oct 2024 07:01:36 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 02ED51C6168 for ; Mon, 14 Oct 2024 11:01:27 +0000 (UTC) X-FDA: 82671916740.07.4593A44 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 92DA94000C for ; Mon, 14 Oct 2024 11:01:29 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.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=1728903554; 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=q5VF7i0WQs1N+NdAn0MqfjtRBJLE8glwn7/XULIeBsQ=; b=5TiNgSMV+2qMq1j/92OYJYszZqRme8OV2omRluU7d0A1Cgb6oLhw7VdKVZM1qTrm61Rik2 JLUrS0EbP1pMdGQTWZvB8ZuUz/LSgcZT/R8//75tnx3aOmES562JjO0nZO5V5gSAaFSaYg 3UDtPM/xRkzJ03KI4NbUPBy0LlACVuk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728903554; a=rsa-sha256; cv=none; b=M196qU8NBMISWNNPeUrGWoi9nB0brw4ZhRikfK8RRCn0Idbd6TEolO2sdmbLOoY3t7sXKh 5osBegzbcFL9Qnhub//L6QDtDx1id1XCIhFS/EvknpDpIfs09nsis6pnMS3fR7cXYRVNH2 K0GLkQiTy5Vn5xfvUasFxNBj3Wyr5gs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com 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 C45931758; Mon, 14 Oct 2024 04:02:03 -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 C54893F51B; Mon, 14 Oct 2024 04:01:31 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , 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-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1 41/57] arm64: Pass desired page size on command line Date: Mon, 14 Oct 2024 11:58:48 +0100 Message-ID: <20241014105912.3207374-41-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-Rspamd-Queue-Id: 92DA94000C X-Stat-Signature: cbo3i4es3yx9eawsb5u7akqcuyuxds8b X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1728903689-450985 X-HE-Meta: U2FsdGVkX19hV+HzbV6qWVtBJY2QrMR/9T7sEH0yYOt8ewE7oLFJ+v4PBAW8UHeOmvn3kAaInmOBgSQ5vUcQMHgKzHPCigirju4xYnYTy0U3umFrKe59lnNBdmWsIoeZU0l3Rlg/eGvRVuh4yqP+fK4YTDYpmwbu5rNvzDN4eLDKEPsPTLr91aCwuKmkg4ue4SvMHe2QfeAbaWxAyokvIwsyV9ISxEUiFokm4UxenrpGF52851SsOoUHckhp1T2e74K+DE6m9AEbgoWalsdGQ+STQfZzvL0+Ye82AkN2i43A+EVXqnVdqaELzc/J5/TVzDLfRRk2G4tPqZaJewME8T1NLmAYY9+cxQYkL1s+vtFf5Qs11qEHFgC9whHxqO57oZqyRJX+x65ZBLN8fNvAJ9P/vcz/jKKXUAhz3iWtegJzofpbrD9FQVehWuSeVRrjaT87h1MyEOTgctDaTfPucNF85MdPzkU5+jvAkkvTK8e8VwJC0x5ZN2xQPfO44VzL5Iu/JT7NizUppMfMyPK7EBnfmuUo5bPbo82IsSMvvKhZ8zJvpJasvN4Poc6g7nPA5eO/TIm49sn96W8O4rBeeotPHIODd1d1CCt8dhJ+1Ygb8IkPWe8Knbxc1gCEDAvy7VrqlUV4g2iSMqtslFRsLn6GT1ese3I5TZGp3DJNw+nwOl3CTZkTBA/Dsayzl9vE1K4EcGBYlFRJdOoNDzk3cNo+ie5Joj/ubb7oBgipORzhKecKLFrlmfhcLkpJdi5o6VuFZ0SVSS8//Vuvxgz2ZXmPjripQUn2xliOTVQKKXTCS2PmeFVD8nmc/x6l5qlaHh3vCH8fq1rwfwfrC0HUVzS6QHNaBXeAJaz3WhUQBfWQTtiKzd2bshNpz0srs/VXehPz4rnciAAQ4EVf8pHXV97tahS60j9qG6qKVyutJD5SPjDWvjlbFFwUIN+DrTzYaOoGUmSfLKQ/JCHtJmV Gk6NO4XB qpLKr213niU6NUvasL40jl1ltSQeJs0UT4h+ZWHcvgMwTBGrfO1zsdRDS9TUjnRLxY+PlhNGIcBODgbPHlyST0fN1/ks7hxMmn/K+qDbqHxM6UGFwCbCgWlSt0IGM6zhNkR7gWwEQlxjCT5bLvYHt/zJiKf1BoXmxnIo0Wx4fbLUCOHhYYmr6J4TnlA== 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: Allow user to pass desired page size via command line as either "arm64.pagesize=4k", "arm64.pagesize=16k", or "arm64.pagesize=64k". The specified value is stored in the SW_FEATURE register as an encoded page shift in a 4 bit field. We only allow setting the page size override if the requested size is supported by the HW and is within the compile-time [PAGE_SIZE_MIN, PAGE_SIZE_MAX] range. This second condition means that overrides get ignored when we have a compile-time page size (because PAGE_SIZE_MIN == PAGE_SIZE_MAX). 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/ arch/arm64/include/asm/cpufeature.h | 11 ++++++++ arch/arm64/kernel/pi/idreg-override.c | 36 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 5584342672715..4edbb586810d7 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -18,6 +18,7 @@ #define ARM64_SW_FEATURE_OVERRIDE_NOKASLR 0 #define ARM64_SW_FEATURE_OVERRIDE_HVHE 4 #define ARM64_SW_FEATURE_OVERRIDE_RODATA_OFF 8 +#define ARM64_SW_FEATURE_OVERRIDE_PAGESHIFT 12 #ifndef __ASSEMBLY__ @@ -963,6 +964,16 @@ static inline bool arm64_test_sw_feature_override(int feat) &arm64_sw_feature_override); } +static inline int arm64_pageshift_cmdline(void) +{ + int val; + + val = arm64_apply_feature_override(0, + ARM64_SW_FEATURE_OVERRIDE_PAGESHIFT, + 4, &arm64_sw_feature_override); + return val ? val * 2 + 10 : 0; +} + static inline bool kaslr_disabled_cmdline(void) { return arm64_test_sw_feature_override(ARM64_SW_FEATURE_OVERRIDE_NOKASLR); diff --git a/arch/arm64/kernel/pi/idreg-override.c b/arch/arm64/kernel/pi/idreg-override.c index 29d4b6244a6f6..5a38bdb231bc8 100644 --- a/arch/arm64/kernel/pi/idreg-override.c +++ b/arch/arm64/kernel/pi/idreg-override.c @@ -183,6 +183,38 @@ static bool __init hvhe_filter(u64 val) ID_AA64MMFR1_EL1_VH_SHIFT)); } +static bool __init pageshift_filter(u64 val) +{ + u64 mmfr0 = read_sysreg_s(SYS_ID_AA64MMFR0_EL1); + u32 tgran64 = SYS_FIELD_GET(ID_AA64MMFR0_EL1, TGRAN64, mmfr0); + u32 tgran16 = SYS_FIELD_GET(ID_AA64MMFR0_EL1, TGRAN16, mmfr0); + u32 tgran4 = SYS_FIELD_GET(ID_AA64MMFR0_EL1, TGRAN4, mmfr0); + + /* pageshift is stored compressed in 4 bit field. */ + if (val) + val = val * 2 + 10; + + if (val < PAGE_SHIFT_MIN || val > PAGE_SHIFT_MAX) + return false; + + if (val == ARM64_PAGE_SHIFT_64K && + tgran64 >= ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED_MIN && + tgran64 <= ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED_MAX) + return true; + + if (val == ARM64_PAGE_SHIFT_16K && + tgran16 >= ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED_MIN && + tgran16 <= ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED_MAX) + return true; + + if (val == ARM64_PAGE_SHIFT_4K && + tgran4 >= ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MIN && + tgran4 <= ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MAX) + return true; + + return false; +} + static const struct ftr_set_desc sw_features __prel64_initconst = { .name = "arm64_sw", .override = &arm64_sw_feature_override, @@ -190,6 +222,7 @@ static const struct ftr_set_desc sw_features __prel64_initconst = { FIELD("nokaslr", ARM64_SW_FEATURE_OVERRIDE_NOKASLR, NULL), FIELD("hvhe", ARM64_SW_FEATURE_OVERRIDE_HVHE, hvhe_filter), FIELD("rodataoff", ARM64_SW_FEATURE_OVERRIDE_RODATA_OFF, NULL), + FIELD("pageshift", ARM64_SW_FEATURE_OVERRIDE_PAGESHIFT, pageshift_filter), {} }, }; @@ -225,6 +258,9 @@ static const struct { { "rodata=off", "arm64_sw.rodataoff=1" }, { "arm64.nolva", "id_aa64mmfr2.varange=0" }, { "arm64.no32bit_el0", "id_aa64pfr0.el0=1" }, + { "arm64.pagesize=4k", "arm64_sw.pageshift=1" }, + { "arm64.pagesize=16k", "arm64_sw.pageshift=2" }, + { "arm64.pagesize=64k", "arm64_sw.pageshift=3" }, }; static int __init parse_hexdigit(const char *p, u64 *v)