From patchwork Wed Dec 11 20:25:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13904123 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 61129E7717D for ; Wed, 11 Dec 2024 20:25:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF2296B0082; Wed, 11 Dec 2024 15:25:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CA1746B0083; Wed, 11 Dec 2024 15:25:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8FE06B0085; Wed, 11 Dec 2024 15:25:45 -0500 (EST) 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 9AA286B0082 for ; Wed, 11 Dec 2024 15:25:45 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C4CC0A123F for ; Wed, 11 Dec 2024 20:25:44 +0000 (UTC) X-FDA: 82883808546.11.B6DCA3A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id F11A0C0010 for ; Wed, 11 Dec 2024 20:25:15 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PE2iUvat; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733948732; 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=ksbtM9EHkNTzFRsceNZ/+H1YFyjHaIe3HxlpDQ6sOig=; b=iWmmd3CzhVhRRWuul/g4gLPKDMoC6IIlAtoK5t+ZZPFRthycCv3TTmTNxE/iGUn80bb9Ip PCU7rHnCCFK0Y2KKPEKFeIRVYA8uvfgIC+ZsDKAiL+Hril/+KkMjaiPxQewuktn27I88yt kNoXS0oqScazSL6BuQeBH2vsRDDKepE= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PE2iUvat; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733948732; a=rsa-sha256; cv=none; b=iamvukCnU3D0M4Oe/PstEXCbTVAwVQc0R6phEGOyZePqeIR4bJd8/mnWv1Umhrm9nDFLo/ hnYjaAzYr9Yl+ekB2nYPe8ZXFAzS8b8JAg4hU7o+PZSENQAxWCUG52/jKtLVhOWW3OqeZf w6bN/MVBaeY9fJfarObXRjERPI5QEy8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=ksbtM9EHkNTzFRsceNZ/+H1YFyjHaIe3HxlpDQ6sOig=; b=PE2iUvatkvAM0U3FfNWu9Q34sD QEwOEaRn+40VhLdDC4lTxR10Bl0STlZVb0cXb3bsmEN5ON2HfJiDi65DYpjc8dIggWSDHCPNJPJHb WL4bn/rUIrhjEBMi08fNnr/WdWhLXfj0pamIp0GydLbDhFZBwPSJueoUhPMysF8jV5uousKrG9jhH Qlz2sRaoSEPnJXGkD/HifohhmmQ6KRxFBvJDOKxZuVa5czhR5turirXB6I3vcB4luzkVarvCE8FzX y9VDdqHFWeNLHFpJ4LaOrC1fC3Imc9l3l6xZMGvizu7VvbqT47MIEgDGm39U9w8GdxJ976hq9RSwW w0YVn1IQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tLTHA-00000000hop-2yNF; Wed, 11 Dec 2024 20:25:40 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , Christoph Hellwig , linux-mm@kvack.org, Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , cgroups@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v3] vmalloc: Fix accounting with i915 Date: Wed, 11 Dec 2024 20:25:37 +0000 Message-ID: <20241211202538.168311-1-willy@infradead.org> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: F11A0C0010 X-Stat-Signature: 19gm1q8jey81ziha59s3ocuodz9yt5xg X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1733948715-607606 X-HE-Meta: U2FsdGVkX1/pActewJtn89U5Vrr+Iat2/p52IdSJRWhczSkYu2EvMLIt+Vjqq55JfV95Uxxw5TxnByHTObZf4nVe3hP7BXLTqPaT3DqGwDhg23SaZGUGthsBGN18hqgLSdnUhNpTk/kGMXKh65uZNJ4dj9gPDatWMQg4KruvntXJvY9GuGy/kfkADJ5cQrBxaxrURpzwF0IXhfsuOBBqQDURlzvZii2OBJQNXkOb1XN6Z0D/pz0KujK5SgkKadYbpOo03mj09Opj845zLz4nYjMiKh+SSCas7UKA2YzPW2plntgpd5sgsj+u4xPz82lAQec3NnEWyS2gZiVuivdgIDPrXZxeCCTP9sOQr77c4ey8uSGoNRGO4xKJmrVZLRhwub3HiEdBUKKNJSVC50sqZ2FBuNPenf0+jT8VcSAzReI8JAOc4efihKzVcKenIz7GpS9NBZD3dG4SPuVW+ooJ7gzOo5i+SDzryZOeyHR6mNz94QGK1SCFu93OyKkqj5SBiAQ5L/caI6PIYcOGb6WvKPbk7Jeu6z8s4v1iNtbImQLxeWtgI2CzIB3Xn49tSLJ7n82x9C4wvW5yda5RQUjB4vAyqTtpaK1rTMMcqoz0kb8oBlRs4T5678WAmillFYnvX+Lqxq2lfUf7GZ2ZX6cqtBM/ybZQtmydsbxY6EGDWF7HZOuaasHRVipmHeYYPN8rEDTiKAsaleIu5Lt0j3Gq3Dq1ETa3El4V82gjpM570toOyVLaJvvvp1ZFt6M7t6Z09i6JZ7MVMaK2SfMK1vgTRqrf3XVzA5Q6k9FByjtoCtvP/qMXsxwZMJ5KFIKeQ3J2TOslIJaqQHBaTT9VyQmmST7/8NdWrny/W7H6Fi1VOfPr921f+JlnlyasR7DHKqoKxa4Tc0lUR5hkzKzb9u+45273OQzQHJowN5/45UGm7T5l9t5WLEZpPGvOFZZ4lqrT62oAszuIdZk4HhfFKOe x0vip4aI AqwLw23smAnrfXJp6uAfdid/EWW+IL0xP1QO8Rh/FwT76wbCOqP8k0/5OSutT6IRI+pekKc5jemLeZDrDJ6vM+k5ekBLA1XNPrdmSJzWniOrRnyr3iEXwHXsMsP1w8QCIyH3o6CFytuANKRm54Lb979LesEdDa2ptp1J08/4gdVoEQAL4NWS9h49TVfs+RMD6t78XIxAhuiB7CC9EWrBlitNOsA1omPV5RBSKmcKkb5NpIPLXXACwDL4lAFdDSupyIY9T/laq11Z2Whm924IBDa8ccwkqiZzBHILlup4vuFLnW35SSrllekhHTueyAKDimq+n 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: If the caller of vmap() specifies VM_MAP_PUT_PAGES (currently only the i915 driver), we will decrement nr_vmalloc_pages and MEMCG_VMALLOC in vfree(). These counters are incremented by vmalloc() but not by vmap() so this will cause an underflow. Check the VM_MAP_PUT_PAGES flag before decrementing either counter. Fixes: b944afc9d64d (mm: add a VM_MAP_PUT_PAGES flag for vmap) Cc: stable@vger.kernel.org Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Johannes Weiner Reviewed-by: Shakeel Butt Reviewed-by: Balbir Singh --- mm/vmalloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index f009b21705c1..5c88d0e90c20 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3374,7 +3374,8 @@ void vfree(const void *addr) struct page *page = vm->pages[i]; BUG_ON(!page); - mod_memcg_page_state(page, MEMCG_VMALLOC, -1); + if (!(vm->flags & VM_MAP_PUT_PAGES)) + mod_memcg_page_state(page, MEMCG_VMALLOC, -1); /* * High-order allocs for huge vmallocs are split, so * can be freed as an array of order-0 allocations @@ -3382,7 +3383,8 @@ void vfree(const void *addr) __free_page(page); cond_resched(); } - atomic_long_sub(vm->nr_pages, &nr_vmalloc_pages); + if (!(vm->flags & VM_MAP_PUT_PAGES)) + atomic_long_sub(vm->nr_pages, &nr_vmalloc_pages); kvfree(vm->pages); kfree(vm); }