From patchwork Thu Aug 8 15:42:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13757856 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 98ACBC52D7C for ; Thu, 8 Aug 2024 15:42:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B2F56B00F8; Thu, 8 Aug 2024 11:42:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 788BB6B00FA; Thu, 8 Aug 2024 11:42:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6612F6B00F8; Thu, 8 Aug 2024 11:42:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 48EDD6B00F8 for ; Thu, 8 Aug 2024 11:42:44 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E738E1413BF for ; Thu, 8 Aug 2024 15:42:43 +0000 (UTC) X-FDA: 82429495806.21.1ADC53D Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) by imf19.hostedemail.com (Postfix) with ESMTP id 1BD3F1A0008 for ; Thu, 8 Aug 2024 15:42:41 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=0h1A8Oal; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf19.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.41 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723131689; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oRSFFXDfNtNVk7lGVeoRIubNta7FSFGwpVVL6fGvxf0=; b=H9ZG2DbONngvWozAWlq2GUvVyJYrXxuW701UPppGYDURf4VJi1Ep1R64MxGAIKDora7P5w RULW/OfHkorzr4yPxeiGnbz2BL2SEQlD5dSa4DyFciVCMr+7F7MBlOwj8+1qwJq4JP+KLn KS7WxdfskJLs0XhyQ8uPxA/bd88uoMk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723131689; a=rsa-sha256; cv=none; b=hqb2SLzBZRWyUBjnNs4KD0XkT4qVgD/P15GJLsFnUl/fqsc5th78mlUrTaaIxOeEqXguEg PWBHU1QsN1Lw/JqQ0GhAY3kqeMhJHRaw5GWoUxqCq0Av2FV4vuQT3DXomHOKGw/Bvv7qcc 2ZTli9NonT/ANpAfOPaV2sMeYTGvvMQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=0h1A8Oal; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf19.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.41 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-6bb96ef0e96so5964196d6.2 for ; Thu, 08 Aug 2024 08:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1723131761; x=1723736561; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=oRSFFXDfNtNVk7lGVeoRIubNta7FSFGwpVVL6fGvxf0=; b=0h1A8OaldduwwMbrHsKqvvkYeYIEg7uU8v56gQzm1ancvzYcWt2s2EZL9djKCVifTc cIFQXkPHJ93l/x8JR+f45ix/gx9u44McltWvYJTIVH9fIYl/U5U7q6XjZ5X7Y5TNvww4 oQiLE7ly5DYO9gyccTqsNddlhVPhPdBpiO+yMlRNzh9TieR1U7yg0rdC6JOOdQQvP0aw 2PvYQgLQt+FcMbwzZ2yvl2Haab2CWJyPLxUXoz8mJdULf/sQqidCYWuL+sZy5YkNMXWT OFV4dVjkTie1xxy00CvF7BtUvb1z19Bi3BIIw0x6QtFwQM3LpYj7UiR/MX5WKIRRDU03 JIag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723131761; x=1723736561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oRSFFXDfNtNVk7lGVeoRIubNta7FSFGwpVVL6fGvxf0=; b=ZeeGCA4p/zxoyYujNT9X+AZYaqhuiv09UEaAjRtQ3cgvebfYfQ7awuMrAurtGuELd9 xwYJ5O7Mioxcnw3BF0mBzcY11D/Xdm6PG+98X0eHSRontbFX+DQ/liV8Ovx0zfPNQOW5 kORO62pqtDe6WcPLI8SXd1uXJd0ChU9zWat6cbahMRk9FTyGB/6mnkg0+I11CTJCJq1B mYC2dZS/MCa0zMVUEx1xGYI/HovCaDYMcGwjgf78TuWO67lyVw337lpmrBtvEuyJgDd6 fV3u0dL37aeevyH99RsaA/jK1wLDJfymPiCsTrdONa//h7H0w0TIwOGGOozIzocvRjmO MrrQ== X-Forwarded-Encrypted: i=1; AJvYcCWAD+D/1/3cNW9sKfJ4Yejx8/JzlTL4H50q089CkYMz6SPr8ksKAGb+rPS5A79R7FrKjUOWMxY1wNt2a6m67rGPgEQ= X-Gm-Message-State: AOJu0Yy4fKw86mDks3sA5M/wC9m/XPK7NU9rIbMW8/WT+3Sl/mmuTKFU 4lxPYLlwgh1HQP7dJcCoFHPmzldnN33VuCqxJ1G3qf0HfaOPLJ5IV4dumkftmjQ= X-Google-Smtp-Source: AGHT+IEedYPnvL6gKHQRQr0wt7cczChz5kQMKQlE59fzWebBtyv5plUCNw68Wg5Sa6xCxlvPXi39qw== X-Received: by 2002:a05:6214:4604:b0:6b9:607e:275e with SMTP id 6a1803df08f44-6bd6bd3263bmr24643256d6.34.1723131761187; Thu, 08 Aug 2024 08:42:41 -0700 (PDT) Received: from soleen.c.googlers.com.com (118.239.150.34.bc.googleusercontent.com. [34.150.239.118]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bb9c7b72d9sm67160936d6.60.2024.08.08.08.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 08:42:40 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, cerasuolodomenico@gmail.com, hannes@cmpxchg.org, j.granados@samsung.com, lizhijian@fujitsu.com, muchun.song@linux.dev, nphamcs@gmail.com, pasha.tatashin@soleen.com, rientjes@google.com, rppt@kernel.org, souravpanda@google.com, vbabka@suse.cz, willy@infradead.org, dan.j.williams@intel.com, yi.zhang@redhat.com, alison.schofield@intel.com, david@redhat.com, yosryahmed@google.com Subject: [PATCH v3 1/4] mm: update the memmap stat before page is freed Date: Thu, 8 Aug 2024 15:42:34 +0000 Message-ID: <20240808154237.220029-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog In-Reply-To: <20240808154237.220029-1-pasha.tatashin@soleen.com> References: <20240808154237.220029-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1BD3F1A0008 X-Stat-Signature: jq6xozr65xt34yszfxygf1sw7gt1thg8 X-Rspam-User: X-HE-Tag: 1723131761-475926 X-HE-Meta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z5xjkk5Vce0PbDFkqw/w41Hr3cJYQw6+1oMO/eumIx1O+RUTLnG3S7yaC3Vqa8yNIc4c85dHNNYAv+VEuwVf7RTGv+qDJYEg/sDCAMbpWA0E2i155ocGFnPHX6NiBeTFTB33ndPkiYlhbye+ROA8CVa36f4u0YKtzdox7jrRY2vBKhdAftcg5iRrEHW/pljfZ1mMfcYDgnTZxeCS5b9Ex6auv+Vs1xr+yQOpBCs7gFo5EVa+jOFEOEcGDNkn/QNPxmEPFgVRVQfBNeinmyxcBD52BiKlilej5dOVFC467b64L/rUF4= 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: It is more logical to update the stat before the page is freed, to avoid use after free scenarios. Fixes: 15995a352474 ("mm: report per-page metadata information") Signed-off-by: Pasha Tatashin Reviewed-by: David Hildenbrand Reviewed-by: Yosry Ahmed Reviewed-by: Fan Ni --- mm/hugetlb_vmemmap.c | 4 ++-- mm/page_ext.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 829112b0a914..fa83a7b38199 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -185,11 +185,11 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, static inline void free_vmemmap_page(struct page *page) { if (PageReserved(page)) { - free_bootmem_page(page); mod_node_page_state(page_pgdat(page), NR_MEMMAP_BOOT, -1); + free_bootmem_page(page); } else { - __free_page(page); mod_node_page_state(page_pgdat(page), NR_MEMMAP, -1); + __free_page(page); } } diff --git a/mm/page_ext.c b/mm/page_ext.c index c191e490c401..962d45eee1f8 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -330,18 +330,18 @@ static void free_page_ext(void *addr) if (is_vmalloc_addr(addr)) { page = vmalloc_to_page(addr); pgdat = page_pgdat(page); + mod_node_page_state(pgdat, NR_MEMMAP, + -1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); vfree(addr); } else { page = virt_to_page(addr); pgdat = page_pgdat(page); + mod_node_page_state(pgdat, NR_MEMMAP, + -1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); BUG_ON(PageReserved(page)); kmemleak_free(addr); free_pages_exact(addr, table_size); } - - mod_node_page_state(pgdat, NR_MEMMAP, - -1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); - } static void __free_page_ext(unsigned long pfn)