From patchwork Tue Mar 12 22:28:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 13590678 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 5DC9FC54E58 for ; Tue, 12 Mar 2024 22:29:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 439658E002A; Tue, 12 Mar 2024 18:29:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C2118E0011; Tue, 12 Mar 2024 18:29:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23B5E8E002A; Tue, 12 Mar 2024 18:29:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0D6F78E0011 for ; Tue, 12 Mar 2024 18:29:15 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E21C81A052D for ; Tue, 12 Mar 2024 22:29:14 +0000 (UTC) X-FDA: 81889829028.19.9AD9690 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) by imf11.hostedemail.com (Postfix) with ESMTP id EAB094000C for ; Tue, 12 Mar 2024 22:29:12 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SCR2f9ux; spf=pass (imf11.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.198.163.15 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=1710282553; 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=6iy+vIqrqTw5SjEIJ96dh53Aug0F1GeH/F9ws4b/4NI=; b=1bWPCmoTxPyiGFpxl+sqXfhGs5ARUo4keTSn2zE1xfUlSu7zOazKeywJ88wHGC5nZRdSBK upgCKQK4VgUgiIcyy97e+xEnFqd8p6Om1MtJKLq7Ci+AMqFHIRD1P4ycerN4dbVGAUypjl +cxLuQknlDWBgop66zNlOVn4yevFsSA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710282553; a=rsa-sha256; cv=none; b=ldj50fbjI5ijC6c4seCfuYeTc19uNAd9G1siH+0BzwtjwKNNKUQO1mSl6lQy9Oj0iMFomc sZcBjDRUssFnetMVtQC40cb2xq9/+fXIouTOtRucwSNqqpRt5Hn4MU8HwtrsNHh/G41mds URGnTuABr5/TJ3teJtVWNe/us6BOZaE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SCR2f9ux; spf=pass (imf11.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.198.163.15 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=1710282553; x=1741818553; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CreGxe5/iXfUXls5YDaI9mwicpyrEDmmn8Wmlsjwro0=; b=SCR2f9uxobshduCzRUnlaQ8ha1N6rUoPYVhjpyxxRildd0yWAiD027ap kfueb3rmpndub8Z6w/8V+YiGn3Sj5zhcTaB1XnBXEPRTCi8ahwtONvRc5 jDRcMcB+D4/AzLjvWuD9njP7HQHhtxoXUvzV5pb/jNVPlnq4lc5LwjVij n8mBQnUHkNJGDJNdN4QPOYBS9ASxX1xzVq/2fuY26MNnMHZhEz5qnYCeU q4hsaPvY6RpIoHeb5//egJGdPfr9Soyswgu9qKtC0JV5duTx04fz9V6hP tC3Z5Lldn5ywBcmnzy9fnXeut5KyiRt9Z7FtP/ZIWrJmRWs0csNY3cMel Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11011"; a="5192059" X-IronPort-AV: E=Sophos;i="6.07,119,1708416000"; d="scan'208";a="5192059" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2024 15:29:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,119,1708416000"; d="scan'208";a="16356880" Received: from gargayus-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.255.231.196]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2024 15:29:04 -0700 From: Rick Edgecombe To: Liam.Howlett@oracle.com, akpm@linux-foundation.org, bp@alien8.de, broonie@kernel.org, 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, christophe.leroy@csgroup.eu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, rick.p.edgecombe@intel.com Subject: [PATCH v3 10/12] x86/mm: Implement HAVE_ARCH_UNMAPPED_AREA_VMFLAGS Date: Tue, 12 Mar 2024 15:28:41 -0700 Message-Id: <20240312222843.2505560-11-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240312222843.2505560-1-rick.p.edgecombe@intel.com> References: <20240312222843.2505560-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: EAB094000C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: f33brxo6bpasmczgpbwz6pimz9wpb86b X-HE-Tag: 1710282552-265915 X-HE-Meta: U2FsdGVkX1/imdtQnoPBSzeX65U5RrznMeEzZPvLZWrJNB/h3GoyvgelLhhFt/fIxe8MDWV5z0Msdl72BjJIuIJC433c3u5ASkeKETE9Q28OsSHWLNheybre5S9B3hEFcznTS8By6THeKod7ol3Wcd0ZwduyueG3LZeIo8KPatnAfvkZBRsg+xiW9JBa9+1OLd0HSJCYHnbb3A+AfcGubplB9kbgzYIV8tT+gYCY7vZh72gLL95H48pHxf5giih3HiFXQfwNLr2724ltIPEv/tkKpZyPzUtc/JKmkgxXkJhsnWOID5eSipdDhVPEViQ6x5Y5D4EpQ8jkxpyC+5K32zWzOehEospW1aRidcDQhClejT+g1+3qTkgWhnGKulIssQXuJH37CdYsS9a58X4CJGFL3o6bqyWrC99b4YpcxkdXnct9HoJrOOd/CfTxRdl4HUZWKzL4ugTU9gtCxhrx+aIvF/+opL3NU0OXyp986vPIoSd7Cxvr2F5kxsJSaXJbm3zvpM2rNbpCBmigVA4HUsL9fu04ZAiFPQ//SlJ+dgI6cDPpjnkkQ6wDtdpZQXz3nYarVxj83UEnNbS+K1r8gZMJZfEY3UIQVZmt4uJ6KfFrarNB8dMnzq6gaUSycEjU3uJ2XsTNoyPn+WEHlXm8sylTmYbQOIzUtUXekILD7BdmFVTvNJUXDYoUZ4c6P1sME4cFhZdmTfdnTV7zNDXE86YzP0CaaRe9UOqITzgUzaWHrl0ERi2S9aStfFWlui7Qc8HQMmPAz34NCJaJyT+QvfqsLwGxAe2OIffwRRFpxJxsq3cBsyNq4VCa/UvBHHbUb4psG6MTRrrY2c2vlCJyWwTNqe+kXRyxb0+h/S0A6qgvY4/n3XceVKiaZ2aT9RriqMPqSR2G9BY= 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 24af25b1551a..13dcaf436efd 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -244,6 +244,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 b3278e4f7e59..d6fbc4dd08ef 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -120,8 +120,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; @@ -156,9 +156,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; @@ -227,3 +227,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); +}