From patchwork Wed Dec 11 23:27:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13904396 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 F37E0E77180 for ; Wed, 11 Dec 2024 23:28:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90E2C6B00A2; Wed, 11 Dec 2024 18:28:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BD8D6B00A4; Wed, 11 Dec 2024 18:28:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EB3D6B00A5; Wed, 11 Dec 2024 18:28:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 45ADD6B00A2 for ; Wed, 11 Dec 2024 18:28:24 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F37BBC1803 for ; Wed, 11 Dec 2024 23:28:23 +0000 (UTC) X-FDA: 82884268404.13.F10637C Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf10.hostedemail.com (Postfix) with ESMTP id AF5C8C000A for ; Wed, 11 Dec 2024 23:28:11 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=BNatJ5bV; spf=pass (imf10.hostedemail.com: domain of 3FCBaZwsKCP0pfqjxmxnslmlttlqj.htrqnsz2-rrp0fhp.twl@flex--kaleshsingh.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3FCBaZwsKCP0pfqjxmxnslmlttlqj.htrqnsz2-rrp0fhp.twl@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=1733959685; 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=UgF7uGjYnhvUd+Jp5od3s3bWQayM3Oz+R04wRikqyig=; b=iKYGxh9e2StVtrF6AeNQpK0IVGTeTEBfYUwsUCsHIamvCJtWGzl7tRRmxMqA/gYJOpz3Mn Wux1fWmP/1ztGrcU+33dYLizZaA/Fld8lQ8sTmraUpUipdMi9qzpOV8Pq55CrHHsYjtHv7 AtusfpONKYhSae+QPahYYiVeg9yhyxs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=BNatJ5bV; spf=pass (imf10.hostedemail.com: domain of 3FCBaZwsKCP0pfqjxmxnslmlttlqj.htrqnsz2-rrp0fhp.twl@flex--kaleshsingh.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3FCBaZwsKCP0pfqjxmxnslmlttlqj.htrqnsz2-rrp0fhp.twl@flex--kaleshsingh.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733959685; a=rsa-sha256; cv=none; b=zRT/amGEXWat91mpSvihVODC6X8itY4F2LQQh8tGJtJP11+n2qEpJGWjQbTfGsrbp1/xZx QlcF3kRwPyxC9hRZxBzA/TmwQj906HKFkE5MAAPOAT7swhnt5cIV/IrE1sjXZ2MQI5zZVk x1Gq+yDDbt0xMBH6UdSBUu6/jNEGL74= Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-728f1c4b95aso25677b3a.0 for ; Wed, 11 Dec 2024 15:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959701; x=1734564501; 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=UgF7uGjYnhvUd+Jp5od3s3bWQayM3Oz+R04wRikqyig=; b=BNatJ5bV/2mieRTcZhcM9XgyYAGuIntakdvLShaaqNsiOcwt/ofr1Z/J3q4+dxTA8G ioStxe53JifBCS5cnvDoIMrLfJsfA3GI0Yj55kfNYzxqcv7G6Frf4NKcBSKAaySdCZnO brSjo4DGwPWuecvCXC3T7qvN/r87BAoMKDlxGDa0wMcf8hD1/FT2K2BXFudoLPiznHbX 4QAiLOHru19alWYrAbf/LN/pdNj9MtkYJXV8CF+5L73I39xMkEmdwnfmPtzNVKqHRxeZ 2/tQ+MYG4cH1TfoiG9OAAJ8CxnGCblyU0PHygfm8wQHSvMelrq8TWMxQX+6RylUDhgXH Wp0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959701; x=1734564501; 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=UgF7uGjYnhvUd+Jp5od3s3bWQayM3Oz+R04wRikqyig=; b=e7w+TZuqSTdrj+NfPfO79gt0uE9xwtCFq4Wh1RmJ1/tOFJ6gufqvZHgdxCMQkqZ7WB hFZsPCA0pUxfH8zDS02S7NST+bDkbrNNGYq9p3e7j+V71glxpYszoTQ5ChXN3OcA+W3G jEtU65qaHDLnOQrzOOk8FwpbVDJPQ9+bRwJ8RlTq9nHhlQj5OVe5PYWKceOCUTzfhG+I QprB68hb1D64PuOSJhdd0HpPdfIHp+Fk4Oeex87cgVsCySKWTSaf/DS+SQHOSZG9Wwci KtEGouVpF3nLwIsmsbg4sUsotLx1XczuC8XV10xBhqE/O9Fz1eYbKS2YVuQwQxtom6Ew M2RA== X-Forwarded-Encrypted: i=1; AJvYcCWy/4TprN6kzDPyRpJ3cvLjaKm5nL52e/bfBpN5wAR28wHa/ez37RdzKTVuCu4wzQPEhXUFk4+l4g==@kvack.org X-Gm-Message-State: AOJu0YzRjpbFQFjCvILf/a6u/spnvSDvmo7+LxrDK0x3Mu3bjKWhafiu tZUpur3LVdzWosZJmyR4DNNs/THB31iMBjEdxdAgtukSPpsjdYBxD40dsljR931fZV6G7rpUCuc sgQOGPHCiS13eajJMrj5FKA== X-Google-Smtp-Source: AGHT+IFqVvEP6jzHMp67taGtKGZyTqxXNFEg2GPfnpgGUKbuvSmZTqL3vNpWjeuOs0OQEe1804BSml5OhCqqS6mIfw== X-Received: from pfbdw6.prod.google.com ([2002:a05:6a00:3686:b0:725:d2c1:3f5f]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:43ac:b0:1e1:9fef:e974 with SMTP id adf61e73a8af0-1e1ceb34d58mr1527638637.24.1733959700835; Wed, 11 Dec 2024 15:28:20 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:50 -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-13-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 12/16] mm: sparc32: 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: rspam05 X-Stat-Signature: gdn8dr9unreg6peywn3t5oxu46tjoikd X-Rspamd-Queue-Id: AF5C8C000A X-Rspam-User: X-HE-Tag: 1733959691-839303 X-HE-Meta: U2FsdGVkX18Posm9Q1eQARqz2VJfu1ZJUPcCWRcLoqNxKKf7FbfvKkWIlcXJh+6b28IUZOYzwu//dpWIuTAOLgb8IJzNoMYCMEFv4ZTAH3ghD4zBtkFJq5AnblE4H4suFkMeCyIdUxD3qhlRAe3T+DmzbJOzAYQtzH2UjmJbDuXwTDwkq934ly+wrsGmaebmH+b+qERpjstz1mItL+suf8aMRbS8Gg/80JjYff3j8hT51t4cRlb5LcEluzmOE139SBNwdO2VDBKsgXpHULTW7Ouh3sRpQG0oWW6cdsyKu+UAuHJ4qsXn9Ln5b5H8PeHNz0HQ3N2j6BShtFRjokFNBX95Zq1wcBmYy32lja2tTlQjDfbrPwkdaP7tsnx1Eo7tDgJpDz0hfUtI1x3u271G2ON7QpVj185nM9gjR3R8Nr82HthOjizx2G70zFMKRz1HZUYJVKKSoMy7z3HjUOON/PwwIrOE5wjqZ3slefGhQ3uUaSExZqXQr3iNfsNasduxcck5xdl5KMPAkDqK8I7nIHZkV+g7Fjedh4Y5ZIaPJiuHeGzhMBZLFVM7DHm3tGqyGT+BVkaQ4akPQbGNQRnvoeBXezjqfXQnxv1VHUftuN/2kcTvQ55HC9rsI78ek6irGT5HF39/K5p1iKLARwkJvEMv1DKz2dTRSB6hpXceHs4LXkVcMcEH8AINisA7Ezs+w9ii7tAw1ocqs/E2cTc4nXaxtbP/7YnhHDjQVKAE2sJ4u/NqJNOABxLfrN/cUndgQrxGwWkeo6JQfQyF83dO/n0u/oyQJoUenDT5Me/4scPh2sy1bTs2s8bIrCZ7TmvB0uuQeD53Mwyuirmx9h37RF+2Jr+4cNgkO3GGX4MKDAj0uv891eG8cEMykq+ltY6ZPnw1oNI/Vx8/lbb65dhdThIzBlKCMwAcsA/Lj0G2cJgKNIpvoRraOfzQBX41SzvRJ5eXxSvutB4iKD110Ur zu5PvBwo 46Qigjf0ZeD7oTO3D4z7LPcTmiIRDbl3wIMZ3UxVJ4FDzsYx3mFNSpzfg3XmZ7oH/Mvl4y3P9fYq3SkUu61k+kc18YhxobwHXicPUjqU2j51ekuTeb7WDIvvoladA9SzFQRMCeiWnkUUUjOybNbD4MGEtEqYvbqtnucYuyCv+v6j9sax9OlA1vOMKtbOFLE/f3h01GWIE11iB9kEW1pjW5cPbQn40rErb+ZuxzXHO+ER4UY5RE/hNdTZOzFHto0p898pGKPxzivLXZeDQ7KUz4l1Lg/2lfaT0WPzGev1wpaaLcmPMaLpQTvpQt+rD1/BuVzY/YBFDQDjQFmN7XoXoflwIKPT2/48lDY2SBTUMugpORmS6u6cte66gdaubzwOABuM3uYTiy497siRaMmi7XcbEpOYG9hFT1Pwh70lcoV47+7a//vs/tK4EiXQqab3Rc9av3mSgCmgPGOEGRE0ppYAQK/8vV9g0QNarpmVhbmc7MQ0zckCpmkfzZh6nupH5Zyizx/2nnrj8/af21t1+PB9l3BfVQg8gx7xRaGCKI5WuV4krzh4UGwXIYNqyX0BRTv7GjBcWqbLkpFCs/yjTgY6BPuhULd58IeoxEO95prWwA8vFe93iFbamfevNcI+qEN9u X-Bogosity: Ham, tests=bogofilter, spamicity=0.138070, 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 sparc32 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/sparc/include/asm/pgtable_32.h | 1 + arch/sparc/kernel/sys_sparc_32.c | 33 +++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h index 62bcafe38b1f..95084c4d0b01 100644 --- a/arch/sparc/include/asm/pgtable_32.h +++ b/arch/sparc/include/asm/pgtable_32.h @@ -437,6 +437,7 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma, /* We provide our own get_unmapped_area to cope with VA holes for userland */ #define HAVE_ARCH_UNMAPPED_AREA +#define HAVE_ARCH_MMAP_HINT #define pmd_pgtable(pmd) ((pgtable_t)__pmd_page(pmd)) diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c index fb31bc0c5b48..0cc717755417 100644 --- a/arch/sparc/kernel/sys_sparc_32.c +++ b/arch/sparc/kernel/sys_sparc_32.c @@ -40,13 +40,17 @@ SYSCALL_DEFINE0(getpagesize) return PAGE_SIZE; /* Possibly older binaries want 8192 on sun4's? */ } -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_unmapped_area_info info = {}; - bool file_hugepage = false; + bool file_hugepage; + + /* See asm-sparc/uaccess.h */ + if (len > TASK_SIZE - PAGE_SIZE) + return -ENOMEM; - if (filp && is_file_hugepages(filp)) - file_hugepage = true; + file_hugepage = filp && is_file_hugepages(filp); if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate @@ -58,14 +62,21 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi return addr; } - /* See asm-sparc/uaccess.h */ - if (len > TASK_SIZE - PAGE_SIZE) - return -ENOMEM; - if (!addr) - addr = TASK_UNMAPPED_BASE; + 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_unmapped_area_info info = {}; + bool file_hugepage = false; + + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; info.length = len; - info.low_limit = addr; + info.low_limit = TASK_UNMAPPED_BASE; info.high_limit = TASK_SIZE; if (!file_hugepage) { info.align_mask = (flags & MAP_SHARED) ?