From patchwork Tue Dec 10 02:41:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13900713 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 B0136E7717D for ; Tue, 10 Dec 2024 02:42:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 093036B0101; Mon, 9 Dec 2024 21:41:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F35BC6B0103; Mon, 9 Dec 2024 21:41:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEA7E6B0104; Mon, 9 Dec 2024 21:41:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A01996B0101 for ; Mon, 9 Dec 2024 21:41:50 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 55491A0261 for ; Tue, 10 Dec 2024 02:41:50 +0000 (UTC) X-FDA: 82877498550.12.D8390BC Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf29.hostedemail.com (Postfix) with ESMTP id 996B612000B for ; Tue, 10 Dec 2024 02:41:18 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="N4/v351a"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3a6pXZwsKCGAI8JCQFQGLEFEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--kaleshsingh.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3a6pXZwsKCGAI8JCQFQGLEFEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--kaleshsingh.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733798488; a=rsa-sha256; cv=none; b=jR5iEd3v0VqNZkEgtxl6Vf+n/xOp2NWLkQvPUwnVaIoeSLiuVlZK2G1bs+xcx116ckdaW2 nZqdobYVTWR1EvmpDXXRGljcvrnE8qXReT8He2SUDt6u0mPpKQMcsJ/9Dx2Dzspm7Tks9/ EXmeMAFaxNAJjNQ92j5C028Ttwm8h8w= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="N4/v351a"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3a6pXZwsKCGAI8JCQFQGLEFEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--kaleshsingh.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3a6pXZwsKCGAI8JCQFQGLEFEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--kaleshsingh.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733798488; 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=lD1y5M/92bgTaY6KXagZAGAzcvbsf/5mzkOXcooW0ho=; b=WyESZTRt4NBWLz8Cz+SMUSZa2zxlOGhntIdSXjcFjeFkbV7ePUC/lXg7NQduyHgVGYcZbL bNPp5ZdA3x6DfoAKW9uhxHUZrKlXYVfc9Tg3TcW3hDiRDN/S19AChiQ79m1a1J41t9mvbs 1QL3VJN7ySmnSIWfTZdPUtAeep8FCJs= Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef909597d9so3594285a91.3 for ; Mon, 09 Dec 2024 18:41:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733798507; x=1734403307; 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=lD1y5M/92bgTaY6KXagZAGAzcvbsf/5mzkOXcooW0ho=; b=N4/v351aZ1sLYld2034x2pPb3NeZmt7xnQog8PemLt2xVD9ONdNccHYv3BgsbQzHrp 4hVwiMhOhYZHoGG3UIQYLH7tQ851WVBxp0GhNWmsyehHlbCje04raH0dZpKWOmCvNH21 XyIiz0YxSdrOBQxtdQkfIREgS9d6+B9mCN3HXI+Clt737Lo5OboDN4u9CgkOiQsTB8En UDrt0ZbtP7FBIiwol6+yzJxOTH0gEZCDI1km35LIiETQXs8SjSA7ENBePcecGqWdQaDQ 11LXYE1b/PymGpyK3iBVsrzDHhIKzpaWRJu49ILtE5/4aLpsnG7MfFuSrnbkgRgNo91L rOuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733798507; x=1734403307; 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=lD1y5M/92bgTaY6KXagZAGAzcvbsf/5mzkOXcooW0ho=; b=XouIn/SHQ3E16qbaeG9RcB1regWh95yXueZAyjRPE+wYnrKJmJtzTFk6U0aHcSZmwj 96d7IjfBHcM01VDtOWGaajlVKTaGl2tW9oUeAX03TAAmQVEeKEevzKpre18Rk2q2yf2/ cV2hBDCL9qA2qM0VlAwnpBLMOLEa/rKTtbcf3kwSz7nZHMy81m6Sx1sQDG/VXGUhISZU QL8kzH2ZnlrJ60VIpUrkA5YgslAhfEn1QNBDpkxxysOxSFG26/QsWzw9b9Nr6YiCKpYc 9QdjawlW5JohCc+J0l7eXWvkr8jVJZYmrSfBCt4GIzXrW/XOcxlV/ylF3MrtwgWxougo A+9A== X-Forwarded-Encrypted: i=1; AJvYcCVmWKybP13QyQXu8arssstxiK94+q0YwVJxTVcKBDJ1nT4QUR3bZIB+mHzD1ifsrggjI1d0wkoDJg==@kvack.org X-Gm-Message-State: AOJu0YxVoDHoIoOCTGcserFkrOLvJ8ZBJxP0UKZnshDxBf88Sfiavsik 7aXPwGPYggeNQkJfE/lPssJ7UobGhCpUInn0a7jfe3NO0CgEegJdoZMyECjzDxWIaos68F8o4tF 4oDdMK4U4H0bLQN2Uh8ttog== X-Google-Smtp-Source: AGHT+IEki7Ie5yO93OnRXKQVvZe4Tx9Zhtxszko37jcevo7YJZw67tf4QTtrn4drQ39DwCB2Qw8B/AwA/g2PTJdBkw== X-Received: from pjg15.prod.google.com ([2002:a17:90b:3f4f:b0:2e0:915d:d594]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4a:b0:2ee:f80c:6892 with SMTP id 98e67ed59e1d1-2efcf136579mr4227892a91.3.1733798507341; Mon, 09 Dec 2024 18:41:47 -0800 (PST) Date: Mon, 9 Dec 2024 18:41:15 -0800 In-Reply-To: <20241210024119.2488608-1-kaleshsingh@google.com> Mime-Version: 1.0 References: <20241210024119.2488608-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241210024119.2488608-14-kaleshsingh@google.com> Subject: [PATCH mm-unstable 13/17] mm: sparc64: 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 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: rspam04 X-Rspamd-Queue-Id: 996B612000B X-Stat-Signature: 5twuziur19c8qpjdqxpzshryeym3jqm8 X-Rspam-User: X-HE-Tag: 1733798478-692159 X-HE-Meta: U2FsdGVkX1+R0Q0JjlM8HV63NvD6b/ul1GGRXpIEYXmWAxaBC2tnQgTCe1wjPgt6M6DtIXV/k1nkmxu57ZrNZu8j7YTlgloYQMSV8NXaWm6ycYK8D6e5MKF7SfEl99JNaFAVkr+7iqoTnZiuJUCMNU0whVlK+D4sksZBru+9GHwJIUU/lL9XqDFdb/XTVp8Hq1CdUDwx8MqHdQITD/NcMxAWA/XAJxROfiitFKFZnaQwnx2eGiSagf7ExE0uN+OhHeFKtXwX3i7hlbDiVYRbroqoGpe4Im/jSWeZcvAr+NwYIdf9UizwffgkRa7GMXPAAmo2sqJqlIf1uxbPoyV2nRzkqkk0Ypv/ec6xhw2MJFBkivx/lRJPcgakHaqWDsARr0j9tkdCcbUxW/HSk2WM/f9zhLQp5stKWOz4cfEWjWxtL/NjGxNuhrdE3KzEN8KL3UzVz5ArYSxjwDQ2EPi2gv5JncZvwUvGSwjGoUM3D2yY3HiPHpSgD+IgyQEGAepbj7FUOercNWsrNg2QwBcIa6nhFfBXLvddrJu6fpN6S6QDVx9ayCZpviL9bhQjZDnoZa08Rk7B+79cm5jz7CI5I9HIgn38olO7ctxO7aMX8h2wgGQ3cwvLZw1CMC1f/TV6iXHM770/NAF7NvqCiFXfuhWIMLv4+IS/3283qz8ofbdmvovAljH7EN95JRcOujQloxMTo51jCjwXdiXr274sLzIbN8nuCgtF25ESVvPitpUBzAircgqW3MSoolRwYfCY5l/RUtH//uJfZO7ggru7LpSAbLVKWH7ha5oYF8f0PHXKRt2FSjqoNFdLmbXgGJdXSWWtnXvmDOFM96KhOvCB7Aszi+z7t87b4IXKTGN3IUfYfXfIevOimk9VnXB73KQDt5U9ZHdW84VufQGAH6VvDJ51maAvy087Kqf1VPmqAMxL2M/MYLILSWdO5p4sWBRlRleEsqVfA6lt6b/Yicx 3Y9MeavC UqwUUA3QDR+Uyl3dg6RaemF04WW0OBJHn/s/nYWuDOizYGFkZE10Hq8lQCga3Rm66ahaaB77n+x8xAUX2/cM4XegAWXQdKu7EBm6YC9RZ81m6VkbjIOUcX432rjxMx+vM7ndxeCgU55B/MIJCrGCxD6FrxzJaVOcjR/p/R+cfnmUok0ogNBYrwCpquwlECnlo/Bhmx6y1T4qKqCjZcOm2LP3m57re4zspQJInrcvr/kikxzmwcE9eVIfvrukTMf1ZRUu+HTNlbw1CWt6WMCYQhYn6Yr/aa8MJYg6ZMvzwKtyfXxvhsvN5Rb1lJyqpWzUzr/hJkF3kdod4MtpyFlhWb02kddELr8jK7Gx9QQr3XeL3N+L1Zh3vlhPM19NcTHxtsK/sI2C26voAeuRhtmh8is6l1lsjwC3FCmvJjJ1rOSy7N6sojyR8prqCrLrkudc/Cpw2nxdVrRcFSwn99YSu74hU+HO703+hXvBUDnCk19P7dnCkPRD0N9j9U0+Z2lH+7vm9jT/R7HVEXOu9S8llLXV9tWuaEnXyZkbX7uP8gmQqRGNHNtZe1Q1kuOC9tsahDUEMagKF+JF2QK2GbeMaF9nm096sl0eaKSo1m0ItCKJWWzT3TlBswnQ6XBePzJ//uYWd X-Bogosity: Ham, tests=bogofilter, spamicity=0.045073, 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 sparc64 arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT. This is a preparatory patch, no functional change is introduced. Signed-off-by: Kalesh Singh --- arch/sparc/include/asm/pgtable_64.h | 1 + arch/sparc/kernel/sys_sparc_64.c | 47 +++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h index 2b7f358762c1..f24a4eb2777b 100644 --- a/arch/sparc/include/asm/pgtable_64.h +++ b/arch/sparc/include/asm/pgtable_64.h @@ -1148,6 +1148,7 @@ static inline bool pte_access_permitted(pte_t pte, bool write) */ #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT /* We provide a special get_unmapped_area for framebuffer mmaps to try and use * the largest alignment possible such that larget PTEs can be used. diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index c5a284df7b41..a782696e98e0 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -98,10 +98,39 @@ static unsigned long get_align_mask(struct file *filp, unsigned long flags) return 0; } +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + unsigned long task_size = TASK_SIZE; + bool file_hugepage = false; + int do_color_align = 0; + + if (!addr) + return 0; + + if (filp && is_file_hugepages(filp)) + file_hugepage = true; + + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) + do_color_align = 1; + + if (test_thread_flag(TIF_32BIT)) + task_size = STACK_TOP32; + + if (unlikely(len > task_size || len >= VA_EXCLUDE_START)) + return 0; + + if (do_color_align) + addr = COLOR_ALIGN(addr, pgoff); + else + addr = PAGE_ALIGN(addr); + + return generic_mmap_hint(filp, addr, len, pgoff, flags); +} + unsigned long arch_get_unmapped_area(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; unsigned long task_size = TASK_SIZE; int do_color_align; struct vm_unmapped_area_info info = {}; @@ -129,17 +158,9 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align = 1; - if (addr) { - if (do_color_align) - addr = COLOR_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; info.length = len; info.low_limit = TASK_UNMAPPED_BASE;