From mboxrd@z Thu Jan 1 00:00:00 1970 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 41325C47DA9 for ; Mon, 29 Jan 2024 11:46:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACB626B00AC; Mon, 29 Jan 2024 06:46:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A499D6B00AD; Mon, 29 Jan 2024 06:46:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EA576B00AE; Mon, 29 Jan 2024 06:46:02 -0500 (EST) 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 799CA6B00AC for ; Mon, 29 Jan 2024 06:46:02 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4FAE1A178A for ; Mon, 29 Jan 2024 11:46:02 +0000 (UTC) X-FDA: 81732169764.21.1990851 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf21.hostedemail.com (Postfix) with ESMTP id 2F8C21C000F for ; Mon, 29 Jan 2024 11:46:00 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf21.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706528760; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZUcXDmvpL9FXE44Mq21KQjImKh/iRaAvhaamp5tiy6E=; b=y0DYwbNiN7jK3II0QrYxygN0465u7xzn0hDZtHVWlKmtSuPSqiIQnlfHOZkIDCqOde12Ox D+OblyKIMz7FxDaBhHBquFIrXecbyKHfgdWO6lj3Nl5+ssRZ0LRA8DMhev8afELxJ5RxjT MlbRk0mCtnXVOUsUG0JrE4/zm2dfMLI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf21.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706528760; a=rsa-sha256; cv=none; b=ckB3t5DNSHGbaKdJAbWlM5S6Hd7dAoAesVlkddB4FIpzm1vNIrakJBJmsioxLERAVobGum D1pm7kjW9q0Y6bWgVF5JL9zs9EWZydZB7GLcDVhnSuLUFiEXjoZP4X8MeK3rj+Aaiu0dpJ 1lTOlZ5y2uUji5UrAV/oZvt2g9yyqvg= 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 1FA1E1FB; Mon, 29 Jan 2024 03:46:43 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E72E63F5A1; Mon, 29 Jan 2024 03:45:53 -0800 (PST) Date: Mon, 29 Jan 2024 11:45:51 +0000 From: Alexandru Elisei To: Anshuman Khandual Cc: 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, pcc@google.com, steven.price@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: Re: [PATCH RFC v3 03/35] mm: page_alloc: Add an arch hook to filter MIGRATE_CMA allocations Message-ID: References: <20240125164256.4147-1-alexandru.elisei@arm.com> <20240125164256.4147-4-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 2F8C21C000F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 3dc5qy48xr836d6gwccsfywmqpffygcb X-HE-Tag: 1706528760-123608 X-HE-Meta: U2FsdGVkX1/3kYaFu+vdZLWGZaTVwi00wDVF22geTsOfu5pWrUZ3X3sRVXKGAG8GPOYkQw+TpqFG0KiSZYJ6kRWny8qLUfOzkelwCJ3dFOnquIPI9EUtUR5ntJXO3mX5sRbyVidxAOZWW+GpnNU8z4djgnyn0agCgw99fVSlP/9h73rvtiocRfMxDkvXOg9hliW/rRVV4HoGJpvDqT2NSpb4SW4v7ipD/H32eoy5bqCt6GS+i4I4A8ZzTMz5JiVo0iG6B2x5gfQY5u7UlLsofOGqZdxBRUYLSA1OQ/hRj5BK6v86eZHyoCPPTAZw5eJIczaOpg6Mu/w/EP1JKgkE1fhbzlm1VZE48440D8dTtPvcIcaL86G0x0qcR8i8o7DYtuhKVQQgDdRoz2WRkeYCa7gpnK1WRsP/iGANCuwrAVH5Xo/uT5omhxTXGax1Eke+2iurRSHYClRIX/uoFGBan78LSUF06zo8OH+aPzPF1EzQMfKZoE8yLtoBM7H6aI+6VgIlJ1Qr6njaEZjE+bJLQ7Vy7DNMhiyhdwNonc1auf1OHchVbJQCUJLZXSsvItyz37SL+VqzFAsmHv0I+YqG+fodqOCtIS9DA9CbHQpKAj+/q+v9AnlGP/AoLbONwDE1mzr5FLQ/WOrojn+Fx9CAJFFydbSN1dH6Zb07f5s6iz2PTzKTSJoIum9Ctw1xuDy/nsASGijSgCQzBe6MNMCBDHdW/1vVZxBl3G+vFKT7tDelMcgOXspqNY5uLYWLlKcq1mt272dnwaaxQrv3jqFTSki7CEwWIZgnFJkjN6RoOuazNl4szPbJoraYilcqHOMUX2+jya/qW5vu1bp+CkLdDnt7vpiNxkzZ9tCooSiLptdgfAJqpLxSkF4fSU0rSs7KedNSxfk14AQPA+94waqo1E1a/PCkpsZTNm+ocpGTIpawyjVz7SmaPBQbUss52EJhricvGfi68QQU61gdqzf xs2qRW6K 6HWZOrO978fE79IKUXk5Uu3o5gBbf+kxVL89yebD79oj0MiJHKgQ8TIdwkka0AGZEKW32gWZnQbeKLokDF8D2EV9RFydwSK4iqL0+XnV9mM1sWXfWRWL7+P8CECACxd8X6ExuNhM+aeaHcDsEpnncnf7tmpZyLbGzQRq3xlZlajjptLpGYvvHO5crry0k8thzKd+5UQN15WDtVIuxL/2Nf+F2zZpwWpmswGH/9oiVA/Ms4zol769w6uawdv9gEMl4asepgw/wbzvlTv8rlpB/Kb441Q== 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: Hi, On Mon, Jan 29, 2024 at 02:14:16PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > As an architecture might have specific requirements around the allocation > > of CMA pages, add an arch hook that can disable allocations from > > MIGRATE_CMA, if the allocation was otherwise allowed. > > > > This will be used by arm64, which will put tag storage pages on the > > MIGRATE_CMA list, and tag storage pages cannot be tagged. The filter will > > be used to deny using MIGRATE_CMA for __GFP_TAGGED allocations. > > Just wondering how allocation requests would be blocked for direct > alloc_contig_range() requests ? alloc_contig_range() does page allocation in __alloc_contig_migrate_range() -> alloc_migration_target(); __alloc_contig_migrate_range() ignores the gfp_mask parameter passed to alloc_contig_range() when building struct migration_target_control, even though it's available in the struct compact_control argument. That looks like a bug to me, as the decription for the gfp_mask parameter says: "GFP mask to use during compaction". Regardless, when tag storage page T1 is migrated to it can be used to storage tags, it doesn't matter if it is replaced by another tag storage page T2 or a regular page, as long as the replacement isn't also tagged. If the replacement is also tagged, the code to reserve tag storage would recurse and deadlock. See patch #16 ("KVM: arm64: Don't deny VM_PFNMAP VMAs when kvm_has_mte()") [1] for the code. Does that make sense? [1] https://lore.kernel.org/linux-mm/20240125164256.4147-24-alexandru.elisei@arm.com/ > > > > > Signed-off-by: Alexandru Elisei > > --- > > include/linux/pgtable.h | 7 +++++++ > > mm/page_alloc.c | 3 ++- > > 2 files changed, 9 insertions(+), 1 deletion(-) > > > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > > index 6d98d5fdd697..c5ddec6b5305 100644 > > --- a/include/linux/pgtable.h > > +++ b/include/linux/pgtable.h > > @@ -905,6 +905,13 @@ static inline void arch_do_swap_page(struct mm_struct *mm, > > static inline void arch_free_pages_prepare(struct page *page, int order) { } > > #endif > > > > +#ifndef __HAVE_ARCH_ALLOC_CMA > > Same as last patch i.e __HAVE_ARCH_ALLOC_CMA could be avoided via > a direct check on #ifndef arch_alloc_cma instead. include/linux/pgtable.h uses __HAVE_ARCH_*, and I would rather keep it consistent. Thanks, Alex > > > +static inline bool arch_alloc_cma(gfp_t gfp) > > +{ > > + return true; > > +} > > +#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 27282a1c82fe..a96d47a6393e 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -3157,7 +3157,8 @@ static inline unsigned int gfp_to_alloc_flags_cma(gfp_t gfp_mask, > > unsigned int alloc_flags) > > { > > #ifdef CONFIG_CMA > > - if (gfp_migratetype(gfp_mask) == MIGRATE_MOVABLE) > > + if (gfp_migratetype(gfp_mask) == MIGRATE_MOVABLE && > > + arch_alloc_cma(gfp_mask)) > > alloc_flags |= ALLOC_CMA; > > #endif > > return alloc_flags;