From patchwork Fri Nov 5 20:37:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12605485 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23F16C433FE for ; Fri, 5 Nov 2021 20:37:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D1F21611C0 for ; Fri, 5 Nov 2021 20:37:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D1F21611C0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 6D1F7940039; Fri, 5 Nov 2021 16:37:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 65A0D940007; Fri, 5 Nov 2021 16:37:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FC2E940039; Fri, 5 Nov 2021 16:37:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id 3A922940007 for ; Fri, 5 Nov 2021 16:37:52 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 00FC96EDE9 for ; Fri, 5 Nov 2021 20:37:52 +0000 (UTC) X-FDA: 78776037984.02.153071F Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf27.hostedemail.com (Postfix) with ESMTP id 99BF970000AE for ; Fri, 5 Nov 2021 20:37:51 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 9018460174; Fri, 5 Nov 2021 20:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1636144670; bh=mQfLVeFky/wjvihXxWdCm3YwQNNOIc8OFRailCxRgaY=; h=Date:From:To:Subject:In-Reply-To:From; b=XLIS7WnvT6OGa1Pj4ukL0J8ai9VXu5qY0TFBftGYk9DTQtUM60R1L2UgOxR3F1ooT 2rQUVwadEO91wHaxx1nUF0wDjPbv+HN3R1tRaGCHKhq0pCrc9BXxQRqIpnxbYhpMgU wp0AAXyGotM8M+khITkxWppPtt6YTgI0ydMhZpRM= Date: Fri, 05 Nov 2021 13:37:50 -0700 From: Andrew Morton To: akpm@linux-foundation.org, guro@fb.com, hannes@cmpxchg.org, linux-mm@kvack.org, mhocko@kernel.org, mm-commits@vger.kernel.org, shakeelb@google.com, songmuchun@bytedance.com, torvalds@linux-foundation.org, willy@infradead.org Subject: [patch 061/262] mm: list_lru: fix the return value of list_lru_count_one() Message-ID: <20211105203750.6jGE4g6rW%akpm@linux-foundation.org> In-Reply-To: <20211105133408.cccbb98b71a77d5e8430aba1@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 99BF970000AE X-Stat-Signature: bp3dnd9d7fprhi9egjzkkyrszftctbyc Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=XLIS7Wnv; dmarc=none; spf=pass (imf27.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1636144671-649686 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: From: Muchun Song Subject: mm: list_lru: fix the return value of list_lru_count_one() Since commit 2788cf0c401c ("memcg: reparent list_lrus and free kmemcg_id on css offline"), ->nr_items can be negative during memory cgroup reparenting. In this case, list_lru_count_one() will return an unusual and huge value, which can surprise users. At least for now it hasn't affected any users. But it is better to let list_lru_count_ont() returns zero when ->nr_items is negative. Link: https://lkml.kernel.org/r/20211025124910.56433-1-songmuchun@bytedance.com Signed-off-by: Muchun Song Cc: Johannes Weiner Cc: Matthew Wilcox (Oracle) Cc: Michal Hocko Cc: Roman Gushchin Cc: Shakeel Butt Signed-off-by: Andrew Morton --- mm/list_lru.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/mm/list_lru.c~mm-list_lru-fix-the-return-value-of-list_lru_count_one +++ a/mm/list_lru.c @@ -176,13 +176,16 @@ unsigned long list_lru_count_one(struct { struct list_lru_node *nlru = &lru->node[nid]; struct list_lru_one *l; - unsigned long count; + long count; rcu_read_lock(); l = list_lru_from_memcg_idx(nlru, memcg_cache_id(memcg)); count = READ_ONCE(l->nr_items); rcu_read_unlock(); + if (unlikely(count < 0)) + count = 0; + return count; } EXPORT_SYMBOL_GPL(list_lru_count_one);