From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2258C186E58; Mon, 23 Dec 2024 16:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734970012; cv=none; b=boi0KhpeQN/DyHtpXkLfFZLfG1OAnIvApaRoyAq8LX2km2jWCCpuiZCYpqhAGyQ0kBzpQ1sd+r3vLct6NwS+AUYT1Nyo3tpNfKVKdMQFyA/r2j1ucIlX/3WXTGnBzu8KgQIsE/qzyDqWeo5mYtjVgKau6ZrfOMoTTD5rkZueJ4M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734970012; c=relaxed/simple; bh=gTIZIE4sJriFUdw8HvinP8LL7N6854ccQq8SMA8DTi8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ez2Rrnw2vLZPoqIjHpbkuyvpKqPeuNU+pFkuEe1w7CBbTwVaukUbUHAC5212igp2pw1vfULn7OybOGEOcJ7B1axfe652nyVfdqBkbNGWnIacVejj7uSzIgAAgmzQmVHxyd3iP4pCK1U8r5CxzsIt05leaA/rlteewvv5u/AavU8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=GOmXVQOL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="GOmXVQOL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 847A6C4CED3; Mon, 23 Dec 2024 16:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734970012; bh=gTIZIE4sJriFUdw8HvinP8LL7N6854ccQq8SMA8DTi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GOmXVQOLVlM6UJgXW2miFKvcpU31ZR6nVSPAGNxzy9MN8EDNSE9BgkuHEtkTbvFP4 91aXEqOlMSG0vBMjE8eZR5bI/DdQ1hhpfdkfe7Iolz7oMuz6VvBscZJTMV9HhSFGnX 8zrzap7eoJXyb7o1aeG4JHXNc+bRuQU05TGG+vJM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Matthew Wilcox (Oracle)" , Johannes Weiner , Shakeel Butt , Balbir Singh , Michal Hocko , Christoph Hellwig , Muchun Song , Roman Gushchin , "Uladzislau Rezki (Sony)" , Andrew Morton Subject: [PATCH 6.12 111/160] vmalloc: fix accounting with i915 Date: Mon, 23 Dec 2024 16:58:42 +0100 Message-ID: <20241223155412.962849551@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241223155408.598780301@linuxfoundation.org> References: <20241223155408.598780301@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Matthew Wilcox (Oracle) commit a2e740e216f5bf49ccb83b6d490c72a340558a43 upstream. 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. Link: https://lkml.kernel.org/r/20241211202538.168311-1-willy@infradead.org Fixes: b944afc9d64d ("mm: add a VM_MAP_PUT_PAGES flag for vmap") Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Johannes Weiner Reviewed-by: Shakeel Butt Reviewed-by: Balbir Singh Acked-by: Michal Hocko Cc: Christoph Hellwig Cc: Muchun Song Cc: Roman Gushchin Cc: "Uladzislau Rezki (Sony)" Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/vmalloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3369,7 +3369,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 @@ -3377,7 +3378,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); }