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: 13904440 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD482E7717D for ; Wed, 11 Dec 2024 23:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=t+2SZZ0hfvfE1wB/PVG8ptvYr9aJVJPmVtSy9l3KX7E=; b=1lfNsfBIqlrfj+FzCWEXCcS9ET 6149v12lTLKLhlVHlsYUzgoVtQI07ofQi7DaiqrEfMqStSvBaU05nSWZxMbjxBH3INymRoHUnYGEW 4wW7Cz7qYDcWAN3gset8ZzN7PFZZNfUYhjJPRJm/leIdbS9x1Veot4fTxigsKhiZMqSZWI3hzeUhd n8M2ar+PF+eyF7rxncqqBEXV+D2eKNvEpHVpxrfcTWIBQtXo5tSJLOTDG6x6R30LwHVxMFUq9a4wo ZdWnH1bsV3vrpSZZTDlxMLMbbvQP1knLdVW41tXjlUbFSE51s9e+h/J5tfWYbrXgpT4zC8kX+7GG0 JjT+zMpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWBn-0000000GTnZ-1dXT; Wed, 11 Dec 2024 23:32:19 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7n-0000000GSWz-3t5D for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=t+2SZZ0hfvfE1wB/PVG8ptvYr9aJVJPmVtSy9l3KX7E=; b=ScIRfcQ58Gj67qJVoipHAcf2aO sjEOuTOKo35IqDD3XNfEQZvv9E1vZXHNB4qS+E4V6EkA2W1ZhHv/0j7/cyke4kXP50hUubymc1dgn reTa7G2R385tR2hDZ3/uzM7+zV+vda2H1PBPiA0x++vt/zfixzEDyJBZFvCxf/WTI3A7s7Mm8U8VS tJrgCUPh7jnYujI56u9IEHkwQ9eTpP/4IEUCISdwPOrcoOZO4pNDKd7lm/Xu/73coo0mSuYHfKOxS QsedwPayNQmV53kdWL7b8XWkfRWKe37Oha/EnmBx/4UsL7HEVtIhr5iVDBPvZmMPRhwF5lrDQSSl+ BqvqWLRA==; Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7k-00000003vzS-21d9 for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:10 +0000 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-7ea8c2b257bso43470a12.1 for ; Wed, 11 Dec 2024 15:28:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959684; x=1734564484; darn=lists.infradead.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=sY+YcBwrHPgurNxqc/rUmBArap7BRwP/Zdq2DKHRKkM1l7XNdr5TC1DjO0Q4TPpj95 nUnQC2nDiVwoBo81DcsSOq6K8hAVd9jBlLOiEvnyeV124HEA62gEDX/wfVrdWDU0rbX3 y5uKRgP8MJ0P0LT8dL82++OQMISboNH/AUGYyNH1TDQb6yA4NPO8B+IM69q7KsxOtArm cpHTbaFQVM4dysSYWJnE+7fq59jZnJ8XKlSYF+Vgqawz4CBqKx/r2cMwBJwt40vQptHA LmCR1IL13N9aGz/m1P/H4HZ08WkEu/KgP8wm5FnXVkwGBrc+GrfTGPnEZnMXv6BgUxtT GN1g== 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=ERRd2ovVhf/7NtX66YX70XpDcVXM8K50UmHbPbtbTqBx923CsJNNWE4JsEnkj0xlkr sTiqXQTtvfo8FVoLSkPWEzBkAuGu6JZGJ36XCxo7fQYtmUYmOFU15w+piVs9pVi6I9FR AHASjKFHOEna2PQu1FmerGII2DnOcCW251Bs3Nkuksvm7oTDcAeghmyEes0J3f2PjpT+ 9+BsfT2vFokFgTMESP+R8Z8ReKTtV0sB2n8QqRKRfTXmohIxTCJRfltYZ03fsjagH3X2 5t/h9+NOkYQRDKZxuxKh5KoBvZ11BqQFM9HBy/+4HlzZ9PJfiP9C8KHA/BD2sD1E/u2T TZng== X-Forwarded-Encrypted: i=1; AJvYcCXfx/yfgEX/jIGyikYVgG6ceKcPUAFhwgV15a07cyDE7S2+piBlT0nTQuGPoOPcKpOag9pg7dsewI7y7uAMKbMP@lists.infradead.org X-Gm-Message-State: AOJu0Yzhu20w6GFEd1MR3bvfkQo5O355Ol8Yk0SDMiC++iD1dzfs4ty7 PDcsGrWG2UQKIPVt+N4Y61um/w+HrHlaFOhB43PjCHxFfIQZTdhFAYXAOvNDympLJZ7mNAzWwpm 8y2CCprIpmu3c12JiVHzrRg== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-4-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 03/16] mm: arm: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232808_898669_E8239E53 X-CRM114-Status: GOOD ( 19.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce arm arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT. This is a preparatory patch, no functional change is introduced. Signed-off-by: Kalesh Singh --- Changes in v2: - MAP_FIXED case is also handled in arch_mmap_hint() since this is just a special case of the hint addr being "enforced", per Yang Shi. - Consolidate error handling in arch_mmap_hint(). arch/arm/include/asm/pgtable.h | 1 + arch/arm/mm/mmap.c | 107 ++++++++++++++------------------- 2 files changed, 46 insertions(+), 62 deletions(-) diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index be91e376df79..1433b3ff4caa 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -330,6 +330,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) */ #define HAVE_ARCH_UNMAPPED_AREA #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#define HAVE_ARCH_MMAP_HINT #endif /* !__ASSEMBLY__ */ diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index 3dbb383c26d5..15e7e4348af7 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c @@ -17,6 +17,41 @@ ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \ (((pgoff)< TASK_SIZE) + return -ENOMEM; + + /* + * We enforce the MAP_FIXED case. + */ + if (flags & MAP_FIXED) { + if (aliasing && flags & MAP_SHARED && + (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) + return -EINVAL; + return addr; + } + + /* + * We only need to do colour alignment if either the I or D + * caches alias. + */ + do_align = aliasing && (filp || (flags & MAP_SHARED)); + + if (do_align) + addr = COLOUR_ALIGN(addr, pgoff); + else + addr = PAGE_ALIGN(addr); + + return generic_mmap_hint(filp, addr, len, pgoff, flags); +} + /* * We need to ensure that shared mappings are correctly aligned to * avoid aliasing issues with VIPT caches. We need to ensure that @@ -32,42 +67,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long flags, vm_flags_t vm_flags) { struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - int do_align = 0; - int aliasing = cache_is_vipt_aliasing(); struct vm_unmapped_area_info info = {}; + bool aliasing = cache_is_vipt_aliasing(); + bool do_align; - /* - * We only need to do colour alignment if either the I or D - * caches alias. - */ - if (aliasing) - do_align = filp || (flags & MAP_SHARED); - - /* - * We enforce the MAP_FIXED case. - */ - if (flags & MAP_FIXED) { - if (aliasing && flags & MAP_SHARED && - (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) - return -EINVAL; + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - } - - if (len > TASK_SIZE) - return -ENOMEM; - if (addr) { - if (do_align) - addr = COLOUR_ALIGN(addr, pgoff); - else - addr = PAGE_ALIGN(addr); - - vma = find_vma(mm, addr); - if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } + do_align = aliasing && (filp || (flags & MAP_SHARED)); info.length = len; info.low_limit = mm->mmap_base; @@ -82,42 +90,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, const unsigned long len, const unsigned long pgoff, const unsigned long flags, vm_flags_t vm_flags) { - struct vm_area_struct *vma; struct mm_struct *mm = current->mm; unsigned long addr = addr0; - int do_align = 0; - int aliasing = cache_is_vipt_aliasing(); struct vm_unmapped_area_info info = {}; + bool aliasing = cache_is_vipt_aliasing(); + bool do_align; - /* - * We only need to do colour alignment if either the I or D - * caches alias. - */ - if (aliasing) - do_align = filp || (flags & MAP_SHARED); - - /* requested length too big for entire address space */ - if (len > TASK_SIZE) - return -ENOMEM; - - if (flags & MAP_FIXED) { - if (aliasing && flags & MAP_SHARED && - (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) - return -EINVAL; + addr = arch_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - } - /* requesting a specific address */ - if (addr) { - if (do_align) - addr = COLOUR_ALIGN(addr, pgoff); - else - addr = PAGE_ALIGN(addr); - vma = find_vma(mm, addr); - if (TASK_SIZE - len >= addr && - (!vma || addr + len <= vm_start_gap(vma))) - return addr; - } + do_align = aliasing && (filp || (flags & MAP_SHARED)); info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len;