From patchwork Wed Dec 11 23:27:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13904387 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 6BA42E7717D for ; Wed, 11 Dec 2024 23:28:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 874586B0092; Wed, 11 Dec 2024 18:28:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 820866B0093; Wed, 11 Dec 2024 18:28:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 673D86B0095; Wed, 11 Dec 2024 18:28:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4283C6B0092 for ; Wed, 11 Dec 2024 18:28:07 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E18931411BA for ; Wed, 11 Dec 2024 23:28:06 +0000 (UTC) X-FDA: 82884267648.06.959A3F8 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf09.hostedemail.com (Postfix) with ESMTP id 0059D140004 for ; Wed, 11 Dec 2024 23:27:48 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=uVavN67A; spf=pass (imf09.hostedemail.com: domain of 3AyBaZwsKCOwYOZSgVgWbUVUccUZS.QcaZWbil-aaYjOQY.cfU@flex--kaleshsingh.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3AyBaZwsKCOwYOZSgVgWbUVUccUZS.QcaZWbil-aaYjOQY.cfU@flex--kaleshsingh.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733959674; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=t+2SZZ0hfvfE1wB/PVG8ptvYr9aJVJPmVtSy9l3KX7E=; b=ov+Dp2D5HA0VBxqJ62Mqd9mfULVlaq1iM0dj6bJICNMBI5VnyNk8k+3Sh99q+w3nHDhjO+ HVOQuVYcO+q8ZnZ9jY8qpYpadq8lfRmfxioSlkz4o+rIegMwa+w58zLJvcKOWApmJunCbb lMOM6Zsc2Ri6sAF9cAV71WPAqBF+Z2s= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=uVavN67A; spf=pass (imf09.hostedemail.com: domain of 3AyBaZwsKCOwYOZSgVgWbUVUccUZS.QcaZWbil-aaYjOQY.cfU@flex--kaleshsingh.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3AyBaZwsKCOwYOZSgVgWbUVUccUZS.QcaZWbil-aaYjOQY.cfU@flex--kaleshsingh.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733959674; a=rsa-sha256; cv=none; b=i9Cz4LOYVWbOZDqGasMcryAQ0PCdWSzmSrLyrxKuRiZ3/j8nqJA6YPot/ujr7dpA1sRS3h rNjNBJTdR2MT8ByawC4lNe1pDZNFDob1Vmu6JHoHxCqALK17waeBSqhLISDeGCmapwIDgs IdH/DX6l3kar8lSWKoofUSVD5KsYtQw= Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7c6b192a39bso34117a12.2 for ; Wed, 11 Dec 2024 15:28:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959684; x=1734564484; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=t+2SZZ0hfvfE1wB/PVG8ptvYr9aJVJPmVtSy9l3KX7E=; b=uVavN67ALqElmzePW3x0AuwEFneXBtnP3Jkq9ktYenkZP2STJIaOtexMoBhR8Xqiqu x6kK+H2MfxMRE1GfKySLOt/xbSlm+g2u/OilVmy1SmsmZyqzlfMDt6amjVsyqBQkKOxG hW0Rd1Xgd8YY2ytUgyRm8FDwQg4bLdgpIoU1m5Jhc7sCYtyuitzz/Dozlw+wW1Carv0D I3nIxl3Ac0dYx6BPO/bCIaU0oylbXCL9lFXMTuEISdlbsZxMEvFY/iXr0xSgJvwVR7Zp vSJNP252mB6VcgyJjSVz/sSGQkELAwlZw5skPfB99AxbeDqhRN6tk5T8M0dSk6LT/CxP 1k3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959684; x=1734564484; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t+2SZZ0hfvfE1wB/PVG8ptvYr9aJVJPmVtSy9l3KX7E=; b=LeePajWnE0AR8IlgSU20RpM2jR6zMn+3vhHxyzH6HPJldMIoPcFAemLtGHleWhG6Om jIYfaOF+y/muRwykZMzFMW4yXD3V2slHeXxZLwXxcxZOerVPceknufk/kNQro1RmGAO8 7ukIDn1hH4nIMSNA5/OefVfF9hNab8lABDuuRNlLjCrvXNLQ5+LKrFSOhC83PgkSi6HS OTG1TUHcDg8ecg31LiNQDEXyihP9NLgLK1BcAxoh4DTgiKmS71PHssDUnZbKmpEumFej IE0N8vIel3FcuooefZxRPFLPNwiwaTU8iYOCY90Hg5ytUcV47DvZ80bgfCQeC00+mxXs lc/g== X-Forwarded-Encrypted: i=1; AJvYcCXc24eIGrxMGSHzEXTx5dzU5Og60IMkH7XBE+R3gZAWoJKeJdIi64S3j9D8FLVtE93lWO/3rU7lGA==@kvack.org X-Gm-Message-State: AOJu0Yx8/DNkkyEcaT+jgnGDmXS7Hv384BUJa/2drLBR/hDarEtguryu /IOp+QEJoHsKxdS2dZwdgoaFnaKihQrkKXgECCAkWaCXwmD4Ois0Mv3t4+TOLua52SJ67Yk/QDj uiYGqaJ5EQrVXQSfphFVN8A== X-Google-Smtp-Source: AGHT+IE/Z/5jS7mczW6P1buMx2K0ifA2tKb3E5Z4r/r+p5Ssl9msAfOzZLWtpmRsmVcD4OTpdOSyZZHLgcfY4EVEyg== X-Received: from pfxa22.prod.google.com ([2002:a05:6a00:1d16:b0:725:db2d:370e]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:43ac:b0:1e1:9fef:e974 with SMTP id adf61e73a8af0-1e1ceb34d58mr1526584637.24.1733959683818; Wed, 11 Dec 2024 15:28:03 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:41 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-4-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 03/16] mm: arm: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-Rspamd-Queue-Id: 0059D140004 X-Stat-Signature: yysao83wgriii8sf7113jbtkf3nxing4 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1733959668-203520 X-HE-Meta: U2FsdGVkX1+UF7lCmMdXxjdNnZr0jriy4CDBZVf8bBC13Dfe5nE/WJj8MOPkII+cvB3iWs+5pHowR0noUThfWOaFW6n0cPHLV7grWlXgqiwV860Nc1XxahWu1qdVzJ21Qsyb6A5iK0pXJ56nEK3fsdH54lG/Ha5r/6bItNTGW0gflZXWNZ/tLc8piRyBG/HvcIOyl0WaGXTC5pBNxueVv+K1Hi9l6rKeRkvtYrd18yvcdwLVqKQVTE4U9LX37NUNXJ2ZsGNsZcx0v5Zv/W1aj0Evqi3aAJJAu3iAoQB24UEWpJFEdxxo/zTktqanteahz+EchQpQXbcUETdEx75AXNidmw1NyPscgMJ9KnA90p6V9NRyLabyvHsP1mIkMZW7HjpYm5TcL7JrBglO8R0DieEfPf8t8CWwZ/Z0JyrTUloIgwUAZSyvYzaxN/VTKZZ15cjKHML7Q3IfhVVXLAPtwssVbOlPr7AGpC75chVrA5tjEgYJMqlmDhc87QCMqmWwPUZFXmGAkvB7T+Ljk06aH8PFiBnjUo9AdlGECIFnR6UPriZIkjEAjrowtCSYxzQUYGDC9vNvuoDXdUjyH4aCRXafIqnLoA4wHIdOpypcqslO01HLXnY+gx9QzEX3etgPS7f5VKjwq3525UOyxU8axeOmqJxyZFaWNkWDx/BVGhElJs9L11Xc5BUxMJfWJjGPSibwOINJCOsMXjT4Z938m1rwvidi2Sp0Ok0OeFybvLi0JkYsm7PPF1L2OtFvscrxMotVd5ro4L4xProPe1VufnUBUpKqM+tEsCdbZiWAN5dS+sOqyqaVl42d3fU6pJzoK/4hP6BBd4A6Z6K3kzTYqRhKxSF9agmX1rkl7V3bH2Pr5k6CfjXWGw/VtgcxH+vcpfwCid9iRlvM9kfXJAMckXgTtQ+LLoWvvZ8gGXPxBSFf1gaeDkV02uyxNIJ4/raAbjQC1zXuFWvgG/CaWyv rW8PN7W9 dvRWptyqOJcv59gx5uvfsZ+zB+Kk1EV0DomMt1gQYohd7me4NCcW/wDDSR8UPhldW1NY7gi42ckHEPXuRz+LSNkjW2dTvSGpMdy4vfsQJPby9w8z46+tXuK8hFMFZT/X7WJcGcqD/me2fygf0UShja/R6oSnkbKygyKz8pNQGLzGyqFq6esJieeLkx8sgmmfhRkEQwXGIoIcLJ3y5A5/9KEhkjlfp1drKrLrg/jdEwPEOpMolVxhvaVlpmoV5Pgh2ueM5P/jzjza1dsPXWWxQh0LPtL0kH7gE+PBIKzMBBZgVDqhmZRp2C+rhEqpXriuBUDgL4CexSD7Jgh+miG3i2e51eU5l86eRJgIRSW0v+N1Drnf/CzrnF3chF3sIeg5bhOZyYY4YI2TeZutE6fA2uIdUSQrizgha2xExjAzLy6we+fqx/GSVRYjZj4ajjoKtitl5Zf89eQCRYkQEDE+qqNuNkG/q1Klr/jrnuQtnHDdQeBcYisAxOClW0LyeiDAXAdJnR5TiVpJH4uYQsXRKugzcSKi7B+8HkuVgXfsfDnHl/bJQqen1WaI65CNzcTviFVmty0v3BREpYRxsekrmo9IKO+/ZHvgesoOQEcf+CKfUnDIRk+XozM2Kjsqqf5ffcD+e X-Bogosity: Ham, tests=bogofilter, spamicity=0.013676, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Introduce arm arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT. This is a preparatory patch, no functional change is introduced. Signed-off-by: Kalesh Singh --- Changes in v2: - MAP_FIXED case is also handled in arch_mmap_hint() since this is just a special case of the hint addr being "enforced", per Yang Shi. - Consolidate error handling in arch_mmap_hint(). arch/arm/include/asm/pgtable.h | 1 + arch/arm/mm/mmap.c | 107 ++++++++++++++------------------- 2 files changed, 46 insertions(+), 62 deletions(-) diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index be91e376df79..1433b3ff4caa 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -330,6 +330,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) */ #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT #endif /* !__ASSEMBLY__ */ diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index 3dbb383c26d5..15e7e4348af7 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c @@ -17,6 +17,41 @@ ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \ (((pgoff)< TASK_SIZE) + return -ENOMEM; + + /* + * We enforce the MAP_FIXED case. + */ + if (flags & MAP_FIXED) { + if (aliasing && flags & MAP_SHARED && + (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) + return -EINVAL; + return addr; + } + + /* + * We only need to do colour alignment if either the I or D + * caches alias. + */ + do_align = aliasing && (filp || (flags & MAP_SHARED)); + + if (do_align) + addr = COLOUR_ALIGN(addr, pgoff); + else + addr = PAGE_ALIGN(addr); + + return generic_mmap_hint(filp, addr, len, pgoff, flags); +} + /* * We need to ensure that shared mappings are correctly aligned to * avoid aliasing issues with VIPT caches. We need to ensure that @@ -32,42 +67,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long flags, vm_flags_t vm_flags) { struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - int do_align = 0; - int aliasing = cache_is_vipt_aliasing(); struct vm_unmapped_area_info info = {}; + bool aliasing = cache_is_vipt_aliasing(); + bool do_align; - /* - * We only need to do colour alignment if either the I or D - * caches alias. - */ - if (aliasing) - do_align = filp || (flags & MAP_SHARED); - - /* - * We enforce the MAP_FIXED case. - */ - if (flags & MAP_FIXED) { - if (aliasing && flags & MAP_SHARED && - (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) - return -EINVAL; + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - } - - if (len > TASK_SIZE) - return -ENOMEM; - if (addr) { - if (do_align) - addr = COLOUR_ALIGN(addr, pgoff); - else - addr = PAGE_ALIGN(addr); - - vma = find_vma(mm, addr); - if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } + do_align = aliasing && (filp || (flags & MAP_SHARED)); info.length = len; info.low_limit = mm->mmap_base; @@ -82,42 +90,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, const unsigned long len, const unsigned long pgoff, const unsigned long flags, vm_flags_t vm_flags) { - struct vm_area_struct *vma; struct mm_struct *mm = current->mm; unsigned long addr = addr0; - int do_align = 0; - int aliasing = cache_is_vipt_aliasing(); struct vm_unmapped_area_info info = {}; + bool aliasing = cache_is_vipt_aliasing(); + bool do_align; - /* - * We only need to do colour alignment if either the I or D - * caches alias. - */ - if (aliasing) - do_align = filp || (flags & MAP_SHARED); - - /* requested length too big for entire address space */ - if (len > TASK_SIZE) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (aliasing && flags & MAP_SHARED && - (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) - return -EINVAL; + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - } - /* requesting a specific address */ - if (addr) { - if (do_align) - addr = COLOUR_ALIGN(addr, pgoff); - else - addr = PAGE_ALIGN(addr); - vma = find_vma(mm, addr); - if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } + do_align = aliasing && (filp || (flags & MAP_SHARED)); info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len;