From patchwork Tue Dec 10 02:41:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13900767 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 0A687E7717D for ; Tue, 10 Dec 2024 02:51:08 +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=dnsK0Z+Vsck1DKfgwLToYEVTibYJ9G64XT5/R8jJ9Xw=; b=AhXRPZB3iGXTiYKS6AWvQm3Uur NFy/czSS2mjGDvWU6f1eO9ADZJqyjq8CNhKdd/6Msz+H5rq6N7gn+hC/nqxFNYk1uQwDULNVYG7bJ BsY+RftfMKLOCzYVhTxUwO1jr+B4V2C/PzFTE9OLxCDhlPG+Wf7MQBrqgyLRBUm6n9WCLghIDFiFo fHMkRmsYsNc5Ti0ayayW2Z6hAtteXMG5lWBIDk6Db6w00BVkyN2/EcwASbfLP+la0oqUQ0BnUk0iT 5+8hJeiWAk0P7Jg4sUga3OvJ8R7bbZ84uGC3wz1jB+xSgGByc4n3fEes/I8ngBQ2PoTJJQ5/d39wu ICUSIMvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKqKu-0000000A2C2-1cvx; Tue, 10 Dec 2024 02:50:56 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKqBv-00000009zfR-2vkY for linux-arm-kernel@lists.infradead.org; Tue, 10 Dec 2024 02:41:42 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-725b37e2b0cso3595931b3a.1 for ; Mon, 09 Dec 2024 18:41:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733798498; x=1734403298; 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=dnsK0Z+Vsck1DKfgwLToYEVTibYJ9G64XT5/R8jJ9Xw=; b=uyZ9k1AQg3e8pwmtki/bBAVg8WkxP5mzGH0CXu3h2sMd1AD14+59E7nLlnL+/H/pxO 4MLgADXGyFTkRxtIucWc+OHeTJuRheuvzBrWqveF0ElEypSg8zmBshBXqQHznWOU4ozy nDgeZDQVJ2j5qasGc2lbPZjjzDlyUWOT+ksrC3k4A1jNRFaPbyiV6Wa0JzJAxtpGCZpr THkV3AyXwVu1r3N8gtnp+VkoSGMq44wHpZFRm8saslBdHv+K8x7TfTff5KM7pCI/HjFg Wx1H6J6dcoQZeO/bbaqMiHaSlbS93GFqB3F5nR6nnqwZPKKfv3D8uYWLbEf6jrhxXQkh M9xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733798498; x=1734403298; 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=dnsK0Z+Vsck1DKfgwLToYEVTibYJ9G64XT5/R8jJ9Xw=; b=XWoWLu20HRTiHiwYR10U5lxe95Ve4WnGrPBMtPH7dr116EAiUDitp2bvSS1p3xev+A md/OMSMBIM85yHA2bVoUm1F/Y2gdxorgo8WGFKJud3iGasI8ZC5ctPLkpxEl8SB28psz ww1raMubLbM63raDtOwXlS5ajR+cb8HYELNwgfMDNcT2JObXu7bGJ73Y7YuZpNH07249 GKeZsGXetjdrUhyEP/l7ELy71HwnQ7fGDLzcQchJYxUo9/lYlSDThgUQN8jfNMYhAQDb 6n7S3o/S8CbBSREA64IMFcuiCpuIYFHWio03IiS0zCE0RU5i3kNGpth5R2tI/m6nbGlA Mz8w== X-Forwarded-Encrypted: i=1; AJvYcCV8OGMkSYU13zh5hjsZ7A4g0HbF259h9r3Oi8BlJ+vTz0HFOaiH74rb0j4SzFNjZ69CDCf8vnGh6agMYr0Hvggr@lists.infradead.org X-Gm-Message-State: AOJu0Yx76k/UggAVj4iZDejGSE1NuLN1RxFG1KcZDHkMf+ifaHgY2OyE 0BhTA1rc83aT1H8p+dxOGufgxnRCwBx8/MiqDMKAEkBHALeW498QuKGV/tZVv9vxFBjklQPGaz+ pcxaHsP0GaUaa4GV8p5/0BQ== X-Google-Smtp-Source: AGHT+IEQiVamF/zzJ8w1wfz7OIeUdP3OCsWBSWfXEHphl91Ep+NYy7TdX+lfoJ5W29b7fSm/JmmQj8+pvlj7NXOkkQ== X-Received: from pfbio2.prod.google.com ([2002:a05:6a00:8e02:b0:725:936f:c305]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7283:b0:1e0:d380:fe71 with SMTP id adf61e73a8af0-1e1b19d4512mr4863730637.0.1733798498297; Mon, 09 Dec 2024 18:41:38 -0800 (PST) Date: Mon, 9 Dec 2024 18:41:10 -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-9-kaleshsingh@google.com> Subject: [PATCH mm-unstable 08/17] mm: mips: Introduce arch_align_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_184139_727732_0A1B4E58 X-CRM114-Status: GOOD ( 14.55 ) 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 mips 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/mips/include/asm/pgtable.h | 1 + arch/mips/mm/mmap.c | 39 +++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h index c29a551eb0ca..837f25624369 100644 --- a/arch/mips/include/asm/pgtable.h +++ b/arch/mips/include/asm/pgtable.h @@ -766,5 +766,6 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, */ #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT #endif /* _ASM_PGTABLE_H */ diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index 5d2a1225785b..cd09a933aad6 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -26,12 +26,31 @@ EXPORT_SYMBOL(shm_align_mask); 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 = {}; @@ -54,23 +73,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;