From patchwork Mon Feb 26 19:09:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 13572729 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 C3064C48BF6 for ; Mon, 26 Feb 2024 19:10:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F4064401B7; Mon, 26 Feb 2024 14:10:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 07BB744017F; Mon, 26 Feb 2024 14:10:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE8F64401B7; Mon, 26 Feb 2024 14:10:06 -0500 (EST) 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 CB45F44017F for ; Mon, 26 Feb 2024 14:10:06 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 97CA91A0989 for ; Mon, 26 Feb 2024 19:10:06 +0000 (UTC) X-FDA: 81834895212.23.7F4BA19 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by imf16.hostedemail.com (Postfix) with ESMTP id A5013180022 for ; Mon, 26 Feb 2024 19:10:04 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=k1A88vYc; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf16.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 198.175.65.12 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708974604; 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=QpIDopAa6aJWE/FyfJUqodq2X8Jt1lCOE+G5EQZEW2I=; b=j4nrueIEr1b8rgqTUPIqpG9/BY9bMyCLmjWIpFH20bnkRckE6vBn0lQcbIa2V7YLFao3HM 6PmZItT7+8/hhe3y8fyREj6ptqP8z5WCySWp2KgWWpQFLe7HSasLnlvfRCyvpBSC/D2B9q /1iboWA1LTnIr+eKl8iACwVV0aU4i3I= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=k1A88vYc; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf16.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 198.175.65.12 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708974604; a=rsa-sha256; cv=none; b=xQFyIldQvy6kdQL7QhYHc57kJD8dSjL3iB4Uq03TV1ghwVaqsaExyYi1lDzfTGXhNKODGi xXNyaR94oJqZtrkVN+LAVVU27DrpMVmM/U1m/DcIfSqEQHRAXMuA8eBFAgf/t0DgDRWUq7 qi7qNW7MBERTwK2OwFgb/mOo9eVsV+E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708974605; x=1740510605; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K/25qnwR+QY0dPYdq2kDmPj6NmWSjdLBsEBSug4d6Ew=; b=k1A88vYcyjw6WJXT1de92wDZar6loS1AxV8YLoIv16Pp514N5h4ks4gV VupC4kF1yOrreFkc5xSd2JyW9hGvOqCqbIL6raTD5K1B+lkiJkjby3RVM hW6utWLD5isoT0WGW5no3u3kcuJHpDUOQQl6/LDB61M7jIf83MIgq/oGE 2bOFVi219AITYKBhv41YqYBpqO7ZBVQENU2CaRzwoAgc1FcOZdGwdNWfU 2bbCNiCalVwmhcApvu/wqD5It1gwu+LqRN6wTx+miXELWz8f4XuunxiiJ cOVoCbQPlgK2wHQVoZjkeXxIW0zwzY1tnySUSJdAx7sxCjEKI1IJ68SrB A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="14721416" X-IronPort-AV: E=Sophos;i="6.06,186,1705392000"; d="scan'208";a="14721416" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 11:10:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,186,1705392000"; d="scan'208";a="6911467" Received: from bdmirand-mobl.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.251.3.213]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 11:10:02 -0800 From: Rick Edgecombe To: Liam.Howlett@oracle.com, akpm@linux-foundation.org, debug@rivosinc.com, broonie@kernel.org, kirill.shutemov@linux.intel.com, keescook@chromium.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, luto@kernel.org, peterz@infradead.org, hpa@zytor.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: rick.p.edgecombe@intel.com Subject: [PATCH v2 7/9] x86/mm: Implement HAVE_ARCH_UNMAPPED_AREA_VMFLAGS Date: Mon, 26 Feb 2024 11:09:49 -0800 Message-Id: <20240226190951.3240433-8-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240226190951.3240433-1-rick.p.edgecombe@intel.com> References: <20240226190951.3240433-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: zenkc355t5jfxkjogc4oj115r69nw3fi X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A5013180022 X-HE-Tag: 1708974604-154642 X-HE-Meta: U2FsdGVkX1/e4jqlDlYFbcWnuqc917Bq/XPwfFddoS7eqexUc7Ujx/FhcGURjTPhbs8GQpgTEb+Kr8De1rDNJwYCDZKiVw1Aeu/a+oMaESfdpkIpPPsj7UxDnhKHNKx3JSACk5+9dSPtGBI2RNYTFHwL+LpnrdvC9ZDwfjYnihwAPUS9fc0UxKSphnv9ZCdj4uzXjSyopEDRp2bUKTGX9gRrT5xNYx68fSBDAhIcooSNiRr2j1B0BqUmTLDtOXSO1NLfoOtHFLBg1cT/NRRuU+humQL+wcG2I1CPuaK634SDr6pmDf+fFUp+NMWYco+FiE3qNrBBuCfTZ2RIcgOYE9i1ro6NPyb5NVcHc1yq3MbOk08peK8rHUuff9DEsFfpk3wMx2TlLr7MAgE/AzBJFGwun7ZYd6KxTYNZge5Eox7mqX4Ne5zVlsqMp+lyF3tRwaBvRKolS8TbolbQmyZ80uYRYsALLspHxiOKcPyWIqjFMTHFoAft0oGwMPpfC5uOaYImeFQWk7ZWF8NAcKM3HwJ20DRSbIKSyaoi2IzDDBOZQ2J07WcJqeEQla7OejEPMGf9X/tj+cWN9BPJ8oNHO/pECGO7bZpQfVp6XhA6Gq8hCj6HNzh9zv4YatxF9fM9r4a8xdyD5saBhogjS1nse8MkiwPAfdqThIzjzWRQVZXbFhBdA0Jhlm3pipUGDn2Yij3C5MIesO5adksVfsGTH4E8gW52vCXdN4wCMvl6Myek76XyvSvs5AZE24kYdkdyzWuHzTuQKvTivEZsiXZqudKbCKbUG3rMfJoXOnDgDpMsbmpoFZacy9BdfuzytU0c6EzqXIa4g+Nz213tVzb0BhN+1i+UWuNEhVA8okgp2ksoZ76h3CWBPQi0W9P8oLzk28X4dQPW8rg= 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 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 --- 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 a629b1b9f65a..eb09a11621ad 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 6e5d4fa5fc42..95cb9efc47fb 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; @@ -158,9 +158,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; @@ -230,3 +230,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); +}