From patchwork Wed Dec 11 23:27:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13904390 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 59AADE77182 for ; Wed, 11 Dec 2024 23:28:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B8736B0099; Wed, 11 Dec 2024 18:28:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 366DB6B009A; Wed, 11 Dec 2024 18:28:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 208D56B009B; Wed, 11 Dec 2024 18:28:13 -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 EBBB56B0099 for ; Wed, 11 Dec 2024 18:28:12 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 97D4C16150C for ; Wed, 11 Dec 2024 23:28:12 +0000 (UTC) X-FDA: 82884267942.07.A9B7112 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf16.hostedemail.com (Postfix) with ESMTP id A3CCE18000D for ; Wed, 11 Dec 2024 23:27:46 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=hB7jWjBj; spf=pass (imf16.hostedemail.com: domain of 3CSBaZwsKCPIeUfYmbmchabaiiafY.Wigfchor-ggepUWe.ila@flex--kaleshsingh.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3CSBaZwsKCPIeUfYmbmchabaiiafY.Wigfchor-ggepUWe.ila@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=My9IlOPq9ns5P/NZxzKqYlKU2U5PkE8SqDXKTXIHc1k=; b=YEMVRjeDkUd6PvC4XXuYc2cCIU7jOeYazK6nGySRI4FcsUu9HjeQ6/RlK1EVXR2dOsj5IU 8555T6qeinHSD/St7mem7HgOhafIYTXexytPg1JKM18aGXrK2ZGVrZxmW02UZzppptiM7a FoXbDr/7nqqK6pskb6g7MKEcUeIe7Z8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=hB7jWjBj; spf=pass (imf16.hostedemail.com: domain of 3CSBaZwsKCPIeUfYmbmchabaiiafY.Wigfchor-ggepUWe.ila@flex--kaleshsingh.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3CSBaZwsKCPIeUfYmbmchabaiiafY.Wigfchor-ggepUWe.ila@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=1y4fTS/SNDCOcprm+s6WWl8lB/rDHnFRXkvZ2X82QYj/K2N6yRHLwBmmWxwUqZvgJ9sPoc Ds/5hFpfmwNOGSfLAuVX0F9YJ8tgGpYxa4pzOoq/zVTWGZNB4s/OvVzagUP+PV6mKQq+53 Ekn0sJkoVsa4UuHsbJKs4mkeQ6q1ZHc= Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-726047a4bd1so24820b3a.3 for ; Wed, 11 Dec 2024 15:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959689; x=1734564489; 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=My9IlOPq9ns5P/NZxzKqYlKU2U5PkE8SqDXKTXIHc1k=; b=hB7jWjBjZaL6gFsAQ7xm4BJgTlyXlgLogITZIxlUmNAsXkYvwIC9esLOrh5pkoSrnN 2mcTx2lwiLtOP5k68pRWFjxM2r/U2xK2lMEI0suFrhzMm5NZqAhTV7eMIb05BXRWoTu6 MS2/4qAV6Yon3MKzCeRkNSfZrtSbWr2wwOnLDF5SKV91nS8Br0U+DxHH8YppsILk6ZLF Xxo9uKwZCLvI8id8evaVZYqGlYglGFCeIayuRV8MuxjKgTx9DcmFeplink6tZUeelfBS ISzicscBPm1TUPhyzXxbptdpJsZpWPM6A6XxsslKIgLTBU9M0ZJU289c1ec0KH6qFYf2 qLCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959689; x=1734564489; 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=My9IlOPq9ns5P/NZxzKqYlKU2U5PkE8SqDXKTXIHc1k=; b=AcZe60EDQOdk7+DZ3eEoQ5CJjv25EMZGKlQJOoH203A3U3++2AJzhL5mTaGo1G2rq7 YEnmCl7CVevwHtzzVrA03o35OAaIz0Q+SMBA7sC75LsdaQWLsN4uyHshLwzmc/U2wutb vlC1L0H4NlviwcfIr4lbMe6ojMTsdazwvrMqMb74b94iab4evxPSZ29zSJgFVUlQPN0G NPYIDsrWyeXfguCTvZsjwE7+i75w0OOkNyLhjq/pKiNgdxfRjuljEA3bAqzP/jAbIXi+ r8ZMTCQzVQYw0dJjPUod+ewf/P8cz0GgWJS77FfnAoM/Dm4n/+bPyzyQyNFZaQCKugZN WINQ== X-Forwarded-Encrypted: i=1; AJvYcCVXQ0isWR6NbiMiCOcH4B6SQdKz+J61YtitgeGPE01HIUd43faZVLI5pDTSH+B8UoqXeTMWNF7APg==@kvack.org X-Gm-Message-State: AOJu0YwSDyjVozCaIufH5eFj72R2ZFnI6zZiURGjuj7j0P/vcsbquAss KaQSIJMv4wknXe19JPdmGDT/xQZpFeohvRuvN3rBAcSo8urnWuwqu0PHtPVjP1E1gROBIjNlto3 6HmaCB5NPZcHSyNSkDIUIZw== X-Google-Smtp-Source: AGHT+IHgv+hz6lUV53h1smjsDXGUMrAdu+yMyNI0Y1qN6skLJAQw6jBsC8TmY8m6/oNaMxzzcfOLndyqCxWrzR4uSQ== X-Received: from pgbee13.prod.google.com ([2002:a05:6a02:458d:b0:7fd:4d08:df94]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7890:b0:1db:e40d:5f89 with SMTP id adf61e73a8af0-1e1cebb5277mr1761320637.28.1733959689528; Wed, 11 Dec 2024 15:28:09 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:44 -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-7-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 06/16] mm: csky: 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-Server: rspam05 X-Stat-Signature: aoobzd4nuqgz8jftsffb1n6q11c1bbrw X-Rspamd-Queue-Id: A3CCE18000D X-Rspam-User: X-HE-Tag: 1733959666-501559 X-HE-Meta: U2FsdGVkX1+Ffqbd8Sja1wo9zIEvMPWRBvTAWpUhu89UL7xn++bO4e/p391JJikdcTMhgnp7NG8saygPvUz4z7uVReDkhlbr5ES2FB9nUHYTvj9X6/sfdkdjMGNh1YWa+3B2K9+nTSfvLJxMnqDMtafYSe4dJVx8Gf/nEqUIakxclntvK2Km6iWwDVd0l8nWGI0lNCjgMJgInFgnxgi93dqmM5Tp1tRbbtqn/5a0xV229Fy21ehWklpkJiJYuep4/m9d+jqFfCbbcf9PpjzkJI4Rpj/vVN2NugN8Sl2voY0vpc1PYTPg60T0VQr+Yu74IMWXNy7yB+JxYCsLguX5Bvk0cK99l7evm35mrYPMe6G2A4VnrKaSyLSvSFLNdqxM7BgiDkAb3xX9F+wRXnnWOZIPFpuhF+L28CScyn0JHBR0d0C35res/iSjIyy+5jT0obstNPhxh9q3inPQfA05z8bKgjqD+8fKu6YOBCdcJAVk6CQ+2Z0BOnw0a37uE2twEE5Oc22ChH5q9uhj1APadNWmTo6NVd/MJrsSKXHHRo23JkUmcAfbveY8RAqHXLVBXCJmF/Vcri8UrTdFaGwoVhqejx+nEcUBv34TjdXRMkA+7+4q1UyrlYAdlWxGcwAJfl1qvrGYB834TnD6D6wcXqJzrwPMkd3lTO+XDHS5SjiVsCpZ5qf13MV43mCKvnV1v9FZ7nxKNwpLu+LYsjfbYUQMN+kLMMR1FGLkll/xC4A+7vUzZgiIKxxh1kodq0uehd2/7Nz7LAjFTvFfS60F/TMyPV57PZXtDuPQcir/c1j3wTgv5EddFKOLhFhBUFqWgN/dT/szv9ZwZe4HosCxAgEg35WIT3RR6wBNDf2EC9+fk5m112wijzjlyHZoIQeBGpWJ1jybpibWXvpgpjaS3uUf8FFCHUsaG3TJLQH9QZJUzw4767IH47SMcmm9rDGqdIafwUiIs5djJ5ySLTE jz3ES/iW Xpc6wL1enpWJMTJe9B93roWgonPULMEtciRPJc28HpQNpmn5XOFAotBUj956IWZu9/rUNkfLe0yiblLbnbJSEGHnC9HJKH/9h5Bv0u8xqvAsHVxnkALJ+vsf1LOGfUIDBiwQybvkfUnlFWAFv35d+Jc46JCNTPaiKqSk1tsVuUiFoH+bYcRJ40oei6cWOMUSOXQKfh1ofSyvdpnm4s0WulOi/LdTjguWnMS4EpAP7eD9Qj6fkSzIaxFTKSLlJqKdTVHLqNcnlC6bAv5SmDkXnNiPItZX1XixAhbVtN4TK3uHcgboZbSj7JSyDIEvv9zkW0LBwtSMBvzMRk2WJmfOD2Ni1I4QzQFvQi9jjSGKi+83Vn58UNVgba1SQES7olWoHAxDlJGEAh31LNy+2TSK2d7HG/5/nVvcaD3M03K0OAI6eJQRWpHKTeHNDgWjGBZoo0A5DCJLZPW4C18VVOIpb8Zh4nRV65ijOIqfLsrefIgCIBB5+USQYRLOx/MT28w0pMKqfcmG+WtMwFLp2R1sXyT61tfU68mSx779Fzo2JH6vkNFA8/dwProcRw91oO8WN2cZdJ8WRqa+0MtwnxTTq5EpHz4gOkjkFIKbgL7/4cP4I5G6qNvwkzL7CBaZKz/A/zfQz X-Bogosity: Ham, tests=bogofilter, spamicity=0.345518, 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 csky 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/csky/abiv1/inc/abi/pgtable-bits.h | 1 + arch/csky/abiv1/mmap.c | 68 ++++++++++++++------------ 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/arch/csky/abiv1/inc/abi/pgtable-bits.h b/arch/csky/abiv1/inc/abi/pgtable-bits.h index ae7a2f76dd42..c346a9fcb522 100644 --- a/arch/csky/abiv1/inc/abi/pgtable-bits.h +++ b/arch/csky/abiv1/inc/abi/pgtable-bits.h @@ -51,5 +51,6 @@ ((offset) << 10)}) #define HAVE_ARCH_UNMAPPED_AREA +#define HAVE_ARCH_MMAP_HINT #endif /* __ASM_CSKY_PGTABLE_BITS_H */ diff --git a/arch/csky/abiv1/mmap.c b/arch/csky/abiv1/mmap.c index 1047865e82a9..0c5c51a081e4 100644 --- a/arch/csky/abiv1/mmap.c +++ b/arch/csky/abiv1/mmap.c @@ -13,6 +13,39 @@ ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \ (((pgoff)< TASK_SIZE) + return -ENOMEM; + + /* + * We only need to do colour alignment if either the I or D + * caches alias. + */ + do_align = filp || (flags & MAP_SHARED); + + /* + * We enforce the MAP_FIXED case. + */ + if (flags & MAP_FIXED) { + if (flags & MAP_SHARED && + (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) + return -EINVAL; + return addr; + } + + 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 @@ -27,8 +60,7 @@ 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; + bool do_align; struct vm_unmapped_area_info info = { .length = len, .low_limit = mm->mmap_base, @@ -36,37 +68,11 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, .align_offset = pgoff << PAGE_SHIFT }; - /* - * We only need to do colour alignment if either the I or D - * caches alias. - */ - do_align = filp || (flags & MAP_SHARED); - - /* - * We enforce the MAP_FIXED case. - */ - if (flags & MAP_FIXED) { - if (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 = filp || (flags & MAP_SHARED); info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; return vm_unmapped_area(&info); }