Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp78915rdb; Thu, 25 Jan 2024 08:44:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqvVo/T7+5E598F21Etz/5JsaCNeaspkze5zWwpYM0D6dln1iHboZUf2bN3d2F6jYDeWsM X-Received: by 2002:a17:903:20f:b0:1d5:c77c:1ba8 with SMTP id r15-20020a170903020f00b001d5c77c1ba8mr1220246plh.113.1706201081649; Thu, 25 Jan 2024 08:44:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706201081; cv=pass; d=google.com; s=arc-20160816; b=x84JArk0ko2YT5bHftp2LabSehU8SCIiS7uOnF7nFDToWDAznSKmDAoWcYIU3D25Xn kQstonV/Gd+edim9Z28s1r5EP8Zqm0GBrZPsU0kDtlPYZ+t9Z7+nx2Iriq3nc9Qn3Nwo bmw64XhPU2YRfwbgYrDA8HaKK6IoUHUxTQxJB9yfRwgkYaiARNSkMoog2CPF/uTT0rQk G1tkY4AA2TrjZ4H6sT2KZVIVkbd+wmAaWFYWNh6baEkzLe7eFj8X5AyWEQQ/9eJsh6mz OEdoW/z1GG1/bCB4f7BfKYLE4GzaDyckNjShyrrk1c9y8bSC5G/x42lXrHstpA1RBxR8 XRwg== 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=wwaMmcFR+7gYAKWJTVbpRrP8BqwS476rsGrY3piUjRU=; fh=ON0oQ90Z4xnjbNCGsyMgiRbLR29nyOKvbeaw6TmRihk=; b=X8NNJU9BzzmpVnd26uB4Zf4D002Yn3gj/GW8Mlc/hYwQAt8AQHaio7Jws4Gdh7cI3g yAbz5rRltLSdXsb95sXEx8VfaWPjjbYENbRgp03nYyxa61Mqfhey3woNnDNqCexS0TAN 04zGQCbId6bt+3tCMDyacWGckrenSbfut2MfcotsHD/B8sMjzx4kqxA5DEQDAapPtlhC 353VyBJp5ctNdTCGWFu4Qx0d+lr4pssTTGGu6pG2vGnDs7pzoBwypPTUhJgM6tbD8C1l mu1zqHLv62ucDhosABaKcsiatcIIAtjn0kryE1DlLPhaDPZ4g9pelJHZgs4zC9ziRXGn +tZw== 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-38915-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38915-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i11-20020a170902c94b00b001d88baf3f09si1225181pla.310.2024.01.25.08.44.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 08:44:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38915-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-38915-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38915-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4F1E52955EC for ; Thu, 25 Jan 2024 16:44:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F4BC1350D3; Thu, 25 Jan 2024 16:43:02 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15A1A1339AC; Thu, 25 Jan 2024 16:42:58 +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=1706200981; cv=none; b=SXtRzpllnD8mw+uO3eGpPy+HL3zfTwz++zLkr5Fl89uxhNyWc0jfnqIk55P8Mcbql0dUwAuI+77knEoCBgUYxbdbinsYuAHWCbDobKOUvUIOh3TFzB/L33Zr1FgBKdVmtgxA/mfKenXZnReSbgCa/NyvbiK53NbBtiGYODC2FiU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706200981; c=relaxed/simple; bh=AU78t+xYF5XPueOYyl2tCt7NLi6rgnb5IFhCKQ+TQ2M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HIGLgaXK8qCEmJ6liyXSufAY1y6Y2yWlvjp6LRpvIFMfT2WFdiMC0xHazHcD/SEobjpbLahoSHqGumrjhp6AWljLtTpu91i7ykU0NWyz5JHSbfWVcIgwcXIdKUew22EXg+XQ/DpDP2saIQJNaKc/hQS/oL08+TR9jLUkFU14ozk= 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 13EB31476; Thu, 25 Jan 2024 08:43:43 -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 219223F5A1; Thu, 25 Jan 2024 08:42:52 -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 02/35] mm: page_alloc: Add an arch hook early in free_pages_prepare() Date: Thu, 25 Jan 2024 16:42:23 +0000 Message-Id: <20240125164256.4147-3-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 The arm64 MTE code uses the PG_arch_2 page flag, which it renames to PG_mte_tagged, to track if a page has been mapped with tagging enabled. That flag is cleared by free_pages_prepare() by doing: page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; When tag storage management is added, tag storage will be reserved for a page if and only if the page is mapped as tagged (the page flag PG_mte_tagged is set). When a page is freed, likewise, the code will have to look at the the page flags to determine if the page has tag storage reserved, which should also be freed. For this purpose, add an arch_free_pages_prepare() hook that is called before that page flags are cleared. The function arch_free_page() has also been considered for this purpose, but it is called after the flags are cleared. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * Expanded commit message (David Hildenbrand). include/linux/pgtable.h | 4 ++++ mm/page_alloc.c | 1 + 2 files changed, 5 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index f6d0e3513948..6d98d5fdd697 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -901,6 +901,10 @@ static inline void arch_do_swap_page(struct mm_struct *mm, } #endif +#ifndef __HAVE_ARCH_FREE_PAGES_PREPARE +static inline void arch_free_pages_prepare(struct page *page, int order) { } +#endif + #ifndef __HAVE_ARCH_UNMAP_ONE /* * Some architectures support metadata associated with a page. When a diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2c140abe5ee6..27282a1c82fe 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1092,6 +1092,7 @@ static __always_inline bool free_pages_prepare(struct page *page, trace_mm_page_free(page, order); kmsan_free_page(page, order); + arch_free_pages_prepare(page, order); if (memcg_kmem_online() && PageMemcgKmem(page)) __memcg_kmem_uncharge_page(page, order); -- 2.43.0