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: 13900771 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D2022E7717D for ; Tue, 10 Dec 2024 02:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lD1y5M/92bgTaY6KXagZAGAzcvbsf/5mzkOXcooW0ho=; b=V2Q8Yowh2q6qzWiz8ySmLuJAQA R+7dglzYBBuXWJ7N1g78Cl3C26NWk0gZJ8g62nF+SCGweHrcakLklJfdMUt33cEqRtFT3oeWFRDLb +CO6H8ZT9L0VnkfM1Hq+tI2A581Osrg/UcqfICZIZhbRHN8fDE25hHV2JznDmfZ+KL6HzxtSQjxE0 ymdl2Mm4eReMwKAXX54EnC9HzdbTINdYt/R4aBCD2vINH0+0k04uWzOlsxEG53qVHeAGtp68KVju2 SAgE/ICct9PSlfidMnhHFtu3qaQ5wTlUjmfKxp0TtxqcsE3+xyTbeOnE/Y02Jax0lq3/pjPpiSevC 5g+2YT7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKqOy-0000000A2pC-1y2B; Tue, 10 Dec 2024 02:55:08 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKqC4-00000009zos-1iCn for linux-arm-kernel@lists.infradead.org; Tue, 10 Dec 2024 02:41:49 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2ef909597d9so3594289a91.3 for ; Mon, 09 Dec 2024 18:41:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733798507; x=1734403307; darn=lists.infradead.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=u3svTV5LhfvDuW3Db6wUpLFXfiqh51qRge86S417ihdlJ2Fqu3Qb/PAmLZoDhZIAmN RFIIOdR/tUiGnBn6KRK9cWk+xXYT6ygDumymzwnv8mwYkghfUKuQgGyVlzwtW8hKQUVq YOE7LsabLuBFC26uiXwX6lf8sw70JIzZB3X3JmgKZOcU5JFyFClE/pZUmqy8Xdt929t/ R5jN4+aCeJqtfzDscE53nTaTIulGYUUEnrI/sJzvsGZvL0ktneEA80gogl6LxQExC27a 5JaXl3In5veRs60/FBmFTFph3KiS+o3ngiamX6pbu0wTjlc/reo5wKyZWj1AvQHhodUf 862g== 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=isCFAST8gwm9ZJEVMzCZp30njpxwbuELruivAeyT6li7eRjtViCMnGs4zE/5+bQI33 AIw34jPVU0obWL+mrrB4Mw/hu4VfE8jmw/MyjWKxP3KA0wD5uMGqYng+VelIjgKpEqWW 0O5AkM7666/+Ob4qtd9FkrCH/GhSUwkMaZTS+83T8fZZRHLQ6DWndkTrJhR05sfK57fP 5wdcVZXLThlU9ricUikgxKzm3q+rGtfPS6B5qpHf1vU8Ejit2I+OBuYpOv0H16Kf3Y+q qRCZJWeHyWjy1kHZrdFMyQ50KW9G+1lo4MZ4stRu7fMnRxn0R4PpxA/q7up+vbHfN9wW aEzg== X-Forwarded-Encrypted: i=1; AJvYcCVEIu37tp22dZ6PSPMMsxrOL/LLDhDw4femJ8yaw8ePaedsizkiBMTHzCyoCtCK7PepmM6SDSDQfp8eyCIes1rH@lists.infradead.org X-Gm-Message-State: AOJu0YySPqwQUTZna2zSmFRAPd15/qlRMTHd4hRmXXNMaLGqRg/v/bwD 29OtfiT+lvNRMFMacgZtrmTnxicNxQDJID+xME2aB1aGNlxrT7pAFFVeRP4cI9iKiILnxGAvxd0 R+E5J1dw3pyCxYxynuDw22Q== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241209_184148_445264_84E65D52 X-CRM114-Status: GOOD ( 13.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;