From patchwork Wed Dec 11 23:27:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13904391 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 250E8E7717D for ; Wed, 11 Dec 2024 23:28:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 195E66B009B; Wed, 11 Dec 2024 18:28:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 11EE96B009C; Wed, 11 Dec 2024 18:28:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E15986B009D; Wed, 11 Dec 2024 18:28:14 -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 BBBBA6B009B for ; Wed, 11 Dec 2024 18:28:14 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 782E81414D7 for ; Wed, 11 Dec 2024 23:28:14 +0000 (UTC) X-FDA: 82884268110.21.56B6473 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf19.hostedemail.com (Postfix) with ESMTP id 936981A0007 for ; Wed, 11 Dec 2024 23:27:47 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=q1wf3zhf; spf=pass (imf19.hostedemail.com: domain of 3CyBaZwsKCPQgWhaodoejcdckkcha.Ykihejqt-iigrWYg.knc@flex--kaleshsingh.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3CyBaZwsKCPQgWhaodoejcdckkcha.Ykihejqt-iigrWYg.knc@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=1733959677; 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=SCptMPgkqno2A/YzE5Va18QE7zdNUHtEUd5zzpUozKw=; b=X9u8U3yLzuYh5aE8WCQmRD4FqTpc4TLZ4yoX8iqEClkrJsmIJ+pseRQz5uwh6sg3OY8w8X 9f3aUsToRwwjtjgR92dvwfepQw3UvIcJyHpEtxi9xJtjfrbEcrR8WX8Hk/q74zjv0na79t kvSQFJLk8l7ADKxxLL0RPokWbmkgeB4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733959677; a=rsa-sha256; cv=none; b=4aEFVCC7X19RRucTa8DNM6Um+a+MHTM5uq+wHz2IItHOFNG3UTKIeHWIQa2OXO2NfQ5Qsc JKbKk81WhAgcbGlE/V98ooxcK+MSrBNTgWVlh13tv6BO6rgVTshL+2HBoDV/wYwKKKlo18 odhyRKk90mUg4DmF2a+EImSY1a0lD7s= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=q1wf3zhf; spf=pass (imf19.hostedemail.com: domain of 3CyBaZwsKCPQgWhaodoejcdckkcha.Ykihejqt-iigrWYg.knc@flex--kaleshsingh.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3CyBaZwsKCPQgWhaodoejcdckkcha.Ykihejqt-iigrWYg.knc@flex--kaleshsingh.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7f72112de23so35412a12.1 for ; Wed, 11 Dec 2024 15:28:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959691; x=1734564491; 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=SCptMPgkqno2A/YzE5Va18QE7zdNUHtEUd5zzpUozKw=; b=q1wf3zhf1+78rRb57winL0ZqQqsqoEjGitAL/CQyAc7ZOhp9UYAd0vdps8ROg6/SNW P4XuplNqZMU8l3TYZFEWDkAQ6nEuJ4q8CE1LIVqRFIF3GOgKjOP4V20vj1Vgb2U5beqO 2cYz2y8LwIp21X4Qq64/iTkNcJtUvoWSEqNZ1ygBNJv7OJw3KjTSO/s/pYHj+pdWZwvB mk89icie2fq7pLAVmomLQK0mfVRR4tVRjp1yPlmOyhJE9AzXYILrrkQES4IvAOqWPcEd VUt5/WNTHcKu5AKmljT5gup5WvfvZkDjaip0OEtD2JFS5zYczX6VOggWfwYLlkHGZ0Te 9aUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959691; x=1734564491; 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=SCptMPgkqno2A/YzE5Va18QE7zdNUHtEUd5zzpUozKw=; b=iaP5TgQtQQuO1a9DrbTTD7txmJoQQtdgAqalIDX8KnZb3/p2aaQoU2eoW3nXGpEGdi X8AIYsTiad4kQCQWF90soewnodltKXiJIkkarTsQMZjI2u8FU9cmUi1pXnaY07VndXNr tGzJPAoeH5TEaGwNYMzWLBAB8vOsPeH7JKQHabuj3BRYpV+1T8a5Z+h1lisVdAqpCyyd /TWUyqLpOEARI9RI1hQvUvF98CX5cBrmWdyivsLMmbkbTCDZvd6jSDRjRXwJDZnuP6zh YSW4tZB3jX88txahJNYrPnucMBRqBUFE9wbMKDEOhF+duUeXYsCR+KmQ5WmD+7oIBsV3 egvQ== X-Forwarded-Encrypted: i=1; AJvYcCW0+AzYULLSrLaPp/+OxB9iEK+Rrfr7D8tecQJ6ZNykcTfc74ZOh6XNCBDhV3ddvHjlxuBcV71sjA==@kvack.org X-Gm-Message-State: AOJu0YwYlRvNGhTqIBltVeWPOh1NO2ib2TSJaP3LQphXUISydOLPR7J/ ilbmjANQe+uZEtNV+EYPd342FksAiE6dZpcqW2rF0VwYqca1t+8vE5zTuBRIYwrEAtOEwhPDSxL uZcmA06/zK4dUc/vhYJwlOQ== X-Google-Smtp-Source: AGHT+IFbvN9gPDak20G0G+YmM9pMBv8oAuiEUiRl+GFZxjvR/H2lZBtc+wP+WVSCEq90xAWHwKXzIcf2MC+rzJKWTA== X-Received: from pfxa2.prod.google.com ([2002:a05:6a00:1d02:b0:725:c7de:e052]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:e306:b0:1db:e922:9eaf with SMTP id adf61e73a8af0-1e1ceb2e4dfmr1374719637.27.1733959691453; Wed, 11 Dec 2024 15:28:11 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:45 -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-8-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 07/16] mm: loongarch: 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: rspam02 X-Rspamd-Queue-Id: 936981A0007 X-Stat-Signature: 3q8k1qcdz54p864o8dxojd66wjsb7fwm X-Rspam-User: X-HE-Tag: 1733959667-107423 X-HE-Meta: U2FsdGVkX1+SBAo3zcW6XOb4GVQkCSGZQMBm4as4ZUTQZzEcA4xrUdB2SBd+WJcKHU9OZmXVghZSpS8zjiaSCs/DkqNJGjOvhnWSQa+8z1mZAYPG25PtpDwxz0rPf2DO8uGRhU3CR4rnUFvqejrx9Eja+UoE3JckUpftDjgkBrRIG9t+9Q6xasfJGnTSGD3IKq+RbsXRpzEmT2Xp3vpKq8VAUzL+VO0l/dQexubYEU3R9o2u+0eG8LPzsxCLiMafx/aWOc+Sbm1K+meGFxadhEXOCNMWIUJx0gYcFpBJyKLxlNRND/jyJLnWvnGQ8NmvddcuqjLT0aY8q5wRdNf4brYgOeJXpKqzhTPExZvSAXzCTYQBXEpxpGfAfTVkWnyM3MjrNGNAOhQ8uPNrRO7pt/C9iJZDkV4OBXd1regtXmjV/7F5va7rx6a7NrtLVFGC36nxbC/KsAWOq48OLco4PcOXmjuyjyGj3WoInnSQDkWL6zJSqH7NcQ82jJ1s8mwrA87g5RV4dG3CqHIH3c9HbhFKEanH4SyW5qTQMym2Iu4xiGg3BXCdJPUoRE0PIaHPpr48REYDbQbOBYtxrN7qCf0ZjjopSa54aaDJAc8Sl3Fjof4MLqHSmO491W5+xrvkIsFzOWuBr5JLngI192NPpm3r1Llk3FHzkqTMbViZURl5fOjQ5ethgsyTbkQ8fMVme/VGoJHDW2BS+b2rtcqKWc3V6185EVo3/Uw3vJMlsIvJxQ/AAYZdTKMcxd6DAgIgq3BAzcNLf7Boml7K7XHgKlyF6ggiGN7xFbY5iURiXK4GolIGY1pjgf0MGuD07eDUreyLTkzotijgYchpHmk5C7/0zz0Jp/Ym8ey42Z/fLCUX1sSYz02fAt3U+R+5m+Z4jlQHMLXSr2EdvLs+zqZTYxlfoL+CrNAyKW66DEZnuPYkX/zQ7kXif2L6DiYC8Ernjw/6n/dsCB/zU768Tt0 aP4VRRfF fZ9nuzox67zZihv13Maz9CA9jYM1szM5ha0KmFqWhq+2ZBkx7mOTUFm4ABW7vWyD2vp29vG5npHgcKQpT8qwz7qlQXgWMSmMjH1bJPSFJFySGESBgIb4rkMLaTrsil6mc+/GhJQcMnonQyy0hAWvN62up16z8uU2kxeUiV+zF6pvAGRKSqxTT6tVndE0vGnTOlm2WbUs4evJYd0XFpuvTxapvdkc/lKNQKrH4PrThNdNnhL8aDMeJqRv9CMnPLseqBFnqcZDQWVA0uXsa/MKVYYGQvWv6iMkjQveKEW+kSl8cVGsYLQYmgR4oTeJSIsMuHhscfjhga6QNYPPkOt5Ckn+kHcZhcocGUr13JIhMjoGg8WRdtWI07PGg6uHf3Kp2oARa7pogzBQtlEDpcOgP4Lyf9PHmuJMIgZ4EygVrJWhgc5F6bX9my4t/dNevUBXQvZbA51WHysOAZE7Kz+j/npijOOoRVjF9A1snutnbEecUAKk7KMyyXS/Ub1+eZ+CcQZoWf04UCYUHcVubHxzpBVururWBbL61JEeDmNDj49hW7FXbj50kJSJxc20WnqM5tvHC8FpyXxH/4LKefFjA8VFOlm0zVGQOG04pgGLdPeagTIvFEZ81nVshp9pwuBZucYBM X-Bogosity: Ham, tests=bogofilter, spamicity=0.024781, 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 loongarch 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/loongarch/include/asm/pgtable.h | 1 + arch/loongarch/mm/mmap.c | 49 +++++++++++++++------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h index da346733a1da..326a6c4b7488 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -624,6 +624,7 @@ static inline long pmd_protnone(pmd_t pmd) */ #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT #endif /* !__ASSEMBLY__ */ diff --git a/arch/loongarch/mm/mmap.c b/arch/loongarch/mm/mmap.c index 914e82ff3f65..9e57bb27642f 100644 --- a/arch/loongarch/mm/mmap.c +++ b/arch/loongarch/mm/mmap.c @@ -17,15 +17,11 @@ enum mmap_allocation_direction {UP, DOWN}; -static unsigned long arch_get_unmapped_area_common(struct file *filp, - unsigned long addr0, unsigned long len, unsigned long pgoff, - unsigned long flags, enum mmap_allocation_direction dir) +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) { - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - unsigned long addr = addr0; - int do_color_align; - struct vm_unmapped_area_info info = {}; + bool do_color_align; if (unlikely(len > TASK_SIZE)) return -ENOMEM; @@ -45,22 +41,31 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, return addr; } - do_color_align = 0; - if (filp || (flags & MAP_SHARED)) - do_color_align = 1; + do_color_align = filp || (flags & MAP_SHARED); + + if (do_color_align) + addr = COLOUR_ALIGN(addr, pgoff); + else + addr = PAGE_ALIGN(addr); + + return generic_mmap_hint(filp, addr, len, pgoff, flags); +} + +static unsigned long arch_get_unmapped_area_common(struct file *filp, + unsigned long addr0, unsigned long len, unsigned long pgoff, + unsigned long flags, enum mmap_allocation_direction dir) +{ + struct mm_struct *mm = current->mm; + unsigned long addr = addr0; + bool do_color_align; + struct vm_unmapped_area_info info = {}; /* requesting a specific address */ - if (addr) { - if (do_color_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; - } + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; + + do_color_align = filp || (flags & MAP_SHARED); info.length = len; info.align_mask = do_color_align ? (PAGE_MASK & SHM_ALIGN_MASK) : 0;