From patchwork Wed Dec 11 23:27:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=gDO2viLO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4007-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sGY0dJzz1yS4 for ; Thu, 12 Dec 2024 10:28:05 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGX0Dl6z2y92; Thu, 12 Dec 2024 10:28:04 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::549" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959683; cv=none; b=TXU9d5050z652U+Ey5H1RDuZWVMF+peUQE4uBUwAvf2FcUKumL6SBbm5/gKgFP4v0A82s1hPQlUSl3LGlDKo0/3/RQ2/e7mv1tTe/aVI3YJpiMMQUJkVmvLJ85IURI9QGFhB4RNVLgUhBvmBQzoBoiVLFP3ZxAcAYGYBhq01oQYb+ncHrZB+y3Uad9JthxwtUzOyxykzayg6K8eEhrNHLSbXs7zZ+PnfsY8YUWIQfZQU0c9vyg8SFExUdBwsqbqqpkKBbdHaGDsbCEzlw1OTQWYpiC2z5256rvVRGnRubsSZbAtiD2K3G+eoeIJ34N9qf2tjuugSyGS7ydOi1D4ZtQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959683; c=relaxed/relaxed; bh=i4sLwXeXnZGwZmaOI+TJwHO8calXr1XpV7HCaSQYyYY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eM6vxGcnK2m83X8mduETFlpp0o9EZuoicWhT/t5ptCfoRbxGd+5e+VDNzVgbIF5jAba4D8VPP/CSSBpKm4QagWrcaVnUO3u8VHcpGtLYNYyWrG8LNNEFEDSoaPpoU2enI1vsX4PGD8qA+lCBNARr2OAI/HniqFlyXeqQAgCHwquyFZOn+FI4T2o42Zpxva+XfhcVRfTRfeOr29dCRWNsP2HRV56LNCMuklJ0sXBulYjHSEhgFZymU4jeH8lMv3F64DYOSQUXZRX7bpQ2S32K1R1e+MAbnbkj34yak1DIC6xj4wWQTYA1vBcXpZxII/3SKSOseHS99/EyjaIoF0NYQA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=gDO2viLO; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::549; helo=mail-pg1-x549.google.com; envelope-from=3_x9azwskdogukvocrcsxqrqyyqvo.mywvsxehzzm-nofvscdc.yjvklc.ybq@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=gDO2viLO; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::549; helo=mail-pg1-x549.google.com; envelope-from=3_x9azwskdogukvocrcsxqrqyyqvo.mywvsxehzzm-nofvscdc.yjvklc.ybq@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGV55BTz2xyG for ; Thu, 12 Dec 2024 10:28:02 +1100 (AEDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7ea8c2b257bso43424a12.1 for ; Wed, 11 Dec 2024 15:28:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959680; x=1734564480; darn=lists.ozlabs.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=i4sLwXeXnZGwZmaOI+TJwHO8calXr1XpV7HCaSQYyYY=; b=gDO2viLOxd9rDxL2GiHoLe4watT21d3/TPiHu7dtTGuQzB6F6LsxvHM26cwyjD8Bpo rarK0TIOGtu8wMi+8zftOLvfVufHrWGpX8NJEh7J60uwl322dt1Edd4fJPzDOFtIfH3a 88yqJtIc2dfSyKjpdOnfjcv6yJwvxnNs47UCrXJaNXmf2+b5cCfOexr0VEBhy/e/TY1X Ss3bH/4CZVAWMi2VN42p4fJz3mkjBRveda4hMH6qdeNke1e8tHEsw2CGuMQ6UHbrSCKy pua9xVwNFNWQMTjNP9U4zyW9KIGLhncQVJ5/7B351MIMY3saI3BP0qr6+adO+0t3Ejiy d3RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959680; x=1734564480; 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=i4sLwXeXnZGwZmaOI+TJwHO8calXr1XpV7HCaSQYyYY=; b=FyZ8B9qe3lAsHtdTW1nNnAaEDVBpjPuylT21LNASm8OhHO20Tq4xX+r8XSEQkLjBGp s1YyaAl8wWEjAz5nTloeNUEZkhZwxQlsDZhWun37h15jpuXr0fMr9eyc1l4pDHoIn7Fc 6kFeevRX/HEyQx8Oks6F0zDJT+VSOoc6OmfkR8VJ4IZCjZ6xOqugjqHUZsB1kCPsYam1 vHw/a6Dbs239wCBFgcHklr2dWIJzjT+oRQM4C2SyfK6NmyHcNWSpZvCzQZ9WXL32y2E+ Hp6eZlJDB7gmynnuTHZln9bRf+m/KBtFwLF/moPu+F6jWu7KgmoLf7dvXJTADae6E9Ra pYJg== X-Forwarded-Encrypted: i=1; AJvYcCWzSfgU3DWd1QcD4m8t5cAMIqCSz5F/3gtVzgRos1gPHNuqcmbTjx4VMhMOpmeH16q9zVxrmJBOaFxh96w=@lists.ozlabs.org X-Gm-Message-State: AOJu0YzAAWy+PINvrjVpwce6f5suZbcNRBff65ZoI3uUrAebDYxhF3fG dXdk8OPPXGQe4+AUY1f4yXVSkSW5E0zzYxDWgcJrjKkIR3RZew95r4ON9WxWIfs5rTU0lwmbVvW 8+yNO48L/BHSyhr9DmmfDzA== X-Google-Smtp-Source: AGHT+IFtd/N2pCFnI2u1d5m96JgTZmL7tbAt9a9u3MHy4m9H51vxoRQ9F2QC80/CNULE+uh+FoVAQHYq51Gg3PfRrg== X-Received: from pjf11.prod.google.com ([2002:a17:90b:3f0b:b0:2ea:29de:af10]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2790:b0:2ee:f80c:688d with SMTP id 98e67ed59e1d1-2f12802a503mr6866191a91.25.1733959679820; Wed, 11 Dec 2024 15:27:59 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:39 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-2-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 01/16] mm: Introduce generic_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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Consolidate the hint searches from both directions (topdown and bottomup) into generic_mmap_hint(). No functional change is introduced. Signed-off-by: Kalesh Singh Reviewed-by: Yang Shi --- 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(). include/linux/sched/mm.h | 4 +++ mm/mmap.c | 76 ++++++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 928a626725e6..edeec19d1708 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -201,6 +201,10 @@ unsigned long mm_get_unmapped_area_vmflags(struct mm_struct *mm, unsigned long flags, vm_flags_t vm_flags); +unsigned long generic_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, diff --git a/mm/mmap.c b/mm/mmap.c index df9154b15ef9..382b4eac5406 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -620,6 +620,47 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info) return addr; } +/* + * Look up unmapped area at the requested hint addr + * + * NOTE: MAP_FIXED is also handled here since it's a special case of + * enforcing the hint address. + * + * Returns: + * ERR_VALUE: If the requested mapping is not valid + * 0: If there isn't a sufficiently large hole at the hint addr. + * addr: If sufficient VA space is available at the hint address; + * or MAP_FIXED was specified. + */ +unsigned long generic_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, *prev; + const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); + + /* requested length too big for entire address space */ + if (len > mmap_end - mmap_min_addr) + return -ENOMEM; + + if (flags & MAP_FIXED) + return addr; + + if (!addr) + return 0; + + addr = PAGE_ALIGN(addr); + vma = find_vma_prev(mm, addr, &prev); + if (mmap_end - len >= addr && addr >= mmap_min_addr && + (!vma || addr + len <= vm_start_gap(vma)) && + (!prev || addr >= vm_end_gap(prev))) + return addr; + + /* Fallback to VA space search */ + return 0; +} + /* Get an address range which is currently unmapped. * For shmat() with addr=0. * @@ -637,25 +678,13 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long flags, vm_flags_t vm_flags) { struct mm_struct *mm = current->mm; - struct vm_area_struct *vma, *prev; struct vm_unmapped_area_info info = {}; const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); - if (len > mmap_end - mmap_min_addr) - return -ENOMEM; - - if (flags & MAP_FIXED) + addr = generic_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma_prev(mm, addr, &prev); - if (mmap_end - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma)) && - (!prev || addr >= vm_end_gap(prev))) - return addr; - } - info.length = len; info.low_limit = mm->mmap_base; info.high_limit = mmap_end; @@ -685,27 +714,14 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags) { - struct vm_area_struct *vma, *prev; struct mm_struct *mm = current->mm; struct vm_unmapped_area_info info = {}; const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); - /* requested length too big for entire address space */ - if (len > mmap_end - mmap_min_addr) - return -ENOMEM; - - if (flags & MAP_FIXED) - return addr; - /* requesting a specific address */ - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma_prev(mm, addr, &prev); - if (mmap_end - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma)) && - (!prev || addr >= vm_end_gap(prev))) - return addr; - } + addr = generic_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; From patchwork Wed Dec 11 23:27:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=RKsJ/O/j; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4008-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sGn5ypRz1yRR for ; Thu, 12 Dec 2024 10:28:17 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGY5Rq0z30TN; Thu, 12 Dec 2024 10:28:05 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::449" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959685; cv=none; b=bqMnR7m9WkB1lKHF0vd7WusSAkFxV5PxO9tqFyVISLkxH4eF5YcPwGtyifOyBGhFALZ5olK9+GjN6ODgz3I0gi2n43x8p+UhTWH0/7xQs5xsu5ZT2D1hcpcQbwWe8XVGZDVrSJwryqV9hP3Q4maUdkrUsjNxQyPwrwbst+99kiihE1wYvrCqYWmtAa/1AYJnbzCZcYfgscMPtKbqRSzHiguCLqCXkqOb7ZIHQUP2P5xrZP0pYQHZzZFQgmGsYL5hqqgfcCblXGldX+lukgPfhUpfTrYERkcZgGQuH6FTlbod6MXkrvc7JiTSyCWiBxqLKmWdZwsNHdpMbbPI2dNr1g== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959685; c=relaxed/relaxed; bh=C3IQSr9A1qLdVskR9rEe7ppqc2lFkJy3Q6Qw5iPRaPE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Si+Z9j1Y8lswZWvxzgCyk68R14HnZHxlJWE9TvPkm6ZUUQpax4FzBkpSFAzKy7ijNG7M4SMKLOHRXKMBF6A8uQRfPT/aU1nA44fCQHzzJiPdoUjYDRrjpu/1NmSjulMyYTtrIxHNvr0TjseCVXVTayCN7d92yC11De391IAhviBCoI0PNi1aBi17weTPVUDLkKsWxT6aybD68C5zEWn+AKR8NpZGVLQ5HAxWNVRvw4s1ikJdfoky+XFOS62preG3oeexF+i62HOhOduDk7XbQcvrfEiYsf/+zfDkbcRpAUh9OmzvhqQc8+ZQFGrcr5+fD09yWZd63vRMRHQI2aqmHA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=RKsJ/O/j; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3asbazwskdoowmxqeteuzstsaasxq.oayxuzgjbbo-pqhxuefe.alxmne.ads@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=RKsJ/O/j; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3asbazwskdoowmxqeteuzstsaasxq.oayxuzgjbbo-pqhxuefe.alxmne.ads@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGX5SBlz2xyG for ; Thu, 12 Dec 2024 10:28:04 +1100 (AEDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-728cd4fd607so26524b3a.0 for ; Wed, 11 Dec 2024 15:28:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959682; x=1734564482; darn=lists.ozlabs.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=C3IQSr9A1qLdVskR9rEe7ppqc2lFkJy3Q6Qw5iPRaPE=; b=RKsJ/O/jaaeUlfJWJzr4k9gAa/4G1L5da/8XRTChr1cQOCgmIgkubhCeNIhNFa0LQz OZXwWaP+avMme/AuF9Rv6pMSHF9LDckVqsctmxYOPTveEjjOjeqnUgwZPhbBfUjPoHbl Zx1QEFFYaF4uIZRXpxgObV948saiiRAVXG4ucCQ1Nxum/9+YNnkqCBo/lLpcw9V0oSyk db3Wz6IEnt/r7KlogNnxVN05RzN2ZuYH6nwBIe8DHCywPgVh9L7maMmJuxoWSlm1fVRV hrzo3+yx9nj7LWJo8Q22Z0PRMP82IbTRQbBLVddgEDwbk7w1fGFYbvhlKqBCs1QrH/u2 Z4wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959682; x=1734564482; 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=C3IQSr9A1qLdVskR9rEe7ppqc2lFkJy3Q6Qw5iPRaPE=; b=eYZC3bV+mSvYOuNKezwNxL2Jk8c0lAEXOE+N9SY7NCUZYSH/FlSJmGCGtgQLIM/j0Y me/Q63zLYn/18p8BOLH3X0M/1HXKnmZKZjFg9yD7YyAf0Qw5715jmI//A2VQMtwjqevO Y4iN+vws3OkgnA7fZahPhvNkJvRChq/GwAooHo0a9Mm7IcXqKs8px+8ie8ijzyITRo0J kvvnKmY66k54HdKdhUaIAp3882okqEUZe+QVuldTyQJQGzu7bD2Akv5lq449rN7VqMOI ui+vX1D4EedWgUzz5nY2DiZx9lTRngfKaM2DgzwB9vtPjpvsaoyY/zY/Nwg0hJ42aYVk /xiw== X-Forwarded-Encrypted: i=1; AJvYcCXfz2WS+iFKdyYMuBdZoLf85HrMQUKyMpi1MSHnXB8E0x9Xs4uumsNjB21ihgc138S+FqYlMfXidLTg+mM=@lists.ozlabs.org X-Gm-Message-State: AOJu0YzgMQYC+HU5kZ4SbhDxTRFmh/R6WELr3pcqxjkENb+bJIsnXSw3 hDfp8NDpu+sXiBRsDx/AAslazs67474ZutRMYEUUtSgs8wdxxc6k1AxOXiznjbN8R9rL7DFh61N 3R2Km2pcNd7/3euAcfb892w== X-Google-Smtp-Source: AGHT+IHwoWCnSZAFhgfRGzh0vJKMetndx4pRL/iGA/i3q5lPp5GtpRRmcU9xCr75DNYXJvBdH8Wl1Hh5YkFK8klCiw== X-Received: from pge13.prod.google.com ([2002:a05:6a02:2d0d:b0:801:9432:2d6d]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:cf83:b0:1d9:18af:d150 with SMTP id adf61e73a8af0-1e1ceafb16amr1741157637.21.1733959681795; Wed, 11 Dec 2024 15:28:01 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:40 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-3-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 02/16] 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, 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Introduce x86 arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT. This is a preparatory patch, no functional change is introduced. Fallback to generic_mmap_hint() if an architecture doesn't provide HAVE_ARCH_MMAP_HINT. 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 most of the error handling in arch_mmap_hint(). - Fallback to generic_mmap_hint() if arch_mmap_hint() is not provided. arch/x86/include/asm/pgtable_64.h | 1 + arch/x86/kernel/sys_x86_64.c | 64 +++++++++++++++---------------- include/linux/sched/mm.h | 5 +++ mm/mmap.c | 9 +++++ 4 files changed, 45 insertions(+), 34 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..008c6d19bd02 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -123,31 +123,44 @@ 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; + + find_start_end(addr, flags, &begin, &end); + + /* requested length too big for entire address space */ + if (len > end || len > TASK_SIZE) + return -ENOMEM; + + /* No address checking. See comment at mmap_address_hint_valid() */ + if (flags & MAP_FIXED) + return addr; + + addr = PAGE_ALIGN(addr); + + /* Fallback to VA space search? */ + if (!mmap_address_hint_valid(addr, len)) + 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; - if (flags & MAP_FIXED) + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; find_start_end(addr, flags, &begin, &end); - 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; - } - info.length = len; info.low_limit = begin; info.high_limit = end; @@ -168,34 +181,17 @@ 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 = {}; - /* requested length too big for entire address space */ - if (len > TASK_SIZE) - return -ENOMEM; - - /* No address checking. See comment at mmap_address_hint_valid() */ - if (flags & MAP_FIXED) - return addr; - /* for MAP_32BIT mappings we force the legacy mmap base */ if (!in_32bit_syscall() && (flags & MAP_32BIT)) 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..f4143703f234 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -205,6 +205,11 @@ unsigned long generic_mmap_hint(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); +/* See generic_mmap_hint() */ +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, diff --git a/mm/mmap.c b/mm/mmap.c index 382b4eac5406..76dd6acdf051 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -705,6 +705,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, } #endif +#ifndef HAVE_ARCH_MMAP_HINT +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + return generic_mmap_hint(filp, addr, len, pgoff, flags); +} +#endif + /* * This mmap-allocator allocates new areas top-down from below the * stack's low limit (the base): From patchwork Wed Dec 11 23:27:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021753 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=t8THSRZ9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4009-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sGv6zb7z1yRR for ; Thu, 12 Dec 2024 10:28:23 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGZ1jW1z30Tm; Thu, 12 Dec 2024 10:28:06 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::549" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959686; cv=none; b=XNRIN4/Ub3NYGNytKbRERjPUyIJBBAlFFVEfGUI+0q7FiJ6Z5LN1TFPQtCP1VN4lcAmeHa8O99Lcl8Ku7a0Jv9CtELmkAQpOmMjSFuQjqlcL3g0UKfkDW6vXgionRH6xo3/mK/T3EyZsKsd/WPoNn5i3id/7qAASmv6MdS39GBfcvPrSNArr7f588+3blJMbYyzgwd8K+eu0RW5VTi7urXyYhmER3LQOf/iaWtyCT2sVR6uaGlqyHx0tvCkfKtd+9MwrSjCvnADsWpFbahFRHMZuZJ/2WFkLGHj1IJwKLR1BmdqxANdF/K93t+GLLfwsr1V5VIwYEZ9HWsyv+8+ZTg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959686; c=relaxed/relaxed; bh=t+2SZZ0hfvfE1wB/PVG8ptvYr9aJVJPmVtSy9l3KX7E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GsUiS/gczluDsQHwrr3DH8ts6VqPOylx+q5fVcC/941TvWKpXktl4qS57TF0TVewxWriMh8DLx2SfBTwe19Xj9Pqt9py8Zdtd7stVM4vB+ySI09wFv7GyFfNbvCkuWUku5i2Bdi1aFI3jQbW9VjsJhGKSARUIvy6JAEkWbfgopiLM/yoo6mA4rEhFwK9O/m1GaPIHVz+PwI6bpKG0InUrMhK5jkmnABn6Bkv5PVEseSvQ0OHiqMFJYLTW5w3yBu7XMniUsWnloocre6q9jku7Yr5nHtulB6E18p4qdG1mAYEjKuPZlz9Yn1e9LB/z3v8CQ1ARQg4au+4GwjrVjG5ug== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=t8THSRZ9; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::549; helo=mail-pg1-x549.google.com; envelope-from=3aybazwskdowyozsgvgwbuvuccuzs.qcazwbilddq-rsjzwghg.cnzopg.cfu@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=t8THSRZ9; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::549; helo=mail-pg1-x549.google.com; envelope-from=3aybazwskdowyozsgvgwbuvuccuzs.qcazwbilddq-rsjzwghg.cnzopg.cfu@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGY2RDbz30TM for ; Thu, 12 Dec 2024 10:28:05 +1100 (AEDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7c6b192a39bso34115a12.2 for ; Wed, 11 Dec 2024 15:28:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959684; x=1734564484; darn=lists.ozlabs.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=t+2SZZ0hfvfE1wB/PVG8ptvYr9aJVJPmVtSy9l3KX7E=; b=t8THSRZ9gEYT46x+0Xls7oWPmeXmorEzMe8vKaCnwsupCMb9LZqvPQxEyUOU4BP0EA XXMmCgBW4CyMCKmTS8exXy0AQTIA/0ci1kMd4VUTZnA6MwdJGwmEjYf/IamPmQLcUBBJ R8QiEm8HfO++fxz6P4XyCLq34EzZshgTye1AW30B+NBoyn8pjkB47EvLuY9pSo4g6lyo Uaqs96triFIvmaj4N7tMiSXInhMrbmIdt0TBEfpIN/1vCBdJn4NHg87yLW85M5sRIfTy KhjpyN708slMwBz9rPUVrGJypQ52J062QQ4qnmNGPkR0+PjCnpaceymRIrKO76g/hQnp YUBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959684; x=1734564484; 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=t+2SZZ0hfvfE1wB/PVG8ptvYr9aJVJPmVtSy9l3KX7E=; b=GjE0CjnSILgJrTovcNOLTEDR8Xw+AcxUdYh014Car8/UBYaUNmgZEFUmmh0SSXHywo 5e+1zAp1NNH7/mZGAYEEDzQjcY3zpbsrfFDLQWGDBh9veu5f2QrH9PrSJicv0FFpq7z4 kWvwsTevpW8Oyg7zYM6QOuCCg9maQEcWjZeJUb0and5gNAu8YIiIbK5Qr4T5EB+LzQlj 09VBiM6vxKbQC6gPZy0Q+bnEosnHIc5/0p2QM26bVBpbxbX7GNBm0Bixj5G4zp4jBimk KPquHsUigIPGTwWeKoNfp4KXnyvLJBfvgIF7CznU+S0RbNQ9PDy9qGDfxY5bce8Mj6Hh Ah3A== X-Forwarded-Encrypted: i=1; AJvYcCXMtPRtewPj/PB56m3aCsann4hA2pvGRCl2XkZdX4D9kCO1+bcIToXknl6glnZVVEq08KM8JYoVpsWyxOo=@lists.ozlabs.org X-Gm-Message-State: AOJu0YwimMVj9nh94wnzB4RNTJKsL8XHdwvKfjr0m0iKqoTPFjAJGtW4 Hc3v7d1fUZ2Fp1FBYln+rP7ykwUybwA4DbcNUj/TqtHdrKaOkSkXThfAtT/L9Db/wCwMpl7EcPm iMfoiz2rmPf2wb6HiNQJ0MA== X-Google-Smtp-Source: AGHT+IE/Z/5jS7mczW6P1buMx2K0ifA2tKb3E5Z4r/r+p5Ssl9msAfOzZLWtpmRsmVcD4OTpdOSyZZHLgcfY4EVEyg== X-Received: from pfxa22.prod.google.com ([2002:a05:6a00:1d16:b0:725:db2d:370e]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:43ac:b0:1e1:9fef:e974 with SMTP id adf61e73a8af0-1e1ceb34d58mr1526584637.24.1733959683818; Wed, 11 Dec 2024 15:28:03 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:41 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-4-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 03/16] mm: arm: 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Introduce arm 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/arm/include/asm/pgtable.h | 1 + arch/arm/mm/mmap.c | 107 ++++++++++++++------------------- 2 files changed, 46 insertions(+), 62 deletions(-) diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index be91e376df79..1433b3ff4caa 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -330,6 +330,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) */ #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT #endif /* !__ASSEMBLY__ */ diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index 3dbb383c26d5..15e7e4348af7 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c @@ -17,6 +17,41 @@ ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \ (((pgoff)< TASK_SIZE) + return -ENOMEM; + + /* + * We enforce the MAP_FIXED case. + */ + if (flags & MAP_FIXED) { + if (aliasing && flags & MAP_SHARED && + (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) + return -EINVAL; + return addr; + } + + /* + * We only need to do colour alignment if either the I or D + * caches alias. + */ + do_align = aliasing && (filp || (flags & MAP_SHARED)); + + if (do_align) + addr = COLOUR_ALIGN(addr, pgoff); + else + addr = PAGE_ALIGN(addr); + + return generic_mmap_hint(filp, addr, len, pgoff, flags); +} + /* * We need to ensure that shared mappings are correctly aligned to * avoid aliasing issues with VIPT caches. We need to ensure that @@ -32,42 +67,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long flags, vm_flags_t vm_flags) { struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - int do_align = 0; - int aliasing = cache_is_vipt_aliasing(); struct vm_unmapped_area_info info = {}; + bool aliasing = cache_is_vipt_aliasing(); + bool do_align; - /* - * We only need to do colour alignment if either the I or D - * caches alias. - */ - if (aliasing) - do_align = filp || (flags & MAP_SHARED); - - /* - * We enforce the MAP_FIXED case. - */ - if (flags & MAP_FIXED) { - if (aliasing && flags & MAP_SHARED && - (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) - return -EINVAL; + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - } - - if (len > TASK_SIZE) - return -ENOMEM; - if (addr) { - if (do_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; - } + do_align = aliasing && (filp || (flags & MAP_SHARED)); info.length = len; info.low_limit = mm->mmap_base; @@ -82,42 +90,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, const unsigned long len, const unsigned long pgoff, const unsigned long flags, vm_flags_t vm_flags) { - struct vm_area_struct *vma; struct mm_struct *mm = current->mm; unsigned long addr = addr0; - int do_align = 0; - int aliasing = cache_is_vipt_aliasing(); struct vm_unmapped_area_info info = {}; + bool aliasing = cache_is_vipt_aliasing(); + bool do_align; - /* - * We only need to do colour alignment if either the I or D - * caches alias. - */ - if (aliasing) - do_align = filp || (flags & MAP_SHARED); - - /* requested length too big for entire address space */ - if (len > TASK_SIZE) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (aliasing && flags & MAP_SHARED && - (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) - return -EINVAL; + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - } - /* requesting a specific address */ - if (addr) { - if (do_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; - } + do_align = aliasing && (filp || (flags & MAP_SHARED)); info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; From patchwork Wed Dec 11 23:27:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=1zYvsFPG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4010-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sH22Txlz1yRR for ; Thu, 12 Dec 2024 10:28:30 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGb71lgz30V3; Thu, 12 Dec 2024 10:28:07 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::449" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959687; cv=none; b=fAn7YjEvE+uV0H3voQ+YM6AEYA10CVeSj9ghSKnLsN9CgMfkM89jcz0PZ0Nyqx5l9vcRTssskz/aprrjON97sYqy3+TlGK/ODiXYeVADs8fWjV8P37sWVEBSpTTnIdKE9rvpiA8AkaIzSYqrC8kQlYI01I1dCfwR7LdioaDhiuzNtb0Vpo3iyEctzH6SLRpI9QNYwU/2SP4cLHwoKfuAc6pNxYzyU33tEc6DYPJSpTTJVCVZd9JC+dVhmvTVblt9U5F/cxbrNrA9gv3pWUelf01A5J6VV2G1UN66dtVaiiPH7ByUxZLtwOmWIY9+6hCCdY3DkMhUQ2qy8LsgZr71bg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959687; c=relaxed/relaxed; bh=vYJJcdIp4OFdB+jw/mn5ZasDVQdafEZmT3OPk14pFSA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Tugntkij1f8GdQ9rkBnoz+5k/foyeCZMEBgns12EK9rWm76/Ww9hJnNothk2bfkgde0X7malNN3P/BgzXQBRblS1gdDNa1yG0zhhR63aLYYMwjOorv6P8s8lWf1FFi9QPlvDrETcYDGn1W6Tj9n/AhmCqdygPbuzO307KJkPHYPOsaLv8VEAkBm8nNetPi1wzb8jvyZJ8nz5+s/s7OxzTDCQUZHoTaA+v0rIlmDGADVPF+dujNYwKHdmcbqYybtWy7QJcLC1w07pMStlmpsYLwMH/YliGss6R6/iX+gLspr38LFO1M9F/qc0naG/AvDFq2jCDoIqQ0DGU1z8S73Q7w== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=1zYvsFPG; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3bsbazwskdo4aqbuixiydwxweewbu.secbydknffs-tulbyiji.epbqri.ehw@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=1zYvsFPG; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3bsbazwskdo4aqbuixiydwxweewbu.secbydknffs-tulbyiji.epbqri.ehw@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGb2JM1z30TM for ; Thu, 12 Dec 2024 10:28:07 +1100 (AEDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-725e8775611so21741b3a.1 for ; Wed, 11 Dec 2024 15:28:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959686; x=1734564486; darn=lists.ozlabs.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=vYJJcdIp4OFdB+jw/mn5ZasDVQdafEZmT3OPk14pFSA=; b=1zYvsFPGPw2+dghPDI4RXM16cNt3wBfhjWWEa3EvaQjEP1xsG+tgBpSoT0T6IT7qDZ RbbRTQ3+PakW32vqEgK8enzk3SEbsjGnqq14sZHZmQSKZejTTrZMrDp3SkZEQEU043rt pwVynQshcv0BrFrC8jY6A+IX9FBPSoX7mau3KoLROeSrQAnooDbETNDFWULyKnCsWb0y ydCzUWzcaEw1aS/a5F9vMjlIXlnLEyarcQ15DY99P2dIvGPjXZNtGanEMmrhXKHGAOcm d7QyhPMwc1ImAoLfEL7Mu23626mo7vPbjN6w8rdogrxJgl9TW/jJACz7boClydv9uEqG hwhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959686; x=1734564486; 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=vYJJcdIp4OFdB+jw/mn5ZasDVQdafEZmT3OPk14pFSA=; b=XgNdNH09/KLzUcWpnWx4iRHNttceeFP8wN16pm6krhsrPdO6Z/HYLZ+M3efHiubdnq Hu2y4z1ZQJfooknm0QrcVoT5T3t9ZIyijYGD6cJNgtZPWO3iHeDYSg10EtGipbJz07iW rVFbdg7u1UwN59b7I5kz6ABwhWp5RVleTBaxvq+lbvRSWcvaeUlLgQFKmJmC+B9oZt67 JlxRuF0jbk/A6dM72wRK6YvpWAUOECiXdTIcxrJSwVNKvZVG2c1bZIENKwmJKLaE+bpY wGi071pPGSEq9ETBo1sUxT/xdmEBpw1chRQvzVUkHlVxxe7aRk8S/KAEdxnBNJdzPvTU MJNg== X-Forwarded-Encrypted: i=1; AJvYcCVpV9dFgojbEsA3ZoVqrPwKledYr81xDuLoXZJ97ZP/qzPJC/2MdmW5druWSumlu4Byr44S4Dfd5tFWchk=@lists.ozlabs.org X-Gm-Message-State: AOJu0YzIGHWJuIFXWNBUDwcOIVgRQsGLfc6Ql077O2wI9rPyZf2OdeI5 W0FFBugvxKmkA9G06MAXeeQZjuvIsPEXH4Bl8D5JrtI4tmH4XTXvpZSBw955HLTsV/prIhOqH1h M9++lDXLAhZHH3E1RqjPE1A== X-Google-Smtp-Source: AGHT+IGKKVpJDJ1y2ylGaA50Z43wv3+APAJV0fjiCw5ytHmnD6GxlKgAyJQZQRFGHnrCD199ncZRE2+HH1UPCzOgAg== X-Received: from pgbfy22.prod.google.com ([2002:a05:6a02:2a96:b0:7fd:4739:79be]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:328c:b0:1e0:c56f:7db4 with SMTP id adf61e73a8af0-1e1cea71c6cmr1602899637.2.1733959685721; Wed, 11 Dec 2024 15:28:05 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:42 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-5-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 04/16] mm: alpha: 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Introduce alpha 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: - Consolidate error handling in arch_mmap_hint(). arch/alpha/include/asm/pgtable.h | 1 + arch/alpha/kernel/osf_sys.c | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h index 635f0a5f5bbd..372885a01abd 100644 --- a/arch/alpha/include/asm/pgtable.h +++ b/arch/alpha/include/asm/pgtable.h @@ -362,5 +362,6 @@ extern void paging_init(void); /* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT. */ #define HAVE_ARCH_UNMAPPED_AREA +#define HAVE_ARCH_MMAP_HINT #endif /* _ALPHA_PGTABLE_H */ diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c index 86185021f75a..308f832732dc 100644 --- a/arch/alpha/kernel/osf_sys.c +++ b/arch/alpha/kernel/osf_sys.c @@ -1225,10 +1225,9 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len, return vm_unmapped_area(&info); } -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) { unsigned long limit; @@ -1241,8 +1240,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, if (len > limit) return -ENOMEM; - if (flags & MAP_FIXED) - return 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) +{ + unsigned long limit; /* First, see if the given suggestion fits. @@ -1253,12 +1259,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, That said, I can see the use in being able to suggest not merely specific addresses, but regions of memory -- perhaps this feature should be incorporated into all ports? */ + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; - if (addr) { - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit); - if (addr != (unsigned long) -ENOMEM) - return addr; - } + /* "32 bit" actually means 31 bit, since pointers sign extend. */ + if (current->personality & ADDR_LIMIT_32BIT) + limit = 0x80000000; + else + limit = TASK_SIZE; /* Next, try allocating at TASK_UNMAPPED_BASE. */ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE), From patchwork Wed Dec 11 23:27:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021756 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=RYyEU/SB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4011-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sH90kyFz1yRR for ; Thu, 12 Dec 2024 10:28:37 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGd64CDz30VR; Thu, 12 Dec 2024 10:28:09 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::449" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959689; cv=none; b=gDQ/SCw9KzN3kxDy2wf41z75sjH3ePReGQvJmuPiWhxYB0uKojE02zxKHdo0mpFMyZoReNzXIHTu8L8SxyOj5DVPVebphNx9LbFsXvEE9t9Oz1SpX0O1dUJhfSJ4M7O/GN+EkrE4jVHLg4OZ7RzeqgsinCEtCjCC8QXt4+t5PdRdUJs6rfKeVgitVV2ho5dIhY1aT9R1fZKhCOemxJs073oGKi5yDkRzOAgbcYWmYN1/gmAQCnwACvb/4M8+XhqIj1SbUmuQD/dOuhxawnLq18lk4zb8kVWSrYNd9/Hd3+RJdpq257FMMKEUdOqX/FMkdAfVhy7D2DrSRcTSqZQgMA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959689; c=relaxed/relaxed; bh=qH5hFVlZb/xpQlMxAKu7QZtletX8CELYGGCCA+g77Tw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NDSBML87JT+UTfQQQUNwsD3Zn7DmIFY7tJn+fJpa3SL5vWkWueaik5bxbSzWN5ZUiL2r0G0cTj6vscQJ6IcQrG4svia7cAcpNKGLq1UEnxXNJvrRbn2QoHdS0BS4uVdJL7uSQtEVpCUerntvX2uvyk9RKQPXFBELgCFcCO2idjNuOJwOt2xVLI00d9/ojTn7X19l9yNKE87/ZgjlY6LuNp+E5f4KRbltI9E1mJaeVBW87a5nQvFcAkYyLy5uP1QntQTHiRMsG6y81QeGoEK4//Lf0+3spw0fc2jIJH+lHN5CtHovVeasClV10MTCsphvlvh/ZlvKs+XYP3XVEX4jRQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=RYyEU/SB; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3bybazwskdpacsdwkzkafyzyggydw.ugedafmphhu-vwndaklk.grdstk.gjy@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=RYyEU/SB; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3bybazwskdpacsdwkzkafyzyggydw.ugedafmphhu-vwndaklk.grdstk.gjy@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGd1GNdz30TM for ; Thu, 12 Dec 2024 10:28:09 +1100 (AEDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-728e7c06768so19694b3a.1 for ; Wed, 11 Dec 2024 15:28:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959687; x=1734564487; darn=lists.ozlabs.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=qH5hFVlZb/xpQlMxAKu7QZtletX8CELYGGCCA+g77Tw=; b=RYyEU/SBxCSjxIvb1TFKuOPzHcCYSrFsKqyUE5hMvByA7qxwjGNN8VpNL6Fjj47eYH qRZ2kCjMKyyyGLGzt2EB9M9NWuTg6D6lVYSWGXXQ9Lr4Ed63SH/QiwxrBoNB+HLEK4q/ WXB3ypGuPx6YN5AioZ48YgwsLx7PgnqDgpzyd5tcv19g1VQ0d+i0qsObzdMxLTgvW2A7 U2L1SGH7JmQQZxpWwFPPOGkPa+k+051hcSQTh+6dDLhwmF/lA5kZS8Qdo94llwEBMw2q yq6jvl2b/TPW5bLDdsrjoPbYR9J7q5XL++nPoC4HPK87bQt7HOsrnIaeZ5EfhwiwZeHi ScxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959687; x=1734564487; 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=qH5hFVlZb/xpQlMxAKu7QZtletX8CELYGGCCA+g77Tw=; b=THCs0En1e97rcPffGOesNloGch2MSqrjqKcpxWLag/vdEaA9rBR4/nY9rrvq72wd92 F0Jwm2oD2S5/hr8+L+4NyfMHxZX8Lo9vnkR47I//qMTXDfqwfQbNiuzLnlJb9c0d1Vmk SY2ai9l1u9V7pMCLqtwMx/4naW+NHZNKtayuSXDkEPSTw4Oq50rmEMHS3vhw6hKg5pOL nRsNSUd0mk0EX/kBI06Ppe2lHX43c0JTCPPaNTeuLch1X1hPsseR4QOwC53XbUCVEYKt bUk7OwvvsmJnT7+urrpbnt7SmBe07eXBxMr5j2shWUJCFnCHtSFXjUjWLZWo8aer5Kbr dsRA== X-Forwarded-Encrypted: i=1; AJvYcCVRbHQe8bRabusMUIJUFtiax1qZf6KnFRZpNZfB7GZjOIAV95S9g6xS0I3lnhyxe1etVFrOsvhAmRwl+7M=@lists.ozlabs.org X-Gm-Message-State: AOJu0YypR1Q5LFOi01PjZaXlBOALACn5JfCw1TTImyY+TI9dBy6v/v9n dD8WUqieKgX1Z7lkoZk2M3i1HcMrmzv0OJAtkX6Y4BKRDsX48eHrXHD9lVCsSoYngPNnrkcasbL yUvawjceEl//69OpeKVZtlQ== X-Google-Smtp-Source: AGHT+IE2HKYkuc89mtKU0bTUEVS1IdL7Se1Uvka0+Ku7HObHaGYamVyFYxuD0miLaBxiy9U265ART8wkxAXV/hrgFQ== X-Received: from pgbct5.prod.google.com ([2002:a05:6a02:2105:b0:7fd:356a:ef35]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7288:b0:1e0:d848:9e83 with SMTP id adf61e73a8af0-1e1ceb1006dmr1536938637.25.1733959687513; Wed, 11 Dec 2024 15:28:07 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:43 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-6-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 05/16] mm: arc: Use generic_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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Introduce arc 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/arc/include/asm/pgtable.h | 1 + arch/arc/mm/mmap.c | 43 +++++++++++++++++----------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/arch/arc/include/asm/pgtable.h b/arch/arc/include/asm/pgtable.h index 4cf45a99fd79..af3210ea4888 100644 --- a/arch/arc/include/asm/pgtable.h +++ b/arch/arc/include/asm/pgtable.h @@ -28,6 +28,7 @@ extern pgd_t swapper_pg_dir[] __aligned(PAGE_SIZE); /* to cope with aliasing VIPT cache */ #define HAVE_ARCH_UNMAPPED_AREA +#define HAVE_ARCH_MMAP_HINT #endif /* __ASSEMBLY__ */ diff --git a/arch/arc/mm/mmap.c b/arch/arc/mm/mmap.c index 2185afe8d59f..df01d4d9964b 100644 --- a/arch/arc/mm/mmap.c +++ b/arch/arc/mm/mmap.c @@ -14,6 +14,26 @@ #include +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + if (len > TASK_SIZE) + return -ENOMEM; + + /* + * We enforce the MAP_FIXED case. + */ + if (flags & MAP_FIXED) { + if (flags & MAP_SHARED && + (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) + return -EINVAL; + return addr; + } + + return generic_mmap_hint(filp, addr, len, pgoff, flags); +} + /* * Ensure that shared mappings are correctly aligned to * avoid aliasing issues with VIPT caches. @@ -27,30 +47,11 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, 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 = {}; - /* - * We enforce the MAP_FIXED case. - */ - if (flags & MAP_FIXED) { - if (flags & MAP_SHARED && - (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) - return -EINVAL; + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - } - - if (len > TASK_SIZE) - return -ENOMEM; - - if (addr) { - 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.low_limit = mm->mmap_base; From patchwork Wed Dec 11 23:27:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=qqF74snd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4012-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sHH3zrhz1yRR for ; Thu, 12 Dec 2024 10:28:43 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGh1Bmvz30Vn; Thu, 12 Dec 2024 10:28:12 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::449" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959692; cv=none; b=P0P4XlvXA378sLh0vLzayWfQOUCW1KHU+vKw7QuypMw4pUd6WpZjfQAovE5EnylwswXpMoHDKUR3USy575SkPXRWchI+zD/x9KQvhVbI8Gv+Lqno8nM34udzS/6zS7WRJ5RBlrZJNp0u6JwHjzpXdi/Nz2CX3/cqx7nJCT71TCSTiLsmohbbVQnxxsq473CK7lH51D95KKEze5kqG6ru0YIOBWLebzXvaNAsmnpiETEwkQHq4I9lG0jaE9MLJhTVkLNqrUA2BSpWbaH9RfFnSUdA05+LhHib2Zk8C+VQz++Wnu/7NpLwdq93ENcDZpwPAXgGu4M0h4880MisdJh2nw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959692; c=relaxed/relaxed; bh=My9IlOPq9ns5P/NZxzKqYlKU2U5PkE8SqDXKTXIHc1k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WdhSetH4hq4VPI86H4eoUcxVA5Of6VwCkuNgD9untHzTn7sKOjRi1H/gBH2wlzw3ilhadKHjfDd9DjwM0NH9OXoQVPXZTQ/hf+JEwV/D161t+OYNPrp8dj4fF+cVHlNTATYT24cQQJfik4Eg+NI9tg1KmjZI2cYkyw43FG82UJN4hRvUVtGt1YIIXYu6wCgwxqi+NhP918axEG4w8cwoU/M/4zji7otOQxPP9T+3ChLoNW+fT/Y8gpD5XuxzQL+uW64d3XBXaPXx9JtAAf044EOErDdIg6uhKcGzXNoA72vEiJvgjWbXeXiaJueH/lzJdIvaMp+Bc+4C02/vP6hddg== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=qqF74snd; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3csbazwskdpieufymbmchabaiiafy.wigfchorjjw-xypfcmnm.itfuvm.ila@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=qqF74snd; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3csbazwskdpieufymbmchabaiiafy.wigfchorjjw-xypfcmnm.itfuvm.ila@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGg1dZKz30TM for ; Thu, 12 Dec 2024 10:28:11 +1100 (AEDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-72739b83336so34837b3a.1 for ; Wed, 11 Dec 2024 15:28:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959689; x=1734564489; darn=lists.ozlabs.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=My9IlOPq9ns5P/NZxzKqYlKU2U5PkE8SqDXKTXIHc1k=; b=qqF74sndXTNyaD7hE2+1pEDlrTKeNRSMfNvK1w/S5k22+BM7MWn05a6zJVHbXanhYX aQU6pSc4BTa4FXqCbYyQ8m0CLTTz0MTeEaDIT7LUTSlQrfpF0Y/1yVkb0WH/cpReIlhk zbyLIkMrHpHkRfa7ips9uS6PeOTG72xDUm3BBEUauhDkFv4nICczUmHjSFVS1zzxCnOB cN5e2Wi3uX9xtZ6TzZep1WgU+IOkhZNCVOHJJRUBsZNg4i0SaZJ+xLLWa48zyxkTu995 dFh/D55qWkf8suwDSLMYNS4/F0B/o10fENI8HTjzr2ccr01gtbtRDcAgYhUqkDqYz/Ll RqKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959689; x=1734564489; 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=My9IlOPq9ns5P/NZxzKqYlKU2U5PkE8SqDXKTXIHc1k=; b=eeYR9xjv0QMOzci82Ga8kd0NpwW5em97Tw28xCYvbZ8HZYd7+ZIFu0w8REx16Mw2YF e4TkZhJGokQecP0BJBMR8xWuckvJ1o56OnvTPnbCij+1AyvXWBi6Ni7q6jRqnzmnz/tE s1U+YyybY5EoWSsEN0WgsAD5KCPn289/fS0hd4mfihtuYkOHP3VBSh23CqduqSYb3xRv ll9ea6d62haidXT3EX37pstbsBhZuptP9XeJon3SbrmxAQK2zKfiPwb1QC90XkAo+GpC L8uvY/cGl/vQ8DmT5WDR5967Xp3GcQYditDBFipPZAsmLx/jjBs7QyW85iWbOe67SGe2 LRgQ== X-Forwarded-Encrypted: i=1; AJvYcCWwGjgciyK0tCpgSxyHDdu3hl6/fgXtw8Fvq/5a1wO7cj9abZIk8QftofFfpnu29wVmZhwEtPVPu4VIwOw=@lists.ozlabs.org X-Gm-Message-State: AOJu0Yx+g87f2RZsywH7P64Ycagfvls0O5JsY895IgYwZCbDR3GjdvEe L5xLbcyhvV+5tFdRY2A0hdkVQ4gOGx0KogsMXX7BBFZPoqB/06MrdcRe9OjY/hYtfjIBlSVULvA gCi/FLO2F//L5jKsCKJNhgA== X-Google-Smtp-Source: AGHT+IHgv+hz6lUV53h1smjsDXGUMrAdu+yMyNI0Y1qN6skLJAQw6jBsC8TmY8m6/oNaMxzzcfOLndyqCxWrzR4uSQ== X-Received: from pgbee13.prod.google.com ([2002:a05:6a02:458d:b0:7fd:4d08:df94]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7890:b0:1db:e40d:5f89 with SMTP id adf61e73a8af0-1e1cebb5277mr1761320637.28.1733959689528; Wed, 11 Dec 2024 15:28:09 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:44 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-7-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 06/16] mm: csky: 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Introduce csky 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/csky/abiv1/inc/abi/pgtable-bits.h | 1 + arch/csky/abiv1/mmap.c | 68 ++++++++++++++------------ 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/arch/csky/abiv1/inc/abi/pgtable-bits.h b/arch/csky/abiv1/inc/abi/pgtable-bits.h index ae7a2f76dd42..c346a9fcb522 100644 --- a/arch/csky/abiv1/inc/abi/pgtable-bits.h +++ b/arch/csky/abiv1/inc/abi/pgtable-bits.h @@ -51,5 +51,6 @@ ((offset) << 10)}) #define HAVE_ARCH_UNMAPPED_AREA +#define HAVE_ARCH_MMAP_HINT #endif /* __ASM_CSKY_PGTABLE_BITS_H */ diff --git a/arch/csky/abiv1/mmap.c b/arch/csky/abiv1/mmap.c index 1047865e82a9..0c5c51a081e4 100644 --- a/arch/csky/abiv1/mmap.c +++ b/arch/csky/abiv1/mmap.c @@ -13,6 +13,39 @@ ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \ (((pgoff)< TASK_SIZE) + return -ENOMEM; + + /* + * We only need to do colour alignment if either the I or D + * caches alias. + */ + do_align = filp || (flags & MAP_SHARED); + + /* + * We enforce the MAP_FIXED case. + */ + if (flags & MAP_FIXED) { + if (flags & MAP_SHARED && + (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) + return -EINVAL; + return addr; + } + + if (do_align) + addr = COLOUR_ALIGN(addr, pgoff); + else + addr = PAGE_ALIGN(addr); + + return generic_mmap_hint(filp, addr, len, pgoff, flags); +} + /* * We need to ensure that shared mappings are correctly aligned to * avoid aliasing issues with VIPT caches. We need to ensure that @@ -27,8 +60,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long flags, vm_flags_t vm_flags) { struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - int do_align = 0; + bool do_align; struct vm_unmapped_area_info info = { .length = len, .low_limit = mm->mmap_base, @@ -36,37 +68,11 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, .align_offset = pgoff << PAGE_SHIFT }; - /* - * We only need to do colour alignment if either the I or D - * caches alias. - */ - do_align = filp || (flags & MAP_SHARED); - - /* - * We enforce the MAP_FIXED case. - */ - if (flags & MAP_FIXED) { - if (flags & MAP_SHARED && - (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) - return -EINVAL; + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - } - - if (len > TASK_SIZE) - return -ENOMEM; - - if (addr) { - if (do_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; - } + do_align = filp || (flags & MAP_SHARED); info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; return vm_unmapped_area(&info); } From patchwork Wed Dec 11 23:27:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=D6m+xtV1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4013-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sHQ0J2cz1yRR for ; Thu, 12 Dec 2024 10:28:50 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGj6Qszz30W4; Thu, 12 Dec 2024 10:28:13 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::549" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959693; cv=none; b=KfZ6jggJQ4MS7hGjW27DPADHopkRearofUIwcsf69EhTFs5dfyHOuZoWShuQmZMzHZtYRxzWheorZCUrXP1r0cinbVRwveSZuZPwyTcSVdT++SV25NorL8o3u5JTgmKu7UuGkGCAcmH7a6FgDpmQcHDkxezRHeXROFU3Lp/V2tbEKl4G2rIwh4zykxZ+UKXepRMU6ptHHdlll21kCZa1DYcoQc0pWy0DLmQxEz2MK3qHsk+cPNt/BrbCpjqsYutI8l8fuy+EZBq8NXGZasP1P7BjdcIUIkg5/oOfevs9ACDi+5I03zdY0E3XBazBgE1tGGsEOh+C3sXp/4KPfH3x2g== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959693; c=relaxed/relaxed; bh=SCptMPgkqno2A/YzE5Va18QE7zdNUHtEUd5zzpUozKw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HGZawAQc+WEu8y6s812PuvUJIRdvmJ0A9JQGTUzb+2CVxkvivTt4WQBlELtjdgLYJ/gQD43iqnLJiawRx6zyWZQCe9nayoKje3c1K4PkxfikgXZQQVRxVpTsnWkbH7dp0EyoymyTmgbDqcEdo7I8s6DQxQ+RflPtNZU7sHoEUG065QqQE+Dz8ncQGVsitrwfVKPdueIV+c3dbyz1C2LkHhUNAXTc5h8LcpslWTG//VteFLfzDGPfpwRAKbBgJFu2Mm34TkuW6jCm1Dm4T4ojV43FzXcMCGzu6q6DM8R2FdEiV8ngn79qfWgEtn6kjhvswhwxq3LVEVKY+ltqYFHWLg== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=D6m+xtV1; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::549; helo=mail-pg1-x549.google.com; envelope-from=3cybazwskdpqgwhaodoejcdckkcha.ykihejqtlly-zarheopo.kvhwxo.knc@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=D6m+xtV1; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::549; helo=mail-pg1-x549.google.com; envelope-from=3cybazwskdpqgwhaodoejcdckkcha.ykihejqtlly-zarheopo.kvhwxo.knc@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGj00X5z30TM for ; Thu, 12 Dec 2024 10:28:12 +1100 (AEDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7f71e2fc065so38259a12.3 for ; Wed, 11 Dec 2024 15:28:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959691; x=1734564491; darn=lists.ozlabs.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=SCptMPgkqno2A/YzE5Va18QE7zdNUHtEUd5zzpUozKw=; b=D6m+xtV1AAG3kNs464ytQA7dvvXe2+DtFjrYt/UTkLpuQuV8R4JgPSJ6NEu/GXLT3M rwXso7r+107lCa8AzFHfoMpqcJ1nPHS8vjnzLfojQ/Ia1gwfRPaQTiKWBk+93eWJNr9f T0IbD/0z2ZRHERbo+SHShZGm67vE9Z/rAEGLFlsauMKOgU+2roK8kWtbu/exAv5peB91 EcRoeJQsV1GQTP+Jgg5x1PACHPNJ7l40gEODDSKhDiJsyzFGOsoC2v0gxUxtfRy7LNxT SkT8LANxRj81TdvRgnws+nkNjCPE663t7KkgCjdn4aOSM00i2jnbwYSvoDYmCn8Z3V7B Hy1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959691; x=1734564491; 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=SCptMPgkqno2A/YzE5Va18QE7zdNUHtEUd5zzpUozKw=; b=nqNUIv5RWZpBC0WW1ICadzosyKkNqXNb1kuWKwwATSNf/WlSBWsjHly0YPUDnRfq4I i6K82rtlunOKqjigxDmrnH5PtW7GyUjn7mSwVu22X36LBBZatGIEGg+2GD5YHecptDIF Ola33jHanqIzwqu4KwV6ETmCmrAvKhVx488iECkX2w4szunkn6JngfGoesK5MuQAbcdS qEzifYm/N+fqqFYzMfgYSHbzBDVJkQNsI6HwKUnHqhwalCH0W7AQ5NxcEewnUr1/NIg5 SCDTPzJkrDRoVcsMkRePogx5svC+e0bJ7o1RNSJ2C56rxZ5aEdpSSQ5ahfV+v5JSd3J+ UPfg== X-Forwarded-Encrypted: i=1; AJvYcCU/yyxD0UYrOvklld8CchmMh1Wpr0soyEFVAZmB37884RRo19Ij2beZ9fIQqnAZ0jG485FhWmNy0vQgMhg=@lists.ozlabs.org X-Gm-Message-State: AOJu0Yyg7w0FwrC/P3ujNN/8S/PzP517cexE3erqAPkkbaxDuOC3I7V7 EDccgQ1IvR7INAq2KQwhVAA5zgnN0FyeWUGJcfElNppC+s3XoIwPuKMXgQYdnaY4EJoEAEbikRc rAwSBumhxM/kVArxyoGo4cA== X-Google-Smtp-Source: AGHT+IFbvN9gPDak20G0G+YmM9pMBv8oAuiEUiRl+GFZxjvR/H2lZBtc+wP+WVSCEq90xAWHwKXzIcf2MC+rzJKWTA== 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:6a20:e306:b0:1db:e922:9eaf with SMTP id adf61e73a8af0-1e1ceb2e4dfmr1374719637.27.1733959691453; Wed, 11 Dec 2024 15:28:11 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:45 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-8-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 07/16] 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, 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org 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 --- 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/loongarch/include/asm/pgtable.h | 1 + arch/loongarch/mm/mmap.c | 49 +++++++++++++++------------- 2 files changed, 28 insertions(+), 22 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..9e57bb27642f 100644 --- a/arch/loongarch/mm/mmap.c +++ b/arch/loongarch/mm/mmap.c @@ -17,15 +17,11 @@ 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; @@ -45,22 +41,31 @@ 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; + bool do_color_align; + struct vm_unmapped_area_info info = {}; /* 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; 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: 2021762 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=DPqtU1lw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4014-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sHX2myRz1yRR for ; Thu, 12 Dec 2024 10:28:56 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGn0yt5z30WC; Thu, 12 Dec 2024 10:28:17 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::44a" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959697; cv=none; b=ccJ4/eLjGyXepobcUVDs1K1Ip+bjEd0taTvB5ljj8QGtQ4NzDOOVuMAiPe4d9yMJlE7ibSWZFDYaszp2Y+J0JzfCFNbgtXFMJds/CMVbwk6aBviqrjQZwQCNYgDVjjEGGOMEX9TifR8jbrS2+icYZdmkRiPCdhJTcczFpnkGNhE/VBdlZQkoOIpRDSWXGQDjGB/gnW8DJZZ5cLwOEHumA+cJS2XL3cJYkZ7kmq8aAfOY+//aKd7MQnR6dHVo1o7hfsNJCyBIsyV9vrurJIwbkf3DyLCNQ6Q+Gf4knkc7uN//sdd5woxPRweetVbUxal0RjPmwXzmzWiLZF1tIb7mhg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959697; c=relaxed/relaxed; bh=lSyWTl6AgHPTeHZ5Av2U3d+7m6ogGk/gBzGXwo6uPmA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HhSlRZ44h3ZG5qe3pm0R/TiFYzTdf8w9Grvyt3KYWcSu+qwm6AtIbGO5/XXBZmzY9UAVnIMYQVin/JiouJELZa1m28tXM8G04aVciLzaJ1ZFrL5VpZJ3cGGSmQPUUWgwihe6TVzVfaLnJQQbUdp+vRnH42f+mmwVD1HvR+bSjxOMsgAY9bM327hkZVaQLE5chDIQUF8ugXZEL5DzfPN9LYsxsIZ0It2uO+Sh0xYRQWVOwxzT1z26oJ24X5ODGMFQIeGqG2M+pJ3jrLGt2cBuY/z1rJGaXZS3FYdcWzIB9kE6cbwVJZQxfD23Nth6sPwhPoTsBRLzm/jMkYSWP2LRdg== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=DPqtU1lw; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::44a; helo=mail-pf1-x44a.google.com; envelope-from=3dsbazwskdpyiyjcqfqglefemmejc.amkjglsvnna-bctjgqrq.mxjyzq.mpe@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=DPqtU1lw; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::44a; helo=mail-pf1-x44a.google.com; envelope-from=3dsbazwskdpyiyjcqfqglefemmejc.amkjglsvnna-bctjgqrq.mxjyzq.mpe@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGm1bmnz30TM for ; Thu, 12 Dec 2024 10:28:16 +1100 (AEDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-728cd4fd607so26644b3a.0 for ; Wed, 11 Dec 2024 15:28:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959693; x=1734564493; darn=lists.ozlabs.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=DPqtU1lwFfAzn3WURf1CCTXXIGMje7Q3oBFckpr79b/7xi+OQkw9h5FwA7y0RfKmwq kS0tyO8F/enHI8gXuBdimTg4ktioW+UbxfwxRCUrst+D94+8j67WfdjSYFAqMVdXrJPb xSoknHZSuOp3BF1fLL4IWjAO7rfeKFg6/WIrWnS7ZAGg/gcYVMs+7rInC9L4bd6G6Y68 VU9LDBfVsdarDEMxHMcwbbwtxoejqL3rF52eCy9dMri6ETzvQ9vKzRRrxHEQhsWFid9B TqbXP4Hx+q4u2S4cXPnnVsUCf4xoZsDV6OzI+YCcstl2m6rPAxtKaNfjoeoXF2K1oUA/ MIJw== 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=E14t78LB9SjuYWuhSQgmE7NAwRzLvR5JJdLkN/voxxZpgD9wdlsPWXvf5krkJItdLu o7F0mLL9POsnEg+UfPJSoj+LTI5TTjSIZThjtWUcB/2PFoDK5lSISenwSNlsVnkw40ke NBCPq+/5LCpkkbyw2k6mHUUCBA+dNyqFqF+N3hVNdtTz0gXubRn8f6Wjmg/doaPwcuRa wfoIekJwsuqDbsFyQNrpdKcVXtJsvzpzZTJW6Ra4rv2ae5Dt68Xnh/wl7ozbEe1im9FP 3/PUWDVqSxVHHOaWDMgMNrE3wem3o4UkvVpq8e6e1Ht3Aq+4LvcA6dqDLhpmrHoxHpFz h6GA== X-Forwarded-Encrypted: i=1; AJvYcCUAsoxR+p54uiNnONhAxL4ZifZy6uFvYGCCiSFhrCLdBDNE/3Ixh1UcIReXwBXF+rydbQqoVNLYnipT0uY=@lists.ozlabs.org X-Gm-Message-State: AOJu0Yxv0nC2R7xqiuI1kYuNicE9q8flqw8et1Q43+1ssCiR7k70izsk /00kQLibDj5q5rgcYWOILhskqs9gpI8sWpFFkHG9Pv7W04yauoMaj22E7wuE+rb5i5AK3V9h/xi I3hfS7ny5blbz1IckBogyUA== 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> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org 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; From patchwork Wed Dec 11 23:27:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=L5pSxMq8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4015-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sHf6hQTz1yRR for ; Thu, 12 Dec 2024 10:29:02 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGp0M1Xz30TM; Thu, 12 Dec 2024 10:28:18 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::449" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959698; cv=none; b=WS1WoiAyUtbr7DPwePxqRP6Z6keZUXtg0+vVnmsOa/vhZCoOskwCDTvOkCbagZk9ttWAO92MgsAkkhF/UbhK3R84AQT+aOAhe7reQ0zGPLzE+ROJMAIiGAjyKN4BpaUAoVZYIS+0uPxuThe85krqJGD5iH8IjsgxeudaNNq6N/sI22W+lJAAEAf4ZSOl1caRHuOKY8nFyCRfLVWspXsj/+lf0tGa0CDWIKvrLLMWFPOnpl73VvHCkS44nBYwO95z8nYYuiK7szGsuGjAxqetG24UdlzkroxrqX8izfrCL+OxkbpTH3Zk010lqlhOI1fC1Pg6qKNLinM/NcQNzY2O/A== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959698; c=relaxed/relaxed; bh=wxiw+xEGORRKxhtCLZq/pFo2CvQKmbacY9QkYe3JDdE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QxTxoDnHLmv93k4fGb8DA3EB4JjkpGUyr52GKuZr16Aq+4TkEThbcqArix6nfTjKs3Qhb/sj00looaX38kH764Pi9hTqmZX40u8QRlJd0KHtqKoc0VGfOO0mM3LSvVCX40IaY2RKGdQdmLZEAdIT+GLBQPBG/yjjcFEXCcDHYW4Fdpd1vVVkexwQ2M3cbbyy0RTev9WZAj4b2eL5i5Owu3a+QmS2pcB9x1lSevw9Sg4hUNEouFYirXCpglpWiQ9LWIVwnBemVlHDPyJndT72deLtr/BGpAdeJO+Gxet1fO1ZYBYFecKb1mdr0938bhdIado1ZzEg+tlEvGcyiQb2WQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=L5pSxMq8; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3dybazwskdpgpfqjxmxnslmlttlqj.htrqnsz2uuh-ij0qnxyx.t4qfgx.twl@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=L5pSxMq8; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3dybazwskdpgpfqjxmxnslmlttlqj.htrqnsz2uuh-ij0qnxyx.t4qfgx.twl@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGn2Kq0z30WL for ; Thu, 12 Dec 2024 10:28:17 +1100 (AEDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-725e4bee252so21383b3a.1 for ; Wed, 11 Dec 2024 15:28:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959695; x=1734564495; darn=lists.ozlabs.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=wxiw+xEGORRKxhtCLZq/pFo2CvQKmbacY9QkYe3JDdE=; b=L5pSxMq8QgxceUjaC3CkudWkzcWUBAq1OL8SZgG8DegiaAwJ3NapEyLS0evhk8cziP jWGZMGkjbkmyRvr7grC9INgDBBFGbORMSi7iKvnYShk3JiVHPlmdX/+mrTribIfQIgmI 279+YgkSih4vkVNZwhU+5Shw2BB8HMwUJ/so0W1VbVL6qE3GhQt8nYnFF2GA1asMtN1T 9MoJkow8qFSwQhnb88qul64hZq2Hs5wpn3lFG1RYXEw4tfmLoY6rEqdKqIzkeNCRpD89 w46xmwUrrL6aEZYv/PUoEw4VtbxAIXHGTYtRxcps5af0+dp8xie6qwNh5fCQXzQ6fPIE kn/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959695; x=1734564495; 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=wxiw+xEGORRKxhtCLZq/pFo2CvQKmbacY9QkYe3JDdE=; b=A1sPcc54aj2ABJZG+PQAV2SPyQwgWagDfVlOFgtgqMWI7ST789NPjdqC5v1hEHT/D8 kNmu+TallxfiBM9Rvx4fUH13IimwEaJ3FHAU7ChyAxkZiKil4cJH0puPXzF7a53TxIEq S2eMgPSdlU4NI20qg41HHBBmu3aQrfQEA26TLp4wR/+/anv0cP7qqy0hY/k9ZbeVIXzQ ZAGUCU+20TDmRlfLKoe9TWoRCpZzzixhfxBZ43fX8Leto+84u+jtkMJayw+Ru62CCtX7 JAVHlsU507L2l2Xj06T2dVVwuzMJWpWK9920kvhSqMdRUfigdUspi1oRDkp4nYK6KLr/ rUpw== X-Forwarded-Encrypted: i=1; AJvYcCWmpeOGIHQCq2iivx4GyjN8co++zphS3C/jeiBTLRFgwQ9RMSEHYTSG6k7zVUfA4DN9CV6xdS9irnxn1Ao=@lists.ozlabs.org X-Gm-Message-State: AOJu0Ywm10AcyIG+Z6Led3ek7uyKcShDGdLTj502R18ucGDZPLxRsr+d MJbktANsfTo+jlGrrRGdRlEjJ5ex0reYwJPy6dZnhmoHcC+VKByG61Y9Kk/JX7hOcN0MKQhh0iw Q1sUzIrpLHNrzMnTSZ3sbtw== X-Google-Smtp-Source: AGHT+IF4fNavDkLG8tRoFUmw2gnTJz71oU9t6WKhM2RNFmEQvjdeJ2dIL8s2CnxPdes2eHu66I58PC2AE4yum4CFsw== X-Received: from pgbdp11.prod.google.com ([2002:a05:6a02:f0b:b0:7fd:4c8f:e6a1]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:258a:b0:1e1:a829:bfb6 with SMTP id adf61e73a8af0-1e1cea52239mr1772079637.3.1733959695421; Wed, 11 Dec 2024 15:28:15 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:47 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-10-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 09/16] mm: parisc: 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Introduce parisc 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/parisc/include/asm/pgtable.h | 1 + arch/parisc/kernel/sys_parisc.c | 53 +++++++++++++++++-------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h index babf65751e81..73987357c78e 100644 --- a/arch/parisc/include/asm/pgtable.h +++ b/arch/parisc/include/asm/pgtable.h @@ -505,6 +505,7 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c index f852fe274abe..c1702d481e33 100644 --- a/arch/parisc/kernel/sys_parisc.c +++ b/arch/parisc/kernel/sys_parisc.c @@ -96,24 +96,16 @@ unsigned long mmap_upper_limit(struct rlimit *rlim_stack) enum mmap_allocation_direction {UP, DOWN}; -static unsigned long arch_get_unmapped_area_common(struct file *filp, - unsigned long addr, 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, *prev; unsigned long filp_pgoff; - int do_color_align; - struct vm_unmapped_area_info info = { - .length = len - }; + bool do_color_align; if (unlikely(len > TASK_SIZE)) return -ENOMEM; - do_color_align = 0; - if (filp || (flags & MAP_SHARED)) - do_color_align = 1; filp_pgoff = GET_FILP_PGOFF(filp); if (flags & MAP_FIXED) { @@ -128,18 +120,33 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, return addr; } - if (addr) { - if (do_color_align) - addr = COLOR_ALIGN(addr, filp_pgoff, pgoff); - else - addr = PAGE_ALIGN(addr); + do_color_align = filp || (flags & MAP_SHARED); - vma = find_vma_prev(mm, addr, &prev); - if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vm_start_gap(vma)) && - (!prev || addr >= vm_end_gap(prev))) - return addr; - } + if (do_color_align) + addr = COLOR_ALIGN(addr, filp_pgoff, 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 addr, unsigned long len, unsigned long pgoff, + unsigned long flags, enum mmap_allocation_direction dir) +{ + struct mm_struct *mm = current->mm; + unsigned long filp_pgoff; + bool do_color_align; + struct vm_unmapped_area_info info = { + .length = len + }; + + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; + + filp_pgoff = GET_FILP_PGOFF(filp); + do_color_align = filp || (flags & MAP_SHARED); info.align_mask = do_color_align ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0; info.align_offset = shared_align_offset(filp_pgoff, pgoff); From patchwork Wed Dec 11 23:27:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=F3VWo512; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4016-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sHn2wKyz1yRR for ; Thu, 12 Dec 2024 10:29:09 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGq5mMfz30WX; Thu, 12 Dec 2024 10:28:19 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::449" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959699; cv=none; b=BhDcp7YSMtCC4HrXvoEwnYZBd0/sLkM6IILiMhu5vXaIy1GhDfnyElq7OM4VEKWcme6DkkUkQ39H4yPIPQeIxxpEcDO1v1wzqlznW8HN9vQHo+0rVsqw+yJltnOvVkCSY6iYDlajus7TaB8dsN18U36SXRKEOv8wDpSJowKaR1uFF4GU+557KvvTWdD2C9tO0wnHEgByBAP1I8wmIxJao6TlqSvzQmD7J7c1ahA6mTEucWpLux/rsqbMupCk7IBDbiAPIIKT241q3y6aXYyWttEa1eDII+5TLB4iJ9H20bUltArOLyStmOvX4FM930pkAYs7llgyObrd0wZtNUY6Vg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959699; c=relaxed/relaxed; bh=6OFip67XXDkH1HTauBcRO/RiBVwg85LoldBpce5+fvY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JPw7sSlLSD6rS2iJg96w9NeXnhQML4+p/VfBSzhTa1v8jP/k+TsjyVCJ6q/BNvhJkDRQ6RQngM7E/aZT7/aO5U8HsH335X1t0TDevWrNmwZwRcrj/8NnOA7yY23XLpXIGnPzBt7M4toFgy1dRZh2CkCDd8ekQDU+pE4iroQupaAZnQ7cOQfVIxKjJUqUBPmeM2bGDz1BRiSl6d2GHvXb7zbjzcjLbWgUo4HJGpvDcrXXpBQgFXZ6Bvr8i4THk9obkc2441bRW/BuE/XWVWN4MgE/VtaFHI/D9oZDt4dSz8HlLAlWu3yyNoozEnXODcGYmaJR6+23QHL7pUBUNAki0A== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=F3VWo512; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3esbazwskdpomcngujukpijiqqing.eqonkpwzrre-fgxnkuvu.q1ncdu.qti@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=F3VWo512; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3esbazwskdpomcngujukpijiqqing.eqonkpwzrre-fgxnkuvu.q1ncdu.qti@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGp6MWLz30WL for ; Thu, 12 Dec 2024 10:28:18 +1100 (AEDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-728e177bc36so23366b3a.3 for ; Wed, 11 Dec 2024 15:28:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959697; x=1734564497; darn=lists.ozlabs.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=6OFip67XXDkH1HTauBcRO/RiBVwg85LoldBpce5+fvY=; b=F3VWo512klewYXnAcacYjD0lpbR1STJ+OAwe23tkOsNRRHU1qz9jsana2+JbPjwsAi hkfXOtAPEUIY2D+Vcrfo5HyuNNjikK+MzrAxW8ETpjJn+3PlpbM9w43O6kJ9uXpQOhv6 BCNiSQnBu3RB/toabXSeokvTTbidH3tBhrPeoWXhV8W3mn/ZBarFsYQnBraGj7EHc57a Dxn+4x2PStRSOPgJRDpc6xFoliBWQ3pNpqQ4Dm3nuj6n1cUbY4dW0Ul0c8sUoYYVEqgK gLHQ6sZmauJykKXu0tqQsrngUqW1gX8lHOHTbAVdcl1KPuOZn10SbQ/HyU6wWxRS+4ud nFPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959697; x=1734564497; 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=6OFip67XXDkH1HTauBcRO/RiBVwg85LoldBpce5+fvY=; b=OnYvcH0DVzBKG+DSOi4yrsQ96elorLBKEoTxBpGRWgYeLpdLN3VM9snyCH9EkJxVDO v+Zrs5pho/xzUNF49cERzt4wXGU9Tut7xb+0vvwmlVOsZEoidtMgOpUJcm7P20Px/2OL RLjG11AId3eBD2Yc+iah/1YI2NSUwA349zPU3bFaWwW/nW8rAVojAxTMqRzvXJ/FsHwj OBgyvz/NuJvsY4rL1ECbepI934wd0dvjuhCBAgqxV1wLhWdI+/Wk6dev8V/WBTzpUKfC 5DjRmBMAp1PsvjxQ9MiMpDWRvsMRQ1FsQ3PsfrIQWg2k/aOY0iSGLNu29gxjWQs8sen7 t8xg== X-Forwarded-Encrypted: i=1; AJvYcCU6aSgT3Dqqua2eDLxNuIzMXQT2rsZUiNteZTVYIGakuWaUABHOHU284rY+vuzmFiYTKUqnlhi3HzsRJlY=@lists.ozlabs.org X-Gm-Message-State: AOJu0YyqP8Hr+XmG8PHozEeQFwsPCuF9ZxBkFKlc6nkD0beDwxBNMlaQ Zrg7BBndLnsm10MG30Nzd/OrxFyH5XFGcmiPO2L6w3v721OP1QBChopNE+jDUrUeH5VJl5za9pZ 3fNExWlqxVDl3ABhrJMaqLg== X-Google-Smtp-Source: AGHT+IHidwQ3DrDPNLywyhRXMiEnGjaKCiBaEc5hXwYPZZjpJE9GCWopm3osDWhhLjTFzQGtE2yr4rptNlkPUN/bOw== X-Received: from pfbch7.prod.google.com ([2002:a05:6a00:2887:b0:725:e05b:5150]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:99f:b0:725:e015:909d with SMTP id d2e1a72fcca58-728faadfd6cmr1845767b3a.21.1733959697352; Wed, 11 Dec 2024 15:28:17 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:48 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-11-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 10/16] mm: s390: Use generic_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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Introduce s390 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/s390/include/asm/pgtable.h | 1 + arch/s390/mm/mmap.c | 51 +++++++++++++++------------------ 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 48268095b0a3..eaecb558ab9b 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1997,6 +1997,7 @@ extern void s390_reset_cmma(struct mm_struct *mm); /* s390 has a private copy of get unmapped area to deal with cache synonyms */ #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT #define pmd_pgtable(pmd) \ ((pgtable_t)__va(pmd_val(pmd) & -sizeof(pte_t)*PTRS_PER_PTE)) diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c index 33f3504be90b..8afb046605c9 100644 --- a/arch/s390/mm/mmap.c +++ b/arch/s390/mm/mmap.c @@ -83,28 +83,33 @@ static int get_align_mask(struct file *filp, unsigned long flags) return 0; } +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + /* requested length too big for entire address space */ + if (len > TASK_SIZE - mmap_min_addr) + return -ENOMEM; + + if (flags & MAP_FIXED) + return 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 mm_struct *mm = current->mm; - struct vm_area_struct *vma; struct vm_unmapped_area_info info = {}; - if (len > TASK_SIZE - mmap_min_addr) - return -ENOMEM; - - if (flags & MAP_FIXED) + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (IS_ERR_VALUE(addr)) + return addr; + if (addr) goto check_asce_limit; - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma(mm, addr); - if (TASK_SIZE - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma))) - goto check_asce_limit; - } - info.length = len; info.low_limit = mm->mmap_base; info.high_limit = TASK_SIZE; @@ -123,25 +128,15 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, unsigned long ad 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; struct vm_unmapped_area_info info = {}; - /* requested length too big for entire address space */ - if (len > TASK_SIZE - mmap_min_addr) - return -ENOMEM; - - if (flags & MAP_FIXED) - goto check_asce_limit; - /* requesting a specific address */ - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma(mm, addr); - if (TASK_SIZE - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma))) - goto check_asce_limit; - } + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (IS_ERR_VALUE(addr)) + return addr; + if (addr) + goto check_asce_limit; info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; From patchwork Wed Dec 11 23:27:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=vL7P4kec; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4017-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sHv59c2z1yS4 for ; Thu, 12 Dec 2024 10:29:15 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGt3Y1Mz30Wh; Thu, 12 Dec 2024 10:28:22 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::64a" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959702; cv=none; b=jtR+7YVlfhXjlpDxEifx9EPXe9l3nabc7Yw+5HWRl5z+qc9luGybH7zvTRI544r5T68obbSXBCr6LSh6urbVP1z2aEFil3mEKpjfwyC5qEcGH0ZGSGQzabWg5vQBpNf3l0VjIlYHwOFAZXzDwrhZUvF/bM5B2pQtvD3vKtfk1T9Rmk/eZqOvxo/aNJkTizwbSXf6d2bNNBulVcHKN7Emi+EgmMwtEV1kPFMPtUSiGzTYz/hODmDgXBZVPBka2yW5v7fExy3CdVQY/rBeZIQY89UMWZhAUDa2nuT8nbdHA6ZIrNfqTvsR7B/GKMtlr9W/RpB5188SQFngPHZfP/Aubg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959702; c=relaxed/relaxed; bh=uS3JA6w5wn3oIbxGMB+ie6BxkNausmcv0DhJz9a4fkc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=V7dEihRBtQRrUEd4QEl/Le0i/giQeMKSASwC4JkzLOckVaS4qOPZYvWLJqiLHx0EA0GpDfA6w/kVDkX4jZ3GBjbQ5BabM5ZWGC5LsLLf2lFF540x4llh1Rr8MChgyhS7MhE/2byh4YTHbRGa7HqpLZ87Yap5wxGhuLbiMTGm7mG1ALOG+1XEUjzta+i8JkNZfWRmTMn5Oq1mIN5+ZmaelgyUQVLve0iCaxInWBwtANtzAe0aE3Uzt7HjN5egrRZAL5Xvkp2Hm4KvJJ2mi+nr4iQBqwNZ75B2rYpGgI97qdc4xXwPaEQYbR5yXlMI71HeQDucXlH62I4g4YQzzrLTRA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=vL7P4kec; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::64a; helo=mail-pl1-x64a.google.com; envelope-from=3eybazwskdpwoepiwlwmrklksskpi.gsqpmry1ttg-hizpmwxw.s3pefw.svk@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=vL7P4kec; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::64a; helo=mail-pl1-x64a.google.com; envelope-from=3eybazwskdpwoepiwlwmrklksskpi.gsqpmry1ttg-hizpmwxw.s3pefw.svk@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGs4Xy8z30WL for ; Thu, 12 Dec 2024 10:28:21 +1100 (AEDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-2163dc0f5dbso34891995ad.2 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=1733959699; x=1734564499; darn=lists.ozlabs.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=uS3JA6w5wn3oIbxGMB+ie6BxkNausmcv0DhJz9a4fkc=; b=vL7P4kechnSW6j6a2cmFHcOCz32Uf8gIuCBEu+dQzDIr13HZYihjI5jqRL1vYUBJKb r6U8vxroBHN6zWo+5qrlcHamhni5XtzEd8JSFjII/7gpRtFT4Hz0UNZ8uvdCRt1Zyul8 maF9GMBAzaX9vc1ETllbddsQ2EsEdeJtVjCBcZF6GSgtmclgOlK64/rxSUhx8xmOB8gU 2XC+RHe7T4ZIlvhQ4s47mCNUM3buAZn357lRRtLBSg0qxruf6XFiUTH3TVTv3NHbFnrl Gq3uD06/B9xmEhLy8rlDX/PAd+aOOgpLIS2yg1Wtl0g8UOdwDjrq+7udS0M4T5RXs/ix ZlXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959699; x=1734564499; 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=uS3JA6w5wn3oIbxGMB+ie6BxkNausmcv0DhJz9a4fkc=; b=CQM8d9sUlMm5JvDAYPakAF0G7hsHq4R3Kk45Gm3hnSOQ0v9r1Ogk4UADGMDfnTwSI7 IG1UQiOSs87Ljvg1lSvzC/AeQGtrFvf/+ovk9s/hhHsenLSEGwcVHpZnuSGzTo1piGUR tlvDzP1oc7EhVeKM3YeDzvVeJQoLwP9SzFklQ58Aw2l7R0nXFDRu3K7M6Crzr2f9Maz8 hP7aByEyBOk7k+wIX+nfVKL3gd46S81a8l0c4CZx0/85+KGgow6nxy9+1fC/IEgGpPnA Vfw1/WTkZ++W3RlmQpjsR1sRRf8rAI0pCv2FYFuVwKGlIE7ZrHIsY+s1M6jFxj3HrCUq hG5w== X-Forwarded-Encrypted: i=1; AJvYcCWN/yoDhLg/4HHHUa2K5O2NORWrVYVPBDr1eTqkTz8zehpBeQde4gfr+3cx+DYqDEqzAUlu7uCKlg1SnaU=@lists.ozlabs.org X-Gm-Message-State: AOJu0YwNrgmtXKD6vvr2u78tWRnUrIlII0ju3n5N0Ezz97tnN+AguXUl YgqIgEZP1Gf+6xbJSx03wp/kTmxImfdMH2+qG4PMNwXQ21bGYH6u3hjnocqIfTc3QVwOo+0OZWG x5JK3LhmVzWi6voGDD2qEzA== X-Google-Smtp-Source: AGHT+IH7t7zoi6yI0PaPMLOJjSIpLoHx+Um10nYrD7SAuARxjRKOSw8DIf3dxsqs6hFZHoDsSpm8PlX4hDRCbsA6SQ== X-Received: from pgbcr9.prod.google.com ([2002:a05:6a02:4109:b0:7fd:4e21:2f5a]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d590:b0:216:7ee9:2227 with SMTP id d9443c01a7336-21778505a3cmr82109795ad.36.1733959699175; Wed, 11 Dec 2024 15:28:19 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:49 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-12-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 11/16] mm: sh: 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Introduce sh 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/sh/include/asm/pgtable.h | 1 + arch/sh/mm/mmap.c | 83 ++++++++++++++--------------------- 2 files changed, 33 insertions(+), 51 deletions(-) diff --git a/arch/sh/include/asm/pgtable.h b/arch/sh/include/asm/pgtable.h index 729f5c6225fb..072dbe038808 100644 --- a/arch/sh/include/asm/pgtable.h +++ b/arch/sh/include/asm/pgtable.h @@ -149,5 +149,6 @@ static inline bool pte_access_permitted(pte_t pte, bool write) /* arch/sh/mm/mmap.c */ #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT #endif /* __ASM_SH_PGTABLE_H */ diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c index c442734d9b0c..ebda962e8c4e 100644 --- a/arch/sh/mm/mmap.c +++ b/arch/sh/mm/mmap.c @@ -51,14 +51,14 @@ static inline unsigned long COLOUR_ALIGN(unsigned long addr, return base + off; } -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 mm_struct *mm = current->mm; - struct vm_area_struct *vma; - int do_colour_align; - struct vm_unmapped_area_info info = {}; + bool do_colour_align; + + if (unlikely(len > TASK_SIZE)) + return -ENOMEM; if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate @@ -70,24 +70,29 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, return addr; } - if (unlikely(len > TASK_SIZE)) - return -ENOMEM; + do_colour_align = filp || (flags & MAP_SHARED); - do_colour_align = 0; - if (filp || (flags & MAP_SHARED)) - do_colour_align = 1; + if (do_colour_align) + addr = COLOUR_ALIGN(addr, pgoff); + else + addr = PAGE_ALIGN(addr); - if (addr) { - if (do_colour_align) - addr = COLOUR_ALIGN(addr, pgoff); - else - addr = PAGE_ALIGN(addr); + return generic_mmap_hint(filp, addr, len, pgoff, flags); +} - vma = find_vma(mm, addr); - if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } + +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 do_colour_align; + + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; + + do_colour_align = filp || (flags & MAP_SHARED); info.length = len; info.low_limit = TASK_UNMAPPED_BASE; @@ -102,41 +107,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, const unsigned long len, const unsigned long pgoff, const unsigned long flags, vm_flags_t vm_flags) { - struct vm_area_struct *vma; struct mm_struct *mm = current->mm; unsigned long addr = addr0; - int do_colour_align; struct vm_unmapped_area_info info = {}; + bool do_colour_align; - if (flags & MAP_FIXED) { - /* We do not accept a shared mapping if it would violate - * cache aliasing constraints. - */ - if ((flags & MAP_SHARED) && - ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask)) - return -EINVAL; + /* requesting a specific address */ + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - } - if (unlikely(len > TASK_SIZE)) - return -ENOMEM; - - do_colour_align = 0; - if (filp || (flags & MAP_SHARED)) - do_colour_align = 1; - - /* requesting a specific address */ - if (addr) { - if (do_colour_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; - } + do_colour_align = filp || (flags & MAP_SHARED); info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; 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: 2021769 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=n4pHEmT0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4018-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sJ21fxmz1yRR for ; Thu, 12 Dec 2024 10:29:22 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGv0gChz30WL; Thu, 12 Dec 2024 10:28:23 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::449" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959703; cv=none; b=AEZJ88fgRF5D7g67270Lx19vwlKArcsKrlwR3rf6Si5emNXaPh6fangHXv5T10LbjrKrGhewNASCjBH+WRZyGh1tYb6AoFs9OFa7i/GBqkA54NNMnWnXloly7sWUoxKG2BIbsvTn4ei73YqsluO6vi3f2O31HEKQehleiozj8FVaFP6IjEvbeSlVet4kgp+tyRZoRsGle4pQ8khqRufnzFFtFwD16YA3sm4I+Y77kb8vwzrDmG9A2CxBDEv4y6pO7+7lOFfp6h8IcYdy5nkORIydUXLELVetncxuiF11IKZNxPwuzLVNhDhbLXTWlunKXDcc/f/+NRzLySwRZlhOMQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959703; c=relaxed/relaxed; bh=UgF7uGjYnhvUd+Jp5od3s3bWQayM3Oz+R04wRikqyig=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CUnAsG3MwPVxxSAkhaEnKWtbs1OlWHC+V5+7AFoS1fBBTRUTdVN6zDS83kMCQ19vmB3g+uwq68cBN6PnVHJ3o3kDmNBE2Ch+N50bMHSPsdCWMevWrNiyt4ra7/YvkR0Je3KnxEwN7Gtz+A6yl7rJ+OOI9ym6iSYqy/i2SXgrdOVAVaYm4Y0UlJte/Mp5NRDDmHAMiRsS3SO0ALnkAF7jNubymQ0+NfsTg/2oP2RqG2Ybl62oUJbSbeeC7SsvSQImsb8VoyOCnu4mvH77OTDq1yLigoXmT/mNg7T9VuJBHYQuiHvPy7p7+NbN+prLp/R2m6IG8BiPX4uJUlulUq3ZLw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=n4pHEmT0; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3fcbazwskdp0pfqjxmxnslmlttlqj.htrqnsz2uuh-ij0qnxyx.t4qfgx.twl@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=n4pHEmT0; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3fcbazwskdp0pfqjxmxnslmlttlqj.htrqnsz2uuh-ij0qnxyx.t4qfgx.twl@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGt2m2rz30Wg for ; Thu, 12 Dec 2024 10:28:22 +1100 (AEDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-728e4e30163so19462b3a.1 for ; Wed, 11 Dec 2024 15:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959701; x=1734564501; darn=lists.ozlabs.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=n4pHEmT0DQpmvsI6F4mBOZb3PZlkCjhzv3Grs8eYt5G2r1xgLPckGYw7Zvbd2zh0ho 0hmcdLBSnjqY1vj9iyj/XcuRJVYvsKuvoCnPld4dfd3A7j2FDscupk7Rk4l4p7YUKkSL FaMIx2P2Uqpl1PZQzDyQQNGQXrlIR8C8AAVSaebQCgKBE//x1lSniySIgTQnd8x0vCPo QAzZ17akOI46XhyhjCbl6FoU90XZ4MSSEEVRtlakfzTMV7douwoYtBoaF06/VQfN/HbT FFPfUrcMxT6YqIqk9HRa+DHUfsiV6N7Pzh9TseUHKMKJmX1u3pCtJzKH3ifS+jkZrlq7 ESOw== 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=YTvg2819xnNo88ms3GBpoBHetNvHsb9tlCBPh5AexgOsZe1fAI4SnklZAdjQUh1HI0 es4xtvcwebCosOlh4Da02XjUwO2Js2WmJ72RpIBiOKTg0LgfAEkh/gMfrHoknak99MhX mRQWPmMD9d7DUtcZWsRW6Q0PWjcwqUP0T0T9HBQnaurjJI4P2r9mMP2AiMFraNIRptNX NXqd16sXkXRir6Zs1rCWFCKRQMmWJllpZdRxEp2R1kLVNHlKvPsJFqqHW1Ml3PK2I3yD 1axl9z9Jes5HYP1uZg4b6Aa8jdfTh04hEChmLfhdwoPLwRBc/K2FYVbkjyu2xuaapc8r AXPg== X-Forwarded-Encrypted: i=1; AJvYcCWCIcmzSKgOQ3aIHukln8ZoCu3iBJCSJyKOmqfL+Y2dJ431o9r3hC77Y0qbpyM+qEyh5dULDhSq7Y8e2L0=@lists.ozlabs.org X-Gm-Message-State: AOJu0YxHtved0i4TnJXeq1NWX1c9PmaD3XeTPwfMFAT+YK2KwujdC49m NxzpzXaDGC20SD33SLmevX1u3+TIzjggUrVnsInX0kz0HdP6k+OL56ciE/C9QMchwm+i+Nz2X7E OnhOYxybak0l2F7Yh6T6lEQ== 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> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org 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) ? From patchwork Wed Dec 11 23:27:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021771 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=tc+UUjJe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4019-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sJ90yggz1yRR for ; Thu, 12 Dec 2024 10:29:29 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sGw5HLPz30YS; Thu, 12 Dec 2024 10:28:24 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::449" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959704; cv=none; b=bEovkpB4dqOfe6tO1U7vkHHZ9xN6720r8DOPa+LGw0XddlZhyzGfFm7Nc2glaQsOvv2Nb/V30GNk4WmvOlWdf3iBJXnkQYfhd44oOBYJAacKc204k/sNKVOejCiAe0tagVe9HxPjku2ayNdQOBERzqF3IBsJ8703EJvZQUxM+mca44jVBZ09qzvv5N2K5OkcbAVsi89Ia6Pr+4UqewIy1kiC64FIvgstZoRsNzhsiD4nZful5E96AliLaAUOHeSjd0Il7aYpv4wvij3FO9lZpUxhg93CGdzK1KWp6DHGNZJ3hhMRhP3vRzq9SrVhgKxhpqR34au3uZaWVWIWlUSr/g== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959704; c=relaxed/relaxed; bh=aLForDZ3L8G53NDE8CmnbZXOU/eHam8tpqogo1+J+z4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Kx1gar8lxL5MdTcIupEyTBrP3o/jJgWpQEOBfPqHhxrB9eQ68/4ajRKH+M8BIehDsBnLZEkbnZyzXapiPtEWuHVCSi2DAh4584bo6E2vU8sq5odtQmQzeVPJRgDUQGVYWN42e0yz5Ut0yZUqSCPbp39Lh/Rldh7JYOLMSyJosvepJ8SPEMjYg6yD0fuSWtMQjDIUFJAiCI/Hw3t8RQqwVs2BeJS3/rfdNiL19Rm8pU4B1cE05boPmGd/s9QPrFhgmfOGgE6ZF04CKKHBSUCrbkV6D33tWOZuGQzYLk5v3uWrvlLuZcgmk/b7qvS/zWMawVHgi9oTPFdcDSnnAE9Uag== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=tc+UUjJe; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3fibazwskdaelbmftitjohihpphmf.dpnmjovyqqd-efwmjtut.p0mbct.psh@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=tc+UUjJe; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3fibazwskdaelbmftitjohihpphmf.dpnmjovyqqd-efwmjtut.p0mbct.psh@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGw0QGlz30Wg for ; Thu, 12 Dec 2024 10:28:24 +1100 (AEDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-728eb2e190cso13280b3a.3 for ; Wed, 11 Dec 2024 15:28:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959702; x=1734564502; darn=lists.ozlabs.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=aLForDZ3L8G53NDE8CmnbZXOU/eHam8tpqogo1+J+z4=; b=tc+UUjJeW92BDxFTVHwePTWJatPfeLEl8Tlgk0oI0dEsOJve2LmfRJFmF+K21+B9Dq cHBxWzFdkgYo7eZcGx3K7nF7smAXq5znaQoDV4bxYSxN/i7eag5DCaD/8J/JlBL66mV0 a3MkougobBgV2ee+E54P6I/y7NpOHAitbqwP6XdQCYkJIqGFDttRUYivsOBQnl7VeC8J uKG0YcS2KiGLPYTCb1fhg/XnYGeIRZHKH2rfcdn7GgEc6sscP1V3xxTe5ApXMTJ78YdV d9kCMitTkPJh6+xPBfZRFRGWlekMIS+ceoU33+VbDEZndo/MjoagdqBEL7mshyvItnyd VqCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959702; x=1734564502; 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=aLForDZ3L8G53NDE8CmnbZXOU/eHam8tpqogo1+J+z4=; b=hnfFO8wUAXt96m33x8d5PpOnZdAjQ+CayRmIFIcEPSPTupTpGmefSJaje647ReeaAU L8g98i0DR/XxUaBVrMqsXTIacty04QFUouu3ucqovxOONktggWKuL3NtCKd9rwHq1azN YHDhVebRDTGtHjC9GxnJwc6arSaYsCVupsce3xHGOiwROrdH5NIjQtGZlnEItVqVnvtj NVgUiahgIJHACC7FC5uIi7T38uXkUfKEaSPsxiTbt59nWlPZPNaHUyuOuNhdsT90FUQe awxWvu30mg+Qn5547vMmLjjlE2iM6SAZ5hwPXbLF6MoTj00dfZJ1qiUprYSs6aCZZlfj oX5A== X-Forwarded-Encrypted: i=1; AJvYcCXWEVqD+M6sod7b783xU5wX3cxanwCuKkqdXwSYravqPNGK1Hj1xB6iVpPZ0na+MB9nJq9v6zRX5b4Ygmo=@lists.ozlabs.org X-Gm-Message-State: AOJu0Yxy3YvswfqcFG1xg8f0hZMggLCm0jNAK+l1TDNbNlrI7GxtxDCz 1iykEk1qBWObfLcGs5wZwqx5WrTXSeq3IGLbzHHunyTDf4vKDz536yzNq0/YulYezPEImwtE6Y/ y+CxbrQ+HSjPy61t6PHrLxw== X-Google-Smtp-Source: AGHT+IGWTEcN8NSoCgFvsRpfbkF7zue8+P2XAq5n+JVkXUUPL+bOWBEsvAKL/CZzz2D8WnFsu8nT+1urmYWqTc7eRw== X-Received: from pfaw10.prod.google.com ([2002:a05:6a00:ab8a:b0:725:ee5e:6efd]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:92a6:b0:727:3cd0:1145 with SMTP id d2e1a72fcca58-728fa9a8139mr1688780b3a.2.1733959702467; Wed, 11 Dec 2024 15:28:22 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:51 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-14-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 13/16] mm: sparc64: 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Introduce sparc64 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/sparc/include/asm/pgtable_64.h | 1 + arch/sparc/kernel/sys_sparc_64.c | 96 +++++++++++------------------ 2 files changed, 37 insertions(+), 60 deletions(-) diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h index 2b7f358762c1..f24a4eb2777b 100644 --- a/arch/sparc/include/asm/pgtable_64.h +++ b/arch/sparc/include/asm/pgtable_64.h @@ -1148,6 +1148,7 @@ static inline bool pte_access_permitted(pte_t pte, bool write) */ #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT /* We provide a special get_unmapped_area for framebuffer mmaps to try and use * the largest alignment possible such that larget PTEs can be used. diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index c5a284df7b41..e44d55b30a84 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -98,17 +98,19 @@ static unsigned long get_align_mask(struct file *filp, unsigned long flags) return 0; } -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 mm_struct *mm = current->mm; - struct vm_area_struct * vma; - unsigned long task_size = TASK_SIZE; - int do_color_align; - struct vm_unmapped_area_info info = {}; - bool file_hugepage = false; + unsigned long task_size; + bool do_color_align; + bool file_hugepage; - if (filp && is_file_hugepages(filp)) - file_hugepage = true; + task_size = test_thread_flag(TIF_32BIT) ? STACK_TOP32 : TASK_SIZE; + if (unlikely(len > task_size || len >= VA_EXCLUDE_START)) + return -ENOMEM; + + file_hugepage = filp && is_file_hugepages(filp); if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate @@ -120,26 +122,29 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi return addr; } - if (test_thread_flag(TIF_32BIT)) - task_size = STACK_TOP32; - if (unlikely(len > task_size || len >= VA_EXCLUDE_START)) - return -ENOMEM; + do_color_align = (filp || (flags & MAP_SHARED)) && !file_hugepage; - do_color_align = 0; - if ((filp || (flags & MAP_SHARED)) && !file_hugepage) - do_color_align = 1; + if (do_color_align) + addr = COLOR_ALIGN(addr, pgoff); + else + addr = PAGE_ALIGN(addr); - if (addr) { - if (do_color_align) - addr = COLOR_ALIGN(addr, pgoff); - else - addr = PAGE_ALIGN(addr); + return generic_mmap_hint(filp, addr, len, pgoff, flags); +} - vma = find_vma(mm, addr); - if (task_size - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } +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 = {}; + unsigned long task_size; + bool file_hugepage; + + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; + + task_size = test_thread_flag(TIF_32BIT) ? STACK_TOP32 : TASK_SIZE; + file_hugepage = filp && is_file_hugepages(filp); info.length = len; info.low_limit = TASK_UNMAPPED_BASE; @@ -164,49 +169,20 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, const unsigned long len, const unsigned long pgoff, const unsigned long flags, vm_flags_t vm_flags) { - struct vm_area_struct *vma; struct mm_struct *mm = current->mm; - unsigned long task_size = STACK_TOP32; unsigned long addr = addr0; - int do_color_align; struct vm_unmapped_area_info info = {}; - bool file_hugepage = false; + bool file_hugepage; /* This should only ever run for 32-bit processes. */ BUG_ON(!test_thread_flag(TIF_32BIT)); - if (filp && is_file_hugepages(filp)) - file_hugepage = true; - - if (flags & MAP_FIXED) { - /* We do not accept a shared mapping if it would violate - * cache aliasing constraints. - */ - if (!file_hugepage && (flags & MAP_SHARED) && - ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) - return -EINVAL; - return addr; - } - - if (unlikely(len > task_size)) - return -ENOMEM; - - do_color_align = 0; - if ((filp || (flags & MAP_SHARED)) && !file_hugepage) - do_color_align = 1; - /* requesting a specific address */ - if (addr) { - if (do_color_align) - addr = COLOR_ALIGN(addr, pgoff); - else - addr = PAGE_ALIGN(addr); + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; - vma = find_vma(mm, addr); - if (task_size - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } + file_hugepage = filp && is_file_hugepages(filp); info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; 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: 2021775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=P840lK1x; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4022-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sJX2wv0z1yRR for ; Thu, 12 Dec 2024 10:29:48 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sH41Nh7z2xrb; Thu, 12 Dec 2024 10:28:32 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2001:4860:4864:20::4a" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959712; cv=none; b=Tb9F8/jJbZXzv+M0xTePCAPR62nFU0r0GSig+/MZOOsRKbW/gZjCFhjlEbXWRHrqTMKnwAaE+m6DGQ4Y6YnnfFFsdkcSukFm4t8uBD+YdKGTIHBDkc0G2KQ4SxzScUNg1vX7VSTzmhw1alYzbmwFDEu4EjGH4NSihRMRuc3WHBZpQvEy1kB+NYYx8nueA4eTlJT2bUZ7dxBfcU68YmENj2k1bGNeaseJDafy3C7zxyDTkWpuFBQOBZeifMxIpL1ySVUdkOq4V/GsYJdyO9BAE39jHP6HAMPeZa6n19Qhz49Jl2VjNqympcqngyYyGtc8ibtnCdnX5Bhqe/E5F3EiIw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959712; c=relaxed/relaxed; bh=z6Hm5oOLdBb7ho6/nkMyyfkvkknoYZ/+aPdlC1ktc9c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ILLqdY1QZRsL2cyAq27AQEvYbl5NnfHd7PusAtitJhkGxQZxue38x2EGduJloom+q1FxrHGOrSP+huZ12mcwNz6xfKfZDkH0345L+9GCRjGix0J+J206Y7WxPJzIg84Q06af4Ae388pW1vc1LHCFPifxy26Sy6l5CkXl9YC5rhm06zpjRwhPxXORDVi01gyqEGJr29bla3ABASsP3SbpVAxF3qTeWMw55fr3mxXHJbBuVtM3azxYc1/8l6RvjKwaKZ1gDvabZgWtt5JT3Bzg7A2i/Izdl/1HULUEUyXR0vBQux7t0OcyPbnRZvDfJ2GkY5CimWZgy/IrqcsM38jvFA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=P840lK1x; dkim-atps=neutral; spf=pass (client-ip=2001:4860:4864:20::4a; helo=mail-oa1-x4a.google.com; envelope-from=3gcbazwskdamndohvkvlqjkjrrjoh.frpolqx0ssf-ghyolvwv.r2odev.ruj@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=P840lK1x; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2001:4860:4864:20::4a; helo=mail-oa1-x4a.google.com; envelope-from=3gcbazwskdamndohvkvlqjkjrrjoh.frpolqx0ssf-ghyolvwv.r2odev.ruj@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-oa1-x4a.google.com (mail-oa1-x4a.google.com [IPv6:2001:4860:4864:20::4a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sH31lbfz30fd for ; Thu, 12 Dec 2024 10:28:31 +1100 (AEDT) Received: by mail-oa1-x4a.google.com with SMTP id 586e51a60fabf-29e5f045c93so13204fac.0 for ; Wed, 11 Dec 2024 15:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959704; x=1734564504; darn=lists.ozlabs.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=P840lK1xaj8iE+u8jwhNlJ9HWqZIHQQ/YcIF3AC3iednBcTPCvcc/1p8D7jO+d+SWk /13dCzosWrZMd7WdTah4Hnkj0Fwab9iW0h3cZW3sj0IYVXahxdai1wlyHfnWGS5kQXTI UnWJb3A5KVGSc4YqiuANlb0aXjx9CsIwfNv/n5gksjCjEhB7y2TmtG3yK6/xjRvuZCUA wP7VYvc3zfd32e9h/eBsNEYJVl521+mD3ZXT0M6BXtQ5S60fV3HZDgshVAiiTbkdlbPl zWzae8Ic7oBtFA6SbdlNYGFra1+AKGawydYg+6r1Xfe4IDkKFQFWv7V2QnzT26ED/aCP VY6A== 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=MyndME2majCJ1E1TRL8dnaHp9UuUlFaCJ80rayxMppxUv6qiyjBUc1x6s0jJr4kyPG 2C9zXZHZAzXYqB3Lo3NPKDfbQgFMR4l6Nr7sMlEKKYyeJ3dAdxmjVwmMW11vGBdbyUhS hT+kYmlZRANiwXJ8CCup38cGqwUE7FrwpeeJRfz638i8uF4xEftAsQhTZh7qg19N4Ww5 Tj7QOZ2+wna7LuHY/Gfp4mAH+wkDJYPoHC1ZjAW6c+yRNlV8s846wn5crGpHMc1N+g+V 1e3ZGnj1Cm24caeh5AqFxAFYQWqy7KPoCR95RGyZDpoD2kOc7h/YhrKjfseJNmjANI2K 33bQ== X-Forwarded-Encrypted: i=1; AJvYcCVlwi3LrihvKQ0HLQipPpjd7n6V33GJb9L7XyqBtjbwp2JCSL7VlMdgiOL+Hy+HSV2sYHR8fGgINtHIBJM=@lists.ozlabs.org X-Gm-Message-State: AOJu0Yzj4/aRmjvtBSb/2XpgW5o9RQhyI4CNVUqrtugQSwouUEprI+nQ wZYAJcRs3fNJjoQ6/DytChFUHXNRNs2F7w4v/jEeTg3RbOr6XzYu+QoxzrLbk+ZAMGng9syVjCE kxlGYrdiELj/T384M2DMLpQ== 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> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org 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). */ From patchwork Wed Dec 11 23:27:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021772 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=BWt2EFmS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4020-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sJH6LYFz1yRR for ; Thu, 12 Dec 2024 10:29:35 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sH04fr2z30TL; Thu, 12 Dec 2024 10:28:28 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::449" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959708; cv=none; b=m0A/WzJbcwsl3BGdTyXXh4aJDMJ4flNLcRf8dfIUYEIjKa/dIW5ZIBGH50SuoyIDBpaM8f0beoEu6FxUiTe9+vIsqFYC7zwK5nz2DSS5WED0DbKQCm5dMM/+RgrS7/xkx9qlgnLIBzLSh2ST4j5oonYO7e6OhqFXFU8q9gW/acLUOLQht8m+D9Btq4hXtaD5lFb5TQUTEiCaLpEmWKOk1MAqldxluiwQisDoRd61fRvDR24riBLZCWv4AvITVLiweSBtJldbAmnfMnSmN+2kxBWS2n8T9/gS1jtjcbf6OSjlVwr5I+f3HCe9U5KzxN1CMzrYuOEu4MJ1IWGwfmGhtg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959708; c=relaxed/relaxed; bh=mzI/WChqoEagnx9fXIUsiKk2yVJ1VLNiv4KjzJVNd2U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Myt2XqGCvaEsdrXj8h75OLk3/ML/eMkCgekO0+iw0bgAm3x8gEP709361IYo44Xu/cmsVHUo/3eTS/J2P3U8YfAGUOlIjU77TjPL24s2I4Xo3bXmLOd7/TAHZrHwAF3CL2C1dO89+xPN7kQw+ZC5+IUhym8qchj0BBiqK/vJaBTW6mt/JPol6iOD6d9uZ7R54zucF6SuQkXcBId/UPfVZHUhHX/IuuBt+08uSyU2+lKhCOJqouS/hSJF5R6nSERxqvkRiip68r7TzV9IcvgieTapeIe/FqgUVj49Y0Gh7bH2h0c/PDD+zlzAxp31MwgVLcIbpfw8njzM3+7c29/Ruw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=BWt2EFmS; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3gibazwskdaupfqjxmxnslmlttlqj.htrqnsz2uuh-ij0qnxyx.t4qfgx.twl@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=BWt2EFmS; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::449; helo=mail-pf1-x449.google.com; envelope-from=3gibazwskdaupfqjxmxnslmlttlqj.htrqnsz2uuh-ij0qnxyx.t4qfgx.twl@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sGz5Cfyz2xrb for ; Thu, 12 Dec 2024 10:28:27 +1100 (AEDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-728e4e30163so19539b3a.1 for ; Wed, 11 Dec 2024 15:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959706; x=1734564506; darn=lists.ozlabs.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=mzI/WChqoEagnx9fXIUsiKk2yVJ1VLNiv4KjzJVNd2U=; b=BWt2EFmSsMeQgBk7nJ+b9XPl0/TE44TUixJMXOFWwO9BhzIz+7U8gpya+njO592raa sqzEJcA7QdRMC6HU6OZvSe1rqPvFFr3Gtl+XsIR1EhQrG5ExKmAKlZtnmyXQXcXzNuli SWH9Db/o8Pak903o9Pd4cmPT4uZ2nmKFFX5c8Pgm2lvdCKLdsU4p+hn34SV/qAii5lvf aepzjtCH9UfPFjXruzHcuadaxIriMe2vMJhuetH9iqvQEAt6B/FdEwgqsOftHBiJwrqu oWdAus39yWfcbZUkHXybYayECz9nrLCARizu65H8otA7SbIv1CJnKtGuWtQ2D3q3DMkw 9OXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959706; x=1734564506; 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=mzI/WChqoEagnx9fXIUsiKk2yVJ1VLNiv4KjzJVNd2U=; b=pwhLXK1Uaj3tdEx6m6dSD7Hbpv9CIzcwiHk3/rEgiXvYyC7bYbNDB4UwCdQsBSjTih UYmk/VjT2vkl+kXg1BDsQZrVPSQE7OZi/boccnh+snxqv5mAzbENbQzyCp+HNpAw4dUm 0de83buziEcNtCX6W1heALLXSlLVmQtORGVnZF6GlfA97sAOjwS+Llyk2mGEiX7Z2Gx2 ZQkEE5zaf7kPnf86jYVi0HVphOxGBnz+DSXwfPSnhpmKAQHYGkuFgqIjiRMA9TBKbwA+ z4od+NelJGMjxBUcWg8xES8Ylfr0+HoOpv16o0uXz4Xk1LIen23HN9P5Un9U8YskdxAK GmJA== X-Forwarded-Encrypted: i=1; AJvYcCX6abMfXXtLSPGqgdAMOZ22/dr9RBlMwsILWY36ceo+/TwldnHzyK5gu+PwiZOh3v9WvpCa78CXt/VNwTA=@lists.ozlabs.org X-Gm-Message-State: AOJu0YyyO9+z52hEF7liFrxAkbvpBtJi6QYvBQKz5Q8pfAbjQZBaQCKL 7ICCtxchLlmFitlOPL3prAFVOTRk9bgjsIGeN9Hiyzstpf8l8dk8+idg0KzKu9B34Zw2i2toMqd 4lp9oLUTEkujmBTcE6zr2Jg== X-Google-Smtp-Source: AGHT+IGnJnRJXQZ5IIc8W3PGTGxBtDfE/sIYeRjCrJpkHMTtOgcOp40OoEyKbTRESGUAjOdqxtzUpt2F+EP39npdAw== X-Received: from pfbcw14.prod.google.com ([2002:a05:6a00:450e:b0:728:e4d7:e3d3]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:a10d:b0:1e1:aef4:9cdd with SMTP id adf61e73a8af0-1e1cea82ca5mr1784516637.1.1733959706098; Wed, 11 Dec 2024 15:28:26 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:53 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-16-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 15/16] mm: powerpc: 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Introduce powerpc 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/powerpc/include/asm/book3s/64/slice.h | 1 + arch/powerpc/mm/book3s64/slice.c | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/arch/powerpc/include/asm/book3s/64/slice.h b/arch/powerpc/include/asm/book3s/64/slice.h index 5fbe18544cbd..89f629080e90 100644 --- a/arch/powerpc/include/asm/book3s/64/slice.h +++ b/arch/powerpc/include/asm/book3s/64/slice.h @@ -10,6 +10,7 @@ #endif #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT #endif #define SLICE_LOW_SHIFT 28 diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c index bc9a39821d1c..b4067c57c778 100644 --- a/arch/powerpc/mm/book3s64/slice.c +++ b/arch/powerpc/mm/book3s64/slice.c @@ -647,6 +647,37 @@ static int file_to_psize(struct file *file) } #endif +static unsigned long slice_mmap_hint(unsigned long addr, unsigned long len, + unsigned long flags, unsigned int psize) +{ + unsigned long hint_addr = slice_get_unmapped_area(addr, len, flags, psize, 0); + + if (IS_ERR_VALUE(hint_addr) || hint_addr == PAGE_ALIGN(addr)) + return hint_addr; + + return 0; +} + +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + unsigned int psize; + + if (!addr) + return 0; + + if (radix_enabled()) + return generic_mmap_hint(filp, addr, len, pgoff, flags); + + if (filp && is_file_hugepages(filp)) + psize = file_to_psize(filp); + else + psize = mm_ctx_user_psize(¤t->mm->context); + + return slice_mmap_hint(addr, len, flags, psize); +} + unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, From patchwork Wed Dec 11 23:27:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 2021774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=cZGcrz6D; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-4021-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y7sJP63tFz1yRR for ; Thu, 12 Dec 2024 10:29:41 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y7sH30cVGz30fM; Thu, 12 Dec 2024 10:28:31 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::54a" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959711; cv=none; b=T/ewTZPjL1BHi7DAc1rLiPulsHAm9jQumXwbQ4/kxE54SMHJ4uH+/ZR7ld+4TLaui+lm/x3wxWfIcL3Qe6CY8GpW+ggtpDPo/d5dihcgZLjNDyWOzeohd2hT9tWv7I1DgNZfhH1T6qHvsT2DH4naKI9ALDiPIDOOA9PI3sQPIXqz8fIRpITRXpMowcHXVc0MMC5sWZ2aiMY07Lu5UR41ZM/B6lnS0ba2JtkBEWyjn0Q7m2xTnwQIoPjhTzsR/rd1fl1u6lXbQYH68k/XBHvp3hMVcMuDZxRyeNLeLGtyLwu+i8uwwz7jKysB79o+Sa3xJMbrtUELj52HcVyE5p6tOg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1733959711; c=relaxed/relaxed; bh=oHbDZ++mGE8tEdFCxijZAS2pZkYuZT5989Fg2aOx0oY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HSaE/sgyCSbGWDGcx5aUHp6pMDjk8GPC3gLzeb05E96DFxgSnpvc73Ia0abjZ11u8FGXuWw31SQwE202i4ciBTxCZUeIHR2197NjlEZeNwpIHVwFnSV1qA5QfAkem1VSz/yYO+1rz3pYmAcUeG2iWxPGUrRSZ/VQBwZkvjr6II5HKpMZd4WuqOFBMZEgrXBKqKtd0Ejjl6iV+iTm7NbwRmneqx2oAEtO+UsaPzR36QGJ6KXWG1H372KVHvZ/VEykmLHkMmwIfPwVNzmiK19MXVTwsliOsct46LQT0KzvIU+WPBOZO0pz231hW4Rnx66WySHmbkkw8uk9JDdv4+PCbA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=cZGcrz6D; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::54a; helo=mail-pg1-x54a.google.com; envelope-from=3hcbazwskdacrhslzozpunonvvnsl.jvtspu14wwj-kl2spz0z.v6shiz.vyn@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=cZGcrz6D; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--kaleshsingh.bounces.google.com (client-ip=2607:f8b0:4864:20::54a; helo=mail-pg1-x54a.google.com; envelope-from=3hcbazwskdacrhslzozpunonvvnsl.jvtspu14wwj-kl2spz0z.v6shiz.vyn@flex--kaleshsingh.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y7sH21k5jz2xrb for ; Thu, 12 Dec 2024 10:28:30 +1100 (AEDT) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-7eaac1e95ffso33106a12.2 for ; Wed, 11 Dec 2024 15:28:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959708; x=1734564508; darn=lists.ozlabs.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=oHbDZ++mGE8tEdFCxijZAS2pZkYuZT5989Fg2aOx0oY=; b=cZGcrz6DbhlSTLri9mgHgB+paA4jcc1Xh07Lsiw/HC27gXDCB6i6m0Py3vwlHtnSkL H7BVXIPgFTNuKnxRkOrO3dq3VXvQ67D3GLNoAR/VRCQFLoFDlW6wA0TMUxOO1MKas35n wFw5V4sqbRneGEQTVKyUftQRMUVVRaErxMZy20JBnG0Br2C+hHMsDczcQVlTmHg98+vY kY3OKudWCEVneQqbSA5+1+1BYTf/sJbRNineW4ByoeFLUhzmOPRQICvtR3KNEucQ5cWl oWzeYChhMT0rMj0fYBGFQKv3lSd2ngLhJgHDiUyLe4kN5Z+SFzVOcm46muz6zHnFMDaC uBgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733959708; x=1734564508; 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=oHbDZ++mGE8tEdFCxijZAS2pZkYuZT5989Fg2aOx0oY=; b=Tpolttm5YR4UwZr+H3HR0f6a3YoxVW13DirsBdep/NIlF/F2W6SBZJXIc81qnqwH4b MCljvLaA0b9W5+fZxCvwi5/7uV/JD5gF3Q8Nd9hSmonQ6o+IeUSdzOXBX4AdeZPBIpnw KSJkJMWT3Pip1daHFigjZ7x7d6hQVhuKdUYMGs2OnFctj3QJDg//tyCy1387nZNuShXQ YfOQLvx8PnAxZ9c13eDxDjr2fHeGUH0ujAlwtcuugZUsADwr+4qVD7261wtH/Mv7QQTy FcUE2ROTUTrxWkM/XLJdhhIm9IDNJ1Z/IlxPK/KeZG6/gtnDMbALaAlgenOZQHVos5Dt 94Gw== X-Forwarded-Encrypted: i=1; AJvYcCUz8V95Dnotmz7dN6Zs+s5RhAptxG/9qSXnwdglFnPSiVV9xX+mlXZLhq12mSrmqUu4IlJFw+uY2hhEFZ8=@lists.ozlabs.org X-Gm-Message-State: AOJu0YxNhnCLakQk6PGisW5uZYgfIc8+3/Oa3nopdY8me+XQ55jHDJu2 H7FP0aVUvIh33WxkmiRoMcgX+t2qMO5j4AHpP8e6TSl1LlxsEsY8bV8AJbm19fkkFlN7+faMvrL V1AewDd82ym3Wi/dHBd41Kg== X-Google-Smtp-Source: AGHT+IGlmctwmnr0LOvk4eyOoUS2Mz0NPFGCSegKhSqs8wGodxRb0W3o7XrsirlslhQ66CcLZRwSCG2H88EXSdEssw== X-Received: from pgbdl12.prod.google.com ([2002:a05:6a02:d0c:b0:7fd:1eba:c2dd]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:150b:b0:1e0:d89e:f5cc with SMTP id adf61e73a8af0-1e1ceaabbb2mr1312325637.11.1733959708164; Wed, 11 Dec 2024 15:28:28 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:54 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: 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-17-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 16/16] mm: Respect mmap hint before THP alignment if allocation is possible 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-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Commit 249608ee4713 ("mm: respect mmap hint address when aligning for THP") fallsback to PAGE_SIZE alignment instead of THP alignment for anonymous mapping as long as a hint address is provided by the user -- even if we weren't able to allocate the unmapped area at the hint address in the end. This was done to address the immediate regression in anonymous mappings where the hint address were being ignored in some cases; due to commit efa7df3e3bb5 ("mm: align larger anonymous mappings on THP boundaries"). It was later pointed out that this issue also existed for file-backed mappings from file systems that use thp_get_unmapped_area() for their .get_unmapped_area() file operation. The same fix was not applied for file-backed mappings since it would mean any mmap requests that provide a hint address would be only PAGE_SIZE-aligned regardless of whether allocation was successful at the hint address or not. Instead, use arch_mmap_hint() to first attempt allocation at the hint address and fallback to THP alignment if there isn't sufficient VA space to satisfy the allocation at the hint address. Signed-off-by: Kalesh Singh Reviewed-by: Yang Shi --- mm/huge_memory.c | 17 ++++++++++------- mm/mmap.c | 1 - 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 2da5520bfe24..426761a30aff 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1097,6 +1097,16 @@ static unsigned long __thp_get_unmapped_area(struct file *filp, loff_t off_align = round_up(off, size); unsigned long len_pad, ret, off_sub; + /* + * If allocation at the address hint succeeds; respect the hint and + * don't try to align to THP boundary; + * + * Or if an the requested extent is invalid return the error immediately. + */ + addr = arch_mmap_hint(filp, addr, len, off, flags); + if (addr) + return addr; + if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) return 0; @@ -1117,13 +1127,6 @@ static unsigned long __thp_get_unmapped_area(struct file *filp, if (IS_ERR_VALUE(ret)) return 0; - /* - * Do not try to align to THP boundary if allocation at the address - * hint succeeds. - */ - if (ret == addr) - return addr; - off_sub = (off - ret) & (size - 1); if (test_bit(MMF_TOPDOWN, ¤t->mm->flags) && !off_sub) diff --git a/mm/mmap.c b/mm/mmap.c index 76dd6acdf051..3286fdff26f2 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -814,7 +814,6 @@ __get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, if (get_area) { addr = get_area(file, addr, len, pgoff, flags); } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && !file - && !addr /* no hint */ && IS_ALIGNED(len, PMD_SIZE)) { /* Ensures that larger anonymous mappings are THP aligned. */ addr = thp_get_unmapped_area_vmflags(file, addr, len,