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: 13904438 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 D30E3E7717D for ; Wed, 11 Dec 2024 23:30:23 +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=i4sLwXeXnZGwZmaOI+TJwHO8calXr1XpV7HCaSQYyYY=; b=sZuyilUnKKGtDaqMtw/4//3K72 jANRywOgxi7rq5Z27rOs4Lsl1YGuFEcG9G+28/vRiHK8pcyYBAXTlQolWPDWXfJYjRSXV3n4S6eHN zTMP+MqSusMlFjgzqYyT9WvHgqfJOecimoKZNEfmnycXF8jCp5FgjN2cx76N8ym1boxEyC6iI+nQs 6ss45yB4etMcCvI3GMZdRHEHdjdSWTh0A8PewHBj3c9CVvf2gkprFlYDhMGOpBX7UAFjR3P6w9bIk KoXuudQISeAloULeWTqpLo1Y/zZCg78UH7SaYDgj3GwBHu4/5RRwcS6uaFc4h7P7env5PpYCW9p0O uu0wl1iw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLW9i-0000000GTJv-3l7u; Wed, 11 Dec 2024 23:30:10 +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 1tLW7j-0000000GSV4-0SxM for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:07 +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=i4sLwXeXnZGwZmaOI+TJwHO8calXr1XpV7HCaSQYyYY=; b=cRRCOX7vzTXZ7ZXnqpL1rQYWGL n1G7yJtFb7whZGHEDx7HX82tNuJ1RpyiPYgMmcaoNvLWi1DSYBOjMk1FrFOAKZ8OQI85BK/7lzrdD LLMEPiaGT6y8XpLg3j9YNmd8DgjXVLjwtjdymsBuMOQXF5OLdX/ju1q5UZ7obSM1UZHJhy24I40yP pnSjVLLCsbONiGAnf+VHi58MvGjZQ5xndvCRqY1EoBwkgv1eL/x1BrlkXLhDc3UFDMf4VesEu1+b7 slHikvpKry7+ThKXsRYwc07lGycmttYG4UFj5CTafi0a0LcCLBaau6VgNhg72wUC+yisRDrDMEvBl mFMFnh0A==; Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7f-00000003vyN-0lEA for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:05 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-8019f05c61aso33874a12.3 for ; Wed, 11 Dec 2024 15:28:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959680; x=1734564480; 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=i4sLwXeXnZGwZmaOI+TJwHO8calXr1XpV7HCaSQYyYY=; b=Vwkch71garP1ztd0OeRBOfZPpNrMMQtpeknY3QduBjmWKZgnMOxaXr3jtZh6PoBX2f DtepdVsC+FlfO/w6+tXxVfoy7jTH1T8UG++qRK0eyINGA4HNZIBATnB9DRAmcIYYoU2j OLh9HfEBgAPCZEj+KmRknRqFLbzWdKNPJh7l8TjWjHP8PfD5t6wiBbN5Kw3lyHz72rLY QZBlj62d68qp/lScsO0vdXM9w3/ZmT68dQcGd+d5wiWJsB+YhLuV/WtFMrBo8bvnV5a0 p8niwVIvoKCbUIKDbjGA+IQT+aLJJH9byAsstTTDt8ClaJkJMTRg4jQfd+CdU3qpeWob Wzjg== 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=WcIxQiO936tlpIZpv3vJIUIBneEMNBmIoqA0qn8SgNdaEuvH7+3TF5xkbALP95gPBu QaIuXarBw/RBrAvblZ1rkfn4Wy1BrMLMEjf8Cen0C2xouEOPSBfit23wPNBIxXJuZYYw k1+lRQ4n6YXgHSpvTV3/kc/8J/5dXuaMiFFFqQMMADMSubzJ4n7RTtHLL4IGg2DJfRs3 bunopWVmEdfRI/95O7rOmQEZLqSOEOitgfFD7Qw+Enzt2i0V+/gAxgokMcK+bBB9wiAA mIiDhvyG7jG387WEZHjRy8wCX/HBw6o/bA7RkgyaLjsWvuPxuNCco2q4pvlB4DoSHmlT WKaA== X-Forwarded-Encrypted: i=1; AJvYcCWzUXVHChyXac77xA4ZS6NOLh2dCkHt/SYHOovW7ExlE2aPP8R5rhsKNM0gbonAXqE2jiBchWsWGlJ2xyz/YCNE@lists.infradead.org X-Gm-Message-State: AOJu0YyuHhTAhCb31Q3N+DGnBDJiebOCXy2iSicNEmfBeqYwmUnHIKt9 pT1B+WMdnwAQ4XBRiNo6VGsdNSq5yB7WIALgs4VLR2eU1f4BdlYJ1lDmWRSPjNGEGgMbLimtQYU V2Km9dhv5CPsq0cPCs+2aSw== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-2-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 01/16] mm: Introduce generic_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232803_563094_07AC9367 X-CRM114-Status: GOOD ( 16.62 ) 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 Consolidate the hint searches from both directions (topdown and bottomup) into generic_mmap_hint(). 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(). 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: 13904439 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 503BCE7717D for ; Wed, 11 Dec 2024 23:31:25 +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=C3IQSr9A1qLdVskR9rEe7ppqc2lFkJy3Q6Qw5iPRaPE=; b=2k4GRScHLHsRNDvrMVBaRi6KoS u7JGMPx4WF4xCIXhEX7kuMzAjIWnt+lF3tyhLnVjTNvmXpZnAIDvBQBHYcpyQG0XOAQMv71QilqHG JV5uD7APVY1NbBJ+skyZgAfm2kFT9HkcLEU8u0QoJrCS5aM9yKueN/SVhR5o5wqzHiyugmLJ2HFNp Igd9n0b9BUgoTsfoVn8ZYfl7w39v98EbRCcFG/dHL/l7AGzsDD2sowtSNl2hL/UW9sAAjH/YiT/Dm DgkogYi5BMycRfd+ghGgfQwoKvauwHLUVMSkl9o+Qz7zQK3aHuoqYAj9iEvkKnBXBeQDyI6gJhzCN JSNzyxVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWAl-0000000GTcR-22Ym; Wed, 11 Dec 2024 23:31:15 +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 1tLW7l-0000000GSVl-1gKf for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:09 +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=C3IQSr9A1qLdVskR9rEe7ppqc2lFkJy3Q6Qw5iPRaPE=; b=bjxAGLAijpOGeSBg8+QHgKgl7n oP6/PignGEJ8I/Jdz4PTaCMzRlc1v94fyh1MJmLuBfNvH3UECOsLBHLT6aNAlgHjZN266k/I32rMC xpDnbjuc2hQTJbE+SfkC4YhaoayM/IQQwAz0nCrHYt/zxz06FRj71SRtwQ50qFan9z1nu8T+vm5dw +n/CQOuqy7nxvuWqG67Y4/XZX/45W79dJxTbbx/y0Y6a4T47GepwIcRxzd2k9Xk7jR/sW4zqpIODH UQLs3mGfSfwztzJtUYP0GpkowO2NfspkZBma1vR2nrM20Ccf93B9DotU06XAwv5uSJJzROLXyfNxy 1sWDjmeQ==; Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7g-00000003vyf-48YT for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:06 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-725cab4d72bso19304b3a.2 for ; Wed, 11 Dec 2024 15:28:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959682; x=1734564482; 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=C3IQSr9A1qLdVskR9rEe7ppqc2lFkJy3Q6Qw5iPRaPE=; b=00F0bz5e+gNvXHk4Kq2xxctR6EeaQvHU6ZIZ06lX92r95IhpdNJ1XZQumZ/LmVNPhQ szIpcXSJ2LGy6Wi9Ce0wbtMRLhsKqulXtThUXLfW4m3i0ZpcVjJNSyq0b8LurwHulWJ/ XMnwGa04NczRlqRFjYXmjYe6WZ7q1eovryEMS44ETTQ6UyP1GpWJGNuFolJfN7pYiawK DQKzDDebJyWbbRd++Jql1HS0gH29dRkpzKZj7xzXABHxlaSYcdyKUknrEbl5MFDUacHM ATM2yQ5wl1e5fvKMNjrIEi90crqr5w2qqxCqjnA8HkTU7SPKDQ9i0gryFw0lMuPQ/+Mc QffA== 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=I5n1HdqmHL1URkk1FeMxtU8RlS/BQ8yOp/MJ8847yRfQbNufLo4hZRIRH+H4w7XNCN MyQjcshZqGTasKZeDwVGYYWZS/hJhgVlc4Kb9R7myNS8ozsahe150/9IwamZuMyfT4R7 M/cVS4HRZ/IdF3YXr/A3VmybiAsyMmzHYnJ6GAIXDvs6amYzI4mNdUr/OQ4X9rvtp8ie HrALeKF7AlVJ5F9aGYRzJ94iV+uMh7BF344GLsDtS6x1bLZWWi9EOLih31ZSbZjpmcAA /8D5otwjAA/wDX5Mq2btl3G49Z273vvyFmeSLMYj4FG5xU9t2hlnAJA+RQDAjo9XKBKS njcQ== X-Forwarded-Encrypted: i=1; AJvYcCWyyEwXdZ9i2KeHpEyKKvLDiyTE6CXXhluiP8w8bqHthYaUO5vDc9sUB3lBIGo3mcTCtDqe+bOaRs4YSGh+l2v1@lists.infradead.org X-Gm-Message-State: AOJu0YzlzOZuByEz9Fk809nzJSTRMW5S+Q47e8KtLV3FnN9bPAp+Fvk6 IXT4WAOwXHiOfJNApOllH9u6V2frmLtVzpEfYUsobm9bqc77HXBOTpCBWPx3J0+CeY1Hg6wSjFH Ka3NKfQr7K+Wn6btn+7JQOw== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-3-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 02/16] mm: x86: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232805_351304_F71A1BC8 X-CRM114-Status: GOOD ( 18.17 ) 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 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: 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; 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: 13904441 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 5F6E8E7717D for ; Wed, 11 Dec 2024 23:33: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=vYJJcdIp4OFdB+jw/mn5ZasDVQdafEZmT3OPk14pFSA=; b=N05tkegK3I7Nav1IM1m3Y7uA5R k2LRPH0DIrJ4zpWcd9peQERvyCGDwOXiXlXNMTl484pYpc4E6wVs4On6Q0gDAW6veGyYwmbnx8e9n 6afBT66xcg5+9QwkgieX5FCcoNuUpIXTGWsRZsieSXFg3C5Ts9bKelO68vISjbiLxYgeJtRRsPW9O YgDZhMNYiEMWnIIAMrQMDYjtJWBUYXsS0M/v67onp1ipeT3d+FWzDRv1lpy6QwSiCOXxdYQRnH0HX KoeUioHkDX8/22ESmjX/rqoZeQmoBeKNXQvC3p6qMOeRL++e+IuDjRDoqjEkn+n2NeQEcpK/WPzOO f+O9KVzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWCo-0000000GTtf-48Ht; Wed, 11 Dec 2024 23:33:22 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7p-0000000GSXD-02ov for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=vYJJcdIp4OFdB+jw/mn5ZasDVQdafEZmT3OPk14pFSA=; b=p5OwmKIuN8VcijgOsSxQRKoX/B MZaZ9fxeCqZGEdQl+OajlodGNdRnErxAoaHZN4g59tjOBRA9nw5hcyY98pyTo+lzOs8nvYjMiI3km zDJMvW0Z4B+oOZsCbsc6crEO8os3cljlV34tEYsfcyd6YC9cMW377xdGDNd6fucvo1qe/fAZ7m/Ux +SGdzlmWYseTzkUtrM/pUqw9PZ0kerKA/BhfTv/eEJ43Nwz+Y65tyDE7MoVjbr6fuA6LAiKW2boDt us0VAn9F9zkoFkvGL8Y9DP7tC/jjZxwJPnS+9nyN8s5/YIxfFR86CEkPnTB8NZYWHWAAmC8XEszEv 2qkcR9KQ==; Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7l-00000001eK2-3FeR for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:11 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-728efcaf454so14860b3a.2 for ; Wed, 11 Dec 2024 15:28:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959686; x=1734564486; darn=lists.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=vYJJcdIp4OFdB+jw/mn5ZasDVQdafEZmT3OPk14pFSA=; b=xgDGUgyKboK7D0b3t4dgs6q99P65HPzaq0vFlrwRRovWD4Sl1lc1l4v7FctgCWukH8 EnOkMSgDy2HNf4Yd6RffvvF4ihn4DfwTFE5OS6sFlwte1ZgskZeVPcBfdnqWFEkarXX8 vWPZxbzljyvR3WUr0lWoHFh9iuSaSuZEOYDVo01hxcrYgVrJNkagPTik7Cc7QGP0ZgKA xhu3s/8icocq5R3Sk2GlwX1NOOiNT/QAc0ozhejIZ3LuXxz/+AgAO1MxJNnhSCCkcqdG /S0OhyoolpOpllPSWCAyTUhStyUuzghOFvnb4LDsZ1m+fzXOKLhiVTWXtpMpAUP4CKdz M8bQ== 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=kLFfGPYwGdqdwBbSjATM1h9hR3d/isMRWjEH27eOXxQ6ORtwlijwQHmuCnVn7CgjXl RAJJC1uew0YrAHRJu7Wm0TmJuSG9Eje6R2AmmPbM2byjkiz5ugJ0+B8pHc4iX0Rk9Kd8 JehUiaVpcaV9o6q2GDDW8uIQXqKAWixBiUXRMhuJMGxULVf26kHu1mw2ORGCnsxX/dqP YLJhiUEv88xiLkUd5vpzY/1H3S5b0iOQO2O24g86sWM1yvNZs3MPynafdX9p4zUksk7E OYYeyPP3JRyUorO0bsf6BJkbD2q4doKZPRNGXRKQjOpNA4gfGRHA4kSvpPNLrhKwg2Ty KYug== X-Forwarded-Encrypted: i=1; AJvYcCWh7SBBoCtUgihtI9UZuon1TrGEWN2G9UNGKNeHQzVpon8bDYPwVh/vmT98UZk4CHa3pd9rkXD7mWOhjpkuN3VU@lists.infradead.org X-Gm-Message-State: AOJu0YyEh+Vdc0Wf0TBFxvcZFHThsJC3qkk6bLHojzwg3tFrGBxc+b2v ff6vEC7Uh4qEWlHqwJE4VQx3FjMcSGFvjI98k1959y/KhpWKY8WnlGSJxoaLjH1kF3q030oENar 78OsiCX+W+NX9gpHPHZmlXg== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-5-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 04/16] mm: alpha: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232809_874178_C1F1F44D X-CRM114-Status: GOOD ( 14.25 ) 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 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: 13904512 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 AED1FE7717D for ; Wed, 11 Dec 2024 23:39:57 +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=qH5hFVlZb/xpQlMxAKu7QZtletX8CELYGGCCA+g77Tw=; b=zweAl+wqXR8PWI1sf53fr5m0AG 0pECjjUC/KqKDIvEQScwGnLA6LhtNtXpDYDBZ4XF7ws8fPawljlyGcxvEM2OBUjruyS1+WqOYHjVb lrOoP6JoNGcgaeV4ICDBdgOoxYvIkrCZWQ31QQ4igCu2bd9HEaHWtAXPDNdcFAc6oCX5Wp1+4xTy1 rMDd9d5lRdNCoz1LIy3tiKYl9r8svaR6kTSBsxRTzR+g3GDeBDIY75VFIAAuEYtjenPpi+StGrP0n QG7jFZ6HWYyGQM5+WZqO1rxEoLI3X4vDRYS+a6+2nsmAhjosPwjSSIixr1QsQsAntgj/u8uXk45e8 S6eDSb7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWJ0-0000000GUoy-3mfT; Wed, 11 Dec 2024 23:39:46 +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 1tLW81-0000000GScP-3baD for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:26 +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=qH5hFVlZb/xpQlMxAKu7QZtletX8CELYGGCCA+g77Tw=; b=m+DORXdQMRvEm9gBjn4f2p9rQa r0/EGFrVXLzYSkzHzMbDP68pz0wNbYvaJjPdvY/4jpGIVolGjxNP9fB3ZHYY84rVadAnUW9AxOc65 yuPkgLJN41eLfcsTSTUklj/61ErMwgE2azBiUoGhpRyVS25Iu73DNgHsoanRDwfrZeYffqFtidXyp mywwPWPyNcmmLm93w+CsZwVYYpGTiSyD4eg01qDtsMrmZEU1l/p5XevV9jbRx9Z9b2+DZMvXOXJzK 9eJRJ4TWBATii9l4G+FXP/l4FfdzMbw3jLUhEfpw2VS2p5Q6HbI5IpnZ37b2JZdC2cXdrsQfz67Hl DeM/deNQ==; Received: from mail-pf1-f202.google.com ([209.85.210.202]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7n-00000003w1G-1zoc for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:22 +0000 Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-728e3d9706dso17885b3a.3 for ; Wed, 11 Dec 2024 15:28:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959687; x=1734564487; darn=lists.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=qH5hFVlZb/xpQlMxAKu7QZtletX8CELYGGCCA+g77Tw=; b=tt6Ksu8CL3hdhJYb2Vo6vL/VLpP/kibOH/YQs++rErt6GFvTAQ8PZtxkeDd7Sxb2xH 0IrGPc6GZ90whuP0tYN6RO1LLFRmZwUJDHzutpMPK+qX6rhOtlINI6s02Uz2NcFJOnVd RG1pHsWyYCU6D7OWzUV2V1rGMGUe9hSeEV/bSz+lnvsRiAqEPE/dE6TkLmA9WoF5E/vl iCg3oLsJZNYv2jwWAtR8V20PkoEsZ5UBy0pFhXlVImn4xm4EuhuJIOiV/dg1Ipax7gNK zzWbtzv1duvpmf2xvqYTdlnpnBTJcYwVNWGM5sFRXsJ6bFY9/9/u480/NY8m5WsljmKm txSg== 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=UiG91n6MuRrlB62FryFroixWxhnzrXfs8Tpkh5VHnhqAXR/xtB7XQW1RmoGtdxXp6j jtMXt09yiAWZ+Vy7q3V0HCeaHxWiCfYXQNwNlIBcY7qaL59zFTbo6ZtadjEouU2FMdd/ GYkk1SdSzM9zmSu1UABliiqWxk1ZKgwxAIarB9rEAXi7Z1LOMjcVcUxJaHq621yxrEiR RnancV9NfTFQ8+lvm8POdppM42sb603TS9Hw0hFXgNQkfHvLK8DBb+Iy2xTEcV5KFNDQ B9YnJwO4he2IhvPcCadxhEHpPs1sBL0UWfT7QWlHOrZEDzi8BLBtoJNAo56istOGJhbr GyjQ== X-Forwarded-Encrypted: i=1; AJvYcCU9xG/vntUguMrBMRQbqlkwQF3lOf10LpzGgR4wcRgEgD+3qd4PrwB3NCwIx3eFYOMXqyM4+mObZwnq9hs23aR0@lists.infradead.org X-Gm-Message-State: AOJu0YyO3S5C/lHtdaIn0pTO8LX/5/CnH7wxRTRL7SPdcJCfNuaw1R1q iKFAOl/GXBCGabL3Feqll6kAQ87eAsrqndgnSEgKyaUaOK2CFAsUv7IINuyj3zswfpU0diw97PQ t2ehmO3i+YwI3/X363G8vfw== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-6-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 05/16] mm: arc: Use generic_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232820_940756_80CB9527 X-CRM114-Status: GOOD ( 15.68 ) 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 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: 13904442 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 1503BE7717D for ; Wed, 11 Dec 2024 23:34:38 +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=My9IlOPq9ns5P/NZxzKqYlKU2U5PkE8SqDXKTXIHc1k=; b=s2cd9Ccff1wJ4YJqIcuWAYeqxZ s6o2fIoH0/hzJeKCcxSs5HPFFcY+Jeq85Y0yTHkwWWrL2LiY2rgAL1jezlZTkfGto4MrbtnMxgrSa W1ytDj96noaME6M+JQP3UZABjSOwwyi1dzrU2+tZQllfVusFQyl2kdCQTO6FEc+dvCKLGCv1sEkLd YPKSkZ27SmqJdl4bE4W25OsRyxDj3MczMLCEViWoDurAGyFutkvQMN568FahPZxaB7eaKLXU7mqs6 xuGdDwITnNesHTEzgUqc6xFRY5LtCWtxqkNyGsiMI9TUNdBBusTRZefHSt9d5ItleS/34lEsMkYvJ g2jBMJdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWDq-0000000GU2S-2p6c; Wed, 11 Dec 2024 23:34:26 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7r-0000000GSXk-0NWo for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=My9IlOPq9ns5P/NZxzKqYlKU2U5PkE8SqDXKTXIHc1k=; b=iFQO87zwjdyVTF7uLetQ2XJXfk DduXJIaKEM0k8tu6C+9hQIrcNAyRPjsdyz7GbrYsJALXpo0k0/PhsVCN+uQ+pamQ5A3DP497foL4B 9W3Ue7kXlfyEzSwET1RXacn+D2ZTJPquNmMQvzCIl14BjEUBomIkthSCXfoZ0LBCnWWhEWa4hgAZC LmI5wxMf2lqNl7L+qD5/R3FxVEqknDhN4AFTwRvWjiINDoftlzZ4Bs3PzCV3qlC/D5X9WmItzvnOZ khtPSEmGh1VCWRfqtoP9YwQU2lx+zd0ACc/it3tQmAnGN73CabOUnYrKuODYk0Yr82m+dvwcC3mxJ Dvlm/DIw==; Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7n-00000001eLu-3xiO for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:14 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-728eda1754eso26696b3a.2 for ; Wed, 11 Dec 2024 15:28:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959689; x=1734564489; darn=lists.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=My9IlOPq9ns5P/NZxzKqYlKU2U5PkE8SqDXKTXIHc1k=; b=Ig3zHH/lTutfYhaOLX46aZk5Aco99mDskmKb8BZxejwrFaR6f2WehuNeDw5FRSyuiO AqZ00JvhVvzuCfVR0uTcKYUEf7mtx6pKgsGgsB16C/YC6XCpCsdiMD9pwvFIRgP+7ktQ +uWKfV0FZnMM/jYOCxvjfxrneN8nZg+hp0WoAAPbktCT9Pi427QLm8Th7RgWYGdhATKD 3H3SvanTVCQ1WvwHRJRF4PSQsHIcn0Z56JaRM0ROX7iffqTJIBW3eX0YL5lFqrfWF7mH aSySmEQ4RWvGb29/q9T9Y8sRjOjlrN8X6UZ6czStoeFolnPGF7UPpmHcEzKut4XryH14 TN6Q== 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=QsZhDW0ptVlraxWhsNEQaE1hxylVcyVfd1Dt8hZ0le0L1PjXHWR0y2vbVFUmdOe7A5 Us4AwjdzpvLO5b2tBsdFj4S1J4R6SmPq5lxvcK9qRdYlm89oos8uPK16mRgGCnVBMECD SFRIv2nDqPH+3e9W+6qVKyXK9J29oL+DAger3hY1FmnMhGtvmux+VEJrLjcusGeL2z7Z lQMA+LJmGvR1cYEDTI+ZTYJeBsDsGL9wrEY0xVUj0zejBCnUwEy64xmk6j8cFc50pHX1 KfPBGhKTcdeAItCsOg1wwu8cEUIp131PZnXmUi82bItiulKbWDlB3DwMpa8T3p5oHjD8 2RmA== X-Forwarded-Encrypted: i=1; AJvYcCUjqAUHJx3Aa+Oqw//0o0VZ2bw61TiGuOMVwENtfO7liWu9aExTq68LBvxO+wPtCC9L07BVCbL881El29PUAA4J@lists.infradead.org X-Gm-Message-State: AOJu0Yw1tspuFgdyZkx3GCl8ox22TyEKrHZoiGcA1Dg9vCgoA/7edK01 SND7MUgQ/pYj1KY14LPMW4HqiwAa4dib69dFKJUKDfxn93HV3lRNad2te8xtnpFZyFspLNKngeK pSL/3biV2jwR8KSgJZ++rGA== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-7-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 06/16] mm: csky: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232812_073568_0E5F58DF X-CRM114-Status: GOOD ( 16.74 ) 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 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: 13904444 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 7BC0DE7717D for ; Wed, 11 Dec 2024 23:36:46 +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=SCptMPgkqno2A/YzE5Va18QE7zdNUHtEUd5zzpUozKw=; b=c0lRAni0wcN0j62JbV9FzTGCso FUxPbCCtGd6/VqlEkfAOsppMO0S1VNIUiHC7Cvc0bUkEGstOGJR+czG1lHc7XG03etF72kYR20KoG j4125r2tx25f4WkaIg54so5avpRxIg0tEc363+ZuK/kxuSWAuS4wh5HLKo2B7QoYr0j3d810hAVyp 8T4af63K10nFaX1H9M71bIF4uPEKXcOuxlNVhjvNNXJfPxCVMKN9mJmKX40+Qhcg9yVh9aynFB7nW v0/cup88lNvWwimYNI23Y55OcEzSxWA8GzsAoZCmVhFvQ67TtNrkl5+te0EX1d+gLlSAQYjaPSlZ1 7XpEsaqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWFu-0000000GUSC-44U1; Wed, 11 Dec 2024 23:36:34 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7w-0000000GSZa-39yY for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=SCptMPgkqno2A/YzE5Va18QE7zdNUHtEUd5zzpUozKw=; b=F0QP4rlntVg1znDPeKri6rEIIv a3gZmPkEZquIKhaDXfOLYOTNNDLuGdCeyQW6l/dXBsZ/9yWEjuI2UdsHgd8pCJM052/vTMUVTcfgV 93nHZV/smrltQ2+AgyEMjwABmZgVmHvIneDQ3mG33QySCE+nw30zO7sg4dadEAw6oN+mTUzveC0zJ ifcb5iYSHmmHz5YPb3PGov6vKuamIyJDwL6TzNeU45PTtb3rQuJ6Gic7xZ3aujL48xhItz6W0aJUO C7V49IEYXRkJPl/q8+Gg2PIWqiE21x2COfSUeK1E4zmL3tUwBL49L1IwLHBHvwymsLGrt8aq/4dtp w6xH0xdg==; Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by casper.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7s-00000001eOR-3SsL for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:19 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7f3e30a441aso28425a12.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=1733959691; x=1734564491; 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=SCptMPgkqno2A/YzE5Va18QE7zdNUHtEUd5zzpUozKw=; b=Vj71ayoTWtBWlC+lCrC2SoVgdluwIfEsca4SSxfY7rV3Vjy0mqBCb4Jp0sMJGKo4SE o4NbpExBndzrCUYHsZZcGNz236cwmTPmu9PCELHPFH7x5H+jgBvBR4LhbnFQMS2oMpgF CR2x1iO1DceBi+nuqvs7mbRQQqPPUUkpBgfWXzyGStDsLO9IdM/07OyryIVjaH6lyzBr qfGkK0lgtWlE7THjV6FB1JL1Ko41sCA1sp1QP8yRyShyeB6JlYewLFPxnhokoR9G3Vi1 U+wub+Hwdx/h5WBfD8pXCU6LA6mGH7K2f8xC3hsV3hADALvxhpbixvx7sWEnd8EYVj1o Q2lQ== 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=YiONUrAX7sV4DlTOCnGOeoT0jP++B5MiSnSPlsjQCLbM0AuPix/bru4Sdwjtt91Fiq im1WtQ6YK9K+iddBF3rRrlLFB8gQwnrTEBt/8ldFtZYIeXqe7rBX8J4rlfvsiMHAkItT An8V+CgEAGfDegc8kCMpvAs1CEbrUbfvFmkofJt4fealv9ZK25s1BWKfdxOQa1jx+V3L Ip9AF8JNnxkTrYyRVYBkgq9xBScvj8jGS+sN/cXeVzS7eV0iGktlRE3oZza4BV6CzLTw enyz1jOlocxkZi9qGH05qc5yysM/DFVmW9GZIqG5h0R8a+ib52ulZk56xPDwumhy5/6A FHIg== X-Forwarded-Encrypted: i=1; AJvYcCXNwAri0pSM2Tze4N9T18u+wyjLw/HA/BUmlmGjpkfTYv7NKO7DbhjaLKLHIgk7b32QGC9mAcpQmQPhVSm5qX4A@lists.infradead.org X-Gm-Message-State: AOJu0YzgOEfGYPfZfkrRnEAQx2jl4m9U/XRMZekXnnQK+dgRjHZALU6N kGdECZZCjFdo960QeTfSqb0nzKF1sC6oKrYO7vWUkBk3LnUx2ulabqjN2LoWiEH1YQPVc5R6Mn0 emvwnE9kEGwe5yMukGS3WjA== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-8-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 07/16] mm: loongarch: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232816_963124_3B2AC307 X-CRM114-Status: GOOD ( 15.45 ) 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 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: 13904443 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 EBBDEE7717D for ; Wed, 11 Dec 2024 23:35:40 +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=lSyWTl6AgHPTeHZ5Av2U3d+7m6ogGk/gBzGXwo6uPmA=; b=ZhakYg1oam5asHhDq7mBBe1eFN ca2Jv51Gxl2dOIRvz0pLDjT5/pQUkfK08b2gR/rZy8VgdsSjoNljwq5cUI06ML2EG/7fRNMjb/ZLn hov9rCDGaegdxiPu4uTh+itS/6W6oc5eT+ga93ZaYuPcuWuBgBEFzV+v6q88z2zFxDSfIlB2vT73/ //RlujkJmKF+p6/1BSCO95fDnBhYRveLWgd+1E7SmF8BsRFB/pODDFsyNXNyqPKvgvNlFQMS1BFWJ ohcQAy6fJRh3lvX00hndRMNGUKFFfq4Cvah78L0+nEajsKyf+67oLbKO+7tZmdWWcP88l7pt79D+e s04U4BWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWEs-0000000GUDr-2JzG; Wed, 11 Dec 2024 23:35:30 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7u-0000000GSYj-3WWm for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=lSyWTl6AgHPTeHZ5Av2U3d+7m6ogGk/gBzGXwo6uPmA=; b=DKFJ5sbzHl19r1aks9EzUnIFMS Cq79IHl4f+9gDVIH3QW0lefU9bWStuXf1NTiPUjc0Om3X72S+wTmQQaQnPSJIco1jyYDxlDEuv6aC EFXInOy5QQzFc1Fq658Bol3mRCuIdMg1FwgIT9ay0Vl1wdXgYYKooJ6ZHuBZMhrzpp8D1qEUjCLe8 mZF3H29BsbiblkRWai1ipi/4a61WG0IYGyYpL8jICPgCNneopYTxfDCOsS98BhKkkeI9mVRxsZ05M iBC+CohJm/gKKQ+SD1SESUk4rvquwgHabNyHxjevFOAXvMrfCy8OkwN3iW/j72PFkdCqQkAf3p56f U2qtBgpA==; Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7r-00000001eQ4-2vWx for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:17 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-725cab4d72bso19398b3a.2 for ; Wed, 11 Dec 2024 15:28:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959693; x=1734564493; darn=lists.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=lSyWTl6AgHPTeHZ5Av2U3d+7m6ogGk/gBzGXwo6uPmA=; b=2a3zxZ/2QY7lXdlwRp46EiUR6/33ZV8i/gUxqgx8O392lSrJkx58OaWyu3wjhFV6kQ umIXB9HyKi94LAA2cBBTUBBbARcrh84xuUp1OedGvDtYHbj37of4epwP9IqbhVECpjoB AmkTijdkzG9G5BIxK6qtOkjOvBFPZMjIoD4InDP7tzkoHxsI3NcNWupl8QRgL8fmXDU+ n7bah4LMb9t1LdN+QWnc09x7OuHnGypckrUlSKLs4M+Rteox+yJgkcjvlTgitrTfYd6m +abZOnUkG1TMaHg8v5TQaaz+0NBE1s46lLaWgCGG2lIXkEw2EfUeU4MpcS2P31PheEwV 02RA== 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=stHZ08qeoIAQl0zTqpB/741eL2WxFXogqPTv2+ZJ/3i0y7Ekm05VK1WOquKjdJi7gC Blx0oQHqwSWgdvIW0jsECNqk4EQ2z+arPMvSer5rdqHz4VbxRy93nEOlSnUa2NP2tSBC NVEvO/iJwok0DWzoZbFWQ3cXthjOR5RwN73mI0uAW6iRYgMDV5g8Ma1BNPZ+RrnbLDUC YuoVVk2Zxg3HlJR9kT+rqHtLDIj1eKaZcKoZmW5HgdUwF5zvcUyNMSqenofrzvls0R5V z39ZlB0N0Xn3F+6eY7lH+SMYuqgTB4LR9CXj5897SCaX41kcWV3zAvox9HidxdrMUicT SfUA== X-Forwarded-Encrypted: i=1; AJvYcCVMjnC3dsaYdC0j+B0RgDDoDU8XGVtR1Zayw977c5b2Vo1svcBIRn08Y6ghLHiH3Xn0w8nNngOYEofLAFu6vuL2@lists.infradead.org X-Gm-Message-State: AOJu0YxzcaNhKmRu5dxGrrdXX5qBCZLvdrhAATXM4TDlGsTJWIYdaB1E PW2mZGy1U/0OXmm11IpK/6Riz/XpaeZpZX3B5eVOtC0Wi6FAMpFmDMi+nrjIckmuRB3w2rIY0Xs Bp4RUn5/qi1vlamwQiGlXxA== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-9-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 08/16] mm: mips: Introduce arch_align_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232815_909332_5011AEA8 X-CRM114-Status: GOOD ( 15.53 ) 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 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: 13904445 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 B3577E77180 for ; Wed, 11 Dec 2024 23:37:49 +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=wxiw+xEGORRKxhtCLZq/pFo2CvQKmbacY9QkYe3JDdE=; b=v2lyPkXEOwG8wBNKHomz9BQExC pvf5sgqbrpSifz2aeymi05bUT5MzGz9Zyd4p1fdDYPG1oukSvau2fCrpMVVTsnPmoxTMWbsGUVvoH VN6pV8TWPTnQN5BpL09gBuJ//UwvciQMmjvfoN2C6TQWd8wrEth1Xr/dykXD76l6/6z6Pauq692bY pgvuFPQYxwTN6yEdkLJKcjs09+eE1d7Z/DuAuTW9XIiSOyROMnTYJ3fIHuq2EqExlwQx1LsyVQxvO ioK7UMWwWN7uEAEELCsQml7TRCNezROHzn6tnQ0w/j1h+vqCHv29lcIgT8KoAV09DVrzXNBrjh4B+ h20fdwvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWGx-0000000GUYB-2N97; Wed, 11 Dec 2024 23:37:39 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7y-0000000GSa8-1CJL for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=wxiw+xEGORRKxhtCLZq/pFo2CvQKmbacY9QkYe3JDdE=; b=MtVA27Z8uOWCiYcXt519Rcjkab 3zAXJ6ipGLQNYY1X2hNcovN5IsuGD5NgRVI9x+eBNV2CsiCeKb0ARa1A4g8wdaALwOQsmKykgujmT VJfSBNjPiYWAQTrp615IjaA5e/pa5q2z3ZebEuIo/2etNg87qRWqnVm/ZaJaYdl+ZExjDLSWX1jqW n647Xme547iu0t9QrZkmkU7m9RYX1ifpR9SbqnYGN96h99mjoeemMsKCe045JF7n+TyPdw3vFV5Ng URShpkUm2/fta6i6u6ppnQ58i20Ku/G6REM5DFInHqvYCEdczFQGjEzbR+S5kpHWZO0pIgrwv/kUM i/8tIw+A==; Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by casper.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7u-00000001eSd-10Wt for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:20 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-725e59e41d2so24097b3a.0 for ; Wed, 11 Dec 2024 15:28:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959695; x=1734564495; darn=lists.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=wxiw+xEGORRKxhtCLZq/pFo2CvQKmbacY9QkYe3JDdE=; b=KpF7kk4WVhru/HFvJ6GmGqwLwSFOMAZ/F4S3xiTLkHAdCpM8anYwV7DQfR06cFlhP4 O1gAjt62rf0nkiVfEYwsoURd7lADnm3QyyWc2dpcRy5JrWTEC2HKFgINskcE6AlJVKEi NQrqqc/e1vhhVmfYcBES1trpxRipOnsFk42ewb46fmH0s1uK+7QGiCBEIqo1Q/bMBCpn eANNmtXEuJSxJ4uX0ubvppUuB28RLc2CH1ytmh22TI1pJ9cDu2XNGNh2ovuWIZX4xA2d dls6fhmIphtlRapqhASvpWbiUulLq+TChAlakVZSuYDOsRB4h9kCkYxycl6JJ2LWBLXG 4JXw== 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=xKZ1RIDZdGKYBFxT1x7e2jY7s9saNTcFsY1m52AwGJ9Yn/0fnYVVGTBVpRfRc2NzVn pd/DljPma4SdT1nZ0GY2WDUPymfMIKW9VQk9NUqQNgM7pTebQsq0KfJZGAVFIFx9CLoi TSgUMSNUdY3An8BRL9WcZdGOOoJDrc/AJUkByqNxm5hSdkrq+9lZ6jltCkJkz4TYk1g2 bEDmEZAIUBqeRD7xYRAvNHXnnUCIjRYolg0ARILTZMVk34ilZ3pU3Ci8c4F8/JCfR1u/ MCuJNo3jjtF/LCV8Ol+MtIgTwzDzFWBsLRTszz1jn/1vkSPnpNCXFWwySnG+/npsvzMh 4RfA== X-Forwarded-Encrypted: i=1; AJvYcCVw5TAEIb72ZjbAu6AAKuscVK5sVRUX1Z7T3vrCcltF/2UV0Uf2cBAEV3bZ4cavYB6ObtzYOSpD6OTGovWr8sNg@lists.infradead.org X-Gm-Message-State: AOJu0Yw6PGAi78AlY9LsonEjxqGGJAn0nODhRQBEkfgW6xKgLzXB61wd W/fmBveO4IG+sU6PvMk+ia817snYAcNFOG4YXLl5uQoeJw+4+3v9BDtILMVy+wLl5rl7g8gZQOT 1BStOU+jh2/LkvBhexBUsQw== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-10-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 09/16] mm: parisc: Introduce arch_align_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232818_422698_073C3568 X-CRM114-Status: GOOD ( 14.59 ) 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 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: 13904513 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 9DE94E7717D for ; Wed, 11 Dec 2024 23:41:03 +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=6OFip67XXDkH1HTauBcRO/RiBVwg85LoldBpce5+fvY=; b=rHPgznwfbFLi7o5eTbqB35dbrp Ub5x+c8Z3AFqlEh6Wl2mSBd5YSZfdpp8u+rw5kWrP9bXRJT6ju6/hYQx2HcFOWcJKU71RohbRmSwU RPJO3ajR92LaROQmBllAc8vqMo6UDk8HVK9/qhmUFdVMoU4k79hWDq3ldMA1SxF8dpaPsruYoULTB KgFouNn1Ui8aDgnNPan4KKf+jA+rqfXVt2qe0L8MCdYMhQT+nXtXlqlXnIFW/5/VIwRSxgVwzwRkn To1HoX17SERy5mmff311pg9qT3SuyvVbiwqI5Zr/QB3sPhrKFhluhGzpS3l2NpBk4PlI+89C3MCTi RFJYe+Xg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWK3-0000000GV4Q-07aQ; Wed, 11 Dec 2024 23:40:51 +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 1tLW83-0000000GSdV-0ju9 for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:27 +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=6OFip67XXDkH1HTauBcRO/RiBVwg85LoldBpce5+fvY=; b=JUR/HcfFR9vmgDQ2/KyfbytWgL Im8j8ij19j7XXaJdwPJS4/+ettQ0IYRrnAbET52PmlHAh7fI0CcabuJe4D4jgAPGyON4ttExuozGR xcI1p4wAqpYwnBY4MQxwDVWUo9/Piy6U6sRj30IMJir6f9ih6FfGAX5l9nPSPjr6/D8tzpEquBS01 fnYHt61+Q3PO49ILouGh8udmqxwQ4zGIe0jTZWhHENE6H/gHHU+oQpzO1YBlCjX2UlRywSU836Cx5 KAz/SzFIuFX9DX0rMy87cU5eLbWBF5GTufBBJXikOMTXfUbA82nNABhIy3Npa41YfGwB09UDj5REZ X933u5iw==; Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7x-00000003w3i-04hj for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:25 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-7289afa200aso47010b3a.0 for ; Wed, 11 Dec 2024 15:28:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959697; x=1734564497; darn=lists.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=6OFip67XXDkH1HTauBcRO/RiBVwg85LoldBpce5+fvY=; b=Kx+rYiIbY4N1ReAGyHcehO8AAMvgX8JVBnbPvkrlcqCnO1ywTCPOoxyHpVnjVZ2+Id pHOjUkhCwF4i9Zpb44nt7GmP/b2jGK89yI3LBs0VJXm8RVBhSXS/+fRSv4o7nVWjcnJ/ XJ/50hAlxCqrfXvgjROjgycMJcfncaA3aTrPbBOmlJXbWfB+gWJWNK7Eykv8zVg5NKUC B8yJH4hT5HQeiDjYneHMds1rFat9X53daynvpJFqXYlpdcHKXTBR87dMPXMEmBxpllyH 6dPsHgFkvRpLtYxXnM8SC64xv8+CkjDRO+uSs/K5whMP2pD71PCM92cm9UtY6ZTFc1w3 2kTQ== 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=KJEU+j3S9DnqOBBhwpOsCVDQJ0j/1ISsdXVTqWALUhDob9UOedhd+kSnrUWNNuuo1B H/hDCUsKcrz3sT38ir+BLG7zg5PRNDI3XI8cYA3imVon5Xbkv5rYV+XUBma5oNAbhhy7 E66MIADE/j0GM4EvBTx/HE6jz+Jz7D5YlfF54wE5XKEcZghVM4wDVMlI31o54+Ng7I5c 1I3PRhnE0lmDkV9pTYQppRa6Huq24TC6XYMMMWzWti8GE6POLLCJtl3TcvDPVbnGivZU JvgXppw4V6M+NcAn3y6ruiyn3+EFfZBadV67atk798dXnhcuT2vgsHLBGR31PbeDSHJE DTRw== X-Forwarded-Encrypted: i=1; AJvYcCXasKo4sYeEw2omSYK1n36bc0znCEZu4fsMTPKs9slKzyvkkEeeD6HIhwdqWP2pVJ+xAlMSRaZ216YZvQc/qD6Z@lists.infradead.org X-Gm-Message-State: AOJu0Yz99CCiXxLkRlO5niymk94vPfiagPDxwRgyVI+9yiGlb23OXXOs LpUj9gd2MyoD9zsAftg56mrc6fDWyrDcdmZbJM+WUZv+D9b9nkm8gPox12DhFbhIHRnQdhuipuH wSSGcGRz327qunhwhy/Lazw== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-11-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 10/16] mm: s390: Use generic_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232824_383450_96B6A2D6 X-CRM114-Status: GOOD ( 16.17 ) 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 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: 13904514 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 90105E7717D for ; Wed, 11 Dec 2024 23:42:08 +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=uS3JA6w5wn3oIbxGMB+ie6BxkNausmcv0DhJz9a4fkc=; b=4AjsD0HhM2eWGb+DJFnxifQEV5 lMSEx4Vzol5WwJH4lvStCdDnCHU12iKtrLEkwqzbk5euC/NHIqIP8Ml/C3UZ2ofZL7oVqww89JNnO w5wYrn47a+nAC292o9xZrDA4u/Vl3pZofxcK44dAAxuR2QkG/nGXiqt8BkJBs0DoUTkIUrCK09IQu QeGV7DtN5lUlnYEHuDD7YMgpfzTlHPuMK611CvG3OaLPmBdly/lriwzUgCiaJkMIm3tY0HRy6ESP0 0nu5H/SIpTwWTPcPCr/nRNgN1eqDJUa69SgeIXXO8OOMhuUNgGgN3cxwFyJgw4fp3KtpFx/Envqyb CMT0nYnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWL6-0000000GVQ5-2A3M; Wed, 11 Dec 2024 23:41:56 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW84-0000000GSeI-3nMY for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=uS3JA6w5wn3oIbxGMB+ie6BxkNausmcv0DhJz9a4fkc=; b=c4T4H/J6QP9yKUKRilKEUJOMC2 am4fY/dUJ5zpwHlQMr7zlV8hKZ4GmVi8DxXLzg0tJPTCd4PAk1I9T3rJWr4uDav7gDj+/M0Apl2Ae O4ncg4fa1f0I0mx2Z3CQfYgxWNvpE8a1vH6urYGuZ6LUdhrZPoFsQFK3FJFbQCWi/KZ3VLC9ZraSI LpJVPUgoDkzJWa5oLSZHebb+8I9hl6CdIbcnmlV6pWDt6NaMf5Q8UintiRrbhy1seWQdOLhVGze5H 4cTCyt8E9XK3HTyo0K9gRgnxnhYY2Olz6ukn6YUrr80bqUU0+cvnXIrRlZ0OOPoskctLimW03Iy79 MOze9M2g==; Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by casper.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7y-00000001eVL-42mR for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:27 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-2178115051dso5245ad.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=1733959699; x=1734564499; 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=uS3JA6w5wn3oIbxGMB+ie6BxkNausmcv0DhJz9a4fkc=; b=NRfl6XdYnyaCsg2QZIyNMQBeP8P6KIH3gWt4/rEoO/sKgTGRYs8tXFe9XdRPXRYgAe 3cebLmRQlS1TPa4eI9UvAeCof3+mEEzS/h5pO3FDzVUcwZirODjpo8uTm59TmfapUlCY kcjZYbaPES6mhliQfk/KIYFgfu/9lEurahW8iXUfHqJdrLlnl22ke6GZ46lNskWn4PJ0 UdV9JFosiwP3ayDd5ljH/hcnuBgUMuW8rvsr5+VjPxmB8citpLyqXXellvPr5uYVl1jl vZ429OZVd9FzT9mpscP4UIqNZmQgz7LM/cveNzQVplbNzSGM8lCq76CXyAF+CfEZWCer W2xw== 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=dNvYawGXMI7lbv4Dc4+G/wTare2aHlWv1/Lcrl/B3Hu/DjJqi1jUorB5fCl1fDGYA6 JnUW+0vjgC7C/r+Q7yT7aGPBZmZ8OIokBdPagNS0qecrFMfmCYLdI7bktB1ghOpyoGQu nJb+dSrhp9gqyzhr9nkl10zstyDuitx30Zo80Mjq5ijO4ihCRFkHpHClrfGkizQQ3OI5 h6/vLyqiNQAfRvyCjvwX6XPPmcunnA6SENdeGVB57M49fU4Yvf84pcLrmXHhiaFLFhcH RJoyOKN3LOVZoy2Jze3+aTlnxBdc6Zd238BDeTETBiYOVrSHrLB6Y/9RIHL3830Bv6vW I7Ig== X-Forwarded-Encrypted: i=1; AJvYcCVAH6KzAkBFGcJKzUY3lbdHcD6i/EO5qkwJqYqBZ2QJeRjemTkICaJhd24G3dsQOgG+U4Qt59Gqk43awNC2Fkbj@lists.infradead.org X-Gm-Message-State: AOJu0YxngYK76uzWUsHn4y//tjTGUgWpkGqn4iFUZQgZrq4Z2cPIXOca wRzO5yNbFzvIwSzhEhQtHwGy5Enw41XaH2ywrwsRyApBeLBfuqErGY1De5UXabg02DUvQic/8bV OsnmCXHj+Gn4KxL3wNKTqsA== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-12-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 11/16] mm: sh: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232823_053331_90274A7D X-CRM114-Status: GOOD ( 15.69 ) 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 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: 13904446 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 903C3E7717D for ; Wed, 11 Dec 2024 23:38:55 +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=UgF7uGjYnhvUd+Jp5od3s3bWQayM3Oz+R04wRikqyig=; b=4qfwx9BFRIlg2HlTTtQXuFo82j Bl+uCTLVyK4x3ML3SkyczpnQN0w9N3P4q+0MENZd0JOekd2qZ7skxCnY18eP98KaCIm4L6+4O7ZH8 2SWwsRhMdnts8ZGOOhTLD77Wnf6gxg6LJhU/lVnMdbbAH4oNE09jPMEeGyDQKrphwkXTSrzW6OycD X33TtaJY9fsXQwTNlxh0nVkmbCjiaWzyUQCKhD2rHE/X6mU+hOzTKAi3nTtJPeIJqpV447w7/8jkj Zfizm7nFsk23fxTGSW6ZvT7mWfSMzOmXgB1nBLD6/tm79OQF0CUN9b0n0mHgG8KKYyUNAuE8E5y2T V4/VtYrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWHz-0000000GUfL-1uEX; Wed, 11 Dec 2024 23:38:43 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW7y-0000000GSa6-1V1V for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:23 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-728eb2e190cso13261b3a.3 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=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=UgF7uGjYnhvUd+Jp5od3s3bWQayM3Oz+R04wRikqyig=; b=LxAuibNI9/xLSXf98Ad3If6UwR18JvaJYwPEzzThyQZzELjy1t6PC/XBYgkvBbX6Bp CbTZ1Cz7bUX8qhxtpgvolDGGQw8FmgAHL7ug8nVmGS7FEAE8ZW8vagftvHwBddIkRJmX CrvCEu5p37aUpFI673SRBItQpF9PotT5flp9eZlyIdgL5tasK2wvsy27k6KBP33l6UF7 M1grxCTW8t+vPyuvJcOlnlWR2trBQfys9n+FhT22+zmUGWvsodDv8W/NOKUjFlltNIrE FMzfnvw/j/5MaovinIXdVEDtA1Zt+Y32uS1+QF+un42+uHYy0ozWIc3gyEuon8fsw2pR P2jg== 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=MXjJILm6yWbg08S0oa8PHzCFxiWkTGPfIYxTQ9JD5Ub04jaTV+ICwsoGCSi/6mB4+5 9usdX0hcs8DVBYQ1CxC2LuoMImh/DsjXZ52NHjiBmSYsKEw7ADp9EP89P+JJAOcVNfMB BXaYxW54BXTtaLvHgRuziP4aByGk9Xn+iSR7vmtqkH8Fy9Qk3ctwmhA3SjnUk+NrL58z u+h3k9HDrVbC/jh9cFzefT9x/kDv5fJdU5/0fBFM3rxf3lc4CttFVzEomzT8nbKcXBlL sPUV4oyjeqJcKkodu90BL0Hc6PolWL4l/baNr0M9S5zLyI2tnwsKJtmODgEfgSNH9NuN p+wA== X-Forwarded-Encrypted: i=1; AJvYcCW1n2d8n0rKjY4GL8uAQ8qM/TecuCd13ljbFmtgb9sX2djZKvYahpKLM9n+HJug/BhbYU9iqQnaf/5IUnWf0fq9@lists.infradead.org X-Gm-Message-State: AOJu0Yxiu+0VpDw8E1nRXUSZQnGwivRHntZVOX5SphS7dGi5gAZcUcO2 zJ4xeG+GHK0HfTlnT3UfDfskAn95gqDVdD43J4LZDwlAtZK6HPqGh3Xv1hA563eJ6Sfxl3l6Y4/ K0u9lEV0AEkR7CSb3QNxb3g== X-Google-Smtp-Source: AGHT+IFqVvEP6jzHMp67taGtKGZyTqxXNFEg2GPfnpgGUKbuvSmZTqL3vNpWjeuOs0OQEe1804BSml5OhCqqS6mIfw== X-Received: from pfbdw6.prod.google.com ([2002:a05:6a00:3686:b0:725:d2c1:3f5f]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:43ac:b0:1e1:9fef:e974 with SMTP id adf61e73a8af0-1e1ceb34d58mr1527638637.24.1733959700835; Wed, 11 Dec 2024 15:28:20 -0800 (PST) Date: Wed, 11 Dec 2024 15:27:50 -0800 In-Reply-To: <20241211232754.1583023-1-kaleshsingh@google.com> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-13-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 12/16] mm: sparc32: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_152822_392907_770FE724 X-CRM114-Status: GOOD ( 15.58 ) 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 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: 13904515 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 7BC16E7717D for ; Wed, 11 Dec 2024 23:43:12 +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=aLForDZ3L8G53NDE8CmnbZXOU/eHam8tpqogo1+J+z4=; b=lIJ5kYgkq+YdRGyvIkw724WjyK 1KK1eZ6ZQq1RUD2lOKJS9BzYXaxS34yiiasLcrsoC7Amwo+7DxaGyX0mp0AwY/N2BpZH3SPHa27Fh Q8aIAylrlJkF7kq7zYRzZOYEDMm9FFa4Weks4d422HKuHP/oUj9ix+6h9ok6sKDx8vq93n1Y+tZGd /B9HYN5tdBRWymuILPvNBnZjg7fo106dddGSBubI5KsPsGdZl2cV8WRNVzkJPSQe0rUuHj0xT2sKm XJA6loRFhW1nzlQM77gYa7mpqDna0HjYHGksNSZM3EjuKPVkMv3WtXBXSyLEtTN2DhbahnKZ9ctev Dqp2eYwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWM8-0000000GVqg-2Nai; Wed, 11 Dec 2024 23:43:00 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW85-0000000GSeL-0L2v for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=aLForDZ3L8G53NDE8CmnbZXOU/eHam8tpqogo1+J+z4=; b=tTWDfJtpsOH+32OcsRtB2OxcLj fSfkS0Gp1ahnz9/jun8Q12mCWmGtpdHH/wY9SBy5wdF+UehzBBDSa/79RicBtOEwcdk4EodknyWrU cTtrksvvmBjq0euABYA7TdI0kKDKRWAPBJQCIsOrNYKE0V4QxK8wvP9wVMV1CMS8YHqaOLK67tusA K2F+od8Tpk3iE7bGLf00vFKj18g+YeILc8HqdSB4Capmsgh40/fIuFkh395piCWvvHYmlWZmVU4oG jLz73VfO9XP7ft7C1uF37BP+z8A9oajoIXwYE4/Ttm+dnjeOjrjr2mfKTys51UBMZmM+cX+sYk7IV twIH1waA==; Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW81-00000001eY9-3cNY for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:28 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-728e4e30163so19494b3a.1 for ; Wed, 11 Dec 2024 15:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959702; x=1734564502; 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=aLForDZ3L8G53NDE8CmnbZXOU/eHam8tpqogo1+J+z4=; b=KfQp3nnSvFY5LUpGzxPcwFmAyy00RnlHcMyCQNa2LOlmW1Wf7yeaavj+el9Iarf3Ee bXfofC9A0iOuvTTQcVfBVa747gDPNUOGWQueUgt0W8r0Q0rbV0nWu+bIfrw6xm2heNsp EcGHhjx0jxUyBKdIQZu+bYvjpNWVprxZbM2fqUQKI2nTpLHsqtKQGNzDOaHVtqZYGnkw g1K+vArmE1ADhJk/zsUOqPWpkT914BaaFzTuNSNvw9HFkT4DwMhYh0fdYBDgMq1ALZPn 2hg6Rkv1DlXqSkxBMRJyPnNeQUBD1ObMBF6bn+TPzDNS1c1f8vs5KcU03TzwkblS21BA 5CIA== 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=W1ZHtHZu89blVNAsgZuqGZt8pUB3aWFDU4QZ/Pt7F+rC8Ewrl/UztblGtmkyQD+PLW 9mduVy3DtYfi6YqyBEbQ2EKqizPcs38toDk7oYVfPRdU1Z4BRyivpcFn47z9PSmvS3Yk IXq47Jm8HA2JaCytPN5AiR0NFzGZQ6PhsjR+hpy3T1iudBcvdGFr1SJUASU/khS9813a 9VMiUiPO+8uGlkFASRRPttOJzVTja12IFZnMpppLnxjJklTOljMlqegL7xfeJwjbBxay QfMInfxCIQj/427CJzMMxF9RrMqTOjr2w080nYB929tyNQSppzRKJWzAz7UJLODihpcx oWVQ== X-Forwarded-Encrypted: i=1; AJvYcCVr59hv/ks6WIhmpyzQchXYZaz1urg3t6vMzOyhFIbIG/wKHV5uiVFFfh0lHqLfu1Mg8caaHPaYEF9HfJhmiJe0@lists.infradead.org X-Gm-Message-State: AOJu0Ywtaxq60svW5M9cjXX77Gmy3J2gmuZcdkNXowljrJL2DPJAXFnY zxnRGuBw6LmG8vlqStdxwKBwPLlQEYJHSCyhXS4jQSzlXcUXedXn62lBJsAJWoAwPoZqD7Eg1gG nWJcMnQwFPD5qLV6ctwWM2A== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-14-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 13/16] mm: sparc64: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232825_978018_94435164 X-CRM114-Status: GOOD ( 16.20 ) 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 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: 13904516 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 2EECAE7717D for ; Wed, 11 Dec 2024 23:44:15 +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=z6Hm5oOLdBb7ho6/nkMyyfkvkknoYZ/+aPdlC1ktc9c=; b=l7Mdu+Xz2MAgW6X5aFqaDEh8Vj PGw/YEHkOtbjo4+0CgAMSiSxkpGPkHUovb7abmuePvWMMxh3/ZcVfbyxxs6ulaoKQwmnpdEQS8Qra RdqFfldycMMNrL8EjKV8q3lCw/FKBzaKIwO1Qvf/b9dp/sCoFp0scKJ1poDgDnueEv2st3xk0ZoNz 45esleFuajRWwLInQrOT7cQaYIiiAxIXvoDWQ2m89MxiSgQX+fCvSMOEDiCF+Xwo0B/zGv2rG/mkT 7dFTTxB5I2HWCdWsifCvoOfnblbfodVWcfWew6SYJuq+Ti0QVSkFPy4nZc75K0rxSPYVc5Y+PJkXW jhrN4hbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWNB-0000000GW6F-0iXs; Wed, 11 Dec 2024 23:44:05 +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 1tLW86-0000000GSfO-2w3n for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:30 +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=z6Hm5oOLdBb7ho6/nkMyyfkvkknoYZ/+aPdlC1ktc9c=; b=o3AjDsOX4U3AI/UNIzKR0PgQ37 4LvMIsnUgViC0HRuUGsQHwQOYOonAC6hrcQsGBSBhp7R11V08KKfG5hhnC+CqbusQs+SrLvbd/nBO iAgcTmJh7Py6cYbV3JjTgK9y6GBcthy6VDN0skw3jII7Tp/Cm4GCy9tJEDRFV+APZGbHHqCXxPjX2 1KgYH3gNC7PJUJ2lc/S9J8LpW9h1WbH3rnZccc10vzda08KbNl6d1DzAE2nycvq0CtzjEC8PbI5I6 ggcHD3DHHrm3O6J6bsDk3e8puoWerVKWi+84nwAzEodb0nwnkyeVYNPtOCME4JePudH5DRzj17/3S U7tg0DWQ==; Received: from mail-oo1-xc49.google.com ([2607:f8b0:4864:20::c49]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW83-00000003w77-2STk for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:29 +0000 Received: by mail-oo1-xc49.google.com with SMTP id 006d021491bc7-5f2d927fe56so11238eaf.2 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=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=z6Hm5oOLdBb7ho6/nkMyyfkvkknoYZ/+aPdlC1ktc9c=; b=Sl5VMlULaaO9iPZ6Qo7l3Rl1aTQIjQ6N20DmSeRRhpZxPf9/F8O50hKFLMa1K5PvGB HGEhO7HWICiB/r+D8yjmQLCtQuc5PAQFz5OYa1RRWyHOGb2xtF+ddU1B5re1KWUuk0KL qHhZYmD2XnSq9ekqlf7dCb2jbWD7+STZzRKt0b7TVCVXcXmbfljTT2sf+p5zTjMh5lZa TZOow3rXsgfksNJ+sC5LAAaa7J7gcJHU8jsK4ZFrgY0+NO85RP1hG9jlM0r/+wSobEwt Xe6q1LtK18EBWnzAtfZlZLGBbsQ45YibdEbLQnVdZI3PbSHtnXWZz8um2/uiv1j8RIZ+ N81Q== 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=Ak14pduQ5lRSD9Ty/NOT/iRFpV+V0pnwR+RPYiK3GiWx4LQI/A8A9IujZmlL+I36ea /IlFQ30wR5xfMAqtYa12w7Sk3gMFNBqu50yl3SllF8Op57ZhRqpOSjLSn07dc28/fQgU JOaysN1w0fIUJ6SiSDUJFNjZenV6JW6ybImGC8JRZD4jtx5Gbk+CYXdRqfiYSgAlUXjC /TR8WM5hBBl//8pw4KipZge6VSGx7gaPXqiKK4HrGir6NstB8cYAObmqj9HX+NXrgUi/ HJqSdouftJBJTgwM/1Ad/fMfbiVnczW5qV/OtDgTJglBAgMGF+hvZ3mVFiJmpFuln5m/ EHpg== X-Forwarded-Encrypted: i=1; AJvYcCUrHE5PnB3s/ruV3DuiV6c6Ea78M3OmCN0f9uwQE3Vk4XGyhOC6wAlWz3uandtyI/MQ83zVfoqhyCGBJ9Pem+sK@lists.infradead.org X-Gm-Message-State: AOJu0YyesJfdxYesvhYHrax91mfJYfTQHi5SbjmSZ/TOS9tnh42YV5BW nYcLKE/AtDR21rustML+rYvicvcss53VVg6EjhwdRHgffW/MIAtZSbMt9xti1srRSUJXPFucsAL jo9YsQQ1ipGdAc+96VcaX8A== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-15-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 14/16] mm: xtensa: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232827_944857_4BFED0AF X-CRM114-Status: GOOD ( 13.12 ) 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 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: 13904517 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 670DEE7717D for ; Wed, 11 Dec 2024 23:45:22 +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=mzI/WChqoEagnx9fXIUsiKk2yVJ1VLNiv4KjzJVNd2U=; b=ci5A3154gLG3oufL01yJ4i3zYf b0NDMuoK/JnUfcvG6MUwyWFt1S/jqxfzakDbUW4eEmPE+LYVNRGpmLj4t8wHHQ6d4R8mrkJTWI8Or 5n8d0Lk/qw2Sap55dj9TPV7004SXHpwn3bsK/6qTDO8NghnOf9LgXgzdT9NqVbz/SdwDAul4BHlxp thxHpJe5Q1WVbpQUHha8e8Joq4e5zk0x7ijRBGgcOXCoN1Ud20U5Dp99/SG7ZZJC3XCey3X9l60Yb 8biuj2C6MJiKD9ssA86ojr2JwHpqmd/qtjXhFhnBPMDJ2WhzyZ/FaWGRW/HlWVnzyvJh/zOks/wjB jrYfnkHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLWOD-0000000GWRE-1gfk; Wed, 11 Dec 2024 23:45:09 +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 1tLW87-0000000GSg8-2mzc for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:31 +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=mzI/WChqoEagnx9fXIUsiKk2yVJ1VLNiv4KjzJVNd2U=; b=i05RCnvtMavUltFhHITwzp2mga 8ZyKxenTWAcGOgWIn2lL26LOl7j8zp/4a1fxy7RtFUck7KD3Lz53u51e/Yb04F6Nz/6hDOXhtFzuf hjQDg3o2OwCzjrcpQ1cKgiwjrM92gLMgWodamMmiggHFx2mEKlYtV1+xqXWeL9yVMCpjHbLU1z3xt 0hKL1zxIvGs+hp6pyg3FhRGc+qbssyFcO+EcSmvRDQtAMfzBtCQFA/VrN7/Z8BS149dClDTCb/F+U 3hYnt+Sv/G2tBAknPxizx7vQRJiO82DTPe/AViVkQHHg2Zgh5vVKZfYtbEnQwCduoKJifAI0uxaHI u9Hot7+g==; Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW84-00000003w80-2ms5 for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:30 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-728f1c4b95aso25742b3a.0 for ; Wed, 11 Dec 2024 15:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959706; x=1734564506; darn=lists.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=mzI/WChqoEagnx9fXIUsiKk2yVJ1VLNiv4KjzJVNd2U=; b=atHxoZkgPzOb167a+gg9+6HJa/uSE3oa6MxP06OsnIKHKAktm+M3IzhPNoFJQb9TQM 9GYxMScNVhNF3WD0OdwyQejV99XYuT1NfE8ImbuqOfH0P1q5ebQjJKjz05JulLZZ9rXJ /KAv1e5w1AS8IhCXPNCmqn7LkR4xi43yW1j1YDZxQNtNgvvMpGlieK5K25KGhYP15dMb ufWBximLoruAoADRzjs4ir+CEU6mMCJLYFacB3PdCzKsipnm/tIqm/yh1BGtKeK5qOGy 0CyH0+FC9/Omh2u8SEYuwWdmahvLAwppA7KPS5An4EgzY9lCnvv8oy88RH/wYqhEvW4B 6vNA== 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=OVMIwj4ayp5MKkwUbAK0C5V5Swm9lzv1L/gYC+yOwtXbTPNGwN43yyRfH9OngU+Ndo TRFm1e30XzPiOvwa/yfg4Fmvqxalth7r8n/Xjn1HQgoCrshwOZBqOizBOuq0Eh4hSjbB soIG28vCmczJ98CLtDPcOvIy+oY0N5W1hOAeY46Knqay4d8AL2vl9uPtIX54rWGOaubl mi4sWJq5MrNT9V83ePNLPREmsw27/TteWM7qODy21I6xFk1K4Sz0ENv1LOVjZZxl5qv5 sP/ak8VL8K4yTUaMtcJwRj9FLBwdHwAhmeE5CyOLHAxAReAbYCuLojWIPSKth3sP53qh PbxA== X-Forwarded-Encrypted: i=1; AJvYcCVpD9BIpYKm6HlY7oQZc/shXrGeHda0CPZ9uWkGtIWm66X96OP1BIv1J/VBoygJ3hVYmAJk88mk4JE1zctlm0E5@lists.infradead.org X-Gm-Message-State: AOJu0YzzkHwjm10uBOyMos7FKQCjZR50votFgtdZvfJXmP3Uze+xIwYk smM5omyko576PYyU6h0M1EkU+DNCNI1b/jr/suMOswrwsTurwHOxnb5Hw4qjsWAViY6q4aSQF6T cn8JdyUUf+UBVzVobOZzaQg== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-16-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 15/16] mm: powerpc: Introduce arch_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232828_912479_8A47A9E3 X-CRM114-Status: GOOD ( 10.54 ) 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 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: 13904588 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 DE2A9E77180 for ; Thu, 12 Dec 2024 01:00:54 +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=oHbDZ++mGE8tEdFCxijZAS2pZkYuZT5989Fg2aOx0oY=; b=ujNO4Oypi0uC0tTfCXGDOwxIZN /zbLxk3V0fpg1KnxhOM4bvxOFdIsTAuefVpFvuEle/gbl55ekFUXhGePK0Cz0U2sI3lhCAJaD7px0 JXWDGSL3/0qP7NBosBKcxWIqcj+CIkOGE59tGrvvgyWGQbqo21jTVRpg6n1hIo2IGsCu8eAnRCbKs twlED3yOkzfsPYKkb+z1kuo+oVJjAueBLIOYbzd4YSRQo0BIsCisHAyJAfZQvrByXMQdisHUaJRai gvhzk4mVYY5HB7D0yeurEzZSdnoKBdWQ/8MtTNMkTY/7Nxib1L1zOv64oG1+T+F0e1WfZmeuo3v2w BQBj12Wg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLXZ2-0000000Gdrx-3kC5; Thu, 12 Dec 2024 01:00:24 +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 1tLW89-0000000GSh0-279X for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Dec 2024 23:28:33 +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=oHbDZ++mGE8tEdFCxijZAS2pZkYuZT5989Fg2aOx0oY=; b=SomsQXzS/4dOxdjbLonzLRsU3f 8D3fY44hbzp7wPexHZNLcRtIgvm5kXVwoXVuy5SUJmXXPlyAy9gyHr7TSLQB7cjCjBzgk4ZBKgCkP xUGdx65xN1ki9ugJdDIxmtxUVhw+8ZG6B5cSocbYjbZkgg7KATGxQtYhyv8I4ycYn9SP7eMek694l HCaKUi71JkVPb7V+TtN3zUo5K/kCcV0UAEfqDkOy2PsvJ8ZibdJae7vkkaU4YSBJQyjR40pvF2nUS Rh3hai0Gx7t2J8F5tzi7b2oBk6BLkDcdkZRoksO/B+ngFe9zz+3hjSK0DXNuESpGOa11eAFH9I7wN RSof1fGA==; Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLW86-00000003w8k-0TWr for linux-arm-kernel@lists.infradead.org; Wed, 11 Dec 2024 23:28:31 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7f712829f05so38159a12.0 for ; Wed, 11 Dec 2024 15:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733959708; x=1734564508; 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=oHbDZ++mGE8tEdFCxijZAS2pZkYuZT5989Fg2aOx0oY=; b=gloDFQOIe55MT4ee1uhsJmSV91C2e2sfS55S5Qstpw/cpCYwZH5U9ghv4SrjsZoIsD 9GZotNtFnZCzeS+zW/Q4aes9Irt/FTjADsfO1bSwnPQt3eb5q+fbrcsEaPqUr/TNgPCh TqxUq8RmTD+noRnTpsnztgHX42qt/IaOXHvjNVYx9Da/At6buqpSs8MusFdoYUN1rr2r VT6hpFrHJWtSQf5iYOwHljlX+WcGdoaNjWHg4gNApq0VW3wEmFAbj/4LSfVbn4c241Jc nolmhSzxQpyio0guFLXGBBq3uVBEuuZIMvM/nT1OfWQdphl6GhAzDu26WH91DrVTwvn+ 8DRQ== 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=WrJeAD1Up1EZk+U0o7OrJzCC7yQwAKdmLFnLfq9axHha9cSU77RXYtmdesm94ppSPt fniCzVK+RIIfefRuR7Amj56t7hOrWi1Ad2s1YNiya7gYuu/2/F4AkhmdKezx83ByCGow BOgrbmArMkeWWPzEYqI94YD1clrgQibXWbb8ITb2natzO1Y+FBOQZEoi1AVWNsZzQ6o4 4BrIIAeT5dBDtX47vHhecYzf+giQkfbXBOtehZqDHztZV6Zk3ThhcbC1h3dRuxwy5Lvl aX5FjMmZgTBTCMSK9AhjYF5p7swEvSLz4wnLXrFvRgDcjZbwsC/7AZZS/zB4CQoVEa53 Ziww== X-Forwarded-Encrypted: i=1; AJvYcCWk+9H2c8zZlmzangEQlUBaMqWwJ+bYUgbQY1KdvE1S010SFzNDs1dINRvSTYsR+HQMvcLu+msxHcez+v8g4dRz@lists.infradead.org X-Gm-Message-State: AOJu0YztnSxbIuXp6Z8QVFKC2IoRIxX3jtbz/nqleOYEteLps8jCyCNg 7OdR1pAZaYo498x7Xq8GQace1wDJqnZ9LCq06RGzbhsM4/hXO9hQL2WrcajlSj2vQQNUU/dfgYc nRbDbzC6/GROOhUf5U4Hg8w== 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> Mime-Version: 1.0 References: <20241211232754.1583023-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241211232754.1583023-17-kaleshsingh@google.com> Subject: [PATCH mm-unstable v2 16/16] mm: Respect mmap hint before THP alignment if allocation is possible From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com, minchan@kernel.org, jyescas@google.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241211_232830_353800_5F170582 X-CRM114-Status: GOOD ( 18.83 ) 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 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 --- 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,