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 613BCD44161 for ; Tue, 19 Nov 2024 14:26:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E47D06B00A7; Tue, 19 Nov 2024 09:25:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DF85F6B00A8; Tue, 19 Nov 2024 09:25:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7D486B00A9; Tue, 19 Nov 2024 09:25:59 -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 A6EAE6B00A7 for ; Tue, 19 Nov 2024 09:25:59 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5F3B51404E9 for ; Tue, 19 Nov 2024 14:25:59 +0000 (UTC) X-FDA: 82803067788.18.8D264B8 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf13.hostedemail.com (Postfix) with ESMTP id A03FA2000C for ; Tue, 19 Nov 2024 14:25:04 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=Dij1Qjf1; spf=pass (imf13.hostedemail.com: domain of gregkh@linuxfoundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732026208; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:dkim-signature; bh=uJtg//6RekFISmDm/ODRc0Jn5lHjlF0SugJnnIJ4Nzk=; b=JjbqHEQeo74zyezRpjeNgWH2y2nl56Rwa269VrD2gmGRzy1mhp0gpmEMRv75HCF7b7gdxn cBWyN7W1896Vy83ZyA2z9BwKRjtM+/l/oNF9nvAtgrNtWzyvuIQas3AGckNt4KPDX8qBUL 8YrgiFv4/RYWsZhzemnY0ybdLp56SNw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732026208; a=rsa-sha256; cv=none; b=etMZeZ1aJD1FRT9SRjXl8FJHGXKr1Y12MTgDs73t1dKI7vFoWxDa61/FSQRTx4TkvTKO2Z pV2FKpaEHAEjYADrbRNwJ+dV1RM9nJdQX6J0hO7OjUSozVTpxO4wyKzqGCmtgDqBiIiTeg zxoSvdwAQUS3EO+V1CaP6sWuX2Y7A0s= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=Dij1Qjf1; spf=pass (imf13.hostedemail.com: domain of gregkh@linuxfoundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 804B8A42AE1; Tue, 19 Nov 2024 14:24:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CF73C4CED0; Tue, 19 Nov 2024 14:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1732026356; bh=QfD9xcFR6M8+gwvI5WI6UkLy9x/j2xf9oX7ewDFT7/I=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=Dij1Qjf1/hGwJBSo8TQ1LEI6LhDy0hINMw7YakJQzBZC7sKkMELNbTIl53Pi+t8uX 4mkmPdTWrrvE4Bz862HyT0eDWJGGntUu8K/PCW9LiuGPysSoWMPMx5dyE72Zywm+2X eiqwJwK9xO9nR/icS+ZPtD8Oo3UYFPbe8HhtKfS4= Subject: Patch "mm: refactor arch_calc_vm_flag_bits() and arm64 MTE handling" has been added to the 6.1-stable tree To: James.Bottomley@HansenPartnership.com,Liam.Howlett@oracle.com,akpm@linux-foundation.org,andreas@gaisler.com,broonie@kernel.org,catalin.marinas@arm.com,davem@davemloft.net,deller@gmx.de,gregkh@linuxfoundation.org,jannh@google.com,linux-mm@kvack.org,lorenzo.stoakes@oracle.com,peterx@redhat.com,torvalds@linux-foundation.org,vbabka@suse.cz,will@kernel.org Cc: From: Date: Tue, 19 Nov 2024 15:25:24 +0100 In-Reply-To: Message-ID: <2024111924-shone-shadily-ec4b@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit X-stable: commit X-Patchwork-Hint: ignore X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A03FA2000C X-Stat-Signature: 88mcsk5cp1z8r7swucijkxnkhfx8rcir X-HE-Tag: 1732026304-589494 X-HE-Meta: U2FsdGVkX18z1qKzMN/oqU+dkUM3nURMi9tYWi9AMQWnwy13dw79dGxhgbTM1b6lkletT+kXwNKUVGOO1uTlMYGPClG8iPl3Kn+eH0zkShZA3mMTFQE8H4cP7pyob+tEyRr+zfZWnSE2l7GR1QzDKuuBku57OKw1tbrmArJxDOtrinpHXh/qKi7zLNGSrr2MWMVETx7XK9ibVtvFYzSV84GlRR/cco9/0aMlISjWSDex1ZyWyBpdUYxn75IiPYPvM0hoM7XRKKeW/u6oY1qhNEA2EcrqzgmZotOT+VUeIRHytEx+puy6UZGK8+7yF7M0Y4/7JpUbdhjG6gsaqOAEvZkUJD0mwEP1W0eT0cKK34ce1wTLc+C6GrIg5lUVkC5W92X+s3rPYYxu5xhc1in8UCBzyJ+3PjMBKX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l9RcQP5J/P0JkgjqMpNDpiXHrBWTz1F91Vu99lFeOZdajGVlE2DbK6ZE+41VhYQ38UpOdChOK/sE27Mu82MiYcaPRPhQ7APKyktYJ7LpzzEQZ7rkfI9fc1lbBEOfaHix3fKxnjNg3Up3CVbGLuBBRilb2OVgLcu3kVmdCD2hfqeRGldko+D7Fuw3LGduTmgvUCoRX6b9femuvJ6mQvmM7LTUcrtciwvk+etQjIzCfKs5JRVHAlK7hgLblAqCA1l6d2TILo2EL9oIw3kOvwtO8M4Y4s7A8MrOPaEx7546rC8GFaWfmNyq6+ss7ZDSEtr5czPK0KrwTOQfavPuvocUIqEiLm5hxWjkwrDP8QcLgMCQzioDHGdcEUyyLxb2Jau4928Q6uEiQV/0BsgXO9zMg== 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: This is a note to let you know that I've just added the patch titled mm: refactor arch_calc_vm_flag_bits() and arm64 MTE handling to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: mm-refactor-arch_calc_vm_flag_bits-and-arm64-mte-handling.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. >From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lorenzo Stoakes Date: Mon, 18 Nov 2024 16:17:27 +0000 Subject: mm: refactor arch_calc_vm_flag_bits() and arm64 MTE handling To: stable@vger.kernel.org Cc: Andrew Morton , "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson , "James E . J . Bottomley" , Helge Deller Message-ID: From: Lorenzo Stoakes [ Upstream commit 5baf8b037debf4ec60108ccfeccb8636d1dbad81 ] Currently MTE is permitted in two circumstances (desiring to use MTE having been specified by the VM_MTE flag) - where MAP_ANONYMOUS is specified, as checked by arch_calc_vm_flag_bits() and actualised by setting the VM_MTE_ALLOWED flag, or if the file backing the mapping is shmem, in which case we set VM_MTE_ALLOWED in shmem_mmap() when the mmap hook is activated in mmap_region(). The function that checks that, if VM_MTE is set, VM_MTE_ALLOWED is also set is the arm64 implementation of arch_validate_flags(). Unfortunately, we intend to refactor mmap_region() to perform this check earlier, meaning that in the case of a shmem backing we will not have invoked shmem_mmap() yet, causing the mapping to fail spuriously. It is inappropriate to set this architecture-specific flag in general mm code anyway, so a sensible resolution of this issue is to instead move the check somewhere else. We resolve this by setting VM_MTE_ALLOWED much earlier in do_mmap(), via the arch_calc_vm_flag_bits() call. This is an appropriate place to do this as we already check for the MAP_ANONYMOUS case here, and the shmem file case is simply a variant of the same idea - we permit RAM-backed memory. This requires a modification to the arch_calc_vm_flag_bits() signature to pass in a pointer to the struct file associated with the mapping, however this is not too egregious as this is only used by two architectures anyway - arm64 and parisc. So this patch performs this adjustment and removes the unnecessary assignment of VM_MTE_ALLOWED in shmem_mmap(). [akpm@linux-foundation.org: fix whitespace, per Catalin] Link: https://lkml.kernel.org/r/ec251b20ba1964fb64cf1607d2ad80c47f3873df.1730224667.git.lorenzo.stoakes@oracle.com Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Signed-off-by: Lorenzo Stoakes Suggested-by: Catalin Marinas Reported-by: Jann Horn Reviewed-by: Catalin Marinas Reviewed-by: Vlastimil Babka Cc: Andreas Larsson Cc: David S. Miller Cc: Helge Deller Cc: James E.J. Bottomley Cc: Liam R. Howlett Cc: Linus Torvalds Cc: Mark Brown Cc: Peter Xu Cc: Will Deacon Cc: Signed-off-by: Andrew Morton Signed-off-by: Lorenzo Stoakes Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/mman.h | 10 +++++++--- include/linux/mman.h | 7 ++++--- mm/mmap.c | 2 +- mm/nommu.c | 2 +- mm/shmem.c | 3 --- 5 files changed, 13 insertions(+), 11 deletions(-) --- a/arch/arm64/include/asm/mman.h +++ b/arch/arm64/include/asm/mman.h @@ -3,6 +3,8 @@ #define __ASM_MMAN_H__ #include +#include +#include #include #include @@ -21,19 +23,21 @@ static inline unsigned long arch_calc_vm } #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey) -static inline unsigned long arch_calc_vm_flag_bits(unsigned long flags) +static inline unsigned long arch_calc_vm_flag_bits(struct file *file, + unsigned long flags) { /* * Only allow MTE on anonymous mappings as these are guaranteed to be * backed by tags-capable memory. The vm_flags may be overridden by a * filesystem supporting MTE (RAM-based). */ - if (system_supports_mte() && (flags & MAP_ANONYMOUS)) + if (system_supports_mte() && + ((flags & MAP_ANONYMOUS) || shmem_file(file))) return VM_MTE_ALLOWED; return 0; } -#define arch_calc_vm_flag_bits(flags) arch_calc_vm_flag_bits(flags) +#define arch_calc_vm_flag_bits(file, flags) arch_calc_vm_flag_bits(file, flags) static inline bool arch_validate_prot(unsigned long prot, unsigned long addr __always_unused) --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -2,6 +2,7 @@ #ifndef _LINUX_MMAN_H #define _LINUX_MMAN_H +#include #include #include @@ -90,7 +91,7 @@ static inline void vm_unacct_memory(long #endif #ifndef arch_calc_vm_flag_bits -#define arch_calc_vm_flag_bits(flags) 0 +#define arch_calc_vm_flag_bits(file, flags) 0 #endif #ifndef arch_validate_prot @@ -147,12 +148,12 @@ calc_vm_prot_bits(unsigned long prot, un * Combine the mmap "flags" argument into "vm_flags" used internally. */ static inline unsigned long -calc_vm_flag_bits(unsigned long flags) +calc_vm_flag_bits(struct file *file, unsigned long flags) { return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) | _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ) | _calc_vm_trans(flags, MAP_SYNC, VM_SYNC ) | - arch_calc_vm_flag_bits(flags); + arch_calc_vm_flag_bits(file, flags); } unsigned long vm_commit_limit(void); --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1316,7 +1316,7 @@ unsigned long do_mmap(struct file *file, * to. we assume access permissions have been handled by the open * of the memory object, so we don't do any here. */ - vm_flags = calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(flags) | + vm_flags = calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(file, flags) | mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC; if (flags & MAP_LOCKED) --- a/mm/nommu.c +++ b/mm/nommu.c @@ -903,7 +903,7 @@ static unsigned long determine_vm_flags( { unsigned long vm_flags; - vm_flags = calc_vm_prot_bits(prot, 0) | calc_vm_flag_bits(flags); + vm_flags = calc_vm_prot_bits(prot, 0) | calc_vm_flag_bits(file, flags); /* vm_flags |= mm->def_flags; */ if (!(capabilities & NOMMU_MAP_DIRECT)) { --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2306,9 +2306,6 @@ static int shmem_mmap(struct file *file, if (ret) return ret; - /* arm64 - allow memory tagging on RAM-based files */ - vma->vm_flags |= VM_MTE_ALLOWED; - file_accessed(file); vma->vm_ops = &shmem_vm_ops; return 0; Patches currently in stable-queue which might be from lorenzo.stoakes@oracle.com are queue-6.1/mm-resolve-faulty-mmap_region-error-path-behaviour.patch queue-6.1/mm-refactor-arch_calc_vm_flag_bits-and-arm64-mte-handling.patch queue-6.1/mm-unconditionally-close-vmas-on-error.patch queue-6.1/mm-avoid-unsafe-vma-hook-invocation-when-error-arises-on-mmap-hook.patch