Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp83254rdb; Thu, 25 Jan 2024 08:53:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3ACWE9VY5sa6C9jXBWAAFFErAS8vzCg4qUjTeysnw8Csk8d+3uUHiUKfWqPrlRUscToUC X-Received: by 2002:a05:6871:5224:b0:210:ad7a:7a0c with SMTP id ht36-20020a056871522400b00210ad7a7a0cmr1397340oac.84.1706201581604; Thu, 25 Jan 2024 08:53:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706201581; cv=pass; d=google.com; s=arc-20160816; b=DlhWWjbk17/bgiYFgWrTN7x06jpGg+KIMFjJMbHcI8lsmDNAiKJgZFc83rMsFV+bXg Snu3lDQTOpIlG1rgo67vXoGrtTlpPzvVsn82iWGcRNNTdeXSSZQZInVVGgbl5YwAJmLG Q2128d/Q9t6LUOyP0BvkXi5DWWowfg2B2UP9XEbQlzOSTPuWrFMBmx7qGQg0/R2m5rOF jpLuj4jcrN9JbslXnDwFQ3uoMQkTz1DAgOYoa6kEj5f/53Qf5y5WN+d/wqxxKKtUY0Im YtQ0VLlSNOoecXKSDnFLfhp+lp+zUq9zBlUd1Ap+CNTh2TfR3J8sdS+DQgJeQK3na+Re OTVg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=5zf4/QVJoGe+m11F6r0cQ8EbqmSgrLFc9Da1YM6fJtc=; fh=ON0oQ90Z4xnjbNCGsyMgiRbLR29nyOKvbeaw6TmRihk=; b=C4ri6Nw/FiLz4OCQ1FxJlxWrGmLBkK0MxXZyqXKeNA4pPN+IgGqQrlj1fG3mscRCOZ ad22gWULs5FWUGlE3qdVpnFFinFY31rh+j8oVuy6pjWFHemc6fZmt2fTQ0I/nVS6/+BJ kyCHPUyMCHtKLmiTbb+eVtthG6T7mc+7hQcdKFHPnxO1f3vZ5MmWbvMLpEQNcdeMjs8O khTgfUAiu+NqgG8oE3wngz417fkcLF4KWR16acxuTGzOxBS5u8DH9urPDiJymzO1zCy7 eqMfVWlqZIJpuOx6ZiC4L+H8v4L5Oas4+HiodFLloA7BtfLu040jmWVanxBIP+R7Uq+t swEA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-38937-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38937-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pc20-20020a05620a841400b00783155238bbsi12074095qkn.67.2024.01.25.08.53.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 08:53:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38937-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-38937-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38937-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5BB821C20433 for ; Thu, 25 Jan 2024 16:53:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF80F13F01F; Thu, 25 Jan 2024 16:44:56 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B4FC1350EA; Thu, 25 Jan 2024 16:44:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706201096; cv=none; b=dVcfsCaMbkC/XreZ5dYLy43zEO5x9YlWstvWrXlKdITV7e3ZVj0ehNoPV67kpf2N2Fvh9/fGhpLz2hvC0iKI5XbSQGuqh7JQjwWaeqk7PSoc2X2JQRogb7FmYwZXPUqotReqYW5spvZnBzJ6imbeyUkMKvKzbbsZBfgb7USQ9Pk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706201096; c=relaxed/simple; bh=5j3hCO+SRe3ogKV7m0cZMRApaUCUfxhFuXhoI8hsaew=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pGwIGPWOho8aA+asoz4tHg2PZtpujmMStT1AMlXGsUrGSjW3wkLTHsnihV2hzC5bnESrjx3QQYR4q2GJDumHX5itx4ksFMMFObDD2p2COlQ0tLE+b9lPeqVX0+l+zsT9TEqSIKffL9gi1agTLSKsyJP0TT08mfVfk1MfDCih5Ew= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); -- 2.43.0