From patchwork Wed Dec 11 23:27:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13904398 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 EC131E77180 for ; Wed, 11 Dec 2024 23:28:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA6F06B00A6; Wed, 11 Dec 2024 18:28:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B55046B00A7; Wed, 11 Dec 2024 18:28:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CFC06B00A8; Wed, 11 Dec 2024 18:28:27 -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 78ACE6B00A6 for ; Wed, 11 Dec 2024 18:28:27 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2C7E716147A for ; Wed, 11 Dec 2024 23:28:27 +0000 (UTC) X-FDA: 82884268782.12.B637276 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.74]) by imf19.hostedemail.com (Postfix) with ESMTP id 500931A0003 for ; Wed, 11 Dec 2024 23:28:00 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="JiuS/oe7"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3GCBaZwsKCAMndohvkvlqjkjrrjoh.frpolqx0-ppnydfn.ruj@flex--kaleshsingh.bounces.google.com designates 209.85.160.74 as permitted sender) smtp.mailfrom=3GCBaZwsKCAMndohvkvlqjkjrrjoh.frpolqx0-ppnydfn.ruj@flex--kaleshsingh.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733959683; a=rsa-sha256; cv=none; b=5xnkbPwReVpZH9sdzyNFzkCOZJhRX2BE18LBgMePlopJMo8BTxRoQnNri2bxitCg5EFwPk iFO8bY5VN71jZr5OQ6zcRy02QdH8LUvbwiTfSr9WKeIGaGvbSejG2F0R1CvwgkXV7cUk3r Jp3Qgg3mdB+oRqjcnJUxX0X77je40So= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="JiuS/oe7"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3GCBaZwsKCAMndohvkvlqjkjrrjoh.frpolqx0-ppnydfn.ruj@flex--kaleshsingh.bounces.google.com designates 209.85.160.74 as permitted sender) smtp.mailfrom=3GCBaZwsKCAMndohvkvlqjkjrrjoh.frpolqx0-ppnydfn.ruj@flex--kaleshsingh.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733959683; 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=z6Hm5oOLdBb7ho6/nkMyyfkvkknoYZ/+aPdlC1ktc9c=; b=FpD5oJnN+W4C0Lr7s5NhNz1DN9VqNS25EecXhX14S0eO8C55GMpQh/Ftj1LdDzObvFfopq dLz/W/7Yez1LmsDFbnzS+TAFD8bX/YF5ElcaXqnCAFewj0pNClGdH15hA/6D6wwSXzcCU6 lh2xTUbbdvqlWNIlzj9TRBPartoH5Jk= Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-29e5f045c93so13203fac.0 for ; Wed, 11 Dec 2024 15:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959704; x=1734564504; 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=z6Hm5oOLdBb7ho6/nkMyyfkvkknoYZ/+aPdlC1ktc9c=; b=JiuS/oe7bySnJOJNyPwcQvg4LwHCSG83zbyivCBCYejtc26NbPhwPULWMhJpw3JIeF RBAWHsc1zY75D6hOhSfV/xRUOppqX46+HD5cxnkCjwe+UH3QH/xU5vCEhJy9Y7vKauiv zmQltjx8Fy0QdB4ECurkZVlLXOiLKg+x+Bgi2Axl3/6ZBkibgqK+43ecNwV303Ta1y2v 8s2jZ4hn9QbFpRq7Roz5MH8WdzU1AWDSDOIKBBHeX+fTMp+wExOQS3AB+gITeO3dEjmX gN48mFp5wUvSQhfw22A/iy6tmD9lqZhYyo1+oRg6HgExFrXVRpJcVEifZfA0HT+jP8cn 4HdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959704; x=1734564504; 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=z6Hm5oOLdBb7ho6/nkMyyfkvkknoYZ/+aPdlC1ktc9c=; b=C291NZkv0jgcMS8LetreToBOflxh/6dxnt5kDjIuM4uuEZXqmeAcX/zReIXo1xP7UU 3n2lgt08AnhnPvqgCKekpYXeLtygIqjHDnMouvXu67ZBDhgpmFIEvGwWcdpie9Jdd7EY FC5XpWcUb6U73fjtcj6U4b85JKRokXTlrUMMyHi22HwMEw4ecgAwmFxxQtn5UaCimLNJ Kv15TdrEsBLmsh4kq7orEU4bqUM8o7lhR1rfY7yecUZCtteVx81bLkeOqFuJVyKXsg+q FjMXSnuKZXGsvuRJhgyxUt2SwOgx2PpavV68UaSBbSzm5oV3dClk1Oy/rvzr3T/76jZ5 q1tA== X-Forwarded-Encrypted: i=1; AJvYcCVqmUOZWVGV1ZvK6EtWjE1MCccG6qyQ9vkS7fUAdiqyNFV09ca5LxSn/dTWTCno4B43GtGEDqw+bw==@kvack.org X-Gm-Message-State: AOJu0YyGaCJuHQnjuUDTzZf5Ou4Hu6eRgNLjNOzcL52OjKaQM9xfKEJs 7ApVr1cCKxavzNaScM1Nqilfq6/H4srNG+z1LLTgR6LFrtuaPuTJhlttsAm3nyuGgtfngNk7CEw lJ3oaYdG42HJoy4nCx68XoQ== X-Google-Smtp-Source: AGHT+IGQDLulfLF8RwhcJUV0HutTvJeMfbYLu8JUEjKppHvTG+7VWlPJjZzjhgEci5/4OsV71lgRhbIjtjk4C1ysLQ== X-Received: from oabrl17.prod.google.com ([2002:a05:6871:6511:b0:296:1589:4069]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:224d:b0:29e:f61:3b62 with SMTP id 586e51a60fabf-2a38236803dmr971354fac.7.1733959704488; Wed, 11 Dec 2024 15:28:24 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:52 -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-15-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 14/16] mm: xtensa: 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, 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: rspam04 X-Rspamd-Queue-Id: 500931A0003 X-Stat-Signature: 1fopixffnbuyxz8gzurmk1omsidqhmcq X-Rspam-User: X-HE-Tag: 1733959680-54811 X-HE-Meta: U2FsdGVkX19fO8/ve5FMJmSSdmFbivC/OhWtr+hmJuuNxFDRsq2nHK63pYnCvJGKBM9v4bKJMV84t1fSUzI7YxixoYYBsswq4OVvTbcK1dSNfWemnIIgxcj9sDklaowvtUeUhykHr40kCsyi/TB424/HyYKC1OfK2cUnIJBgCJeb9eqaOWHoMLcMGlGTuPynW/xXhc5OQfn2aeoJNYcaxDgumdE0V4QS0kMRd/uh/WyBGxwRuFA6ci9EEN/lKUu3Jnhj6F9RFapy5lO+t2WuVamFKX4PJmJRvMZ//KkXm42uNKX1sZ3HCcieKyfk4X9Ze9/ylnXK+MOXwqfyELJb1I2CHUOQbYaosLsHcHn2uY3ON8kvi2i80RcLZ6H1sIdRxjkHHD3d3nj1EYa9gPteq5vpDTu76vXxUwPiWduJKL25EX94Ui59ZQq7fm0a/jd59tG9vLSwvNDSBifEVaniAgErOVSrkW2JkCahEdSVvKVSqRrFfOqsDeMAsG1eIKMafNUiuaMS8cw8c1COz++usTHdD0uOREJ3yK6FUU1MGji92yq4nWLKIjryWu6GF5egx3yPRpmYnbLCHPUWP2QsblFK0SlPJ7UnJLLfGuOKHkwq2zsNIUHn7fLRdwxy62ps5J2xrgFjB6/kPZvPJTkysMa7/TfJ3n+OZFbjioKoGOpAYVYPahWCMqVrlItBm5z3Z0JRVHT/89Nc0yXkag+GeQmz69DWPskdWKySRSOkxfefWvIVclWpdzv9Q6qRxx0bD6cTTYye0TmZah3J5vqX8kWX8g+gM5laHOu02dBmy8UQ72omJkx8bpZmgfqO5IUh7Mz274XPFrWjmBpagR4Q6WIq/v/+i9ywN5rVCRJqSZY9MLTIcOcWx4OI5CUvGj7TyN+pUOcL/a9n7vEiJclPCfdTT1VKFOUc+NRd3nqw/wtaZdO0ay48Rw7poaQHjQjqa93l154FHHQs/VfVFTP oU+N3+b7 vOxr5dz0AkmGNQWEgC5366Il+ih3xoj16RYDh3eJijYLY9Iy8lyWdqIH57AAQ88Gj/IlVNutb1cyC2Q50nbmXZORe0BZttD1KMsRna2vsoyFclWbue2VN2kdSJehx+mVyIY+l9S8HnDUMAqrdZUuwjPiBZ1WgX7LBwSoD82DSAbLAbhrPZuWytgBI1TLDHAlWFdb6qaTC+OPOtDpETEIxlxyCtHwMwNpyUGvXU8+lqZrcu6z+2ID7ajGUDKmtYSzG/q/yz3WxW9TeK5Sec8WvIVJBKRFu/OhDICXHdnELAZ/xeVzd7W+rJNgNzhPwtKcGBsBSl8LDhRGBFmMXGu+eM/RZrskxlnvy+vOcOAJNv6lbz6BRDfWNABYigtS5fmw5xe6KU1zvsig0YZO9fga4X58V1okqAfqN5NyVDaVCfmnN4k9j7o0GA1SLD4wHUwqRpamQ7ZzyYBLs4Bgc8RNW7swLCn45J4But2xV7kUtNj1rLioKh4K0qWowEH3humRnPbPnkZiMESPv6E4NjnBX1urp4L3XUQp+6Ml/TI8LqNc3LpwpqJJ/5kv3sLSH09xGD0W+2vBzNaNFYM2UY0T0RsTgUJK5h5zTVI93QXJyfWsZ6aEWQTzR4b8i7jv9v2FNbi7Z X-Bogosity: Ham, tests=bogofilter, spamicity=0.194096, 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 xtensa arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT. If a sufficiently sized hole doesn't exist at the hint address, fallback to searching the entire valid VA space instead of only the VA space above the hint address. 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/xtensa/kernel/syscall.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/arch/xtensa/kernel/syscall.c b/arch/xtensa/kernel/syscall.c index dc54f854c2f5..6bbe10c2a633 100644 --- a/arch/xtensa/kernel/syscall.c +++ b/arch/xtensa/kernel/syscall.c @@ -54,12 +54,12 @@ asmlinkage long xtensa_fadvise64_64(int fd, int advice, } #ifdef CONFIG_MMU -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) +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) { - struct vm_area_struct *vmm; - struct vma_iterator vmi; + if (len > TASK_SIZE) + return -ENOMEM; if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate @@ -71,16 +71,27 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, return addr; } - if (len > TASK_SIZE) - return -ENOMEM; - if (!addr) - addr = TASK_UNMAPPED_BASE; - if (flags & MAP_SHARED) addr = COLOUR_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 vm_area_struct *vmm; + struct vma_iterator vmi; + + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; + + addr = TASK_UNMAPPED_BASE; + vma_iter_init(&vmi, current->mm, addr); for_each_vma(vmi, vmm) { /* At this point: (addr < vmm->vm_end). */