From patchwork Thu Jan 25 16:42:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 13531339 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 95B56C47422 for ; Thu, 25 Jan 2024 16:44:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28AA2280002; Thu, 25 Jan 2024 11:44:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 207568D0002; Thu, 25 Jan 2024 11:44:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 082CA6B00A6; Thu, 25 Jan 2024 11:44:57 -0500 (EST) 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 E65156B00A4 for ; Thu, 25 Jan 2024 11:44:56 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C392116082A for ; Thu, 25 Jan 2024 16:44:56 +0000 (UTC) X-FDA: 81718407792.02.5825671 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf11.hostedemail.com (Postfix) with ESMTP id 1854740023 for ; Thu, 25 Jan 2024 16:44:54 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706201095; 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=5zf4/QVJoGe+m11F6r0cQ8EbqmSgrLFc9Da1YM6fJtc=; b=ueJN1xPQMwX3jnrMH7fVt8CLP0lZbZymgmlYruQpOI2YY3F2mYnQKTkjuu4yUy5Mtgv+HR t66U7n5H9JegI1r3kmWPO7f5LHIWitTMaa9Lw3SzAJjCmW7fjGBKAQengkkRabzXzGIVTP lh9b36NTn452GVV8VpBwm0txkdZmheE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706201095; a=rsa-sha256; cv=none; b=ka08MmKMUzZ3bfaquSarlgeY/SOAkIRQBrfmIWyMmDCHo8iLRyKC+MYGYxtdjyfxr5DkhN TQ1vzimxxfcaAyUXYl3ixmWp/tZPvDhKQ1Z0GioNBEMt+Ni7ndcqoxO0nPxNHv+yqp2zic FYrqMJRgbCff0eipOuH9I4vvHMtAOKA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com; dmarc=pass (policy=none) header.from=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 B1083168F; Thu, 25 Jan 2024 08:45:38 -0800 (PST) Received: from e121798.cable.virginm.net (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C149A3F5A1; Thu, 25 Jan 2024 08:44:48 -0800 (PST) From: Alexandru Elisei To: catalin.marinas@arm.com, will@kernel.org, oliver.upton@linux.dev, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, arnd@arndb.de, akpm@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, mhiramat@kernel.org, rppt@kernel.org, hughd@google.com Cc: pcc@google.com, steven.price@arm.com, anshuman.khandual@arm.com, vincenzo.frascino@arm.com, david@redhat.com, eugenis@google.com, kcc@google.com, hyesoo.yu@samsung.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH RFC v3 22/35] arm64: mte: Enable tag storage if CMA areas have been activated Date: Thu, 25 Jan 2024 16:42:43 +0000 Message-Id: <20240125164256.4147-23-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240125164256.4147-1-alexandru.elisei@arm.com> References: <20240125164256.4147-1-alexandru.elisei@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1854740023 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: yebzf39fbwidtcj6t58dq4fis6ffhuix X-HE-Tag: 1706201094-251289 X-HE-Meta: U2FsdGVkX18x1QwMmHGW1K9RNcikB/DEOgEsyHQDDfddcOakggYQMFLm9DdU9X8WsRbUiIAVmaHCYPe/VAMm8K3rYmqnxSEAW9v2OWc7EcptuByzKgUg7/VFhcte5EkKQpNACpGRz/dKOlFpJMyJ2kEzkiKZCheL4m53nchHrz+1tLvngveKRlynTDrUWoqHWTYTgiq9uSCXrSO6FFLQyirZTjTpPKTheHgIHzCu16YNqdAfTDcycxlYelqTcpul7vKcgahkCzPgg4IJaHRyu/bzI8tzPTkIC1YBF81vSIA5a+Cd9FXgoFOMGoJ3uSCx2H+/ujf2Vqqi9vNa2u115kuLH/Uu3DkltUxTZ23jOTe9SAfbXy127TbmSzW8qCKbMc+XH/NIPDFrnlDd1FHl8LWVUxSYSr/74xlYUs5SO45E+FO4+NDRora8YYAkzr8PtxO8ar+HcrSFBaCVhhD8nkjrAZrGwGJg/3CGXbjBpzbu0+tRSBJQviWLiT6nNeYDt5kvvs2h4NLvdoBH+c+cz3J+7BVNljfIrN4imJDjkvPceb1Ad5Y5k7EPjmiX5g0ABCUfSeuRS2RgzeRj3bZ4NW6u2YMiK2IgcLFZbcqRJmBPjsgzZDP8CqTsZ0W7jzLpp7GDvJn63rCW+1lpx6mWSp0NSNZXGLMZJZupzJ7H8UjXI2yj/8g1VRroHWnYQ6UWbzvow0zZuS1Rf+eG9y9gOPS+Hw+uTLn+kbhGXrKPir0fNFZEabdnYKZ0f2LKnVm6+gHJsOSBN7mnTA+VPfFUmji8ANIIdH3EPKxtLX9glACggJU4vulRWRXS6BI8XXNxTOaS7ZTm+FYvMQGUGmwh2QcgShVZLr1Bwdey11t2H5Ot8ZUstulCVrI6PwiJRTSWimX0ipECK4gqskczqPWwVMWlnz1/oC/K/xF0sCHX9ssYE9jBraFYl6BD44W7CImt50ynhhD77ECxptYfvV0 EziAsllN pMiFLqjLGbZ+voX0D3AA9AixJHjmb53o6wH3XdLppnQLocqAbHow9qz2v0jXzp76TDgbIBmISjPpZVA+aB9UXbIBh5SUSamj6Sgyc9WW/VP4WOSw2NV+ZzB6A34otRksbqGvyYfVBPRlkvbOf5/BgeqVpe6TOdG829OqQ 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: Before enabling MTE tag storage management, make sure that the CMA areas have been successfully activated. If a CMA area fails activation, the pages are kept as reserved. Reserved pages are never used by the page allocator. If this happens, the kernel would have to manage tag storage only for some of the memory, but not for all memory, and that would make the code unreasonably complicated. Choose to disable tag storage management altogether if a CMA area fails to be activated. Signed-off-by: Alexandru Elisei --- Changes since v2: * New patch. arch/arm64/include/asm/mte_tag_storage.h | 12 ++++++ arch/arm64/kernel/mte_tag_storage.c | 50 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/arch/arm64/include/asm/mte_tag_storage.h b/arch/arm64/include/asm/mte_tag_storage.h index 3c2cd29e053e..7b3f6bff8e6f 100644 --- a/arch/arm64/include/asm/mte_tag_storage.h +++ b/arch/arm64/include/asm/mte_tag_storage.h @@ -6,8 +6,20 @@ #define __ASM_MTE_TAG_STORAGE_H #ifdef CONFIG_ARM64_MTE_TAG_STORAGE + +DECLARE_STATIC_KEY_FALSE(tag_storage_enabled_key); + +static inline bool tag_storage_enabled(void) +{ + return static_branch_likely(&tag_storage_enabled_key); +} + void mte_init_tag_storage(void); #else +static inline bool tag_storage_enabled(void) +{ + return false; +} static inline void mte_init_tag_storage(void) { } diff --git a/arch/arm64/kernel/mte_tag_storage.c b/arch/arm64/kernel/mte_tag_storage.c index 9a1a8a45171e..d58c68b4a849 100644 --- a/arch/arm64/kernel/mte_tag_storage.c +++ b/arch/arm64/kernel/mte_tag_storage.c @@ -19,6 +19,8 @@ #include +__ro_after_init DEFINE_STATIC_KEY_FALSE(tag_storage_enabled_key); + struct tag_region { struct range mem_range; /* Memory associated with the tag storage, in PFNs. */ struct range tag_range; /* Tag storage memory, in PFNs. */ @@ -314,3 +316,51 @@ void __init mte_init_tag_storage(void) num_tag_regions = 0; pr_info("MTE tag storage region management disabled"); } + +static int __init mte_enable_tag_storage(void) +{ + struct range *tag_range; + struct cma *cma; + int i, ret; + + if (num_tag_regions == 0) + return 0; + + for (i = 0; i < num_tag_regions; i++) { + tag_range = &tag_regions[i].tag_range; + cma = tag_regions[i].cma; + /* + * CMA will keep the pages as reserved when the region fails + * activation. + */ + if (PageReserved(pfn_to_page(tag_range->start))) + goto out_disabled; + } + + static_branch_enable(&tag_storage_enabled_key); + pr_info("MTE tag storage region management enabled"); + + return 0; + +out_disabled: + for (i = 0; i < num_tag_regions; i++) { + tag_range = &tag_regions[i].tag_range; + cma = tag_regions[i].cma; + + if (PageReserved(pfn_to_page(tag_range->start))) + continue; + + /* Try really hard to reserve the tag storage. */ + ret = cma_alloc(cma, range_len(tag_range), 8, true); + /* + * Tag storage is still in use for data, memory and/or tag + * corruption will ensue. + */ + WARN_ON_ONCE(ret); + } + num_tag_regions = 0; + pr_info("MTE tag storage region management disabled"); + + return -EINVAL; +} +arch_initcall(mte_enable_tag_storage);