From patchwork Tue Dec 10 02:41:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13900702 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 7328DE77180 for ; Tue, 10 Dec 2024 02:41:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 02B7F6B0085; Mon, 9 Dec 2024 21:41:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17F3B6B0092; Mon, 9 Dec 2024 21:41:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC1346B0085; Mon, 9 Dec 2024 21:41:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B353E6B0082 for ; Mon, 9 Dec 2024 21:41:30 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6870C40D0E for ; Tue, 10 Dec 2024 02:41:30 +0000 (UTC) X-FDA: 82877498130.14.EF1B497 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf22.hostedemail.com (Postfix) with ESMTP id E3CF9C0009 for ; Tue, 10 Dec 2024 02:41:05 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=b+KFfHcm; spf=pass (imf22.hostedemail.com: domain of 3V6pXZwsKCEwyozs6v6w1uvu22uzs.q20zw18B-00y9oqy.25u@flex--kaleshsingh.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3V6pXZwsKCEwyozs6v6w1uvu22uzs.q20zw18B-00y9oqy.25u@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=1733798466; 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=2BgI/2JSXOfwO1cJ/ZJEscy7eN8JKVXEE4s6V/DqQoM=; b=oI842P1bxUCgNKmNW7hgy7eoaQe1thd2LRumn+dKSh+BWzlaey4cc3fR7mB2izS9cWMVdq rm16aASCnh23tWrk3ovQF1in9krGxGi+JestBOWmAYGoVG54koMlAyQItCLj0ysRT9dahz L1kvikKm+Cfqv+hDQnVjfnij9a+i2Cs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733798466; a=rsa-sha256; cv=none; b=gAl8ZuLN5CGfBEzB3fmWewPhv8oTwN9YVL0H5NiKeuud57XK92l+ZFnQECJie0h6LNe4n0 PmOBrPmSJKq671RHLOqe4MGDDs2Fs2rSFpPpoLWi/otHUUW4wNkyTay7W4R8Wwq50QtO8q oqQ0aM8fx+DXWqI/4LFJHkMRk5GUkew= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=b+KFfHcm; spf=pass (imf22.hostedemail.com: domain of 3V6pXZwsKCEwyozs6v6w1uvu22uzs.q20zw18B-00y9oqy.25u@flex--kaleshsingh.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3V6pXZwsKCEwyozs6v6w1uvu22uzs.q20zw18B-00y9oqy.25u@flex--kaleshsingh.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef79d9c692so4104459a91.0 for ; Mon, 09 Dec 2024 18:41:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733798487; x=1734403287; 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=2BgI/2JSXOfwO1cJ/ZJEscy7eN8JKVXEE4s6V/DqQoM=; b=b+KFfHcm1EbtUKvFcDBHiEqNzpgNM1WglGCj1I64FO6+fAu1FAYXeqLIcFcH0m7YRf 184vdYtDGdJgndUdYRJc/TNkWJU7yR4762p9XynzyTlAVrV0aFNM7/loYJsbGAEg/c+M d1Mmkf87qjjEQkjdXBFthbFIiteVrYnQTNEWIFmuOeoQMkvLQHX4L32nCcdOubtc6kSY uI+6u+KUJjlxl8paydElw3cWpQ6ZKODZZfgTP4k9UfCtt0zeBr9008Wa2md1AVk8wbTA GkSWI09owRWPNIpgWgJ9vu3ymjFhZVvZi7crIZyozLbqUqm8srJkb5coFhXIw//elwSG zICw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733798487; x=1734403287; 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=2BgI/2JSXOfwO1cJ/ZJEscy7eN8JKVXEE4s6V/DqQoM=; b=LJfHWN4cG7qZOQimDAiBJHlHeC9VIJH67JHFSmDlymCHc757Ooo3DDYWqfCjmPehP5 ZeMKOqaEEHPZVTZiEC8soIcypivYWtOR+GctOHXncHmhYN4yKV3jYCLWQ3oMTVfiCC4R 3LEDEZb2RDF9rQKQF0FlD11iWth5IYeGNZPzEJ6hbhLrZwGMsmKuP6dUFoiRagZEwX37 UOJn9sjkzBvi/k+l0KmHLMD4V3buYyBgF/WNe1Hh2tDCpNDpbOhmJ+dYtVxwcnksqhCS 0WkXl+U77Ka7bEMCW+johuVRNfTVjdgIsqnvUiU6MPgRnUO86/xGW7YRw0dPSVvaTM0N FPMQ== X-Forwarded-Encrypted: i=1; AJvYcCUUUfALBTlf9qXB/PJYP4OCbmV1EtJhUP6xdForTEKQhNdWLLNty7X7gCkJXOvHBw5STR+QjITvaQ==@kvack.org X-Gm-Message-State: AOJu0YzPxW2uo8Q5NS7XMzcvouokxVBLOa+VidfHTDRXDjuK8T8FlOId bgxJDduaIrQ72McaqBq5mbNTOSZT7uvq2fUCMy6dJVTVEdoqgBxxplfZ2WKb20pqUsZPZXJ+mVY mYehO1Kn3ZT5wkIL5QUMAWw== X-Google-Smtp-Source: AGHT+IHGMMlno4Vk4yfFbORjSDqS/i277l7+d9BxYohAoyJsB+e3g5dCRC4WlkbDRxt5bsVXivF+KHNj2TLxNR/xQA== X-Received: from pjbpd17.prod.google.com ([2002:a17:90b:1dd1:b0:2ef:d283:5089]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2e43:b0:2ee:6d04:9dac with SMTP id 98e67ed59e1d1-2ef6ab27c90mr19454039a91.32.1733798487472; Mon, 09 Dec 2024 18:41:27 -0800 (PST) Date: Mon, 9 Dec 2024 18:41:04 -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-3-kaleshsingh@google.com> Subject: [PATCH mm-unstable 02/17] mm: x86: 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-Rspamd-Queue-Id: E3CF9C0009 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 4a3g5ne9haqa7u1zmme96wfpoh65waet X-HE-Tag: 1733798465-646307 X-HE-Meta: U2FsdGVkX19JBPZ4qxs4mLo85aBLhsHTdjxj+u2rtVx79R0GZLfGUVhRKEFZr9tp/IkLs5auWlJs3KgJ03lG8TqZI1y4LJa1qhyBV2t7q9D5NnqmOeua+hWqKwSCLHlG2nYQtzhben5xSkjmNmR7V4+7229E9nu1N714RS2fKCAHWUsZ5V7W/Jvh+py6klSpX+fSQqzNhH8WwMVsgyHoRX2BT3IxDhHmEjyZiNx9iInL/ZyCTMFftw/RGB1ne/kTI1VEoAqlwMUA19qqUkekHG9jZUC9Xa4R3V7p2z8I6mbPYqCjBaYXbtVY0gslHxjcEUwI927Q35svQ1zIjWFSLbbcXmqk/gLUOTkuZ2rA4J/9n4zxujNSY5Ki1PcQ4bMbR+d5hY98Nx2uD6mDYBvrP04/WjZKBIHdhTv3NebRd1u+xeFPy3QKaZHTa0gIMpJSuTyX6ZdQLHi98bu1/OeUQxgVokH/NReYpXrUtfZdbbMpXVb4rzvExdpd13m5qPaqvXtEC6oOIIghWCLfye71aUb6JLz/lzbDCNGTAh3G2qiAjSn2XUF2hYb3pRkuQVlgBLjFk3aNrMQtzqPM1BqP38wIqU3Q4q8QJC0G6aIUagUCAAmxYsUPtmcAswbVayNRtOOHQZBmZbvX2SlrwENw4r3SeH7NqniqqtlwGDFrzUC9fb7L5x6XObfpfTyKNrETfbNi/rBtfdF8LwaflBv9e64jMh4JaGoY88WzHTWMFLULPtaSXKYoXJ/jhKPxBe+FD4J6J1c8Ld2OxWaVJEdzaMea5y0O8JgxL0jZTB7cCSJX1pKsjLjcOlLJm2shD50P2d2fJTjMdcEeN698lwGcyamPx1y39I6O9bXmo7N7ifS9yyLzaJaDzwytr1UnWhJ38jzYaqe47Es5Za9fjAbt0MtGcoNbfd0m8HjKd8XpQZOpy2obWB7yC9zbnc4DHtaP3em+8ZY0nekHZy+Ulzg u0z1GSPk e+HvWO+rA10dUDLC9RKjKDTbKDBuuk4Tw5RYw6BSpZuURg2mdWFAtaxsUWz04FdtBL0ooIRAJxEBd0Od9Ja9jkFkhFMyZoV2qPe3IkBZxuh5jkZAM6UZR97NRuFqxySO8VVGPZ2t9FIa42AZrdd+MocIi/QtjcVQReGI3Qn+pNCLQdorcd1hd4pPIOKpAdbS3NOVlVaurFzfLRYixf/2ySU3gl8/zCKXTDN9EM0MVqnCeZOwMWWxY19rq/0REXUMXOVeYNlGWGdbe+EO/UhyTd5rqbt/Ot/QIr4/shZeba+1Yi2KyTicyFt+g+QTvxysvr7KvFk5zZT17OutZdaikFCObLMLLLXZ+dyCyy2lZrKKWWCbr6A1+xV1d26PevxcHESz9e4NgHcjFZMYoU/QRb3l24gRSwO2zQ2F7o6nF42MhNeTdcnj7g6E5Mzl51zvwB/m+pz3wO1P08AkIWoxo4lheCCcKVay/nt358uJ0GT4Y72/FKb+R7Nc/DEOprqWdtxltdiXvytNZbikCQpZMK0lp0MKIZisbGaIxLa7/rQpvzKRVuTEe92criWJiftoNh4PBAs+lGnZhjyiRXKcELZz6cNIhYJWuWq/6AqWi8ozTmJO2RaGa9avNCUYHHHGWSuIx X-Bogosity: Ham, tests=bogofilter, spamicity=0.224797, 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 x86 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/x86/include/asm/pgtable_64.h | 1 + arch/x86/kernel/sys_x86_64.c | 49 ++++++++++++++++++------------- include/linux/sched/mm.h | 4 +++ 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h index d1426b64c1b9..4472fd0040c3 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -245,6 +245,7 @@ extern void cleanup_highmap(void); #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT #define PAGE_AGP PAGE_KERNEL_NOCACHE #define HAVE_PAGE_AGP 1 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 776ae6fa7f2d..95a39ef915b7 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -123,12 +123,32 @@ static inline unsigned long stack_guard_placement(vm_flags_t vm_flags) return 0; } +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + unsigned long begin, end; + + if (!addr) + return 0; + + find_start_end(addr, flags, &begin, &end); + + addr = PAGE_ALIGN(addr); + + if (!mmap_address_hint_valid(addr, len)) + return 0; + + if (len > end) + return 0; + + 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 mm_struct *mm = current->mm; - struct vm_area_struct *vma; struct vm_unmapped_area_info info = {}; unsigned long begin, end; @@ -140,13 +160,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, if (len > end) return -ENOMEM; - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma(mm, addr); - if (end - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; info.length = len; info.low_limit = begin; @@ -168,8 +184,6 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr0, unsigned long len, unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags) { - struct vm_area_struct *vma; - struct mm_struct *mm = current->mm; unsigned long addr = addr0; struct vm_unmapped_area_info info = {}; @@ -186,16 +200,9 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr0, goto bottomup; /* requesting a specific address */ - if (addr) { - addr &= PAGE_MASK; - if (!mmap_address_hint_valid(addr, len)) - goto get_unmapped_area; - - vma = find_vma(mm, addr); - if (!vma || addr + len <= vm_start_gap(vma)) - return addr; - } -get_unmapped_area: + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index edeec19d1708..f12d094649f7 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -205,6 +205,10 @@ unsigned long generic_mmap_hint(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags); + unsigned long generic_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff,