From patchwork Fri Aug 16 11:13:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Karwatzki X-Patchwork-Id: 13766011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B57ECC531DC for ; Fri, 16 Aug 2024 11:15:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 407CA6B01F1; Fri, 16 Aug 2024 07:14:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33EEA6B01F3; Fri, 16 Aug 2024 07:14:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11B106B01F4; Fri, 16 Aug 2024 07:14:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D0E676B01F1 for ; Fri, 16 Aug 2024 07:14:45 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 839DD121B18 for ; Fri, 16 Aug 2024 11:14:45 +0000 (UTC) X-FDA: 82457850930.21.27029A1 Received: from mout.web.de (mout.web.de [212.227.17.12]) by imf30.hostedemail.com (Postfix) with ESMTP id 95B1A8000B for ; Fri, 16 Aug 2024 11:14:43 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=L5L+6Zcl; spf=pass (imf30.hostedemail.com: domain of spasswolf@web.de designates 212.227.17.12 as permitted sender) smtp.mailfrom=spasswolf@web.de; dmarc=pass (policy=quarantine) header.from=web.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723806785; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E0tenUw2wopYUJtJXU9/jIJXrBQpDpxL8g+F0RGALdE=; b=2DDVP7OO6i0hq6S1v+W2xx9g+xKNjESKdmdCVHiL5jLo6RkbpS6e7p9eURiPulzBPWzGL5 nvXPFTkjApq/A3+t42x/CMdwa1ljDVwi6q/9HGTJYOL3vMV1cqBoHpsRBRYgTm9o1k5VYU YEjz02jRomueNOV2iM3+GNxIcJFVTUQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=L5L+6Zcl; spf=pass (imf30.hostedemail.com: domain of spasswolf@web.de designates 212.227.17.12 as permitted sender) smtp.mailfrom=spasswolf@web.de; dmarc=pass (policy=quarantine) header.from=web.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723806785; a=rsa-sha256; cv=none; b=16CIPXPhl/gg65WChEhzPirIDo8iYVX+arJFv4ChTTbBIG/2lSbTQHet9WGnQ2b8Ir1+fj CvrzithM6/jPUjyGPTCPNQQf11m6u9MdQe+a/44Eb/VwKbjqOpghpoQyeYJQ4lmsIp8lxF td5xX02RJMH6clsOXNmia6E/aZseFUg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1723806876; x=1724411676; i=spasswolf@web.de; bh=E0tenUw2wopYUJtJXU9/jIJXrBQpDpxL8g+F0RGALdE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=L5L+6ZclSX42QYLUW8vtiT2DDV1YDpOhnQExdYUeK+gKP70ob6BDFbrVi57Dq7OD SXzKAOx1jelINkzMw2MfwIV2Kl52MFHcPAX375TlyL2TmOyHep89DAAZ8+ngEuJ6L Ly2dssKnMC0UV2kJBrEOUMgEwAdlX241/FTZvk8JvjV5W2a8QybRKXiGem/R6kGnq hRoEN3F4MEZhJPdgQ4+r7OWE1S0mDvuxJTIQ7nbsc9aERcP758G+R+Bd3CrFg8OU+ K+fQj5pRuDpnX2m6ifzsS+kZp5egWy/gp9959iTbgEA0h7t0Yyq1xxzw88p/sNyX6 DkBQeZlouAHl4Kilpw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from localhost.localdomain ([84.119.92.193]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MIL4Y-1sQYuW0HC8-00380E; Fri, 16 Aug 2024 13:14:36 +0200 From: Bert Karwatzki To: "Liam R . Howlett" Cc: Bert Karwatzki , Suren Baghdasaryan , Vlastimil Babka , Lorenzo Stoakes , Matthew Wilcox , sidhartha.kumar@oracle.com, "Paul E . McKenney" , Jiri Olsa , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Kees Cook , Jeff Xu , "Liam R . Howlett" , Lorenzo Stoakes Subject: [PATCH v5.1 15/19] mm/mmap: Use PHYS_PFN in mmap_region() Date: Fri, 16 Aug 2024 13:13:56 +0200 Message-ID: <20240816111405.11793-16-spasswolf@web.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240816111405.11793-1-spasswolf@web.de> References: <20240816111405.11793-1-spasswolf@web.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:eCVsU7mzHyULyhBGJDmXZIAx9FHHpxBOTVU7MpEzaMObRLktneQ WA9rkX1sAY1n5DbOrkqc9/qYe7aDDa2u7GPHUCOV8ylG9qS49ksbEXIrvUIXVxJJa6IplUS RnAiqkGx7jYtteewJE8JIdovsqUFWe1pDqORtMKUBECCsrjkaid7BH/By5+WMbpm5GbwLm3 q2AOA3OXOU82MSdb86uxw== UI-OutboundReport: notjunk:1;M01:P0:bA1vkDMWn8Q=;9XG+PHSHOtTHHkd5lMT97oXUb+9 /QaI7lZ3s0q6Hr0G6SODvGqbbwspTcKMBg/AngIZtq+pN/N/whiiXDuBZLFDdUN72p1ebRTmS ZsdDtfDYTAidoAWZ42p7wBUj45WSk7qJrtt3lj9XDyh368F7fh9yHgG1dNUQymRhefuqV4w4S yVQQeSTFRJtYslXnqWdh0mlLMCnyM/ugUFANiJrtGBnIbdjtcBbQAWvuf89NzrGm43p91VlED HqzBXet5JHKzyFrdR2rG+m5SkXaWEnCsEyTboAJ37nicTU2OT/OzB1A6jtufxkVeIVSA10H2p mzsq0D9e+vabkp/IKwwvk3VINxlSsjeMRpaRb4dtDu1uLAIlLybpIo/aC2k5pMXc185jw8Egb dwA42nv1Qi6Zavr1OUnVkO3b2gZKoC7hnZ2Fntl4yCfN/RhdzqgVmWE+klqF7tzLAUO3g8KHi KoDZABV1mJ+m93IqnMloI6nngx7qXWovS917yy+WiOGTY45HNjkWB9ZdlJztiHQTB9Ryiwoxb pU/andK5GpJoiHjyVQEuOvgnMNn5caRsVwmL/GRHdeFSFZ91/YjpjxMOdlxDUA8DAPkEF7/7S AlEtgHAIUSW5ongs+ezmE1uVlcO89p7XyqcnWZnp1sE35oID9GpvX8VVcg8G/AjIZtR28aQL0 f+ZwnUeTUegV9JblYi+o0M9Pggjke/kaWMidpvB01UaqPvA2a4tzHkYGf5FqIy3S9LhponjG0 +y3B0IY3KFIKDB5/pnF2wXzLpePCQzbGKKGWo+jS/EoDnfep7kwgESuZ2mHACN4MMtWGM1dWF T0Ra8v2JMpZ5MNkzUpMz6dzg== X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 95B1A8000B X-Stat-Signature: i4t4fygb8c1dmtr1o7mf5xwqzmu78uec X-Rspam-User: X-HE-Tag: 1723806883-477771 X-HE-Meta: U2FsdGVkX1+7DXaDzHLgp3jTW6T4PxFIIdd600sC3UyZwPQpOU/N9pXV2AElgI7FISCUGcqvOjglQLbKr4VQeyRLbMp9Cv+MuAoVfKK75F5wAN2u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27XEkXQNkJ/Qn5kFJjbrYv2jnkI9wucNL6G1DjfhXxwiG1pHkTxCAWYHgZXyLyyOaP2qxf+M1FGPr3VLps90dtKHh8lvCHq6PzKneeX4zv/WryJvwAXQ0Vehf+MrAjQDESjmAvLIJT/d5uLQcenBYegIZJg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Instead of shifting the length by PAGE_SIZE, use PHYS_PFN. Also use the existing local variable everywhere instead of some of the time. Signed-off-by: Liam R. Howlett Reviewed-by: Lorenzo Stoakes Reviewed-by: Suren Baghdasaryan --- mm/mmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.45.2 diff --git a/mm/mmap.c b/mm/mmap.c index e152b6caaf9c..57fb1c82a852 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1364,7 +1364,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, struct mm_struct *mm = current->mm; struct vm_area_struct *vma = NULL; struct vm_area_struct *next, *prev, *merge; - pgoff_t pglen = len >> PAGE_SHIFT; + pgoff_t pglen = PHYS_PFN(len); unsigned long charged = 0; struct vma_munmap_struct vms; struct ma_state mas_detach; @@ -1384,7 +1384,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * MAP_FIXED may remove pages of mappings that intersects with requested * mapping. Account for the pages it would unmap. */ - if (!may_expand_vm(mm, vm_flags, (len >> PAGE_SHIFT) - nr_pages)) + if (!may_expand_vm(mm, vm_flags, pglen - nr_pages)) return -ENOMEM; if (unlikely(!can_modify_mm(mm, addr, end))) @@ -1415,7 +1415,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * Private writable mapping: check memory availability */ if (accountable_mapping(file, vm_flags)) { - charged = len >> PAGE_SHIFT; + charged = pglen; charged -= nr_accounted; if (security_vm_enough_memory_mm(mm, charged)) goto abort_munmap; @@ -1575,14 +1575,14 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (vms.nr_pages) vms_complete_munmap_vmas(&vms, &mas_detach); - vm_stat_account(mm, vm_flags, len >> PAGE_SHIFT); + vm_stat_account(mm, vm_flags, pglen); if (vm_flags & VM_LOCKED) { if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm)) vm_flags_clear(vma, VM_LOCKED_MASK); else - mm->locked_vm += (len >> PAGE_SHIFT); + mm->locked_vm += pglen; } if (file)