From patchwork Wed Dec 11 23:27:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13904392 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 F0DC1E7717D for ; Wed, 11 Dec 2024 23:28:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D0A06B009C; Wed, 11 Dec 2024 18:28:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 257E96B009D; Wed, 11 Dec 2024 18:28:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CF716B009E; Wed, 11 Dec 2024 18:28:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DFF5F6B009C for ; Wed, 11 Dec 2024 18:28:16 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6FE14A12FC for ; Wed, 11 Dec 2024 23:28:16 +0000 (UTC) X-FDA: 82884267312.20.D2FEF1A Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf05.hostedemail.com (Postfix) with ESMTP id 7D307100015 for ; Wed, 11 Dec 2024 23:27:29 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KpzhbvJd; spf=pass (imf05.hostedemail.com: domain of 3DSBaZwsKCPYiYjcqfqglefemmejc.amkjglsv-kkitYai.mpe@flex--kaleshsingh.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3DSBaZwsKCPYiYjcqfqglefemmejc.amkjglsv-kkitYai.mpe@flex--kaleshsingh.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733959679; 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=lSyWTl6AgHPTeHZ5Av2U3d+7m6ogGk/gBzGXwo6uPmA=; b=KFUvqkx9FKaPIek62DX1Pbz9HEVv7Gxf0a4sCzgcOePF23hUrNf9MgvkVcPUv9WWDVYNS9 0hb43eRR4SC4mSJzt0Md5MlSxKOcKQ3WZRWTc3MQcHotYl2gqlWy+K38VwG4qvtakmbfn2 W5CwGQnz0BmwBSN12m4U6QoGLblLqqM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733959679; a=rsa-sha256; cv=none; b=CnOJNDXa+laKfT8iyC5KgO9GCbjR6XeEiymYolfw8NWZTJzL8mnMy40ufHMkOl5wUc85bn FQxwhO0MvixRcb6snZToOONAqYS/Hg1lWtOjXC8D8UPCsN7MsXrINFvrpPxknvpKHZfkkg bjmdncPcCK6+tyTopVYKJjtJLvXU75A= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KpzhbvJd; spf=pass (imf05.hostedemail.com: domain of 3DSBaZwsKCPYiYjcqfqglefemmejc.amkjglsv-kkitYai.mpe@flex--kaleshsingh.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3DSBaZwsKCPYiYjcqfqglefemmejc.amkjglsv-kkitYai.mpe@flex--kaleshsingh.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-728e7c06768so19744b3a.1 for ; Wed, 11 Dec 2024 15:28:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959693; x=1734564493; 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=lSyWTl6AgHPTeHZ5Av2U3d+7m6ogGk/gBzGXwo6uPmA=; b=KpzhbvJdceyHmZx+mqfeXfNm60Pl3Si+acED1ALNXJm7p/liW53A2s6j/9cHlPOVc+ 5doJhZDEL8CNjbvwOhL7R5dRSgVgdqPEFx0ECAWZsKpoM4SeC3mHHwYFLVzcTJIZu2wb +ODFRo9UMkGVyg52r0A6NaDZ8PZ4QDtqzjyVtCFvCm9mqs9KRwBhr5dLcsVk4dlEA3oY Xh/wGYPjjZlTJJb0OkgZa5v4iiSR8cTQh3WX0PtosGwQhWPe0Hoeubr4TK6FQIQF7k3B FodABafyNtJKugfc8CK4Uw50/PmCkzUpgwfWvGrVVjla6YcLdS8LmIv89h4MsjDZRcot GdDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959693; x=1734564493; 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=lSyWTl6AgHPTeHZ5Av2U3d+7m6ogGk/gBzGXwo6uPmA=; b=ovnYXMeJWoEX/BUE/jaPzBc3Hk8cJlvF0NqVhMqRCEuZV4TTCwuICyuTFnh2iqzy/I m/spgN34YFpnGvImbN+DFVVhbGfDnXbSX0/zLqKyDkJxGrJe11A90M4KemQguCeAzRNt jo/Lxm3RV+5BeWKMIUKNMkheVxSr7ctid1TilYzlsYJE3izJpOObbnB89hld0EnMFI4S TBRvUolmcLIl7QybiL3tomupvOJ5GPvDVaPukP2jAThHwXf+iDA1dyHXhv150e3s+fnj WtfNKuK7IpM7u3x9K6GlJdjXLLcKGuocunAXzlAoGgrzK32nROWcB89MPFmFt1EXN/lv xw+Q== X-Forwarded-Encrypted: i=1; AJvYcCV8DC3h0nUzE+W8iyWoVuoae26Hr3qVz4SCGuh/YnPRO7alwK7vgbnjVBA1DSsqqi1P2+tIp/D4HQ==@kvack.org X-Gm-Message-State: AOJu0Yyhtt8p+DM9I4O/m6pnEYXoX9C2eGN/0VEq0H10awMuvKhK64o6 56g+cCfyl17YpDazzg1lAxkIrcUfpWMTqj3agsIh09EuiLNvHQ4Pqq2tpLFmF1iw8QrhnNItiK9 IjIlU+Wwcn0MsPgXkn2l4nQ== X-Google-Smtp-Source: AGHT+IELNRPT2MoTQPIqvo9hLlMpqD0+8YUx/FKtbvg/ITxUep08nhQE+boeOUdV49+7nevT39OL6ys2YO6NUc/bEw== X-Received: from pfxa2.prod.google.com ([2002:a05:6a00:1d02:b0:725:c7de:e052]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:c95:b0:725:f376:f4f4 with SMTP id d2e1a72fcca58-728faa23b24mr1501920b3a.13.1733959693368; Wed, 11 Dec 2024 15:28:13 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:46 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-9-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 08/16] 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, minchan@kernel.org, jyescas@google.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: rspam02 X-Rspamd-Queue-Id: 7D307100015 X-Stat-Signature: 43ookezk38fgore1mdgupy6eqfsyd48d X-Rspam-User: X-HE-Tag: 1733959649-248527 X-HE-Meta: U2FsdGVkX1/t5FJCyCLDT+FjfPBIIVLsu0TxuG5m/DKTNnbjIngcNBT22VVkwwQTq9695pnwT1EZpwu6TnWGa2vxTqiSeZdL8DIr3AbAo086sKSa1JSjp3QlT20fBBHH18DQtdHlRZA666gjf9UDjCUmrVT9FrBGaVnv4dstNtPSL+YRTjvM+Lsqj3IQhly6QGwzsISBU57Frya05cBVfj9BcnBKCVzUOfUcZ/ED4AimaIEuDGgV0a9dZ1p+67xTTUKWVcmA8LHoCn7uJyRXMv4kpUvOj+cXkVMqQq6NmVqIjpK3V1ncSpkPzKIB7SXcvwlFkihR0ntaTmOnyaENem8MR2KBU5q1GV4T75qPGx5HEdrsfreqza8K8MHpdDudSBg7vDDTHDxJtwf6R9rpYEoUhJLgFWPoyYg6Fm6/SpBH1pdgYOZhPyoIyNFxdm+Sah2wtDPgvvKTRS08PhMXuZUl9rZfL+ywTNW094RrzJwzc5iHsFRXNbGlixuhIbJawLPayi6Hh3W1H+SfRflxq6hQkE1lR6T5XaJk87thpAjaz+628mrarobTOhZ/RkjUwjz3t5aBxg77BZAPyxbIOrCrjTjya+xPCklbo2T/LK3qJY/PiEeZ8d9pIclBMCR8RNHRg/zjyaV4Swst2AVuKqjAFBxnUoWtgV5s3korlj1Wo1vHcdhsfYoaEGWVY0WL2eMw0orVJhFY1Rce40AYMUPaI62Ih10UQydEAgEpZdT9wFUF2QD5aNyL5azqQwF9/SJ/K4ak88DPX6upuaEe2WmMv2urMdo+2ScHlXxfIBQ1PEf/9Ag2wlxxT9W6OkyirmB5rpOFx9dz1BfHx55HM/QsxSJEURYzlnYWSnYMLQxzbso1GhGxMKFbigL72u420MyDqBT8ubfQIK8/NM3Hjm6IyZrjuoDF+5Fxa+Yhs1FOzYhkNfnRw26JwnCLI65tE1eL48hJA7dgWXCcWXZ au4srzcd Zx2KBPwkmCAR7jX9U6SLPktQ8cwwQtN1rPw/Rdr4jSEgdwf976fBKJVYVZBDZY5zJ4CJyls0nSl5gXpgb4MHyWoEOAeIIwyCdMUKLr5zhV9KgU1XjWX8kNcvaS4v+7sIFYAfKF5uNCRQnbZVAyMMkCA2N1QllitSIl0JZV27esRXC2wqRTbEZmMHAkEg7rdF4a4JYYdGXQoSEQVP0Lsobe6wX/3oKWajuqyymJZMUqyZ4rVm87H/50uG0D+l3slcMqdIEee100gQ0YKLRd5QVFU6/bYyU8gUeJH2nprcrk1nVrSewRVsE5KeJ4zUqkyLnSD58YZv1BTHgwMYC+uu/u8peya0kwwaSn8iJf4DOwybXx7WEkc0d/KtD+idifoTOjzsMI4BxzK31vix6NGuspyl9mVNg4UGAdc0T0HvsXtiw9jjkXG+OXYeFx6pWXIakLHuk74ftTthtOjaI9katNcsEyQqV7zk9js1Jgl0yVnEYCV4KB0tsz/j1ZlHvlOk+q6i06m8O7w12V0R6LXQeiRmJ7DIcQgSy4uEmlY5KPEWrN411Re1lTJCK+bvagawVg5Ojp924rrdkRn7p9DGpXLK/+6Y3wcl2rqSCsk1Z7grYzbx1zibSKyra39TkTeZHITcJ X-Bogosity: Ham, tests=bogofilter, spamicity=0.039776, 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 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 --- Changes in v2: - MAP_FIXED case is also handled in arch_mmap_hint() since this is just a special case of the hint addr being "enforced", per Yang Shi. - Consolidate error handling in arch_mmap_hint(). arch/mips/include/asm/pgtable.h | 1 + arch/mips/mm/mmap.c | 50 ++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 22 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..ee9f675190f1 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -26,15 +26,11 @@ EXPORT_SYMBOL(shm_align_mask); enum mmap_allocation_direction {UP, DOWN}; -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) +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) { - 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 = {}; + bool do_color_align; if (unlikely(len > TASK_SIZE)) return -ENOMEM; @@ -54,22 +50,32 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, return addr; } - do_color_align = 0; - if (filp || (flags & MAP_SHARED)) - do_color_align = 1; + do_color_align = filp || (flags & MAP_SHARED); + + 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; + unsigned long addr = addr0; + struct vm_unmapped_area_info info = {}; + bool do_color_align; /* 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; - } + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; + + do_color_align = filp || (flags & MAP_SHARED); info.length = len; info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;