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 D8DE7D44162 for ; Tue, 19 Nov 2024 14:26:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 436A66B00B1; Tue, 19 Nov 2024 09:26:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E5856B00B2; Tue, 19 Nov 2024 09:26:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 289986B00B3; Tue, 19 Nov 2024 09:26:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 03EF06B00B1 for ; Tue, 19 Nov 2024 09:26:20 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BE2131A04C8 for ; Tue, 19 Nov 2024 14:26:20 +0000 (UTC) X-FDA: 82803067452.19.444B6EF Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf29.hostedemail.com (Postfix) with ESMTP id F1276120014 for ; Tue, 19 Nov 2024 14:25:10 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=RrtPcUwQ; spf=pass (imf29.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=1732026287; 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=rERbkM8szdVL0Zstol54KoFqttf2pbYOQTl2R7KVMS4=; b=R0xypgUfQUSpdDIR5OBXr83QNQKlAozMyE+oh5pN1GQIWPDtdbHxzh/9FJAf5sOR/V+lV/ 1ZRfeEVZFm8AU3JkW6JHU6IvIQl/CkOeMN98ANqx52H7xbwgt7ylSRmckOyW5JeAuQnVi5 mwry/Smq9dFRewCuVkeowztcDEBKp3E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732026287; a=rsa-sha256; cv=none; b=kB1hqnGSYsKLNI62hHxehioJdElSMlT6K3xtlq+x2a/rliCXvezgUqaaKrnaG052NtKaBA p3OlQPRlXCWuT0AXRDT/AdXu7JgWkX9M0hejevlgl3T7wUvLecZlHybH4i1u1IHLBciwXG 8AMlUN6BHEkRUpn+Mzi0Trc2aeKO4pg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=RrtPcUwQ; spf=pass (imf29.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 D98C1A42AE4; Tue, 19 Nov 2024 14:24:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2C87C4CECF; Tue, 19 Nov 2024 14:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1732026378; bh=8xYnoBYiFRTqj748S/FkOwvTPQD8aBe5yBX2iRqLP0E=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=RrtPcUwQGcP25iQ/fDBTHnjdUDIcnpr0Mhe7ifFy1HZy9miJHrbFxSxIXF3/nMjsS ZZHIUycdmNAVe+j3wMnVsSJY4AvQF8GvhjXGSPLwtjZDyFCXVS9I0ofi9+90kNPmWP l1ohZporTrKArtsUPmbl26ig068FK6D3O9N1JPtU= Subject: Patch "mm: refactor arch_calc_vm_flag_bits() and arm64 MTE handling" has been added to the 6.6-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:46 +0100 In-Reply-To: <7c0218d03fd2119025d8cbc1b814639cf09314e0.1731672733.git.lorenzo.stoakes@oracle.com> Message-ID: <2024111946-spectator-judicial-fa10@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-Rspamd-Server: rspam10 X-Stat-Signature: dxj1pjxgizfafks9z5xcxe7azt3okka6 X-Rspamd-Queue-Id: F1276120014 X-Rspam-User: X-HE-Tag: 1732026310-26076 X-HE-Meta: U2FsdGVkX1+yogRGTaRMggrBagfXO3t1J8giuUV7AqAF4uCv4bGlGhwdNfs72Uc6+1iWhqsJhGZBdIPcQcz6nzSn0W1eRGeqZzSCQLYKwTc/ay3x68lQiSOR0yvNxgLKt+anpblZ+WF7TkyMIvbyUIRQ4MeYtwaVJxyG737vF6cggq0W/ififhZ43DylwrGjbjZZBXa2vamXX5GjvMSyOTVy86PCdxUILIx3MXE0Fzsl8RDKNWCHG8Ij5NtZ+2VzsoH1ImYXrFYmXzFIh2cJZe/esgVp550GFom9GLwoIqNC5Mcv+NTpOGsgzwc33NI/4eXE7aqEfaEGEYOjSZWDVu4xOvE5hujv0zyWqVcvyph4bXXtQ0ObFhk27po5CS31NsaD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x4zaC+6CfMnsUBOiEJMlOFlqtpq8hlkDB59rLVKq3zNeBJTGFZe1w+PRr/EK1eOdKA85J5jrbz+69TviikLdPGnIGSU+X8HSlr/ZlgKIF6WScdQ1z7DjYZdkhrDzVEpRJsNxgy8j8M3UFyYgGlcF+2QWFq45I7XBsRU3AmFiJcKM3yhXjHSO2DAOQossB2erV/u6TIGwCnJdXJW+StimnteL1fiTKMojqtECuPyEJzfc47VVYkP7ej11WvKK8ZYEOqYZX/eLsWQr4XWgahBjaiaaZGq45WIT4X5dzmUek7X4OR+K64LPTXE+484sCofVFKjmZdsm48MMIzE/AtUVfF1/oLcuF3ofGpVua1NP+6Fxn5kBo2KylBxaxVIxbNmCuRLNX3+x/pB7TogTB2owZfBxLd+Y2/pvzMh+jG4JlCOXKBPq7KsPorVFGbUKg== 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.6-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.6 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. >From stable+bounces-93538-greg=kroah.com@vger.kernel.org Fri Nov 15 13:43:44 2024 From: Lorenzo Stoakes Date: Fri, 15 Nov 2024 12:41:57 +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: <7c0218d03fd2119025d8cbc1b814639cf09314e0.1731672733.git.lorenzo.stoakes@oracle.com> 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 +++++++--- arch/parisc/include/asm/mman.h | 5 +++-- include/linux/mman.h | 7 ++++--- mm/mmap.c | 2 +- mm/nommu.c | 2 +- mm/shmem.c | 3 --- 6 files changed, 16 insertions(+), 13 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/arch/parisc/include/asm/mman.h +++ b/arch/parisc/include/asm/mman.h @@ -2,6 +2,7 @@ #ifndef __ASM_MMAN_H__ #define __ASM_MMAN_H__ +#include #include /* PARISC cannot allow mdwe as it needs writable stacks */ @@ -11,7 +12,7 @@ static inline bool arch_memory_deny_writ } #define arch_memory_deny_write_exec_supported arch_memory_deny_write_exec_supported -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) { /* * The stack on parisc grows upwards, so if userspace requests memory @@ -23,6 +24,6 @@ static inline unsigned long arch_calc_vm 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) #endif /* __ASM_MMAN_H__ */ --- 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 @@ -94,7 +95,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 @@ -151,12 +152,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 @@ -1273,7 +1273,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 @@ -853,7 +853,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); if (!file) { /* --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2400,9 +2400,6 @@ static int shmem_mmap(struct file *file, if (ret) return ret; - /* arm64 - allow memory tagging on RAM-based files */ - vm_flags_set(vma, VM_MTE_ALLOWED); - file_accessed(file); /* This is anonymous shared memory if it is unlinked at the time of mmap */ if (inode->i_nlink) Patches currently in stable-queue which might be from lorenzo.stoakes@oracle.com are queue-6.6/mm-resolve-faulty-mmap_region-error-path-behaviour.patch queue-6.6/mm-refactor-arch_calc_vm_flag_bits-and-arm64-mte-handling.patch queue-6.6/mm-unconditionally-close-vmas-on-error.patch queue-6.6/mm-avoid-unsafe-vma-hook-invocation-when-error-arises-on-mmap-hook.patch queue-6.6/mm-refactor-map_deny_write_exec.patch