From patchwork Tue Mar 26 02:16:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 13603267 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 90F9EC54E58 for ; Tue, 26 Mar 2024 02:17:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B807D6B0099; Mon, 25 Mar 2024 22:17:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B0CE96B009B; Mon, 25 Mar 2024 22:17:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E6BF6B009D; Mon, 25 Mar 2024 22:17:27 -0400 (EDT) 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 6D45C6B0099 for ; Mon, 25 Mar 2024 22:17:27 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 45B358019B for ; Tue, 26 Mar 2024 02:17:27 +0000 (UTC) X-FDA: 81937578534.23.49BA7A2 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by imf06.hostedemail.com (Postfix) with ESMTP id 48D4D180005 for ; Tue, 26 Mar 2024 02:17:25 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=jTIIXDg5; spf=pass (imf06.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 198.175.65.16 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711419445; 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:references:dkim-signature; bh=PaLSyVVvKykie/0xoWH+rnIzylulthbSti8320sfefU=; b=MhqrlO51WkkqwipczYJ/YzbqQzRdVWeHQQ855wAiMX/PQCvMxwPa4fn0jr6kR8ChgWEnZn 33FimeLVpCKeAWsbZpkbhnIMUkgpGlpL2bKj2UlFlbgx7T71UvakIBT4Ow1If6K/VDOLXm QuN6G6r/eS34g01lI98hpiaNjjDx/PQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711419445; a=rsa-sha256; cv=none; b=f2afcQbJnnmoNtO87B7uo3PB+MFiMVE1yTtoG6aJatxtrM0fROhMHyTjEXF4f5YZiLBOja KihrZrtPK8Uq61+jv2mpSg9NqToxoRl9zgBDDl3SQ7TWctN+24pFHukiMP2GOgJ3dsikig u7vIHpuyYeMwfkGNjK+5TzbTgbDnXw8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=jTIIXDg5; spf=pass (imf06.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 198.175.65.16 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711419445; x=1742955445; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uO697Q/RqZjisoLPzX7dc/TQTP+f7eWP95gfUGD1wX8=; b=jTIIXDg54ApJBYIsY6t1OAQYrrkaPE6z/QOEPErXfpKZWLSq3B/SiLOX zJd/MblbEfYbFQ/msGCW9+37xI5vdBvbyXfAykvPhkZtWxAOqc0mtIVA5 mq7lWY1UX6dV3lS4mtfvwjs1OEGU/4MiauBNsz4k6K19XAhsfIbIr04+l SfufTXe7mFtcDABeABjteljKRn5RZKPoN7lsu3P1VVpdFTvLak6CDMYyZ EB0jkkHTccgwWj+O8TShiags5/qavW/GhOG0slwRsmmVc1iBWtWvrayKb KJjKQe6NiGPFYV42BB8KidlBs92o3x7jLFdB/avUusLSKI5AtMqIILkKP g==; X-IronPort-AV: E=McAfee;i="6600,9927,11024"; a="6564367" X-IronPort-AV: E=Sophos;i="6.07,154,1708416000"; d="scan'208";a="6564367" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 19:17:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,154,1708416000"; d="scan'208";a="20489913" Received: from rpwilson-mobl.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.251.11.187]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 19:17:17 -0700 From: Rick Edgecombe To: Liam.Howlett@oracle.com, akpm@linux-foundation.org, bp@alien8.de, broonie@kernel.org, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, debug@rivosinc.com, hpa@zytor.com, keescook@chromium.org, kirill.shutemov@linux.intel.com, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, tglx@linutronix.de, x86@kernel.org Cc: rick.p.edgecombe@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v4 12/14] x86/mm: Implement HAVE_ARCH_UNMAPPED_AREA_VMFLAGS Date: Mon, 25 Mar 2024 19:16:54 -0700 Message-Id: <20240326021656.202649-13-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240326021656.202649-1-rick.p.edgecombe@intel.com> References: <20240326021656.202649-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 X-Stat-Signature: xhfuznjyug63qkwe6k4fdem1371fwj4m X-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RYoE3K+ fDmPoDEt9SBQSVO2zPK2uleXx0iNrYCUntrY1SmfJg8TJMqzTFURNDChDk0OGcxz2RcxxmL6z23S5GjwYNXWReD1BB7fm30Bv+1fu8bbNcue0tiqSGtAj48ICKsSRi/EBaZ7zdlK9SCFiqjsCmV5448VbzSc4PbAic0drVx01DUKe9Jnc2Fs47P29whYEf0lUktH/WFBqzP1T8cQYRVjED95/LLK8H+spin0v2IIyKCBlyMNNYjP+9NJrwg== 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: 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 long standing 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. Signed-off-by: Rick Edgecombe --- v3: - Commit log grammar v2: - Remove unnecessary added extern --- arch/x86/include/asm/pgtable_64.h | 1 + arch/x86/kernel/sys_x86_64.c | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h index 7e9db77231ac..3c4407271d08 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/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 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 96b9d29aead0..75966afb6251 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -113,8 +113,8 @@ static void find_start_end(unsigned long addr, unsigned long flags, } 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 addr, } 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 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, */ 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); +}