From patchwork Fri Aug 16 16:09:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Karwatzki X-Patchwork-Id: 13766575 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 5BA43C531DC for ; Fri, 16 Aug 2024 16:10:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E37BE6B0361; Fri, 16 Aug 2024 12:10:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE6386B0362; Fri, 16 Aug 2024 12:10:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C86D56B0363; Fri, 16 Aug 2024 12:10:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AACAA6B0361 for ; Fri, 16 Aug 2024 12:10:15 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3BE1FC010E for ; Fri, 16 Aug 2024 16:10:15 +0000 (UTC) X-FDA: 82458595590.11.589764A Received: from mout.web.de (mout.web.de [217.72.192.78]) by imf29.hostedemail.com (Postfix) with ESMTP id 15F3E12001F for ; Fri, 16 Aug 2024 16:10:12 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=dxxA5BNK; dmarc=pass (policy=quarantine) header.from=web.de; spf=pass (imf29.hostedemail.com: domain of spasswolf@web.de designates 217.72.192.78 as permitted sender) smtp.mailfrom=spasswolf@web.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723824553; a=rsa-sha256; cv=none; b=5bJQaMZEcrXN6Box4tXwOfNAB4HI4/yZzZIPqM/AVp4EQYtvztMqbgWh685hzIX4rpnAeu FQmBn6hdGhEdqOmdQXP8SI9Sni9A5JhejJlJJRH3vAkVv9X13QDOiyjuxWgpEQH0JqT0VN Jk5W5PIWSZFXTPpXFQhrOuVswFxZBx8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=dxxA5BNK; dmarc=pass (policy=quarantine) header.from=web.de; spf=pass (imf29.hostedemail.com: domain of spasswolf@web.de designates 217.72.192.78 as permitted sender) smtp.mailfrom=spasswolf@web.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723824553; 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:references:dkim-signature; bh=AmchI/mG/89rB0ctm/Lc5xogMtZgADTp8F1OlxCErWc=; b=JNjxRJ3jVzm5SsgrY0wRZeNvlcrQVvtE4zpvFVSD8MZhABmHAMY6Wy0vXmFnptChNvuqaX u/aWsL1qA1l9UiNIGw1DRAReI+YbpnQ6JAt6Zbi03y7MsyGW3ec4qhjRqmOCz/9+GkpnAn rsv4fc4bFOCA9DRYk7ipe274hNdsbt0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1723824604; x=1724429404; i=spasswolf@web.de; bh=AmchI/mG/89rB0ctm/Lc5xogMtZgADTp8F1OlxCErWc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID: MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=dxxA5BNKt5E5dGXUu/1mShVE24nJUcfB78loaTD872vuFvtgyz1RKXh5gGQ+rXLe 6/jIMEbGg7qrdkxNW2GOrzcFgnO2XadlpkOPb/yMGugpY0siNzA0fJz/0hWgMnzFo NAhqRBhN0dBPrtGJDOaU+ORNGMGYcqwGUer5HcwDY76cBhtuSbDz0D18WAwPCO2nd n3OCNvgWxKElISQzNYPqN/RcSoKJE2PotgKGJzAN/ihnS1PIt7UOW0dIa+pgs6pHB Tscg0WkYEkYiGXtl8nTaL/Hn+Ram82RnyLcRB5X8a28FdhfyOA0NvUeOtThSA1lo9 UcK2W7OR6vCGd+VByA== 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 1MCol0-1sW9q012sC-008eIT; Fri, 16 Aug 2024 18:10:04 +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" , linux-security-module@vger.kernel.org, Lorenzo Stoakes Subject: [PATCH v5.1 16/19] mm/mmap: Use vms accounted pages in mmap_region() Date: Fri, 16 Aug 2024 18:09:59 +0200 Message-ID: <20240816161000.2805-1-spasswolf@web.de> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Provags-ID: V03:K1:JGM+UFz9mnK+dk5IHlGfFo+pKmuhMOGrj45PRVD26wBmNPDV41E lK47NqDqgqByTLZbGjYLjaYF+HFeVqqH/jmbrgXKSwbT8tLJn2FGSghTWWgW9LWw56x/gGU NNerZhrasjoetmqnt1SJQaXnvW5iyvlwe0Xodks8udK7iOARL+PrfoXpZNb3pDsiOf4cB+z fRtx6+prJocut62CHYCcQ== UI-OutboundReport: notjunk:1;M01:P0:rRzJMlqlChs=;NhoU0uBcvC7hw644J1GISkdkjoa UIvvOWBiilyu7LnRug6QLpm/RgZ/hH+yerngyKY0lGQgc0y4nGLLIveat4s8TFN7BsQ8IKXfv 3xSVBIbpET/rHH2OC1V42Og6SN/2YMwkUswzPPSk8YJqbd+au4igW1UP2ygvcs4Fdp3Rw/0kv eAPCU0zQR8qvGZuB12l61QtciYO+bWnndY6TS2beIRbjHKS0N0GksyA+EgY6/iDYDIMrq+5SA 91xMW26mQjg2SjGhH9aXZ6/Xty8G6/woRKj1pzl6gtqsw5YBwQshxYrO6cfhZXo7DgIVdiYsN El4T8+HK61YDFDeyqyMohwjboLa/WOYcBV6Qu1opAiTdSiqp/3KyEbEu/pQOL2fvDPo5vNOTO 2Nj9TAfp0n5KmCjp/Jt6JjZ3ualApxvhz574v7J3aL60m1rwXQA5+7uScdpC9iGyc7yBrqCok 2uRSWVzPFiWb71knOWLJeL4OYEWALEZXP0fr749sRLq1KsAxPvJmFE1DCd2ZnPfimo9wZGn5Y MPkdNRtfQVvXm/b9t7BljR2JiC3yhZtuxQ3442Memu7bs2qgfQdOmHPsrAUKnUFtn7VFO+8Lt jCtt7NI7PjcRvWrSX+dIC7IUWtlQMKbzU7jr01p6w6gq/K+dSnbFWmGFbAck4yepCoRh6Yd4p Ouw1oIGQBNfYGqRkYdCWr4KrhOCHolJ9/eb2YsCe65AykVfO6382Rs4lQ+L4zxg/VMcN0clIZ qv6d9VValj2uGFeOds1AHlMXKY347kOABfeYVn0niwcP1QKnZMJGSfHhQwyQDXL0t/YSKhR0k V6pM+pZVK52KQ4GGjJq+uD3A== X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 15F3E12001F X-Stat-Signature: u7tadef17r87c4ajbnheps38ay17s1jb X-Rspam-User: X-HE-Tag: 1723824612-443697 X-HE-Meta: U2FsdGVkX1+a/s/TChEb9/OBWymSr5PjjuUjuMBPlIbNcsYO4NW2qZmhHQoAUfKoPU67qTJNTVtEPNLi+jDadDtRcNm8I1yfpNTsByQIS5UJi+RotfPC2lEGDqSZDGgBHufMd6izgS5nmRk8AGdm1QRqjaRFOkXBoU+s4SCEbP4M5/oBMr9RSkF5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+SYx8bshq9QkzvEjkzSAKFB+gzObkxXEMdZl8YLKzAPKy+LMFICqq6m32m5HLv0opKYO7P2kJYGim1PaEYzu0NVULDKaljoSDCIxSsNhlFVKf6uDcj636bFM/SHS9Tp319p3w== 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: Change from nr_pages variable to vms.nr_accounted for the charged pages calculation. This is necessary for a future patch. This also avoids checking security_vm_enough_memory_mm() if the amount of memory won't change. Signed-off-by: Liam R. Howlett Cc: Kees Cook Cc: linux-security-module@vger.kernel.org Reviewed-by: Kees Cook Reviewed-by: Lorenzo Stoakes Reviewed-by: Suren Baghdasaryan --- mm/mmap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.45.2 diff --git a/mm/mmap.c b/mm/mmap.c index 57fb1c82a852..d0942b1a62f0 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1416,9 +1416,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, */ if (accountable_mapping(file, vm_flags)) { charged = pglen; - charged -= nr_accounted; - if (security_vm_enough_memory_mm(mm, charged)) + charged -= vms.nr_accounted; + if (charged && security_vm_enough_memory_mm(mm, charged)) goto abort_munmap; + vms.nr_accounted = 0; vm_flags |= VM_ACCOUNT; }