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: 13904368 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76AB11F2C50 for ; Wed, 11 Dec 2024 23:28:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959683; cv=none; b=d7uS+k2DSSeIZb0DH6I64U2C+6Mbd0iprXe//or0++p1j7mr46VmG3fsLA0Du/blTK8J08MrM8yCstqUHjSydovNFYbLGdpa+p5NpTuq6uNDyE23Hf1OL7HLykyozbsMoBGKRItcM0DJBO68FnN0zIoIpWww4V4bh/QFT27zyfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959683; c=relaxed/simple; bh=5kEtQOaPanyE2cx8lsqVLC93wX6vcTaHvurrW1k4Yig=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Q6hPEuAD367s7tvpT232OwyXDDmTimIBWWaTBi5ijEOYS/XwHOCZBHdKCKIk8hAHcqEND/UxzsZuKS8kQA5d7EwHQqSo4ZduPcJ2f1BlVOJx33fGD8mfFR5JxqxwwlFExZhUzAs8LKEQ1Daai5/5ge+qhkSWYdEX53ruKEIqhno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=q9mU/wIo; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="q9mU/wIo" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-8019f05c61aso33872a12.3 for ; Wed, 11 Dec 2024 15:28:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959680; x=1734564480; darn=vger.kernel.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=q9mU/wIoJVgmu21ln5xeVjwpMGBbR3GaD+A9DgICdmHVElUhvydm8POdDunankc+9D VRQ/TSxUyov53jBrWDqVVZnluaU8i7njJnwglBIwRTNRvBlwXKcnB7sjJLncO68D3TKl tkIvGfDlEs4lh79XBvskOex67yRoMz/YgfxKb9IHmnbnvLgnzrzT1lJmTeUqqBqX5nsN etMq88yL/xI7zpo9I5ODI1ueR3E7yk0MhlksZdtDsiI13k2E1ptAZQVbFW2QT7F66cv0 ANXNparaNz2whfZElMDHpqOSteQne1D11s9enIkSJxwGd80vSluJJPa/jAR2cACb6BTB wwqA== 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=ZUoSfSWdGoCykj11Fwl2oGfj/glWDG1aOlBrJEUxhUxwOfxC1Znug2bEXuWoe23TVU S0hKjdqZc8wlUdwGRy8aOj9c8i2oAXI7iPipE52nK1QiPD6CcJXUB1thqX3xAhGUc8FG jiAVztEVe/Q93rr2QvYIX063wBYzscRtkjJimbx1pe0sIQWpdAmZi5sPob7a3od+iNx7 NkLvtDumdRYF1Lh8O06hN1QdGbB4O018LckUvcfrjtCep34gsvII2Ik6JlyPEyPtLJNh ai+0X4UMJjGWCKjPYLoFb7QNLNSANEMqomvv/y2fvmB17KBiHXsTFU0XxMDuyR5udNZg fGLA== X-Forwarded-Encrypted: i=1; AJvYcCW0d38T/Rxx/ATNOuBtCPEe/7SY4qiLQiUSAFb641/tHqnJEixLyKJeUb3vVMOzOsBafgJpBnmkHr0X@vger.kernel.org X-Gm-Message-State: AOJu0YxfUZgAw/jDz/8YGNnksUfWyBAocyS7/a/0OGohoi9Bh0hEArkU 62PFMUzMbj0/5kwGTWA5y9mLCFkW1dM6EfCxtCEwknc/Na7CiZ5tIfCxE7joX9A40dXloQtIB8b 3uV+9BPVb38DUUxoGIx2ZKQ== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904369 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9564F1F37C0 for ; Wed, 11 Dec 2024 23:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959684; cv=none; b=b5+F+qixAK66/owUXsW9ko6y1yENmY1AnyyoRwfbC1pnMt1iG4SNMHTKA+zbwU1dvSj3SoNDb1tMcKgqvnJHBaTyf6dgidVJfHvLTo+KLugyDmfibf6EREXDZf09GZtTcjrTB7u2IN4AHw86lDX5CYyvRKhy2L/aTJOszJLk7MU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959684; c=relaxed/simple; bh=uM+q/yzsIcRuyjHcDmC8155xmbCZFE2hF94cz6in5vY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Xyl0G7gV1VtpN8HE09ZqvUUZ7NMavWtyP+rniWz6fcoqGUKcawyUIW7IM+0FCkbZvvxtKYYCFkbZgodqhd1tFEkFMG5Evmpbb2H0xwDOp6abkhiw9k+HlI4X0g4whY9bRaqYvn7CUl9MzjM2gpEWh2BQthLfo46OKCzTMgR6Gb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ejCWzEcS; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ejCWzEcS" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-728cd4fd607so26522b3a.0 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=1733959682; x=1734564482; darn=vger.kernel.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=ejCWzEcSItb/pYmUDQW9i3/51hX9bZULXDyiOV1Trv+DDVZtqg1cf3mx6FtSNPtprl m0t54O5ALg6tlV7UPSnDp/7j91VGIuqQ9DwOooKQI/GHWd56Y7RdkujtFXWDalc9Qt2R r/Hj4f+yVP8FmXygrjDUkQ9zODK+EgJUz2ZY7/1aevmO2AMDlWTTBn6bGf5969an/94x 8CrqJo59hGcway3KgEnDifOeCyQ8uACi97gpOYbNI/wwVRDoWCPC5xOuhzJFixS2M3dl 0RxCiqgeEkHI8VCvW3zefH5PuLHaQOZWHVuYbL1E6uA9IJeNOfAUDL/f5AaHL3NWLWhN /pCA== 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=U/DrS39O2T4EYvgAEq+ajubbTW+b7rlr8zFX2m6qmbuTZ8zTrqeOpbVUD+4+QrBFUD 86eR0aFUukFeUCq9aoHmVdh6Ti0R0SVgS5FtwsqTh7eHqcWd6s9EvvN2NZdOlG7bzJeV ohN95zo6M03GcyTvxcZSkZW7grmw/DS037rwqmPUSHNarmVP8ZYFdaBsiC5omoPrSXWH kHtR18LSdQc0zJThToKm82i2hyPv6FjR4szOTpl5YSUIUOB2ET8abhCvLg1/RB9vlH05 6L/xAbC4xdhB5siQiK5ItMITwCK2fEoH6EH0HIRv8xE3whZ6hlxxGldv+EvrKFM5dstv 8cGA== X-Forwarded-Encrypted: i=1; AJvYcCUZRD8BxLAg2fwNzD90ZQ0gQ5j16T/9aCenmblK45IaVh0d/T5GzyIVC1iYJ22cDyAgCp70E8dZT2Gb@vger.kernel.org X-Gm-Message-State: AOJu0YylyGtlfpYcXfW2frqQzVg//tGsBhOAQLlXPXEK5TEvVHTbC+kl UymlyFmPjHjbd3u+/e9RGIOpVUAYgtxDvz14J77KkwttBuHjXCEwwAwvUj4b74NXkfAtadCu5e3 ws9jB+H4dXnvim/xAOOYH8Q== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904370 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 533221F3D31 for ; Wed, 11 Dec 2024 23:28:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959687; cv=none; b=rX/6tKCf1t32dnecWqzgq3ArFSH7vDPALSxvv/OjK6FdLbL7oRfo1s9ggC6aCjARqSC0vXYkOgbVss+ibwgwKSsZPZHqJNPRe2Z0JFCXdha8IEN+XTEbrLCXeTCm2NnBN/wX4jNMIfaM2/vM75/DZDVdEo2QRdRoYf5GgaOxp68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959687; c=relaxed/simple; bh=NnTieUYeUvmhWo3xd+MtJWfu2roMqPBYkKqsqJw1fGI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=e5cCov1VaA4CTrwE0GUSwK3uoZE3MCZAhuPnO1qN4ndYy3POImqh6QbX6+H2V/4bSU/9Dyvj5ErTLC9fETy99AJUTgG8u/7x5pfXgemLZhZ00GUtfc5SKUL6751xZ0E9ms/HFkxCWa6yEFcP94wAf7nbEGibxY08HH47i7Y7uio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rXGBv9SZ; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rXGBv9SZ" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7ea69eeb659so36264a12.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=1733959684; x=1734564484; darn=vger.kernel.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=rXGBv9SZtapIGtfe24AN94v/kOZFAoioIsO+8kvkc3RjHbXhCGvB4r502qBZEGs8r+ 5qKznIpTDG+zYZ1FPXFah0BpiNdyilokgPAXSy0Gn17IWZtygXZdlk4Rw6s7KTY6/EI3 A0mmmIWdW4s8LE3Xb+WjUprYoC/BYtixOoxEOcytDYUb2Xd8IUbtshsZy/UyKphUZdMH ubRGjopdQxAh1ivaUSTMC4b1RUYAK546SkBOeDME53SEJeMu3cVo+AhsebzmafCU6RwY DwPbyrmZBD5tZPM+zoSRt8s1C2nzUiWlQLpiRi0jRFFU5H4G9BJozFUvntC3nUbgLS1S WtEg== 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=ny/eg1KHt+J+kIM5uLjcJCyDLmBbwAIHZyHi5rN25q4wyv4bl88EgnKQLBRy/eHZSS LcKP1tAjPEPFHPAxBmbO6v4Lygiev3r7mSLhuQtuRdD07IS55DBJ/qTfW3FFp5R6Yu7g 6E5zfmwDnVaDVj5ESWgvnrIFBlcDy8eaJCFxygPNrycs4K0JpmAvj6EKqNOdB8DjJxHc 2uDYpP5+Sk0NlsmsffdYoIP0xlhVnApzFbl9gtS5pIgLiTIGtVu3PIm7Lm8tMTAUIx5V VkposAbCDyInTZqH2xU2rqqonwThaKqZr9GJ7cKoXEaZ/zAwBV7oVX+uxxYItAA8SpuT /WLQ== X-Forwarded-Encrypted: i=1; AJvYcCVGwlC5I509+HYfLlczRa0nc8XJJFs/5kKeT1nMSTFMzwXuEfo2jTkC2m5CDRpQTblt8z1QXJjMz+Y2@vger.kernel.org X-Gm-Message-State: AOJu0Yz5mYJvFPMmNwbHcjy/qnm8j+hLW+Ucb4P3BS92j3S9Y6I2rF9z R7MSHMbPB/+rhRKLXUt/LPDonbt6v8qiqfycwNPAHwjIpPXqOBReRFrRuf7SFdAml0dAT4tiHW1 nf9ZwyPWP7+8dLPcggt/HaQ== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904371 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A717E1F2C3B for ; Wed, 11 Dec 2024 23:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959689; cv=none; b=RsGx+XSBtbxlW38XyTseTczBHE3uk57uIdEFBVz0/lThrZhHrFJf1gq/dEtRmnrAcKKZpiQRaq5GaNAvZcei2RGrWwnEDmt6kjcNz1F4M58FxNaaVeLs5yBlGY1DCDM+LeUmUIIgVuIKs3aYivEtPq8szeZ9/tgy+pRXv3Z8u9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959689; c=relaxed/simple; bh=2QMnrZNODJRgXg+9Jbu8htHUIP61bT8W2ZT8cLF7tfM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iTC/nWH8Gllre9kTbkP0wajt9dJgOIa6kTtdLqCC2qTqUFYoRi+OGKG2iM6aW1j7U0i0rapTI8/Am2ePbN7GKRVmrbutKMDGZ7LIfxnX0+ZX5AhuZjYAOYjzvAkOKaYQ/p0euefqoCM3KSzQEQaCpAJCsvSdgh71BhVOB51ElYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iJuilSx9; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iJuilSx9" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-725e8775611so21739b3a.1 for ; Wed, 11 Dec 2024 15:28:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959686; x=1734564486; darn=vger.kernel.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=iJuilSx9ae6vsJfFvviFJ88vwaSqeue7iUQaqKlzapvMRGFvDvoC25KU+Vv+lwmtg6 L4EHc2uqmG9mgLGTa+oiYiZZh6BmTeHMqxN80rFWDQ5rdKr3NGFmgpNzbIJhehQA9oCu N+K84hdj8u68XcRQ5cf1GWc1Bv6IH3OAv7VhzMQK1IdH2wJcnQ/wyFuSMyKwjbLOon07 ArQOfWcFbsOVqlT3Ohxbb9UFpI1jK1yTzDuZckLcjnt00g0ZvPMuvNX/TYjn5I7C4rQN SRHRAt9wpvWRWoQqvfzbwpb0pUb91lX6VU4Gl7DLPAVw12T67pSUpD9DoX6BOPUtWBhH HClg== 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=tUj8mHhz8d1mADciAqYefxFaMCb5Ny37ElTeHGNrb1d2XnBwTUDcTPe3uVbnUSpkE9 jk8zU7QffVU0IHoNmoDBKpfBtHiCBmbB3m5Ow/D4LvOtx2HB4Ve5zbGkiOUBzkke+Hd0 xN4aB63MNSGc/TlxjlwpG/bhZqAYCs7X5DsX3GfS1En78ToLk0iDuF9OJKbOA7hDaITP VPqJUf7ROUl1M2GIg3Q4tUfCeeGPk0BFmAWb6TZ3e4XEeVEeP50UkBqGgpMq7U3Gln/r EgDO0Tm9btUbonzISxB9hFV9XtH+auJVmzn2Fvmghb9xb0bkSyhKd9C1zf6H9SssubdO T1Nw== X-Forwarded-Encrypted: i=1; AJvYcCVA2F06aYsMhPsuV3Ick+M0V+T/NkC247otimX/y7DBDyIqOsObsCOSjpErHxBE+WtTiFqp4kS5mmuU@vger.kernel.org X-Gm-Message-State: AOJu0YxBeiPd8Vmlya9/WNv9CAEKnyg/N7dMnEWiiW9QD5SXX6TuTkSR utQjqI3KuzZzt9NOwYNriJ3xp7FpIcdDfj3LIfhh9cNPUjpkPgnEkIi+G3hTf6f24028KJLWgDM XPdmTbntPpGNftnNJTvNpjg== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904372 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A02B1F4E4F for ; Wed, 11 Dec 2024 23:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959690; cv=none; b=NiIGpVUlf5fhYFrIZp+CAm+AybbuvEUFW/inQ6NuWdnmUo9GBSz+6GAEfgHbABTwcYutRWS8/XE2xAEuxbVrZ5el33oZeI8yezARK0ZBl1Gdm6Vl/mk2MEBTv1mjBy/lP0k8dpbI0veoSSNkAU4sh0XPk32RETz6yfjlfn8lSNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959690; c=relaxed/simple; bh=yEE7Rr9UWrNi0Mgc9EzqgQ6AB6dGlFOT3/O0VBhmQmQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZBNlmGZCRHnziyGIxnGXrLy7jwrUnO3YFbUWq4sM4e5PcqEVpiB31HVwM/FGjw7bhrnYiif0nzlQiiWOJl7nkuMbbRDXZisqyFF95xDPp4mXz8zvP7AJlj3I9LbLJkrp8UuavC4in8jkKcbAp9Yo22Qf882zwgPrxgiaV6m6y40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zh9/3tx6; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zh9/3tx6" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-728cd4fd607so26571b3a.0 for ; Wed, 11 Dec 2024 15:28:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959687; x=1734564487; darn=vger.kernel.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=zh9/3tx6qxSxEgriTfA6WowuSH58ojYOnbHYF6HDH5eYi7S9sRJDAJu+7km5fTdnsN +6PawGCtYxr0fdIHPbXp4nSxhYctO+0KRXWHDmv+T7v3jqT0vTMmJB3vc0yuckSw0UyI yNSwogj5mgj+ybUQfVYso/eA9n/K4TNCXWhEpBJWBAkNbnl3mBBpWdftzLbb0Azo7NiE Y3T1Rzxo1FG/C8bzCcG/XXG/CEsGIkAZd+uJ4wnfTkZTvZXPi4v+3oSXgmtv8OqQrjSb jY2n9tnoddblux0iuZEmztMseVuR1m9qYSH5O7sE5M12WZMlmx8poDjXShE0fI8Jopa3 qWyw== 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=mmaaKvr98QV/DTorMTKPwapuTouL5rX3m6db4Wa0WMNI99Bijti9jk9BGkKOsAMLx9 Kzap+wXHcMYQY9J7PQeR4jKS09AGepJBaemA7/vdor+cR3TChzngkA8za/tX9NV4tC5a QVlaYQUfz33UYzeyEx0MT/GZ3/nBNyaVzheSeyaPZFozjChE1HWk6P2Lk8ytuZ5bzZEl n/QEazjKMZQADSvOJSZxt7pcNyNEB0TxO6aO3Ee9LjyDSkpYsjvMD+JUBdp5eiq9mqwd 1n9wTN1raVTe1rBy9c1HEBv4fH9/U2Gj9JhiOmfFDiaE8y5rVIEn5WoRHJMxtoZQ1AwF gazA== X-Forwarded-Encrypted: i=1; AJvYcCU34yTh0QFEeo6UeKyv0Y+iLwC6+gpgPTzQfBR+V8GLf2yrD3kljJ3r4Zifi5nE39a6dyJWIpDCpIK9@vger.kernel.org X-Gm-Message-State: AOJu0YxwnALaFGL4h4gGDcXui54e1C6a4hR71vf18AZDZN1k2tBPIZi0 yScvIlCXbm56XbeMBQWslBmQJlDH+tC0SspNlsH3k81Uuly2FLijhrkaLbOP6YVHvrAEafBYCMY XJDc9lIYVCH1265AHD+5TiQ== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904373 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 896861F37C8 for ; Wed, 11 Dec 2024 23:28:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959692; cv=none; b=q9NBc0IY3E4xmOSS5ff4Q6VIaZsL+KDN6VKg0Usp4txzuO0D3jqVxxp9d+qGLWdsl2SmzUlL7aOOK2MKAlgBrJaosl8ZkjnC7vITj30H80R3pDodXW3WcJUK3egTQa5bhPB675SzSBg7LE4vsdF+kJ0hci+OipxED6WkMmOQo80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959692; c=relaxed/simple; bh=OABjfOtbfmCcY7qx3gEUORn5iMVfTmN9C0DEpRCjQaA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gF17NEREcv0aLBwwJmqnAtnCD6YwiFQ63An2b2XDDvSuGclv06Z7101El+mmMqiXTxs/Z83zqN0wZ19pYTvgQXKyqLG3zYDEHqCezygr1PeVImuxyjd5e3xdNet1ZkFLdNsfiEOPaaCMlX1G/tbaKkubTdxPFvGnHv08lhQuX+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1umiCUIJ; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1umiCUIJ" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-72739b83336so34839b3a.1 for ; Wed, 11 Dec 2024 15:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959689; x=1734564489; darn=vger.kernel.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=1umiCUIJXXrwMzFakb0c0O/Owq7AyGBooM89qAg+AulPQYCTi3UxU3Zsya7zhx4eor LzieFlxrxhi+XKfVc59cl+B6h245L5CLopdq//H4KdlJ09V2OLMxyHx5c8aXtDrz7Z4X ixx4SRKQ77wHrBKXVuXkGS+f44de91rrIPRmK/YmMSxFzSr7dvcfDkVAzWPQifDqPJBO zybFPRDoYiVX7plxkIEDaUI8lg0qBFHj/pkzzQFgH5CiryyoEKugYePbhDcmPfHXt6ss UCZ6A3IdJOanzEXEceVpXcaWHRf0asu4bpAayHMaWxZZaQ2dGiZrpFpo7RSQZrwVqEOh Ndkg== 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=HF/Q0PDSr5xp4jHICaFbBZfeo6+yA3L5KVZvBfetEbTPh+ZKeExbu1ochFfzfM8Fpq XYzjo9TQiUQsgAA/JePjofjW6ddW/fIvtIK5MmRTWcN/m7vDlH57alcJ+ERHPjE2ceR+ uW2UN2yyGNesghHjIH1ZVwv17KGrY5X9/w2p+gq1oEqld6mwUoUoBrPXYdKPerVZF6KA xaFq1u2j7DP++JBYofksN4zizgLKhJ/34kd8yp8YziQKdKmzjsofN8JHjevKqrgJB5SY BFDz9AeecrBqcd9Cjpkd7tRvGZNBhj1cHzW35M0yy3k6Fo99IphXar9o1talMDzm/0HW tmfw== X-Forwarded-Encrypted: i=1; AJvYcCXES+XUE9zhQCpnylqgcTkUZYDCdBSPC6Rc5ZiZcAfveaUkkkUB29Eq6gpeTA4hk57VW1OBELACn0jV@vger.kernel.org X-Gm-Message-State: AOJu0YzQRALDtE8m1HDxwqDHCMz8Q3WDBEvdalvVwjKUPZktYhzTxSG6 NNl1Qa3RmbNN1/x7mGZAkx3Z9rYtsr3t9essSB2XZfyb6yrBmcMUeK55yfFMIQRlfZzXGBo3Ykz MnFaNFKDdgiP1/86bFEJaag== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904374 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D5DF1F63D5 for ; Wed, 11 Dec 2024 23:28:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959694; cv=none; b=TxA3ffAdzlJdOpI2jZM6UqzTOpd8ENMicTDAdz+Gbryzcz8aQasDJOi8J3fqNsplfluXF9oEkGNN8bsPU96+iShjtOu9WK6mbcsbA7P1+UgQLuxQWOeAmo4vvzATmD8XHQo2/SvSqkPgcMehEUQOFG42ivVhUDz5S1tKNgccL9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959694; c=relaxed/simple; bh=WNz9MY3T4BNNlqu11Rf0CyS+w9rSVzKPgNdD4KY5WCw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tWD4zsb5ArQBV5mIXvg1snX0HLGMEbSEIAVKlMT48spfAmJR/z8/sVxU1onvf+gNzVqXGDSAMZvOeZ6FOiySvmdV4ve9FemLUkg+VSVmChdP+GMsZodDWQDbWdHsWE4IpNm/OQXrQ7ppfF5k2y0CI0I0ten6hzXRGrNeE7fdj2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UC15JYSD; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UC15JYSD" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7f71e2fc065so38262a12.3 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=1733959691; x=1734564491; darn=vger.kernel.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=UC15JYSDAm2GAotOPsUvKMWvjsrHx/B4c0V3D/A8VAjwQSkTSK5fx2ddQiJR0tl6sA EhOcsuUVX2+2B4sZ6oOThtpyT0eAKig2mLU6I4v5pRaR3VRnrhWkMtED4XNIofeG4WVl vIZpD7XnZxnFb1/xFzVdVJS4XihMcjKmZGXAQFfphbNqt2yqlzoKzwWmzSpNaGLE2vKe C/cv1NStk2OzFNXE/PebL2BdbWFR1l4/YlI7Sho9RxXx+VVqhJAhb4KBggKY1fhWEPtO POvovPIund02i5CUq0xnNhJO5dehaFb1szn2a7S+6LSjBKAPHXWjMqqv1vjzkeSjfbno Pcgw== 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=PhD0LsLc/N/lhnSCUEDcu2TdB5z+Z2Sjl+FmP0Fyj32QJfYMZmPTSUP0Ce+w6YI/lx h3AKLHgQ2LhKMAzrQqT90I/zOTTZvigsDNnXhGYnQnb66ImhvNFm94Va/lsyI+iiTPRW HGyxMsQuzzX+HH39UEaZmbkRhVIACdfkT8WrqBCj0W9Am2xNHXqhlWQ35A0qFlFeiyeL J0RthcdDDXECOxgCESw5pNx0YSc+PZLt3UigG7eFcVhxwENW4xyFZIDvFPcf9D5xmTLP aHBZzf7Dnu9lLpNkF83lgQY0gEngPFzdu1nyWAxJhg1i8KmJAEO8Mx74W3u1eMqkswAG Otcg== X-Forwarded-Encrypted: i=1; AJvYcCUyhbRy03cgjkoufdcIw+wFM9hu4NPOq9qShdHxvW8j9UKoADvj0wjDnFlTOUTaehN+ADKsoPuh4P8n@vger.kernel.org X-Gm-Message-State: AOJu0Yzd5EAr8EwNPit57w0rHJoWJgKullfTOYLDnbLRafUQdjnJt+kM QRrszkEKOg7lsTJWsgrw3BWhDU0UOmgSqjrcdXt/2RP0+/zbvwA+3/mZErgZlMwbHT60qC8gtz0 aGFR1DddadPb7pNedX/30YA== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904375 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53C101F2C5A for ; Wed, 11 Dec 2024 23:28:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959696; cv=none; b=t/ewKwVrqgdy/pIwtD7ey0Zc5WctAdck+VxWXAZV2H+0yXT2ubmKDdr/JRpaR/PP9Rv1O9LQfkoqie0LE7SlQl9wIq1kTGMUKk+X1ZFsovGQkuB/qHLXwdZULVOFyBOiz9xK/h1t25r4b6m5bnhJ6CtkI+saPFaTMdpBFdJh3IY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959696; c=relaxed/simple; bh=zlxExqXE0l4h8ndRv7/8KLE54iJ3pIBdvNI0YUqUibM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Gv0gbmxMNqN4kWIbaT2KCh8wnFK6KASSYIaWNDEbcq4ZmMrOUK5CJq1bljLX2iwu3O4l8wonWEdHkL/vX0CBoEg+fL73QyTLisDeI6Tfg6bbSU02XzzSOJfl0jHO7tEMpZA5J3KRgM3TKE20ppIEU4VqXm51Vupdl8Brrw3+gEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZKXFlgBZ; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZKXFlgBZ" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-725cab4d72bso19401b3a.2 for ; Wed, 11 Dec 2024 15:28:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959693; x=1734564493; darn=vger.kernel.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=ZKXFlgBZuKsCHE4ttDnhBKzrwxSKcFIens9/3CDa3+eFbyy24lNz2KOEOpbkcTdmYE qvY1MH2wjqJoQhyvypeHkoYmFQKhVAoO8zB0WeT4ZBYLUgxhXOAKIoxGtznmLMWZsBsB 2jcaU767JBLrmDWlQqK1kIti9Qhj4NxPsdG71tiaqQ5t8L3/wYubo5gsff81mWgkrakX x7hMai+cJST8b2/uawEAovKqclpuPmvfQdMVIL1r/0q1dyWoHLp3JYC/WkreHN24EKGF Kcus68vuC2nzW+wcHTicUnxqnLZwQDeG1XWDdweKTf6DVgSRUTS38bj5G7gyzNeuwcLk ygAg== 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=i6vJdZiHhOrQSHFrf+IwH5Ue63v5aujuL5kz04SPa4rIqx9mTjXvjfP3ClrHp4z1Lx JIl3ZsRNqgecdqeBKC8IjnsQ0DMqMWxZ8eKerxHQHxB/k8xxM1uCudYbf5MCtjhXvca6 K88R6t90zn1dQrH8LN/JqP8R9FDfyLbg3/hWu9IklpqXO/01qjg/chWQeTHRGPXiDiXQ 0Q9islykSWWwH5CHoumFB/ghpoQo1wnEPqecmX8W+the/HJJEOz+4beLDPH11QGeznBj YUfq7pHXFc7R3FoGMpfMBzdhske2SMGGHThYJz50ADH/WV2wfrOGvQKyNWlZttRksikS iQog== X-Forwarded-Encrypted: i=1; AJvYcCX+zLMTCJ2d+brtTxtNFsxAzgtIbHxamrvcloLtmAY9ZjLX9lP11qVxwH97fZzct2kZ9hSir0qvJ9dP@vger.kernel.org X-Gm-Message-State: AOJu0YyEhJGNMGZsG9yizCTst4tJWmUtpaCNOHzL+6vCU1cn2ytZWYSe fjccSRr+kEEfFf+rR9G9sLRQCDO6Fa2wkWfA5ch3hHmhCcJ0pK4kSATQIt0MOsigMh1J+adthDK XqwBjirypX4nGIhB/wU8OVw== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904376 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A4B91FA8E5 for ; Wed, 11 Dec 2024 23:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959698; cv=none; b=hOJkzQd14f/HdtTPWRq1nLsfn62DtWEbMq8bLB4s0XhAFbvKSNpVhDfyD19XNBn7+bWX5vDTghhu0IP8lCD4fE8DSTEIE7/Lx4zpjEZ11Nb8oTZ0ynbr3525RbXKmGpEci2nznRIVi/MYPUTx+swyXPffBztbO8FN1udPzDLxQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959698; c=relaxed/simple; bh=/lMssxhouWcBXo7JAyWkdnKcOZ00wUnq0ZyKJQ3+mOI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TftBmkcLOupvYYhpFuT9XR6E9F8RklOQ3R4Nu9/njy/PSqUY6qogkamDT1fMXKwNkutJVml+v3yC2AW9GvtfZJzNqtDHM+3G/HdnQRh4fN8wBVPLC5G2wD24f2XwVPieKL/6LsWhln67zDDlsCDj6TWZR0gBSdk7cp/97Q0p26U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WPqaYw9L; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WPqaYw9L" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-725e59e41d2so24094b3a.0 for ; Wed, 11 Dec 2024 15:28:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959695; x=1734564495; darn=vger.kernel.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=WPqaYw9LUFgWq/usG611a2q5dJ+0bswcVHjB1VEsglst26pjGKbx5+yorenqrSUB6G /yJ+GAFbZqJezHNpTJF7PbdJrNVTRlJ90HUfg/lvJQQzpD/Hlh9CXsjfAdiuQeA9rCbk YeXFCsefU0C47ntB51g++MZP4Ip2kthpuRH9EnbeQlM9JdHJlF75GkRnZ6txe7r2BT6p P8y+XapmUAUxrHMQjTjKYEtTcuHJ1U7okLnDY3tXqc+VIFtcUTWWBvHjbNKrMY1LU59u +OKEhLfwKGs6p14i9t9f68Zyt4pDXXIrZ1dGIa12OUAuzA6psXV7I1kzhcK+k6hk8Y1/ TZAg== 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=LtlP25mB3iK/bka4PELhsjsalnKPfhXF1vJy66XWWoCgCLJaeGELdgcn0xTmJ6R2ve EkxaLd+QeIKdv5vvfixRNdvU+ImN+ZK26ld14/hc1cfgFSHZu1sBOF6RQniD5s5dhd2V cIHjQssUotTm5zmJMb0tQvn2EF2nW7aVkPxxESVF+hv/GyN4A8e4kE4hs3BJMb52MBrg cy1V5uUHk7VupsaTEGvoD7c2JLmrZOHMPyaiFaUV2M6Jkz60LTZBAK0fP0iW95nZpVp9 WKuxDh7zyoftTE9Zmog10TooF/24rVl9V0ob4v2dLVwTzdS+RZAmWkz9XRZIA0Uz85y7 nkpg== X-Forwarded-Encrypted: i=1; AJvYcCXZEeshZo1ZUeDMXhJYveJgtNSrDQfRPhLkyQxc1iEW59sNoK4nO6LyZNUg/UrlGOx/TPyT0Ht3Clb4@vger.kernel.org X-Gm-Message-State: AOJu0YzC86rVLQPR74nBwyRIjeWTLjz66ACzFr0O2iLR8sRCiGulWMa6 P8nig5L3Ds9vM5iYZCrGi7eYdxQ2nctgsN0b0AWu87UOJx4anBrY79BtmohMi50QlGy3YsemMl/ 8OhLgrCwv7YBFQW2CuID7Lg== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904377 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FC2E1F8693 for ; Wed, 11 Dec 2024 23:28:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959700; cv=none; b=e1P0xnR5zm2hDV3mdjpYSk6Fzkajt2ikctR4Dknl7Nlnot20aUJAxFvE/5LQjy4k+N2XZo9RW17nCSVDJRxIVuOQ2/ICPuveJsIi89XrLq2OoyPrIUCsh7sS6zeEH7voETJwmMGbYq8MYPItwZ7TFHy/CRCaxFC2eSsNFFd7m9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959700; c=relaxed/simple; bh=ZUqH/sj5oGsfJqdsLTZvI82joWf3NzCeB51cGD07HYk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=u1Pzk0lVnKdnuayDXw5BcRBPzQ2hT/o4Qj0Y1fqj/7U7JINcQht/EKVu0Tnb6n+6APX0DCZhmkcoh0W0aRYW9Z08b4Flh/42LZpqG3wMcfdiUzzMgSceN7UyhpDujQEO5jfsgsTnxtBWLu25hNqaRsZwRUnTz5cSdREALvcP4Zo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Km7buvLq; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Km7buvLq" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-728e177bc36so23370b3a.3 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=1733959697; x=1734564497; darn=vger.kernel.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=Km7buvLqNdikfD9RZfNvSMilBn91PqQQCrPg7k3a8g+hCViZIIYK8seVUwFLEY33Ke 4ly/7MbKpvELPEtrGVXzmcK3KXdbAtbzJmSGVMg2PTstC53gJnVV0MyHTiNSuLzWx2VH 9BuPckYI4NZ3eG/iRlmXw6ntiQUAIfgmiaumUEQqBu+lHyxY8hR+uTPHCM2ORVv+n1eq da6p4lAsjpsAX7ZXhCP8w3o2jhl7t84ZE75h9TR9z8sHl/rGUlLnz2q6FXzqVSLbtaRh DSsiHWjs/hqDz9c3RI39i4xwwGaov6TI4j8vYfTOr9D6ATuYbTe0D1TWCt6BIjB7mLBq MsLQ== 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=IoOwqSd5uEU0wFqsCTa33DsWnghQ/M2AleUagu/RyRpn7Uk7UGVWSGc5t9tsML0TTj Q2tZTXcW29wbRRa6umBHW838hosmIvGRsZzf4727KF2gcRs8MnxSnPYU64xoB0sANy1y +uMa4zErNVGnO1FkXkzM+5ddsbygCfNvCvjOHV+QwESYieoRAAgFTf8PQUks4BxZaXuu wBseOfLIshXAjggWYFFEfMjdDP56rt9caChuH6m7hPj96ZHF73n1argDOqQYfZbQyLUj ACTiRn/RM2VYfbYowWlSXGKkt2InrB2acQ1T/yxFPHyF2fJ0ejMocOwHwm8gAy5D6Veu DgAA== X-Forwarded-Encrypted: i=1; AJvYcCUOkeyaLO5ZsB+mxO2HaUfYsyhAY2NWxRQ3tmZtkZms2q6PZQI8btS6wD3JvO01aUHGyitY/+orO5TR@vger.kernel.org X-Gm-Message-State: AOJu0Yy/ag5fyoh7QuTZ/Julbq13C2dzapJLZXr2iAFaZcnDIUAwZBiG 3/uwyXcCMXLNzaLDLCm+T2r21cTzmBKTaLoWLL+ThhTXMhCxRc8xS/4JnzBNpJ+d4oMzqjtVK6l jCPpxrvV0m5zTJBB/Idtrhw== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904378 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B438717838C for ; Wed, 11 Dec 2024 23:28:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959702; cv=none; b=meUXjjwmIEFvZZD9DFbh1Q1JtbH2HLvSjfXaRKABxSB+OSmVBboaOkq2OymE3W4ZRvqqMFs4YAvfU/2pmev2D/+v5qzG5C/jTPbW96N6LrIEH7BOcp2ZFn7gJI17IvjNFKymyP6c4olp8Ak0sol5l5xTPjbsXtb0nxcMOQ7EJ6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959702; c=relaxed/simple; bh=ihwAm37IJ2/hyH8wk9p8tewzBNUAFvpAvR4rEE9oF+8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WDG1/94+SLNQP/zqVCEFwA8hUN7bnldt4EJNPY7hVYeP9Yj8jtfJsVU7c2zWH+9IVWMf2QAUq0gd201io7gfTfY+oOaqpne6/QOY2iXqp3FMfFECoRFmn4fdWCyu+aThEeRjqh0g0GVk7zXOWTDBilCawImZb83w9gD2OoiwQa0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uQR62U21; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uQR62U21" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2163dc0f5dbso34892015ad.2 for ; Wed, 11 Dec 2024 15:28:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959699; x=1734564499; darn=vger.kernel.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=uQR62U217bS+T1AweoH918/5FFDimU0rPOTcz+N1nByJhHqrKlo8nwPm0+nqlBU45B WrPADAHSbRqfp2GCPefvAbI9wCOIeWBiniKXINJ2LWu60bFuekVilayqfzUBvLxWXV9R wIs0Bjheu0LrYfSDg52K3U+OLXAhcOQOk/NEx0orAuFtge1GCpQEmfQtdWePC5FqtczM +yRp5Yv3V1GMmYqYw9+il62IIDvfxdzHP7DIFfMNR+FwBX19HPqHZ/JD4+HZjFqTQ1Dy w0tLB7BUfTh+l87ZlLQGmbYsjLqXgGY+OndYds4N28PiJgWIjRNVxDV2CGxwLlM0oE0z fdGg== 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=frEY7Z1FjZyuQpIQF15cWto2bLuP7VhAW6HTRvMTviVp1FVC3VggXHNMw9ODPjDnl8 Lt7MOH3hGPmuLe6NaW+ksvoc0PHuMDnX6tjxobwlFLBrgVCrNklPUnZBV6/fFSdveUW8 9+O/lSnbEN1Yrh/t80PyVAmt/fHRcqUapHOKodDXMp0PWK+oIfwDL2Y7rmkHSnkozPke H2Frca4nesy9KP4heO/dSZUzpHhU54A3PHWLGu/g+HQ/t6ojbCbjaRQvySnFE5s9WP1k N4V32fRMiDL/fDrilOIIKgQMEV+n9Wea0j1fSPaTqgsmcwUZ36sywDa4Be3dOt98NeEP jziw== X-Forwarded-Encrypted: i=1; AJvYcCWfUPx7V8XqbnyLyYruWwjr85cnTQ8K26EbVXRDA/P7b11b9rGYOuw7/eVDPm7LjphFQkMFlgUbyKjO@vger.kernel.org X-Gm-Message-State: AOJu0Yx0Lo5vJ+jvmdjJtp7MCSWmn5EyYwt7c5j/5p/PsdGegGDQbr9U gkSaZmN7y4Tl0wjFmf/xV8kcXndN4Asov5adVoHBPVY/A+bihmSluLVwGQNj3o9MiKPZ3dEbhUj RA97DgrEimK2pUCxhoZyVtQ== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904379 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F4921F3D5C for ; Wed, 11 Dec 2024 23:28:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959704; cv=none; b=dKU19jQIU7ja1GvluPoTHeWNfb8h2CNesM3wo+KWECxhynkGdUrO0o4+LTdqUaQ4CvfudDo7XY6jLaGb/IUNyaNSn6q6CKhb2f0jGM4lGtupkQ/2Ra+Tcw4tCxc+cVCTXz6vCL7PeqVrkWC4GXDeZe3slP2r4/KFTeGsdmQKRIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959704; c=relaxed/simple; bh=t20Jm0mocAcK7lQ29shtI55Q6k8DV8IzFPooZ89HtI8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oyIkBq/C30IgvDCyY4t5UYPxUvZkpYWW+JJhjkRAYJRhZSIsybASm1cRC5w0H5VTUakhucm6216h6FJj0oHngcFu603SRrGy6tXyfunpPEAJ5dQrJwJZCyTGPs1KWZwkUDMuNh3IxPJAAIu0jzzUoikkrXDEQX2o4CvSVnCFzMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jdn9oz7v; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jdn9oz7v" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-728e4e30163so19459b3a.1 for ; Wed, 11 Dec 2024 15:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959701; x=1734564501; darn=vger.kernel.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=jdn9oz7vQF1zkP0hokK9Ur/G9iVbtEDdXqbpxPL+YFh/9/tH5hE70Y1hhPgLboWEGW FDnZ98S05qO21xK1GC8H9UVf2zwwLN5PCAkDjUaUxWTUVwIRt+gzszEMOuRfmXHEmGe2 od96ykr4B/SNxkmo8w1j9iqGmLZk04ktr+GY+nXzRHST+QP9Splbi+jkDxN4ROCPFAhN wneV51QJFj2tmwrGq297aNPbUeKQ+wf+2RMMB7S24UwRVAsF6zoSyoozYpK+d65F9W8Y d0zwWvxTkmJPLSYgWubMXwJzbpd4rDK72vk4QURRTTyAoV0rWikxHZMpqXU6WKTBfkth R96Q== 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=pF2M0Gcrt/0FebC39E06raqjQskKqONW0oK2J18Bi0eVM6W5WEPe3cPJrsd3zI5s0q YyLUhN3l9dn0WFhJPbAKfKf88pPSI67DaQEKcreRlbtFkAXzuVMCPcDgnbJX6COx1ATd FH02teZ/xU+6cuYjNuAcHi9ltdoliL8Cilz6ExiezSiA88DAMDGbCGqYMJWx3geaANWc iTN7PPS3NZFZoYnVIaRDRq3TTXwVnkDK3T+UKVC+DEg50Z7Wku6vgSj9T8FYnAFUlVJB 58HblGvPOvzcllKOJXIWPDjAL3z8tmQBx8imGZRi7Sw8m5rnoNm9vmw35tFqYoyUfXlD hrSw== X-Forwarded-Encrypted: i=1; AJvYcCXTTpIn2OuIzbydPAL6SepakmvywD3rMuJGXvMPYb1lINEMo3aMQl2tg6hDB1aVOzP+OmrJPy/m0R6z@vger.kernel.org X-Gm-Message-State: AOJu0YyuR3fz1twhvfi2HJVyRRKmTxSd+Ch+w+4hbPBRsfAb8+sZkB+N 6Kxqf608cFlX897iUwBjxy5bajzbrsaj7pRa8VAOYhEcoeRwcZb6wMo0TkndPtPM4/5e/uG14lu gXTeBB+gpTuvZqjBDkgMpjw== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904380 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1272E1FD7B5 for ; Wed, 11 Dec 2024 23:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959705; cv=none; b=oU2IbvNCAp8TCz/DDVI6ohBO42g3s383VVuBT1Vg/EMjRYuzLNu97aUEiZTqYibrCXPBy6zHb/N29ZTSKHeToEUltBeAuflTXbJF9qGkO6pU2wWxH8Zh96Hr3EQBVCI2BCJaMHPg25p/6jGoOBt+iXKbMYNmTs/wMZc5qaL7bYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959705; c=relaxed/simple; bh=TGkiChoIiuc2VpG2S0Af0lfN/4uYZUOoXh2Df7S0kBA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Tw3tkrZ0fXjxanT44U51A7WAjOxD9Lj4JLpOozB9nNTNuyjaK5BVcrHZQ+GzfYiv1fQTM/S2hxiqxPLYdfbQ8Fn5CA8JGJc9dIFr47l2qiJ7tnWtS0MOvTyhbZWj6LALVN3bnVs/055WV8QfUDyk9HogcPEdCGA11bbuK/hTAOI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=I7+FEnVj; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="I7+FEnVj" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-725cf25d47bso14422b3a.2 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=vger.kernel.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=I7+FEnVjVtOUVOnpssEOCkYksACpupBbaEG/ro2qNAXyfwRxiXIRYgEEEIRF5+7znv g+arOY3w9EzyMeFVEGV3ruicaP5uayjC+Jg9OBOKINRionEoNBDEhNzaCSDpUthTGzP3 g2EoITzgriVjT7Du4LMuG4rarP84UVdYDgRO1/n8XTbORpqnUH4Lt4kD05BbLouoGmZs PrhUyyWaDycCPbH3Fn5EsrLI6V+daQO2z6hrMtbeodHlAivw1Fsg/hD+47MSDixllBvb 1e6fLKzBMcdRdgjwZHxVQsG5kf35D1ie8P82G8jOvcPOUKVjFu1QY6pmc1y98IQuXGXW 3kyg== 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=a4ToFgS2QZwKpGFkukkv2jVlgRcZr7fdlFzMvN5R8v7V5UYs6s0FHrIRHfGIbyMwrs xstoRuwoY09Wc6dIDu6HCzEZEOXWRC1k8z170K8aN8O1562+ByY+UxlrFcjgqYYIkE0M CTxNUKwoT5yA6sUR33CluCghrYXNRCATP+/xdVhFtYvgmD8GVflkFCoBH/o7GZIvGYzR jdAeQgFH5dTEc+F0umimmU+w0dtxn9iUy8xJFCMBCcqYs1jZIHuyLW5ERgnWGGWq0S5/ 2aryUDvTJVu12E/wOjO/kFAVhg8SX0+3StlCySyRQcnxOP2JoREJqk62UERgrKx0xJSC NDNg== X-Forwarded-Encrypted: i=1; AJvYcCWmvSruCCsP99mn6W+L+SXWplSXMrDs9nzIOmqe2i5MfB3dm4dMWT5qBhVeob8yB1gXB2TaseU7VfpB@vger.kernel.org X-Gm-Message-State: AOJu0YyYAar26B0rc8Ck8ggTtPZ+paZKdLBSbep1Tpw6UdNsvUj8mTN8 lUeJsmTwv+eVvH2kcRHN9vnqaAjZfYmyWx4cTG1RvNn3YATO2H9JOLqal3Q7WJroihFk0gy20Bh PKe11imfvGuQQgbYg9NZq4Q== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904381 Received: from mail-oa1-f73.google.com (mail-oa1-f73.google.com [209.85.160.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D1141FF601 for ; Wed, 11 Dec 2024 23:28:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959707; cv=none; b=Q2Ytz22Jfyid8NvYRoZsTSp3HfIh7PzTBRz8l/c/MtLEqBTTT7ZkxkXKEvaYvqKmkxNoU+gpeLlVh/li6ogNip09Fyvv6u4LRZOggUgvwYyfhFYTnDPh8KNvVj6b8PC8ocv+oFOEIdVRwrP1Xp1kczvb8c+7FXgp9TEEzHRUPtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959707; c=relaxed/simple; bh=IV94/17VU942v+SUppuhN1JByKB2U0oRaUQ8yQsFAy0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iHn2Z4USOmfUBoMdysHrkYB/DwwJ4S3QjEWHjWqI8rBDLNc8l5zDZYVo1PcXxVWctU44CzThFzlNPTLHcsgPe8QjvlqC1lNFE8jqFNKT2QayR5e69gMuuut9lGWZ9Yw4BSBvm0E2ifeHhStqXUNQnAm6bU1zh6gttZpJ9BaMsC4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=znlqGrEf; arc=none smtp.client-ip=209.85.160.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="znlqGrEf" Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-29e2bd938a1so3287419fac.3 for ; Wed, 11 Dec 2024 15:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959704; x=1734564504; darn=vger.kernel.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=znlqGrEfDteMQMEQMrHRT/VFZUJqKn13qlRAuc49AQewDWPfUKRhcvh6q8eYf00wJ8 7sPyjtrzDi+CxOXMp/duiSD3d1jY4DXH9ebxKojNVFDc3+SEwUfGE3OiMi+QP20FKEGt 2holzL4AGj+DC70nyIuNYc2N4lBHVQEi8aliBAlG7SZ0xqhHaeZOF9S2dg+catQMaPSK I84IL/pqaJlS2LFUpV8QkJUgiHNKSgRgGudxaAFuqH1EzEOWCe3h9LZIHxOpv6lxK2j2 7SR3zJN7xugwyWxp9T8sg59b3Ak2UEuJKzODXNmo9EEETb2BaBYdZuLWz6UNCRHgdPzm fwnA== 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=pCWcKTIvPtjYlEU1oyoTvtXTPWlcZYz1MnLfLXonT+9ThM19Ps9aA16MoofvHH9q/M Xq85U9hKXKSySWjn7ZFAK14nwHhg8pq/j/VFaQLXBnwhpy/LUtGfDLFmsa6lSGms+I3m 8fDQWyh5VLSdovviTzZKBqhqoxA77zU/YwiJjCsTtU+H75pNn7XWvnMfbFDOYhzaFlP/ cwuXiWJUOcXTJcd7+x2pfzjn90El1zoGZXeExflBE+H8LYgJX52gvuWHZkyZCLTydN0p mzWFx2A6wHX7aRYTOBvig+sqZ0Qhr/YQJ6VZgC5V+b2rpwLwib86sKZOfSo9c7hr6Mlu OTsQ== X-Forwarded-Encrypted: i=1; AJvYcCWyE7JeAoD8tBKpPBQpOrar+n+2qjPqhH8mv+rQ1xmH5Eq06CLjUi2tn+E6hJmuN8EHa0+wJzyfnIMk@vger.kernel.org X-Gm-Message-State: AOJu0YxVpHj97b9uDAq/0qlaFs3RqEGGrUAyVxym4cgUgDRIJT9d5CuL WaQvrOWX1Rnz/Hh1eOQVE516OfGB8Wc3DDfdi7a04UDWBQEYfWNgg4uJDNWt3qvagpgRzOHFG5u 0UEJvJrunI2uEN1h9QnQuig== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904382 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 148AB1FCF62 for ; Wed, 11 Dec 2024 23:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959709; cv=none; b=D68JJc2D3UhDtgDLxKHwqpBTbqyCpHoJF7STSxeBGvNY1jit/umSckD5yD3Qd14N0MqX3hn0OL3PsiwgB4r04V/xV57oVTQKbpelHj1dxgfxtNqM15YIG5rJ0on4ObEWdH+M5b0JPBDf9P7TgLWckgLNwrf4xNjyY4RT5OMcVSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959709; c=relaxed/simple; bh=e6BnmSCV2QrrtoqE+kEeLZmDcpCmkfYXz43FlPij0LM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W6ouEEnw0UfmKc8uslyJFBDQuphDFmqnYi5e33jEY5/xQIBA+uxsw+RjYrZBPTv0+fycBNugtuZ5IsyUh+Z1AZMCxQe797H8FZQdCXUlsonV50I6lI0fp2EajJGDiuqC3AbT3KAouA4dNOsI3+cT6r7NmPN/PYkWO7PrF9Gpvcw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OXajPhuQ; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OXajPhuQ" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-728eb2e190cso13315b3a.3 for ; Wed, 11 Dec 2024 15:28:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959706; x=1734564506; darn=vger.kernel.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=OXajPhuQrIh+qiUrSPxrwqRABByE6r0uBtIra/NXAhrZWdRhgIXKn6oBQMg01UPGCE 36CnE3+f1S7sGsp2c9lfX3FK2LFG6yaMe1UwcVQtHOyfH4pB4efEP1nDAJPbeoEOUfPK 4t6z3rdpI4j7tYB3W0m1DJz3PCB+OO9lBVuPOvBd22D1rxzu3droH932qVtl9kbXTCPY SVhWEV4FWmckLmjCH6qRgFKfR+JUindoxy8maZbdre66KeN4iV2DBwDKHAfaBXq8RmDd LNPDeFLjao067G8USlrya6O0tfRLNcvx7Qu9KQOROGMgtjeB/l54BQzmqFdKImC3an7F Kt3Q== 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=RVSmkARYw6uWZ7eKZL4ozB7ZVv3TtD5co8GBXu+Vg/KQS8xJPFTHX0AWhtFW82Sm83 ybTxiaGf7c+PW+yYr/1OWrneJhr6BstMmkLE3pzcI3epMWfEG7mOQOwJIZBbrpoXKCg7 ABPyTZGD1A+/ML9GI4ZUave80ywjZ5migkIwMqdFwZexV0tnQHHOA9OJF9avT9+OOgwt p7RL2KMP4a40vebRTxPIR0UHxHuDHd+hsVU2f5GyP3Vmnh0VAK29hXSEgYSsGZZadt60 Tvu570RbdOqJZu5lXT/26vd8fpU6TLP9IV+8d/rsodO/Zmf4UaDjnpe6RTBTaSi21Poc C2LA== X-Forwarded-Encrypted: i=1; AJvYcCUEe6AZUREcLPc2CNFmOxUuFtN9fu1/aejjFvBG3pozl+NIobEgtIjs6lrWfS2CQOpGZ+Gv1nzWs1vZ@vger.kernel.org X-Gm-Message-State: AOJu0YzcdMUAUddUscBmXhZ5+IzNCbXal7lduzmOTYGtH5sdGP7gXjo0 VsxYzOGjz3Y9jtcgfVYAIwReZFXUAp0ObebRm5KFSwggj9lOxEERa6J5rFgJnwVSygHYtSfJAhr dsiwZB/uJWtk1F6ElNXeqhA== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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: 13904383 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B32E520011A for ; Wed, 11 Dec 2024 23:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959711; cv=none; b=svXlrXdYztl90kYU4uLf+/vGG1zoUqiCzbt8IMGSDBVKJg/mdcy2tI3QrrZeKH0uRI2G2h03xDLWjaKARnmxCx/tZf7YMJ/TMqWwUV/c0mOd5MVoEfakTKL+A9Yss/zW+mJsDm7Xxmf6SFcym//rETHhdo60C2hK49PqwxRvr0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733959711; c=relaxed/simple; bh=MlGm5TTjfr6vCXVALZb0EK8yBbfELhsbFEVcKacrZbw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NiT8Jv83woXKj/mME04P2JXHhH8PNsQsKPwGnjWuDsHhiTkslknZWsxpcoJX/i9vg6jUyq7/QQlRI6WGqeDoATEtE4UzB6yDlO1osWxpTa280XNOpvJ78toRsTlDp0jZATZqIH+Q4wBtaIvtdxuQrRJ6SB6N5dT3v6yLD/4Yt6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Dhku2VAb; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Dhku2VAb" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-727c59ecb9fso20608b3a.1 for ; Wed, 11 Dec 2024 15:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959708; x=1734564508; darn=vger.kernel.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=Dhku2VAbxZZM2UN/YnJNvFaxTc/yGPJX2iNH3/E8Kn5N7E+9GLNcR1E4TWMtU888V2 pOEj3iHLM5J+oL8wnVNZjcjrV+aZf6KfNKQp3OK2mHMdXtoN7tGqfzRDGJ1kpCGLGd2R RYnjy7KmrVmvRudOYpi6kFbxJSVhcud+fQXn7QgvYIZw6uumG8p3T242Y7QJq8sl0XwO 7uvnFLqIm+Y/ptnTZpsLF8C817Kdnt9NS8rYWUYBPQybU1nm8HdsiGlj2ic+Gl1GmN+T z8hUsVb2Iro5yXN72RdeXqd+mBHF1951GcmXIqCbVO54aUT7QoMWKzvtI3xdoh6CevNj aglA== 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=wvcqcWeu5MbZ+3e7vzPCCWxmp7peO5/5UI5t5VovtlQtXRtoBsOdHuPmoFbki+cZJe jiBvSqU3QFg83yck+Cinas3IDAbo+a5uJu1oVe+QRevviy4rSMV9lO3dlxxQE0tCpUuu MNSPg/xzdoDyZFhEnW7ZlSmIz+nR/yHFnPJapq6vVI4RfTCh+Kb1sPbPfpQ9KDcJkhgs 841BnLSxVDBGF+iQaMy1g1Tj6ed57qyPmcsXqfHCmY+CcmljKx5j5JXdCPnkp2ZGhcwu 8KK5YfAVN69Jfjm6LVG7Z0YMvbKzJ2cDCWwVk6wKPSH2mK199MZ/U45xSijU8fhKlmFt 35uA== X-Forwarded-Encrypted: i=1; AJvYcCXvK9y8kBtzeGYcLy1ujiqZdqvOv+orex5MA7t6gv8/OiA1rv0jNmzQvkF4ljEfYN84sho0bUvKIoek@vger.kernel.org X-Gm-Message-State: AOJu0Yz8COb7dQS/yWuiX3xLfSzzQgd/1JEgqqbXGmbKvcTP8F/kiais vs1Pg0dDJ8WwKMtKABv7qOj9K3NftoSLGZAwyqloCQDYUyJsvxUO/g5LNihmQWcRa7e0hqtH5ez A3yHB87g84O2bU+p96EXAOA== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 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,