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: 13900707 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 D0477E77180 for ; Tue, 10 Dec 2024 02:41:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C25C6B00F4; Mon, 9 Dec 2024 21:41:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 040A66B00F6; Mon, 9 Dec 2024 21:41:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD7B16B00F7; Mon, 9 Dec 2024 21:41:39 -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 B88A16B00F4 for ; Mon, 9 Dec 2024 21:41:39 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 66B3516020A for ; Tue, 10 Dec 2024 02:41:39 +0000 (UTC) X-FDA: 82877498004.21.EEB714A Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf20.hostedemail.com (Postfix) with ESMTP id 0A4361C0004 for ; Tue, 10 Dec 2024 02:41:14 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3Ia+QuzM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3YKpXZwsKCFU7x81F4F5A343BB381.zB985AHK-997Ixz7.BE3@flex--kaleshsingh.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3YKpXZwsKCFU7x81F4F5A343BB381.zB985AHK-997Ixz7.BE3@flex--kaleshsingh.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733798487; a=rsa-sha256; cv=none; b=qsMNn/IlJK2BVrHfp0vQwY1NMiWHNmqgXAWvmgufC262CAjCHVh4LvO5Xl8+S1jUrQJjU3 kyZmcgu7Skk23+RR4t5g0B2wEYI9IOUpDBcWwW1gPyQ2TqIWe1N1Mpkauy8eHO4CNoLs0H lP23hkOy2XQq5wVDaGR18Lru8UkSs5E= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3Ia+QuzM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3YKpXZwsKCFU7x81F4F5A343BB381.zB985AHK-997Ixz7.BE3@flex--kaleshsingh.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3YKpXZwsKCFU7x81F4F5A343BB381.zB985AHK-997Ixz7.BE3@flex--kaleshsingh.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733798487; 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=S88A34UwW99gwo3FHZNSbMidEba+jodHLuTGE22Alms=; b=gTATivq+BH44EpJT6RTp+3KzmpVT7INg/l62IXdE9dVCcrgbXDxgcfa3zOqlpMOB72DNFT +C1Mcq40XpuZf1yo4MU7lndRF6ETW+XQntcv3w3T1MQ4Mz795c7CLO2YdD+8G7OHEmxJRt pljK5X8LKYvXcagyiqtkTcnLT9K4AfM= Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef728e36d5so3395144a91.3 for ; Mon, 09 Dec 2024 18:41:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733798496; x=1734403296; 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=S88A34UwW99gwo3FHZNSbMidEba+jodHLuTGE22Alms=; b=3Ia+QuzMsRn5QIdrPRbw0KAXziiGfP3zKxSf8ptqrxhbndwoUNM1mr9OY2Vey7b12x JoIAcH0+GlNBCn77mb098p1Sv1GFYZEpROGn87PbC9Er7A/JOt8zbq1BYPrixidNoMGc lqTBKfkJfG4FVULZ6iszOQYZQdZ0ebZ3tca81QKKIo2wX0Mz0IOnLCVVz9gt9aPzpxPF PFIRqsrnY9ch9nIaIq9LixbWtO0LSBgxcgHd2zNltLIGjbKvsBsXz7lY3qIOpKqZJ+4g Zt5XkdnmaVHrodqbLEsrPZFpY7hUkmcWTQ3vfNheK58ZzsONhwgEFCmZzNq1C23eAe02 cGgA== 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=fIOEyi/5GJwTvZbTv+6cLcz+dDAWcXcaR6yAd6GR+A+Li6DMGcAwW9AMXMRxCHQHSy /0oAkiC/jdkmi/nqAgyiABa7DFA/6N0VkjwWgDyxv132iQFrcO3/pKGFzTgJXMqUc3NF weQNFGWPPFP51HnI7Altu4UV2wgPngzIhwnmOcdvh0Lin8rhxDYt3iqtF8cAY68xNi/m jxzJiSoEBFXnJFGe047LLHiSEn5fOym6sLF7Pa3XNO5B8icpi/H2w70tm0iR9cNajraR DbnpTo2T94wYq9i4bQNRi5jToRYKV15tN3o6fyAp0bQQe4mpMeiCSEAlWpanNZz/kRer rM+w== X-Forwarded-Encrypted: i=1; AJvYcCWyb2fw0nfJOGvzcHCVEjj6MlorxGaZ+VhG+7ZWbVnr7GZqGQtq8FYC3dk6vB6yyy9/KkMgE0GOFg==@kvack.org X-Gm-Message-State: AOJu0YwJTjjYerxHmfSGmnz/iu5v4FWUdHt1X7usyyYhqF76StqsyQPg EVPCWoK/le9EAILSk2eAtOHZ6mjVzwKSi0tb0tN4T3riuog4y2xvw2ixajcbfAGMpKoHe6u2upk F48kLaUXjfJiXBie6CwJRog== 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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0A4361C0004 X-Stat-Signature: f91uu43wo3xqpspghyo5r1gg68x57crt X-HE-Tag: 1733798474-75217 X-HE-Meta: U2FsdGVkX1/KyWusfG4vVOHTr0jhoO2DzOsJrPXJar9R6vz8EPPkS4f62SJTXJmFQP3rVZYLG+xhI6x1YAyw9VV25bgTLvWYsYo5R1Kk9HjW2f7dht/l0pGtuOzoEgxZEEDlawjg89UUDWvTKRhkstgqLt8ZTpXyvjFkUdrw7FBuUHiq0lTR4GTB7YdPa0VIh/qyKggH69+l7QbP4VcEQyEoNhCHE61aI6aAQFnj/kqHrKbU+lrkZKVfkL+pLjrjflLoBHclQFtaeVpaMxt5DPGpJPuzRdH2e5Z9xcfpSov3KNzMu072w1TTmLxRZK5NBLK/66NZ7pKyb03GSPZ/HV08wm05QSUKwtY70Oq1DgrgYW/KJ4SI1efRnH5dKDUpzlY8un0y09WzgelYUDj1TsF/4bqajeOCuJuKgN1f5ZsJIUbE6vsTa+gJI9vEhinqkA6SZtE3HhhhiABUTCtXqBZCu2GMDKGWGCIM9ajT6re7d5h/cC0Etfxpt6CSgk+Q9mPbktfWw9KFKSEK8dLxBCo6erD2zdmSjFSPcWjBuEG3pxbIQhgdgLC6GZY3AtQzl44ywNtdXctCPdDFVt/XVizFOArFDG5eeJEhBx7krKMDLDMMFGq7H1EOQyTpEijsPpHgUbczfVamZTQlsqSzScT4YgjA+owc6oG3XfRCZ4C6SrpItQn4gRp6BnsDNMI2bOzZSwiTbP0uirRIbosGwJEPY0qCkaUjqTsL2kRXZNUd58FTkidUmgA3iEpUw/M3KqZyLR6ghXdm/82TLDku1nhEJ3t1KLJIOCjxl5nwRQMCcVMCqqNkWqKpH09RF8F9k316oVvnr6wm2Y6JpRjQSog4NGZkaWphkq1RtQHFDKawUo0U0KnIxonxCNLjOJoOSJq+HOtQDrMpa25HEiGlx9oiEOoemlm2b6EB6N/+d5J+Zfp1w3OdAnezR+RiftCmQf3wGsp+mQtMebmsztW 4TEYLlcb gxAYAqh3MJJFMiINsDlRa8BbdEja4EANF+HPkKKVRxpjooijfv2WdmDn44tq8IMJZWglPVGzMrc6/+RvYeAttHb/GNgC4r1bBY08zPetetwg13ZRSiI6e2ggJPq9d4zZzMLYx9iyAVK7aJNVfSFS9gaIbz0pL3Yhq1JPwyszTt04ryAVRD5OOOdZOKe97zCe5MS8vRSP2gsDTbFNfiRYBDDBrOqBwYMQOPtSZOrDToyqho1ufe9NU1dGNnC5Cfq6fTkBy3Z0D7qX6eBGe07B5buYLxavJucrEsf+v5JIGRfWB5QrFB+vCJ1YEh5Hk4DudIenl4Hc1lwczIjDYqf8mpXuoq4o0oukRScUYfEBNDhGPu/YY3DF3GslPQC+gwguy15JAt1/NMeMoVhRkEWH3O9VhWWqacC+1Ergh924R2xpNZv4K2ltR3Rr6pS+npUqdvfi1QocPj753JyfuhhM24BppbclBI4VvIwcFti3snfU8DVd2xVTqrO+dR8wm3vtHimzJKLo3AlSi0z7PsiAeH3X9nfIsN/QZ2/L5xX1aXtL9MGgysBSj6YkJyZ7spWIcWPu/xLJnuF7/gN/oQjLbHVFMn1S1aXu9qlH+Gd+Hy4Ej1O4YOC4jY3S2v84espCjjVaa X-Bogosity: Ham, tests=bogofilter, spamicity=0.167180, 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 --- 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;