From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A7231514F1 for ; Wed, 27 Mar 2024 20:11:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711570312; cv=none; b=miCiDMVWEi3X7CKTMHUfPZaEODEYwOkj5UyOHjZvadzhWbu7bpfRzs95ZE0AHIz5QGSN6Bx5101HMZj88NQjmk1YBpE/jIpM6qyRpT1IKyzZ+EK6kN/RZPc7XIsjelMxwF2rNJ55gju4005eMHCVun1KC1gX7U49oaUaxyew/rw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711570312; c=relaxed/simple; bh=Dg/j0whBh3g7p7w/kA++JTdWnz30DzTy4TC7ACdIodw=; h=Date:To:From:Subject:Message-Id; b=SE14qKVxo4A8TTALlofEmX7DucDoTUOKoUxO0Mp4b5HOenzilBucgtBpNv9fR73S9COTN38RI02cML7vaY8Ff9mH0lF61HwCpbwpdW+tbCy09EJklzUM4HLc9VYD1/SQ9Q2ZrtC0U/Y8c4zKbJaQ1Y2U5igkb1p5UGJ2BCn9Q2E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=mqMr9H9N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="mqMr9H9N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84CEEC433F1; Wed, 27 Mar 2024 20:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1711570311; bh=Dg/j0whBh3g7p7w/kA++JTdWnz30DzTy4TC7ACdIodw=; h=Date:To:From:Subject:From; b=mqMr9H9NOkVpxcKcretwyhndz79SI1llMM0B8IBDrVkPKe9c7ZXpVJxyeb7L2kHoa 2afDSf1OIYa5pwtFpHEtu7gNDlGJiydeJVnrSJmI6ZXE1ghRd9AVxsF0G2NxRfwew2 ST94znc4FqsO3Y6sDtUiovK70nKf5PzyAMdBROi4= Date: Wed, 27 Mar 2024 13:11:50 -0700 To: mm-commits@vger.kernel.org,tglx@linutronix.de,peterz@infradead.org,npiggin@gmail.com,naveen.n.rao@linux.ibm.com,mpe@ellerman.id.au,mingo@redhat.com,luto@kernel.org,Liam.Howlett@oracle.com,kirill.shutemov@linux.intel.com,keescook@chromium.org,James.Bottomley@HansenPartnership.com,hpa@zytor.com,guoren@kernel.org,deller@gmx.de,debug@rivosinc.com,dave.hansen@linux.intel.com,dan.j.williams@intel.com,christophe.leroy@csgroup.eu,broonie@kernel.org,bp@alien8.de,ast@kernel.org,aneesh.kumar@kernel.org,rick.p.edgecombe@intel.com,akpm@linux-foundation.org From: Andrew Morton Subject: + x86-mm-implement-have_arch_unmapped_area_vmflags.patch added to mm-unstable branch Message-Id: <20240327201151.84CEEC433F1@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: x86/mm: implement HAVE_ARCH_UNMAPPED_AREA_VMFLAGS has been added to the -mm mm-unstable branch. Its filename is x86-mm-implement-have_arch_unmapped_area_vmflags.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/x86-mm-implement-have_arch_unmapped_area_vmflags.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Rick Edgecombe Subject: x86/mm: implement HAVE_ARCH_UNMAPPED_AREA_VMFLAGS Date: Mon, 25 Mar 2024 19:16:54 -0700 When memory is being placed, mmap() will take care to respect the guard gaps of certain types of memory (VM_SHADOWSTACK, VM_GROWSUP and VM_GROWSDOWN). In order to ensure guard gaps between mappings, mmap() needs to consider two things: 1. That the new mapping isn't placed in an any existing mappings guard gaps. 2. That the new mapping isn't placed such that any existing mappings are not in *its* guard gaps. The longstanding behavior of mmap() is to ensure 1, but not take any care around 2. So for example, if there is a PAGE_SIZE free area, and a mmap() with a PAGE_SIZE size, and a type that has a guard gap is being placed, mmap() may place the shadow stack in the PAGE_SIZE free area. Then the mapping that is supposed to have a guard gap will not have a gap to the adjacent VMA. Add x86 arch implementations of arch_get_unmapped_area_vmflags/_topdown() so future changes can allow the guard gap of type of vma being placed to be taken into account. This will be used for shadow stack memory. Link: https://lkml.kernel.org/r/20240326021656.202649-13-rick.p.edgecombe@intel.com Signed-off-by: Rick Edgecombe Cc: Alexei Starovoitov Cc: Andy Lutomirski Cc: Aneesh Kumar K.V Cc: Borislav Petkov (AMD) Cc: Christophe Leroy Cc: Dan Williams Cc: Dave Hansen Cc: Deepak Gupta Cc: Guo Ren Cc: Helge Deller Cc: H. Peter Anvin (Intel) Cc: Ingo Molnar Cc: "James E.J. Bottomley" Cc: Kees Cook Cc: Kirill A. Shutemov Cc: Liam R. Howlett Cc: Mark Brown Cc: Michael Ellerman Cc: Naveen N. Rao Cc: Nicholas Piggin Cc: Peter Zijlstra Cc: Thomas Gleixner Signed-off-by: Andrew Morton --- arch/x86/include/asm/pgtable_64.h | 1 + arch/x86/kernel/sys_x86_64.c | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) --- a/arch/x86/include/asm/pgtable_64.h~x86-mm-implement-have_arch_unmapped_area_vmflags +++ a/arch/x86/include/asm/pgtable_64.h @@ -245,6 +245,7 @@ extern void cleanup_highmap(void); #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_UNMAPPED_AREA_VMFLAGS #define PAGE_AGP PAGE_KERNEL_NOCACHE #define HAVE_PAGE_AGP 1 --- a/arch/x86/kernel/sys_x86_64.c~x86-mm-implement-have_arch_unmapped_area_vmflags +++ a/arch/x86/kernel/sys_x86_64.c @@ -113,8 +113,8 @@ static void find_start_end(unsigned long } unsigned long -arch_get_unmapped_area(struct file *filp, unsigned long addr, - unsigned long len, unsigned long pgoff, unsigned long flags) +arch_get_unmapped_area_vmflags(struct file *filp, unsigned long addr, unsigned long len, + unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags) { struct mm_struct *mm = current->mm; struct vm_area_struct *vma; @@ -149,9 +149,9 @@ arch_get_unmapped_area(struct file *filp } unsigned long -arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, - const unsigned long len, const unsigned long pgoff, - const unsigned long flags) +arch_get_unmapped_area_topdown_vmflags(struct file *filp, unsigned long addr0, + unsigned long len, unsigned long pgoff, + unsigned long flags, vm_flags_t vm_flags) { struct vm_area_struct *vma; struct mm_struct *mm = current->mm; @@ -220,3 +220,18 @@ bottomup: */ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags); } + +unsigned long +arch_get_unmapped_area(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, unsigned long flags) +{ + return arch_get_unmapped_area_vmflags(filp, addr, len, pgoff, flags, 0); +} + +unsigned long +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr, + const unsigned long len, const unsigned long pgoff, + const unsigned long flags) +{ + return arch_get_unmapped_area_topdown_vmflags(filp, addr, len, pgoff, flags, 0); +} _ Patches currently in -mm which might be from rick.p.edgecombe@intel.com are proc-refactor-pde_get_unmapped_area-as-prep.patch mm-switch-mm-get_unmapped_area-to-a-flag.patch mm-introduce-arch_get_unmapped_area_vmflags.patch mm-remove-export-for-get_unmapped_area.patch mm-use-get_unmapped_area_vmflags.patch thp-add-thp_get_unmapped_area_vmflags.patch csky-use-initializer-for-struct-vm_unmapped_area_info.patch parisc-use-initializer-for-struct-vm_unmapped_area_info.patch powerpc-use-initializer-for-struct-vm_unmapped_area_info.patch treewide-use-initializer-for-struct-vm_unmapped_area_info.patch mm-take-placement-mappings-gap-into-account.patch x86-mm-implement-have_arch_unmapped_area_vmflags.patch x86-mm-care-about-shadow-stack-guard-gap-during-placement.patch selftests-x86-add-placement-guard-gap-test-for-shstk.patch