From patchwork Tue Dec 10 02:41:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13900766 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 83A2BE77180 for ; Tue, 10 Dec 2024 02:50:03 +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=S88A34UwW99gwo3FHZNSbMidEba+jodHLuTGE22Alms=; b=uXaxEIQNYQ/dh4/8piLsrci7dG eYu1bIZtfoIK09xEIyljpJtSUyiIv9WQ5LIKqpWvlA9fZdrmRnlTnUF+v3EtM6cT/HO3aIQ960ZvY chtzNhUQd9I/Ej5n8J2HmIfvFpfkGaKEdLQ3XDZr83DLGE9nNMCU4c9i3EIo2SSgm55HhIpik9f2b UDvxaNt0GUrF9CADujNEsgw9BdGKwfdgZavjHXF1Ez1IvN5HqAd/OYvPyDBYOQ28TUgG/CRw+IH/h rK0CHyFJU28R1/aDfobKGpVbVMvCi3ZZx698J0FNU55e8P9tVlhHWZkPXWgFXDrEMrNk/nWkms8YC R6gsNfQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKqJt-0000000A243-2E7R; Tue, 10 Dec 2024 02:49:53 +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 1tKqBt-00000009zdx-37Gh for linux-arm-kernel@lists.infradead.org; Tue, 10 Dec 2024 02:41:41 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2ef728e36d5so3395141a91.3 for ; Mon, 09 Dec 2024 18:41:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733798496; x=1734403296; 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=S88A34UwW99gwo3FHZNSbMidEba+jodHLuTGE22Alms=; b=MsDXMW9sbfiCRWVxsROjW45qr95pRpqcwQiH5FarItWs/jSFCC97xmiMybr6Juabqj 8FUMsUzTqiMIjDXUTs16KoxsAdTTL8q1Iuz8IIynR2xOa84W550opUtQqQryENQYF8EU mkZOisKILXstjqu+E27cQnhseFAusHy4KaYpgKVZTHGW32G1ZB16B3mhYKNahGLPzVbc vTWSAHAyGSWm81sDR6MlROvlEikCAK2Cjp+RJKvpc+1GyfIPpzWRKE6UowpSgxeZx9FP f6hz0afWhRXoKPovbYLmscP5cGP40pneZU80Yp4p7myGg6uglTblBxWACZByhQiZpkEC t6jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733798496; x=1734403296; 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=S88A34UwW99gwo3FHZNSbMidEba+jodHLuTGE22Alms=; b=JgGfg8rKz5Y0lCBTatczecwSjStLCzQjfS0owsCnr1lu1eaJqvm6eG6alHKSJmNe5v sniC05j+jWHKnfBLQPpGgN2CPwHNrWiM44Mam7je/ipPsmQ8328SSYeUZlg/cTjAHL4Q ThMTQGq+clJvZX7/kdzx0z7XEcFkhvuxxmD7V77m3Ph9xWnbb6seBDhWAWfwg5wuyvry /qUn1Tf0M8fmmv3YCJMeZybg9XrXNcG1U7YcZS//8VE4e0iETHRMeXL5FvjqIZQNVwwe UUQW9bgd/GwPwwlnYDMCoIoXsZdMVUj8sBfhlo4NtGR/0kw2qMTbHJqFstPkUbtbAHP6 HApQ== X-Forwarded-Encrypted: i=1; AJvYcCUB6WJ5F3/zcKe9LPaGZffb0K/CV5HqrKX6wbjvni8pqQb6LIB+pCsxm9vz+hhJ/DDZGQ0FOyZlBlODwy8B6k6h@lists.infradead.org X-Gm-Message-State: AOJu0YwLrezsb+K735Q53f/GfrQ9Gh/oV6DwDbIc5JBpfMKh8MuMTTX0 oqPCj90aNdiDMXV5PywjlJaT1E6sl6S0PbGKVIUfDImsGiAqBazxnAhDmJ4HDuUgyxcewI5jXQN +uZs75bDRvVR2w/SAwPA4fQ== X-Google-Smtp-Source: AGHT+IGKFXSWCJqlNS2qFXMxzoG4Xb3NRDnkhhqp5lhhsQRnzkIpBXQqaaHYQ40OzOD6Dmlpa/x+DpWxNJUXLfVq7w== X-Received: from pjvb11.prod.google.com ([2002:a17:90a:d88b:b0:2ea:7d73:294e]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1d0c:b0:2ee:ed07:d6d2 with SMTP id 98e67ed59e1d1-2ef6ab2888cmr21797074a91.37.1733798496370; Mon, 09 Dec 2024 18:41:36 -0800 (PST) Date: Mon, 9 Dec 2024 18:41:09 -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-8-kaleshsingh@google.com> Subject: [PATCH mm-unstable 07/17] 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 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_184137_777186_B82455ED X-CRM114-Status: GOOD ( 14.46 ) 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 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 --- arch/loongarch/include/asm/pgtable.h | 1 + arch/loongarch/mm/mmap.c | 40 ++++++++++++++++++---------- 2 files changed, 27 insertions(+), 14 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..b7db43fabca1 100644 --- a/arch/loongarch/mm/mmap.c +++ b/arch/loongarch/mm/mmap.c @@ -17,12 +17,32 @@ enum mmap_allocation_direction {UP, DOWN}; +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + int do_color_align = 0; + + if (!addr) + return 0; + + if (filp || (flags & MAP_SHARED)) + do_color_align = 1; + + 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; - struct vm_area_struct *vma; unsigned long addr = addr0; int do_color_align; struct vm_unmapped_area_info info = {}; @@ -45,23 +65,15 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, return addr; } + /* requesting a specific address */ + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; + do_color_align = 0; if (filp || (flags & MAP_SHARED)) do_color_align = 1; - /* 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; - } - info.length = len; info.align_mask = do_color_align ? (PAGE_MASK & SHM_ALIGN_MASK) : 0; info.align_offset = pgoff << PAGE_SHIFT;